You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEAT] - Allow specifying identity file and certificate #2266
Is this feature for paramiko acting as a client or a server?
Client
What functionality does this feature request relate to?
Keys/auth
For client-side features, does this relate to a specific type of SSH server?
No response
If you're using paramiko as part of another tool, which tool/version?
No response
Desired behavior
If a server is set up to require SSH certificates there are cases where a single private key might have different certificates per server. Right now, as far as I can tell, there is no way to deal with this in Paramiko other than duplicating the private key so that the file names can be found automatically in Paramiko.
Since there is no way to specify the key and the certificate together, I know have to copy the key so that I have:
my_key
my_key_server1
my_key_server1-cert.pub
my_key_server2
my_key_server2-cert.pub
In an automated environment, with potential dozens of different servers, this can get really chaotic really quick.
Therefore I think Paramiko's connect method should have an explicit field to provide a certificate. The developer can then either provide a private key, or provide a certificate (and have the private key get found automatically) or provide both and have Paramiko use the specified combination.
bitprophet has been working on improving the flexibility of the key/auth tooling lately, per #387 and #23. Please check out the experimental new features described in the 3.2.0 paramiko CHANGELOG (including the new OpenSSHAuthStrategy implementation in Fabric 3.1.0) -- it's possible that they may let you do what you need here on the user side, and not require augmentation of paramiko itself.
I'm not deeply familiar with what the current features enable, so I can't say for sure whether they address this use case. We would greatly appreciate any investigation you might be able to do and report back here, though. The new features will be fully added and finalized over the next few minor versions, so now is a great time to make sure your needs are factored into the functionality.
Thanks for the reply. I checked those documents and I don't think what I'm looking for is currently possible. The basic AuthStrategy seems to be meant for subclassing. It takes an ssh_config but then all of the subclasses do not take a config and do not allow me to specify a key and certificate independently as far as I can tell.
@michaelochs Ok, thank you for the info. I'll raise this to bitprophet's attention, to see whether this is something already planned for a future stage of the auth rework, or if it's not been on his radar yet.
This sounds worth doing, I think I ran across a mention of this somewhat corner-case-y SSH feature a while ago, but yes, the current new-style auth classes do not cover it yet.
AFAIK this does not require any paramiko.SSHConfig patches, since what matters is the interpretation of IdentityFile/CertificateFile, not the parsing thereof.
However it may require updates to paramiko.AuthHandler (and some wrapping bits in paramiko.Transport), and/or paramiko.PKey and its subclasses, since IIRC those all tend to only handle the common case of "the cert and the key are always paired up / share filename prefixes / etc".
I still recommend trying to "drive" these lower level changes via some concrete AuthStrategy subclass, per above, as that is the API for auth things going forwards. The Fabric one may be the fastest way to get here (re: just being able to test existing, and new, behavior).
The AuthStrategy classes may also need a little bit of love to work with this, eg OpenSSHAuthStrategy is what would need to understand that you can have separate IdentityFile and CertificateFile paths for a single connection/auth attempt. It would probably then need to pass some new kwargs to the Transport, etc side of things.
Yeah I looked through the code a bit and did not see anything super obvious as there seem to be multiple places that make assumptions about the location. Only thing I could think of is that paramiko.PKey itself maybe should become a bit smarter and hold both, the certificate as well as the key. But all places consuming this would probably have to be update for this.
Activity
bskinn commentedon Jul 11, 2023
bitprophet has been working on improving the flexibility of the key/auth tooling lately, per #387 and #23. Please check out the experimental new features described in the 3.2.0 paramiko CHANGELOG (including the new
OpenSSHAuthStrategyimplementation in Fabric 3.1.0) -- it's possible that they may let you do what you need here on the user side, and not require augmentation ofparamikoitself.I'm not deeply familiar with what the current features enable, so I can't say for sure whether they address this use case. We would greatly appreciate any investigation you might be able to do and report back here, though. The new features will be fully added and finalized over the next few minor versions, so now is a great time to make sure your needs are factored into the functionality.
Thanks for the suggestion!
michaelochs commentedon Jul 11, 2023
Thanks for the reply. I checked those documents and I don't think what I'm looking for is currently possible. The basic
AuthStrategyseems to be meant for subclassing. It takes an ssh_config but then all of the subclasses do not take a config and do not allow me to specify a key and certificate independently as far as I can tell.I put together a simple SSH config:
But if I read that as config and pass it on to the
AuthStrategybase class that raises aNotImplementedError.So I looked for a concrete subclass that takes a key and a certificate as parameters, but I couldn't find that.
bskinn commentedon Jul 20, 2023
@michaelochs Ok, thank you for the info. I'll raise this to bitprophet's attention, to see whether this is something already planned for a future stage of the auth rework, or if it's not been on his radar yet.
bitprophet commentedon Jul 28, 2023
This sounds worth doing, I think I ran across a mention of this somewhat corner-case-y SSH feature a while ago, but yes, the current new-style auth classes do not cover it yet.
Those classes are mostly foundational in Paramiko and have a (still early, but workable) concrete subclass in Fabric here: https://github.com/fabric/fabric/blob/main/fabric/auth.py - I'd be curious if you are able to see an obvious patch (to that strategy, or a subclass of it, not sure I care offhand) that handles the logic you need here.
IIRC the OpenSSHAuthStrategy class has some TODOs in it for this particular situation, so it may be relatively straightforward?
bitprophet commentedon Jul 28, 2023
To clarify that a bit more:
paramiko.AuthHandler(and some wrapping bits inparamiko.Transport), and/orparamiko.PKeyand its subclasses, since IIRC those all tend to only handle the common case of "the cert and the key are always paired up / share filename prefixes / etc".michaelochs commentedon Sep 2, 2023
Yeah I looked through the code a bit and did not see anything super obvious as there seem to be multiple places that make assumptions about the location. Only thing I could think of is that
paramiko.PKeyitself maybe should become a bit smarter and hold both, the certificate as well as the key. But all places consuming this would probably have to be update for this.