Repository navigation
Retry failed netrc cred requests #3179
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,12 +234,13 @@ type getCredsExpected struct { | |
| } | ||
|
|
||
| type getCredsTest struct { | ||
| Remote string | ||
| Method string | ||
| Href string | ||
| Header map[string]string | ||
| Config map[string]string | ||
| Expected getCredsExpected | ||
| Remote string | ||
| Method string | ||
| Href string | ||
| Header map[string]string | ||
| Config map[string]string | ||
| Expected getCredsExpected | ||
| SkipNetrc bool | ||
| } | ||
|
|
||
| func TestGetCreds(t *testing.T) { | ||
|
|
@@ -364,6 +365,27 @@ func TestGetCreds(t *testing.T) { | |
| }, | ||
| }, | ||
| }, | ||
| "ignore ntlm with netrc": getCredsTest{ | ||
| Remote: "origin", | ||
| Method: "GET", | ||
| Href: "https://netrc-host.com/repo/lfs/locks", | ||
| Config: map[string]string{ | ||
| "lfs.url": "https://netrc-host.com/repo/lfs", | ||
| "lfs.https://netrc-host.com/repo/lfs.access": "ntlm", | ||
| }, | ||
| Expected: getCredsExpected{ | ||
| Access: NTLMAccess, | ||
| Endpoint: "https://netrc-host.com/repo/lfs", | ||
| CredsURL: "https://netrc-host.com/repo/lfs", | ||
| Creds: map[string]string{ | ||
| "protocol": "https", | ||
| "host": "netrc-host.com", | ||
| "username": "netrc-host.com", | ||
| "password": "monkey", | ||
| }, | ||
| }, | ||
| SkipNetrc: true, | ||
| }, | ||
| "custom auth": getCredsTest{ | ||
| Remote: "origin", | ||
| Method: "GET", | ||
|
|
@@ -395,6 +417,28 @@ func TestGetCreds(t *testing.T) { | |
| Authorization: basicAuth("abc", "def"), | ||
| }, | ||
| }, | ||
| "ignore netrc": getCredsTest{ | ||
| Remote: "origin", | ||
| Method: "GET", | ||
| Href: "https://netrc-host.com/repo/lfs/locks", | ||
| Config: map[string]string{ | ||
| "lfs.url": "https://[email protected]/repo/lfs", | ||
| "lfs.https://netrc-host.com/repo/lfs.access": "basic", | ||
| }, | ||
| Expected: getCredsExpected{ | ||
| Access: BasicAccess, | ||
| Endpoint: "https://[email protected]/repo/lfs", | ||
| Authorization: basicAuth("user", "monkey"), | ||
| CredsURL: "https://[email protected]/repo/lfs", | ||
| Creds: map[string]string{ | ||
| "protocol": "https", | ||
| "host": "netrc-host.com", | ||
| "username": "user", | ||
| "password": "monkey", | ||
| }, | ||
| }, | ||
| SkipNetrc: true, | ||
| }, | ||
| "username in url": getCredsTest{ | ||
| Remote: "origin", | ||
| Method: "GET", | ||
|
|
@@ -572,7 +616,7 @@ func TestGetCreds(t *testing.T) { | |
| client.Credentials = &fakeCredentialFiller{} | ||
| client.Netrc = &fakeNetrc{} | ||
| client.Endpoints = NewEndpointFinder(ctx) | ||
| endpoint, access, _, credsURL, creds, err := client.getCreds(test.Remote, req) | ||
| endpoint, access, _, credsURL, creds, _, err := client.getCreds(test.Remote, req, test.SkipNetrc) | ||
| if !assert.Nil(t, err) { | ||
| continue | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make sure that I'm reading this change correctly: do you intend to mark when
doWithAuthshould and should not use the credentials found in~/.netrcupon each request?If this is the case, it sounds like we start with credentials found in
~/.netrc, and (if those fail), move on to the credential helper, and then the URL credentials, and so on.That sounds like a reasonable plan to me. I have a few stylistic remarks regarding the new parameter to this function:
Do you think we could name the boolean argument positively? For example, instead of
ignoreNetrc(nit also, casing should beNetrcnotNetRc), could we name it asuseNetrc? I think that this makes the conditional on line L123 and L155 easier to grok. Instead ofif !ignoreNetrc, it would readif useNetrc, which is IMHO easier to read.Should this argument be added at all? I usually find that adding a boolean argument to a function is a smell indicating a split in behavior change that should instead be applied via a function extraction. Do you think that this is possible with the current code structure? I'm generally wary of changing code in this file, but I think that removing the 6th return value from
getCredsmight be a worthwhile tradeoff for the risk.More broadly, though, I'm wondering if this is the right way to go about this change. The credential helper that this function (
c.getCreds) returns has the following interface:and has an implementation that tries multiple
CredentialHelpers in succession until either (1) one succeeds or (2) all of them fail. That goes by the name of*CredentialHelpers. I'm wondering if we could replace:https://github.com/git-lfs/git-lfs/blob/v2.5.1/lfsapi/auth.go#L174
with an implementation of the
CredentialHelperinterface that fills from a user's~/.netrc. In this case,Accept()would be a no-op, butReject()could indicate that further calls toFill()for a given hostname should fail immediately. A bad~/.netrcfile could return an error anytime that it's asked to fill a request.This way, we could return one
CredentialHelper(backed by a*CredentialHelpers) that would transparently attempt the~/.netrcfirst, and then cascade down through other credential helpers without having to re-call this method and juggle the extra argument.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with you on the credential helper approach. I think there are two really clear benefits: the code will be cleaner, and URL credentials will be prioritized above .netrc credentials, which will make us more consistent with git.
My only concern is that this change will modify auth priorities and the order in which we perform auth operations in this file. I discovered first-hand while making this PR that even a simple change in ordering can cause some weird, unexpected behaviours (for example, switching the order of the conditionals at lines 123 and 127 causes some requests to fall through to the credential helper when they should be using .netrc instead). I think we'd want to make extra sure the change was safe before it goes into a release.