From ed3644ed32c6de42a179bc2be73d2da20b176614 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Tue, 20 Oct 2026 12:23:40 +0000 Subject: [PATCH] Gates: no credential in the project; GREEN checks its added lines, the final gate the whole tree (M10.2) New plugin/bin/secrets scans for private key blocks and fixed-prefix tokens (AWS, GitHub, GitLab, Slack, Stripe, Google, Anthropic, OpenAI) and reports path:line:kind, never the text. `aloop: allow-secret` exempts a fixture line. Test: scripts/test/supply-chain.test.py cases 3-4. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_015QxyVf3NgwsgRyYpBgDDTC --- docs/ROADMAP.md | 2 +- plugin/agents/final-gate.md | 2 + plugin/agents/green-worker.md | 2 + plugin/bin/README.md | 1 + plugin/bin/_gatelib.sh | 9 ++ plugin/bin/gate-final | 9 +- plugin/bin/gate-green-verify | 5 +- plugin/bin/secrets | 121 ++++++++++++++++++ plugin/pipeline/execution/02-green/persona.md | 2 + .../execution/04-final-gate/persona.md | 2 + scripts/test/supply-chain.test.py | 52 +++++++- 11 files changed, 200 insertions(+), 7 deletions(-) create mode 100755 plugin/bin/secrets diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index dfd3fd4a..f539e5d4 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -29,7 +29,7 @@ original plan. | **M7 — Any host** | v0.18 | Session 9: `HostAdapter`, capability matrix, `.aladdin/config.yaml`, host swap, metrics (§4.9–4.10) | done: `HostAdapter` + `host check` in CI, capability matrix, usage accuracy, `.aladdin/config.yaml` with migration, `host swap`, the full metrics table incl. context-window share (tests: `host-adapter`, `portable-config`, `host-swap`, `metrics`); DeepSeek Harness (`dsh`) as a fourth host, tested on its real runtime (tests: `dsh-plugin`, `dsh-runtime`); a measured live dsh run is open (needs a DeepSeek key) | | **M8 — Aladdin 1.0** | v1.0 | Session 10: `/aladdin` + `aladdin` CLI with aliases, site, measured public runs (§4.11). The rename to aloop shipped early in v0.11.0 | in progress: `bin/aladdin` + `/aladdin` with `aloop`/`agentic` aliases (test: `aladdin-cli.test.py`); natural-language auto-trigger on every host (`intent-trigger`, test: `intent-trigger.test.py`); README reordered product-first; site at `docs/index.html` (Pages switch is the owner's). evidence ledger `docs/evidence/README.md` + `run-summary` (test: `evidence.test.py`). `e2e-live.sh --host codex|opencode` runs the same loop on those hosts (`aloop install ` into the run repo, then `codex exec --json` / `opencode run --format json`; `--dry-run` prints the command; test: `e2e-live-hosts.test.py`). Open: the measured public runs themselves (this environment has no `codex`/`opencode` CLI: run `make e2e-live YES=1 HOST=codex` and `HOST=opencode` on a machine with both and add the rows; reason: a number we cannot measure is not published) Mac release run (2026-10-19) found two bugs Linux CI never sees, both fixed with tests: `stats sprint-close` counted 0 attempts when the project sat behind a symlink (macOS `/var` → `/private/var`; paths are now compared by realpath), and `make conformance` hung when another aloop checkout's `plugin/bin` was ahead on PATH (`ensure-tools --resolve` returned that checkout's shim; any aloop bin dir is now skipped). RED is now verified on any language: a non-cargo repo runs its `standards.md` matrix's test command, and a RED whose tests pass or do not collect is blocked (pytest, `go test`; test: `any-language.test.py`). Reason: the north star is any intent, and RED was dynamically checked only for Rust. GREEN and the final gate now refuse Python/Go/JS skips, and the final gate finds a planned `def`/`func` test (before, it found only `fn`, so every planned Python test blocked). `INTENT=slugify` is the Python fixture. Run 36 (slugify, the first Python run): 11/12, 11m37s, $0.83, 5 wakes, 0 plugin-source reads, 15 blocks (9 caught by self-checks). The sprint merged a correct `slugify` with 13 passing tests and the final gate passed. The one failed check was the fixture's own: bare `pytest` leaves the repo root off `sys.path` (now `python3 -m pytest`). It found two gate bugs that Rust runs had hidden. First, a worker's worktree has no `docs/agents/` (git-ignored), so the gates never found `standards.md` and ran the default Rust matrix: RED blocked 4 times on `cargo fmt`, and in a Rust project a custom matrix was silently swapped for the default. Second, `ctx-symbols conflicts` walked the merged task checkout under `.aladdin/worktrees/` and reported `slugify` as a HIGH duplicate, so the structural reviewer was rejected 4 times. Fixed with tests: the gates read the story's sprint `standards.md` (else this tree, else the main tree), and a non-cargo project with no matrix blocks with a message naming `standards.md`; ctx-symbols skips `.aladdin/`. Run 37 on these fixes: 12/12, 9m42s, $0.69, 1 wake, 11 blocks (7 caught by self-checks). It found that a `standards.md` whose matrix is a table parses empty, so RED blocked 3 times; `gate-standards-cited` now refuses a standards.md with no runnable `## Gate matrix` block (test: `any-language.test.py`). Run 38 (`INTENT=roman`, the first Go run): 12/12, 14m15s, $1.02, 3 wakes, 9 blocks (7 caught by self-checks). It found that the sprint dir's `init.md` had no `type: init` header (the supervisor began it with a dispatch block), so the structural reviewer was blocked 7 times; `aloop budget contract` now writes that header (test: `budget-contract.test.py`). Run 39 on the fix: 12/12, 7m52s, $0.56, 0 init.md blocks. It found that GREEN's default scope let it touch Rust test files only, so a Go GREEN removing RED's `_test.go` shim was blocked 10 times; GREEN now shares RED's any-language test globs (test: `any-language.test.py`). Run 40 on it: 12/12, 13m03s, $0.75, 1 wake, 0 GREEN scope blocks (5 blocks, all caught by self-checks). The structural reviewer's HIGH foundation-poisoning finding in runs 38 and 40 was a false positive: a worker's `selfcheck` resolved a stale 0.11.0 `ctx-symbols` (before the `.aladdin/` exclusion) ahead of the session's current build; `ensure-tools --resolve` now skips a stale own build (test: `ensure-tools.test.py`). RED is verified on JS too (a test file that cannot load what it imports is blocked; test: `any-language.test.py`), and `INTENT=camel` is the JS fixture. Run 41 (camel, the first JS run): 12/12, 6m45s, $0.56, 1 wake, 2 blocks (both RED self-checks refusing a source edit). The loop is now measured on Rust, Python, Go and JS. Run 42 (`INTENT=extend`, the first brownfield intent: add `compare` to a crate whose `parse` already works and is tested): 13/13, 7m11s, $0.67, 2 blocks (both self-check catches); the seed's code and tests were left unchanged and still pass (reason: every earlier fixture started from an empty library, and most real intents land on existing code). Run 43 (`INTENT=modify`: change that existing `parse` to accept a leading `v` and trim whitespace): 13/13, 9m10s, $0.67, 6 blocks, all self-check catches; the change was 3 lines in `parse`, with its signature and seed tests kept. `INTENT=cli` (an application: a wc-like binary tested by running it, checked by running the merged binary) is ready; run 44 (the retry after the usage limit lifted): 13/13, 24m55s, $1.54, 6 blocks (all self-check catches), and the merged binary works. Its cost came from planning: 2 stories and 7 tasks for a small tool, so 7 RED/SCAFFOLD/GREEN cycles and 56 supervisor turns (runs 42–43: 1–2 tasks, 16–30 turns). The planner now sizes tasks up to the budget instead of one per behaviour (reason: per-task cost is a fixed ~8 supervisor turns). Run 45 on it: 3 tasks (from 7), 13/13, 16m22s, $1.07. Its HIGH foundation-poisoning halts were `ctx-symbols` reading a test's `const USAGE` as a duplicate of the binary's; a test constant no longer counts (test: `conflicts.rs`). Run 46 on both fixes: 3 tasks, 13/13, 15m19s, $0.99, no review halt, 6/6 blocks self-check catches. Its 4 `targets` "symbol is not defined" blocks were T3 modifying symbols T2 plans in an existing file; a symbol another target plans now counts (test: `semantic-targets.test.py` case 8). Run 47 on it: 13/13, $1.04, 2 blocks (from 6), no "not defined"; but 5 tasks in 2 stories, so planner task count still varies. The spread is now bounded: before execution, `targets check` refuses two adjacent tasks of one story on the same files with 8 or fewer tests between them (replayed on past plans it would have merged runs 23, 40, 43, 44 and 47 and passed every other; test: `semantic-targets.test.py` case 9). Run 48 on it: 2 tasks, 13/13, $0.76, 25 supervisor turns (run 44: 7 tasks, $1.54, 56). One GREEN self-check block in each of runs 46–48 was a false positive: the Rust suppression grep matched an iterator's `args().skip(1)` (a JS pattern); Rust now checks only `#[ignore]` (also with a reason, which it used to miss) and `cfg(not(test))` (test: `suppression-contract.test.py`). Planner friction next: across runs 36–41 the most frequent block was `targets` "create needs planned_symbol" on a new test file (8); a test-file create now takes it from the task's `tests` (test: `semantic-targets.test.py`). The `gate-validate-artifact` plan.md refusals (4) were the persona's bare `stage: 1`, now quoted and checked (test: `persona-shapes.test.py`). Next: the final-gate block order (3). Running every suite under a locally built bash 3.2 found that the `standards.md` gate matrix was silently replaced by the default Rust matrix (`mapfile` does not exist in bash 3.2). It is fixed and guarded by `bash-portable.test.py`. A `macos` CI job now runs the host tests and the conformance fixtures on macOS (reason: both were found only by hand on the owner's Mac). | | **M9 — Mission layer** | v0.13 | The "Missionary Aladdin Genie" spec (2026-10-17): a human-set mission above goals; fixed roles (research, product testing, state, evaluation, planning, ethics) build a confirmed baseline and a reproducible evaluation layer from user journeys; goals derived from the gap list become Aladdin intents; re-evaluate on a cadence and after each sprint; GA4 usage informs goals and is never a gate; every element has a deterministic check (§4.12). Reason: the owner's mission-driven loop, stacked on Aladdin | in progress: M9.0 core (`aloop mission init / check / approve / status`, sealed mission + approval events, area discovery, test glob; test: `mission-core.test.py`); M9.2 baseline, M9.3 journeys and M9.10 assess/evaluate (`mission-{baseline,journeys,evaluate}.test.py`). Open tracks: M9.1, M9.4–M9.9; the task graph is in §4.12, track notes in `plugin/mission/README.md`; hardened after an adversarial review (ledger records over status fields) | -| **M10 — Agent habitat** | v1.1 | Containment around the gates (§4.13): contained workers, a security and supply-chain gate, fetched content treated as data, one stop for a whole project. Reason: a 2026-10-20 comparison with Replit's "agent habitat" (orchestration, error recovery, safety and sandboxing, networking, identity) found aloop strong on orchestration, recovery and gates but missing containment | in progress: M10.2 dependency half done: GREEN refuses a dependency added to a manifest (Cargo.toml, package.json, requirements*.txt, pyproject.toml, go.mod) that the approved plan does not name (`bin/deps`; test: `supply-chain.test.py`). Next: M10.2 secret scan and dependency audit in the final gate's matrix; M10.1, M10.3, M10.4 planned; plan approval as a gate is M0.9 | +| **M10 — Agent habitat** | v1.1 | Containment around the gates (§4.13): contained workers, a security and supply-chain gate, fetched content treated as data, one stop for a whole project. Reason: a 2026-10-20 comparison with Replit's "agent habitat" (orchestration, error recovery, safety and sandboxing, networking, identity) found aloop strong on orchestration, recovery and gates but missing containment | in progress: M10.2 dependency and secret halves done: GREEN refuses a dependency added to a manifest (Cargo.toml, package.json, requirements*.txt, pyproject.toml, go.mod) that the approved plan does not name (`bin/deps`), and a credential (private key, fixed-prefix token) in the lines it adds; `gate-final` refuses one anywhere in the project (`bin/secrets`, built in rather than a matrix line so it runs on every stack with no install; test: `supply-chain.test.py`). Next: M10.2 dependency audit (`cargo audit`, `npm audit`, `pip-audit`, `govulncheck`) in the final gate's matrix, which needs the standards role to write it and the tool on the host; M10.1, M10.3, M10.4 planned; plan approval as a gate is M0.9 | **Order rationale:** identity and conformance fixtures first, so every later change is measured against today's behaviour; budgets and handoff next, because they shape every run; diff --git a/plugin/agents/final-gate.md b/plugin/agents/final-gate.md index 90ff446f..eced6f51 100644 --- a/plugin/agents/final-gate.md +++ b/plugin/agents/final-gate.md @@ -20,6 +20,8 @@ matrix is green with zero suppressions and every plan-ready.md fully ticked. Do not fail the sprint on any other pattern: an `#[allow(dead_code)]` in `tests/common/` (shared test helpers each test crate uses only part of) is not a suppression. Note any other lint `allow` you see in `src/` in your report for the retrospective. +- No credential in the project (private keys, cloud and API tokens): `selfcheck final-gate` + scans for one and names the file and line. Report it; never paste or move the secret. - Walk every story's plan-ready.md; confirm every checkbox is [x]. ## Tools diff --git a/plugin/agents/green-worker.md b/plugin/agents/green-worker.md index e937010e..b86fbb16 100644 --- a/plugin/agents/green-worker.md +++ b/plugin/agents/green-worker.md @@ -34,6 +34,8 @@ your init block's `### Budget` line has the exact numbers). Plan for it: - Never reaches green by suppressing/weakening a test. - Adds no dependency to a manifest (Cargo.toml, package.json, requirements*.txt, pyproject.toml, go.mod) that the plan does not name; the gate refuses it. Use what the project already has. +- Writes no credential into the project: read keys from the environment. The gate refuses a + private key or API token in the lines a task adds. ## Comms — the channel (story-bound, append-only) Your brief is the LAST `## … · green-worker · …` block in `$STORY_DIR/init.md`; read the diff --git a/plugin/bin/README.md b/plugin/bin/README.md index ed7fb210..44eea554 100644 --- a/plugin/bin/README.md +++ b/plugin/bin/README.md @@ -68,6 +68,7 @@ ctx-symbols) → WARN + grep fallback; never a silent pass. | `intent` | the internal Intent Contract (ROADMAP §4.1): `new` issues the canonical `intent_id` + skeleton under `docs/agents/intents/`; `check FILE [--mode reviewed\|autonomous]` validates fields and the clarification policy (exit 2 invalid, 3 an `ask` needs the human); `summary FILE` lists defaults/assumptions/spikes for approval. Run by `gate-intake`. | | `ids` | canonical identity + referential integrity (ROADMAP §4.5): `freeze SPRINT_DIR` checks the structured references (story frontmatter ↔ dir, dirs ↔ stories.md, validate.md ↔ tasks.md headings, `split_from` → a retired task) and issues frozen UUIDv7 ids in `sprintN/ids.json`; a retired alias is never reused · `check` · `resolve ALIAS`. Run by `gate-stage2-complete`; events then carry `story_uid`/`task_uid`. | | `deps` | supply chain (ROADMAP M10.2): `added --base REF` lists the dependencies a change adds to Cargo.toml, package.json, requirements*.txt, pyproject.toml or go.mod · `unplanned --base REF --story DIR` the ones the story's plan does not name (exit 2); gate-green-verify blocks on them. No third-party parser. | +| `secrets` | secret scan (ROADMAP M10.2): `scan [--base REF]` reports `path:line: kind` for a private key or a fixed-prefix token (AWS, GitHub, GitLab, Slack, Stripe, Google, Anthropic, OpenAI), never the text; with `--base` only added lines. gate-green-verify scans the task's added lines, gate-final the whole project (exit 2). `aloop: allow-secret` on a line exempts a fixture. | | `targets` | semantic execution map (ROADMAP §4.6): the planner's `/targets.json` — change targets and, with `tasks`, the whole semantic plan. `render STORY_DIR [--check]` writes tasks.md / validate.md / plan.md as deterministic views over it (the gate refuses a hand-edited view) · `check STORY_DIR` (run by `gate-stage2-complete`) · `target Tn STORY_DIR` (file:line, or `planned` for the shadow workspace) · `shadow` · `scope Tn STORY_DIR` (the diff scope gate-green-verify derives when SCOPE_GLOBS is unset) · `context Cn --budget N` (just the target's definition) · `refs\|callers\|callees` via the LSP server in `AGENTIC_LSP_COMMAND` (`_lsp.py`: references + call hierarchy); no server or a missing capability → exit 4, never guessed. Backend: ctx-symbols, else a definition regex flagged weaker. | | `impact` | optional cross-project impact provider seam (ROADMAP §4.8): `query consumers\|rationale\|migration\|standards SUBJECT [--task]` runs `AGENTIC_IMPACT_PROVIDER` (defaults.md or env), keeps only results with a `source_ref`, saves them under `docs/agents/impact/` and emits `artifact.created`. No provider or a failing one → WARN, exit 0. Builds no index. | | `layout` | the run-data dir (ROADMAP M1): `show` (which of `.aladdin/` / `.agentic/` is live and why) · `check` (exit 2 unless every run dir is git-ignored) · `migrate` (move `.agentic/` run data into `.aladdin/`, refused while worker worktrees are live; in `make test-hosts`) | diff --git a/plugin/bin/_gatelib.sh b/plugin/bin/_gatelib.sh index 352b8c22..913c3ae1 100755 --- a/plugin/bin/_gatelib.sh +++ b/plugin/bin/_gatelib.sh @@ -369,6 +369,15 @@ assert_planned_dependencies() { fi } +# Secrets (ROADMAP M10.2): no credential in the project. With an argument, only lines added since +# that ref (a task's diff); without, every file (the sprint sign-off). exit 2 if one is found. +assert_no_secrets() { + local out + if ! out="$("$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/secrets" scan ${1:+--base "$1"} --root "$(repo_dir)" 2>&1)"; then + fail "credential in the project: $(echo "$out" | tr '\n' ';' | sed 's/; *$//'). Read it from the environment or a git-ignored file instead; a test fixture that must look like a key carries an \`aloop: allow-secret\` comment on its line" + fi +} + # True if $1 matches any space-separated glob in $2. # Test files by convention: Rust's tests/ and tests/common/, any tests/ dir, and the Python/Go/JS # test-file names. RED writes only these; GREEN may touch them besides its scope, to drop shims. diff --git a/plugin/bin/gate-final b/plugin/bin/gate-final index 7e053350..3f9921c6 100755 --- a/plugin/bin/gate-final +++ b/plugin/bin/gate-final @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# FINAL GATE (sprint sign-off): full standards matrix green, zero suppressions, -# every plan-ready.md fully [x]. (Rust, Python, Go, JS; matrix from standards.md.) +# FINAL GATE (sprint sign-off): full standards matrix green, zero suppressions, no credential +# in the project, every plan-ready.md fully [x]. (Rust, Python, Go, JS; matrix from standards.md.) GATE_NAME="gate-final" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" : "${CLAUDE_PLUGIN_ROOT:=$(cd "$HERE/.." && pwd)}" @@ -18,6 +18,9 @@ root="$(repo_dir)" # 1) Zero suppressions anywhere. assert_no_suppression +# 1b) No credential anywhere in the project (ROADMAP M10.2). +assert_no_secrets + # 2) Every plan-ready.md fully ticked — in this tree AND in the sprint's docs in the main # tree (a worker worktree has docs/agents/ sparse-checked out, so look there too). sprint_dir="${SPRINT_DIR:-}" @@ -52,7 +55,7 @@ fi # 3) Full gate matrix (from standards.md) green. run_standards_matrix -note "FINAL gate passed: matrix green, zero suppressions, all plan-ready ticked, every planned test on main" +note "FINAL gate passed: matrix green, zero suppressions, no secrets, all plan-ready ticked, every planned test on main" # 4) Sprint close — by the harness, only on the real SubagentStop run (never a self-check): # sprintN/stats.md, docs/agents/NEXT.md (the post-/clear handoff), token totals. diff --git a/plugin/bin/gate-green-verify b/plugin/bin/gate-green-verify index 42ac9f1a..8c84ce71 100755 --- a/plugin/bin/gate-green-verify +++ b/plugin/bin/gate-green-verify @@ -1,6 +1,6 @@ #!/usr/bin/env bash # GREEN gate: this task's tests pass, no regression, diff within tasks.md scope, -# the standards.md matrix is green, zero suppressions, no unplanned dependency, output.md validates. +# the standards.md matrix is green, zero suppressions, no unplanned dependency or added credential, output.md validates. # (Target: Rust. The matrix is the one DECLARED IN standards.md — not hardcoded.) GATE_NAME="gate-green-verify" HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" @@ -38,6 +38,9 @@ fi # 3b) Supply chain: no dependency the approved plan does not name (ROADMAP M10.2). assert_planned_dependencies +# and no credential in the lines this task added (the final gate scans the whole project). +secrets_base="$(diff_base)" +[ -n "$secrets_base" ] && assert_no_secrets "$secrets_base" # 4) The standards.md gate matrix (fmt/lint/test/coverage/...) must be green. # This also asserts the task's tests now pass and nothing regressed. diff --git a/plugin/bin/secrets b/plugin/bin/secrets new file mode 100755 index 00000000..0dda2dcb --- /dev/null +++ b/plugin/bin/secrets @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +"""secrets — credentials committed to the project (ROADMAP M10.2). + +Acceptance proves behaviour, not safety: a test can pass with a live API key pasted into the +code. This scans for credential shapes that are near-certain on sight (private key blocks and +the fixed-prefix tokens of AWS, GitHub, GitLab, Slack, Stripe, Google, Anthropic and OpenAI). +Generic `password = "..."` heuristics are left out on purpose: a gate must not guess. +It prints `path:line: kind`, never the matched text, so the block message cannot leak it. + +A line carrying `aloop: allow-secret` is skipped (a test fixture that must look like a key). + +Usage: + secrets scan [--base REF] [--root DIR] with --base: lines added since REF (committed, + staged, unstaged and untracked files); + without: every tracked and untracked file. + exit 2 if any credential is found +""" +import os +import re +import subprocess +import sys + +KINDS = [ + ("private key", re.compile(r"-----BEGIN (?:RSA |EC |DSA |OPENSSH |ENCRYPTED |PGP )?PRIVATE KEY(?: BLOCK)?-----")), + ("AWS access key id", re.compile(r"(? MAX_BYTES: + return None + data = open(full, "rb").read() + except OSError: + return None + if b"\0" in data[:8192]: + return None + return data.decode("utf-8", "replace") + + +def hits(line): + if ALLOW in line: + return [] + return [kind for kind, rx in KINDS if rx.search(line)] + + +def scan_files(root, paths): + out = [] + for p in paths: + text = read(root, p) + if text is None: + continue + for i, line in enumerate(text.splitlines(), 1): + out += [(p, i, k) for k in hits(line)] + return out + + +def untracked(root): + return git(root, "ls-files", "--others", "--exclude-standard").splitlines() + + +def scan_all(root): + paths = sorted(set(git(root, "ls-files").splitlines() + untracked(root))) + return scan_files(root, [p for p in paths if not skipped(p)]) + + +HUNK = re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@") + + +def scan_added(root, base): + out, path, n = [], None, 0 + # the working tree against REF: committed, staged and unstaged changes in one diff + for line in git(root, "diff", "--no-color", "--no-ext-diff", "-U0", base, "--").splitlines(): + if line.startswith("+++ "): + path = line[6:] if line.startswith("+++ b/") else None + if path and skipped(path): + path = None + elif line.startswith("@@"): + m = HUNK.match(line) + n = int(m.group(1)) if m else 0 + elif path and line.startswith("+"): + out += [(path, n, k) for k in hits(line[1:])] + n += 1 + return out + scan_files(root, [p for p in untracked(root) if not skipped(p)]) + + +def main(argv): + if not argv or argv[0] != "scan": + print(__doc__, file=sys.stderr) + return 64 + opts = dict(zip(argv[1::2], argv[2::2])) + root = opts.get("--root") or os.getcwd() + found = scan_added(root, opts["--base"]) if opts.get("--base") else scan_all(root) + for p, i, k in found: + print("%s:%d: %s" % (p, i, k)) + return 2 if found else 0 + + +if __name__ == "__main__": + sys.exit(main(sys.argv[1:])) diff --git a/plugin/pipeline/execution/02-green/persona.md b/plugin/pipeline/execution/02-green/persona.md index 8c96301e..d03781c3 100644 --- a/plugin/pipeline/execution/02-green/persona.md +++ b/plugin/pipeline/execution/02-green/persona.md @@ -37,6 +37,8 @@ your init block's `### Budget` line has the exact numbers). Plan for it: - Never reaches green by suppressing/weakening a test. - Adds no dependency to a manifest (Cargo.toml, package.json, requirements*.txt, pyproject.toml, go.mod) that the plan does not name; the gate refuses it. Use what the project already has. +- Writes no credential into the project: read keys from the environment. The gate refuses a + private key or API token in the lines a task adds. ## Tools read, write(production files in task scope) diff --git a/plugin/pipeline/execution/04-final-gate/persona.md b/plugin/pipeline/execution/04-final-gate/persona.md index 0bd28678..79e6506c 100644 --- a/plugin/pipeline/execution/04-final-gate/persona.md +++ b/plugin/pipeline/execution/04-final-gate/persona.md @@ -15,6 +15,8 @@ matrix is green with zero suppressions and every plan-ready.md fully ticked. ## Mandate - Run the full cross-cutting gate matrix from sprintN/plan.md, zero exceptions. - Grep the workspace for every suppression pattern; confirm count is zero. +- No credential in the project (private keys, cloud and API tokens): `selfcheck final-gate` + scans for one and names the file and line. Report it; never paste or move the secret. - Walk every story's plan-ready.md; confirm every checkbox is [x]. ## Hard limits diff --git a/scripts/test/supply-chain.test.py b/scripts/test/supply-chain.test.py index 8c7b71db..c4b46f5e 100644 --- a/scripts/test/supply-chain.test.py +++ b/scripts/test/supply-chain.test.py @@ -1,9 +1,11 @@ #!/usr/bin/env python3 -"""ROADMAP M10.2 (first half): GREEN refuses a dependency added to a manifest that the approved -plan does not name. Package installs are the usual supply-chain entry, and acceptance proved +"""ROADMAP M10.2: GREEN refuses a dependency added to a manifest that the approved plan does not +name, and a credential committed to the project blocks GREEN (in the lines it added) and the +final gate (anywhere). Package installs are the usual supply-chain entry, and acceptance proved behaviour, not where the code came from. `deps added` lists the new names per manifest (Cargo.toml, package.json, requirements*.txt, pyproject.toml, go.mod); gate-green-verify blocks on any the story's plan (tasks.md, targets.json, plan.md, validate.md, stories.md) leaves out. +`secrets scan` finds fixed-shape credentials and prints where, never the text. python3 scripts/test/supply-chain.test.py """ import atexit @@ -107,4 +109,50 @@ def green(): assert r.returncode == 0, r.stderr ok("GREEN refuses a dependency the approved plan does not name, and accepts it once the plan names it") +# Fake credentials are assembled at run time so this file never holds one (push protection). +SECRETS = os.path.join(BIN, "secrets") +FAKE_KEYS = { + "private key": "-----BEGIN RSA " + "PRIVATE KEY-----", + "AWS access key id": "AK" + "IA" + "Q3EGRZ7XKPLMNB2Y", + "GitHub token": "gh" + "p_" + "a1B2c3D4e5F6g7H8i9J0k1L2m3N4o5P6q7R8", + "Slack token": "xo" + "xb-" + "1234567890-abcdefghij", + "Anthropic API key": "sk-" + "ant-" + "api03-" + "x" * 40, +} + +# 3) `secrets scan`: each shape is found with its file and line, the text never printed; a marked +# fixture line and an ordinary line pass; with --base only added lines count +write(os.path.join(MAIN, "conf.py"), "".join('k%d = "%s"\n' % (i, v) for i, v in enumerate(FAKE_KEYS.values()))) +r = subprocess.run([SECRETS, "scan", "--root", MAIN], env=ENV, capture_output=True, text=True) +assert r.returncode == 2, r +assert sorted(r.stdout.split("\n")[:-1]) == sorted("conf.py:%d: %s" % (i + 1, k) for i, k in enumerate(FAKE_KEYS)), r.stdout +assert not any(v[8:] in r.stdout + r.stderr for v in FAKE_KEYS.values()), "the scan printed a secret" +write(os.path.join(MAIN, "conf.py"), 'k = "%s" # aloop: allow-secret\ntoken = os.environ["API_TOKEN"]\nsk = "sk-learn"\n' % FAKE_KEYS["GitHub token"]) +assert sh(SECRETS, "scan", "--root", MAIN).stdout == "" +write(os.path.join(MAIN, "conf.py"), 'k = "%s"\n' % FAKE_KEYS["AWS access key id"]) +sh("git", "add", "conf.py") +sh("git", "commit", "-qm", "an old key") +sh("git", "tag", "before") +write(os.path.join(MAIN, "app.py"), "x = 1\ny = 2\n") +assert sh(SECRETS, "scan", "--base", "before", "--root", MAIN).stdout == "" +write(os.path.join(MAIN, "app.py"), "x = 1\ny = 2\nkey = '%s'\n" % FAKE_KEYS["Slack token"]) +r = subprocess.run([SECRETS, "scan", "--base", "before", "--root", MAIN], env=ENV, capture_output=True, text=True) +assert r.returncode == 2 and r.stdout == "app.py:3: Slack token\n", r +ok("secrets scan finds each credential shape by file and line without printing it, honours the allow marker, and --base sees only added lines") + +# 4) GREEN blocks a credential its own diff adds; the final gate blocks one anywhere in the project +sh("git", "checkout", "-q", "--", "app.py") +sh("git", "merge", "-q", "--no-edit", "main", cwd=wt) # main moved in case 3: the old key is not GREEN's +write(os.path.join(wt, "app.py"), "import requests\nimport leftpadx\nKEY = '%s'\n" % FAKE_KEYS["Anthropic API key"]) +sh("git", "commit", "-qam", "green: key", cwd=wt) +r = green() +assert r.returncode == 2 and "app.py:3: Anthropic API key" in r.stderr and "environment" in r.stderr, r.stderr +assert FAKE_KEYS["Anthropic API key"][8:] not in r.stderr +write(os.path.join(wt, "app.py"), "import os\nimport requests\nimport leftpadx\nKEY = os.environ['ANTHROPIC_API_KEY']\n") +sh("git", "commit", "-qam", "green: env", cwd=wt) +assert green().returncode == 0 +final = subprocess.run([os.path.join(BIN, "gate-final")], cwd=MAIN, input="", capture_output=True, text=True, + env=dict(ENV, REPO_DIR=MAIN, AGENTIC_SELFCHECK="1", GATE_RUN_MATRIX="0", SPRINT_DIR=os.path.dirname(STORY))) +assert final.returncode == 2 and "conf.py:1: AWS access key id" in final.stderr, final.stderr +ok("GREEN blocks a credential its diff adds and passes once it reads the environment; the final gate blocks one anywhere") + print("\n%d checks passed" % n[0])