Skip to content

Support privileged executions. - #4677

Merged
sipsma merged 1 commit into
dagger:mainfrom
sipsma:priv
Mar 7, 2023
Merged

sipsma merged 1 commit into
dagger:mainfrom
sipsma:priv

Conversation

@sipsma

@sipsma sipsma commented Mar 1, 2023 •

Copy link
Copy Markdown
Contributor

This adds a new bool flag called InsecureRootCapabilities to WithExec options that enables privileged execution of containers. See discussion here for reasoning behind allowing this to be set in the engine (though the field itself defaults to false). The operator manual is also updated with instructions on disabling it if needed.

Went with the name InsecureRootCapabilities because it conveys that it's inherently insecure (security onus is on the user) and technically accurate in that it results in root capabilities being inherited by the process (whereas "privileged" is somewhat more ambiguous). Feel free to bikeshed away though.

In the longer run it would be great to give users fine grain settings for which capabilities should be inherited, but that can be added later in a backwards compatible way if needed.

Resolves #3874

@sipsma
sipsma force-pushed the priv branch 2 times, most recently from edd5dfc to f8d23d3 Compare March 1, 2023 23:15
@sipsma sipsma changed the title DO NOT MERGE: proof-of-concept for privileged exec and docker-in-dagger Support privileged executions. Mar 6, 2023
@sipsma
sipsma requested review from aluzzardi and vito March 6, 2023 20:51
@sipsma
sipsma marked this pull request as ready for review March 6, 2023 20:51

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one concern about the engine config, otherwise LGTM!

Comment thread core/integration/container_test.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw you could also set tcp://docker:2375 instead of calling Endpoint, but both are valid, just stylistic trade-offs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi @vikram-dagger for examples later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread internal/mage/engine.go Outdated
Comment on lines 81 to 89

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously I switched to having a blank default engine.toml and applying our own defaults at runtime, to make this config additive:

func setDaggerDefaults(cfg *config.Config) error {

The advantage of doing it this way is that when someone needs to add e.g. registry mirror config to engine.toml they don't need to keep updating it to include whatever other defaults we add.

insecure-entitlements is a little tricky though because it's hard to differentiate between the Buildkit default empty value and the user intentionally setting it to empty to prevent our default. 🤔

One option is to add our own flag to the engine like --disable-insecure-root-capabilities that prevents us from adding these defaults.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that makes sense, what do you think about this:

  1. Update the setting of the worker label to be automatic in main based on whether the entitlement is present or not. This remove the need for that whole section of config.
  2. Move the default shim binary setting to also be in our main, next to the other default engine config settings you added
  3. Leave in a a default toml config, but now it consists just of
debug = true
insecure-entitlements = ["security.insecure"]

I updated with the above, let me know what you think. My concern with --disable-insecure-root-capabilities as a flag is that it gets confusing to explain in combination with the existing buildkit flag and in general I think it's simpler to only have to explain to users where they need to change a toml config file rather than start explaining mixes of toml configs, command line flags, entrypoint settings, etc.

Users who want a custom toml config will need to include those two lines, but that seems like not too much to ask or subject to lots of change in the same way the more complicated networking/worker configs are. So overall felt like a good balance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, yeah that seems like a good balance since now engine.toml only contains optional things and an empty one is valid again. 👍

Comment thread internal/engine/client.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 - neat idea; I had a similar problem in #4711 where the schema needed to know the DNS domain. I decided to just remove it but this makes sense too, and might be useful information to make available to an operator if we decide to keep it after all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I have a local branch w/ a half-written operator api implementation, which this would fit in nicely with. Unfortunately I keep finding barely good enough workarounds such as this one for it to make sense to go finish that implementation, but someday! In the meantime, worker labels are (terrible) read-only kv api I guess.

@jpadams jpadams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Support privileged Exec

3 participants