Repository navigation
Retry failed netrc cred requests - #3179
PastelMobileSuit wants to merge 1 commit into
Conversation
When a request is made with netrc credentials and that request fails, retry the request with non-netrc credentials
ttaylorr
left a comment
There was a problem hiding this comment.
Thanks, @PastelMobileSuit! I think that this is off to a good start. I left a single remark below that you may want to consider:
| } | ||
|
|
||
| func (c *Client) doWithAuth(remote string, req *http.Request, via []*http.Request) (*http.Response, error) { | ||
| func (c *Client) doWithAuth(remote string, req *http.Request, via []*http.Request, ignoreNetRc bool) (*http.Response, error) { |
There was a problem hiding this comment.
To make sure that I'm reading this change correctly: do you intend to mark when doWithAuth should and should not use the credentials found in ~/.netrc upon 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:
type CredentialHelper interface {
Fill(Creds) (Creds, error)
Reject(Creds) error
Approve(Creds) error
}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:
with an implementation of the CredentialHelper interface that fills from a user's ~/.netrc. In this case, Accept() would be a no-op, but Reject() could indicate that further calls to Fill() for a given hostname should fail immediately. A bad ~/.netrc file 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 ~/.netrc first, and then cascade down through other credential helpers without having to re-call this method and juggle the extra argument.
There was a problem hiding this comment.
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.
|
I'm with you on the credential helper approach. I think there are two
really clear benefits: [...]
Sounds good, and I agree.
My only concern is that this change will modify auth priorities and
the order in which we perform auth operations in this file.
That's fair; this code is called from lots of different places within
Git LFS, and the authentication procedures are both complex and fragile.
Maybe it would be worth documenting the order in which different things
happen under all possible circumstances, and saving your findings in
`docs`? I think that writing tests that encode the same would be
similarly helpful.
I think we'd want to make extra sure the change was safe before it
goes into a release.
Agreed, as is good practice to do on all changes, small or large.
|
When a request is made with netrc credentials and that request
fails, retry the request with non-netrc credentials
Closes #3130