Skip to content

fix: clear the 1Password socket on a session switch - #38

Merged
tbhb-agent merged 1 commit into
mainfrom
switch-client-hook
Nov 24, 2026
Merged

tbhb-agent merged 1 commit into
mainfrom
switch-client-hook

Conversation

@tbhb-agent

Copy link
Copy Markdown
Collaborator

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.

Opened-by: LLM effort=medium;harness=claude-code:2.1.331;model=anthropic:claude-sonnet-5-5;session=sha-256-64:5540cd94a5c67150;surface=cli
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

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
tbhb-agent requested a review from tbhb as a code owner November 24, 2026 21:00
@tbhb-agent
tbhb-agent merged commit af84e0e into main Nov 24, 2026
5 checks passed
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