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.1.tar.gz
.
File metadata
- Download URL: dj_db_rotated_secret-0.1.1.tar.gz
- Upload date:
- Size: 4.6 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 | 6bb30f7f8ea0e355b7b6ce8602be832128d2ec7823f9be59e81506d294a00d55 |
|
MD5 | 5d8f9c7289da708a26a7cee27831e7e2 |
|
BLAKE2b-256 | 0a730f92cec1fe40e7d7b49f85e958d63cd7f40317ffbae70a0feb0ba8f0fd7a |
File details
Details for the file dj_db_rotated_secret-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: dj_db_rotated_secret-0.1.1-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 | de32f6182cfb768d8a26a9edd9f4a7a093812adac562990c94d8645f0fa9c9fb |
|
MD5 | 502db5d9b272f767009688fa442480e4 |
|
BLAKE2b-256 | 427d7815a5c9e097503144c368fdbbe0fe4f1df34fb9e3120ac597db1faf0578 |