Skip to content

Stabilize the Engine remote protocol? #9516

Closed

Description

@shykes

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:

  1. Promote the escape hatch to a fully supported feature. This means replacing _EXPERIMENTAL_DAGGER_RUNNER_HOST with 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:

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

  1. 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?

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

  3. Decide

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

  1. gerhard commented on Mar 4, 2025

    @gerhard
    Contributor

    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_HOST combines both concerns and therefore pulls in the Compute Drivers context. Before we stabilize _EXPERIMENTAL_DAGGER_RUNNER_HOST into a first-class feature, the consensus is that we want to reduce its scope. The proposal is to:

    1. Introduce a new CLI flag that configures a remote Engine HTTP connection only (no provisioning cocerns)
    2. Introduce a new environment variable alternative to the above

    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 is HTTP, 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, no https support, 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_TOKEN should 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:

    1. Does the narrower scope seem right to you?
    2. What is the connection string format that we want to start with?
    3. Thoughts on enforcing CLI <-> Engine authentication via Dagger Cloud if either is connected to Dagger Cloud?
    4. Is there anything else that we must discuss before we can start implementing this narrower feature?
    5. What must happen in follow-ups?
    6. What are we comfortable deferring?

    While this comment already answers 1.-4., this is what I think about the rest:

    1. 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.
    2. 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?

  2. shykes commented on Mar 4, 2025

    @shykes
    ContributorAuthor

    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.

  3. gerhard commented on Mar 4, 2025

    @gerhard
    Contributor

    We assume that an Engine exists, and we need to connect to it via a remote TCP/IP connection. 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?

  4. sipsma commented on Mar 5, 2025

    @sipsma
    Contributor

    The "REP", the protocol that is private today but we are considering making public

    @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_HOST are just specifying how the connections are made:

    • tcp://, unix://, etc. - just directly connect using normal ip/unix socket
    • ssh:// - connect via ssh
    • docker-container:// - get a net.Conn by invoking docker exec as a subprocess and proxying through it's stdio to simulate a net.Conn
    • docker-image:// - first pull the docker image, start it, then do the same thing as docker-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.

    Today authentication is not our problem. If we make the REP public, it will be. How do we want to handle that?

    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.

    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?

    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.

    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?

    The only way you could ever avoid any possibility of client/server version incompatibility is to:

    1. Never break the interface again
      • Extremely limiting obviously, though there's no known need to make breaking changes here at this exact moment
    2. Always have the CLI provision the engine it connects to
      • This rules out use of a pre-provisioned shared engine, which is also extremely limiting for users. I don't know of any real way to support a pre-provisioned engine that doesn't result in some client/server version compatibility still existing, no matter how we rearrange it.

    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:

    1. retains the ability for users to connect to pre-provisioned engines
    2. doesn't just replace one version compatibility concern for another

    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 don't see the coupling or sequencing requirement between creating / deleting and connecting. Do you @jedevc @sipsma ?

    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

    1. We make the hook for getting connections (what's called _EXPERIMENTAL_DAGGER_RUNNER_HOST) public and documented
      • To start, these do not incorporate any sort of provisioning. It's purely "give me a connection" and the CLI connects, does it's version compatibility checks, etc.
      • I'll just call this stabilized feature a "Connection Driver" as a placeholder for now
    2. We design and introduce a concept of a Provisioner, which does handle requesting a new engine be created/retrieved
      • Importantly, the Provisioner works by returning a Connection Driver to use to connect to the engine

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

  5. shykes commented on Mar 5, 2025

    @shykes
    ContributorAuthor

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

  6. jedevc commented on Mar 5, 2025

    @jedevc
    Contributor

    The sequencing I'm imagining which incorporates both connecting and then provisioning

    We make the hook for getting connections (what's called _EXPERIMENTAL_DAGGER_RUNNER_HOST) public and documented

    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_HOST today 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 in docker-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.

  7. jedevc commented on Mar 5, 2025

    @jedevc
    Contributor

    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?

    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 /Info endpoint - 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 string vX.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).

    if err := c.startEngine(connectCtx); err != nil {
    return nil, nil, fmt.Errorf("start engine: %w", err)
    }
    if !engine.CheckVersionCompatibility(engine.NormalizeVersion(c.bkVersion), engine.MinimumEngineVersion) {
    return nil, nil, fmt.Errorf("incompatible engine version %s", engine.NormalizeVersion(c.bkVersion))
    }

    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

    // MinimumEngineVersion is used by the client to determine the minimum
    // allowed engine version that can be used by that client.
    MinimumEngineVersion = "v0.16.0"

    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:

    • Every time we make a change to a session attachable API, or some other "REP" change, we add a new capability.
    • When an engine wants to access data from a client using an attachable (e.g. a Git credential fetch, or a local directory load), we assess whether the client exposes the capabilities we need, and present a neat error if not (instead of "you need a newer dagger version").

    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.

  8. sipsma commented on Mar 5, 2025

    @sipsma
    Contributor

    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_HOST today 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 in docker-image:// eventually.

    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.

  9. gerhard commented on Mar 5, 2025

    @gerhard
    Contributor

    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.

  10. shykes commented on Mar 5, 2025

    @shykes
    ContributorAuthor

    Would it make sense to push the Provisioners discussion into what is today called #5583 and keep this issue focus on the Connection Driver?

    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.

  11. reopened this on Jul 25, 2025
  12. shykes commented on Jul 25, 2025

    @shykes
    ContributorAuthor

    Here's a POC: #10790

  13. locked and limited conversation to collaborators on Jul 25, 2025
  14. converted this issue into a discussion #10791 on Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions