Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Conversation

@AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Nov 9, 2018

Add following config for supporting "rootless" mode

  • DisableCgroup: disable cgroup
  • DisableApparmor: disable Apparmor
  • RestrictOOMScoreAdj: restrict the lower bound of OOMScoreAdj

Signed-off-by: Akihiro Suda suda.akihiro@lab.ntt.co.jp


A quick way to test this PR is to use Usernetes v20181109.0 ( https://github.com/rootless-containers/usernetes )

$ ./run.sh default-containerd
$ ./kubectl.sh run -it --rm --image alpine foo

cc @giuseppe for consistency with CRI-O implementation (https://github.com/kubernetes-sigs/cri-o/blob/2accad9fab352c445bb4c414d9d3c8cdf351c524/server/rootless.go could be simplified as in this PR with the latest runc IIUC)

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

See comments, I missed containerd/containerd#2766 going in, sry. If we want this back ported to earlier releases we'll want to keep these changes you made and walk them back as deprecated.. then do a follow up commit putting them in as runc options vs cri root options.

@Random-Liu
Copy link
Member

Random-Liu commented Nov 12, 2018

In OCI spec, both AppArmor and OOMScoreAdj is a Process level configuration. I think we can match that, so I'm fine with a daemon level NoAppArmor and RestrictOOMScoreAdj option.

As for NoCgroup, although it is Linux specific, but it is still different from the existing runtime options, e.g. "NoPivot":

  • Options like "NoPivot" or "SystemdCgroup" are actually runc specific (they are runc flags), and they are actually changing runc's behavior.
  • However, NoCgroup (NoAppArmor and RestrictOOMScoreAdj as well) is changing the cri plugin's behavior - it changes how cri should config the OCI spec. Given so, I think it is a cri daemon level configuration. As for the fact that it is Linux specific, we need to have different groups of daemon level configurations for Windows and Linux in the future anyway.

@AkihiroSuda Are these options only useful for rootless? If that is the case, can we add a Rootless section in the config? So that it is clear to the user that this is for rootless.

@mikebrow
Copy link
Member

mikebrow commented Nov 12, 2018

@AkihiroSuda Are these options only useful for rootless? If that is the case, can we add a Rootless section in the config? So that it is clear to the user that this is for rootless.

I was sort of thinking these are runtime config options required for filtering oci spec generation to make sure it will run rootless. But I don't see why we would want to filter/force all pods on the host to be rootless. Is that the goal here? Push rootless up the stack or to support running the shims/runc/containerd as rootless? Switching to rootless at the host/containerd/cri level seems like a pretty big switch.

It might be better to return error if an apparmor profile is specified and is disabled, than to filter the profile option.

How will these changes effect kata support?

@Random-Liu
Copy link
Member

Random-Liu commented Nov 13, 2018

Switching to rootless at the host/containerd/cri level seems like a pretty big switch.

If I understand correctly, "Rootless" means run containerd as a non-root user. If that is the case, it is a daemon level thing to me.

It is "rootless" containerd, not running a non-root container.

@AkihiroSuda
Copy link
Member Author

In this context I mean running everything (runc, containerd, kubelet) as a non-root user. I can explain the details in person and show you demo during KubeCon Shanghai

@mikebrow
Copy link
Member

ok. Even kubelet, interesting.

@mikebrow
Copy link
Member

mikebrow commented Nov 13, 2018

Maybe what's needed here is a single check to see if we are running as root or not then use that as flag to filter out any attempt to do something that is known to fail when not running as root. For example, if !runningAsRoot && apparmorProfile != "" return err.."apparmor is not supported when running as non-root..."

@AkihiroSuda
Copy link
Member Author

It might be complicating, if we want to support automatic detection, maybe we should change the variable type from bool to string, and reserve "auto" for the future implementation (Either way, probably we should allow setting NoCgroups=false even in rootless mode, because cgroups can be used when the fs is chowned)

@AkihiroSuda
Copy link
Member Author

@Random-Liu @mikebrow any thought?

@mikebrow
Copy link
Member

mikebrow commented Nov 23, 2018

Suggest: using a string for a rootless option, "auto" should be default. False would make sure we are running as root otherwise throw error on init, true would make sure we are not running as root otherwise error on init. Agree to implementing NoCgroup, NoAppArmor, and RestrictOOMScoreAdj as daemon level options. See @Random-Liu's comment above regarding:

move implementation of these options to the place the option was originally configured, e.g. OOMScoreAdj is configured in setOCILinuxResource

Thoughts?

@AkihiroSuda
Copy link
Member Author

thanks, updated

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

/LGTM

g.SetProcessNoNewPrivileges(securityContext.GetNoNewPrivs())

// TODO(random-liu): [P1] Set selinux options (privileged or not).

Copy link
Member

Choose a reason for hiding this comment

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

Add unit test cases for this logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can we cover this in an integrated test (in a follow-up PR)?

Copy link
Member

Choose a reason for hiding this comment

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

It is current hard to write an integration test with different containerd configurations.

I think a unit test would be easier. You can check existing unit tests, it should be simple to add a similar one. :)

@k8s-ci-robot k8s-ci-robot removed the lgtm label Dec 26, 2018
@AkihiroSuda AkihiroSuda changed the title support NoCgroup,NoApparmor, RestrictOOMScoreAdj support DisableCgroup, DisableApparmor, RestrictOOMScoreAdj Dec 26, 2018
@AkihiroSuda
Copy link
Member Author

updated

g.SetProcessNoNewPrivileges(securityContext.GetNoNewPrivs())

// TODO(random-liu): [P1] Set selinux options (privileged or not).

Copy link
Member

Choose a reason for hiding this comment

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

It is current hard to write an integration test with different containerd configurations.

I think a unit test would be easier. You can check existing unit tests, it should be simple to add a similar one. :)

@Random-Liu
Copy link
Member

LGTM other than the comments.

@AkihiroSuda
Copy link
Member Author

thanks, updated

Add following config for supporting "rootless" mode

* DisableCgroup: disable cgroup
* DisableApparmor: disable Apparmor
* RestrictOOMScoreAdj: restrict the lower bound of OOMScoreAdj

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Copy link
Member

@Random-Liu Random-Liu left a comment

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants