Skip to content

✨ Support privileged Exec #3874

Closed

Description

@wxdao

What are you trying to do?

The goal is to support setting a Exec privileged so that processes like docker-in-docker can be run.

Why is this important to you?

Some of our projects are Kubernetes controllers. To test these tools like kind are needed to start up cluster components through containers, which is impossible without running the process in privileged mode.

It's also useful to like developing iptables, cgroups and some kernel stuff.

It is relatable even after the Services #3037 feature is added. Without privileged mode you can't run a docker-in-docker as service anyway.

How are you currently working around this?

Can't find a workaround.

Activity

  1. shykes commented on Nov 16, 2022

    @shykes
    Contributor

    Thanks for filing this @wxdao ! @aluzzardi @sipsma what are the security implications of adding this to the API? I'm guessing with a remote engine it may complicate things, since it essentially grants clients root access on the runner machine? Not sure how to solve that without pulling in authorization, which is a whole new layer of complexity...

  2. sipsma commented on Nov 16, 2022

    @sipsma
    Contributor

    Buildkitd only allows privileged execs if they have been specifically toggled on when starting buildkitd (some scary sounding flag like --allow-insecure-entitlement iirc), so we could re-use that sort of authorization model. However that just means we need to solve the problem of making the remote engine provisioning more configurable, which may be easy but definitely has a lot of implications we need to think through.

  3. shykes commented on Nov 16, 2022

    @shykes
    Contributor

    Buildkitd only allows privileged execs if they have been specifically toggled on when starting buildkitd (some scary sounding flag like --allow-insecure-entitlement iirc), so we could re-use that sort of authorization model. However that just means we need to solve the problem of making the remote engine provisioning more configurable, which may be easy but definitely has a lot of implications we need to think through.

    Yeah, if we copied that model as-is, I believe we would inherit buildkit's problem which is that, basically, your runner is not safely multi-tenant out of the box. Right?

  4. sipsma commented on Nov 16, 2022

    @sipsma
    Contributor

    Yeah, if we copied that model as-is, I believe we would inherit buildkit's problem which is that, basically, your runner is not safely multi-tenant out of the box. Right?

    Yes (though buildkit isn't really safely multitenant out of the box even with this disabled, but that's another thread, enabling privileged exec certainly makes the issue much much worse)

  5. shykes commented on Nov 16, 2022

    @shykes
    Contributor

    Yeah, if we copied that model as-is, I believe we would inherit buildkit's problem which is that, basically, your runner is not safely multi-tenant out of the box. Right?

    Yes (though buildkit isn't really safely multitenant out of the box even with this disabled, but that's another thread, enabling privileged exec certainly makes the issue much much worse)

    My first thought is: perhaps we could create the concept of 1) privileged operations in the API, 2) a privileged session bit, without which privileged operations are denied, 3) a simple session authorization hook which allows administrators to configure which sessions get privileged. If we have that, and assuming buildkit API is fully hidden and wrapped, then we could run our buildkit with -allow-insecure-entitlement always set, with the (as you say imperfect, but better than nothing) multi-tenancy profile of buildkit preserved.

  6. wxdao commented on Nov 16, 2022

    @wxdao
    Author

    TBH I’ve never considered a shared builkitd being secure with or without the flag. For in-house usage workloads are controlled and nobody cares security. For multi tenant saas platforms security is solved by running builkitd inside isolated VM.

  7. wxdao commented on Nov 16, 2022

    @wxdao
    Author

    My point is it’s not wise to aim for multi tenant safety too much on buildkitd and dagger level. It’s already insecure by nature as long as builkitd need -privileged flag to run. If someone cares about multi tenant safety they should go for isolating buildkitd itself.

  8. shykes commented on Nov 16, 2022

    @shykes
    Contributor

    TBH I’ve never considered a shared builkitd being secure with or without the flag. For in-house usage workloads are controlled and nobody cares security. For multi tenant saas platforms security is solved by running builkitd inside isolated VM.

    Right, like @sipsma said you wouldn't want to expose a shared buildkitd on the internet, with or without the privileged flag.

    But still, security layers matter and I would rather not lose that particular layer completely. I would also rather not make it a global static configuration flag, because most organizations don't know for sure in advance which client will need to run privileged containers, so they will either 1) enable the privileged flag by default, just in case, or 2) disable it by default, creating a tight coupling between infrastructure and application layers: "my app pipeline needs privileged access, let me open an issue with SRE to change how they provision dagger engines, or perhaps create a separate privileged farm just for me". Neither is a good experience.

  9. wxdao commented on Nov 16, 2022

    @wxdao
    Author

    @shykes How about in the short term 1) add privileged option on exec operation 2) enabled privileged exec support by default for embedded dagger engine? I guess the authorization hook design only makes sense for shared dagger engine anyway.

  10. shykes commented on Nov 16, 2022

    @shykes
    Contributor

    @shykes How about in the short term 1) add privileged option on exec operation 2) enabled privileged exec support by default for embedded dagger engine? I guess the authorization hook design only makes sense for shared dagger engine anyway.

    That makes sense to me, but I defer to @aluzzardi and @sipsma who will have a more informed opinion on the engineering tradeoffs. High-level: we want to find a way to unblock you in the short term, without causing more problems down the road. We'll figure it out :)

    Thanks for bearing with us!

  11. wxdao commented on Nov 17, 2022

    @wxdao
    Author

    Thanks. Waiting for the good news then.

  12. sipsma commented on Mar 3, 2023

    @sipsma
    Contributor

    We have a pressing need for this and it has been prototyped successfully for the use case of running dockerd in dagger in this draft PR: #4677

    IMO the best long term solution is as described in this issue (operator api + authn/authz support), but the authn/authz part specifically seems like it may be too large a project to be feasible in the time frames we'd like (though I'd be delighted to be wrong about that).

    Thinking about simpler shorter term solutions:

    1. Enable by default, opt-out via custom provisioned engine

    The simplest option is probably to:

    1. Enable any use of privileged execs in our default engine
    2. If users want to disable privileged execs, require they use a custom provisioned engine where they change either the entrypoint or the default config file

    One argument in favor of this is that the default engine provisioning path already relies on calling docker run --privileged and also supports proxying the host docker socket to any dagger container, so in that sense the default provisioning path already supports privileged execs, just not directly in dagger.

    This also probably results in the least amount of ecosystem fracturing. If you want to run your own engine you can disable the feature but that's true of many/most features (networking being a big one).

    2. Disable by default, opt-in via custom provisioned engine

    Just the inverse of option 1.

    Given the aforementioned existing way of already running privileged containers, I'm not sure this is actually more secure even though it superficially "sounds" more secure on the surface.

    For example, if we did this I'm not sure how we could 100% prevent the equivalent of this:

    c.Container().From("docker:cli").
      WithMountedUnixSock("/var/run/docker.sock", "/var/run/docker.sock").
      WithExec("docker exec -it <dagger-engine-container> sh -c 'echo security.insecure >> /etc/dagger/engine.toml'")

    There's certainly tricks that could make it less straightforward, but I think the only way to conclusively prevent it would be via a custom provisioned engine anyways.


    To my own surprise, I think I'm actually in favor of option 1 right now, but will think some more.

  13. vito commented on Mar 3, 2023

    @vito
    Contributor

    @sipsma For what it's worth, I ended up making the same decision for Bass -- with a similar amount of hesitation. (I also vote option 1.)

    The cost of fragmentation felt too high, and it seemed like the most common mode of operation would be to trust the workloads you're running anyway. Untrusted workloads can be accounted for by disabling privileged exec, as you pointed out, and you'd probably want to change a bunch of other knobs in that scenario too (e.g. resource limits, disabling Docker socket forwarding, etc.).

  14. shykes commented on Mar 5, 2023

    @shykes
    Contributor

    Option 1 makes sense for me too.

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

    area/engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions