Skip to content

feat(core): add private git support via SSH auth - #7708

Merged
grouville merged 1 commit into
dagger:mainfrom
grouville:private-git
Aug 20, 2024
Merged

grouville merged 1 commit into
dagger:mainfrom
grouville:private-git

Conversation

@grouville

@grouville grouville commented Jun 19, 2024 •

Copy link
Copy Markdown
Member

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

  • Following @sipsma's work to securely isolate sockets per sessions. We can now automatically and securely load the SSH socket when the SSH_AUTH_SOCK env variable is set. This is the auth that will be used to access the private repo.
  • File / Directory passed as CLI args do not rely on the os.env lookup anymore

Currently this has only been manually tested, but works e2e, just needs polish.

E.g. Currently accepted private repo ref

dagger_dev -m ssh://gitlab.com/dagger-modules/private/test/more/dagger-test-modules-private.git:top-level@2cb6cb4b0dba52c1e65b3ff46dd1a4a8f9a02f94 functions

TODO:

  • Fix HTMLURL if only ssh ref style is possible
  • Handle private ref neatly. I think it is possible to consider all refs with .git inside as SSH refs, bind it with the vcs.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
  • Implement corresponding test suite

@nipuna-perera

nipuna-perera commented Jun 20, 2024 •

Copy link
Copy Markdown
Contributor

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.

@grouville

Copy link
Copy Markdown
Member Author

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,
Mmmh, great remark. The first stopgap is the ssh version, the PAT version might also be implementable, but probably as a follow-up. I need to check with Erik to see his vision on the subject 🙏

@nipuna-perera

Copy link
Copy Markdown
Contributor

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, Mmmh, great remark. The first stopgap is the ssh version, the PAT version might also be implementable, but probably as a follow-up. I need to check with Erik to see his vision on the subject 🙏

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?

@jedevc

jedevc commented Jun 24, 2024 •

Copy link
Copy Markdown
Contributor

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:

  • We redefine module refs as [proto://]host/path[@version] or [.]/path/to/module (for local refs)
    • proto is optional - when empty, it defaults to git+http/git+https
  • If it's git+http://, we do our cool path splitting using HTTP?
  • If it's git+ssh://, I guess we can't do path splitting? Maybe there's something else we could do?
    • e.g. we could do this: ssh [email protected] "git-receive-pack dagger/dagger" - split the path at each /, and repeat until we find the first one that succeeds. You can poke around to see how that works.
  • If it's ssh://, we could fallback to git+ssh://.

In this model, all git URLs are prefixed with git+, as suggested by @helderco in #6957 (comment) - that way, we can distinguish between https://path/to/file and https://path/to/git/repo easily in the CLI.

Examples:

  • github.com/dagger/dagger is the same as https://github.com/dagger/dagger, which is this repository
  • ssh://[email protected]/dagger/dagger is this repository (but over ssh)
    • SCP-style URLs shouldn't be supported for now, they're an insane pain.

@github-actions

github-actions Bot commented Jul 9, 2024

Copy link
Copy Markdown
Contributor

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.

grouville added a commit to grouville/dagger that referenced this pull request Jul 11, 2024
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]>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

@jedevc jedevc Jul 11, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@grouville heads up! Socket CLI support is incoming 🎉 #7804

@grouville

grouville commented Jul 11, 2024 •

Copy link
Copy Markdown
Member Author

Update

Thanks @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:

We redefine module refs as [proto://]host/path[@version] or [.]/path/to/module (for local refs)
proto is optional - when empty, it defaults to git+http/git+https ✅

If it's git+http://, we do our cool path splitting using HTTP?
If it's git+ssh://, I guess we can't do path splitting? Maybe there's something else we could do?
e.g. we could do this: ssh [email protected] "git-receive-pack dagger/dagger" - split the path at each /, and repeat until we find the first one that succeeds.
If it's ssh://, we could fallback to git+ssh://.

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:
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

The implications of that is that we would need, for some refs, have this .git, but that's really how most people end up resolving the issue in Go: golang/go#29953

In this model, all git URLs are prefixed with git+, as suggested by @helderco in #6957 (comment) - that way, we can distinguish between https://path/to/file and https://path/to/git/repo easily in the CLI.

It is perfect, and totally makes sense

Context

Go 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).
To know if Dagger shall copy this model, we first need to list all the things to consider:

Let's deep dive on the requirements / possibilities:

  1. Splitting repo ref / path: github.com/dagger/dagger/dev/markdown is a module inside the dagger/dagger monorepo. We need to have a ref format that works for both private AND public repos whilst remaining explicit (especially on the errors) AND that does not fail (GitLab / Go issue for private repos)
  2. Multi VCS: currently Dagger only supports Git but there is totally a path towards multi VCS support (Bazaar, Mercurial, Subversion) -> grouville/go-vcs@2e8fc1b
  3. Auth protocol support: What are the protocols handled for auth. Currently, only SSH auth is supported, but we already have requests for HTTP / PAT support ; also, each of these vcs have different ways of authenticating under the hoods -> https://docs.gomods.io/configuration/authentication/#atlassian-bitbucket-and-ssh-secured-git-vcss.
  4. Ref -> web view. Dagger provides link to automatically click and see the tree of the current module on the provider. Whilst accepting new formats, we need to make sure to convert the refs to a working URL
  5. CLI: support passing a remote URL as file argument CLI: support passing a remote URL as file argument #6957. We need to differenciate a call to a git repo and an http call inside the CLI
    -> CLI: support passing a remote URL as file argument #6957

