forked from mirrors/kingfisher
6.2 KiB
6.2 KiB
AGENTS.md
Guidance for coding agents working in this repository.
Scope
- Applies to the entire repository rooted at this file.
- If a deeper
AGENTS.mdexists, that file takes precedence for its subtree.
Project
Kingfisher is a Rust secret scanner, live credential validator, revocation helper, and access-map tool. It scans repositories, git history, local files, archives, cloud storage, source-host artifacts, Docker images, and collaboration-platform exports.
Key Paths
src/: main CLI binary and application code.src/cli/commands/: CLI command definitions and wiring.src/scanner/: scan orchestration, input enumeration, repository/artifact fetching, validation phase.src/matcher/: pattern matching, captures, filtering, deduplication.src/reporter/: TOON, JSON, JSONL, SARIF, BSON, HTML, and pretty output.src/access_map/: blast-radius and permission mapping.crates/kingfisher-core/: shared core types.crates/kingfisher-rules/: rule schema, rule loading, and bundled rule data.crates/kingfisher-rules/data/rules/: YAML detection rules.crates/kingfisher-scanner/: embeddable scanning API and shared validators.tests/andtestdata/: integration tests and fixtures.docs/,docs/viewer/,docs-site/: docs, report viewer assets, and generated MkDocs site.vendor/vectorscan-rs/: vendored Vectorscan bindings.
Toolchain
- Workspace minimum Rust version is
1.94inCargo.toml;make check-rustenforces>= 1.94.1for build targets. - Rust formatting is defined by
rustfmt.toml(max_width = 100, 4 spaces, Unix newlines, reordered imports). - Build scripts assume
bashwithset -eu -o pipefail. - Windows Makefile targets expect MSYS2 with
pacman.
Common Commands
- Build:
cargo build - Release build:
cargo build --release - Preferred test wrapper:
make tests - Direct tests:
cargo test --workspace --all-targets - Nextest:
cargo nextest run --workspace --all-targets - Format:
cargo fmt --all - Lint:
cargo clippy --workspace --all-targets -- -D warnings - Clean:
make clean
Workflow Expectations
- Keep edits minimal, targeted, and consistent with touched code.
- Do not revert user-authored or unrelated in-progress changes.
- Prefer clear fixes over broad refactors unless requested.
- Run the narrowest relevant tests first; run broader checks when practical.
- If a validation/build command cannot be run, state exactly what was skipped and why.
- Prefer
kingfisher scan --format toonfor agent/LLM workflows; useprettyonly when human-interactive output is explicitly desired. - 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 generated output stays in sync.
Architecture Notes
- Detection rules are YAML-driven and loaded from
crates/kingfisher-rules/data/rules/. - Allocator feature flags live in root
Cargo.toml:use-mimallocdefault,use-jemalloc, andsystem-alloc. - Optional validator feature sets live in
crates/kingfisher-scanner/Cargo.toml. - Validation modules live primarily in
crates/kingfisher-scanner/src/validation/andsrc/validation.rs.
Validation And Revocation Policy
- Default to YAML validation (
validation:), especiallyHttporGrpc; do not add Rust validation unless YAML cannot express the flow reliably. - Typed validators are schema-level reusable families:
AWS,AzureStorage,Coinbase,GCP,MongoDB,MySQL,Postgres,Jdbc, andJWT. - Raw validators use
validation: { type: Raw, content: <name> }and are implemented incrates/kingfisher-scanner/src/validation/raw.rsfor provider-specific exceptions. - If Rust validation is unavoidable, prefer a raw validator before introducing a new typed validator.
- Do not convert existing typed validators to
Rawfor consistency alone. - For rules with validation, add
revocation:when the third-party API safely supports revocation.
Rule Authoring
Use this when creating or updating rules in crates/kingfisher-rules/data/rules/.
- Read
docs/RULES.mdbefore non-trivial rule/schema work. - Start from a nearby provider-family rule and preserve the existing YAML style.
- Use a stable
kingfisher.<provider>...rule id and setconfidence: medium. - Write a valid Hyperscan/Vectorscan regex. Lookahead and lookbehind are not supported.
- Start
patternwith(?x), use one unnamed capture around the secret for{{ TOKEN }}, and use non-capturing groups for structure. - Prefer specific token formats and provider context; avoid broad generic patterns.
- Use
min_entropy,pattern_requirements,ignore_if_contains, and checksum requirements when format constraints are known. - Include
examplesthat must match. - Use
depends_on_rulefor multi-part credentials; considervisible: falsefor helper rules. - Add YAML validation and revocation only when reliable and safe.
Rule Verification
- Rule crate:
cargo test -p kingfisher-rules - Rule syntax/check path:
kingfisher rules check --rules-path crates/kingfisher-rules/data/rules/<file>.yml --load-builtins=false --no-update-check - Scan fixture/corpus:
kingfisher scan ./testdata --rule <rule-family-or-id> --rule-stats - Validator check:
kingfisher validate --rule <rule-id> <token-or-secret> - Broad regression when practical:
cargo test --workspace --all-targets
Common Tasks
- Add a detection rule: follow the rule authoring and verification sections above.
- Add a CLI command: implement under
src/cli/commands/and register it in CLI wiring. - Add a validator: prefer YAML first; if Rust is required, use
raw.rsand the narrowest feature/dependency wiring. - Update docs-site rule counts: run
uv run '/Users/mickg/src/kingfisher/data/default/rule_cleanup/count_rules.py', updatedocs-site/overrides/anddocs-site/mkdocs.yml, then rebuild the docs site when practical.
Docs Pointers
- Usage:
docs/USAGE.md,docs/ADVANCED.md,docs/INTEGRATIONS.md - Rules:
docs/RULES.md - Architecture:
docs/ARCHITECTURE.md,docs/ACCESS_MAP.md - Deployment/install:
docs/INSTALLATION.md,docs/DEPLOYMENT.md,docs/PYPI.md - Library API:
docs/LIBRARY.md