Skip to content

Retry failed netrc cred requests - #3179

Closed
PastelMobileSuit wants to merge 1 commit into
masterfrom
netrc-issue
Closed

PastelMobileSuit wants to merge 1 commit into
masterfrom
netrc-issue

Conversation

@PastelMobileSuit

Copy link
Copy Markdown
Contributor

When a request is made with netrc credentials and that request
fails, retry the request with non-netrc credentials

Closes #3130

When a request is made with netrc credentials and that request
fails, retry the request with non-netrc credentials

@ttaylorr ttaylorr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, @PastelMobileSuit! I think that this is off to a good start. I left a single remark below that you may want to consider:

Comment thread lfsapi/auth.go
}

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) {

Copy link
Copy Markdown
Contributor

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 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:

  1. Do you think we could name the boolean argument positively? For example, instead of ignoreNetrc (nit also, casing should be Netrc not NetRc), could we name it as useNetrc? I think that this makes the conditional on line L123 and L155 easier to grok. Instead of if !ignoreNetrc, it would read if useNetrc, which is IMHO easier to read.

  2. 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 getCreds might 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:

https://github.com/git-lfs/git-lfs/blob/v2.5.1/lfsapi/auth.go#L174

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.

@PastelMobileSuit PastelMobileSuit Aug 20, 2018 •

Copy link
Copy Markdown
Contributor Author

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.

@ttaylorr

ttaylorr commented Aug 21, 2018 via email

Copy link
Copy Markdown
Contributor

@PastelMobileSuit

Copy link
Copy Markdown
Contributor Author

I'm going to close out this PR, as @ttaylorr and I have decided that writing a new credential helper is the best way to go (more details on #3130)

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

Successfully merging this pull request may close these issues.

2 participants