Using SSH
Result: an agent that authenticates to git hosts and remote machines with an
Ed25519 key that exists only inside Turnkey's secure enclaves. tk ssh agent
answers the OpenSSH agent protocol on a Unix socket and turns each challenge into a
policy-checked signing activity under the agent's own credential.
Inputs: the root profile (admin), the agent profile and AGENT_USER_ID from
provisioning-agent-identity, and the host or git host that will hold the public key.
Reference
- ssh:
ssh keys,ssh public-key, andssh agentrecords and default paths. - resources: the
policy createrecord that scopes signing to oneprivate_key.id. - activities:
activity listandpolicy evaluationson a failed signing activity.
Rules
- Root creates the Turnkey private key once with
ssh keys create, which also registers it in root's own registry. The agent host registers the same id withssh keys add, which needs nothing but the id. The private key stays in Turnkey's secure enclaves and there is nothing to back up on the host. - The signing policy is allow-always, scoped by
private_key.id(agents-sign-sshin policy-patterns.md). SSH waits for the signature synchronously, so an approval-gated policy makes every connection fail, not wait. - Socket access is signing authority. The socket lives in the principal's own home and is never forwarded off the host; under the broker path it is shared with the application alone, read-only, and nothing else crosses.
- Rotating the agent's API key needs no daemon restart when the daemon
runs from a profile; one started from the
TURNKEY_*environment must be restarted. - The registry is
~/.config/turnkey/tk.config.tomlunder theHOMEof the process that runsssh keys addandssh agent start. PinHOMEand--profileexplicitly where the daemon runs; a service with a different home sees an empty registry. - Host-key verification stays on.
tkreplaces the client key, not the trust in the server. - When a signing broker holds signing, do not create
agents-sign-*policies; run this workflow as the broker principal, taggedBROKER_TAGunder the deploying-signing-broker credential DENY. Step 2 namesBROKER_USER_IDforAGENT_USER_ID; step 4 startstk ssh agentunder the broker'sHOME; the application gets only the socket.
Instructions
Create the private key. Root, once:
<!-- example: ssh.create-key -->tk --profile admin --message-format json ssh keys create --name agent-sshSet
PRIVATE_KEY_IDto the record'sprivateKeyId; the policy and the agent host both need it. Rerunning with the same name registers the existing key instead of creating a second one.Allow the agent to sign with that key. Root:
<!-- shared: agents-sign-ssh --> <!-- example: ssh.policy -->tk --profile admin --message-format json policy create --name agents-sign-ssh --effect allow \ --consensus "approvers.any(user, user.id == '${AGENT_USER_ID}')" \ --condition "activity.type == 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2' && private_key.id == '${PRIVATE_KEY_ID}'"One policy per key. A key without a matching policy is still listed by the agent, and every signature with it is refused.
Register the key and publish the public half. The agent, in the home the daemon will use:
<!-- example: ssh.register -->tk --profile agent --message-format json ssh keys add --private-key-id PRIVATE_KEY_ID tk --profile agent --message-format json ssh public-key --key PRIVATE_KEY_ID | jq -r .publicKey > ./agent-ssh.pubInstall
agent-ssh.pubwhere the server expects it: the remoteauthorized_keys, or the git host's SSH key settings for the agent's account. That step is manual and outsidetk.Start the agent. The agent identity, with
<!-- example: ssh.agent-start -->--profileexplicit:tk --profile agent --message-format json ssh agent start export SSH_AUTH_SOCK=~/.config/turnkey/ssh-agent.sock tk --profile agent --message-format json ssh agent statusagent_startedcarriespid,socket, and thekeysfingerprints it serves;agent_status_reportrepeats them while it runs. An unattended deployment passes--key SSH_FINGERPRINTso the daemon serves one key; custom socket and pid-file paths are in ssh.Optionally, pin the destinations; no Turnkey policy can see the host a challenge came from. The daemon then signs an SSH login only after the client's
<!-- example: ssh.constrain -->session-bind@openssh.comnames a host key in the file, and git'sssh-keygen -Y sign -n git(gpg.ssh.program=ssh-keygen) only in an--allow-namespacenamespace on an unbound connection, a tk extension. An OpenSSH 8.9+ssh -Aforward arrives bound and gets neither; a relay (ssh -R,socat, a pre-8.9 forward) sends no bind, so share an--allow-namespacesocket only with the one boundary that signs git (another OS user, or one container or VM through a mount) and never forward or relay it beyond that boundary.gpg.ssh.program=tkneeds no socket (signing-git-commits); see ssh. Checkssh-keyscanoutput against the host's published fingerprints, and drop--allow-namespace gitwhen git does not sign through the socket:ssh-keyscan github.com > ~/.config/turnkey/ssh-allowed-hosts tk --profile agent --message-format json ssh agent stop tk --profile agent --message-format json ssh agent start --allowed-hosts-file ~/.config/turnkey/ssh-allowed-hosts --allow-namespace gitTo forward or relay the login socket, keep
<!-- example: ssh.constrain-forwarded -->--allow-namespaceoff it and sign git fromssh-git.sock, step 5's verify socket:tk --profile agent --message-format json ssh agent stop tk --profile agent --message-format json ssh agent start --allowed-hosts-file ~/.config/turnkey/ssh-allowed-hosts tk --profile agent --message-format json ssh agent start --allowed-hosts-file ~/.config/turnkey/ssh-allowed-hosts --allow-namespace git --socket ~/.config/turnkey/ssh-git.sockPoint clients at the socket and verify. Per repository, or per connection:
SSH_OPTS="-o IdentityAgent=~/.config/turnkey/ssh-agent.sock -o IdentitiesOnly=yes -o IdentityFile=./agent-ssh.pub" git config core.sshCommand "ssh $SSH_OPTS" ssh $SSH_OPTS user@hostIdentitiesOnlywith the public key file stops ssh from offering keys it finds on disk, so only the Turnkey key is ever presented.Verify the chain without a server, with OpenSSH tools only:
<!-- example: ssh.verify -->ssh-add -L ssh-keygen -Y sign -n git -U -f ./agent-ssh.pub ./payload.txt ssh-keygen -Y check-novalidate -n git -f ./agent-ssh.pub -s ./payload.txt.sig < ./payload.txtssh-add -Llists each served key asssh-ed25519 ... turnkey:PRIVATE_KEY_ID. The sign step writespayload.txt.sigthrough the socket; the check step accepts it. Both exit0or the key is not usable yet.Hand off. Report
PRIVATE_KEY_ID, the fingerprint and public key line, the policy id, the socket path, and the exactstartcommand the agent's process runs. Stop.
Verified by
| Examples | Test |
|---|---|
| ssh.create-key, ssh.policy, ssh.register, ssh.agent-start, ssh.verify | ssh_agent::using_ssh_register_serve_sign |
| ssh.agent-start | ssh_agent::agent_serves_every_registered_key_and_reports_its_lifecycle |
| ssh.constrain | ssh_agent_destinations::constrained_agent_signs_only_allowed_namespaces_and_reports_them |
| ssh.constrain | ssh_agent_destinations::constrained_agent_gates_ssh_userauth_by_server_host_key |
| ssh.constrain-forwarded | ssh_agent_destinations::constrained_agent_refuses_a_forwarded_hop |
| ssh.constrain-forwarded | ssh_agent_destinations::constrained_agent_signs_only_allowed_namespaces_and_reports_them |
| ssh.register | ssh::ssh_key_register_list_print_and_remove_by_every_name |
Troubleshooting
ssh agent startexits1withinvalid_input"the registry holds no SSH keys" or "no registered SSH key matches": step 3 was skipped or ran under anotherHOME. Register in the home the daemon uses.ssh agent statusexits1withcommand_error"ssh-agent is not running": nothing holds the pid file. Start it; if--socketor--pid-filewere given at start, give them here too.ssh agent startexits1withcommand_error"ssh-agent is already running on": stop that one first, or start on another--socket.ssh-keygen -Y signorsshfails with "agent refused operation" whilessh-add -Llists the key: check for the signing activity first. As root, runtk --profile admin --message-format json activity list --limit 5.- A failed
SIGN_RAW_PAYLOADactivity exists: Turnkey denied the signature. As root, runtk --profile admin --message-format json policy evaluations --activity-id ACTIVITY_IDon it; the usual cause is a policy scoped to a differentprivate_key.idor a consensus that names the wrong user. Do not start the daemon as root instead. - No
SIGN_RAW_PAYLOADactivity exists: the daemon, started from a profile, could not reload its credential for that signature. The registry under itsHOMEis unreadable or does not parse, its--profilewas deleted or no longer selects a credential for the key's organization, or the profile's API key file is unreadable. In the daemon'sHOME, runtk --profile agent --message-format json whoami; the daemon signs again once that succeeds, with no restart. - No activity,
whoamisucceeds, and--allowed-hosts-fileis set: the daemon refused a pre-8.9 client, an unlisted host key, a failed bind, an 8.9+ client's forwarded hop, or-Y signbound or outside--allow-namespace. ssh keys addexits1withinvalid_inputnaming another curve: the id is an existing non-Ed25519 key. Create one with step 1.- The key is served but the server rejects it: the public key line is not
installed on that host or account; compare it with
ssh public-key.
Related Skills
- signing-git-commits: sign commits with the same registered key, or with an OpenPGP key.
- managing-identities: the agent user, its profile, and rotating its API key.
- managing-policies: debugging the
agents-sign-sshscope withpolicy evaluations. - provisioning-session-agent: when the agent's key expires and renews.
- sidecar-patterns: where the daemon and socket live when the agent runs in its own OS user or container.