7

Is it possible to use agent forwarding excluding all keys from being forwarded, except ones specifically stated? Alternatively, are there any ways to specify the order the keys are tried per session?

Using ssh-agent requires managing different sockets: https://superuser.com/questions/357602/use-a-specified-key-from-ssh-agent/401737#comment396923_358604

Are there any alternative agents that are more easily configurable?

For example:

Client A -->  ssh/agent-forwarding --> Server B -->  Server C 
                                            | 
                                            ------>  Server D 

I want to allow only one key in agent forwarding, allowing: A -> B -> C, and not A -> B -> D. Or at least specify the order the keys are tried.

(Edited for clarity after @jeff-ferland answer.)

3 Answers 3

1

I'm not aware of any agents that allow for the selective forwarding of keys as you've diagramed. Once a key is forwarded to a host, it's as if it were locally stored and can be used to authenticate against any host from there.

Looking at your question on another level, I have two ideas about what you might be trying to do:

  • Prevent somebody from authenticating to certain hosts without physical presence at a location.

If this is your goal, you cannot achieve it through control of authentication keys. You must control access through architecture and host restrictions such that no host which can be accessed remotely is capable of accessing a "safe" host.

  • "Protect" certain keys so they're not exposed.

If this is your goal, it's a misunderstanding of how to protect keys. Keys themselves are never forwarded. The ability to access the ssh agent to authenticate against a key is forwarded. However, that forwarding can only be taken advantage of while the forwarding is in place and only if the machine you've forwarded your agent to is run by an untrustworthy admin (voluntarily or through compromise). Thus in your diagram, unless you successfully log from machine B -> D and export forwarding from A -> B -> D, you are not at risk of exposing your credentials. You can forward from A -> B safely if you trust B.

I suggest you read a very verbose explanation of how forwarding works with diagrams if you're still unclear about the concept.

3
  • The goal was actually to get around the fact that the order the keys are used on "Server B" can't be easily customized during agent forwarding. Everything works using a regular .ssh session with .ssh/config. However, during agent-forwarding it seems you have no control over the ordering of the keys tried. The question was more for curiosity than practical/security concerns. Thanks for the detailed response and sorry for the confusion.
    – dgo.a
    Mar 17, 2012 at 18:42
  • it seems completely legitimate to trust B only for a specific task and thus only forward keys that can authenticate B-ish tasks to B. Thus you seem to be misunderstanding why "Protect certain keys so they're not exposed" is a reasonable goal. If the key can be used to authenticate, access to whatever it protects can be lost and then whether the key was exposed or not is irrelevant.
    – user239558
    Aug 3, 2015 at 20:19
  • This comment seems quite confused. If hosts are differently trusted, it's obvious that it shouldn't be possible to get from a host with lower trust to a host with higher trust!
    – user239558
    Sep 21, 2018 at 19:02
2

A feature like the one requested would belong in the ssh client.

It would be too difficult for the ssh-agent to figure out when it was communicating through a forwarding and when it was communicating with a local ssh client. Letting the server apply the restriction would be a security flaw. This leaves the ssh client as the only place such a feature could reasonably exist.

A quick look through the openssh source lead me to the client_request_agent function in clientloop.c. From what I see there I get the impression the ssh client simply forwards the raw byte stream without trying to understand which keys are being used. This means it would require a significant effort to add this feature to the client.

Another related feature, which could be added with less work would be an option to use two different agents. One agent could be used for authenticating with the server while another agent could be forwarded to the server.

Both would be useful features which I would make use of as well, but alas appears to not exist in openssh (yet).

1

If this problem comes up solely for app deployment using various private repos that require different keys:

You can skip agent forwarding altogether. Copy the files onto the machine containing the various keys, then rsync the cloned repos over to the server where deployment occurs.

Client A
    |
* private keys
* `git clone ...` private repos 
* /tmp/repos
      | 
      |  ------------> rsync/scp -----------> Server B

You could automate the process with alias, shell scripts, etc. Capistrano even has this built in. It's called the copy strategy: http://rubydoc.info/github/capistrano/capistrano/master/Capistrano/Deploy/Strategy/Copy

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .