Skip to content

fix: allow the 1Password agent only for a terminal login shell - #36

Merged
tbhb-agent merged 8 commits into
mainfrom
ssh-agent-allowlist
Nov 24, 2026
Merged

tbhb-agent merged 8 commits into
mainfrom
ssh-agent-allowlist

Conversation

@tbhb-agent

@tbhb-agent tbhb-agent commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The ssh guard keys on agent markers (SSH_CONNECTION, CLAUDECODE, CODEX_HOME). A process without them still reaches the 1Password agent and raises Touch ID on an unwatched screen. Scrubbed environments, hooks, gate wrappers and scheduled jobs all lack the markers.

Behavior change

The 1Password agent is now an allowlist. A login shell on a terminal, with none of SSH_CONNECTION, CLAUDECODE and CODEX_HOME, exports TBHB_OP_AGENT=1, SSH_AUTH_SOCK and OP_ACCOUNT. ~/.ssh/config sets IdentityAgent none unless that marker is 1, and git signs through a wrapper that drops an inherited 1Password socket under the same rule. In tmux, the server and each new or attached session drop the marker and a 1Password socket, and each pane's login shell sets them again for the operator. A harness-started server loses its CLAUDECODE and CODEX_HOME too. The operator's panes no longer inherit an agent identity. A headless login shell clears an inherited marker.

Decisions

Chose a marker plus the existing agent-variable check over the marker alone, because a harness started from a terminal inherits the marker. Chose not to restrict the op binary itself, because the repo has no op plugin or alias setup. The only op setting is OP_ACCOUNT, which now follows the same rule.

Needs human judgment

Accepted security debt, ruled by Coordination. Any child of the operator's terminal inherits the marker. A pane that an agent opens with tmux new-window on a harness-started server gets a login shell with the marker and the socket. The first command given to new-session keeps the socket too, since tmux spawns it before the hook runs. A switch-client can copy the socket back into the target session. A scrubbed process on a pseudo-terminal that runs zsh -l also gets the marker.

Risk

Tier 2 (agent ssh trust). A terminal shell that sets none of the variables keeps the agent. One that opens without a terminal, such as a login shell run by a launcher, loses it until it runs export TBHB_OP_AGENT=1. Revert the PR to roll back.

Verification

bazelisk test //:ssh_agent_guard_test //:render_test //:cspell_test passes. The guard test renders the config and runs env -i ssh -G for seven environments and four -J hop cases. It also runs the signing wrapper against a stub ssh-keygen for five. Against the old config three ssh cases fail. A throwaway tmux server started with the marker and a 1Password socket shows neither in show-environment -g after sourcing the rendered conf. A server started with CLAUDECODE=1 gives a new pane a login shell with the marker and no CLAUDECODE.

Opened-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;surface=cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli

Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
@tbhb-agent
tbhb-agent requested a review from tbhb as a code owner November 24, 2026 03:17
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
Generated-by: LLM effort=medium;harness=claude-code:2.1.330;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
@tbhb-agent
tbhb-agent merged commit 111da59 into main Nov 24, 2026
5 checks passed
tbhb-agent added a commit that referenced this pull request Nov 24, 2026
Why
`tmux switch-client` copies the client's `SSH_AUTH_SOCK` into the target
session and fires neither the new-session hook nor the attach hook. A
harness-started server keeps the 1Password socket in that session, and
later panes inherit it. cr2 reported this on #36.
Coordination ruled it security debt, tracker row DF-S1.

Behavior change
A `client-session-changed` hook runs the same scrub as the attach hook.
It removes a 1Password `SSH_AUTH_SOCK`, `CLAUDECODE` and `CODEX_HOME`
from the session the client switched to. A forwarded agent socket
remains.

Decisions
The hook reuses the attach hook's command. A new `tmux` server still
starts from the scrubbed global environment.

Needs human judgment
None.

Risk
Only `.tmux.conf` changes. A new hook can't affect a login shell.
Removing the line restores the old behavior.

Verification
On a throwaway server started with `CLAUDECODE=1`, a terminal client
attached to one session with a 1Password `SSH_AUTH_SOCK` and switched to
another. Without the hook, the target session held the socket. With the
hook, it didn't. Reloading with `source-file` is a separate debt, DF-S2,
and remains open.

Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
tbhb-agent added a commit that referenced this pull request Nov 25, 2026
Why
Hosts update their chezmoi source only when someone pulls by hand, and
nothing reports their distance from `main`. Eight macOS and Linux hosts
fell up to 55 commits behind `main` before a manual fast-forward to
af84e0e, and fixes such as #36 and #38
reached them late.

