Skip to content

fix: key unlock leases by native lock identity - #73

Merged
abruption merged 2 commits into
mainfrom
fix/unlock-lease-identity
Sep 29, 2026
Merged

abruption merged 2 commits into
mainfrom
fix/unlock-lease-identity

Conversation

@abruption

Copy link
Copy Markdown
Owner

Summary

Derive the unlock operation lease from the native lock it protects instead of from the caller's --codex-home spelling and environment.

Closes #53
Closes #60
Closes #64

Type

  • fix

Safety impact

Changes unlock coordination only; lock probing, owner validation, and signaling are unchanged. New coordination reasons (lock_directory_unavailable, coordination_parent_unavailable, coordination_parent_is_not_owned, coordination_path_changed) are reported inside the existing unlock_coordination_failed:<reason> form, and runtime_directory_is_not_private no longer occurs. The JSON schema is unchanged.

Checklist

  • npm run check passes
  • npm run lint passes
  • npm test passes (91 pass, 0 fail, 0 skipped; the case-variant test ran on a case-insensitive APFS volume)
  • npm run smoke:package passes
  • Commits follow Conventional Commits
  • Documentation is updated when behavior or output changed
  • No tokens, private paths, or unredacted process data are in the diff

Tests

Real advisory locks with fixture owners only:

  • concurrent CLI unlocks with different TMPDIR/XDG_RUNTIME_DIR send exactly one SIGTERM;
  • aliased homes (linked subdirectories, symlinked home, case variant) are refused while the owner stays alive;
  • a squatted 0777 codex-unlock-<uid> under TMPDIR no longer denies unlock;
  • a pre-created unsafe codex-unlock/ (0755 directory, symlinked directory, regular file) and a symlinked lease file are refused;
  • no lease directory is created when the lock directory is missing.

The three new CLI tests fail when src/coordination.ts is reverted to main.

Notes (maintainer decisions)

  • Lease location: codex-unlock now leaves a codex-unlock/ directory in the Codex home (beside thread-writer-locks) instead of a runtime/temporary directory. A per-user home location was considered, but it would require an environment override for tests, which reintroduces fix: environment-dependent coordination root lets concurrent unlocks bypass serialization #64. The Codex home shares the native lock's trust boundary.
  • Known limitations (documented in the safety race matrix): 0.4.0 and earlier do not see leases taken by this version, and vice versa, during an upgrade overlap; bind-mounting only thread-writer-locks produces the same key under different lease directories. If the canonical parent of the lock directory is owned by another user, unlock now refuses.
  • Group/other write permission on the parent is not checked: with umask 002, ~/.codex can legitimately be 0775, and an attacker with that access could already replace thread-writer-locks and sessions. The post-flock revalidation covers path replacement.

Derive the unlock operation lease from the canonical native lock
directory instead of the caller's --codex-home spelling and environment.
The lease file now lives in a codex-unlock-owned directory beside the
realpath of thread-writer-locks (normally $CODEX_HOME/codex-unlock) and
is keyed by the lock directory's device/inode and the thread UUID.

Symlinked homes, homes whose thread-writer-locks is a symlink to the same
target, and case-variant spellings now contend on one lease, and shells
with different TMPDIR or XDG_RUNTIME_DIR values are serialized. There is
no shared predictable temporary root left for another user to pre-create.

The parent must be owned by the current user, the lease directory must be
a private non-symlink directory, the lease file a private regular
single-link file, and the path must still name the locked inode after
flock; any failure refuses without signaling.

Leases taken by 0.4.0 and earlier are not seen by this version; the
safety race matrix documents that upgrade limitation.

Closes #53
Closes #60
Closes #64
@abruption
abruption force-pushed the fix/unlock-lease-identity branch from 1527bb5 to 1bd2f39 Compare September 29, 2026 00:04
@abruption
abruption merged commit 9e97142 into main Sep 29, 2026
23 checks passed
@abruption
abruption deleted the fix/unlock-lease-identity branch September 29, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant