Skip to main content

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

Metadata

Release files for dj-db-rotated-secret 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dj-db-rotated-secret 0.1.1
File Size Uploaded
dj_db_rotated_secret-0.1.1.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dj-db-rotated-secret 0.1.1
File Interpreter ABI Platform
dj_db_rotated_secret-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / dj_db_rotated_secret-0.1.1.tar.gz

Download URL dj_db_rotated_secret-0.1.1.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6bb30f7f8ea0e355b7b6ce8602be832128d2ec7823f9be59e81506d294a00d55
BLAKE2b-256 checksum
How to use checksums
0a730f92cec1fe40e7d7b49f85e958d63cd7f40317ffbae70a0feb0ba8f0fd7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.5 Darwin/23.5.0

Release files / dj_db_rotated_secret-0.1.1-py3-none-any.whl

Download URL dj_db_rotated_secret-0.1.1-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
de32f6182cfb768d8a26a9edd9f4a7a093812adac562990c94d8645f0fa9c9fb
BLAKE2b-256 checksum
How to use checksums
427d7815a5c9e097503144c368fdbbe0fe4f1df34fb9e3120ac597db1faf0578
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.5 Darwin/23.5.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page