secure-credentials-kit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. secure_credentials_kit-0.1.0/LICENSE +21 -0
  2. secure_credentials_kit-0.1.0/PKG-INFO +227 -0
  3. secure_credentials_kit-0.1.0/README.md +197 -0
  4. secure_credentials_kit-0.1.0/pyproject.toml +52 -0
  5. secure_credentials_kit-0.1.0/secure_credentials_kit/__init__.py +0 -0
  6. secure_credentials_kit-0.1.0/secure_credentials_kit/cli.py +105 -0
  7. secure_credentials_kit-0.1.0/secure_credentials_kit/credentials.py +128 -0
  8. secure_credentials_kit-0.1.0/secure_credentials_kit/fastapi.py +53 -0
  9. secure_credentials_kit-0.1.0/secure_credentials_kit/management/__init__.py +0 -0
  10. secure_credentials_kit-0.1.0/secure_credentials_kit/management/commands/__init__.py +0 -0
  11. secure_credentials_kit-0.1.0/secure_credentials_kit/management/commands/credentials_edit.py +20 -0
  12. secure_credentials_kit-0.1.0/secure_credentials_kit/management/commands/credentials_generate_key.py +29 -0
  13. secure_credentials_kit-0.1.0/secure_credentials_kit/secrets_loader.py +63 -0
  14. secure_credentials_kit-0.1.0/secure_credentials_kit/utils.py +194 -0
  15. secure_credentials_kit-0.1.0/secure_credentials_kit.egg-info/PKG-INFO +227 -0
  16. secure_credentials_kit-0.1.0/secure_credentials_kit.egg-info/SOURCES.txt +24 -0
  17. secure_credentials_kit-0.1.0/secure_credentials_kit.egg-info/dependency_links.txt +1 -0
  18. secure_credentials_kit-0.1.0/secure_credentials_kit.egg-info/entry_points.txt +4 -0
  19. secure_credentials_kit-0.1.0/secure_credentials_kit.egg-info/requires.txt +8 -0
  20. secure_credentials_kit-0.1.0/secure_credentials_kit.egg-info/top_level.txt +2 -0
  21. secure_credentials_kit-0.1.0/setup.cfg +4 -0
  22. secure_credentials_kit-0.1.0/setup.py +4 -0
  23. secure_credentials_kit-0.1.0/tests/test_fastapi.py +77 -0
  24. secure_credentials_kit-0.1.0/tests/test_key_roles.py +118 -0
  25. secure_credentials_kit-0.1.0/tests/test_packaging.py +68 -0
  26. secure_credentials_kit-0.1.0/tests/test_secrets_loader.py +28 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alexander
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,227 @@
1
+ Metadata-Version: 2.4
2
+ Name: secure-credentials-kit
3
+ Version: 0.1.0
4
+ Summary: A secure encrypted credentials system for Django and FastAPI, inspired by Rails credentials
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/lexpank/django-secure-credentials-kit
7
+ Project-URL: Issues, https://github.com/lexpank/django-secure-credentials-kit/issues
8
+ Keywords: django,fastapi,credentials,encryption,security
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Framework :: Django
18
+ Classifier: Framework :: FastAPI
19
+ Classifier: Topic :: Security
20
+ Requires-Python: <3.15,>=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: cryptography>=41.0.0
24
+ Requires-Dist: pyyaml>=6.0
25
+ Provides-Extra: django
26
+ Requires-Dist: Django<6.1,>=5.2; extra == "django"
27
+ Provides-Extra: fastapi
28
+ Requires-Dist: fastapi>=0.100.0; extra == "fastapi"
29
+ Dynamic: license-file
30
+
31
+ # Secure Credentials Kit
32
+
33
+ A secure, encrypted credentials system for Django and FastAPI, inspired by Rails credentials.
34
+
35
+ ## Features
36
+ - Environment-specific encrypted credentials
37
+ - Framework-neutral CLI for generating and editing encrypted credentials
38
+ - Master keys for editing credentials and read-only keys for application runtime access
39
+ - Django management commands
40
+ - FastAPI helpers for loading credentials into application state
41
+
42
+ ## Installation
43
+
44
+ The PyPI distribution, Python package, and CLI are all named for Secure
45
+ Credentials Kit:
46
+
47
+ - Distribution: `secure-credentials-kit`
48
+ - Python package: `secure_credentials_kit`
49
+ - CLI: `secure-credentials-kit`
50
+
51
+ Supported versions:
52
+
53
+ - Python 3.10, 3.11, 3.12, 3.13, and 3.14
54
+ - Django 5.2 LTS and Django 6.0
55
+
56
+ For Django:
57
+
58
+ ```sh
59
+ pip install "secure-credentials-kit[django]"
60
+ ```
61
+
62
+ For FastAPI:
63
+
64
+ ```sh
65
+ pip install "secure-credentials-kit[fastapi]"
66
+ ```
67
+
68
+ ## Local Development
69
+
70
+ This project uses `pyproject.toml` for package metadata and uv for local
71
+ dependency management.
72
+
73
+ Install uv, then create a development environment:
74
+
75
+ ```sh
76
+ uv sync
77
+ ```
78
+
79
+ Install framework extras when you need to test integrations:
80
+
81
+ ```sh
82
+ uv sync --extra django
83
+ uv sync --extra fastapi
84
+ ```
85
+
86
+ Run tests:
87
+
88
+ ```sh
89
+ uv run python -m unittest discover -v
90
+ ```
91
+
92
+ Build the package:
93
+
94
+ ```sh
95
+ uv run python -m build
96
+ ```
97
+
98
+ ## Credentials Files
99
+
100
+ Add secret keys to `.gitignore`:
101
+
102
+ ```sh
103
+ echo "secrets/*.key" >> .gitignore
104
+ ```
105
+
106
+ Generate a new key:
107
+
108
+ ```sh
109
+ secure-credentials-kit generate-key <environment>
110
+ ```
111
+
112
+ This creates two keys:
113
+
114
+ - `secrets/<environment>.master.key` can decrypt, edit, encrypt, and sign credentials.
115
+ - `secrets/<environment>.readonly.key` can decrypt and verify credentials, but cannot produce accepted credential updates.
116
+
117
+ You can regenerate a read-only key from an existing master key:
118
+
119
+ ```sh
120
+ secure-credentials-kit generate-key <environment> --role readonly
121
+ ```
122
+
123
+ Edit encrypted credentials:
124
+
125
+ ```sh
126
+ secure-credentials-kit edit <environment>
127
+ ```
128
+
129
+ Editing requires `secrets/<environment>.master.key`. Applications should normally
130
+ run with only `secrets/<environment>.readonly.key`.
131
+
132
+ The editor opens the decrypted YAML. The YAML root must be a mapping:
133
+
134
+ ```yaml
135
+ SOME_ENV_VAR: secret-value
136
+ database:
137
+ url: postgres://user:password@localhost:5432/app
138
+ api:
139
+ token: token-value
140
+ ```
141
+
142
+ Credentials are stored in `secrets/<environment>.yml.enc`, and keys are stored in
143
+ `secrets/<environment>.master.key` and `secrets/<environment>.readonly.key`.
144
+ The encrypted file is generated by the tool and should not be edited by hand. It
145
+ contains a signed encrypted payload similar to:
146
+
147
+ ```json
148
+ {
149
+ "version": 2,
150
+ "payload": "gAAAAAB...",
151
+ "signature": "..."
152
+ }
153
+ ```
154
+
155
+ ## Django Usage
156
+
157
+ Add `secure_credentials_kit` to your `INSTALLED_APPS` in `settings.py`:
158
+
159
+ ```python
160
+ INSTALLED_APPS = [
161
+ ...
162
+ 'secure_credentials_kit',
163
+ ...
164
+ ]
165
+ ```
166
+
167
+ You can also use Django management commands:
168
+
169
+ ```sh
170
+ python manage.py credentials_generate_key <environment>
171
+ ```
172
+
173
+ ```sh
174
+ python manage.py credentials_generate_key <environment> --role readonly
175
+ ```
176
+
177
+ ```sh
178
+ python manage.py credentials_edit <environment>
179
+ ```
180
+
181
+ To load the credentials in your Django app:
182
+
183
+ ```python
184
+ from secure_credentials_kit.secrets_loader import decrypt_credentials
185
+ credentials = decrypt_credentials("environment")
186
+ ```
187
+
188
+ Where `credentials` is an instance of class `CredentialsContainer` containing the decrypted credentials.
189
+
190
+ ## FastAPI Usage
191
+
192
+ Load credentials into FastAPI application state:
193
+
194
+ ```python
195
+ from fastapi import Depends, FastAPI
196
+ from secure_credentials_kit.fastapi import (
197
+ credentials_dependency,
198
+ setup_secure_credentials_kit,
199
+ )
200
+
201
+ app = FastAPI()
202
+ setup_secure_credentials_kit(app, "production")
203
+
204
+
205
+ @app.get("/settings")
206
+ def settings(credentials=Depends(credentials_dependency())):
207
+ return {"api_host": credentials.get("api_host")}
208
+ ```
209
+
210
+ If no environment is passed to `setup_secure_credentials_kit`, the helper checks
211
+ `SECURE_CREDENTIALS_KIT_ENV`, `FASTAPI_ENV`, `ENV`, then falls back to `development`.
212
+
213
+ ## Accessing Credentials
214
+
215
+ To access a credential:
216
+
217
+ ```python
218
+ credentials.get('key')
219
+ ```
220
+
221
+ or
222
+
223
+ ```python
224
+ credentials.dig('key', 'subkey')
225
+ ```
226
+
227
+ for complex nested credentials.
@@ -0,0 +1,197 @@
1
+ # Secure Credentials Kit
2
+
3
+ A secure, encrypted credentials system for Django and FastAPI, inspired by Rails credentials.
4
+
5
+ ## Features
6
+ - Environment-specific encrypted credentials
7
+ - Framework-neutral CLI for generating and editing encrypted credentials
8
+ - Master keys for editing credentials and read-only keys for application runtime access
9
+ - Django management commands
10
+ - FastAPI helpers for loading credentials into application state
11
+
12
+ ## Installation
13
+
14
+ The PyPI distribution, Python package, and CLI are all named for Secure
15
+ Credentials Kit:
16
+
17
+ - Distribution: `secure-credentials-kit`
18
+ - Python package: `secure_credentials_kit`
19
+ - CLI: `secure-credentials-kit`
20
+
21
+ Supported versions:
22
+
23
+ - Python 3.10, 3.11, 3.12, 3.13, and 3.14
24
+ - Django 5.2 LTS and Django 6.0
25
+
26
+ For Django:
27
+
28
+ ```sh
29
+ pip install "secure-credentials-kit[django]"
30
+ ```
31
+
32
+ For FastAPI:
33
+
34
+ ```sh
35
+ pip install "secure-credentials-kit[fastapi]"
36
+ ```
37
+
38
+ ## Local Development
39
+
40
+ This project uses `pyproject.toml` for package metadata and uv for local
41
+ dependency management.
42
+
43
+ Install uv, then create a development environment:
44
+
45
+ ```sh
46
+ uv sync
47
+ ```
48
+
49
+ Install framework extras when you need to test integrations:
50
+
51
+ ```sh
52
+ uv sync --extra django
53
+ uv sync --extra fastapi
54
+ ```
55
+
56
+ Run tests:
57
+
58
+ ```sh
59
+ uv run python -m unittest discover -v
60
+ ```
61
+
62
+ Build the package:
63
+
64
+ ```sh
65
+ uv run python -m build
66
+ ```
67
+
68
+ ## Credentials Files
69
+
70
+ Add secret keys to `.gitignore`:
71
+
72
+ ```sh
73
+ echo "secrets/*.key" >> .gitignore
74
+ ```
75
+
76
+ Generate a new key:
77
+
78
+ ```sh
79
+ secure-credentials-kit generate-key <environment>
80
+ ```
81
+
82
+ This creates two keys:
83
+
84
+ - `secrets/<environment>.master.key` can decrypt, edit, encrypt, and sign credentials.
85
+ - `secrets/<environment>.readonly.key` can decrypt and verify credentials, but cannot produce accepted credential updates.
86
+
87
+ You can regenerate a read-only key from an existing master key:
88
+
89
+ ```sh
90
+ secure-credentials-kit generate-key <environment> --role readonly
91
+ ```
92
+
93
+ Edit encrypted credentials:
94
+
95
+ ```sh
96
+ secure-credentials-kit edit <environment>
97
+ ```
98
+
99
+ Editing requires `secrets/<environment>.master.key`. Applications should normally
100
+ run with only `secrets/<environment>.readonly.key`.
101
+
102
+ The editor opens the decrypted YAML. The YAML root must be a mapping:
103
+
104
+ ```yaml
105
+ SOME_ENV_VAR: secret-value
106
+ database:
107
+ url: postgres://user:password@localhost:5432/app
108
+ api:
109
+ token: token-value
110
+ ```
111
+
112
+ Credentials are stored in `secrets/<environment>.yml.enc`, and keys are stored in
113
+ `secrets/<environment>.master.key` and `secrets/<environment>.readonly.key`.
114
+ The encrypted file is generated by the tool and should not be edited by hand. It
115
+ contains a signed encrypted payload similar to:
116
+
117
+ ```json
118
+ {
119
+ "version": 2,
120
+ "payload": "gAAAAAB...",
121
+ "signature": "..."
122
+ }
123
+ ```
124
+
125
+ ## Django Usage
126
+
127
+ Add `secure_credentials_kit` to your `INSTALLED_APPS` in `settings.py`:
128
+
129
+ ```python
130
+ INSTALLED_APPS = [
131
+ ...
132
+ 'secure_credentials_kit',
133
+ ...
134
+ ]
135
+ ```
136
+
137
+ You can also use Django management commands:
138
+
139
+ ```sh
140
+ python manage.py credentials_generate_key <environment>
141
+ ```
142
+
143
+ ```sh
144
+ python manage.py credentials_generate_key <environment> --role readonly
145
+ ```
146
+
147
+ ```sh
148
+ python manage.py credentials_edit <environment>
149
+ ```
150
+
151
+ To load the credentials in your Django app:
152
+
153
+ ```python
154
+ from secure_credentials_kit.secrets_loader import decrypt_credentials
155
+ credentials = decrypt_credentials("environment")
156
+ ```
157
+
158
+ Where `credentials` is an instance of class `CredentialsContainer` containing the decrypted credentials.
159
+
160
+ ## FastAPI Usage
161
+
162
+ Load credentials into FastAPI application state:
163
+
164
+ ```python
165
+ from fastapi import Depends, FastAPI
166
+ from secure_credentials_kit.fastapi import (
167
+ credentials_dependency,
168
+ setup_secure_credentials_kit,
169
+ )
170
+
171
+ app = FastAPI()
172
+ setup_secure_credentials_kit(app, "production")
173
+
174
+
175
+ @app.get("/settings")
176
+ def settings(credentials=Depends(credentials_dependency())):
177
+ return {"api_host": credentials.get("api_host")}
178
+ ```
179
+
180
+ If no environment is passed to `setup_secure_credentials_kit`, the helper checks
181
+ `SECURE_CREDENTIALS_KIT_ENV`, `FASTAPI_ENV`, `ENV`, then falls back to `development`.
182
+
183
+ ## Accessing Credentials
184
+
185
+ To access a credential:
186
+
187
+ ```python
188
+ credentials.get('key')
189
+ ```
190
+
191
+ or
192
+
193
+ ```python
194
+ credentials.dig('key', 'subkey')
195
+ ```
196
+
197
+ for complex nested credentials.
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "secure-credentials-kit"
7
+ version = "0.1.0"
8
+ description = "A secure encrypted credentials system for Django and FastAPI, inspired by Rails credentials"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10,<3.15"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ keywords = ["django", "fastapi", "credentials", "encryption", "security"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Framework :: Django",
24
+ "Framework :: FastAPI",
25
+ "Topic :: Security",
26
+ ]
27
+ dependencies = [
28
+ "cryptography>=41.0.0",
29
+ "pyyaml>=6.0",
30
+ ]
31
+
32
+ [project.optional-dependencies]
33
+ django = ["Django>=5.2,<6.1"]
34
+ fastapi = ["fastapi>=0.100.0"]
35
+
36
+ [project.scripts]
37
+ secure-credentials-kit = "secure_credentials_kit.cli:main"
38
+ secure-credentials-kit-edit = "secure_credentials_kit.cli:edit_main"
39
+ secure-credentials-kit-generate-key = "secure_credentials_kit.cli:generate_key_main"
40
+
41
+ [project.urls]
42
+ Homepage = "https://github.com/lexpank/django-secure-credentials-kit"
43
+ Issues = "https://github.com/lexpank/django-secure-credentials-kit/issues"
44
+
45
+ [tool.setuptools.packages.find]
46
+ exclude = ["tests", "examples"]
47
+
48
+ [dependency-groups]
49
+ dev = [
50
+ "build>=1.2.0",
51
+ "twine>=6.0.0",
52
+ ]
@@ -0,0 +1,105 @@
1
+ import argparse
2
+
3
+ from secure_credentials_kit.credentials import edit_credentials, generate_credentials_key
4
+
5
+
6
+ def print_key_paths(env: str, key_paths: dict) -> None:
7
+ for role, key_path in key_paths.items():
8
+ print(f"{role.title()} key for {env} has been generated and saved to {key_path}")
9
+
10
+
11
+ def generate_key_main(argv=None) -> int:
12
+ parser = argparse.ArgumentParser(
13
+ description="Generate an encryption key for secure credentials."
14
+ )
15
+ parser.add_argument("env", help="Environment name")
16
+ parser.add_argument("--secrets-dir", default="secrets", help="Credentials directory")
17
+ parser.add_argument(
18
+ "--role",
19
+ choices=["all", "master", "readonly"],
20
+ default="all",
21
+ help="Key role to generate",
22
+ )
23
+ args = parser.parse_args(argv)
24
+
25
+ try:
26
+ key_paths = generate_credentials_key(args.env, args.secrets_dir, args.role)
27
+ except (FileExistsError, FileNotFoundError, PermissionError, ValueError) as exc:
28
+ print(exc)
29
+ return 1
30
+
31
+ print_key_paths(args.env, key_paths)
32
+ return 0
33
+
34
+
35
+ def edit_main(argv=None) -> int:
36
+ parser = argparse.ArgumentParser(description="Edit encrypted secure credentials.")
37
+ parser.add_argument("env", help="Environment name")
38
+ parser.add_argument("--secrets-dir", default="secrets", help="Credentials directory")
39
+ parser.add_argument("--editor", help="Editor command to use")
40
+ args = parser.parse_args(argv)
41
+
42
+ try:
43
+ encrypted_path = edit_credentials(args.env, args.secrets_dir, args.editor)
44
+ except (FileNotFoundError, PermissionError, ValueError) as exc:
45
+ print(exc)
46
+ return 1
47
+
48
+ print(f"Data has been encrypted and saved to {encrypted_path}")
49
+ return 0
50
+
51
+
52
+ def main(argv=None) -> int:
53
+ parser = argparse.ArgumentParser(prog="secure-credentials-kit")
54
+ subparsers = parser.add_subparsers(dest="command", required=True)
55
+
56
+ generate_parser = subparsers.add_parser(
57
+ "generate-key",
58
+ help="Generate an encryption key for an environment.",
59
+ )
60
+ generate_parser.add_argument("env", help="Environment name")
61
+ generate_parser.add_argument(
62
+ "--secrets-dir",
63
+ default="secrets",
64
+ help="Credentials directory",
65
+ )
66
+ generate_parser.add_argument(
67
+ "--role",
68
+ choices=["all", "master", "readonly"],
69
+ default="all",
70
+ help="Key role to generate",
71
+ )
72
+
73
+ edit_parser = subparsers.add_parser(
74
+ "edit",
75
+ help="Edit encrypted credentials for an environment.",
76
+ )
77
+ edit_parser.add_argument("env", help="Environment name")
78
+ edit_parser.add_argument(
79
+ "--secrets-dir",
80
+ default="secrets",
81
+ help="Credentials directory",
82
+ )
83
+ edit_parser.add_argument("--editor", help="Editor command to use")
84
+
85
+ args = parser.parse_args(argv)
86
+
87
+ if args.command == "generate-key":
88
+ try:
89
+ key_paths = generate_credentials_key(args.env, args.secrets_dir, args.role)
90
+ except (FileExistsError, FileNotFoundError, PermissionError, ValueError) as exc:
91
+ print(exc)
92
+ return 1
93
+ print_key_paths(args.env, key_paths)
94
+ return 0
95
+
96
+ if args.command == "edit":
97
+ try:
98
+ encrypted_path = edit_credentials(args.env, args.secrets_dir, args.editor)
99
+ except (FileNotFoundError, PermissionError, ValueError) as exc:
100
+ print(exc)
101
+ return 1
102
+ print(f"Data has been encrypted and saved to {encrypted_path}")
103
+ return 0
104
+
105
+ return 1