Skip to main content

A Django middleware for Google Cloud RUN IAP authentication.

Project description

Django Cloud Run IAP Authentication Middleware

This package provides a simple Django middleware to authenticate users via Google Cloud's Identity-Aware Proxy (IAP), specifically tailored for Cloud Run deployments.

Installation

pip install -e git+[https://github.com/boot-sandre/django-cloudrun-iap.git](https://github.com/boot-sandre/django-cloudrun-iap.git#egg=django-cloudrun-iap)

Or after publishing to python pypi registry:

pip install django-cloudrun-iap

Configuration

To integrate django_cloudrun_iap into your Django project, follow these steps to modify your settings.py file.

1. Add to INSTALLED_APPS

First, add django_cloudrun_iap to your INSTALLED_APPS list to register the application with your project.

# settings.py
INSTALLED_APPS = [
    # ... other apps
    'django_cloudrun_iap',
]

2. Add Middleware

Next, insert the IAP middleware into your MIDDLEWARE list. It is crucial to place it immediately after Django's built-in AuthenticationMiddleware.

# settings.py
MIDDLEWARE = [
    # ... other middlewares
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django_cloudrun_iap.middlewares.IAPAuthenticationMiddleware',
    # ... other middlewares
]

3. Configure IAP Settings

Finally, add the following configuration variables to your settings.py file.

# settings.py

# Toggle the IAP middleware. Set to False to disable IAP authentication.
IAP_ENABLED = True

# The audience claim for your IAP-secured resource. This value can be found
# in your Google Cloud Console under the IAP settings for your resource.
# Format: /projects/$PROJECT_NUMBER/locations/$REGION/services/$SERVICE
IAP_EXPECTED_AUDIENCE = '/projects/123456789123/locations/europe-west1/services/myawesomedjango'

# (Optional) Restrict logins to a specific Google Workspace or Cloud Identity domain.
# Can use a string, a list of domain, or a tuple
IAP_EMAIL_DOMAIN = ["emencia.com", "velops.eu"]

IAP_EXEMPT_URLS = [
    "/api/healthcheck/",
    "/status/"
]

Usage

The middleware checks for the presence of specific headers provided by Google Cloud IAP. It then validates the JWT to ensure the request is legitimate and comes from a trusted source. Finally, it matches the user's email to a Django user account and logs them in.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_cloudrun_iap-0.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_cloudrun_iap-0.0.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file django_cloudrun_iap-0.0.1.tar.gz.

File metadata

  • Download URL: django_cloudrun_iap-0.0.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.0

File hashes

Hashes for django_cloudrun_iap-0.0.1.tar.gz
Algorithm Hash digest
SHA256 9acdf75bdb39779f656340232655d74dd993fcc85f705532b797336996951f33
MD5 83215f6f56cd6d067876b37c3920c728
BLAKE2b-256 e165ecd59ab3c80f04d93fcbf44e6eb52dd414917b5774d747bbcb57a33e3a5c

See more details on using hashes here.

File details

Details for the file django_cloudrun_iap-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_cloudrun_iap-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1f1332399437001d393fa964b2ee7289f4479be20326c2133e803c7133fa3ad0
MD5 b3cbaf6c6666e690e02c5d6585fbb789
BLAKE2b-256 a448daed21d1fdf2debd30869d7255e8d27a4697e779944522c7fc984de9e54e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page