Skip to content

support mounting host Unix sockets into containers - #4025

Merged
vito merged 9 commits into
dagger:mainfrom
vito:unix-sockets
Nov 30, 2022
Merged

vito merged 9 commits into
dagger:mainfrom
vito:unix-sockets

Conversation

@vito

@vito vito commented Nov 29, 2022 •

Copy link
Copy Markdown
Contributor

fixes #3850

Implements the following schema:

extend type Query {
  "Load a socket by ID"
  socket(id: SocketID): Socket!
}

"A content-addressed socket identifier"
scalar SocketID

type Socket {
  "The content-addressed identifier of the socket"
  id: SocketID!
}

extend type Host {
  "Access a Unix socket on the host"
  unixSocket(path: String!): Socket!
}

extend type Container {
  "This container plus a socket forwarded to the given Unix socket path"
  withUnixSocket(path: String!, source: SocketID!): Container!

  "This container with a previously added Unix socket removed"
  withoutUnixSocket(path: String!): Container!
}

The current approach is to call llb.SSHID with the content-addressed SocketID prefixed by socket: to distinguish it from the current named sockets, making this backwards-compatible. The implementation is very similar to how the secret provider works (passing a FooID to the session.Attachable), but it's simpler for now since there's no container-to-network socket forwarding (yet?).

@vito
vito force-pushed the unix-sockets branch 3 times, most recently from d5e1d1e to b29863c Compare November 29, 2022 21:17
@vito
vito marked this pull request as ready for review November 29, 2022 21:49

@sipsma sipsma 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.

minor comments, looks great!

Comment thread core/integration/container_test.go Resolved
Comment thread core/schema/container.graphqls Resolved
Comment thread engine/sshsock.go Resolved
vito added 3 commits November 29, 2022 22:22
untested

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Comment thread sdk/python/tests/api/test_codegen.py 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.

This shouldn't be needed since it's not being used in the tests bellow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

👍 will remove, I was just pattern matching here :)

vito added 4 commits November 30, 2022 11:49
this test is incredibly complicated, and required adding support for
configurable SSH known hosts, but now we can trust this feature to work.

Signed-off-by: Alex Suraci <[email protected]>
@vito

vito commented Nov 30, 2022

Copy link
Copy Markdown
Contributor Author

@sipsma ready for another look!

@sipsma sipsma 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.

LGTM!

Comment thread core/container.go Outdated

target = absPath(payload.Config.WorkingDir, target)

payload.Sockets = append(payload.Sockets, ContainerSocket{

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.

This is a dumb corner case but I guess if you put multiple socks at the same location the behavior is probably weird: either buildkit returns an error but only when you try to do an exec and/or the without behavior removes the "lower" socket rather than the upper.

Probably better to fail if the user tries to do that. Not a blocker though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, pushed a tweak so WithUnixSocket will replace an existing socket with the same path, rather than blindly appending.

require.Contains(t, res.Git.Commit.Tree.File.Contents, "Dagger")
}

func TestGitSSHAuthSock(t *testing.T) {

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.

🆒

@vito
vito merged commit 0c4d6d9 into dagger:main Nov 30, 2022
@vito
vito deleted the unix-sockets branch November 30, 2022 19:59
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.

Mount unix socket into Exec

4 participants