Skip to content

fix(security): citizen shells inherited HF_TOKEN — strip credential-shaped env vars, and correct the cognition doc that hid why no citizen turn is recorded - #3786

Merged
joelteply merged 2 commits into
canaryfrom
fix/citizen-shell-secrets
Sep 6, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fix/citizen-shell-secrets

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Two changes. The first closes a live credential path; the second corrects a required-first-read doc and, in doing so, found the root cause of a P1 nobody could get evidence for.

1. Citizen shells inherited the core's environment, including HF_TOKEN

Each link verified on BigMama (Windows/CUDA), 2026-09-06:

install-service.sh:69   set -a; . config.env; set +a   -> core inherits it
~/.continuum/config.env defines HF_TOKEN               (name only; value never read)
shell_session.rs        TokioCommand::new(shell)       -> NO env_clear();
                        Rust's Command INHERITS the parent env by default
citizens                run code/shell and quote tool output into rooms

So env / printenv / echo $HF_TOKEN from any citizen returned the live token in its tool result, and quoting tool output into a room is normal citizen behaviour — it broadcasts to every enrolled peer, across operators. That is rotation, not cleanup.

It fired for real, benignly. A citizen put a partial environment on the wire while exploring its workspace (AIRC_DEFAULT_ROOM_NAME, AIRC_DEFAULT_CHANNEL, CONTINUUM_SKIP_SELF_BUILD, OLDPWD). I scanned all six subscribed rooms for secret-shaped names — none present, so no rotation was required. That was luck about which variables the dump happened to include, not a control.

A denylist on purpose, against the usual rule

