You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@aluzzardi continuing our API design / bikeshedding discussion here to keep better records:
container-to-host: processes running inside the container can connect to a tcp port, udp port or unix socket, and the traffic is forwarded to a given address in the host network stack
2 parts:
Host() API exposes unix/tcp/udp sockets
Container() API allows to pass unix/tcp/udp sockets
First reaction: TCPSocket and UDPSocket don't make it clear if we're listening or connecting.
Technically it's not clear with UnixSocket either, but one can make an educated guess based on most common use cases: probably this is for connecting to a docker engine or ssh agent, so probably we're connecting. But you still have to guess.
I think dagger.Socket might suffer from the same problem: is it a "listener", a "connecter", or both?
I know @vito did a lot of this with bass. There's a lot of considerations to take into account, especially around not busting the cache.
I think the answer might be different from inbound and outbound (which again are hard to distinguish in the proposed API).
Outbound: useful both in short-lived containers and long-lived services. Connect to docker engine; to ssh agent; to sql database; to api endpoint... Short-lived containers already do all those things: outbound proxying just gives them more endpoints they can connect to.
Inbound: most useful for long-lived services. It would be reasonable to not support them in short-lived containers IMO. But we have to be prepared to change our minds if users show us a reasonable use case we hadn't thought about (or if they just use horrible hacks to bypass the limitation).
host-to-container: processes running inside the container can listen on a tcp, udp or unix address, and traffic is forwarded from a given listening address on the host
Same question as above -- does it make sense for non-services? I think not, for the same reasons.
Same answer as container-to-container. Different for inbound and outbound.
I know @vito did a lot of this with bass. There's a lot of considerations to take into account, especially around not busting the cache.
I'll fill in some gaps with what I learned from/did with Bass. The main thing I learned is that this kind of feature intersects many tricky subjects and the key thing will be figuring out where to embrace constraints.
Note that all of the following is really only relevant for TCP/UDP. I haven't considered Unix socket support yet. But it makes sense to discuss them all together anyway.
DNS + bridge networking
Bass containers reach services by addressing them over a bridge network, using DNS to resolve to container hostnames to IPs at runtime.
DNS was my solution for not busting the cache. The key point is to avoid having ephemeral container IPs ever enter into LLB. I got DNS to work by configuring Buildkit to use CNI and installing dnsmasq and the dnsname plugin:
Bass uses the thunk 'name' as the DNS address, which is a hash of the thunk like GRLO5DSIPLJPQ. It's not possible to set your own name. I didn't want the user to have to deal with collisions, so having content-addressed addresses made sense here, especially since Buildkit also handled deduping two thunks that represent the same service.
Compared to Dagger: this model is pretty different than what @aluzzardi has proposed so far, which seems more along the lines of forwarding sockets in to local addresses within the container. Do I have that right?
Thunk addresses
Bass forces thunks to be self-contained by using thunk addrs as the primitive for passing addresses to commands.
Rather than something stateful (start service with hostname foo, wait for it to start, use it for a bit, and then stop it), thunk addrs contain the service that it's reaching, and Bass automatically runs it when needed. Buildkit handles deduping equivalent services (e.g. same thunk addr used by multiple clients) and stopping them when all clients go away.
Thunk addrs contain a string template where $host and $port are replaced with the actual host and port of the destination service at runtime. But this is obviously TCP specific.
Compared to Dagger: thunk addrs seem unlikely to be the right approach for Dagger, since our spec dictates that env/args are simple String!s. But I don't think it needs to work the same way in Dagger. If our approach is to proxy addresses into localhost:SOME_PORT I can make this work easily by just resolving $host to localhost and $port to whatever container-side port they chose.
edit to add: I think we should definitely try to maintain the spirit of this design though: having hard dependencies between the client + service so the whole plan is self-contained and stateless.
Health/liveness checks
Some really common cludgy code to write is "start this service and then do a while loop checking for it to be running before continuing on."
I opted to just have Bass do this for you, since services are started on-demand. When a thunk uses with-port this tells Bass to poll for that port to be bound prior to running the thunk that depends on it.
Note that this health check literally just opens a connection on the port and closes it. Other systems allow you to configure more sophisticated checks, but I haven't bothered with all that jazz.
Compared to Dagger: this still makes sense to have IMO. Having to perform health checks yourself seems really clunky.
TLS & certificate generation
My "north star" for services in Bass was to be able to run a registry as a service and use it for later thunks. This forced me to figure out how to do TLS, because using DNS or even container IP addresses for Buildkit's image fetching requires the registry to use TLS.
I decided to have Bass generate and manage its own CA and use it to mint certificates for any thunks that request a TLS cert/path using with-tls. Bass's shim then injects the CA as a trusted cert for the container, so any thunks that use the service will automatically trust it.
This worked out really nicely! It made it really easy to use TLS for any service.
Compared to Dagger: it's unclear how we would expect TLS to work if we're forwarding sockets into containers instead of having containers directly address one another.
I think that covers the interesting bits, but I may have missed/glossed over some parts. AMA!
@shykes For what it's worth, I don't share the same confusion with inbound/outbound; it feels pretty intuitive to me if I draw parallels to Host Directory access.
I see Host.(Unix|TCP|UDP)Socket as something that gives you a reference to an existing address on the host, and Container.With(Unix|TCP|UDP)Socket as something that makes a socket reachable inside the container's local filesystem/network on the specified path/port. The same way that Host.Directory gives you a Directory which can be mounted in to a container.
Replace Host with Container (for a container that runs a service) and I'd interpret it the same way, but drawing parallels to Container.Directory instead.
So to me this design feels pretty clean, but my only question is whether we can really have TCP addresses work by forwarding sockets to container-local addresses, or whether we could/should use a bridge network + TLS + DNS + etc. instead.
Roll call on this. Who is OK to move forward with the above for Unix sockets, without waiting for a complete solution on TCP and UDP forwarding?
SGTM, unix socket support is relatively straightforward, unblocks a lot of valuable use cases and I can easily see how we can layer on the tcp/udp forwarding later in a backwards compatible way.
Activity
aluzzardi commentedon Nov 15, 2022
shykes commentedon Nov 15, 2022
aluzzardi commentedon Nov 15, 2022
shykes commentedon Nov 15, 2022
shykes commentedon Nov 15, 2022
@aluzzardi continuing our API design / bikeshedding discussion here to keep better records:
First reaction:
TCPSocketandUDPSocketdon't make it clear if we're listening or connecting.Technically it's not clear with
UnixSocketeither, but one can make an educated guess based on most common use cases: probably this is for connecting to a docker engine or ssh agent, so probably we're connecting. But you still have to guess.I think
dagger.Socketmight suffer from the same problem: is it a "listener", a "connecter", or both?Same problem as above: are we proxying connections inbound (to container) or outbound (from container)?
I think the answer might be different from inbound and outbound (which again are hard to distinguish in the proposed API).
Outbound: useful both in short-lived containers and long-lived services. Connect to docker engine; to ssh agent; to sql database; to api endpoint... Short-lived containers already do all those things: outbound proxying just gives them more endpoints they can connect to.
Inbound: most useful for long-lived services. It would be reasonable to not support them in short-lived containers IMO. But we have to be prepared to change our minds if users show us a reasonable use case we hadn't thought about (or if they just use horrible hacks to bypass the limitation).
Same answer as container-to-container. Different for inbound and outbound.
vito commentedon Nov 28, 2022
I'll fill in some gaps with what I learned from/did with Bass. The main thing I learned is that this kind of feature intersects many tricky subjects and the key thing will be figuring out where to embrace constraints.
Note that all of the following is really only relevant for TCP/UDP. I haven't considered Unix socket support yet. But it makes sense to discuss them all together anyway.
DNS + bridge networking
Bass containers reach services by addressing them over a bridge network, using DNS to resolve to container hostnames to IPs at runtime.
DNS was my solution for not busting the cache. The key point is to avoid having ephemeral container IPs ever enter into LLB. I got DNS to work by configuring Buildkit to use CNI and installing
dnsmasqand thednsnameplugin:buildkitd.tomlconfigBass uses the thunk 'name' as the DNS address, which is a hash of the thunk like
GRLO5DSIPLJPQ. It's not possible to set your own name. I didn't want the user to have to deal with collisions, so having content-addressed addresses made sense here, especially since Buildkit also handled deduping two thunks that represent the same service.Thunk addresses
Bass forces thunks to be self-contained by using thunk addrs as the primitive for passing addresses to commands.
Rather than something stateful (start service with hostname foo, wait for it to start, use it for a bit, and then stop it), thunk addrs contain the service that it's reaching, and Bass automatically runs it when needed. Buildkit handles deduping equivalent services (e.g. same thunk addr used by multiple clients) and stopping them when all clients go away.
Thunk addrs contain a string template where
$hostand$portare replaced with the actual host and port of the destination service at runtime. But this is obviously TCP specific.Health/liveness checks
Some really common cludgy code to write is "start this service and then do a
whileloop checking for it to be running before continuing on."I opted to just have Bass do this for you, since services are started on-demand. When a thunk uses
with-portthis tells Bass to poll for that port to be bound prior to running the thunk that depends on it.Note that this health check literally just opens a connection on the port and closes it. Other systems allow you to configure more sophisticated checks, but I haven't bothered with all that jazz.
TLS & certificate generation
My "north star" for services in Bass was to be able to run a registry as a service and use it for later thunks. This forced me to figure out how to do TLS, because using DNS or even container IP addresses for Buildkit's image fetching requires the registry to use TLS.
I decided to have Bass generate and manage its own CA and use it to mint certificates for any thunks that request a TLS cert/path using
with-tls. Bass's shim then injects the CA as a trusted cert for the container, so any thunks that use the service will automatically trust it.This worked out really nicely! It made it really easy to use TLS for any service.
I think that covers the interesting bits, but I may have missed/glossed over some parts. AMA!
@shykes For what it's worth, I don't share the same confusion with inbound/outbound; it feels pretty intuitive to me if I draw parallels to Host Directory access.
I see
Host.(Unix|TCP|UDP)Socketas something that gives you a reference to an existing address on the host, andContainer.With(Unix|TCP|UDP)Socketas something that makes a socket reachable inside the container's local filesystem/network on the specified path/port. The same way thatHost.Directorygives you aDirectorywhich can be mounted in to a container.Replace
HostwithContainer(for a container that runs a service) and I'd interpret it the same way, but drawing parallels toContainer.Directoryinstead.So to me this design feels pretty clean, but my only question is whether we can really have TCP addresses work by forwarding sockets to container-local addresses, or whether we could/should use a bridge network + TLS + DNS + etc. instead.
mircubed commentedon Nov 29, 2022
Adding a reminder for myself that are a few users who are stuck and need this:
gerhard commentedon Nov 29, 2022
We talked to @grouville about this today.
Updating the assigned person to reflect reality: #4025 💪
vito commentedon Nov 29, 2022
Ah thanks for assigning, should have made that more clear! 🙂
shykes commentedon Nov 30, 2022
Roll call on this. Who is OK to move forward with the above for Unix sockets, without waiting for a complete solution on TCP and UDP forwarding?
cc @sipsma @vito @aluzzardi @grouville @samalba @mircubed
sipsma commentedon Nov 30, 2022
SGTM, unix socket support is relatively straightforward, unblocks a lot of valuable use cases and I can easily see how we can layer on the tcp/udp forwarding later in a backwards compatible way.