Now, as it is a user-facing feature, its implications are big:

  1. retro-compatibility / no breaking changes
  2. Good DX
  3. Shell command interpretability

Currently, the design decision balances between the explicitness / easy DX and the

Let's dive a bit deeper each point:

  1. we currently rely on the vcs.RepoRootForImportPath function (taken from Google) to split the root of a repo and a path inside. This actually works well for both private and public repos on most of VCS apart for GitLab as GitLab purposefully returns a correct incorrect meta tag if we query a private repo without the auth tokens set

  2. As shown in this commit, there is an easy path for us to include inside our RepoRootPath helpers to separate the root for the path. Then, the following would be to implement the equivalent of our git implementation and decouple moduleSource from the corresponding VCS.

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 bzr+, svn+ / hg+ to isolate the vcs provider explicitely. Coupled with our extension of RepoRootForImportPath, we seem to have a solid path towards a unified DX across all those providers and a quite elegant solution

  1. The underlying auth protocol should not impact the ref style. What was important in such exploration is to have a style that could fit all use-cases (please add some if you miss some). Here, vcs.RepoRootForImportPath implementation above should not fail with PAT auth for example, as we rely on a declarative model for the GitLab VCS

  2. As we keep relying on RepoRootForImportPath, we have "for free" the root URL, which is the same for public and private repos

  3. As we rely on this declarative model for module resolution: git+ would be consistent for CLIs file / repo refs

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

@grouville grouville changed the title feat(core): add private git support feat(core): add private git support via SSH auth Jul 11, 2024
grouville added a commit to grouville/dagger that referenced this pull request Jul 13, 2024
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]>
grouville added a commit to grouville/dagger that referenced this pull request Jul 13, 2024
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]>
grouville added a commit to grouville/dagger that referenced this pull request Jul 15, 2024
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]>
grouville added a commit to grouville/dagger that referenced this pull request Jul 16, 2024
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]>
grouville added a commit to grouville/dagger that referenced this pull request Jul 18, 2024
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]>
grouville added a commit to grouville/dagger that referenced this pull request Jul 18, 2024
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]>
@grouville
grouville force-pushed the private-git branch 2 times, most recently from e7c289e to 051b280 Compare July 18, 2024 09:04
grouville added a commit to grouville/dagger that referenced this pull request Aug 1, 2024
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]>
@grouville
grouville requested a review from jedevc August 1, 2024 07:47
@grouville

grouville commented Aug 1, 2024 •

Copy link
Copy Markdown
Member Author

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:

  • for azure, shall we handle the difference between the ssh.dev.azure.com and the dev.azure.com ? As users will specify git+ssh://, I could infer and modify on the fly the host for that use-case ?

grouville added a commit to grouville/dagger that referenced this pull request Aug 1, 2024
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]>
grouville added a commit to grouville/dagger that referenced this pull request Aug 1, 2024
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]>
@grouville

grouville commented Aug 2, 2024 •

Copy link
Copy Markdown
Member Author

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

grouville added a commit to grouville/dagger that referenced this pull request Aug 9, 2024
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]>
grouville added a commit to grouville/dagger that referenced this pull request Aug 9, 2024
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]>
@grouville
grouville force-pushed the private-git branch 3 times, most recently from 482659e to 1509eae Compare August 9, 2024 07:36
grouville added a commit to grouville/dagger that referenced this pull request Aug 10, 2024
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]>
@grouville
grouville force-pushed the private-git branch 2 times, most recently from 01b9987 to 3ed670d Compare August 10, 2024 01:35
grouville added a commit to grouville/dagger that referenced this pull request Aug 12, 2024
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]>
grouville added a commit to grouville/dagger that referenced this pull request Aug 13, 2024
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]>
@grouville

Copy link
Copy Markdown
Member Author

This is again ready for review 🙏 cc @jedevc

@jedevc jedevc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 :shipit:

Comment thread core/integration/git_test.go Resolved
Comment thread core/integration/private_key.pem Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Comment thread core/modfunc.go
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread docs/docs-graphql/schema.graphqls Outdated
"""
The URL to access the web view of the repository (e.g., GitHub, GitLab, Bitbucket)
"""
repositoryUrl: String!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 htmlRepoURL instead.
  • Make sure the URL casing matches htmlURL.

@grouville grouville Aug 13, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 👌

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread engine/client/client.go Resolved
Comment thread docs/docs-graphql/schema.graphqls Resolved
// SCP-like ref format
{
name: "SSH Private BitBucket",
gitTestRepoRef: "[email protected]:dagger-modules/private-modules-test.git",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

@jedevc jedevc added the needs/changelog Pull requests that require a changelog entry label Aug 13, 2024
grouville added a commit to grouville/dagger that referenced this pull request Aug 14, 2024
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]>
@jedevc jedevc mentioned this pull request Aug 15, 2024
1 of 2 tasks
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs/changelog Pull requests that require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants