Repository navigation
Description
Problem
In order for a client library or tool to communicate with the Dagger Engine, it must open a GraphQL session. When using a Dagger SDK this is abstracted away. However some developers need to target the GraphQL API without the help of an SDK. At the moment this is a painful experience because, although Dagger's GraphQL implementation is standard, the procedure for opening a session is specific to Dagger - and it is quite painful to understand and implement.
Specifically, the procedure for opening a graphql session has 3 problems:
- It's not documented: a client developer must ask questions and read other implementations to learn it
- It's misleading: learning the current interface creates misconceptions about Dagge's architecture.
- It's too much work to implement: when multiplied by many clients down the line, even small increments in implementation effort can make a difference.
People affected
As noted above:
some developers need to target the GraphQL API without the help of an SDK
This includes:
- Developers using languages for which a Dagger SDK is not yet available
- Developers of unofficial SDKs and exec wrappers
- Contributors to Dagger SDKs
- Contributors to the Dagger CLI, specifically the
dagger runwrapper
Additionally, some people may want to understand the process for opening a GraphQL session, even if they themselves don't need to implement it. This includes:
- Power users who wish to understand how to operate Dagger in depth before using it in production
- People looking to setup Dagger in a client-server mode, and being misled by the
$DAGGER_HOSTenvironment variable used by the SDKs.
Solution
Define a new "Dagger Session Interface" (DSI?) that 1) is well documented, 2) helps understand Dagger's architecture, and 3) is as easy to implement as possible.
Design proposal
For a client to open a session to a Dagger Engine, it must implement the Dagger Session Interface (DSI). There are two levels of implementations for DSI: basic, and advanced.
DSI-basic: no bootstrap
DSI-basic defines the simplest possible way to open a session to a Dagger engine. It can typically be implemented in 10 lines of code or less. The tradeoff is that the client cannot be executed standalone: the operator must execute it in the context of a dagger run command. For example: dagger run python mytool.py, or dagger go run mypipeline.go.
To implement DSI-basic, follow the steps below:
graph TD;
subgraph DSI-basic
start[Start]
if_env_set(Are $DAGGER_SESSION_PORT and $DAGGER_SESSION_TOKEN set?)
env_set_connect[connect to tcp://localhost:$DAGGER_SESSION_PORT, as user $DAGGER_SESSION_TOKEN]
error[Error]
success[Success]
end
start --> if_env_set
if_env_set --yes--> env_set_connect --> success
if_env_set --no--> error
DSI-advanced: with bootstrap
DSI-advanced extends DSI-basic with a bootstrap feature: if a session is not already open, then DSI-advanced specifies how to automatically open one, with no additional dependencies. A client implementing DSI-advanced can be executed standalone: it does not need to be wrapped with dagger run, and the Dagger CLI does not need to be installed. The tradeoff is that DSI-advanced is more complex to implement.
graph TD;
subgraph DSI-advanced
subgraph DSI-basic
start[Start]
if_env_set(Are $DAGGER_SESSION_PORT and $DAGGER_SESSION_TOKEN set?)
env_set_connect[connect to tcp://localhost:$DAGGER_SESSION_PORT, as user $DAGGER_SESSION_TOKEN]
success[Success]
end
start --> if_env_set
if_env_set --yes--> env_set_connect --> success
if_cli_installed(Is Dagger CLI installed in $PATH?)
cli_auto_install[Download the latest dagger CLI]
cli_session[Execute 'dagger session']
cli_read_env[Read json-encoded environment object from standard output of 'dagger session', export to environment variables]
if_env_set --no--> if_cli_installed
if_cli_installed --yes--> cli_session --> cli_read_env --> env_set_connect
if_cli_installed --no--> cli_auto_install --> cli_session
end
Open questions & issues
DAGGER_SESSION_PORT or DAGGER_SESSION_URL?
Since the session must always be accessible as a tcp port on localhost only, there are two options for the client to determine the URL:
| Option 1: _PORT | Option 2: _URL | |
|---|---|---|
| How to assemble session URL | http://localhost:$DAGGER_SESSION_PORT |
$DAGGER_SESSION_URL |
| In current proposal? | Yes | No |
| Pros | Makes it more clear that the session is local only; no confusion with $DAGGER_HOST; less opportunity for ill-advised hacks that will only end in tears |
Less characters to type for client developers; more flexibility for unknown future use cases |
| Cons | More characters to type for client developers; less flexibility for unknown future use cases | Less clear that the session is local only; confusion with $DAGGER_HOST; more opportunity for ill-advised hacks that will only end in tears |
Which CLI to download
In DSI-advanced, the client must download the Dagger CLI. But which version?
- Currently, clients in official SDKs specify an exact version
- How does an official client developer decide when to upgrade the hardcoded version, and to what value?
- What about everyone else? Should they also specify a version? If so, which version and how/when to change it? If not: then what?
Could dagger listen be folded into dagger session?
Currently these two commands are different (but hidden). They are close enough in functionality, though, that the possibility of merging them is intriguing.
Implementation Progress
- Update CLI to use engine.Start: CLI: use engine.Start directly #4119
- Add hidden
sessionsubcommand to CLI that is exact replica of engine-session bin (to start): Replace engine-session binary w/ cli session cmd. #4145 - Publish CLI on every push to main (same as engine image): Add cli publish from main and tests against it. #4208
- This is needed at minimum to give the SDKs something to pull before we do an official release of the CLI w/
sessionsubcommand, but it's probably desired anyways
- This is needed at minimum to give the SDKs something to pull before we do an official release of the CLI w/
- Update SDKs to pull CLI from S3 and invoke
sessionsubcommand: Update SDKs to pull CLI from S3 URL. #4194- Also requires bumping the CLI url instead of engine session URL when we publish the engine+cli
- Make SDKs use session tokens (same as
dagger run): Replace engine-session binary w/ cli session cmd. #4145- This will make the SDKs compatible w/
dagger run
- This will make the SDKs compatible w/
- Switch
DAGGER_SESSION_URL->DAGGER_SESSION_PORT: Switch session url to port #4285 - Re-activate macos provisioning tests: Add cli publish from main and tests against it. #4208
- Zipfile CLI download support on windows: Add zipfile cli download support for windows. #4286
- Change buildkitd state dir to something with control and configure: Change buildkit config+state to be dagger specific. #4287
- Add the rest of the builtin runner connection providers we get from buildkit and remove external access to
docker-imageSupport the rest of the default buildkitd conns. #4288 - Add docs for all this. Internal for
_EXPERIMENTAL_*params, external for the others (probably just need updates to this doc): Document new interface for using custom provisioned engine #4215
Spun off longer-term follow ups:
Activity
shykes commentedon Nov 15, 2022
sipsma commentedon Nov 15, 2022
sipsma commentedon Nov 15, 2022
shykes commentedon Nov 15, 2022
shykes commentedon Nov 15, 2022
sipsma commentedon Nov 15, 2022
sipsma commentedon Nov 15, 2022
shykes commentedon Nov 15, 2022
sipsma commentedon Nov 15, 2022
aluzzardi commentedon Nov 15, 2022
shykes commentedon Nov 15, 2022
marcosnils commentedon Nov 15, 2022
sipsma commentedon Nov 15, 2022
helderco commentedon Nov 15, 2022
marcosnils commentedon Nov 16, 2022
26 remaining items
sipsma commentedon Nov 30, 2022
@shykes @aluzzardi @vito @marcosnils posted the latest summary in my previous comment. Any other concerns left? If not, I'll break this down into subtasks (including as just discussed w/ Marcos updating the CLI to use the engine directly rather than the go sdk).
This all also ties heavily into OX, but I'm gonna make separate issues for more proposals there as it starts to branch too far out from this issue.
shykes commentedon Dec 1, 2022
Thanks for the summary! Some thoughts below. I also updated the top comment to be up-to-date with my understanding.
👍
👍
👍 Agreed, that is a security downside that we should acknowledge and document. I do believe that having an unprivileged local user that 1) may be untrusted, 2) has sniffing capability, and 3) is not root, is incredibly unlikely. A shop that cares about that risk would likely either make sure non-root doesn't have sniffing capability (seems like a no-brainer to me), or restrict local access to the machine. (Unprivileged, untrusted users that can sniff local traffic are bad news regardless of dagger).
👍 + 🙋🏻♂️
I updated the proposal to specify how that should be encoded. I went for a json object because that seemed the simplest to implement and also extend in the future. But we can bikeshed.
I updated the diagrams in the top comment, can you re-check that we're on the same page on the flow?
🙋🏻♂️ I left
DAGGER_SESSION_PORTin my proposal, and added an "open question" section to help us discuss and decide. I do think _PORT is better.👍 + 🙋🏻♂️ No issue here. One question out of curiosity: will it cause confusion that the secret is passed as a username instead of password? Is that common practice for access tokens? Since the original purpose was to avoid "weirdness" I thought I'd ask.
👍 I think those will be superseded by flags & configuration for
dagger runsoon enough, but that's why we prefixed them with_EXPERIMENTAL, so no objection :)sipsma commentedon Dec 2, 2022
JSON SGTM
I initially did this because it's what Stripe does: https://stripe.com/docs/api/authentication?lang=curl
And then some subsequent googling suggested that it's mostly arbitrary whether it's
(empty username, non-empty password)or(non-empty username, empty password)but occasionally some systems (client or server-side) want you to never have an empty username, so username-only is a fine default.I guess if we ever want this process to serve multiple sessions (not sure that we do, but who knows) it also makes some logical sense in that, with a lot of hand waving, you could then say that a session is closer to a user (i.e. scoped data) than a password.
I'm fine with this. Someday we'll have to deal with some minor annoyance around forcing the engine session to listen on both ipv4 and ipv6 loopback addresses (https://gist.github.com/aojea/94f6f483173641647c731f582e52f0b0) since we can't just tell the client which one to connect to when it's only the port, but that's fine, obscure and probably easy to address.
Other than that it's mostly arbitrary for me since we can start w/ port and expand if needed in the future. I guess it's less one-way-door-y in that sense.
cc @marcosnils in case you have any objections to switch to DAGGER_SESSION_PORT
Broad answer is that it's when we've done an engine upgrade and they have tested that their client works with it. For more specifics, I think we should split that off into a follow up issue (one of several that I'll be making once we're in agreement on the rest)
Yeah I think they will, I'm just waiting til I actually get to the implementation to confirm we can combine them since there's a small risk they have some subtle incompatibility in the interface (in which case
sessioncan just stay hidden indefinitely, no major harm done).Yep, my only extreme nit is that in DSI advanced we don't need to "export to environment variables"
shykes commentedon Dec 2, 2022
👍 Makes sense, thanks for the details.
👍
👍
You’re absolutely right, even worse it’s an unnecessary pollution of the client’s environment. I can’t remember why it seemed like a good idea a few hours ago. I blame sleep deprivation 😅
RealHarshThakur commentedon Dec 2, 2022
@sipsma Does this mean that when we do a
dagger.Connect(...), there would be a parameter to configure where the remote runner is?I'm trying to avoid using Docker. Is it possible to make it TCP-based similar to how BUILDKIT_HOST is? Or if it is the Dagger engine that's being exposed, HTTP-based?
PS: I'm stuck on v0.3.x of Dagger since remote buildkit worked with
BUILDKIT_HOSTand dagger.Connect(..)inferred it
sipsma commentedon Dec 2, 2022
@RealHarshThakur
For now we're thinking of an environment variable that is set when calling
dagger.Connect, will that work for you? We are trying to avoid putting experimental, unstable parameters in our arguments todagger.Connect, but if an env var creates hardship let us know.You should be able to avoid Docker, however you will need to run the dagger engine somewhere and that engine is distributed as a container image. While we haven't tested it, I can't image why it fundamentally wouldn't work with non-docker container runtimes (podman/lima/etc.).
The caveat (for now anyways) is that if you don't want to use docker you will need to set up the container yourself somewhere ahead of time and then set
_EXPERIMENTAL_DAGGER_RUNNER_HOSTto point to it. We should be able to supporttcp://addresses pretty easily for that though.Does that sounds like it'd work for you?
RealHarshThakur commentedon Dec 2, 2022
Env var works :)
I plan to run it with containerd (orchestrate it with K8s in future, maybe). IIRC, Podman/lima work with
docker://but containerd doesn't.Yep, that sounds great.
Would the image be a bundled Dagger engine+buildkit daemon? If so, would it be similar to load balancing and scaling Buildkit so cache is still shared?
shykes commentedon Dec 6, 2022
Just double-checking that we’re on the same page on this one @sipsma @RealHarshThakur @aluzzardi .
Given the general trend of making
dagger runthe primary mechanism for operator control, I think a logical conclusion is that configuration of remote engine will follow the same path. This would mean (in the future) deprecating_EXPERIMENTAL_DAGGER_RUNNER_HOSTin favor ofdagger run& associated config flags/files/env vars.Still relevant :)
RealHarshThakur commentedon Dec 6, 2022
Yeah, works for me.
sipsma commentedon Dec 7, 2022
Sent out the first part of implementing all this: #4119
I also updated the description of this issue w/ the task list needed to implement it fully (cc @shykes). I considered breaking each task into a separate issue but I don't really see much benefit since they need to be done in quick succession of one another, not really left in the backlog. Happy to break into separate issues if others prefer though.
mircubed commentedon Dec 13, 2022
note to self - we should update this help thread once this is closed -https://discord.com/channels/707636530424053791/1031785076029128784