secretshield 0.2.0__tar.gz → 0.3.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.
- {secretshield-0.2.0 → secretshield-0.3.0}/LICENSE +1 -1
- {secretshield-0.2.0 → secretshield-0.3.0}/PKG-INFO +130 -5
- secretshield-0.2.0/secretshield.egg-info/PKG-INFO → secretshield-0.3.0/README.md +481 -381
- {secretshield-0.2.0 → secretshield-0.3.0}/pyproject.toml +3 -4
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield/__init__.py +1 -1
- secretshield-0.3.0/secretshield/autofix/__init__.py +7 -0
- secretshield-0.3.0/secretshield/autofix/env.py +73 -0
- secretshield-0.3.0/secretshield/autofix/fixer.py +273 -0
- secretshield-0.3.0/secretshield/autofix/gitignore.py +32 -0
- secretshield-0.3.0/secretshield/autofix/python.py +161 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield/cli.py +219 -14
- secretshield-0.3.0/secretshield/git/__init__.py +21 -0
- secretshield-0.3.0/secretshield/git/hooks.py +236 -0
- secretshield-0.3.0/secretshield/github/__init__.py +7 -0
- secretshield-0.3.0/secretshield/github/actions.py +58 -0
- secretshield-0.2.0/README.md → secretshield-0.3.0/secretshield.egg-info/PKG-INFO +506 -355
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield.egg-info/SOURCES.txt +14 -1
- secretshield-0.3.0/tests/test_autofix.py +335 -0
- secretshield-0.3.0/tests/test_git_hooks.py +146 -0
- secretshield-0.3.0/tests/test_github_action.py +58 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/tests/test_scan.py +42 -0
- secretshield-0.3.0/tests/test_v030_cli_integration.py +162 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield/config.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield/detector.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield/guardian.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield/notifications.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield/patterns.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield/redactor.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield.egg-info/dependency_links.txt +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield.egg-info/entry_points.txt +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield.egg-info/requires.txt +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/secretshield.egg-info/top_level.txt +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/setup.cfg +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/tests/test_detector.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/tests/test_logging.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/tests/test_redactor.py +0 -0
- {secretshield-0.2.0 → secretshield-0.3.0}/tests/test_stdout.py +0 -0
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: secretshield
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Detect and redact likely secrets before they reach Python's terminal output or logging system.
|
|
5
|
-
Author:
|
|
6
|
-
License: MIT
|
|
5
|
+
Author: secretshield contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/Sam3360/secretshield
|
|
8
8
|
Project-URL: Repository, https://github.com/Sam3360/secretshield
|
|
9
9
|
Project-URL: Issues, https://github.com/Sam3360/secretshield/issues
|
|
10
10
|
Keywords: security,secrets,redaction,logging,stdout,credentials
|
|
11
11
|
Classifier: Development Status :: 3 - Alpha
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
13
|
Classifier: Programming Language :: Python :: 3
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
15
|
Classifier: Programming Language :: Python :: 3.11
|
|
@@ -266,6 +265,110 @@ secretshield.configure(
|
|
|
266
265
|
|
|
267
266
|
Sensible defaults mean most projects need zero configuration.
|
|
268
267
|
|
|
268
|
+
## Auto-Fix -- moving secrets into `.env`
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
secretshield scan . --fix
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
`--fix` adds an *interactive* repair step on top of the normal scan.
|
|
275
|
+
For each detected secret, SecretShield asks whether to move it into a
|
|
276
|
+
local `.env` file:
|
|
277
|
+
|
|
278
|
+
```text
|
|
279
|
+
Secret 1/1 detected
|
|
280
|
+
File: app.py
|
|
281
|
+
Line: 5
|
|
282
|
+
Detected value: ********
|
|
283
|
+
|
|
284
|
+
Would you like me to move this secret to a local .env file automatically? [y/N]
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
If you confirm, this:
|
|
288
|
+
|
|
289
|
+
```python
|
|
290
|
+
API_KEY = "actual-secret-value"
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
becomes:
|
|
294
|
+
|
|
295
|
+
```python
|
|
296
|
+
import os
|
|
297
|
+
|
|
298
|
+
API_KEY = os.getenv("API_KEY")
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
with the real value moved into `.env` (created if missing, and never
|
|
302
|
+
overwritten -- new variables are only ever appended), `.gitignore`
|
|
303
|
+
updated to exclude `.env` if it isn't already, and `.env.example`
|
|
304
|
+
updated with a blank placeholder (`API_KEY=`, never the real value) so
|
|
305
|
+
you can safely commit the example file.
|
|
306
|
+
|
|
307
|
+
**Auto-Fix is conservative by design.** It only rewrites Python, and
|
|
308
|
+
only lines that are unambiguously a simple assignment --
|
|
309
|
+
`API_KEY = "..."`. Anything less certain -- a value inside a dict, an
|
|
310
|
+
f-string, a function call argument, a non-Python file -- is reported
|
|
311
|
+
but left untouched:
|
|
312
|
+
|
|
313
|
+
```text
|
|
314
|
+
Secret detected, but SecretShield could not safely determine how to
|
|
315
|
+
replace it automatically.
|
|
316
|
+
|
|
317
|
+
No changes were made.
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Every fix is validated after being written (confirming the secret is
|
|
321
|
+
gone from the source and present in `.env`); if anything about a fix
|
|
322
|
+
fails, that file is rolled back to its original content rather than
|
|
323
|
+
left half-modified. `--fix` only prompts in a real interactive
|
|
324
|
+
terminal -- in CI or any non-interactive environment, it makes no
|
|
325
|
+
changes and does not hang waiting for input.
|
|
326
|
+
|
|
327
|
+
## Git pre-commit hook
|
|
328
|
+
|
|
329
|
+
```bash
|
|
330
|
+
secretshield install-hook
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Installs a hook that scans **staged file contents** (not the whole
|
|
334
|
+
working tree, and not what's merely on disk if you've only partially
|
|
335
|
+
staged a file) before every commit, blocking it if a likely secret is
|
|
336
|
+
found:
|
|
337
|
+
|
|
338
|
+
```text
|
|
339
|
+
SecretShield: scanning staged files...
|
|
340
|
+
|
|
341
|
+
✗ Potential secret detected
|
|
342
|
+
|
|
343
|
+
File: config.py
|
|
344
|
+
Line: 14
|
|
345
|
+
Type: API token
|
|
346
|
+
|
|
347
|
+
Commit blocked.
|
|
348
|
+
|
|
349
|
+
Remove the secret from the staged changes and try again.
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
If a `pre-commit` hook already exists, SecretShield never overwrites
|
|
353
|
+
it: the original is backed up to `pre-commit.secretshield-backup` and
|
|
354
|
+
wrapped so both run on every commit. Remove SecretShield's hook (and
|
|
355
|
+
automatically restore any hook it wrapped) with:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
secretshield uninstall-hook
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
## GitHub Actions
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
secretshield github-action
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
Generates `.github/workflows/secretshield.yml`, a workflow that installs
|
|
368
|
+
SecretShield and runs `secretshield scan .` on every push and pull
|
|
369
|
+
request, failing the check if a potential secret is found. Won't
|
|
370
|
+
overwrite an existing workflow file unless you pass `--force`.
|
|
371
|
+
|
|
269
372
|
## Detection methods
|
|
270
373
|
|
|
271
374
|
`secretshield` combines two strategies:
|
|
@@ -292,7 +395,16 @@ secretshield/
|
|
|
292
395
|
├── config.py # configure()/get_config(): runtime settings
|
|
293
396
|
├── notifications.py # safe, secret-free console/desktop warnings
|
|
294
397
|
├── guardian.py # stdout/stderr wrapping + logging record-factory hook
|
|
295
|
-
|
|
398
|
+
├── cli.py # `secretshield` command-line entry point
|
|
399
|
+
├── autofix/ # interactive scan --fix
|
|
400
|
+
│ ├── fixer.py # orchestration, atomic writes, rollback
|
|
401
|
+
│ ├── python.py # ast-based safe-assignment detection
|
|
402
|
+
│ ├── env.py # safe .env / .env.example handling
|
|
403
|
+
│ └── gitignore.py # ensures .env stays out of Git
|
|
404
|
+
├── git/ # pre-commit hook install/uninstall
|
|
405
|
+
│ └── hooks.py
|
|
406
|
+
└── github/ # GitHub Actions workflow generation
|
|
407
|
+
└── actions.py
|
|
296
408
|
```
|
|
297
409
|
|
|
298
410
|
Key design points:
|
|
@@ -353,6 +465,19 @@ local exposure during development and debugging — not as a substitute
|
|
|
353
465
|
for proper secret management (vaults, environment isolation, `.gitignore`
|
|
354
466
|
discipline, secret scanning in CI, least-privilege credentials, etc.).
|
|
355
467
|
|
|
468
|
+
**Auto-Fix (`--fix`)** only rewrites Python, and only when a line is
|
|
469
|
+
unambiguously a simple `NAME = "value"` assignment (checked via Python's
|
|
470
|
+
own `ast` module, not a regex). Secrets inside dicts, f-strings,
|
|
471
|
+
function-call arguments, or any other language are reported but never
|
|
472
|
+
automatically rewritten — you'll need to fix those by hand.
|
|
473
|
+
|
|
474
|
+
**The pre-commit hook** invokes the `secretshield` command by name, so
|
|
475
|
+
it needs to be resolvable on `PATH` at commit time. If you installed
|
|
476
|
+
SecretShield inside a virtual environment, make sure that environment
|
|
477
|
+
is active (or `secretshield` is otherwise on `PATH`) whenever you run
|
|
478
|
+
`git commit` — otherwise the hook itself will fail to run rather than
|
|
479
|
+
silently skip the scan.
|
|
480
|
+
|
|
356
481
|
## Security considerations
|
|
357
482
|
|
|
358
483
|
* secretshield performs **no network calls** and collects **no
|