DEV Community

johnettagaweraks
johnettagaweraks

Posted on

An SSH agent can hold a key without granting every destination

An SSH agent can hold a key without granting every destination

An SSH agent is convenient because a private key can stay in one process while many terminals request signatures. The usual risk is broad: if every client can ask the agent for the same key, a compromised jump host or session inherits access to every server that accepts it. OpenSSH added destination-constrained keys to narrow that delegation, but the constraint only helps when the key is loaded and managed correctly.

ssh-add(1) documents the -h destination_constraint option. The OpenSSH project's agent-restriction design says destination constraints were added in OpenSSH 8.9 and that keys are not constrained by default. When a constrained key is added, ssh-add looks up the destination host keys in the local known_hosts database and sends those restrictions to the agent.

How the restriction works

A destination constraint tells the agent that a key is intended for a particular host. The agent checks the signing request against the host-key identity it associated with the key. This is useful when an operator needs to use a key to a bastion or a named set of servers without making the same key usable for every connection made through the agent socket.

The first operational condition is a trustworthy host-key database. An unknown host cannot be safely encoded as a destination constraint. The agent also needs a current entry when a host key is rotated. Teams should provision and update known_hosts through configuration management instead of approving an unexpected key during an incident.

A constrained key does not remove the need for server-side authorization. The destination must still validate the authenticated user, enforce the authorized_keys options, and record the session. The constraint also does not make a stolen forwarding socket harmless if the same agent holds unconstrained keys. Inventory every loaded key, not only the one being tested.

Deployment pattern

Use separate keys for separate trust domains. Load the narrow key with one or more explicit -h values, keep its lifetime short, and avoid ssh-add defaults that turn a temporary key into a permanent one. For automation, prefer a dedicated agent socket or an SSH configuration that restricts the identity to the intended host. Remove the key when the maintenance task ends.

Review client configuration for ForwardAgent. Forwarding exposes the agent socket to the remote host, and destination constraints are the control that determines what a signing request from that side can reach. Log the host-key fingerprint used for the constraint and the identity of the person or job that loaded it.

A practical test should connect to an allowed destination and to a second destination that the key must not reach. Check the agent's key listing, the latest known_hosts entry, and the SSH server's authentication log. A failed connection with a clear agent denial is a better result than a successful login that reveals the constraint was never loaded.

OpenSSH destination constraints make delegated signing authority narrower. They are a useful second control behind host-key verification, least-privilege server accounts, and prompt removal of temporary credentials.

References

Top comments (0)