Repository navigation
feat(core): add private git support via SSH auth - #7708
Conversation
|
Hey @grouville I have a clarifying question. Are you considering private repo access that doesn't use SSH also? In my company we aren't allowed to use SSH to access our Github Enterprise repos. Instead we have to use a Personal Access Token (PAT). Just want to make sure you are taking that scenario into consideration also. |
Hi @nipuna-perera, |
Oh man! I won't be able to use this then 😢 . I thought the PAT version will be easier to support because there are less moving parts (like sockets). I'd imagine a lot of companies have the same restrictions mine does with opening SSH to the outside world. Especially for Github Enterprise or BB Cloud as it's a SaaS. SSH method may be more common for other Git providers though but that's just a guess. Hopefully the jump from this to token based is not huge. Could you modify the title and the description of this PR to reflect that it's for SSH please? |
|
Nice work so far @grouville 🎉 I'm not sure I think we should accept buildkit style refs here. Here's an alternative idea: Here's a suggestion for how we could resolve this:
In this model, all git URLs are prefixed with Examples:
|
|
This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
There was a problem hiding this comment.
Such test is necessary. As we still cannot pass Socket via the CLI in modules, this test relies on the connect to access the socket and mount it. The client implements the new loading of socket when the SSH_AUTH_SOCK env variable is set, which we need to ensure is not set during the test execution, as it could interfere with the state of the test
On the other side, this private key adds read only rights to the private test repository
There was a problem hiding this comment.
@grouville heads up! Socket CLI support is incoming 🎉 #7804
UpdateThanks @jedevc for the proposal on the ref style. This unlocked me and helped me realized that the scp style I was trying to implement was a rabbithole. Current state of PR is not finished, but, we made major improvements in a sense that we can already see the new ref design: https://github.com/dagger/dagger/pull/7708/files#diff-8432d1812b1f1b774598e92639e78ab8a25fcb6804617f7587d692149d155e21 Your suggestions are pretty strong:
The only tweak that I personally prefer is to just continue relying on vcs.RepoRootForImportPath to isolate the root of the repo and the subdir. For most providers, the root of a private repo will either be: The implications of that is that we would need, for some refs, have this
It is perfect, and totally makes sense ContextGo ref style One of the biggest advantage of Go's ref style is its simplicity and decoupling from VCS providers. People just point the ref, and it automagically figures out how to query it. This works quite well but it is not a 100% perfect solution (link to Go auth issues). Let's deep dive on the requirements / possibilities:
Now, as it is a user-facing feature, its implications are big:
Currently, the design decision balances between the explicitness / easy DX and the Let's dive a bit deeper each point:
In terms of ref design, this is also not a problem, as above proposal works too: we could copy Helder's tool that relies on
Open question@sipsma opened an issue around git redirects: #7787. This part is a bit blurry still in my mind, especially on the implications on such ref style, wdyt ? I presume that this would enable us (in a second time) to handle scp-like refs by loading this conf as part of RepoRootForImportPath |
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
e7c289e to
051b280
Compare
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
|
Implemented all the changes (thank you for the review), removed the http / https schemes as we might want to move to git+https / git+http or no scheme as we have right now I left the Azure repo commented as an example, as unfortunately we cannot scope the SSH key to a read-only one for just one repo It is also rebased on top of #8063, which should be merged first One question that remains:
|
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
|
Some new inputs following a discussion with our CTO: #6113 (comment) and some feedback from users. Implementation will be tweaked tomorrow to fit this new ref style, unless some other inputs get into the balance |
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
482659e to
1509eae
Compare
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
01b9987 to
3ed670d
Compare
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
|
This is again ready for review 🙏 cc @jedevc |
jedevc
left a comment
There was a problem hiding this comment.
Yeah, this is neat work 🎉 very cool 🎉
I've left a few small nits/comments/etc - only one large piece about not removing cloneURL but deprecating it. That should massively help the daggerverse process, as well as avoid breakages from anyone else who might be using this API (though I don't think that's anyone - better to be safe than sorry!).
I've approved though - once you've resolved the comments, and tests are passing, feel free to merge whenever ![]()
There was a problem hiding this comment.
Can we name this file to indicate what it's for? It would be good to avoid accidental "oops what's this doing here" moments.
@gerhard do you know if this would raise any scanner issues/etc?
| props[prefix+"source_kind"] = "git" | ||
| props[prefix+"git_symbolic"] = git.Symbolic() | ||
| props[prefix+"git_clone_url"] = git.CloneURL | ||
| props[prefix+"git_clone_ref"] = git.CloneRef |
There was a problem hiding this comment.
We should update https://github.com/dagger/dagger.io/blob/main/ENGINE_ANALYTICS.md in a follow-up.
| """ | ||
| The URL to access the web view of the repository (e.g., GitHub, GitLab, Bitbucket) | ||
| """ | ||
| repositoryUrl: String! |
There was a problem hiding this comment.
Hm, I'm confused on this.
I don't think we should actually expose this as a field - we probably only need to expose htmlURL, right? I think we can just set field to be false for this one.
If you do decide to:
- The naming should probably be more like
htmlRepoURLinstead. - Make sure the
URLcasing matcheshtmlURL.
There was a problem hiding this comment.
You're right, it is a bit confusing. Some context:
- htmlURL is the base URL to access the module on a Git provider. In order to do so, it constructs opinionated URLs (with
src,tree..) - repositoryURL is the base HTML URL to that Git repo
Daggerverse currently relies on the user ref, when publishing a module, to transform all relative paths inside all Markdown ( which also includes our functions, object documentations / Readme [in the past]). For that, it needs another format of URL, to access the raw content for each provider: https://raw.githubusercontent.com/dagger/dagger/6249cc93f9467434215d155e6e768431e507feb7/core/integration/git_test.go, which can be accessed originally as https://github.com/dagger/dagger/raw/6249cc93f9467434215d155e6e768431e507feb7/core/integration/git_test.go
I am totally fine in hiding it, and have a function on Daggerverse's side to parse HTMLURL() and use that ; having this field as public could lead to some more painful changes in the future. So ok for the small overhead added internally 👌
There was a problem hiding this comment.
Ah, right. I was missing that context, my bad 🎉
Yeah, it's absolutely fine to have this, daggerverse shouldn't have to parse HTMLUrl, that's very annoying! But yeah, let's do the suggestions from above: it should be called htmlRepoURL instead.
| // SCP-like ref format | ||
| { | ||
| name: "SSH Private BitBucket", | ||
| gitTestRepoRef: "[email protected]:dagger-modules/private-modules-test.git", |
There was a problem hiding this comment.
nit: can you add another test entry for an scp-like ref that has a /path/to/a/module?
Would also be good to add a basic GitHub test case if you can (I expect that's one of the most common code paths).
In order to fully handle the new ref scheme, we extend the parseRefString to: 1. properly parse this new scheme 2. store that value (to reconstruct the ref upon save) 3. Thoroughly test it (unit test) Current ref format is based on: dagger#7708 (comment). However, we still rely on vcs.RepoRootForImportPath to isolate the root of a repo and a subpath. For most providers, this will either be: 1. found via the regex 2. the provider returns the root of repo with go-get=1 even for private repos 3. Last resort (GitLab case, which purposefully obfuscates the root of the repo), the solution that Go uses is to be declarative: add the `.git` inside the ref This is a strong / easy to implement ref style that covers all use-case Signed-off-by: Guillaume de Rouville <[email protected]>
This commit introduces support for SSH-style Git references across all currently
supported Git providers, enabling authentication for private Dagger modules.
This enhancement significantly improves the flexibility and security of Git
operations within Dagger, particularly for private repositories.
Key Changes:
1. Git Reference Handling:
- Implemented support for SSH-style Git references
- Extended parseRefString to handle new reference schemes, including:
a. Go-style: github.com/dagger/dagger/subpath@version
b. Git-HTTP: https://github.com/dagger/dagger/subpath@version
c. Git-SCPlike: [email protected]:dagger/dagger/subpath@version
d. Explicit SSH: ssh://[email protected]/dagger/dagger/subpath@version
- Updated core/schema/moduleSource logic for SSH references
2. Authentication and Security:
- Added automatic support for client auth sock in all git operations
- Implemented SSH authentication for git subcommands, focusing on git tags
- Introduced automatic forwarding of SSHAuthSocketPath for nested Dagger executions
3. Azure DevOps Support:
- Extended multi-git server support to Azure DevOps
- Addressed issues with Azure's handling of `go-get=1` for monorepos
- Implemented explicit VCS inference for Azure refs
4. Testing Infrastructure:
- Extended test suite for better isolation of SSH_AUTH_SOCK tests
- Introduced mountedPrivateRepoSocket as a test helper
- Added comprehensive tests for private repositories
- Implemented in-memory SSH agent for testing
5. Code Refactoring and Improvements:
- Refactored parseRefString for better readability and maintainability
- Updated GitModuleSource type to separate Ref, CloneRef, and RepositoryURL
- Introduced GitModuleSource.HtmlRepoURL for accessing root repo URLs
- Improved comments and documentation throughout the codebase
6. Security Enhancements:
- Base64 encoded new test SSH key to address GitHub scanner flags
7. Documentation and SDK Updates:
- Updated SDKs and GraphQL documentation to reflect GitModuleSource changes
- Regenerated documentation and SDKs to maintain consistency
Deprecation / v0.13.0 breaking Changes:
- Modifications to GitModuleSource schema (internal, deemed acceptable)
This commit significantly enhances Dagger's Git integration capabilities,
providing more robust and flexible support for private modules across various
Git providers while maintaining security and improving testability.
Signed-off-by: Guillaume de Rouville <[email protected]>
Co-authored-by: Erik Sipsma <[email protected]>
WIP implementation of private Git support (works, just not with a generic / nice ref yet)
This is rebased on top of #7663, which adds integration tests and fixes some of the VCS logic.
Core changes
SSH_AUTH_SOCKenv variable is set. This is the auth that will be used to access the private repo.Currently this has only been manually tested, but works e2e, just needs polish.
E.g. Currently accepted private repo ref
TODO:
HTMLURLif only ssh ref style is possible.gitinside as SSH refs, bind it with thevcs.RepoRootForImportPath. This is the current exploration. With this vision, the above ref would be:gitlab.com/dagger-modules/private/test/more/dagger-test-modules-private.git/top-level@2cb6cb4b0dba52c1e65b3ff46dd1a4a8f9a02f94