Skip to main content

AWS Secrets has a auto-rotation feature, but Django doesn't support it out of the box. This package provides a way to rotate the secret in Django settings.

Project description

DJ DB Rotated Secret

AWS Secrets auto-rotation will cause a password authentication failure in Django that is unhandled.

This is a low level wrapper around Django's _cursor and connect db functions to handle and and allow graceful rotation.

WARNING

This is very much an alpha release. Jenfi uses it in production, but it is entirely suited to our needs. PRs welcome to expand the capabilities.

Things to Know

  • Postgres only via psycopg 2 & 3

  • It is a monkey patch and can only be added via installed_apps.

    • i.e. if a password gets rotated after django loads but before this library gets loaded while another app makes a DB connection, the password error won't get caught. Extremely narrow window.
  • This library does not know/care about how to obtain the updated password. Simply tell it a function path to run and it will call it assuming a return dict of:

    {
      "username": "...",
      "password": "...",
    }
    

Install

  1. poetry add dj-db-rotated-secret

  2. Add to installed apps, below django and above other apps.

        INSTALLED_APPS = [
          ...
          "dj_db_rotated_secret",
          ...
        ]
    
  3. Declare a function to run when password auth fails:

        DJ_DB_ROTATED_SECRET_FUNC = "path.to.function"
    

Function Info

  • The function takes no arguments.
  • The function must return a dictionary with the keys username and password.

Development

  • Uses poetry

Running Tests

Run psycopg2 and psycopg3 in isolation (like ci does):

  1. Run docker compose up
  2. Run chmod +x run_tests.sh
  3. Run ./run_tests.sh

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

dj_db_rotated_secret-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

dj_db_rotated_secret-0.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file dj_db_rotated_secret-0.1.0.tar.gz.

File metadata

  • Download URL: dj_db_rotated_secret-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.5.0

File hashes

Hashes for dj_db_rotated_secret-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aff04e5b04ffd17857047f067a790090bcef504e3f303c2ea1d160e2009dfbd5
MD5 7b26e3ee6d6b55ebfcf2711284fa35f1
BLAKE2b-256 1092ba8bd7781641746630415741d1daac72c5dbf08aa22966a67a478c6a759b

See more details on using hashes here.

File details

Details for the file dj_db_rotated_secret-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dj_db_rotated_secret-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 49f897656e05af121aba75cdf40dbf9eaa35d49982a78ccfcc7808e09a456976
MD5 499e33f1b3ca9cc85dd40a83c53b2ef6
BLAKE2b-256 b7661165af7ec8161dd08d7d7e8d977fc105693ee81cd989f7cf95f6805658d1

See more details on using hashes here.

Supported by

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