forked from mirrors/kingfisher
3.5 KiB
3.5 KiB
AGENTS.md
Rule-authoring instructions for this directory.
Scope
- Applies to
crates/kingfisher-rules/data/rules/and all files under it. - This file overrides broader AGENTS guidance for rule-writing tasks in this subtree.
Goal
- Add or update YAML detection rules with high precision, low false positives, and safe remediation support.
Rule File Conventions
- Keep provider rules in provider-named files (for example
github.yml,openai.yml). - Prefer lowercase filenames with
.yml. - Keep rule IDs stable and unique. Prefer
kingfisher.<provider>.<number>unless a descriptive suffix is already established for that provider. - Reuse nearby provider patterns/styles instead of inventing new structure.
Required Rule Shape
Each rule entry should define:
nameidpatternmin_entropy(default to 3.0)confidence(default to medium)examples(at least one realistic positive example)
Strongly recommended fields:
pattern_requirements(for extra filtering)references
Pattern Quality Rules
- Prefer specific anchors/prefixes and provider context over broad generic regex.
- Use
pattern_requirementsto enforce quality constraints (min_digits,min_uppercase,min_lowercase,min_special_chars,ignore_if_contains,checksum). - Use checksum validation in
pattern_requirements.checksumwhen token formats support it. - Use
visible: falsefor helper/non-secret captures used only by dependent rules. - Use
depends_on_rulefor multi-part credential validation (for example ID + secret).
Validation Policy (Important)
- Default: define validation logic in YAML under
validation:. - Do not move validation logic into Rust unless YAML cannot reliably express it.
- Code-backed validation types (for example AWS, GCP, Coinbase, MongoDB) are notable exceptions and should remain rare.
- For new rules, first attempt
Http/GrpcYAML validation before considering exception paths.
Revocation Policy
- If a rule has validation and the provider API safely supports revocation, add
revocation:in the same YAML rule. - Prefer explicit success criteria in
response_matcher. - Use
HttpMultiSteprevocation when API workflows require pre-fetch/extraction steps. - If revocation is intentionally not supported, document why with an inline YAML comment.
Authoring Workflow
- Choose the target provider file (or add a new provider file if no suitable file exists).
- Copy a structurally similar rule from this directory.
- Implement/adjust
pattern,examples, and filtering (pattern_requirements,min_entropy). - Add YAML
validation(default path). - Add YAML
revocationwhen supported. - Add
referencesfor token format/API behavior. - Verify locally (below).
Local Verification Checklist
- Syntax/load checks:
cargo test -p kingfisher-rules
- Broader regression check:
cargo test --workspace --all-targets
- Behavioral check against sample content:
kingfisher scan ./testdata --rule <rule-family-or-id> --rule-stats
- Validation check (when validation is present):
kingfisher validate --rule <rule-id> <token-or-secret>
Documentation
Read these before complex edits:
docs/RULES.md(schema, pattern requirements, checksum, Liquid, validation/revocation)docs/MULTI_STEP_REVOCATION.mddocs/TOKEN_REVOCATION_SUPPORT.md
Change Discipline
- Keep changes scoped to the specific provider/rule request.
- Do not refactor unrelated rules in the same PR unless explicitly asked.
- Preserve existing YAML style and indentation conventions in this directory.