moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.21k stars 1.16k forks source link

Proposal: buildctl daemon command #237

Open tonistiigi opened 6 years ago

tonistiigi commented 6 years ago

BuildKit uses daemon model for many benefits like parallel job processing, easier extendability, precise privileged execution control, remote control etc. The downside of it is that it makes the setup harder for new users and people who want to run it occasionally.

The proposal is to hide the presence of daemon unless some more advanced use cases are needed.

Automatic bootstrapping

If the user runs a buildctl command that requests API access and there is no response.

buildctl first finds if there is a buildd binary(or other dependencies for macOS) and gives up if it can't locate it.

Then it tries to check if it has enough privileges to start the daemon. In Linux, this means root with needed capabilities enabled. On macOS, the daemon would be launched in a vm without requiring extra privileges.

The command would look something like:

sudo buildctl daemon start --root=/home/myuser/buildkitstate --allow-user=myuser --entitlements=security.confined

This command will:

An unprivileged user using the buildkit daemon this way should be considered as secure as containers. There shouldn't be any way for the user to issue a command against buildkit daemon that has access to anything outside of the state directory they already have access to.

Extra commands

When the daemon is running user can use some helper command to control it.

buildctl daemon state - shows info about current config(maybe logs as well)

buildctl daemon stop - stop the server. restarted automatically by buildctl when needed. There could also be a --timeout for the daemon start command for automatically shutting down server on inactivity.

buildctl daemon reset - start a fresh daemon with empty state dir

AkihiroSuda commented 6 years ago

Rather than tackling sudo and hyperkit (and hyperv for windows), can we just use Docker for Linux/Mac/Windows?

tonistiigi commented 6 years ago

@AkihiroSuda We could show the Docker example as well(especially if we can detect Docker), but BuildKit shouldn't have a (recommended) dependency on Docker and it doesn't really solve the security problem because having access to Docker API is not secure while BuildKit API should be secure(unless configured with insecure entitlements).

AkihiroSuda commented 6 years ago

BuildKit shouldn't have a (recommended) dependency on Docker

Accurately, it will just have a dependency on github.com/moby/moby/client, not Docker. But we can recommend Docker (for Mac/Windows) for ease of installation.

it doesn't really solve the security problem

If buildctl can call sudo, isn't it already unsecure?

tonistiigi commented 6 years ago

If buildctl can call sudo, isn't it already unsecure?

buildctl can't randomly call sudo. User calls sudo one time to grant access to the user in a limited form. If this command doesn't explicitly allow the build jobs to use insecure entitlements then a regular user can keep using buildkit without having a way to do anything that they couldn't do as a regular user (contrary to Docker API, where if you have access you are effectively root on the host).

kunalkushwaha commented 6 years ago

If no one is working on this, I would like to work on this.

tonistiigi commented 6 years ago

@AkihiroSuda What was your take on this? While I'm all for the rootless when it is enough I think this still has use cases and when we can detect that rootless is supported without downsides we can use the rootless mode instead. I'd also like a better mac experience.

Lets try to break it into multiple smaller chunks with separate PRs. Maybe adding something that would support https://github.com/genuinetools/img/issues/92#issuecomment-393733812 would be a good start(or even that can be in multiple phases)

AkihiroSuda commented 6 years ago

Maybe we can revisit this when we have support for distributed daemons?

tonistiigi commented 6 years ago

@AkihiroSuda The distributed case would always manual setup for defining the cluster so I'm not sure how they are related. Unless you're already thinking about automatically spawning the cluster. Priority wise, I agree that I'd like to see the distributed mode more.

AkihiroSuda commented 6 years ago

@jessfraz any thoughts?

jessfraz commented 6 years ago

no opinions here :)

kunalkushwaha commented 6 years ago

The points suggested in https://github.com/genuinetools/img/issues/92#issuecomment-393733812 are required for if has to be run as single process(daemon-less) like img.

Whereas this proposal seems starting daemon process if its not running (depends on various condition), so cache keys issue may not be problem here.

tonistiigi commented 6 years ago

@kunalkushwaha

This proposal would start the daemon automatically as well if there are enough permissions for that, multiple buildctl instances would share it and if it is automatic it should be shut down as well if unused. That part is similar to img requirements. In addition this defines how the user can grant the set of privileges one time with sudo if the automatic path doesn't work.

Do rootless build is planned to run as daemon-less mode or buildkit daemon will be always there?

I don't think there is such a thing as fully daemonless mode if we want multiple clients. The question is only if we expose to the user that there is a deamon process and do they need to do anything special for it. If we can detect that we can avoid it and the user does not want to customize their experience then there is no need to expose the daemon.

What will be other parts to problems that may require to solve this. capabilities/entitlement

Entitlements are not strictly required for this but this proposal defines how to handle entitlements for the unprivileged user. That being said, I think entitlements feature itself would be a higher priority than this in case you would like to work on that.

kunalkushwaha commented 6 years ago

@tonistiigi thanks for explaining in detail. I would like to work on both.

So more comments I will add on entitlement proposal.

AkihiroSuda commented 5 years ago

daemonless UX: #979