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

Separate SSH prompting from ENV logic #23737

Merged
merged 8 commits into from
Sep 19, 2017
Merged

Separate SSH prompting from ENV logic #23737

merged 8 commits into from
Sep 19, 2017

Conversation

omus
Copy link
Member

@omus omus commented Sep 17, 2017

Separating some of the SSH callback logic so that allow_prompt only enables/disables interactive user prompting. Other changes include:

  • Avoid asking for a public key if the private key file does not exist
  • Avoid setting "~/.ssh/id_rsa" as the default private key if it does not exist (defaults to "" instead)
  • Avoid setting "$private_key.pub" as the default public key if it does not exist (defaults to "" instead)
  • Avoid invalidating the public key before the credentials should be "saved"
  • Remove private key missing warning. Either the user will be re-prompted or an error will be displayed
  • Avoid prompting for a public key as much as possible

Part of #20725.

Code should be logically identical to the previous revision.
The credential code is very careful not to modify the saved credentials
until the end of the callback. This was the only exception.
@omus omus added the libgit2 The libgit2 library or the LibGit2 stdlib module label Sep 17, 2017
Copy link
Contributor

@rofinn rofinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from a minor concern around test coverage this seems pretty good. This might also be a good time to fix some style issues with the rest of base, but I don't think it's huge priority.

end
if !isfile(privatekey)
response = Base.prompt("Private key location for '$prompt_url'",
default=privatekey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well fix the spacing to better fit with the existing base julia style (e.g., default=privatekey lined up with opening parenthesis).

Copy link
Member Author

@omus omus Sep 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up leaving the indentation for the default keyword as is as it matches the winprompt indentation.

# typically this will just annoy users.
if !isfile(publickey) && isfile(privatekey)
response = Base.prompt("Public key location for '$prompt_url'",
default=publickey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same spacing issue.

@@ -1825,7 +1825,6 @@ mktempdir() do dir
# User provides an empty private key which triggers a re-prompt
challenges = [
"Private key location for '[email protected]':" => "\n",
"Public key location for '[email protected]' [.pub]:" => "\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this test doesn't make sense now that we're only checking for the public key when the private key is provided, but don't we still need to check the public key prompting when a valid private key is provided?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one test I can add for public keys at this point. There's one round left of refactoring that will allow me to add a few more tests which currently cause the credential_loop to infinite loop.

if Sys.iswindows()
response = Base.winprompt(
"Your SSH Key requires a password, please enter it now:",
"Passphrase required", privatekey; prompt_username = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue here is prompt_username = false?

Copy link
Contributor

@rofinn rofinn Sep 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, and a few others. Looking at other places in base I'm guessing it should be.

response = Base.winprompt("Your SSH Key requires a password, ",
                          "please enter it now: Passphrase required",
                           privatekey; prompt_username=false)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the more extreme cases of this is in authenticate_userpass:

response = Base.winprompt("Please enter your credentials for '$prompt_url'", "Credentials required",
    isempty(username) ? p.username : username; prompt_username = true)

which would become the following in order to fit within the 92-limit:

response = Base.winprompt("Please enter your credentials for '$prompt_url'",
                          "Credentials required", 
                          isempty(username) ? p.username : username; 
                          prompt_username=true)

I think this is also acceptable in Base (I've been allowed to do this before):

response = Base.winprompt(
    "Please enter your credentials for '$prompt_url'", "Credentials required", 
    isempty(username) ? p.username : username; prompt_username=true)

I'll note that the last example just slightly exceeds the 92-limit but I think is probably the most readable.

I'll try to strike a balance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Note: currently one the tests cannot be run.
@omus
Copy link
Member Author

omus commented Sep 18, 2017

I'll merge once the CI passes.

@omus omus merged commit 77cbd18 into master Sep 19, 2017
@omus omus deleted the cv/libgit2-env branch September 19, 2017 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libgit2 The libgit2 library or the LibGit2 stdlib module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants