Skip to content

Enable use of custom provisioned engine images #4105

Closed

Description

@sipsma

We have many requests from users to support a few interrelated features:

These all require specific individual solutions, but the commonality between them is that they require use of an engine image different than the default ghcr.io/dagger/engine one we publish and execute in our default provisioning codepath. The difference may be in that they require more files in that engine (e.g. the CA certs), that they need some sort of non-default configuration or that they need to execute it differently than our default provisioning codepath does.

This issue is just meant to tackle the high-level approach to this problem. After we agree on this we can tackle the particulars of each feature individually in separate issues.


Preferred Solution - Experimental Docs in our Git Repo

To start, I think we should just document the process of customizing the engine. The docs also shouldn't live on our website quite yet as they will be referencing experimental unstable features that we will likely end up adjusting (if not entirely rethinking).

  • The docs can instead just live in markdown in our git repo for now and will be headed with warnings that this is all experimental+unstable. Our website could have a FAQ about custom engine images that points to this internal doc, but shouldn't emphasize the use case more than that yet.
  • I think this is the right place to start because this is a really tricky use case to get right. "Running engine in a custom way" opens up a pandora's box of possibilities. Ideally, we should not only try to support as many of these as possible in the long run, we should also ensure that they each work smoothly. That implies significant engineering effort not only to get them working but also tested.
  • If we dive right into something like docker machine or buildx builders where we introduce automation around managing and customizing these workers, we'll be making a bigger commitment to supporting that interface stably and also putting in a bigger engineering effort towards something that we may end up changing, reverting, etc.

Overall, starting with docs allows us to unblock users who need these features and then gather data from them on what works well and what needs a better OX. Once we have that data, we can start putting together more long term solutions (or, there's always a chance our process will actually be good enough and we can just move it from experimental -> officially supported and doc it on our website).

One big risk worth calling out here is that this means we will be documenting how to setup buildkit specific config files like /etc/buildkit/buildkitd.toml, so we will be directly exposing APIs we don't control directly.

What to doc

Where is our base image?

We are working on setting up a vanity URL for our registry. Once that's ready we'll just point users to it.

How do I customize the base image?

This will depend heavily on how users normally build images. E.g. if you use dockerfiles, then you can use that to pull our image, customize it and push it to a registry. If you use toolxyz, use that. Etc.

We thus can't document this thoroughly. For now, just giving one simple example (e.g. Dockerfile) should suffice.

Of course, users can also user Dagger to customize the engine image, which in theory is ideal. This would be especially awesome in a future w/ extensions where we could have an engine image extension that outputs a Container for our current image based on input customizations like CA certs, etc.

The downside is that this creates chicken-egg bootstrapping problems. We're willing to deal with that in our CI, but the way of solving that generally across any sort of environment users may need to execute in is not clear. At the very minimum, we need more user data to know whether and how we could solve this. And the best way to get user data is to let them first customize using whatever build tool they normally use and get feedback from there.

How do you know when the base image is updated? When should you upgrade to use it?

For now, to know about new engine image releases just subscribe to our Github releases.

  • If anyone knows of better approaches here I'm all ears, I admittedly don't have a ton of experience around this sort of problem specifically

To know which engine base image a given SDK is compatible with, I think we should for now just highlight that in the release notes for the SDK. E.g. This SDK uses registry.dagger.io/engine:v0.5.6.

How do you configure CA certs for a registry in the image?

It will require putting them somewhere in the image and then setting up /etc/buildkit/buildkitd.toml as (sort-of) documented here: https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md

How do you configure "engine-wide" settings like turning on privileged execs, gc policies, etc.?

This again will just require setting up /etc/buildkit/buildkitd.toml as (sort-of) documented here: https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md

Once you've built an engine image, how do you run it?

This will also depend very heavily on how the user runs container images generally. Specifics vary from one container engine to another.

We can just document the docker run flags we use, explain them and tell users to use an equivalent setup on the engine of their choice.

How do you tell an SDK and/or CLI to connect to the custom engine once its running?

We will tell them how to use _EXPERIMENTAL_DAGGER_RUNNER (as described here: #3830)

Alternative Possibilities

A lot of this will be possible in the longer-run; we aren't ruling them out by not doing them now.

Custom config file and/or entrypoint flags (rather than passing through to buildkitd)

Rather than directly having users setup /etc/buildkit/buildkitd.toml, we can immediately jump into using our own config file that only exposes the knobs we want to expose.

Alternatively, instead of a config file we could make our entrypoint be a wrapper script that exposes those knobs via command line flags.

If we wanted to truly and fully control this in a way where users can't skirt around it we'd need to wrap the full buildkitd binary, which is entirely possible too.

CLI-based management of workers

This would be something like docker machine or the buildx builder interface where runners can be provisioned and managed via a CLI interface.

As much as I'd like to avoid this, it feels inevitable in the very long run that we'd want this eventually. If we don't, someone else will create a utility for doing this. However, as stated above, it's very tricky to get this right so we shouldn't rush into it until we have more initial feedback and data from users.

Use Dagger to build custom Dagger engines

As mentioned above, this is great in every way except for the bootstrapping headaches it will probably cause in many scenarios. We shouldn't rule out having an extension that builds custom engines in the long run, but we shouldn't rush into making it the one and only way immediately.

Activity

  1. added
    area/engine
    on Dec 5, 2022
  2. self-assigned this
    on Dec 5, 2022
  3. sipsma commented on Dec 5, 2022

    @sipsma
    ContributorAuthor
  4. shykes commented on Dec 6, 2022

    @shykes
    Contributor

    I am very wary of enabling this as a support user-facing feature (even for power users). I think all the requirements you listed can, and should, be implemented without requiring a custom image:

    Support for custom CA certs needed to connect to private registry: #3943 #2142 (comment)

    This should be exposed in the Dagger API. Having it manageable only by a static config file is bad UX, and we should not inherit it from buildkit.

    Setting up a custom runner not in docker #3939

    Can't this be done with the regular Dagger Engine image, just with a different provisioning method?

    Use of an engine image pulled from a mirror https://discord.com/channels/707636530424053791/1031785076029128784/1044829278367404132

    Same as above: same image, just different provisioning method.

    Connecting to the engine over different protocols like tcp #3939

    We should design and implement this as a regular Dagger Engine feature. Exposing underlying buildkit configuration IMO is opening a pandora box that we will never be able to close.

    Support for running privileged execs #3874
    Crucially, this is probably something we can't enable by default, it has to be something that users can opt into enabling in their engine if they are comfortable w/ the security tradeoffs.

    I disagree actually. It should always be enabled, and gated by adding a concept of "privileged operation" and "privileged client" to the GraphQL API. Then add an authorization hook to the engine, to let operators decide which clients, if any, have access to the feature. But the feature should always be enabled, without having to tweak static configuration files or ask sysadmins to do it. Otherwise, the Dagger ecosystem will splinter in two parts: the engines with privileged exec enabled, and those with privileged exec disabled. Some pipelines will only run on one of those two subsets of the ecosystem. This is a fundamental breach of our promise of "run any pipeline anywhere" and must be avoided at all cost.

    No issue for it yet AFAIK, but @marcosnils mentioned a possible need to configure buildkitd GC policies in playground to help prevent the disk from filling.

    I don't know the specifics, but same idea as above.

    Of course implementing all the above will take time, and I realize some of it is difficult design & engineering. In the meantime, power users are stuck without all the configuration knobs they want and would like an escape hatch. I think the escape hatch should be to fork the dagger repo and build your own image from source. This should not be documented as a user-facing feature. As painful as it is to have some power users give up because the feature they need is not yet ready, and doing it all from source without user docs is too hard; that pain is nothing compared to having power users cross all these one-way doors.

    The risk if we are not careful is that the stopgap becomes the preferred solution, and either we never get around to shipping the "real" solution, or by the time we do it doesn't matter, because all users rely on the stopgap and are not willing or able to switch.

  5. changed the title [-]Enable use of custom engine images[/-] [+]Enable use of custom provisioned engine images[/+] on Dec 6, 2022
  6. sipsma commented on Dec 6, 2022

    @sipsma
    ContributorAuthor

    @shykes your concerns make sense, I was approaching this from the perspective that we're getting a ton of requests around all this and wanted to find the quickest possible solution to giving users a barebones escape hatch so we can get more data and then use that to figure out the right end design.

    You're right though that technically they are free to just fork right now. I think that increases the risk that they just give up or stay forked for a long time, which has to be balanced against the other risk of them using our temporary solution and pressuring us to support it for a long time.

    But if we can find consensus on the right long-term approach and get it implemented in a short time frame, I guess that's the best of both worlds.

    This should be exposed in the Dagger API. Having it manageable only by a static config file is bad UX, and we should not inherit it from buildkit.

    Good point, it will require upstream changes in buildkit but I thought about it and realized there might be a relatively straightforward path to implementing it actually. Asked about it here: moby/buildkit#3366

    Can't this be done with the regular Dagger Engine image, just with a different provisioning method?

    Same as above: same image, just different provisioning method.

    Due to my original approach, I was grouping everything together into this issue that would end up having the solution of "just document it and have the user set _EXPERIMENTAL_DAGGER_RUNNER". So that includes both when you need a truly custom image and when you just need to pull the image or run it in a different way. In my original thinking they are all tied together.

    The title of the issue wasn't clear though, that's my bad, I changed it now to reflect that. Depending on how we decide to approach the problems here, it will most likely make sense to split this up into separate issues. I'll do that at that time.

    We should design and implement this as a regular Dagger Engine feature. Exposing underlying buildkit configuration IMO is opening a pandora box that we will never be able to close.

    Yeah I'm all on board with not directly exposing the buildkitd configuration if we consider the risk too big and are willing to trade some more upfront effort.

    The question then is where this knob for configuring where the remote engine listens should exist. If we are going right to what we want the long-term solution to be rather than a temporary escape hatch, then my only immediate idea is to include the provisioning management as part of the CLI since it's something that has to be configured when the engine starts.

    Let me know if there's other ideas on approaches here. Designing a CLI interface around all that will be a separate issue if we want to pursue it.

    I disagree actually. It should always be enabled, and gated by adding a concept of "privileged operation" and "privileged client" to the GraphQL API. Then add an authorization hook to the engine, to let operators decide which clients, if any, have access to the feature. But the feature should always be enabled, without having to tweak static configuration files or ask sysadmins to do it. Otherwise, the Dagger ecosystem will splinter in two parts: the engines with privileged exec enabled, and those with privileged exec disabled. Some pipelines will only run on one of those two subsets of the ecosystem. This is a fundamental breach of our promise of "run any pipeline anywhere" and must be avoided at all cost.

    Same as before, I'm all onboard with not exposing this knob via buildkitd config directly and also on board with figuring out the ideal long term approach and doing that right away instead if we are willing to trade time+effort.

    The thing that immediately comes to mind is something like k8s w/ RBAC based on mutual tls certs or similar. If we're going that route, it also is probably something that should be configurable at runtime. Maybe the engine should expose an "admin" graphql API for configuring knobs like who's allowed to run a privileged exec, what the GC config is, etc. This would obviously only be served to authorized clients.

    That's no small task, but let me know if you agree something in that direction is where we'd want to go in the long run. Then we can start figuring out the path to it (in a separate issue).

  7. shykes commented on Dec 11, 2022

    @shykes
    Contributor

    @shykes your concerns make sense, I was approaching this from the perspective that we're getting a ton of requests around all this and wanted to find the quickest possible solution to giving users a barebones escape hatch so we can get more data and then use that to figure out the right end design.

    You're right though that technically they are free to just fork right now. I think that increases the risk that they just give up or stay forked for a long time, which has to be balanced against the other risk of them using our temporary solution and pressuring us to support it for a long time.

    Agreed on all points.

    But if we can find consensus on the right long-term approach and get it implemented in a short time frame, I guess that's the best of both worlds.

    Yes please 😁 I believe it's doable.

    This should be exposed in the Dagger API. Having it manageable only by a static config file is bad UX, and we should not inherit it from buildkit.

    Good point, it will require upstream changes in buildkit but I thought about it and realized there might be a relatively straightforward path to implementing it actually. Asked about it here: moby/buildkit#3366

    An upstream change will be cleaner. But while we wait for that, we could just use duct tape? For example parametrize it in our OCI image somehow? As a volume to be mounted, or some other mechanism? The key being that we release the engine as an OCI image and not an individual binary, which gives us an unfair advantage over upstream buildkit for implementing solutions.

    Can't this be done with the regular Dagger Engine image, just with a different provisioning method?

    Same as above: same image, just different provisioning method.

    Due to my original approach, I was grouping everything together into this issue that would end up having the solution of "just document it and have the user set _EXPERIMENTAL_DAGGER_RUNNER". So that includes both when you need a truly custom image and when you just need to pull the image or run it in a different way. In my original thinking they are all tied together.

    The title of the issue wasn't clear though, that's my bad, I changed it now to reflect that. Depending on how we decide to approach the problems here, it will most likely make sense to split this up into separate issues. I'll do that at that time.

    Yeah, I see why you grouped them, but it makes sense to split them, as the timing and design constraints are different IMO:

    • Run the unmodified dagger engine image yourself, customize how it's provisioned: no big design risk, high pressure to ship it soon
    • Create a custom dagger engine image to bypass missing configuration options: big design risk, we should take the time to add the configuration options instead, those too impatient should fork

    The question then is where this knob for configuring where the remote engine listens should exist. If we are going right to what we want the long-term solution to be rather than a temporary escape hatch, then my only immediate idea is to include the provisioning management as part of the CLI since it's something that has to be configured when the engine starts.

    I think we should rely primarily on the OCI image being the only official delivery mechanism for the engine. Provisioning by our CLI is potentially useful, but will never be the soure of truth as some (most?) operators will prefer using their existing provisioning tools. If and when we ship provisioning from the Dagger CLI, it can be built on top of the same OCI image and associated configuration knobs.

    Let me know if there's other ideas on approaches here. Designing a CLI interface around all that will be a separate issue if we want to pursue it.

    I disagree actually. It should always be enabled, and gated by adding a concept of "privileged operation" and "privileged client" to the GraphQL API. Then add an authorization hook to the engine, to let operators decide which clients, if any, have access to the feature. But the feature should always be enabled, without having to tweak static configuration files or ask sysadmins to do it. Otherwise, the Dagger ecosystem will splinter in two parts: the engines with privileged exec enabled, and those with privileged exec disabled. Some pipelines will only run on one of those two subsets of the ecosystem. This is a fundamental breach of our promise of "run any pipeline anywhere" and must be avoided at all cost.

    Same as before, I'm all onboard with not exposing this knob via buildkitd config directly and also on board with figuring out the ideal long term approach and doing that right away instead if we are willing to trade time+effort.

    👍 yes I completely agree it's a tradeoff, but I believe it's worth it.

    The thing that immediately comes to mind is something like k8s w/ RBAC based on mutual tls certs or similar. If we're going that route, it also is probably something that should be configurable at runtime. Maybe the engine should expose an "admin" graphql API for configuring knobs like who's allowed to run a privileged exec, what the GC config is, etc. This would obviously only be served to authorized clients.

    That's no small task, but let me know if you agree something in that direction is where we'd want to go in the long run. Then we can start figuring out the path to it (in a separate issue).

    For the part with mutual tls certs, I would need more details to form a useful opinion. But generally, yes I think the correct approach here is to individually define the design we want for each feature on the list; then individually decide on implementation stopgaps if any; then ship it. It's more design work up front, but it's worth it.

    I'm happy to help any way I can.

  8. sipsma commented on Dec 19, 2022

    @sipsma
    ContributorAuthor

    Splitting this issue out into separate ones for individual items. In addition to the list in the description, made a few new ones for specific points brought up here:

    cc @shykes can continue discussions there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/engine

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions