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

Refactor libgit2 credential callback #17691

Merged
merged 2 commits into from
Aug 1, 2016
Merged

Refactor libgit2 credential callback #17691

merged 2 commits into from
Aug 1, 2016

Conversation

Keno
Copy link
Member

@Keno Keno commented Jul 29, 2016

Cleanly separate the SSHCredentials and UserPasswordCredentials to only use each type
when appropriate (the former for SSH keys, the latter for HTTPS for SSH password/keyboard-interactive
authentication). Previously the types would sometimes get confused and SSHCredentials
would be used for userpass authentication, since the field names happen to be a subset
(though they have different meaning, since the pass field in SSHCredentials is the
SSH key passphrase while the pass in UserPasswordCredentials is the remote user's
password).

Fix a couple issues in the process:

  • Allow externally passed in credentials to reach the right place
  • Don't skip using the SSH agent if there are two private packages

@Keno
Copy link
Member Author

Keno commented Jul 29, 2016

cc @wildart for review. Also, for anybody else testing locally would be appreciated, since this functionality is not yet tested.

@kshyatt kshyatt added the libgit2 The libgit2 library or the LibGit2 stdlib module label Jul 29, 2016
@@ -24,6 +24,153 @@ function mirror_callback(remote::Ptr{Ptr{Void}}, repo_ptr::Ptr{Void},
return Cint(0)
end

function authenticate_ssh(creds::SSHCredentials, cred::Ptr{Ptr{Void}}, username_ptr, schema, host)
Copy link
Contributor

Choose a reason for hiding this comment

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

could we give creds and cred more clearly distinguishable names? this is going to be bug-prone otherwise

Copy link
Member Author

Choose a reason for hiding this comment

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

cred -> libgit2credptr?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I think that would be better

@blakejohnson
Copy link
Contributor

Works for me!

p.count <= 0 && return true
p.count -= 1
return false
end
"Resets authentication failure protection count"
reset!(p::CachedCredentials, cnt::Int=3) = (p.count = cnt)
Copy link
Contributor

Choose a reason for hiding this comment

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

these probably shouldn't be no-ops?

base/libgit2/types.jl:62:reset!(p::AbstractCredentials, cnt::Int=3) = nothing
base/pkg/entry.jl:427:                            LibGit2.reset!(creds)

@Keno Keno force-pushed the kf/refactorlibgit2 branch 2 times, most recently from 0b3cf2d to 5c2d153 Compare July 29, 2016 17:17
Cleanly separate the SSHCredentials and UserPasswordCredentials to only use each type
when appropriate (the former for SSH keys, the latter for HTTPS for SSH password/keyboard-interactive
authentication). Previously the types would sometimes get confused and SSHCredentials
would be used for userpass authentication, since the field names happen to be a subset
(though they have different meaning, since the `pass` field in SSHCredentials is the
SSH key passphrase while the `pass` in UserPasswordCredentials is the remote user's
password).

Fix a couple issues in the process:
- Allow externally passed in credentials to reach the right place
- Don't skip using the SSH agent if there are two private packages
"Resets authentication failure protection count"
reset!(p::CachedCredentials, cnt::Int=3) = (p.count = cnt)
reset!(p::Union{UserPasswordCredentials, SSHCredentials}, cnt::Int=3) = (p.count = cnt)
reset!(p::CachedCredentials) = foreach(reset!, values(p.cred))
Copy link
Contributor

Choose a reason for hiding this comment

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

no 2-arg method for CachedCredentials?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not really sure what the point of retrying 3 times is anyway. The protocol is generally realiable and transport errors won't call the authentication callback anyway. I kept it this way because that's what was there before, but this is probably something to get rid of anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

the retrying 3 times was something @wildart needed to implement in order to work around the upstream API not being very flexible, IIRC

Copy link
Member

Choose a reason for hiding this comment

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

without reporting an authentication result back to credential callback, it is hard to figure out whether credentials are faulty or used several times on various urls. That is why credentials are used 3 times before falling back to user prompt.
@Keno Have you fixed authentication error reporting to credential callback?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have not. The count still doesn't make sense to me. Either the credentials are incorrect, in which case retying them 3 times doesn't help, or they're not in which case there's no problem. I agree that we have to record whether we tried or not since we don't get the error back, but I don't know why trying three times would help.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not suggesting the count be removed entirely, I'm just suggesting setting it to 1 would be sufficient.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. So what should we do right now? Merge this PR as is and leave the current strategy?

Copy link
Member

Choose a reason for hiding this comment

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

Fine, make it 1.

Copy link
Contributor

Choose a reason for hiding this comment

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

x-ref libgit2/libgit2#3761 (comment) where someone using the ruby bindings had reported spurious errors with a limit of 1

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing that out @tkelman, let's leave things as is for now and fix this mess upstream.

@Keno
Copy link
Member Author

Keno commented Aug 1, 2016

I'm gonna go ahead and merge this, we can make further changes later if we want.

@Keno Keno merged commit e2d2925 into master Aug 1, 2016
@tkelman tkelman deleted the kf/refactorlibgit2 branch August 1, 2016 17:07
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.

5 participants