Skip to content

fix: harden state after direct start modes exit - #16

Merged
eXPerience83 merged 5 commits into
mainfrom
agent/harden-direct-start-modes
Jul 26, 2026
Merged

fix: harden state after direct start modes exit#16
eXPerience83 merged 5 commits into
mainfrom
agent/harden-direct-start-modes

Conversation

@eXPerience83

Copy link
Copy Markdown
Owner

What changed

  • Add a shared run-direct-session wrapper for foreground direct sessions.
  • Route START_MODE=codex and START_MODE=shell through that wrapper instead of executing Codex or Bash directly.
  • Reapply secure-persistent-state whenever the direct foreground process exits.
  • Preserve the foreground process exit status unless credential hardening itself fails.
  • Install the wrapper in the Codex image.
  • Add smoke coverage for wrapper status preservation and for both direct tmux start modes restoring auth.json to mode 0600.
  • Record the security behavior in the changelog.

Why

The menu path already hardened persistent credentials after interactive actions, but the supported direct codex and shell start modes used exec on the foreground process. A token refresh or codex login could therefore leave auth.json group-readable on permissive TrueNAS dataset ACLs until the entire container restarted.

Impact

  • Direct Codex and login-shell deployments now receive the same post-session credential hardening as menu-launched sessions.
  • Normal interactive behavior and tmux persistence are unchanged.
  • A direct session still returns its original exit status; a hardening failure is surfaced as an error instead of being ignored.
  • No privileges, capabilities, mounts, networking settings or persistent paths change.

Validation

  • Bash syntax validation passed for the changed scripts.
  • The wrapper was exercised with a command exiting 23; it preserved that status and changed a deliberately permissive auth.json from 0660 to 0600.
  • Branch is based directly on current main with no unrelated changes.
  • AMD64 image build and runtime smoke tests pass in GitHub Actions.
  • CodeRabbit/Codex review findings are addressed.

Root cause

The direct tmux commands executed codex or bash --login themselves, so no parent process remained to invoke secure-persistent-state after they exited. The new wrapper remains as the parent and performs hardening from an EXIT trap.

Follow-up

After CI and review pass, merge this fix and retest the newly published edge image on TrueNAS. No stable release is created by this PR.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 193228b4-710e-4ec6-b520-759032a4ae6b

📥 Commits

Reviewing files that changed from the base of the PR and between 9606ce6 and 28addd3.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • images/codex/Dockerfile
  • scripts/attach-remote-dev-tmux.sh
  • scripts/run-direct-session.sh
  • scripts/smoke-test.sh
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (3)
**/*.md

⚙️ CodeRabbit configuration file

**/*.md: Check that documentation matches the implemented behavior and clearly distinguishes experimental edge builds
from stable releases. Flag outdated versions, unsafe deployment guidance and claims not proven by CI or testing.

Files:

  • CHANGELOG.md
scripts/**/*.sh

⚙️ CodeRabbit configuration file

scripts/**/*.sh: Review as production Bash. Check quoting, set -euo pipefail behavior, cleanup traps,
bounded retries and timeouts, non-interactive execution, idempotency and useful failure messages.
Flag commands that can hang, leak credentials, silently ignore failures or mutate persistent data unexpectedly.

Files:

  • scripts/run-direct-session.sh
  • scripts/attach-remote-dev-tmux.sh
  • scripts/smoke-test.sh
images/**/Dockerfile

⚙️ CodeRabbit configuration file

images/**/Dockerfile: Review for reproducibility, supply-chain security and minimal image growth.
Require pinned upstream versions and checksum or digest verification for downloaded binaries.
Flag secrets, floating base tags, unsafe remote-script execution, broken multi-architecture logic,
cache misuse, unnecessary packages and changes that weaken the secure-by-default runtime.

Files:

  • images/codex/Dockerfile
🪛 Shellcheck (0.11.0)
scripts/smoke-test.sh

[warning] 57-57: attempt appears unused. Verify use (or export if used externally).

(SC2034)


[info] 179-179: Expressions don't expand in single quotes, use double quotes for that.

(SC2016)


[info] 283-283: Expressions don't expand in single quotes, use double quotes for that.

(SC2016)

🔇 Additional comments (9)
scripts/run-direct-session.sh (1)

1-22: LGTM!

images/codex/Dockerfile (2)

54-54: LGTM!


63-66: LGTM!

scripts/attach-remote-dev-tmux.sh (1)

19-23: LGTM!

CHANGELOG.md (1)

49-49: LGTM!

scripts/smoke-test.sh (4)

29-35: LGTM!


52-86: LGTM!


174-187: LGTM!


247-288: LGTM!


Summary by CodeRabbit

  • Security

    • Improved credential-state protection for direct Codex and shell sessions by reapplying hardening when the session exits.
    • Added validation to ensure authentication files retain secure permissions.
  • Reliability

    • Direct sessions now preserve the original command’s exit status while reporting credential-hardening failures.
  • Testing

    • Expanded smoke tests to cover direct-session, Codex, and shell workflows.

Walkthrough

Direct Codex and shell tmux sessions now run through a wrapper that reapplies credential hardening after the foreground command exits. The wrapper is packaged into the image, and smoke tests verify command status, session termination, and auth.json permissions.

Changes

Direct session hardening

Layer / File(s) Summary
Wrapper and image integration
scripts/run-direct-session.sh, images/codex/Dockerfile
Adds command validation and exit-trap hardening while preserving command status; installs the wrapper as an executable image command.
tmux startup routing
scripts/attach-remote-dev-tmux.sh, CHANGELOG.md
Routes Codex and shell START_MODE sessions through the wrapper after changing to the workspace, and records the security behavior.
Direct-session smoke validation
scripts/smoke-test.sh
Tests wrapper status handling, dedicated tmux session cleanup, session exit detection, and hardened auth.json permissions for Codex and shell modes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Tmux
  participant DirectSession as run-direct-session
  participant ForegroundCommand as codex or bash --login
  participant PersistentState as secure-persistent-state
  Tmux->>DirectSession: start foreground command
  DirectSession->>ForegroundCommand: execute command
  ForegroundCommand-->>DirectSession: return exit status
  DirectSession->>PersistentState: reapply credential hardening
  PersistentState-->>DirectSession: return hardening status
  DirectSession-->>Tmux: return final status
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: hardening state after direct start-mode sessions exit.
Description check ✅ Passed The description covers what changed, why, impact, validation, root cause, and follow-up, with only the safety checklist omitted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/harden-direct-start-modes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@eXPerience83
eXPerience83 marked this pull request as ready for review July 26, 2026 20:43
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@eXPerience83
eXPerience83 merged commit 881f9c8 into main Jul 26, 2026
2 checks passed
@eXPerience83
eXPerience83 deleted the agent/harden-direct-start-modes branch July 26, 2026 20:49
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