Skip to content

#216 fetch credential references: resolve, scope per hop, never echo - #231

Merged
gregoryfoster merged 23 commits into
mainfrom
216-fetch-credentials
Nov 23, 2026
Merged

gregoryfoster merged 23 commits into
mainfrom
216-fetch-credentials

Conversation

@gregoryfoster

Copy link
Copy Markdown
Member

Refs #216

Builds the approved design (2026-11-23-216-fetch-credential-references-design.md, #230). Replicator now resolves ContentFetchCommand.credential_headers (co-core 0.51.1, cannobserv#577): a header name mapped to a fetch-<role> reference, resolved from a host table, scoped per hop, and never echoed.

This PR owes a deploy. With nothing provisioned, the only behaviour change is cookie lifetime (call 1A). Provisioning is the operator's; the commands are on #216.

Commits, in the design's order

Commit What
fix: a cookie jar per command, not per worker CommandScopeTransport, outermost, reads the command's scope from a ContextVar set around _fetch. A hop with no scope is refused. The client jar never stores; cookies live for one redirect chain. Each hop is sent on a copy of the request
refactor: the request-header rules move to src/worker/headers.py Same rules, public names; avoids a handler ↔ credentials import cycle
feat: the fetch credential table src/worker/credentials.py, REPLICATOR_FETCH_CREDENTIALS_FILE, PRODUCTION_ENV; values in SecretStr, read at boot
feat: credential_unknown and credential_refused the two new tokens (D6)
feat: guard the credential headers and resolve them D4 steps 1–2, ahead of the ceiling and the pacer
feat: scope each credential per hop D3: https, port 443, host in every binding, checked per hop before DNS; the only get_secret_value() call
test: the reference is a key, the value is the transport's charter §2c, with planted-violation tests, plus the charter text
docs: … issuer and outcome references, issuer contract, ENVIRONMENT, ARCHITECTURE, STREAMS, seed_fetch.py --credential-header
test: a credentialed frame per hop against a live broker -m integration, end to end
two small follow-ups Generator annotation (ty); the reflection limit in the issuer reference

Where the build departs from the doc

  • §7 detector. The "no server framework" check refused the whole stdlib http package, which caught http.cookiejar (the never-storing jar's policy). It now names http.server, with planted tests for both halves, and the charter row says so.
  • The scope holds (reference, binding) pairs (Resolved), so a hop refusal can name the reference without the binding carrying its own key (the alias table's CR managing-skills: the auto-refresh hook is half-installed — vendored skills frozen since 2026-08-05 #39).
  • The reference check uses co-core's validate_fetch_credential, not FETCH_CREDENTIAL_RE. The exported pattern ends in $, and the handler's own anchor test (\Z only) refused it there. The validator uses fullmatch, so the result is the same.
  • §2c differs from §2b on purpose. A refusal's detail names the reference, so "never formatted" can't carry over. The scan allows a reference only as a lookup, validator or Resolved argument, or as a placeholder in a PermanentFetchError message. A comparison, a store or a path built from a reference fails the scan.
  • Wildcard hosts are refused at load. PolicyHost admits *.x.com, but a binding matches hosts exactly, so a wildcard would silently match nothing.
  • A value with leading or trailing whitespace is refused, not stripped as an issuer's header value is. A stripped secret is a different secret.
  • The issuer reference carries its support line in this PR, not after the deploy. The deploy follows the merge directly, and a reference resolves only where it was provisioned anyway.

Gates (worktree, base c2b9dd5)

Gate Result
default suite 2223 passed, 2 skipped (base 2074 / 2); coverage 99.0%, new modules 100%
default suite, env loaded same
-m integration (scratch redis-server 7.0.15) 58 passed (base 57 + the new one)
-m browser (delegated scope) 31 passed
-m gcs 17 passed
tests/ci 57 passed
tests/deploy + test_deploy.py 108 passed, 1 skipped
ruff clean
ty (touched modules, non-gating) one pre-existing error at handler.py:169 (the _CEILING_FROM_SETTINGS sentinel); nothing new
mutations removing the jar policy, mutating the handed request, leaking through an error message, startswith on a reference, a second get_secret_value: each fails its test

Verification skipped

🤖 Generated with Claude Code

gregoryfoster and others added 11 commits November 23, 2026 16:58
Operator call 1A. The fetch client's jar lived for the worker's
lifetime, so one command's Set-Cookie rode every later command to the
same host — a credentialed fetch's session would ride an anonymous one.

CommandScopeTransport, outermost over the guard, reads the command's
scope from a ContextVar the handler sets around _fetch. Cookies live in
the scope for one redirect chain; the client's own jar never stores. A
hop with no scope is refused (RuntimeError). Each hop goes out on a copy
of the request, because httpx builds the next hop from the handed one.

The §7 "no server framework" detector named the whole stdlib http
package; it now names http.server, so http.cookiejar (the never-storing
jar's policy) is allowed. Planted-import tests pin both halves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unchanged rules, now public names: HEADER_NAME, HEADER_VALUE,
REFUSED_HEADERS, REFUSED_HEADER_PREFIX and the two bounds. The fetch
credential table checks a binding's header and value against the same
rules the handler applies to `headers`, and the handler will import the
table, so the rules can't stay in handler.py without a cycle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
src/worker/credentials.py, in the alias table's shape: a JSON table at
REPLICATOR_FETCH_CREDENTIALS_FILE, read once at boot with every value
file it names, frozen behind MappingProxyType. A binding pins its header
(call 3), names its hosts in PolicyHost's form (exact, no wildcard), and
holds its value in a SecretStr (call 2). An unusable binding is dropped
with the rule it broke; neither a value nor an off-rule reference is
ever logged. Unset provisions nothing.

The setting joins PRODUCTION_ENV, as the credential scrub requires.
Loaded at boot; the handler takes the table in a later commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two content.fetch reason tokens, both terminal with status_code and
attempts unset (D6). credential_unknown: no usable binding for the
reference. credential_refused: the binding exists, but the header, host,
scheme or port is outside it — pre-flight or at the redirect hop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
D4 steps 1 and 2, both pure and both ahead of the ceiling and the pacer.

Step 1, in _request_options: credential_headers' names get the headers
guards, folded with headers — a name in both maps (E3) or twice by case
(E4) is a duplicate — plus E5's names, the count bound over the union,
and E1 (any credential under render="browser"). invalid_request_options.

Step 2, _resolve_credentials against the boot table: a reference off
fetch-<role> (checked whole, with co-core's validator) or never
provisioned is credential_unknown; the wrong header for its binding is
credential_refused (call 3); the byte bound over both maps, resolved
values counted, is invalid_request_options; a submitted URL outside any
binding's scope (https, port 443, the host in every binding) is
credential_refused. An off-rule reference is never quoted.

The resolved (reference, binding) pairs ride the command scope to the
transport; FetchContent never holds a value. The worker passes the boot
table to the fetch handler; unset provisions nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
D3. CommandScopeTransport, outermost, checks every hop against every
credential in the command's scope before anything below it runs:
https only, port 443 only (call 4), the host — raw_host, canonical —
in every binding's hosts. A hop out of scope raises credential_refused
and is never sent; out of scope and in a refused range is
credential_refused, with no DNS lookup (call 5).

A hop in scope carries each credential on the copy it sends; the
request httpx holds is never mutated, so a later hop starts without it.
This is the only get_secret_value() call site. A Cookie credential is
followed by the command's jar cookies in the same field.

A forced mid-fetch failure's logged traceback, and the facts, carry no
value; both mutations (a leaking error message, an in-place header)
fail the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The charter's §2c, mirroring §2b's alias scan with one deliberate
difference: a refusal's detail names the reference, so the issuer knows
which binding to provision. So the legal uses of a reference bound by
the credential_headers .items() loop are a lookup, the validator,
Resolved, or a placeholder in a PermanentFetchError message; a compare,
a store or a path built from one fails. The map's values are reachable
no other way, the field is read in handler.py alone, and
get_secret_value() has one call site: the scope transport.

Planted-violation tests for each detector; mutations of the real
handler (a startswith on a reference, a second secret read) fail it.
The charter gains the credential-reference paragraph, the taxonomy
rows, and both enforcement rows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…h path

- issuer reference: a credential_headers section (what a reference is,
  what a binding pins, per-hop scope, the refusal table and tokens, the
  per-command cookie lifetime), the bounds row pointing at headers.py,
  and the version-history line;
- outcome reference: the two tokens, and their taxonomy rows;
- issuer contract: the rule in brief, linking the section;
- ENVIRONMENT: REPLICATOR_FETCH_CREDENTIALS_FILE, its format, rules,
  file posture, boot lines, and rotation-is-a-restart;
- ARCHITECTURE, STREAMS: the command scope outside the guard;
- seed_fetch.py --credential-header, with COMMANDS.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two seeded commands through the real driver and the scope transport:
one redirected within the binding's host stores a blob with the
credential on both hops; one redirected off it closes
credential_refused, the off-scope host never contacted. No scratch
stream, the DLQ included, carries the value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ty flags Iterator on a @contextmanager as deprecated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gregoryfoster and others added 6 commits November 23, 2026 18:26
A dropped binding logged its value_file whenever it was a string, and an
invalid host was quoted twice (the detail and PolicyHost's message). A
value pasted into either field reached the journal. value_file is logged
only when it is an absolute path; a bad host is named by position.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Path.read_bytes() had no bound, so a value_file at /dev/zero (or a huge
file) held the boot forever — a loader that promises to fail closed
never returned. It now reads the header bound plus two bytes, and the
length check runs before the charset so a truncated read is named for
its length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It had split the alias table's comment from the call it describes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ENVIRONMENT, STREAMS, the issuer contract and the charter are back under
10,000 tokens; each now states what it owns and links the issuer
reference for the rules. The outcome reference stays 75 over: it had 15
tokens of headroom before #216, and its two tokens' one row can't fit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Either branch closed it credential_unknown, so it didn't prove the
reference is checked whole.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gregoryfoster

Copy link
Copy Markdown
Member Author

CR round 1, applied under a blanket --fix (one commit per finding):

# Finding Result
1 🔴 A dropped binding logged value_file whenever it was a string, and quoted an invalid host twice, so a value pasted into either field reached the journal Fixed b6a433c: the path is logged only when absolute; a bad host is named by its position
2 🟡 The value-file read had no bound (/dev/zero hung the boot) Fixed 5d5a9e6: reads the bound plus 2 bytes, length checked first
3 🟡 The credential load split the alias table's comment from its call Fixed 6e16921
4 🟡 Five docs pushed over their 10k-token budget Fixed cca1dc3 for four. The outcome reference stays 75 over: it had 15 tokens of headroom before #216. Left for curating-context
5 💭 The trailing-newline test didn't discriminate between branches Fixed 8a32f35
6 💭 A boundary test swapped the module-global REPO Fixed 812d0e5

Gate after the fixes: 2227 passed, 2 skipped; -m integration 58 passed; ruff clean; CI green on all 4 jobs.

gregoryfoster and others added 6 commits November 23, 2026 19:00
Exact counts (count_tokens), before -> after:
  docs/DEPLOYMENT.md                                10222 -> 9116
  docs/contracts/content-fetch-outcome-reference.md 10072 -> 9935
  docs/TESTING.md                                   10025 -> 9984
  docs/INFRASTRUCTURE.md                            10011 -> 9981
  docs/DEPENDENCIES.md (destination)                 4097 -> 5193

Relocated (class B, moved verbatim):
- DEPLOYMENT.md "### Dependabot proposes the action and Python bumps (#76, #169)"
  -> DEPENDENCIES.md "## Dependabot proposes the action and Python bumps": the
  heading lost its provenance per the #162 seams note (both issues stay in the
  body); its two links re-aimed (DEPLOYMENT.md#main-takes-pull-requests-208,
  and #the-build-backends-bound-and-cis-uv same-doc). Pointers repointed:
  .github/dependabot.yml (2), tests/ci/test_dependabot.py, .skills/doc-sections,
  .skills/doc-sensitive-paths; DEPENDENCIES.md's scope line names the section.

Tightened (class C, every atom kept, claims_dropped 0):
- outcome reference, "How the blob TTL clock runs": the window's history ("used
  to be" a host setting) and the operator-side pairing detail INFRASTRUCTURE.md's
  lifecycle table carries;
- TESTING.md: "Both divergences were found by running against the real server",
  and "The grant's full shape is broker#2's to state" (broker#2 stays on the line);
- INFRASTRUCTURE.md: "It reached 97% on 2026-10-22", "not as a courtesy", and
  the grants subsection's narrative lead-in.

Deleted: nothing. No FALSE facts; links, anchors, orphans, unindexed all empty.

Seams: 0 after judging 8 — the #216 heading `credential_headers ... (#216)`
renamed (its two anchors updated), six standing provenance headings and one
legitimate AGENTS.md back-reference acknowledged in .skills/context-seams-ok.
Warrants: .skills/context-loss-ok (3 + 11 + 2 + 4), .skills/context-claims-ok (2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A baseline row per doc at 812d0e5 and a curation row per doc at 803f11e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tightening said the reap rule was 'on REPLICATOR_BLOB_TTL_SECONDS's
horizon', contradicting the next paragraph (nothing keeps the two in
step). The rule is daysSinceCustomTime: 8 against the horizon published
from the setting. Restores what the boot line shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Dependabot move left the deploy question without a pointer from the
doc an operator reads for it; a row in its when-to-do-what table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gregoryfoster

Copy link
Copy Markdown
Member Author

Context curation of the four docs over the 10,000-token budget (803f11e; exact counts):

Doc Before → after How
docs/DEPLOYMENT.md 10222 → 9195 demoted the Dependabot section verbatim to docs/DEPENDENCIES.md (4097 → ~5200); heading provenance dropped per #162's note; pointers repointed in .github/dependabot.yml, tests/ci/test_dependabot.py, .skills/doc-sections, .skills/doc-sensitive-paths; a table row now points back (CR 8)
content-fetch-outcome-reference.md 10072 → 9951 tightened the TTL section's history; every claim kept
docs/TESTING.md 10025 → 9984 tightened two narrative sentences
docs/INFRASTRUCTURE.md 10011 → 9981 tightened a dated reading, a filler clause and a lead-in

Nothing deleted. No-loss check passes on all four (warrants in .skills/context-loss-ok and context-claims-ok), links, anchors and orphans are clean, seams 0. Telemetry has a baseline and a curation row per doc.

CR round 2, applied under --fix:

# Finding Result
7 🟡 The tightening put the lifecycle rule "on" REPLICATOR_BLOB_TTL_SECONDS, contradicting the next paragraph Fixed e875da9
8 🟡 The move left DEPLOYMENT with no pointer to whether a bot PR owes a deploy Fixed 6c4f848
9 💭 A ragged line in DEPENDENCIES.md's scope paragraph Fixed da647ea

Gate: 2227 passed, 2 skipped; tests/ci 57 passed; ruff clean.

@gregoryfoster
gregoryfoster merged commit 6718cc9 into main Nov 23, 2026
4 of 5 checks passed
@gregoryfoster
gregoryfoster deleted the 216-fetch-credentials branch November 23, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant