Repository navigation
feat: PAT support -- private git support on http / https - #8805
Conversation
|
There are other configs in |
I think this is more related to #7787 ? What you want is to propagate those .gitconfig inside the engine, from what I understand ? What use do you have of those options ? |
|
hi @grouville , if i query: but, |
|
I normally install the binary via Aqua. |
Hi @sheldonhull, |
0d5b420 to
1cd78da
Compare
vito
left a comment
There was a problem hiding this comment.
Overall approach and implementation seems great 👍 - just a couple of comments, otherwise lgtm!
| Args: []dagql.NamedInput{ | ||
| { | ||
| Name: "name", | ||
| Value: dagql.NewString("gitAuthtoken"), |
There was a problem hiding this comment.
Not sure if this is still the case, but iirc these secret names are session-wide. So if you use two separate private repos in the same session it seems like these might clobber. Maybe just set a name that's a hash of the plaintext, like we do for the CLI?
There was a problem hiding this comment.
Secrets are stored per-client so that sort of clobbering shouldn't be an issue.
The only extremely obscure case I can think of that would be impacted is:
- You're using an SDK directly on the host (i.e. not just
dagger call) - You set your own secret that also happens to be named
gitAuthtoken
Not worth agonizing over, but yeah we could just set name to a sha256 of the plaintext to squash any possibility of that happening.
| return nil, err | ||
| } | ||
|
|
||
| isBitbucket := u.Host == "bitbucket.org" |
There was a problem hiding this comment.
Do we need to worry about any other hosts, like we do with GitHub enterprise? 🤔
There was a problem hiding this comment.
my host name could be different for azure devops based on a combination of the protocol with http or ssh, as well as the way dev.azure.com and visualstudio.com are both valid addresses (due to legacy url).
I don't have a ton of time, but if you get me an idea of what would help I can draft something out to help enhance this with dev.azure.com processing too
I use git-credential-manager for authorization still if that matters.
There was a problem hiding this comment.
Mmh, I do agree that we could miss some edge cases, but here it was changes that were part of #8778. Basically, the core git implementation was not passing the PAT properly, as bitbucket has another way of passing the auth tokens.
We could have some edge cases on github enterprise and some azure, but I added some tests https://github.com/grouville/dagger/blob/a924e0e9b054ece63086badc9c84142cd0bb11d0/core/integration/git_test.go. I tested azure, and github enterprise has already being used by users. I do think that this should be ok ; if it breaks we should then extend I agree 👍
| message GitCredentialResponse { | ||
| oneof result { | ||
| CredentialInfo credential = 1; | ||
| ErrorInfo error = 2; |
There was a problem hiding this comment.
nit (can be changed later): I think the gRPC way of doing this is to return an actual error from the function, rather returning nil as an error with a custom error field in the response
|
|
||
| // Handle token authentication | ||
| if s.token { | ||
| if s.credHelper { |
There was a problem hiding this comment.
nit: is there a way to get this from the client config instead?
as @vito mentioned above, we might have a problem with GH enterprise as well
7f0f4a9 to
5a61ab1
Compare
| // 5. Handle PAT auth | ||
| var authToken *core.Secret = nil |
There was a problem hiding this comment.
nit, not a blocker: do you think it would make sense to skip this if the user has an SSH auth socket setup? Slightly nice if so since there's a little bit of expensive work to retrieve the auth token that we may as well skip if we are just going to use the auth socket.
If there's a use case for having both in place or this is otherwise easier said than done, then no biggie
There was a problem hiding this comment.
I actually implemented a change, following your comment.
Now, we first parse the ref's scheme, and, based on that, the logic is now:
- if the person set an SSH socket explicitely, then load the socket
2.It not,
2.1 - if the ref's scheme is SSH, then load the SSH socket
2.2 - If the ref's scheme is HTTP(s), then try the PAT thing
The reason I wouldn't skip if the user has an SSH auth socket setup with this example:
dagger -m ssh://module-ref --dir https://github.com/grouville/daggerverse-private.gitSkipping the PAT when we can load the SSH token enforces users to be consistent on the ref types they use. I do agree that this has a cost, but it seems to be preferable, wdyt ?
Based on the ref's scheme, we use the corresponding auth type -- userland can then cache the tokens with their credential helpers if they want fast auth against them
| URLs: []string{remote.Remote}, | ||
| }) | ||
|
|
||
| _, err := repo.List(&git.ListOptions{Auth: nil}) |
There was a problem hiding this comment.
nit: should probably use ListContext so we can cancel the request if the call is canceled
| Args: []dagql.NamedInput{ | ||
| { | ||
| Name: "name", | ||
| Value: dagql.NewString("gitAuthtoken"), |
There was a problem hiding this comment.
Secrets are stored per-client so that sort of clobbering shouldn't be an issue.
The only extremely obscure case I can think of that would be impacted is:
- You're using an SDK directly on the host (i.e. not just
dagger call) - You set your own secret that also happens to be named
gitAuthtoken
Not worth agonizing over, but yeah we could just set name to a sha256 of the plaintext to squash any possibility of that happening.
|
|
||
| // TestGitCredentialErrors verifies Git authentication for private modules across different providers | ||
| // using host-specific PATs and isolated Git credentials per test. | ||
| func (GitCredentialSuite) TestGitCredentialErrors(ctx context.Context, t *testctx.T) { |
There was a problem hiding this comment.
Could we get one more test case that's similar to the existing ones except that it calls a module and passes a Directory as an arg that's from a git repo? e.g. something like:
dagger call test --dir https://github.com/grouville/daggerverse-private.git
and make sure ops on the git dir work as expected in the module (can list the dir or something like that)?
That's just one tricky case where the resolution with git needs to happen within the CLI+auth-token and after should be usable from modules even if they don't have access to the auth provider directly.
There was a problem hiding this comment.
Synced up offline about this, but Guillaume added the test and hit a bug. Was a super subtle thing around secrets needing to appear in the dagql Call DAG in order to be passed through args to functions, pushed fix here w/ more deets: e86d0d4
5a61ab1 to
0919bda
Compare
The GitCredentialAttachable establishes the client - engine communication. It represents the scheme on which we query the Git PAT infos Signed-off-by: Guillaume de Rouville <[email protected]>
Implements the logic to query the git CLI to retrieve the auth informations: 1. query the git credential fill with protocol / host / path 2. Parse output We ensure that the git CLI is present on the host, that error occured on the process Signed-off-by: Guillaume de Rouville <[email protected]>
Bind everything to test auth Signed-off-by: Guillaume de Rouville <[email protected]>
Bind the auth to the git API + print a bit everywhere to fix bugs: 1. race on the gitcredentials client accessor (fixed with the shell script) + the mutex 2. check if secret creation works It works Signed-off-by: Guillaume de Rouville <[email protected]>
Remove the Authenticate endpoint, which was used as a stopgap to advance on the implementation I also refactored the gitcredential to simplify it without changing the logic Signed-off-by: Guillaume de Rouville <[email protected]>
some cleanup This commit ensures that the PAT support is only available to client originating the session. This is an easy way to ensure isolation of the sessions, but the integ tests won't be able to use nested execs It also does some debug cleaning Signed-off-by: Guillaume de Rouville <[email protected]>
Only fail silently when git credentials haven't been found. We could extend the logic to alway fail silently, but need to ask feedback around that Signed-off-by: Guillaume de Rouville <[email protected]>
Signed-off-by: Guillaume de Rouville <[email protected]>
This tests our proto / host interaction, to ensure that we correctly handle all unexpected host configuration when querying the `git credential fill` command on the user's host Signed-off-by: Guillaume de Rouville <[email protected]>
Fixes some lint errors + checks if a ref is public prior requesting a git token Signed-off-by: Guillaume de Rouville <[email protected]>
Add integration tests to verify Git authentication for private modules across different providers (GitHub, GitLab, BitBucket). Tests use isolated Git credentials per host to enable parallel execution. Each test: - Sets up local Git credentials using provider-specific PATs - Verifies access to private modules using `dagger functions` - Runs in isolation using temporary Git configs Also includes negative test case to verify authentication failures. Signed-off-by: Guillaume de Rouville <[email protected]>
Apply recommendations: 1. SHA256 the added PAT so that naming never conflicts across sessions or with an SDK setting that name 2. Use ListContext so we can cancel the request if the call is canceled Signed-off-by: Guillaume de Rouville <[email protected]>
Only retrieve the PAT via the git credentials when the ref is http / same for ssh (unless the socket is specifically passed). Signed-off-by: Guillaume de Rouville <[email protected]>
Adds the test case to pass a private repo as a directory Signed-off-by: Guillaume de Rouville <[email protected]>
0919bda to
c16973c
Compare
In order for a function to be granted selective access to a secret, the secret needs to appear in the dagql Call. Previously the secret was just set on a field in the returned struct, now it is in the returned dagql.Instance and thus passes to function clients through args. Signed-off-by: Erik Sipsma <[email protected]>
|
@grouville approved 🎉 but just realized we should have a changelog for this (docs can be separate). Should be good to merge once you add that |
Doing it rn 🙏 |
Signed-off-by: Guillaume de Rouville <[email protected]>
| } | ||
|
|
||
| func (s *gitSchema) git(ctx context.Context, parent *core.Query, args gitArgs) (*core.GitRepository, error) { | ||
| func (s *gitSchema) git(ctx context.Context, parent dagql.Instance[*core.Query], args gitArgs) (inst dagql.Instance[*core.GitRepository], _ error) { |
There was a problem hiding this comment.
@grouville suggestion for a follow-up - is there a way to break down some of this logic into separate functions, maybe even into core/git.go itself?
The comments here really help, but if we could use function calls to help show the structure that would be even better 🎉
There was a problem hiding this comment.
Yeah sure 👍 I saw a lot of monolithic functions, so wasn't sure ; but 👌
Fixes #7990
This is the PR introducing PAT support auth.
Implementation
As requested on the issue by the community, we rely on the git credential to request for authentication:
gitCLIgit-credentialThis gives userland the power to configure auth however they want, with their preferred auth tool
How does this work
gitintroduces a standard: git credential which is queryable from thegitCLI:The engine is directly querying this command on the user's host, via the CLI and parses the output of the command ; it then injects it back inside its session, safely, as a secret
How can you test
Please break this PR as you would, especially try to see if this maps your usual auth pattern (personal and enterprise environment):
git credential managers
There are a lot of git credential managers out there, all mapping with the
git credentialstandard. They can also be chained, and this will allow you to manage the caching side of those tokens client-sideTODO:
cc @nipuna-perera @sheldonhull