Skip to content

Add role hooks and fnox key resolution to safe - #85

Merged
technicalpickles merged 1 commit into
mainfrom
safe-role-hooks
Oct 22, 2026
Merged

technicalpickles merged 1 commit into
mainfrom
safe-role-hooks

Conversation

@technicalpickles

@technicalpickles technicalpickles commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • safe now sources config/agent-safehouse/role-<role>.sh after the tool's hook, so the role can set env and add rules at run time, not just ship a static .sb.
  • Hooks append generated rules with safe_profile_add. The socket grants use it too, so there's one generated profile per run instead of a socket-only one.
  • role-work.sh exports short-lived AWS credentials for AWS_PROFILE (skipped when unset, and a lapsed SSO login warns instead of failing) and grants one docker socket when SAFE_DOCKER=1. role-work.sb gets the sorbet and rubocop cache grants.
  • SAFE_FNOX_KEYS names secrets that safe resolves with fnox export and passes through, so callers can stop wrapping safe in fnox exec. The prime-agent profile defaults it to OPENROUTER_API_KEY.

This is what lets a per-tool wrapper script go away: safe prime-agent gets the same setup however it's launched.

Notes for review

  • The private root (~/.local/share/safe/<tool>) is now created for any tool safe runs, not only tools with a .sh, because role hooks use it (the docker config copy).
  • AWS credentials now reach every tool under the work role when AWS_PROFILE is set, not just prime-agent.
  • Hooks run unsandboxed. role-work.sb already denies sandbox writes to the dotfiles worktree they live in. ADR 0064 says so.

Test plan

Ran bin/safe against its own config copy with the real safehouse, from an unsandboxed terminal:

  • With AWS_PROFILE set, the AWS credential vars and a SAFE_FNOX_KEYS secret are set inside the sandbox, and ~/.aws stays unreadable.
  • SAFE_DOCKER=1 makes docker version work through the granted socket, and the copied config has no auths. Without it, docker can't connect.
  • safe prime-agent --version runs under the profile, and no generated profiles are left in $TMPDIR.

Also ran it with a stubbed safehouse and aws to check the home role adds nothing and a missing fnox key warns and is skipped. A full prime-agent session (daemon, kernel venv, a model call) needs this merged and deployed first, so that's still to do.

🤖 Generated with Claude Code

role-<role>.sh is sourced after the tool's hook, so the work role can export
AWS credentials from AWS_PROFILE and opt in to one docker socket. Hooks add
generated rules with safe_profile_add, which replaces the socket-only profile.
SAFE_FNOX_KEYS resolves secrets with fnox export, so callers don't need to wrap
safe in fnox exec.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@technicalpickles
technicalpickles merged commit 1deba0e into main Oct 22, 2026
1 check passed
@technicalpickles
technicalpickles deleted the safe-role-hooks branch October 22, 2026 21:06
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