Skip to content

Wrap credential data to allow late credential prompting and update NTLM/SSPI to attempt SSPI login prior to prompting for credentials. - #3617

Merged
bk2204 merged 15 commits into
git-lfs:masterfrom
AJH16:master
May 8, 2019

Conversation

@AJH16

@AJH16 AJH16 commented Apr 18, 2019

Copy link
Copy Markdown
Contributor

This is very rough at the moment as I just picked up Go and have very little idea about it's structures, so I may be mishandling objects or over-exposing things, but this provides what should be a general framework for encapsulating the information related to credentials and making it so that the Fill can be called later in the process to support things like NTLM SSPI or anything else where an automatic credential should be tried prior to prompting the user, but where we can't take the initial action until after the credential helpers have been setup.

The code builds and the general concept should be sound as far as I can tell, but I can't guarantee anything towards proper function at the moment.

This is an attempt at resolving #3615.

@bk2204

bk2204 commented Apr 19, 2019

Copy link
Copy Markdown
Member

Sorry for not getting back to you sooner on this. I've taken a first pass over it, and I hope to give it a more comprehensive look on Tuesday.

@bk2204 bk2204 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Overall, this looks like it's moving in the right direction. I've left some general comments on some style and cleanliness stuff, but it seems generally sane.

It looks like CI has failed, so you'll likely want to investigate why that is and squash in some changes to address the cause of that failure.

Comment thread creds/creds.go Resolved
Comment thread lfsapi/auth.go Resolved
Comment thread lfsapi/ntlm.go Resolved
@AJH16

AJH16 commented May 1, 2019 •

Copy link
Copy Markdown
Contributor Author

It appears that the test for lfsapi is timing out after 10 minutes, but I'm not sure how anything I changed could have caused that. I'm not sure how I would even go about debugging the test. I think it might have something to do with the credential prompt and the test now being able to provide anything for the credentials, but I'm not sure how that works.

@bk2204

bk2204 commented May 1, 2019

Copy link
Copy Markdown
Member

I recently hit a test timeout as well and it was a hang in the code. Does the test hang when you run make && make test integration on your system?

@AJH16

AJH16 commented May 1, 2019

Copy link
Copy Markdown
Contributor Author

when I do make test integration I get a bunch of \ and then make: *** [lint] Error 1. When I do "go test ./lfsapi" it runs for 10 minutes and then times out.

@bk2204

bk2204 commented May 1, 2019

Copy link
Copy Markdown
Member

If you're seeing that failure in go test, then something in your code is causing a hang. That would probably be why CI is failing.

The make lint failure means that you may have introduced a new dependency, in which case you may need to do make vendor to include it.

@AJH16

AJH16 commented May 1, 2019

Copy link
Copy Markdown
Contributor Author

"make vendor" also fails with an error 1.

@bk2204

bk2204 commented May 1, 2019

Copy link
Copy Markdown
Member

Can you provide the actual error output? Are you using a version of Go that's at least 1.11?

@AJH16

AJH16 commented May 1, 2019 •

Copy link
Copy Markdown
Contributor Author

Apparently there is a temporary environment variable that I had to set to get vendor to work. GO111MODULE was "auto" and needed to be "on".

@AJH16

AJH16 commented May 1, 2019

Copy link
Copy Markdown
Contributor Author

But yeah, I know that it's the lfsapi test that's failing. I'm pretty sure it is because the timing of the credential prompt changed and the test execution doesn't provide anything for the input, but I'm not really sure how to make that happen as I don't really understand what the current test is actually doing.

@bk2204

bk2204 commented May 2, 2019

Copy link
Copy Markdown
Member

I think the problem is that something is getting called in a loop without making progress. For example, if I apply the following patch and run go test -v ./lfsapi, it prints “called credential helper” over and over:

diff --git a/lfsapi/auth_test.go b/lfsapi/auth_test.go
index 358e984e..0dcabdda 100644
--- a/lfsapi/auth_test.go
+++ b/lfsapi/auth_test.go
@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"net/http"
 	"net/http/httptest"
+	"os"
 	"strings"
 	"sync/atomic"
 	"testing"
