A secure, encrypted credentials system for Django, inspired by Rails credentials.
- Environment-specific encrypted credentials
- Simple management commands (edit, show, generate key)
pip install django-secure-credentials
Add secure_credentials
to your INSTALLED_APPS
in settings.py
:
INSTALLED_APPS = [
...
'secure_credentials',
...
]
Add secret keys to .gitignore
:
echo "secrets/*.key" >> .gitignore
Run the following command to generate a new key and credentials file:
python manage.py credentials_generate_key <environment>
This will create a new key and credentials file at config/credentials.yml.enc
.
To edit the credentials file, run:
python manage.py credentials_edit <environment>
To load the credentials in your Django app:
from secure_credentials.secrets_loader import decrypt_credentials
credentials = decrypt_credentials("environment")
Where credentials
is an instance of class CredentialsContainer
containing the decrypted credentials.
To access a credential:
credentials.get('key')
or
credentials.dig('key', 'subkey')
for complex nested credentials.