feat: add scrub command to remove credentials from AI CLI session logs#24
feat: add scrub command to remove credentials from AI CLI session logs#24c0tton-fluff wants to merge 9 commits intoboostsecurityio:mainfrom
Conversation
7ec595d to
b881fff
Compare
- Run() and FindEligibleFiles() accept context.Context as first param (CTX-1/CTX-2) - Replace context.Background() with caller's context in errgroup - Extract logger via zerolog.Ctx(ctx) instead of passing via RunInput struct - Log filepath.Walk errors instead of silently swallowing them
|
Pushed a follow-up commit fixing three issues from code review:
All tests pass with |
|
Pushed UX overhaul after having a quick chat with François before Monday's review.
All tests pass with -race, linter clean. Hope all is well and you had a good weekend! |
| @@ -0,0 +1,351 @@ | |||
| // Copyright (C) 2026 boostsecurity.io | |||
There was a problem hiding this comment.
@c0tton-fluff this is reimplementing a lot of the existing flow that bagel uses to detect secrets in those locations. We should leverage existing scanning capabilities instead of reimplementing everything like this
There was a problem hiding this comment.
Hey @SUSTAPLE117
Apologies for late reply, it has been a super busy week. I am looking into it and realising my mistake at the original approach. I will refactor and rework it so it is much, much better and I hope to contribute in best way! 💪 🧠
There was a problem hiding this comment.
@c0tton-fluff no worries your contribution is very much appreciated!
Addresses PR boostsecurityio#24 feedback: scrubber no longer reimplements file discovery and secret detection. Each detector now implements an optional Redactor interface. The scrubber becomes a thin orchestration layer that calls registry.RedactAll(). - Add Redactor interface + RedactAll to detector.Registry - Add Redact() method to all 8 existing detectors - Create SplunkTokenDetector (new, covers splunkd_ tokens) - Extend CloudCredentialsDetector with AWS session/secret patterns - Delete pkg/scrubber/patterns.go (patterns now live in detectors) - Refactor scrubber to accept *detector.Registry - Wire up cmd/bagel/scrub.go with newScrubRegistry()
pkg/scrubber/scrubber.go
Outdated
| // FindEligibleFiles walks known AI CLI paths and returns files older | ||
| // than graceMins minutes. Files modified within the grace period are | ||
| // skipped to avoid interfering with active sessions. | ||
| func FindEligibleFiles(ctx context.Context, graceMins int) ([]string, error) { |
There was a problem hiding this comment.
Bagel already builds when scanning a File Index of all the interesting files we look for. It's based on that file index that detections are done when running the scanning so you don't need to reimplement this here. The redact command should piggy back on the existing file index and scanning
pkg/scrubber/scrubber.go
Outdated
| // sessionDirs lists known AI CLI session log and shell history | ||
| // locations relative to $HOME. An empty RelPath means files live | ||
| // directly in $HOME (matched by name, not walked recursively). | ||
| var sessionDirs = []sessionDir{ |
There was a problem hiding this comment.
Those should be added to the file index
pkg/scrubber/scrubber.go
Outdated
|
|
||
| // Scan finds eligible files and counts what would be redacted. | ||
| // It never writes to disk. | ||
| func Scan(ctx context.Context, input ScanInput) (ScanResult, error) { |
There was a problem hiding this comment.
As mentionned the existing scanning in Bagel should be leveraged to do this. The scrubbing should be something done after file index is built and bagel has scanned for findings and then we scrub the values found per finding that can be scrubbed
|
On it! I will rewrite what is needed. 😃 |
|
@c0tton-fluff lgtm just need to fix the test on windows |
Summary
Usage
bagel scrub # dry run
bagel scrub --confirm # apply redactions
bagel scrub --confirm --grace-minutes 0 # include recent files
bagel scrub --file --confirm # single file
Files added
Test plan
Closes #22