Behavior change
Hourly, a `launchd` agent on macOS or a `systemd` user timer on Linux
runs `~/.local/bin/tbhb-dotfiles-drift`. It fetches `origin main` into a
private ref and compares the chezmoi source tree with it, using `git`
alone. One line per run:

    drift=0|1 behind=N dirty=N branch=B src_sha=S origin_sha=O

A dirty tree, a branch other than `main`, or a commit that differs from
the ref exits 1. A failed step prints `drift=1 error=<step>` and exits
2. It never merges, checks out, or applies. Its `git` calls take no
optional locks and skip the `fsmonitor` hook. The fetch skips tags,
`FETCH_HEAD`, auto maintenance and commit graphs, and its own output
goes to stderr. Inherited `git -c` settings, the agent socket,
credential helpers, prompts and the user `ssh` config all stay out.
Linux logs to the journal as `tbhb-dotfiles-drift`, and macOS to
`~/Library/Logs/tbhb-dotfiles-drift.log`. Loading takes one manual apply
per host.

Decisions
- Chose a read-only report over an unattended update after three review
  rounds found ways an unattended apply could write files it must leave
  alone. Updating stays a manual apply.
- Chose `git` alone over `chezmoi status`, which runs every `modify_`
  script, even an ignored one.
- Chose a fixed one-line output with an exit code, which a log alert can
  match without parsing.
- Chose a private fetch ref over `FETCH_HEAD`, which another fetch in
  the same tree can overwrite.
- Skipped the job for a home path with whitespace, quotes, a backslash,
  `%` or `$`, in place of escaping it for `systemd` and the shell. The
  units, the agent file, and the loader render empty there.
- Set `SyslogIdentifier` because the host log collector keys journal
  lines on that field.

Needs human judgment
- The host log collector misses these lines today. On Linux the journal
  allowlist in the ops `host_telemetry` role matches only fixed
  identifiers and system units, and the identifier needs adding there.
  On macOS no collector exists. Whether the collector can read user
  journals is unverified.
- On Linux the timer runs only while the user manager is alive.
  Lingering on each host is a separate request.

Risk
Open tech debt:

- The job compares the source only, not live home files.
- Nobody has tested live loading or log collection.
- The fetch also writes objects and ref logs.
- The path guard misses Unicode spaces and backticks.
- No test catches an extra `FETCH_HEAD` read.
- On `git` before 2.39, the job prints `error=symbolic_ref`.
- With no user manager or login session, the loader warns and exits 0,
  and loading waits for a unit change.

To stop the job, unload `dev.tbhb.dotfiles-drift` with `launchctl` or
run `systemctl --user disable --now tbhb-dotfiles-drift.timer`.

Verification
`bazel test //...` passes, except a local `//:reuse_test` miss on
ignored files.

The test runs the script in a throwaway origin, clone, and home.
Wrappers fail it on any writing `git` verb, any chezmoi call but
`source-path`, or any run of a `run_onchange_` or `run_always_` script.
Cases cover sync, behind, ahead, edits, an untracked `modify_` script,
off `main`, a branch aliased to `main`, detached, and a tag named
`main`. Others cover a concurrent fetch, noisy fetch output, an
unchanged index under an `fsmonitor` hook, inherited `git -c` and
`GIT_CONFIG_*` settings, a failing source lookup, fetch or
`symbolic-ref`, and `devcontainer` runs of the script and the loader.
Rendering checks cover empty output in a `devcontainer` and for odd home
paths, escaping in the agent file, and `systemd-analyze verify` where it
exists.

It fails when a mutation adds a merge, an apply, a `run_always_` call, a
`chezmoi status` call, or fetch output on stdout. Removing a scrub, the
lock or hook flags, `--no-tags`, `--no-recurse`, a `devcontainer` exit,
the odd-path skip, or the agent-file escape also makes it fail.

Generated-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-opus-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-24T22:36:43Z;subagent=sha-256-64:d6a3aa5c8a2fb50c;surface=cli
Assisted-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;started_at=2026-11-15T17:46:19Z;surface=cli
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