Secrets in ML Apps: Scan, Move Out, Rotate (Python)
I planted 5 made-up secrets in a made-up ML app; a two-rule scanner found 4, missed 1 and raised 1 false alarm.
Video #163 ยท MLOps and deployment
Steps in the video
- 0:00 5 made-up secrets planted: my scanner found 4, missed 1, and raised 1 false alarm
- 0:29 The idea
- 0:50 Setup
- 1:09 The made-up app
- 1:35 A notebook and the history
- 1:56 Two rules
- 2:25 Score the scanner
- 3:00 Keep values out of the code
- 3:19 Where the values come from
- 3:51 Clean the notebook
- 4:27 Rotate, with narrow scopes
- 5:15 What this does not show
- 5:40 Mistakes to avoid
- 6:10 My take and next steps
- 6:26 Recap
Files
- fixed.py (32 lines)
- planted.py (37 lines)
- provider.py (30 lines)
- run.py (60 lines)
- scan.py (19 lines)
Tested with
Python 3.12.15
What this does not show
A made-up app with made-up keys built at run time; a two-rule scanner tuned to those keys (no real scanner is run); a text file stands in for git history and a dictionary for the key service; no secret manager is used.
Sources
- https://12factor.net/config
- https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
- https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository
- https://docs.github.com/en/code-security/concepts/secret-security/secret-scanning
Learning IT by Example.