#163 MLOps and deployment 6.8 min
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.
Widen the key's scopes
Copy the code folder first. In run.py in the rotate branch change keys.issue({"predict"}) to keys.issue({"predict", "delete_model"}). Predict what the second line will say, then run python run.py rotate. On my machine delete_model was allowed for key-1, which is why the video gives the app only the predict scope.
A hint
Compare with the video, where key-1 is refused delete_model.
Remove the false alarm
In scan.py change {8,} to {20,} in the named rule. Predict which line stops being flagged, then run python run.py scan. On my machine the false alarms fell to 0 while the scanner still found 4 and missed 1.
A hint
The tokenizer value is short compared with the keys.
Rotate to a different scope
In run.py in the rotate branch change the rotate call so the new key gets {"delete_model"} instead of {"predict"}. Predict what key-2 can do afterwards, then run python run.py rotate. On my machine the last line said key-2, predict: refused (not in scope).
A hint
Scopes are chosen when a key is issued.
Catch the missed key
The scanner misses the Bearer header. In scan.py add a third rule to RULES for the word Bearer followed by at least 20 letters or digits, then run python run.py scan. On my machine the result became found 5, missed 0, false alarms 1. Then decide whether such a rule would also catch real keys, remembering that the video's rules only fit its own made-up values.
A hint
Use a raw string such as r"Bearer\s+[A-Za-z0-9]{20,}".
These tasks are for you to try on your own machine. Nothing is checked or saved.
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.
Up next in MLOps and deployment
More in MLOps and deployment
Related videos
- #90 Stop Leaking API Keys: Build a Secret Scanner in Python AI security and governance
- #233 Delegated Authority: Let an AI Agent Act for a User, Safely Enterprise architecture and AI agents
- #92 Excessive Agency: Limit What Your AI Agent Can Do AI security and governance
- #157 Model Registry by Hand: Versions, Promote, Roll Back MLOps and deployment