carlos / platform Public

Gitleaks CI step: digest allowlist design open

LLM

Gitleaks as a CI step, split out of branch race-helpers (Go code-health batch 3, #1123; Paul's decision 2026-11-18 after stopping rule 2).

The draft on race-helpers ran gitleaks v8.30.1 over tracked files with .gitleaks.toml. Default rules report 211 findings today, none real: 151 sha256 source digests in census tests and implementation/always-awake-consumers.json, 25 fake credentials in test files, 9 fake instance keys, 8 RFC 6455 sample keys, 7 prose or code misreads, 6 fake Stripe keys, 2 MinIO test passwords, 2 registrar fixture codes, 1 configseal test key.

Astra rejected the digest allowlist twice, for one reason: an allowance must separate an approved digest from a credential.

  1. The first version allowed any 10 to 64 hex value in the census files.
  2. The second matched the whole line, but the census entry's second field accepted arbitrary text, so "api_key=<hex>" there was hidden. The chunk-boundary pattern for plan9b8census_test.go had the same hole, and its path covered every census test.

The design to build:

  • Limit the second census field to valid unit names.
  • Replace the chunk-boundary pattern with an exact allowance for the one known digest fragment, scoped to its exact file.
  • Add a test that plants a synthetic key in every field of a census entry and in the JSON checklist, and requires the scan to fail for each.
Agent notes

Draft config from race-helpers (not safe as it stands: the census line patterns accept arbitrary text in the second field). Start the follow-up from here.

# gitleaks' default rules, less the values this repository commits on
# purpose. `make gitleaks` (.amadan/ci.d/80-gitleaks) scans the working
# tree's tracked files with it; the Makefile says why not the history.
#
# Every allowance names its values, anchored, so a value that merely
# contains one is still found; only the source digests go by their shape:
# the whole line must be a digest entry, in the files that hold them. Where a value only belongs in some files,
# the allowance is scoped to them (condition AND: a path and a value), so
# the same value anywhere else still fails the gate. Nothing is allowed by
# fingerprint in .gitleaksignore: a fingerprint names a commit, and this
# scan reads no commits.
#
# AN ALLOWANCE WITH `paths` MUST NAME `targetRules`. In `gitleaks dir`
# (v8.30.1), a global allowance's paths skip the whole file before it is
# read, whatever its condition says: an AND of a path and a value allowed
# every secret in every file the path matched. One with targetRules is
# moved onto those rules, where the AND holds and the rest of the file is
# still scanned.
#
# A new finding is fixed, not allowed, unless it is a value that has to be
# committed. Then add it here, in the group that fits, with its reason.
[extend]
useDefault = true

# sha256 digests the census pins: of a function's source, in
# internal/provision's *_census_test.go layers. A hash of code that is
# itself in this repository; generic-api-key matches it because the field
# before it names a record key. Matched against the whole line, so only a
# complete census entry passes: a hex credential on any other line of these
# files, an `api_key = "..."` above all, is still found.
#
# The second pattern is the same entry cut short. gitleaks reads a big file
# in chunks, and in plan9_b8_census_test.go one boundary falls inside a
# digest. For a finding on a chunk's unterminated last line, gitleaks hands
# over the whole chunk as the "line", so this pattern holds only the chunk's
# last line to the entry's shape. Older layers are frozen, so that boundary
# does not move.
[[allowlists]]
description = "census entries' source digests"
targetRules = ["generic-api-key"]
condition = "AND"
regexTarget = "line"
paths = ['''^internal/provision/[^/]+_census_test\.go$''']
regexes = [
  '''^\s*(?:censusEntry)?\{"[A-Za-z0-9_./-]+\.go", "[^"\n]+", "[a-z-]+", "(?:key|sel):[A-Za-z]+(?:,(?:key|sel):[A-Za-z]+)*", "[0-9a-f]{64}"\},\s*$''',
  '''\n[ \t]*(?:censusEntry)?\{"[A-Za-z0-9_./-]+\.go", "[^"\n]+", "[a-z-]+", "(?:key|sel):[A-Za-z]+(?:,(?:key|sel):[A-Za-z]+)*", "[0-9a-f]{10,63}$''',
]

# The same digests in a design checklist's source_hashes: a Go file's path,
# then the sha256 of that file. Whole line again, for the same reason.
[[allowlists]]
description = "design checklist's source digests"
targetRules = ["generic-api-key"]
condition = "AND"
regexTarget = "line"
paths = ['''^implementation/always-awake-consumers\.json$''']
regexes = ['''^\s*"[A-Za-z0-9_./-]+\.go": "[0-9a-f]{64}",?\s*$''']

# Fake credentials typed into tests, each recognisable as one: a counting
# run (0123456789abcdef), a word (SecretValue, SENTINEL, nope), a test's
# own label. The Stripe keys exist to test that the console tells a live
# key from a test key and a restricted key from a secret one, so they must
# keep Stripe's prefixes. Three are 64-hex values: 9f86d081... is
# sha256("test"), fd61a03a... a second stand-in for an HMAC, and
# c7aff5eb... the callback signature key derived from the golden vector's
# fixed master, "master-fixed-for-the-vector". Test files only: the same
# value in production code is still found.
[[allowlists]]
description = "fake credentials in tests"
targetRules = ["generic-api-key", "stripe-access-token"]
condition = "AND"
paths = ['''_test\.go$''']
regexes = [
  '''^rk_test_51SecretValue$''',
  '''^rk_live_51SecretValue$''',
  '''^sk_test_51SecretValue$''',
  '''^rk_live_51AbCdEfGhIjKlMnOpQrStUv$''',
  '''^tok-flagship-2$''',
  '''^tok-second-64hex$''',
  '''^tok_SECRET_123$''',
  '''^tok-0123456789abcdef0123456789abcdef$''',
  '''^SES_SECRET=s3kr1t$''',
  '''^SECRET-SENTINEL-7f3a$''',
  '''^cdk1\.bab\.titogo\.0123456789abcdef\.$''',
  '''^cdk1\.bae\.titogo\.nope$''',
  '''^carlos-0123456789abcdef0123456789abcdef-1$''',
  '''^0123456789abcdef0123456789abcdef$''',
  '''^0123456789abcdefghij0123456789abcdefghijkl$''',
  '''^3f9a0c1d2e4b5a6978877665544332211$''',
  '''^AbCd12_EfGh34_IjKl56_MnOp78$''',
  '''^ba9876543210$''',
  '''^PLAN14_E45_CONTAINED$''',
  '''^apps/bab/other/instances/$''',
  '''^9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08$''',
  '''^fd61a03af4f77d870fc21e05e7e80678095c92d808cfb3b5c279ee04c74aca13$''',
  '''^c7aff5eb65835639b68c63a226767768ac2049fe0b57ab83844691ae5cca1d17$''',
]

# The fake instance key the instance-key tests and their plans share
# (note its tail, ...bC6dF5gH0iJ1kA=: typed, not generated). Allowed in
# tests and docs alike, because the plans quote the tests.
[[allowlists]]
description = "fake instance key shared by tests and plans"
regexes = ['''^q\+/Zk3vJ0aW1Yx9sR7tUe2oPl4mN8bC6dF5gH0iJ1kA=$''']

# RFC 6455's sample Sec-WebSocket-Key ("the sample nonce", base64), the
# one every WebSocket handshake test and its spec quotes. A nonce is not a
# secret even when it is not the RFC's.
[[allowlists]]
description = "RFC 6455 sample WebSocket key"
regexes = ['''^dGhlIHNhbXBsZSBub25jZQ==$''']

# Committed fixtures. configseal_vectors.json is the cross-language
# vector set sealed by configseal.js and opened by Go; its key is a
# throwaway minted for the vectors and protects nothing (the file says so,
# in the key's own name). lookup.json is a recorded registrar response
# with its domain auth code replaced by a counting run. Each value in its
# own file only.
[[allowlists]]
description = "configseal test-only vector key"
targetRules = ["generic-api-key"]
condition = "AND"
paths = ['''^internal/console/testdata/configseal_vectors\.json$''']
regexes = ['''^xKbVxY32zPtWRkhfwugpfIdsamLLebvaWKnV9WLWQ48=$''']

[[allowlists]]
description = "registrar fixture's placeholder auth code"
targetRules = ["generic-api-key"]
condition = "AND"
paths = ['''^internal/registrar/openprovider/testdata/lookup\.json$''']
regexes = ['''^1a2b3c4d5e6f$''']

# The password 30-minio-contract gives a user of the MinIO it starts on
# loopback for one job and then deletes; the plan that wrote the step
# quotes it.
[[allowlists]]
description = "throwaway MinIO user in the contract step"
targetRules = ["generic-api-key"]
condition = "AND"
paths = [
  '''^\.amadan/ci\.d/30-minio-contract$''',
  '''^docs/superpowers/plans/2026-10-22-db-region-forward-plan-2-query\.md$''',
]
regexes = ['''^dbfukboxsecret1$''']

# Not values at all: generic-api-key matching the word after "key" in code
# comments and prose (a function name, a header, a review's heading, a
# CLI flag in a list of flags, an env line in a README), and a bucket name
# whose number is an AWS account ID, which identifies and does not
# authenticate.
[[allowlists]]
description = "prose and code the generic rule reads as a key"
regexes = [
  '''^ed25519\.Verify$''',
  '''^if-none-match=$''',
  '''^retry/duplicate$''',
  '''^CARLOS_REGION=ie$''',
  '''^--enable-primary-ipv6$''',
  '''^carlos-flagship-271376211898$''',
]
LLM

Parked on branch gitleaks-1251 (not merged). Astra's round 3 of 3 came back NOT READY with two P1s, and a fourth round needs Paul's go (AGENTS.md stopping rule 1). Findings: docs/superpowers/reviews/FINDINGS-gitleaks-1251-R3.md on the branch.

  1. A digest-shaped entry is accepted without proof that its value is a checked digest. A real 64-hex key in the checklist's sourcehashes, on a matching line outside sourcehashes, or in an unused census declaration passes the gate; no test validates those values.
  2. The gate's sentinel file overwrites a tracked file of the same name before the scan, so a credential committed under that name would never be scanned.

The second is a small fix. The first is the same fault family as the two earlier rounds: the shape of a line can't prove a value is a digest.

Options for whoever picks this up:

  • Scan everything except the census test files and the checklist, by exact path, and state plainly that those files are not scanned. Simple and honest.
  • List every approved digest exactly. Strict, but each census change must also update the list.
  • Have the gate verify each digest against the census inventory and the checklist's source revision. Most complete, and the most work.

Recommendation: the first option, with the sentinel fix.

Paul, 2026-11-19 06:3xZ: OK to a fourth round. The build takes the recommended option: exclude the census test files and the checklist by exact path, plus the sentinel fix, on gitleaks-1251 (7aac4320). Astra round 4 then decides; there is no fifth round.

MERGED as 12158f4 (2026-11-19 07:2xZ). Astra round 4 READY with no findings; branch CI green on every step including the new 80-gitleaks. What ships: a pinned gitleaks scan of every tracked file after a self-test that plants keys; 26 digest files left out by exact path (scripts/gitleaks-gate/notscanned.go), stated in the config, the step, the Makefile, the README and AGENTS.md; the sentinel written under a fresh random name with O_EXCL. Known limits, accepted: a credential in one of the 26 listed files is not found; a new census file whose digests gitleaks flags turns the step red until someone checks and lists its exact path. CI-only change: no release needed.