Root on a shared SSH bastion logged in to production as an SRE who had used ssh -A; what had agent forwarding lent it?
answer
- a socket, not a key
- file permissions versus root
- valid while the session lasts
- sign as you, anywhere it works
basics
~20 sAgent forwarding lent root on the bastion a socket into the SRE's laptop agent: while her session was open, root could have the agent sign logins to any host her keys open. It could not copy the private keys.
solid answer
~50 s`ssh -A`, or `ForwardAgent yes`, asks the server to create a Unix-domain socket on the bastion and set `SSH_AUTH_SOCK` in the session; every connection to that socket is carried back over the SSH connection to the laptop's agent. The socket is protected only by file permissions, which root bypasses. So root can point its own `ssh` at her socket, list her keys and have her agent sign a public key login to any production host that trusts one of them, as her, from the bastion. It never gets the key material, and the access ends when her session closes, but anything it did in that window, such as planting its own key on a production host, outlives it. The fix is not to forward: reach the hosts with ProxyJump, or constrain what a forwarded key may do.
go deeper
Remember that -A lends the remote host a way to ask your agent for signatures, and that OpenSSH leaves forwarding off unless you ask for it.
Walk the chain: socket on the remote host, SSH_AUTH_SOCK in the session, channel back to the laptop agent, and why root on that host can use it.
Explain the blast radius: every host the forwarded keys open, for the session's lifetime, with persistence afterwards, and which fix you would apply first.
Treat forwarding as delegation to the least trustworthy host on the path, and argue for making the safe route the default for everyone.
## What forwarding sets up **Agent forwarding** extends a local `ssh-agent` to a remote machine so that `ssh` running *there* can authenticate onward with keys that stay on the laptop. It is requested with `ssh -A` or the client directive `ForwardAgent yes`; OpenSSH's client default is `ForwardAgent no`, and `ssh -a` turns it off for one connection. When it is on: 1. The client asks the server to provide agent forwarding for the session. 2. `sshd` creates a **Unix-domain socket** on the remote host, owned by the logged-in user, and puts its path in that session's `SSH_AUTH_SOCK`. 3. When any process on the remote host connects to the socket, `sshd` opens a channel back over the existing SSH connection. 4. The laptop's `ssh` hands that channel to the local agent, which answers exactly as it would answer a local client: list keys, sign. The SSH architecture RFC (RFC 4251, section 4.3) makes this strictly opt-in: a server must not open connections to the user's agent unless forwarding was requested. ## What root on the remote host can do The forwarded socket is protected by ordinary file permissions. The `ssh` manual states the consequence: users who can bypass file permissions on the remote host "can access the local agent through the forwarded connection". On the bastion in this scenario that means root, or anyone who has become root. - **List the keys** the agent holds, which reveals what the SRE can reach. - **Request signatures** for public key authentication, which is everything a login needs. - **Log in as her** to any host that trusts one of those keys, starting from the bastion, for as long as her session keeps the socket alive. - **Persist** by using that login to change something lasting on the target, such as adding a key of its own. ## What root cannot do | Root on the bastion | Possible? | Why | |---|---|---| | Get signatures from the agent | yes | the socket relays sign requests to the laptop | | Copy the private key | no | the agent never releases key material, only signatures | | Use the agent after she disconnects | no | the socket and its channel close with the session | | Read her passphrase | no | it was typed into `ssh-add` on the laptop, not the bastion | The manual's own phrasing is precise: an attacker "cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent". ## Why "cannot copy the key" is little comfort The protection is real but narrow. A signing service reachable by an attacker is, for login purposes, as good as the key while it is reachable. A long-running session through a bastion left open all day is a long window. The red-team result in the question is the expected outcome, not an exotic one: compromise of one shared host turned into authenticated access to every system the forwarded keys opened. Three properties make it worse than it sounds: - **Every loaded key is lent**, not only the one the session needed; forwarding exposes the whole agent. - **The window is long**: a bastion shell often stays open for hours, and every minute of it is usable. - **The logins look normal**: they come from the bastion, the one address internal hosts are configured to accept, and they authenticate with a genuine key, so access logs show the SRE logging in as usual. ## Reducing the exposure The options, roughly in order of strength: - **Do not forward.** Reach inner hosts with ProxyJump, which relays an encrypted connection through the bastion while authentication happens on the laptop; the bastion receives no socket at all. - **Forward less.** `ForwardAgent` also accepts the path of a different agent socket, so a second agent holding only one low-value key can be the one that is forwarded. - **Constrain keys.** `ssh-add -h` restricts which hosts a key may authenticate to and through; `ssh-add -c` demands a confirmation for each use; `ssh-add -t` shortens how long a key is loaded. - **Server policy.** The server can refuse forwarding entirely, a setting covered under server hardening. The SSH connection protocol RFC (RFC 4254, section 11) adds one more rule of thumb: disable agent forwarding to a host whose host key has changed without explanation.
- Does the danger end when the SRE logs out of the bastion?The forwarded socket disappears with the session, so new signatures stop. But whatever root did with the signatures it got persists: a login to a production host, a key added to an account there, a scheduled job. Closing the session ends the lending, not its consequences.
- Why doesn't ssh-add -c make forwarding safe?It makes every use of the key raise a confirmation prompt on the laptop, which helps, but the prompt shows the key and its fingerprint rather than which host the request came through. An attacker who times a request to coincide with the user's own logins gets it approved. OpenSSH's own write-up calls confirmation "somewhat easy to phish".
- Is forwarding to a host you administer yourself safe?Only as safe as that host's root account and everyone who can reach it while you are connected. Forwarding delegates signing power to the remote machine; if that machine is shared or later compromised, the delegation goes with it.
Agent forwarding is like lending your signet ring to a clerk in another office: while you stay on the line, anyone in that office who can reach the clerk can stamp documents in your name, but nobody there can make a copy of the ring.
- Root on the bastion can read the private key out of the forwarded agent.
- Agent forwarding is safe because the forwarded socket is owner-only.
- ssh -A copies the private key to the remote host for the session.
- Once the session closes, nothing the attacker did can persist.
- OpenSSH's client forwards the agent by default.