Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changes/unreleased/Added-20240815-073952.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: Added
body: |-
Support private modules with new SSH ref scheme and forward of SSH agent:
- Go-like refs (currently used) remain active
- http / https schemes are now supported as alternative public module refs
- SSH refs are introduced, with support of SCP-like refs git@provider:user/repo and explicit ssh://provider/user/repo

The Dagger CLI now securely forwards the SSH_AUTH_TOKEN for authentication
time: 2024-08-15T07:39:52.263039405Z
custom:
Author: grouville
PR: "7708"
2 changes: 1 addition & 1 deletion cmd/dagger/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ var moduleInstallCmd = &cobra.Command{

if depSrcKind == dagger.GitSource {
git := depSrc.AsGitSource()
gitURL, err := git.CloneURL(ctx)
gitURL, err := git.CloneRef(ctx)
if err != nil {
return err
}
Expand Down
24 changes: 24 additions & 0 deletions core/integration/git_test.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ sleep infinity
require.Equal(t, []string{"README.md"}, entries)
}

func (GitSuite) TestGitTagsSSH(ctx context.Context, t *testctx.T) {
c := connect(ctx, t)

repoURL := "[email protected]:dagger-modules/private/test/more/dagger-test-modules-private.git"

// Test fetching tags with SSH authentication
t.Run("with SSH auth", func(ctx context.Context, t *testctx.T) {
sockPath, cleanup := setupPrivateRepoSSHAgent(t)
defer cleanup()

tags, err := c.Git(repoURL, dagger.GitOpts{
SSHAuthSocket: c.Host().UnixSocket(sockPath),
}).Tags(ctx)
require.NoError(t, err)
require.ElementsMatch(t, []string{"cool-sdk/v0.1", "v0.1.1"}, tags)
})

t.Run("without SSH auth", func(ctx context.Context, t *testctx.T) {
_, err := c.Git(repoURL).Tags(ctx)
require.Error(t, err)
require.Contains(t, err.Error(), "Permission denied (publickey)")
})
}

func (GitSuite) TestAuth(ctx context.Context, t *testctx.T) {
c := connect(ctx, t)
gitDaemon, repoURL := gitServiceHTTPWithBranch(ctx, t, c, c.Directory().WithNewFile("README.md", "Hello, world!"), "main", c.SetSecret("target", "foobar"))
Expand Down
24 changes: 22 additions & 2 deletions core/integration/module_call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,13 @@ func (m *Test) ToStatus(status string) Status {
t.Run("module args", func(ctx context.Context, t *testctx.T) {
c := connect(ctx, t)

mountedSocket, cleanup := mountedPrivateRepoSocket(c, t)
defer cleanup()

modGen := goGitBase(t, c).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(mountedSocket).
With(daggerExec("init", "--source=.", "--name=test", "--sdk=go")).
WithNewFile("foo.txt", "foo").
WithNewFile("main.go", `package main
Expand Down Expand Up @@ -1923,9 +1927,13 @@ func (ModuleSuite) TestCallByName(ctx context.Context, t *testctx.T) {
t.Run("git", func(ctx context.Context, t *testctx.T) {
c := connect(ctx, t)

mountedSocket, cleanup := mountedPrivateRepoSocket(c, t)
defer cleanup()

ctr := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
WithWorkdir("/work").
With(mountedSocket).
With(daggerExec("init")).
With(daggerExec("install", "--name", "foo", testGitModuleRef(tc, ""))).
With(daggerExec("install", "--name", "bar", testGitModuleRef(tc, "subdir/dep2")))
Expand All @@ -1942,30 +1950,42 @@ func (ModuleSuite) TestCallByName(ctx context.Context, t *testctx.T) {
}

func (ModuleSuite) TestCallGitMod(ctx context.Context, t *testctx.T) {
c := connect(ctx, t)

testOnMultipleVCS(t, func(ctx context.Context, t *testctx.T, tc vcsTestCase) {
c := connect(ctx, t)

t.Run("go", func(ctx context.Context, t *testctx.T) {
mountedSocket, cleanup := mountedPrivateRepoSocket(c, t)
defer cleanup()

out, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
With(mountedSocket).
With(daggerCallAt(testGitModuleRef(tc, "top-level"), "fn")).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "hi from top level hi from dep hi from dep2", strings.TrimSpace(out))
})

t.Run("typescript", func(ctx context.Context, t *testctx.T) {
mountedSocket, cleanup := mountedPrivateRepoSocket(c, t)
defer cleanup()

out, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
With(mountedSocket).
With(daggerCallAt(testGitModuleRef(tc, "ts"), "container-echo", "--string-arg", "yoyo", "stdout")).
Stdout(ctx)
require.NoError(t, err)
require.Equal(t, "yoyo", strings.TrimSpace(out))
})

t.Run("python", func(ctx context.Context, t *testctx.T) {
mountedSocket, cleanup := mountedPrivateRepoSocket(c, t)
defer cleanup()

out, err := c.Container().From(golangImage).
WithMountedFile(testCLIBinPath, daggerCliFile(t, c)).
With(mountedSocket).
With(daggerCallAt(testGitModuleRef(tc, "py"), "container-echo", "--string-arg", "yoyo", "stdout")).
Stdout(ctx)
require.NoError(t, err)
Expand Down
Loading