1
0
System for loading secrets from a variety of sources.
Go to file
takunomi-build-bot 01ecb7710f
All checks were successful
Package Python / Package (push) Successful in 25s
Python Ruff Code Quality / ruff (push) Successful in 22s
Run Python tests (through Pytest) / Test (push) Successful in 24s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 21s
🤖 Bumped version to 0.1.30
This commit was automatically generated by a script: https://gitfub.space/Jmaa/repo-manager
2024-12-02 18:24:13 +01:00
.gitea/workflows 🤖 Repository layout updated to latest version 2024-10-27 17:27:20 +01:00
secret_loader 🤖 Bumped version to 0.1.30 2024-12-02 18:24:13 +01:00
test Removed unneeded noqa 2024-11-01 01:54:44 +01:00
.gitignore 🤖 Repository layout updated to latest Python version 2024-06-13 22:01:55 +02:00
LICENSE 🤖 Repository layout updated to latest version 2024-07-16 22:15:42 +02:00
README.md 🤖 Repository layout updated to latest version 2024-11-28 21:02:35 +01:00
requirements_test.txt README and requirements 2024-07-08 18:10:55 +02:00
requirements.txt README and requirements 2024-07-08 18:10:55 +02:00
ruff.toml 🤖 Repository layout updated to latest version 2024-10-31 22:38:54 +01:00
setup.py 🤖 Repository layout updated to latest version 2024-10-31 22:38:54 +01:00

Secret Loader System

Test program/library Codequality (Ruff)

System for loading secrets from a variety of sources.

Usage:

import secret_loader

secrets = secret_loader.SecretLoader(env_key_prefix='MYAPP')

db_username = secrets.load_or_fail('DATABASE_USERNAME')
db_password = secrets.load_or_fail('DATABASE_PASSWORD')

Secret loading order:

  1. Hardcoded values. This is purely for debugging, prototyping, and for configuring below options.
  2. Files pointed to by environment variables. Docker friendly.
  3. Secrets folder. Also Docker friendly. Defaults to secrets, but can be configured through the SECRETS_DIRECTORY key (NOTE: passed directly, rather than through a file.)
  4. Pass: the standard unix password manager. Most suited for personal usage; very unsuited for server environments. Requires pass installed locally, and configuration of the PASS_STORE_SUBFOLDER through one of the above methods.

Future extensions

  • Key casing should be more consistent
    • Case-insensitive for hardcoded and load.
    • Upper case for environment variables.
    • Lower case for files and others.
  • New special configuration value for switching the secrets directory.
  • Wrap secrets in intelligent strings:
    • Instead of returning None on unloaded, return UnknownSecret, that produce error when formatted.
    • repr(secret) should not include contents, but only the secret and how it was loaded.
    • Methods on Secret should be kept minimal.
  • Avoid leakage to swap files.
  • Vault:
    • Ensure vault code path works.
    • Document usage and requirements.
  • Get inspiration from https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html

Dependencies

All requirements can be installed easily using:

pip install -r requirements.txt

Full list of requirements:

License

MIT License

Copyright (c) 2024 Jon Michael Aanes

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.