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
{{ message }}
Repository navigation
SSPI should be checked prior to prompting for credentials #3615
Currently ntlmReAuth in ntlm.go calls ntlmGetCredentials prior to testing if SSPI already provides access. It would be preferable to attempt authentication using SSPI first and only prompt the user for credentials if SSPI fails. Without creating a Windows Credential with the Git Credential Manager, every access to LFS prompts for a username and password and then succeeds when you enter nothing and simply hit enter. Pre-checking the SSPI credentials would prevent this from occurring by allowing the SSPI authentication to occur without a user prompt.
I think this should be a pretty simple change, but I am not aware enough of the overall design around the code to be certain of making the change myself.
The creds could also be checked to make sure it's the proper return for no credentials being provided by Git Credential Manager. This would prevent excessive login attempts as environments not using SSPI would only have the SSPI auth failure when the git credential manager does not have a record for the location. After git credential manager stores the credentials, they would be used prior to attempting the SSPI authentication in the future.
I will admit to not being very familiar with NTLM, but it sounds like you're describing a situation analogous to Kerberos: you have some sort of cached token that can be accessed without needing a username and password, and as long as that authentication succeeds, no prompt for credentials is necessary.
I definitely think that this would be great to fix, but since I don't have access to a Windows domain controller, I can't fix it myself. The NTLM code was contributed by someone else and I don't have a way to test it. If you're interested in looking at the code, I'm happy to provide helpful feedback and answer any questions you might have. The NTLM code is generally pretty easy to find with a git grep -i ntlm, and hopefully it's not too complex.
My only request here is that this function with any credential manager, not just the one with Git for Windows. It may be the case that users are using other credential managers or non-Windows machines with a Windows domain and we should make sure that continues to work well.
Ok, so the part I was unsure about is how exactly you are making the request and how to make the attempt in such a way that it can still make the request with the provided credentials if it fails. I'm also not sure exactly what the client c is going to provide from the abstract credHelper when there is no record. It might also be possible to sidestep it somewhat by using SSPI rather than NTLM in the lfs.{env}.access setting.
The actual code for working with SSPI is actually already in after #2871, so all that is actually needed is managing to try a call to ntlmAuthenticateRequest with nil as the cred. When ntlmAuthenticateRequest is passed nil as the cred on Windows, it uses sspiCreds, err = ntlm.AcquireCurrentUserCredentials() to get the credentials for the active user and logs in with them.
I think what you may want to do is adjust the getGitCreds function to stuff in a special credential helper at the beginning that returns nil for the credentials if we're using NTLM. If it fails (which it will know because it got a Reject call), then it should not return the same credentials.
Either that or always pass the access type to the credential helper and always include the special NTLM helper at the beginning, ignoring it if the access type isn't NTLM.
Ok, yeah, I was looking in the wrong spot. Realized that when I actually went to build the code. The code I thought was doing the prompt wasn't what I thought it was initially.
The code that causes the prompt is the call to the credential helper. We call git credential fill (or git credential reject, as appropriate), and git credential is the program that actually prompts.
Ok, so I see two possible fixes now that I understand the code a bit better. The first is simple and pretty easy, but a little less fault tolerant. The second is more complicated, but a bit more resilient.
The simpler version would be to add a new access.Mode for SSPI specifically. It would still hit most of the NTLM code paths, but it would bypass the credential manager entirely as SSPI doesn't use credential manager. The draw back is that if the mode is set to SSPI and we aren't actually able to auth via SSPI, it's going to not be able to authenticate without trying something else (though perhaps failing SSPI could cause the mode to switch back to something else).
The more durable approach would be to delay the call to getGitCreds until further down the process. This should be possible since access.Mode NTLM is already using a different code path, but it would mean making the code further different from the non NTLM/SSPI code paths and would lead to somewhat misleading use of getCreds since the getCreds would return junk for NTLM/SSPI.
Any thoughts on preference between the two options?
I think something like the latter is probably a better solution. We'll want to be able to fall back to using a username and password if SSPI fails and adding a new mode for SSPI wouldn't allow that to happen.
We can delay the call to getGitCreds for NTLM, although, as I mentioned, it may be easier to have that call return nil for the creds the first time and only prompt if that fails.
Couldn't we do something with c.Endpoints.SetAccess(newAccess) to change away from SSPI if it fails? It looks like it is already doing something about possibly changing the access type if there is an AuthError. Sorry if this is overly basic, I'm not familiar with go, so I'm not 100% certain I'm reading this stuff correctly.
Theoretically, that's possible, but it requires getAuthAccess to be able to guess which one we should use. Currently, it doesn't know anything about that, and that information isn't really available from the server; it's more of client information about which credentials we'd like to use, since the actual protocol is the same either way, we're just using the built-in Windows credentials or ones we prompt for ourselves.
Therefore, it makes more sense to use a credential-based solution, since this is really about choosing the right credentials to use.
Ok, so I've made quite a bit of progress I think, but I'm a bit confused by the function doWithCreds in auth.go. It takes in a bunch of credentials but only seems to use them on the NTLM call, how do non-NTLM connections get the credentials?
What I'm trying to build is a wrapper to encapsulate the credentialHelper, creds and URL so that the wrapper is passed around instead of the set of values. Then the wrapper can be used to do the fill whenever we actually need to make use of the credentials but has all the setup done before hand, but I'm not sure if what I'm doing will work with the non-NTLM paths since I can't find how they are consuming credentials.
Just FYI, you can be confident that our testsuite adequately exercises the Basic auth paths and the credential helpers, so if you're unsure about how the non-NTLM paths work, you can run make integration and it will tell you if you've broken anything. You can also instrument those paths and run the testsuite (or use the test server) and see what they output.
I haven't actually been able to get make working right on my local environment. It's giving me flack about something to do with goimporters and what looks like some kind of version reporting module for go that I don't have and can't seem to find, so make is failing to run at all for any purpose.
goimports should be optional, so nothing should go wrong if you don't have it. On Windows, you do need goversioninfo so that we can embed the version number into the binary in the way Windows wants. You can probably do go install github.com/josephspurrier/goversioninfo and if $GOPATH/bin is in your path, it will be picked up automatically.
FYI, it turned out to be go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo but your tip gave me enough to go on to find it. That said, the output from make test doesn't make any sense to me. I get a bunch of \ and it ends with make: *** [lint] Error 1. After a big block of stuff at the start about goimport.
Integrate gets file locking issues after the builds followed by inability to find lfstest-gitserver.exe
Activity
AJH16 commentedon Apr 17, 2019
The creds could also be checked to make sure it's the proper return for no credentials being provided by Git Credential Manager. This would prevent excessive login attempts as environments not using SSPI would only have the SSPI auth failure when the git credential manager does not have a record for the location. After git credential manager stores the credentials, they would be used prior to attempting the SSPI authentication in the future.
bk2204 commentedon Apr 17, 2019
Hey, thanks for writing in.
I will admit to not being very familiar with NTLM, but it sounds like you're describing a situation analogous to Kerberos: you have some sort of cached token that can be accessed without needing a username and password, and as long as that authentication succeeds, no prompt for credentials is necessary.
I definitely think that this would be great to fix, but since I don't have access to a Windows domain controller, I can't fix it myself. The NTLM code was contributed by someone else and I don't have a way to test it. If you're interested in looking at the code, I'm happy to provide helpful feedback and answer any questions you might have. The NTLM code is generally pretty easy to find with a
git grep -i ntlm, and hopefully it's not too complex.My only request here is that this function with any credential manager, not just the one with Git for Windows. It may be the case that users are using other credential managers or non-Windows machines with a Windows domain and we should make sure that continues to work well.
AJH16 commentedon Apr 17, 2019
Ok, so the part I was unsure about is how exactly you are making the request and how to make the attempt in such a way that it can still make the request with the provided credentials if it fails. I'm also not sure exactly what the client c is going to provide from the abstract credHelper when there is no record. It might also be possible to sidestep it somewhat by using SSPI rather than NTLM in the lfs.{env}.access setting.
The actual code for working with SSPI is actually already in after #2871, so all that is actually needed is managing to try a call to ntlmAuthenticateRequest with nil as the cred. When ntlmAuthenticateRequest is passed nil as the cred on Windows, it uses
sspiCreds, err = ntlm.AcquireCurrentUserCredentials()to get the credentials for the active user and logs in with them.bk2204 commentedon Apr 17, 2019
I think what you may want to do is adjust the
getGitCredsfunction to stuff in a special credential helper at the beginning that returnsnilfor the credentials if we're using NTLM. If it fails (which it will know because it got aRejectcall), then it should not return the same credentials.Either that or always pass the access type to the credential helper and always include the special NTLM helper at the beginning, ignoring it if the access type isn't NTLM.
AJH16 commentedon Apr 17, 2019
Ok, yeah, I was looking in the wrong spot. Realized that when I actually went to build the code. The code I thought was doing the prompt wasn't what I thought it was initially.
AJH16 commentedon Apr 17, 2019
Where is the code that would actually cause the user to be prompted for a credential?
bk2204 commentedon Apr 17, 2019
The code that causes the prompt is the call to the credential helper. We call
git credential fill(orgit credential reject, as appropriate), andgit credentialis the program that actually prompts.AJH16 commentedon Apr 17, 2019
Ok, so I see two possible fixes now that I understand the code a bit better. The first is simple and pretty easy, but a little less fault tolerant. The second is more complicated, but a bit more resilient.
The simpler version would be to add a new access.Mode for SSPI specifically. It would still hit most of the NTLM code paths, but it would bypass the credential manager entirely as SSPI doesn't use credential manager. The draw back is that if the mode is set to SSPI and we aren't actually able to auth via SSPI, it's going to not be able to authenticate without trying something else (though perhaps failing SSPI could cause the mode to switch back to something else).
The more durable approach would be to delay the call to getGitCreds until further down the process. This should be possible since access.Mode NTLM is already using a different code path, but it would mean making the code further different from the non NTLM/SSPI code paths and would lead to somewhat misleading use of getCreds since the getCreds would return junk for NTLM/SSPI.
Any thoughts on preference between the two options?
bk2204 commentedon Apr 17, 2019
I think something like the latter is probably a better solution. We'll want to be able to fall back to using a username and password if SSPI fails and adding a new mode for SSPI wouldn't allow that to happen.
We can delay the call to getGitCreds for NTLM, although, as I mentioned, it may be easier to have that call return
nilfor the creds the first time and only prompt if that fails.AJH16 commentedon Apr 17, 2019
Couldn't we do something with c.Endpoints.SetAccess(newAccess) to change away from SSPI if it fails? It looks like it is already doing something about possibly changing the access type if there is an AuthError. Sorry if this is overly basic, I'm not familiar with go, so I'm not 100% certain I'm reading this stuff correctly.
bk2204 commentedon Apr 17, 2019
Theoretically, that's possible, but it requires
getAuthAccessto be able to guess which one we should use. Currently, it doesn't know anything about that, and that information isn't really available from the server; it's more of client information about which credentials we'd like to use, since the actual protocol is the same either way, we're just using the built-in Windows credentials or ones we prompt for ourselves.Therefore, it makes more sense to use a credential-based solution, since this is really about choosing the right credentials to use.
AJH16 commentedon Apr 18, 2019
Ok, so I've made quite a bit of progress I think, but I'm a bit confused by the function doWithCreds in auth.go. It takes in a bunch of credentials but only seems to use them on the NTLM call, how do non-NTLM connections get the credentials?
What I'm trying to build is a wrapper to encapsulate the credentialHelper, creds and URL so that the wrapper is passed around instead of the set of values. Then the wrapper can be used to do the fill whenever we actually need to make use of the credentials but has all the setup done before hand, but I'm not sure if what I'm doing will work with the non-NTLM paths since I can't find how they are consuming credentials.
AJH16 commentedon Apr 18, 2019
Never mind, found it being set on the request earlier.
bk2204 commentedon Apr 18, 2019
Just FYI, you can be confident that our testsuite adequately exercises the Basic auth paths and the credential helpers, so if you're unsure about how the non-NTLM paths work, you can run
make integrationand it will tell you if you've broken anything. You can also instrument those paths and run the testsuite (or use the test server) and see what they output.AJH16 commentedon Apr 18, 2019
I haven't actually been able to get make working right on my local environment. It's giving me flack about something to do with goimporters and what looks like some kind of version reporting module for go that I don't have and can't seem to find, so make is failing to run at all for any purpose.
bk2204 commentedon Apr 19, 2019
goimportsshould be optional, so nothing should go wrong if you don't have it. On Windows, you do needgoversioninfoso that we can embed the version number into the binary in the way Windows wants. You can probably dogo install github.com/josephspurrier/goversioninfoand if$GOPATH/binis in your path, it will be picked up automatically.AJH16 commentedon Apr 19, 2019
FYI, it turned out to be
go get github.com/josephspurrier/goversioninfo/cmd/goversioninfobut your tip gave me enough to go on to find it. That said, the output frommake testdoesn't make any sense to me. I get a bunch of \ and it ends with make: *** [lint] Error 1. After a big block of stuff at the start about goimport.Integrate gets file locking issues after the builds followed by inability to find lfstest-gitserver.exe