@@ -292,6 +293,7 @@ func newMockCredentialHelper() *mockCredentialHelper {
 }
 
 func (m *mockCredentialHelper) Fill(input creds.Creds) (creds.Creds, error) {
+	fmt.Fprintf(os.Stderr, "called credential helper\n")
 	if found, ok := m.Approved[credsToKey(input)]; ok {
 		return found, nil
 	}

I'm not sure why this is, but it's definitely the cause of the hang.

@AJH16

AJH16 commented May 3, 2019 •

Copy link
Copy Markdown
Contributor Author

So I tracked it down but I don't know go well enough to know what the fix is. It appears the problem is that FillCreds does not end up updating the Creds property correctly. When I call in to FillCreds on auth.go:152, within the method I have the correct creds, but after the function returns, the creds on the object are empty.

It appears perhaps it needed a *. Changing that seems to have fixed it to be pass by reference.

Now it looks like i just have issues with ntlm_test - TestNtlmAuth and auth_test - TestGetCreds. Both seem to be related to what my initial thoughts were on why it would have issues and now that I see where they are I can probably work it out.

@bk2204

bk2204 commented May 3, 2019

Copy link
Copy Markdown
Member

So I tracked it down but I don't know go well enough to know what the fix is. It appears the problem is that FillCreds does not end up updating the Creds property correctly. When I call in to FillCreds on auth.go:152, within the method I have the correct creds, but after the function returns, the creds on the object are empty.

It appears perhaps it needed a *. Changing that seems to have fixed it to be pass by reference.

Oh, yeah, I missed that. Typically you want to make methods use the pointer version in Go (the version with the *). Glad you got it figured out.

AJH16 added 2 commits May 3, 2019 12:50
Fix test of NTLM credentials test to test both SSPI and non SSPI cases.
@AJH16

AJH16 commented May 3, 2019

Copy link
Copy Markdown
Contributor Author

Looks like something is still failing with the NTLM test, I hadn't been able to get that one working locally yet either and wasn't 100% clear on what it's doing. I'll do some more digging. It's the actual ntlm_test - TestNtlmAuth that seems to be the problem.

@AJH16

AJH16 commented May 3, 2019 •

Copy link
Copy Markdown
Contributor Author

Ok, so I have tracked down the problem. There apparently is not currently any SSPI test suite. Switching the order so that SSPI goes first resulted in unexpected requests to the test server which result in it crashing. I do not have the knowledge to implement an SSPI server side test emulator, so I'm not sure how we want to move forward.

Oh wait, it's just keeping count of the request number and faking a response, so I should be able to just provide a failure error for SSPI and get it to advance to the NTLM test. There still won't be an SSPI test suite, but that isn't here already.

@bk2204

bk2204 commented May 3, 2019

Copy link
Copy Markdown
Member

That's probably fine for now. If you're interested, there's a good doc that goes into depth about NTLM, should you want to synthesize a test.

@AJH16

AJH16 commented May 3, 2019

Copy link
Copy Markdown
Contributor Author

I'm not even sure if we could synthesis a good cross platform one since with SSPI the credential is going to be pulled from the active user. We'd be faking it hard to the point of probably being pretty close to no value anyway.

@AJH16

AJH16 commented May 3, 2019

Copy link
Copy Markdown
Contributor Author

It appears there is now some kind of fault in the ntlm_auth_test_nix, but I'm not able to debug that test as I don't have a *nix environment handy. Any idea what that test is supposed to be doing?

@bk2204

bk2204 commented May 3, 2019

Copy link
Copy Markdown
Member

I think that test is supposed to be checking that you can authenticate on Unix. In Go, you can have build commands at the top of the file to control the platform, and the _nix.go files are only built on non-Windows.

Part of the problem here is that SSPI doesn't work on Unix, because the credentials that are available on Windows won't exist, so the test is failing because it's getting nil credentials, which it doesn't expect. It may be a good idea to wrap the nil credentials code in something like if runtime.GOOS == "windows", since we know that code will never work.

@AJH16

AJH16 commented May 3, 2019

Copy link
Copy Markdown
Contributor Author

Yeah, sorry I didn't update earlier, but I figured that out and added a value to the ntlm_auth implementation that is platform specific to indicate if SSPI is available or not. Right now it's just true and false hardcoded, but it's possible it could have more complicated logic to determine in the future.

@AJH16

AJH16 commented May 3, 2019

Copy link
Copy Markdown
Contributor Author

Well, after updating the NTLM test to respond correctly when skipping the SSPI attempt on *nix, it's now made it past the unit tests. Guess we'll see how the rest of the test suite does. That is quite the set of tests.

@AJH16

AJH16 commented May 3, 2019 •

Copy link
Copy Markdown
Contributor Author

Ok, so I think things should be good now. I'm not sure how to make it so that the requested changes are addressed. I updated them in the code, but it seems that I did something wrong process wise for having them flag as clear. I was also able to test this in my local TFS environment and it successfully did a clone of an LFS enabled repo without prompting for a password and succeeded via SSPI.

I've got an environment where I can test it with a user whose SSPI credentials will fail too, but it takes a bit. I'll post back when I have completed that test.

@AJH16

AJH16 commented May 3, 2019

Copy link
Copy Markdown
Contributor Author

And doing a clone of an LFS enabled repository just worked on a machine that is not on a trusted domain using NTLM credentials without going through SSPI as well.

@AJH16 AJH16 changed the title Initial pass at wrapping the credential data Wrap credential data to allow late credential prompting and update NTLM/SSPI to attempt SSPI login prior to prompting for credentials. May 6, 2019
@AJH16

AJH16 commented May 6, 2019

Copy link
Copy Markdown
Contributor Author

Updated title of pull request now that this is an actual fix for the issue and has been more rigorously developed and tested.

@bk2204 bk2204 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great! Thanks for working on this, and sorry it's taken me so long to get back to you with a final review.

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