Skip to content

[FEAT] - Allow specifying identity file and certificate #2266

Open

Description

@michaelochs

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.

Example:
my_key
my_key_server1-cert.pub
my_key_server2-cert.pub

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.

Anything else?

No response

Activity

  1. bskinn commented on Jul 11, 2023

    @bskinn
    Contributor

    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 suggestion!

  2. michaelochs commented on Jul 11, 2023

    @michaelochs
    Author

    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.

    I put together a simple SSH config:

    IdentityFile = /path/to/key
    CertificateFile = /path/to/certificate
    

    But if I read that as config and pass it on to the AuthStrategy base class that raises a NotImplementedError.

    So I looked for a concrete subclass that takes a key and a certificate as parameters, but I couldn't find that.

  3. bskinn commented on Jul 20, 2023

    @bskinn
    Contributor

    @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.

  4. added
    Feature request eval needed
    on Jul 20, 2023
  5. bitprophet commented on Jul 28, 2023

    @bitprophet
    Member

    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?

  6. bitprophet commented on Jul 28, 2023

    @bitprophet
    Member

    To clarify that a bit more:

    • 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.
  7. added and removed
    Feature request eval needed
    on Jul 28, 2023
  8. michaelochs commented on Sep 2, 2023

    @michaelochs
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions