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
-
poetry add dj-db-rotated-secret
-
Add to installed apps, below django and above other apps.
INSTALLED_APPS = [ ... "dj_db_rotated_secret", ... ]
-
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
andpassword
.
Development
- Uses poetry
Running Tests
Run psycopg2 and psycopg3 in isolation (like ci does):
- Run
docker compose up
- Run
chmod +x run_tests.sh
- Run
./run_tests.sh
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | aff04e5b04ffd17857047f067a790090bcef504e3f303c2ea1d160e2009dfbd5 |
|
MD5 | 7b26e3ee6d6b55ebfcf2711284fa35f1 |
|
BLAKE2b-256 | 1092ba8bd7781641746630415741d1daac72c5dbf08aa22966a67a478c6a759b |
File details
Details for the file dj_db_rotated_secret-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: dj_db_rotated_secret-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f897656e05af121aba75cdf40dbf9eaa35d49982a78ccfcc7808e09a456976 |
|
MD5 | 499e33f1b3ca9cc85dd40a83c53b2ef6 |
|
BLAKE2b-256 | b7661165af7ec8161dd08d7d7e8d977fc105693ee81cd989f7cf95f6805658d1 |