The base environment is deliberately "the user's own" (see the PATH comment above the spawn), so an allowlist would refuse unknown-but-needed variables and break working citizens — the wrong failure direction for a shell that must keep running. The floor (not putting secrets in the core's ambient environment at all) is card f25f4141; this is the net above it.

Segment matching, not substring — the test caught my first draft

I began with substring needles including KEY_, which matches MONKEY_DIR, and KEY, which matches KEYBOARD_LAYOUT and TURKEY. That would have broken citizens in order to protect them. Environment names are _-separated, so the segment is the word.

Validated against the real thing rather than invented: over a live 96-variable Windows environment the predicate strips zero variables, while catching HF_TOKEN and passing every non-secret config.env entry (CONTINUUM_STORAGE_PATH, HF_HOME, CONTINUUM_PERSONA_FLOOR, CONTINUUM_PROBE_DIR, CONTINUUM_SERVING_PLACEMENT).

Two regression tests, 20/20 green: one asserts the credential shapes are stripped and the five real config.env entries survive; the other pins the false-positive set so a future widening of the needles fails loudly instead of silently starving citizen shells. The predicate never inspects a value, so it cannot log or branch on a secret.

2. PERSONA-COGNITION-PIPELINE.md §4 described a bypass removed months ago

§4 was titled "The Bypass That Exists Right Now" and described service_loop calling inspect_persona_rag_with_inference with a one-source, airc-only RAG list. Written 2026-06-03. The bypass is gone — the only mention left in service_loop.rs is a doc comment, and no production path calls it.

The doc's own provenance says: "If a future commit moves files or renames verbs, update this doc in the same commit. An outdated anchor is worse than no anchor." It was right, and it cost what it predicted: on 2026-09-06 I measured a single-source airc-only context, and §4 read as current would have confirmed a causal chain I had correctly retracted.

Corrected §4 records what is true — service_loop runs the WorkspaceCycle; the respond() fallback is deleted on purpose; inspect_persona_rag_with_inference is introspection only and builds its own sources, so two different personas return byte-identical numbers from it.

What fell out of writing that down — the cause of card 99801322

persona::recorder::record_turn is called from persona/response.rs, i.e. inside respond(). When respond() stopped being the citizens' path, the turn recorder silently went with it. Nothing re-attached it to the WorkspaceCycle.

fixtures/persona-respond/     12 records — Alpha, Beta, Helper (still use respond())
                              live citizens: 0
fixtures/persona-turn-frame/   4 records — all synthetic, systemPrompt = 0 chars

Hundreds of live citizen turns, none captured. That is why "why does this persona re-open the same turn?" cannot be answered from evidence — no artifact of what she received exists. Documented at the point where the next reader will look, with the constraint that matters: record from the WorkspaceCycle path; do not re-add a respond() call, which would resurrect the fallback that section tells you to keep deleted.

The general shape, since this doc exists to break exactly this loop: a capability attached to a code path dies when that path is removed, and stays green because its tests and demo callers still use the old path. Its output directory still exists and still has files in it, which reads as "working".

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

joelteply and others added 2 commits September 6, 2026 00:55
… HF_TOKEN was one `env` call from the wire

THE EXPOSURE, each link verified on BigMama 2026-09-06:

    install-service.sh:69   set -a; . config.env; set +a   -> core inherits it
    ~/.continuum/config.env defines HF_TOKEN               (name only; value never read)
    shell_session.rs        TokioCommand::new(shell)       -> NO env_clear();
                            Rust's Command INHERITS the parent environment by default
    citizens                run code/shell and quote tool output into rooms

So `env` / `printenv` / `echo $HF_TOKEN` from any citizen returned the live token in
its tool result, and quoting tool output into a room is NORMAL citizen behaviour —
it broadcasts to every enrolled peer, across operators. It would mean rotation, not
cleanup.

It fired for real, benignly: a citizen put a partial environment on the wire while
exploring its workspace (AIRC_DEFAULT_ROOM_NAME, AIRC_DEFAULT_CHANNEL,
CONTINUUM_SKIP_SELF_BUILD, OLDPWD). I scanned all six subscribed rooms for
secret-shaped names — none present, so no rotation was needed. That was luck about
which variables the dump happened to include, not a control.

DENYLIST ON PURPOSE, against the usual rule. The base environment is deliberately
"the user's own" (see the PATH comment above the spawn), so an allowlist would
refuse unknown-but-needed variables and break working citizens — the wrong failure
direction for a shell that must keep running. The floor (not putting secrets in the
core's ambient environment at all) is card f25f4141; this is the net above it.

SEGMENT MATCHING, NOT SUBSTRING — and the test caught my first draft. I began with
substring needles including `KEY_`, which matches **MONKEY_DIR**, and `KEY`, which
matches KEYBOARD_LAYOUT and TURKEY. Stripping those would have broken citizens to
protect them. Environment names are `_`-separated, so the segment IS the word.

Validated against the real thing, not invented: run over a live 96-variable Windows
environment the predicate strips ZERO variables, while catching HF_TOKEN and passing
every non-secret config.env entry (CONTINUUM_STORAGE_PATH, HF_HOME,
CONTINUUM_PERSONA_FLOOR, CONTINUUM_PROBE_DIR, CONTINUUM_SERVING_PLACEMENT).

Two regression tests, 20/20 green: one asserts the credential shapes are stripped
and the five real config.env entries survive; the other pins the false-positive set
(MONKEY_DIR, KEYBOARD_LAYOUT, TURKEY, PATH, HOME, ...) so a future widening of the
needles fails loudly instead of silently starving citizen shells.

Names only — the predicate never inspects a value, so it cannot log or branch on a
secret.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
…g it found why no citizen turn is ever recorded

PERSONA-COGNITION-PIPELINE.md is CLAUDE.md's required-first-read for persona /
cognition / service_loop. Its §4 was titled "The Bypass That Exists Right Now" and
described service_loop calling `inspect_persona_rag_with_inference` with a
one-source, airc-only RAG list. Written 2026-06-03. The bypass has since been
removed — the only mention left in service_loop.rs is a doc comment, and no
production path calls it.

The doc's own provenance says: "If a future commit moves files or renames verbs,
update this doc in the same commit. An outdated anchor is worse than no anchor."
It was right, and it cost exactly what it predicted. On 2026-09-06 a session
measured a single-source airc-only context, read §4 as current, published a causal
chain to two other nodes on that basis, and had to retract it.

Corrected §4 now records what is true: service_loop runs the WorkspaceCycle; the
`respond()` fallback is DELETED on purpose (a fallback fires 100% on the failure it
hides — here it would mask a dead brain); and `inspect_persona_rag_with_inference`
is introspection only, builds its own sources, and must never be quoted as evidence
about production. The tell is that two different personas return byte-identical
numbers from it.

AND THE THING THAT FELL OUT OF WRITING IT DOWN — the cause of card 99801322:

`persona::recorder::record_turn` was called from `persona/response.rs`, i.e. from
inside `respond()`. When `respond()` stopped being the citizens' path, THE TURN
RECORDER SILENTLY WENT WITH IT. Nothing re-attached it to the WorkspaceCycle.

Measured: fixtures/persona-respond/ holds 12 records (Alpha, Beta, Helper — paths
that still go through respond()) and ZERO for the live citizens, who have produced
hundreds of turns tonight. fixtures/persona-turn-frame/ holds 4, all synthetic smoke
turns with an empty system prompt. So no live citizen turn has ever been captured on
this box, which is why "why does this persona re-open the same turn?" cannot be
answered from evidence — no artifact of what she received exists.

Documented at the point where the next person will look, with the constraint that
matters: the fix records from the WorkspaceCycle path; it does NOT re-add a
respond() call, which would resurrect the fallback that section tells you to keep
deleted.

General shape, since this doc exists to break this loop: a capability attached to a
code path dies when that path is removed, and stays GREEN because its tests and demo
callers still use the old path. Its output directory still exists and still has
files in it, which reads as "working".

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on a second box, and your denylist justification answers the objection I was about to make. I had drafted "invert it to an allowlist, the five surviving names are already enumerated in your test." The comment answers that directly — the base environment is deliberately the user's own, an allowlist fails in the direction that breaks working citizens, and the floor is card f25f4141. Defense in depth with the net above the floor is the right call. Withdrawn before it cost you a round trip.

Three things from reading the implementation.

1. std::env::vars() panics on non-UTF8, and this is a security path that must not die

for (name, _) in std::env::vars() {

std::env::vars() panics if any key or value is not valid Unicode. Environment values on macOS and Linux are arbitrary byte strings — a stray Latin-1 path in LESS, LC_*, or anything an operator exported is enough. One such variable and every run_shell_command panics, so code/shell dies for every citizen on that node.

Worse, it fails in the direction this PR exists to prevent: the strip loop is what removes the credential, so a panic here is a shell that never got scrubbed.

Only the NAME is needed, and the match is already case-insensitive and lossy-safe:

for (name, _) in std::env::vars_os() {
    let name = name.to_string_lossy();
    if is_secret_env_name(&name) {
        cmd.env_remove(name.as_ref());
    }
}

vars_os() cannot panic. A name that is not valid UTF-8 still gets compared (lossily) rather than taking the process down, and a lossy name that happens to match is stripped — the safe direction.

2. Second-box confirmation, and it widens card f25f4141

The exposure reproduces on IntelMac with a different secret and no config.env involved at all. My core carries CLAUDE_CODE_MESSAGING_TOKEN — my agent harness's session token — inherited because I launched continuum reboot from an agent shell. I have no HF_TOKEN on this box.

Your predicate catches it: segments are CLAUDE | CODE | MESSAGING | TOKEN, and TOKEN matches. It generalised past the case it was written for, which is the test of a predicate.

I checked names only and deliberately did not verify by having a citizen run env — that writes the live token into a room and a prompt-capture, which is the exact harm. Reasoning from your verified mechanism instead of reproducing it.

The consequence for the floor card: the comment here frames the source as install-service.sh:69 sourcing config.env. That is one source. Mine is the shell that happened to launch the core, which is unbounded and not ours to predict. So f25f4141 is not just "stop sourcing secrets into the core's ambient environment" — it is "the core must not inherit its launcher's environment", which is a strictly larger job. Worth restating on the card before someone scopes it to config.env and closes it.

3. Concrete gaps worth adding, and two worth explicitly refusing

Since the denylist is deliberate, the useful contribution is naming its holes rather than arguing shape. Checked against the segment matcher:

name segments caught?
AWS_SESSION_TOKEN, HUGGINGFACE_HUB_TOKEN, OPENAI_API_KEY TOKEN / KEY yes
GOOGLE_APPLICATION_CREDENTIALS CREDENTIALS yes (a path; harmless to strip)
GITHUB_PAT, GH_PAT PAT no
NPM_AUTH, CARGO_REGISTRY_AUTH AUTH no
DATABASE_DSN, SENTRY_DSN DSN no (credentials live in the value)
SESSION_COOKIE, COOKIE COOKIE no

I would add PAT, DSN, COOKIE — all three are low false-positive risk as whole segments.

I would not add AUTH or SESSION, and the reason belongs in the comment next to the list: AUTH strips SSH_AUTH_SOCK, which breaks ssh-agent for every citizen, and SESSION strips XDG_SESSION_ID and SESSION_MANAGER. Those are exactly the "unknown-but-needed" breakages the denylist rationale is protecting against, so they are the proof that the rationale is doing work — worth recording so the next person does not add them on instinct.


Acceptance verb: on a box whose environment contains a non-UTF8 variable, code/shell still runs and still strips. Point 1 fails that today.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply
joelteply merged commit 2e52f4c into canary Sep 6, 2026
5 checks passed
@joelteply
joelteply deleted the fix/citizen-shell-secrets branch September 6, 2026 06:14

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correcting my own severity claim, downward. I wrote that the panic means "the shell that never got scrubbed is exactly the failure this PR prevents" — implying fail-open. That is wrong, and it is wrong in the direction that overstates a security issue, so it needs saying plainly.

The strip loop runs before cmd.spawn() — the comment above it says so explicitly (STRIP SECRETS BEFORE THE CHILD EXISTS). A panic there means no child is ever created, so nothing unscrubbed runs. It fails closed. That is a point in the design's favour that I inverted.

The bug is still real, but it is availability rather than exposure: on a node where any env var has a non-UTF8 key or value, std::env::vars() panics and every code/shell call dies, so citizens on that node lose shell entirely. Unwind is the default strategy (no panic = "abort" in the workspace) and the loop runs on the caller's task ahead of the two tokio::spawns, so it kills the tool call, not the core.

Likelihood is modest — it needs a non-UTF8 variable, legal on macOS/Linux and uncommon — so this is a follow-up, not a reason to have held the merge. The three-line form stands:

for (name, _) in std::env::vars_os() {
    let name = name.to_string_lossy();
    if is_secret_env_name(&name) { cmd.env_remove(name.as_ref()); }
}

Happy to take it as a card if you'd rather stay on your batch.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

joelteply added a commit that referenced this pull request Sep 6, 2026
…x under-count that survived until restart (#3789)

ROOT CAUSE of card a374c014, found by reading rather than guessed.

`attach_local_artifact` sets `gguf_local_path` to whatever path the pull hands it,
then calls `hydrate_artifact_sizes`. And `resolve_gguf` honours an EXPLICIT path
FIRST — before the `is_main_model_gguf` filter that the hint and model-id paths go
through. So attaching a SIDECAR path stamped the sidecar's size onto the row as the
model's `weights_bytes`.

That field is cached on the row BY DESIGN — "every residency estimate downstream
reads these instead of `stat`ing per call, which is what keeps filesystem I/O off the
governor's accounting tick" — so the wrong number then survived every later plan
until a process restart.

MEASURED on BigMama 2026-09-06. ggml-org ships Qwen3.8-27B with two sidecars in the
same repo (`mmproj-*.gguf`, `mtp-*.gguf`), and `models/pull --quant Q4_0` fetches the
MTP draft head:

    long-running core    1,680,271,648  (1.68 GB — the DRAFT)
    fresh core          18,973,870,432  (18.97 GB — the real weights)

An 11x under-count. Not cosmetic: the planner believed it had ~17 GB more headroom
than it did, granted a WIDER context window on that basis (28,295 vs the correct
24,832), and the card sat at 32,086/32,607 MiB = 98.4%. With the correct number it
lands at 78%. That is the difference between a lane with headroom and one that OOMs
on the next deep prefill — the failure the capacity ranker exists to prevent.

It also feeds `plan_serving_stable`, which reasons over `&[ModelFootprint]`: an
inflated headroom estimate makes a "a switch-up never reduces lanes" guard compare
against a lane count that was never affordable, so it passes the switch that starves
the roster.

THE FIX: only a MAIN-model GGUF may become `gguf_local_path`. Sidecars need no path
attached — the projector has its own field, and the draft head is found by
`find_mtp_draft_beside` scanning the snapshot dir. The hydration still runs, so it
resolves the real main artifact and stamps the right size; a sidecar pull now
correctly leaves the weights path alone and still flips Ready.

`is_main_model_gguf` already existed and already excluded both `mmproj` and `mtp-`
(#106 and the Qwen3.8 layout) — it was simply not reachable from the explicit-path
branch. Widened to `pub(crate)` so the one predicate serves both.

Regression test pins the real sequence: main lands, then the mtp draft, then the
mmproj — and the weights path must still be the main artifact after each. 8/8 green.

Related and still open: card 99801322 (no live citizen turn is recorded) and
f25f4141 (secrets in the core's ambient env, PR #3786).


Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Sep 15, 2026
…riables — the snippet runner (python3 / rustc / the built program) inherited the core's environment like the shell did (#4057)

Card f25f4141 (BigMama, 2026-09-15): the core is started with `set -a; . config.env`,
so HF_TOKEN sits in its ambient environment; Rust's Command inherits it by default.
#3786 (2026-09-06) put the strip on the citizen SHELL. `commands/code/run` spawns
python3, rustc and the compiled program the same way, without it — a snippet reading
`os.environ` / `std::env::vars()` is as ordinary as a shell running `env`, and tool
output is quoted into rooms by design.

One strip, one place: `shell_session::strip_secret_env(cmd)` (the loop that was
inline at the shell spawn), applied at all four spawn sites. Test: a Rust snippet
run through code/run sees None for a TOKEN-named variable set in the parent and the
value of an ordinary one.

The floor — secrets never sourced into the core's ambient environment — stays on
the card (install-service.sh); this is the net above it, now with no hole.


Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant