You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some of my co-workers experience a weird authentication issue with
git-lfs.
[ ... ]
I wonder if there is some kind of mode which could give more inside on
what is going on in git-lfs.
Can you re-run the affected commands with `GIT_TRACE=1` and
`GIT_CURL_VERBOSE=1` in your environment and post the output here?
Note that your sensitive credentials will be included in the above, so
please be sure to remove them from the output before sharing publicly.
OK, this is quite interesting. It looks like your client _is_ sending an
authenticated request, i.e., that it contacted some credential helper
and found appropriate credentials for your remote:
> Authorization: Basic * * * * *
But, the server responded back with 401 Unauthorized
< HTTP/1.1 401 Unauthorized
Indicating what I think means that the server rejected your credentials.
First of all, I think that it would be good to double-check that you
have the right credentials configured in your credential helper.
Secondly, I think the reason that this is failing is that Git LFS
expects a 403 Forbidden instead of a 401 Unauthorized, which is the
standard HTTP response code that Git LFS looks for in order to determine
that the server _will not_ accept connections with the given
authentication.
So, I think that Git LFS sees the 401 Unauthorized, and says, "Oh,
that's the status code that I see when I need to _send_ credentials, so
I'll re-authenticate and send new ones." I think we ought to change Git
LFS such that it treats 401s as 403s iff its given in response to an
authenticated request.
@PastelMobileSuit is this something that you have interest in working
on?
@dryganets Thanks for the bug report! As @ttaylorr said, it looks like something is going wrong when we receive a 401 response, and we're currently looking into this on our end. A couple of things:
Based on the log you gave us it looks like Git LFS is sending credentials to VSTS, and the 401 response is being returned because those credentials are being rejected. Can you check to make sure your credentials are valid?
Following on from that, it looks like VSTS is returning a 401 when credentials are rejected, when it should instead be returning a 403. This isn't correct, so they'll need to update their API.
Something is definitely going wrong on our end as well when we receive the 401 response. To help us debug this, could you apply this diff and retry the same commands again with GIT_TRACE=1 and GIT_CURL_VERBOSE=1, and providing the same credentials? To apply the diff, you can just download the file and run git apply <filename> && ./script/bootstrap in your Git LFS source directory. You can then link Git LFS into your $PATH by running sudo cp ./bin/git-lfs $(which git-lfs). As before, you'll want to remove your credentials from the output before sharing it here.
I've done some digging into the LFS authorization code. In your case, Git LFS should be putting your credentials into the Authorization header for the HTTP request, and it should be formatted as Authorization: Basic username:password.
The authenticated HTTP requests are appearing in the log, so can you check in your non-anonymized version that the authorization header contains the username and password that you're expecting?
Hi, I have not anonymized auth headers in git-lfs logs. It is logged exactly as posted: 'Authorization: Basic *'. However I can see correct credentials in git logs, for example in the git clone log above, these were replaced by --token1-- and --token2--.
Is it possible that git-lfs has problems fetching credentials via credential helper? It should be using credential.helper=osxkeychain which seems to work fine for git.
To clarify there is a --token1-- which is incorrect. There is also --token2-- which also doesn't look like correct plaintext token, maybe it is hashed in some way? (Michael told me that the second HTTP request succeeded but token in the logs doesn't match the token in the toolchain.)
He can't find any trace of the --token1-- on his machine.
Could you list the possible sources of the tokens/password and clarify how do you choose over a few different auth sources present on the user machine.
It looks like there is a mismatch between the git order and git-lfs order in some corner case.
We will be glad to help to find out the source of the mismatch.
@dryganets@mrousal I did a little more digging and I think the token will actually be hashed instead of in plaintext, sorry about the misinformation on that! Also, thanks for the additional information on your setup with regards to the credential helper, that's very useful to know.
In regards to picking credentials, I believe with Basic Authentication, Git LFS should do the following:
Use credentials setup in a .netrc file in the user's home directory
If those are not present, use credentials provided directly in the remote URL
If no credentials are provided in the URL, default to the credential helper configured through Git
Git LFS prints a trace message if it was successfully able to fill in credentials from the credential helper. I'm not seeing that in the log you posted, which means LFS is either grabbing credentials from somewhere else before it gets to the credential helper, or something went wrong when querying the credential helper.
I've uploaded another patch file with some more robust debug statements, which I'm hoping will help us pinpoint the source of the issue and get to the bottom of what's happening. Could you apply this new patch file as before, and provide a new log?
Ok great, this explains it, I had some old password in ~/.netrc which was first git attempt before it went for creds from osxkeychain helper. After deleting entry from ~/.netrc git-lfs started to work.
So the inconsistency between git and git-lfs is that git goes for another source of creds after 401 failure from ~/.netrc but git-lfs fails.
Ok great, this explains it, I had some old password in ~/.netrc which
was first git attempt before it went for creds from osxkeychain
helper. After deleting entry from ~/.netrc git-lfs started to work.
Interesting. I wonder if we should retry a request with a different
password (i.e., one that _isn't_ from your `~/.netrc`) if the one from
your `~/.netrc` fails.
@git-lfs/core: do you have any thoughts?
Working through #3179 has exposed another issue with the way we currently handle .netrc credentials.
In Git LFS, a request has an 'Access Mode' that indicates how it should be authenticated, with an Access Mode of None indicating an unauthenticated request should be made. The code to retrieve credentials checks this access mode and bails out if it's None to prevent credentials from being added to this request. The sole exception to this is .netrc credentials, which are retrieved and added to the request before the access mode is checked.
As a result of this, if a host has an entry in the .netrc file, all requests made against that host will contain the .netrc credentials, regardless of whether or not they should be sent. Additionally, this also happens before we check the URL for credentials, meaning .netrc credentials will always take priority over those.
@ttaylorr and I have decided the best way to handle this is to write a new credential helper for retrieving .netrc credentials. The credential helpers are only queried when the request requires credentials, and this querying only occurs if credentials weren't provided directly in the URL. Additionally, because we support multiple credential helpers, Git LFS will retry a request with new credentials if one set of credentials fails. This should fix all the outstanding issues with .netrc credentials at once.
This has unfortunately uncovered another latent issue with regards to authentication and the way we track access modes (#3194). That issue will need to be fixed before we can make these .netrc changes.
Activity
ttaylorr commentedon Jul 16, 2018
dryganets commentedon Jul 18, 2018
Here is anonymized log for the failed attempt.
You could see that git passes while git-lfs fails.
ttaylorr commentedon Jul 19, 2018
PastelMobileSuit commentedon Jul 23, 2018
@ttaylorr I can spend some time looking at this!
PastelMobileSuit commentedon Jul 24, 2018
@dryganets Thanks for the bug report! As @ttaylorr said, it looks like something is going wrong when we receive a 401 response, and we're currently looking into this on our end. A couple of things:
GIT_TRACE=1andGIT_CURL_VERBOSE=1, and providing the same credentials? To apply the diff, you can just download the file and rungit apply <filename> && ./script/bootstrapin your Git LFS source directory. You can then link Git LFS into your$PATHby runningsudo cp ./bin/git-lfs $(which git-lfs). As before, you'll want to remove your credentials from the output before sharing it here.Thanks!
dryganets commentedon Jul 28, 2018
Hmm, the git is able to authenticate, the git-lfs uses wrong auth method for some reason.
Another thing is that it happens only for some people.
I ask Michal to try your patch out, sorry for delay in response.
mrousal commentedon Jul 30, 2018
log with the patch applied:
PastelMobileSuit commentedon Jul 31, 2018
@mrousal @dryganets Thanks so much for the response!
I've done some digging into the LFS authorization code. In your case, Git LFS should be putting your credentials into the Authorization header for the HTTP request, and it should be formatted as
Authorization: Basic username:password.The authenticated HTTP requests are appearing in the log, so can you check in your non-anonymized version that the authorization header contains the username and password that you're expecting?
mrousal commentedon Aug 2, 2018
Hi, I have not anonymized auth headers in git-lfs logs. It is logged exactly as posted:
'Authorization: Basic *'. However I can see correct credentials in git logs, for example in thegit clonelog above, these were replaced by--token1--and--token2--.Is it possible that git-lfs has problems fetching credentials via credential helper? It should be using
credential.helper=osxkeychainwhich seems to work fine for git.dryganets commentedon Aug 4, 2018
To clarify there is a --token1-- which is incorrect. There is also --token2-- which also doesn't look like correct plaintext token, maybe it is hashed in some way? (Michael told me that the second HTTP request succeeded but token in the logs doesn't match the token in the toolchain.)
He can't find any trace of the --token1-- on his machine.
Could you list the possible sources of the tokens/password and clarify how do you choose over a few different auth sources present on the user machine.
It looks like there is a mismatch between the git order and git-lfs order in some corner case.
We will be glad to help to find out the source of the mismatch.
PastelMobileSuit commentedon Aug 6, 2018
@dryganets @mrousal I did a little more digging and I think the token will actually be hashed instead of in plaintext, sorry about the misinformation on that! Also, thanks for the additional information on your setup with regards to the credential helper, that's very useful to know.
In regards to picking credentials, I believe with Basic Authentication, Git LFS should do the following:
.netrcfile in the user's home directoryGit LFS prints a trace message if it was successfully able to fill in credentials from the credential helper. I'm not seeing that in the log you posted, which means LFS is either grabbing credentials from somewhere else before it gets to the credential helper, or something went wrong when querying the credential helper.
I've uploaded another patch file with some more robust debug statements, which I'm hoping will help us pinpoint the source of the issue and get to the bottom of what's happening. Could you apply this new patch file as before, and provide a new log?
mrousal commentedon Aug 7, 2018
Ok great, this explains it, I had some old password in ~/.netrc which was first git attempt before it went for creds from osxkeychain helper. After deleting entry from ~/.netrc git-lfs started to work.
So the inconsistency between git and git-lfs is that git goes for another source of creds after 401 failure from ~/.netrc but git-lfs fails.
ttaylorr commentedon Aug 7, 2018
PastelMobileSuit commentedon Aug 7, 2018
@ttaylorr It sounds like that's the way Git works, so I'm 👍 for mirroring that behaviour
PastelMobileSuit commentedon Aug 23, 2018
Working through #3179 has exposed another issue with the way we currently handle
.netrccredentials.In Git LFS, a request has an 'Access Mode' that indicates how it should be authenticated, with an Access Mode of
Noneindicating an unauthenticated request should be made. The code to retrieve credentials checks this access mode and bails out if it'sNoneto prevent credentials from being added to this request. The sole exception to this is.netrccredentials, which are retrieved and added to the request before the access mode is checked.As a result of this, if a host has an entry in the
.netrcfile, all requests made against that host will contain the.netrccredentials, regardless of whether or not they should be sent. Additionally, this also happens before we check the URL for credentials, meaning.netrccredentials will always take priority over those.@ttaylorr and I have decided the best way to handle this is to write a new credential helper for retrieving
.netrccredentials. The credential helpers are only queried when the request requires credentials, and this querying only occurs if credentials weren't provided directly in the URL. Additionally, because we support multiple credential helpers, Git LFS will retry a request with new credentials if one set of credentials fails. This should fix all the outstanding issues with.netrccredentials at once.This has unfortunately uncovered another latent issue with regards to authentication and the way we track access modes (#3194). That issue will need to be fixed before we can make these
.netrcchanges.PastelMobileSuit commentedon Oct 9, 2018
I've just merged in a fix for this issue (#3307)! It should make it into the next release