Repository navigation
Description
Problem
Officially, there is no supported way to connect remotely to an engine. But there is an escape hatch (_EXPERIMENTAL_DAGGER_RUNNER_HOST) and lots of people use it in production. In fact it has become a de facto standard for everyone running Dagger in self-hosted CI clusters.
This disconnect between what users do, and what we support, must be resolved. We face a simple choice:
- Promote the escape hatch to a fully supported feature. This means replacing
_EXPERIMENTAL_DAGGER_RUNNER_HOSTwith a stable environment variable, a CLI flag; but also documenting the underlying protocol (which I will call the "remote engine protocol"), clarifying its role and relationship to the Dagger GraphQL API; versioning it; and gracefully handle mismatches between client and engine versions.
or:
- Discontinue the escape hatch, and propose something better instead.
Either way, we need to make a clear decision, and we need to make it soon. At this point we have enough production usage that the lack of clarity itself is becoming a reliability issue.
Solution
-
Explore the ramifications of option 1. What are the drawbacks and benefits of stabilizing the remote engine protocol at it exists today? How will we deal with versioning? Does it fit in our future vision for a scale-out engine and dagger-native infrastructure?
-
Define the alternative. If we don't stabilize the REP, then what? I have a strawman proposal which I will flesh out in the comments. I think it's healthy to challenge the default solution, even if we end up choosing it anyway.
-
Decide
-
Implement the solution we choose, document it clearly, and communicate it to our production users
Design considerations
Two different protocols
In the past my biggest concern was that the REP and the GraphQL API had nothing in common. The former was a thin wrapper over the buildkit grpc protocol. The latter was a simple http endpoint that could only be accessed locally. This made it very difficult to stabilize and document the REP, because it was so alien, and the relationship between the two protocols so difficult explain. This has been one of my main objections to making it public.
Today this has changed for the better. As @sipsma explained to me today: the REP and the GraphQL API are cleanly layered, and together they form the complete Dagger API.
Terminology
In spite of my best efforts in this issue, we don't have a canonical terminology for:
- The GraphQL part of the API that is public today
- The "REP", the protocol that is private today but we are considering making public
- The overall API that is made of the other two parts
Authentication
Today authentication is not our problem. If we make the REP public, it will be. How do we want to handle that?
From past experience, I am not a fan of stuffing the dagger binary with tons of TLS and other auth-related flags... It may be inevitable but I want us to be deliberate about this. How do we respect separation of concerns? Are we sure we want to take that responsibility in a production setting?
Load-balancing
People will hide engines behind load-balancers. They will try to cache HTTP requests to them. They will try all sorts of topologies, some very smart, some not so much. All of them will be our problem. How do we feel about that?
We need to get ahead of this, and think about the production topologies we want today; and also the topologies we will want in the future, when the engine evolves to support scale-out job dispatching, and cache persistence - and we know those features are coming.
Versioning
This is the big one... How will we version this API? How will we manage the version matrix between clients and servers? There are so many ways to get this wrong... And this is a one way door. Once we go through it, there's no going back.
The day Docker crossed that one-way door, is the day it lost a lot of options in future evolution of its stack.
Engine / CLI split
So far the division of responsibilities between CLI and Engine has been fluid. We have moved large chunks of functionality from one side to the other, and nobody even noticed. The day we make the remote protocol public, that's over. It won't be impossible to move the functional boundary, but it will be much harder.
We talked about the possibility of merging CLI and engine in "one binary"; or at least making their distribution more tightly coupled, to make distribution and provisioning easier, and to collapse the version matrix. If we make the REP public, doesn't that take us in the opposite direction, of enshrining a version matrix that we hoped to make disappear?
As @jedevc said today, maybe it was wishful thinking anyway - maybe the version matrix was never going to be collapsable. But we should still discuss where we stand on these past ideas.
Compute drivers
Remember those? I still think we need them... Docker is still hardcoded in the CLI, and it's weird. How does the REP fit into that design?
Activity
gerhard commentedon Mar 4, 2025
We talked about this with @jedevc & @sipsma and the key take away from that conversation is that we want to split the connecting & provisioning concerns.
Today,
_EXPERIMENTAL_DAGGER_RUNNER_HOSTcombines both concerns and therefore pulls in the Compute Drivers context. Before we stabilize_EXPERIMENTAL_DAGGER_RUNNER_HOSTinto a first-class feature, the consensus is that we want to reduce its scope. The proposal is to:The value will be a URL in a format that is yet to be defined.
Note
While the simplest thing would be to re-use the existing
tcp://<FQDN>[:PORT]connection format, considering that the underlying protocol isHTTP, my proposal is to use the universally accepted format, i.e.<http|https>://[USER:PASS]@<FQDN>:[PORT][?ARGS]. I am keen to simplify as much of this as possible - for example, nohttpssupport, or no[USER]:[PASS]- but I am thinking a few steps ahead here in terms of the discussions that we should be having around:Another aspect worth mentioning is that today the CLI connects to the Engine's HTTP API, and then upgrades to gRPC as needed. This is seamless, no extra configuration needed.
While we did not discuss this, I am wondering if we want to lean on Dagger Cloud for authentication. To be specific, I am wondering whether an Engine which is connected to Dagger Cloud via
DAGGER_CLOUD_TOKENshould only accept connections from a CLI that is also authenticated to Dagger Cloud, and refuse all other connections.In the interest of encouraging quick replies - especially from @jedevc @sipsma @shykes - I am keeping this comment focused on what was discussed. A few questions that we might want to answer:
While this comment already answers 1.-4., this is what I think about the rest:
Compute Drivers- I am going to comment on that issue next. My intention is to address scale-out engine & dagger-native infrastructure in that context.Load-balancing(this is a control plane concern in my mind, not CLI) &Versioning(this is already handled by the version compatibility matrix as far as I know)What are your thoughts on the above?
shykes commentedon Mar 4, 2025
Before I can comment on this half of the proposal @gerhard @jedevc @sipsma I need the other half. Reducing the scope of conversation doesn't automatically reduce the scope of the design. It may just sweep parts of it under the rug.
If we ship a flag with no concern for provisioning, we're making a bunch of implicit decisions. For example we're deciding that any client version can connect to any server version and it's our responsibility to manage the full compatibility matrix. I think we should make that decision explicitly, not sweep it under the rug.
gerhard commentedon Mar 4, 2025
We assume that an Engine exists, and we need to connect to it via a remote
TCP/IPconnection. That is the boundary of this issue, both in terms of discussion & design.I just started collecting my thoughts on how an Engine gets provisioned, via a "compute driver" in the other issue, which is focused on creating & deleting Engines, with no connection concerns.
I don't see the coupling or sequencing requirement between creating / deleting and connecting. Do you @jedevc @sipsma ?
As for the version compatibility part, my understanding is that this is already handled in https://github.com/dagger/dagger/blob/bfc0a943594bf7b8b9566da5754c9ffc0fa26e74/engine/version.go . Did I misunderstand the purpose of this built-in functionality?
sipsma commentedon Mar 5, 2025
@shykes We don't need to make all of that public. The only thing we need to be made public is the hook the CLI uses to get a network connection to the engine server (in concrete terms, the CLI needs a
net.Conn). Today the various values of_EXPERIMENTAL_DAGGER_RUNNER_HOSTare just specifying how the connections are made:tcp://,unix://, etc. - just directly connect using normal ip/unix socketssh://- connect via sshdocker-container://- get anet.Connby invokingdocker execas a subprocess and proxying through it's stdio to simulate anet.Conndocker-image://- first pull the docker image, start it, then do the same thing asdocker-container://After that, the CLI can make all the requests it needs to the REP without exposing the details of the REP to the hook used to get network connections.
The only reason we'd need to make the REP public is if we wanted to support totally custom clients connecting to the engine. E.g. someone wanted to write their own dagger CLI. As far as I know that's never come up as a use case we need/want to support (and it would be borderline implausible anyways once you consider the amount of session attachables that would need to be ported, both now and in the future).
So unless I'm missing something fundamental there, we can get away with just making the "connection driver" interface public, no need for the whole REP.
Referring to the above, it can be handled by the hook used to get connections to the engine, after which the CLI just uses the net.Conn with any auth wrapping taken care of. You can already see that today with the
ssh://value where we outsource auth to the hook and don't do anything special with SSH in our CLI's code directly. You could do the same thing with TLS, auth tokens, etc.I think even something like token refresh could be hidden behind that interface, but worst case supporting that would just be a slight extension of the "connection driver" interface.
If someone wants to do load balancing with sticky sessions and a reverse proxy sort of approach, that's fine. The CLI doesn't need awareness of it.
For more intelligent load-balancing (e.g. spread a single build across multiple machines), the engine servers must be the one distributing that work, so again the CLI does not need awareness.
The only way you could ever avoid any possibility of client/server version incompatibility is to:
The existing version compatibility checks exist today and I don't know how to get rid of the need of them without giving up one of the above. Unless there's a concrete idea on how to avoid the compatibility checks that:
I don't think it's worth it. We just have to continue dealing with it like we already do today. That being said, I'm happy to find ways of limiting it, reducing the pain, etc. of course. I just don't see it being eliminated fundamentally.
I think there's some degree of coupling in the big picture, but agree that we can do this incrementally sort of how you described.
The sequencing I'm imagining which incorporates both connecting and then provisioning
_EXPERIMENTAL_DAGGER_RUNNER_HOST) public and documentedObviously there's plenty to discuss in terms of the Provisioner interface, and a few details to fill in for the Connection Driver. But if we can agree on that sort of approach, I think it's our best chance of making forward progress soon since the effort can be done incrementally.
shykes commentedon Mar 5, 2025
@sipsma could you explain (roughly) how the version checks work today? How does the CLI determine whether it can use a given engine version? Are there know limitations and planned improvements to that system?
Thanks for sharing all these details it's super helpful.
jedevc commentedon Mar 5, 2025
I'm good with the sequencing here, but just to nitpick - I think that one of the reasons to design these together, is that the
docker-image://in_EXPERIMENTAL_DAGGER_RUNNER_HOSTtoday is actually more of a Provisioner, instead of a Connection Driver. So ideally I'd like to sketch a path to what a Provisioner actually looks like, so we can make sure that there's a good home for the functionality that's indocker-image://eventually.I've wanted to clean this up for ages, e.g. the garbage collection, the dangling images, etc - these all ideally need resolving, but everytime I've tried, it becomes apparent that's it's just got all the same problems as Provisioning.
jedevc commentedon Mar 5, 2025
Jumping in 👋
There are two types of version checks generally - between the engine and modules, and between the cli and the engine (the latter is what we're interested in here).
When the CLI connects to an engine it performs a naive health check by hitting a gRPC
/Infoendpoint - essentially, it's hitting a buildkit implementation (which we're still exposing in the dagger engine, it's the same mechanism that we end up using to attach session attachables). This endpoint returns metadata about the version of the dagger engine - specifically the semver stringvX.Y.Z-prerelease+build(the same data that the{ version }query would return). (in the future, we could just get this data via a direct graphql query - as we reduce our dependency on buildkit).dagger/engine/client/client.go
Lines 213 to 218 in 09acd85
With the version fetched, we store it in on client object in the CLI. Before continuing with any operations, we do a quick compat check - comparing the CLI version to the fetched engine version. We don't require them to match exactly! Instead, the CLI has knowledge about it's "minimum" supported engine version - that's
MinimumEngineVersion:dagger/engine/version.go
Lines 32 to 34 in 6fa1d3a
If the engine version is less than this required version, we just error out.
That's how it works now.
However, there's some potential to adjust this in the future. One idea I've had depends on the idea that the CLI is just another client - just like a module is - and we have version compatibility here. Actually, the main reason that we don't support a much more relaxed compatibility check (the check is still necessary though!) is because of session attachables - not because of changes in the actual dagger API.
So this is where I think the capability model we've discussed comes into play:
This would be a bit of work, but probably not that much - in return, we'd allow a wider range of CLIs to talk to a wider range of engines - as long as we don't ever break our Dagger API (which is what we're already committing to for modules).
TL;DR - there's a potential piece of work in the future to increase our compatibility, but it's still not going to be perfect - e.g. if a future engine requires a new CLI attachable to fetch, say, some LLM specific config, then if the doesn't support that, then we have to error out.
sipsma commentedon Mar 5, 2025
Oh yeah I totally agree, sorry that wasn't clear in what I meant by sequencing. I mainly was thinking in terms of implementation. I guess we don't need every last detail filled in on the design for Provisioners filled in before starting first implementation steps, but agree it would be good to have at least a gist of it first.
gerhard commentedon Mar 5, 2025
It's great seeing this issue come alive!
Would it make sense to push the Provisioners discussion into what is today called Compute Drivers and keep this issue focus on the Connection Driver?
While my assumption was that we would keep the first implementation of this stable flag / environment variable limited to
http / https, if we think that the other protocols will be easy to implement & maintain, I'm all for it.shykes commentedon Mar 5, 2025
No, we have to discuss it together. I challenge that "connection driver" and "provisioner" are even different concepts. It's all compute drivers to me. By splitting them up before even discussing their design, you're front-loading a design decision before the design discussion even started.
shykes commentedon Jul 25, 2025
Here's a POC: #10790