Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for in-memory SSH keys is missing #320

Open
fooker opened this issue Jun 14, 2018 · 7 comments
Open

Support for in-memory SSH keys is missing #320

fooker opened this issue Jun 14, 2018 · 7 comments

Comments

@fooker
Copy link
Contributor

fooker commented Jun 14, 2018

libgit2 has support for in-memory SSH keys. There is already git2::SSH_MEMORY to indicate that the credentials type is allowed, but a wrapper for git_cred_ssh_key_memory_new is missing.

@fooker fooker changed the title Support for in-memory SSH keys Support for in-memory SSH keys is missing Jun 14, 2018
@JMLX42
Copy link
Contributor

JMLX42 commented Jul 10, 2018

I this the corresponding PR was merged 7 days ago.
So I tried using 0.7.2which was released 5 days ago.

Yet I still get the following error message:

this version of libgit2 was not built with ssh memory credentials

@alexcrichton
Copy link
Member

@promethe42 can you share snippets for how to reproduce to poke around?

@JMLX42
Copy link
Contributor

JMLX42 commented Jul 10, 2018

@alexcrichton here you go:

pub fn git_credentials_callback(
    _user: &str,
    _user_from_url: Option<&str>,
    _cred: git2::CredentialType,
) -> Result<git2::Cred, git2::Error> {
    let user = _user_from_url.unwrap_or("git");

    if _cred.contains(git2::CredentialType::USERNAME) {
        return git2::Cred::username(user);
    }

    match env::var("GPM_SSH_KEY") {
        Ok(k) => {
            let key_path = path::Path::new(&k);

            if key_path.exists() {
                debug!("authenticate with user {} and private key located in {}", user, k);
                git2::Cred::ssh_key(user, None, key_path, None)
            } else {
                debug!("authenticate with user {} and private key stored in the GPM_SSH_KEY env var", user);
                git2::Cred::ssh_key_from_memory(user, None, &k, None)
            }
        },
        _ => Err(git2::Error::from_str("unable to get private key from GPM_SSH_KEY")),
    }
}

@JMLX42
Copy link
Contributor

JMLX42 commented Jul 16, 2018

@alexcrichton The issue comes from libgit2-sys. The GIT_SSH_MEMORY_CREDENTIALS flag has to be defined:

cfg.define("GIT_SSH_MEMORY_CREDENTIALS", "ON");

@JMLX42
Copy link
Contributor

JMLX42 commented Jul 16, 2018

@alexcrichton here is a PR that makes this feature actually usable: https://github.com/alexcrichton/git2-rs/pull/331

@JMLX42
Copy link
Contributor

JMLX42 commented Jul 28, 2018

@alexcrichton thanks for merging the PR!

Any chance we can get a 0.7.4 with this fix anytime soon?

@alexcrichton
Copy link
Member

sure thing, should be done now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants