SSH as Auth Backend
SSH accounts as secret backends #115 focuses on generating ssh accessible user accounts from secrets stored in vault.
The SSH Auth backend however would allow to authenticate to vault by SSH connecting to a vault server with a trusted SSH key.
If understand correctly it would work analog to the cert Auth Backend.
The SSH Auth backend might be named ssh. An operator would configure it with trusted SSH public keys. These keys could be either user keys or host keys.
For example one could have a pool of cloud instances for which the SSH host keys were generated during cloud-init. After verifying these keys they would be used to configure auth/ssl also similar to the cert auth backend:
vault write auth/ssh/i-0e48fbcf display_name=i-0e48fbcf \
policies=web,prod \
key=@i-0e48fbcf_rsa_key.pub
To login from a cloud host:
sudo vault auth -method=ssh -key=@/etc/ssh/ssh_host_rsa_key
The sudo might be needed for accessing the private key /etc/ssh/ssh_host_rsa_key. The command would:
-
Determine SSH server address associated with vault. With a vault address
VAULT_ADDR='https://vault.example.com:8200'this might be undervault.example.com:8222 -
The command above would essentially copy the login response by SSH connecting an copying file
login:sudo scp -i /etc/ssh/ssh_host_rsa_key -P 8222 vault.example.com:loginThe output would look similar to other methods (adapted from userpass method):
{
"lease_id":"",
"renewable":false,
"lease_duration":0,
"data":null,
"auth":{
"client_token":"c4f280f6-fdb2-18eb-89d3-589e2e834cdb",
"policies":[
"root"
],
"metadata":{
"username":"i-0e48fbcf"
},
"lease_duration":0,
"renewable":false
}
}
.3. The auth cli would capture the client_token and use this in subsequent CLI commands and would take care of the normal things such as to lease renewals.
Blog post Writing a replacement to OpenSSH using Go (2/2) appears to suggest that this kind of capability could be implemented using golang.org/x/crypto/ssh.
Unfortunately I don't have any code up my sleeves for this nor can I commit to contribute this.
However I am curious whether such a capability would be desirable and fit into the vault architecture. In particular the idea to have vault listen at another address for ssh connections.
@henrjk This is a great idea! We looked at supporting this for 0.1, but its a fair bit more involved than the cert backend. The TLS handshake is broadly implemented, and luckily we can just overload our use of TLS for that. However for Vault, we would need to do the SSH handshake over TLS, which is not impossible, just tricky.
Basically, the handshake would need to be a less "interactive" as Vault is request/response oriented, without compromising the security. This can probably be done by sending the current timestamp in plaintext, as well as signed with the SSH key. The server can verify the signature is valid and done by a trusted cert, as well as ensuring the freshness of the timestamp to avoid a replay attack. It's not quite as good as the interactive random nonce approach of SSH, but may work well enough.
+1 for an SSH auth backend
2016-04-20 0:27 GMT+02:00 Jack Pearkes [email protected]:
Closed #193 https://github.com/hashicorp/vault/issues/193.
Does this mean it is no longer a desired feature? Or has this already been commited?
— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/hashicorp/vault/issues/193#event-633695774
Albert Cervera i Areny http://www.NaN-tic.com Tel. 93 553 18 03
@albertca
Some of the Vault issues were closed by mistake from a syncing software. We apologize for the confusion caused. We have reopened the issues that were closed and are investigating the problem that caused this. We are very sorry for the inconvenience.
Oh hey, I was just thinking this would be a fantastic feature and I searched the history for it. It sounds like it might be complicated by the need to proxy thru a TLS connection. But is there any chance it could be implemented as a new listener so it could be called with an SSH client? This would allow, for example, user authentication via a forwarded ssh-agent. I'm thinking of a workflow like:
user@workstation$ ssh-add .ssh/id_rsa
Password: ...
Identity added: .ssh/id_rsa
user@workstation$ ssh -A bastion-host
user@bastion-host$ export VAULT_TOKEN=$( ssh [email protected] )
user@bastion-host$ echo $VAULT_TOKEN
82c1cd4c-3c15-415f-991f-93a169d2e3a8
user@bastion-host$ vault token-lookup
Key Value
--- -----
accessor 6f73e74f-ec3f-4189-bae3-ac0a032924db
creation_time [... etc ...]
This would be incredibly useful and make life a lot easier for our users. I realize it would introduce a lot more complications to implement another listener... It could be implemented as a separate service on top of Vault of course.
To expand on what daveadams said, this kind of workflow would also allow for the use of smartcards for authentication. Unless I'm missing something, the easiest way to gain access to a Vault instance is to steal someone's token - but I (and hopefully a lot of other people) protect my SSH key better than I could ever protect an arbitrary, rotating token. Thus it would not just be more convenient, but far more secure.
+1 for an ssh auth backend
+1 are there any plans for implementing this soon?
@gites There are currently no plans to implement this.
@jefferai Is this because it's not a good idea, or because of a lack of development time, or...?
+1 for an ssh auth backend
There is definitely a lack of engineering capacity, so whether it's a good idea isn't even in the mix at the moment.
Is the issue still open to contribution? I would like to give it a try
@Srinivas11789 it's open but given Vault's HTTP workflow there isn't currently a good way to implement this.
Closing for now as it's not on the Vault team's radar. If @Srinivas11789 or others want to propose a design we're happy to evaluate.
@jefferai What about narrowing this idea to SSH Certificates as Auth Backend ?
At the moment we're using vault to create ssh certificates, it would also be nice to reuse those certificates for auth.
For this to work we could sign a timestamp like Armon suggested in https://github.com/hashicorp/vault/issues/193#issuecomment-101861953 and use eg https://github.com/go-fed/httpsig to sign/send/verify the ssh certificate with the signed timestamp.
Based on the principals in the certificate the user can get access.
Ideally this works transparantly with the user's ssh-agent, so vault auth -method=sshcert will just "work".
But also vault auth -method=sshcert -key=@id_rsa -cert=@id_rsa-cert.pub
I'm willing to work on this and see if a poc is possible.
For those interested I've made a ssh auth backend plugin on https://github.com/42wim/vault-plugin-auth-ssh Supporting ssh public keys and certificates.
Code reviewers welcome :)
Ideally this works transparantly with the user's ssh-agent, so
vault auth -method=sshcertwill just "work".
@42wim Is this possible right now? I'm kinda' stuck right now with your project. I have configured it successfully and can use the commands you show in the README. But (as far as I understand it right now) this command (which only works when issued being authenticated) will give me a token which I can use then to login in vault. What am I missing or what needs to be done to be able to login to vault from an unauthenticated host just by having a valid/accepted ssh private key in place?
@wernerfred maybe best open an issue on my repo to further discuss ?
quick response here now:
As my plugin now works, you create a role which has a ssh principal OR a ssh public key specified and has policies specified.
Then you "login" as below and you'll get a token which has the policies you defined, just like a normal vault token
vault write auth/ssh/login role=<role> public_key=@<publickey> nonce=<base64encoded randomdata> signature=<base64encoded ssh signature over random data>
About the ssh-agent, doing this with the normal vault command can not be done without hashicorp support as it needs modification in vault itself.
You can however use your own tool to do this and get a token (I'm using this internally), I'll try to put an example on my site later.