Guidance for coding agents working in this repository.
Kingfisher is an open-source secret scanner and live secret validator written in Rust by MongoDB. It detects, validates, and helps remediate leaked API keys, tokens, and credentials across code repositories, git history, and integrated platforms.
Key capabilities:
- Secret detection with 950 built-in rules (826 standalone detectors + 124 dependent rules; 485 standalone detectors include live validation as of 2026-05-04)
- Live credential validation against provider APIs
- Direct secret revocation from CLI
- Blast radius mapping (AWS, GCP, Azure, GitHub, GitLab, Slack)
- Output formats: TOON, JSON, SARIF, interactive HTML
- Platform integrations: GitHub, GitLab, Azure Repos, Bitbucket, Gitea, Hugging Face, S3, GCS, Docker, Jira, Confluence, Slack, Microsoft Teams, Postman
- Applies to the entire repository rooted at this file.
- If a deeper
AGENTS.mdexists in a subdirectory, that file takes precedence for its subtree.
src/: main binary sourcesrc/cli/commands/: CLI command implementationssrc/matcher/: pattern matching enginesrc/scanner/: core scanning logicsrc/parser/: language-aware context verification (lightweight lexers,tlfor HTML,cssparserfor CSS)src/reporter/: TOON/JSON/SARIF/HTML report generationsrc/access_map/: access mapping analysiscrates/kingfisher-core/: shared types and core logiccrates/kingfisher-rules/: rule loading and rule datacrates/kingfisher-rules/data/rules/: YAML detection rulescrates/kingfisher-scanner/: embeddable high-level scanning APIcrates/kingfisher-scanner/src/validation/: shared typed and raw credential validatorstests/: integration/e2e teststestdata/: test fixturesdocs/: user and developer docsdocs/viewer/: static hosted/local report viewer assetsdocs-site/: MkDocs documentation sources, overrides, and generated site outputvendor/vectorscan-rs/: vendored vectorscan bindings
- Shell assumptions in build scripts:
bashwithset -eu -o pipefail - Workspace minimum Rust version:
1.94(Cargo.toml) make check-rustenforces>= 1.94.1for build targets- Windows Makefile targets (
windows-x64,windows-arm64) expect an MSYS2 environment withpacmanavailable. - Prefer
rgandrg --filesfor fast code/file search.
- Development build:
cargo build - Release build:
cargo build --release - Tests (preferred wrapper):
make tests - Tests (direct):
cargo test --workspace --all-targets - Nextest (if installed):
cargo nextest run --workspace --all-targets - Format:
cargo fmt --all - Lint:
cargo clippy --workspace --all-targets -- -D warnings - Clean:
make clean
- Host convenience:
make linuxmake darwinmake windows(Windows host; buildswindows-x64andwindows-arm64)
- Explicit platform archives:
make linux-x64make linux-arm64make darwin-x64make darwin-arm64make windows-x64(Windows host only; MSYS2/MinGW flow)make windows-arm64(Windows host only; MSYS2 clangarm64 flow)
- Ubuntu bare-metal (Zig/cargo-zigbuild flow):
make ubuntu-x64make ubuntu-arm64
- Rust formatting is defined in
rustfmt.toml(max_width = 100, 4-space indentation, Unix newlines, reordered imports). - Keep edits minimal and scoped; preserve existing conventions in touched files.
- Prefer clear, maintainable fixes over broad refactors unless requested.
- Rules are YAML-driven and loaded from
crates/kingfisher-rules/data/rules/. - Allocator feature flags are in root
Cargo.toml:use-mimalloc(default)use-jemallocsystem-alloc
- Validation modules live in
crates/kingfisher-scanner/src/validation/; optional validation feature sets are defined incrates/kingfisher-scanner/Cargo.toml(e.g.,validation-raw,validation-aws,validation-gcp,validation-database,validation-all).
- Default rule: define validation logic in rule YAML (
validation:block), especiallyHttporGrpc, not Rust code. - Typed validators are first-class schema variants (
AWS,AzureStorage,Coinbase,GCP,MongoDB,MySQL,Postgres,Jdbc,JWT) for stable, reusable validation families. - Raw validators use
validation: { type: Raw, content: <name> }and are the ad-hoc exception path for provider-specific or protocol-specific validation that cannot be expressed reliably in YAML alone. Implement them incrates/kingfisher-scanner/src/validation/raw.rs. - Treat Rust validation additions as rare; prefer extending YAML-based validation first.
- If a Rust exception path is required, prefer adding a raw validator before introducing a new typed validator. Add a new typed validator only when it represents a reusable schema-level validation family.
- Do not convert existing typed validators to
Rawjust for consistency. - For rules that include validation, add a
revocation:section whenever the third-party API safely supports revocation.
- Add a detection rule: follow the workflow below and validate with relevant tests.
- Add a CLI command: implement under
src/cli/commands/and register in the CLI command wiring. - Add a validator (rare exception path): implement it in
crates/kingfisher-scanner/src/validation/, preferraw.rsfor one-off provider flows, and wire the narrowest feature/dependencies incrates/kingfisher-scanner/Cargo.tomlonly when YAML validation cannot express the required logic. - Update docs-site rule counts: use
uv run '/Users/mickg/src/kingfisher/data/default/rule_cleanup/count_rules.py'and updatedocs-site/overrides/plusdocs-site/mkdocs.ymlto match the reported totals before rebuilding the docs site.
Use this when creating or updating rules in crates/kingfisher-rules/data/rules/.
- Pick a nearby reference rule file in the same provider family and copy its structure.
- Define a stable rule id (
id, prefixed withkingfisher.) and detection regex (pattern) underrules:. - Include
examplesthat must match. These can be tested withcargo test check_rulesorkingfisher rules check --rules-path crates/kingfisher-rules/data/rules/slack.yml --load-builtins=false --no-update-check - Set guardrails:
min_entropyfor high-entropy tokens.pattern_requirements(e.g.,min_digits,min_uppercase,min_lowercase,min_special_chars,ignore_if_contains) when format constraints are known.pattern_requirements.checksumwhen provider formats include check digits/signatures.
- Add
validationonly when a reliable provider/API check exists. - Put validation in YAML by default. If YAML cannot express the check, use an existing typed validator or
type: Rawexception path; add new Rust validator logic only for rare, justified cases. - Add
revocationwhen the provider API supports safe revocation and the flow is well understood. - If a rule needs context from another match (for example ID + secret pair), use
depends_on_ruleand considervisible: falseon the helper rule. - Verify locally:
cargo test -p kingfisher-rulescargo test --workspace --all-targetskingfisher scan ./testdata --rule <rule-family-or-id> --rule-stats- If validation is implemented:
kingfisher validate --rule <rule-id> <token-or-secret>
- Confidence for rules should be set at
confidence: medium - The
patternfield must contain a valid Hyperscan/Vectorscan regular expression. Lookahead and lookbehind assertions aren’t supported. Because inefficient or overly broad regex can degrade performance, patterns should be as specific as possible and written to minimize false positives.- Writing
pattern: Start with(?x)(free-spacing). Use one unnamed capture( ... )around the secret—it becomes{{ TOKEN }}. Use\bword boundaries and(?: ... )for non-capturing structure. For flexible context between keywords and token, use(?:.|[\n\r]){0,N}?. Hyperscan doesn't support(?=...); usepattern_requirements(e.g.min_digits) instead.
- Writing
docs/RULES.md:Rule Schemafor required/optional fieldsCharacter Requirementsforpattern_requirements,ignore_if_contains, andchecksumTemplating with Liquidfor request signing/transformsMulti-Step Revocationfor complex revoke flowsWriting Custom Rulesand examples for best practices
- Do not revert user-authored or unrelated in-progress changes.
- Prefer targeted patches.
- After changes, run the narrowest relevant tests first, then broader checks when practical.
- If validation commands cannot be run, report exactly what was skipped and why.
- Prefer
kingfisher scan --format toonwhen invoking Kingfisher from an LLM or agent workflow; keepprettyfor interactive human CLI use unless the task explicitly calls for a different format. - After markdown/doc changes, verify local documentation links when practical.
- After
docs-site/source changes, rebuild withdocs-site/.venv/bin/mkdocs build -f docs-site/mkdocs.ymlwhen practical so checked-in generated output stays in sync.
docs/USAGE.mddocs/ADVANCED.mddocs/ARCHITECTURE.mddocs/ACCESS_MAP.mddocs/DEPLOYMENT.mddocs/RULES.mddocs/INSTALLATION.mddocs/INTEGRATIONS.mddocs/LIBRARY.mddocs/PYPI.md