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

Conversation

@miaoyq
Copy link
Member

@miaoyq miaoyq commented Aug 23, 2017

Support selinux optios/label

Signed-off-by: Yanqiang Miao [email protected]

/cc @Random-Liu

@Random-Liu
Copy link
Member

@miaoyq Thanks! We do need this, but haven't got time to work on it. Will review it.

@Random-Liu
Copy link
Member

Also assign @mikebrow because he's recently working on security related stuff. :)

@Random-Liu
Copy link
Member

@miaoyq Do you have a selinux environment? Have you tested this? :)

@miaoyq
Copy link
Member Author

miaoyq commented Aug 25, 2017

@Random-Liu Not yet:pensive:, I will add this part

@mikebrow
Copy link
Member

I'm rooting for ya!

@crosbymichael
Copy link
Member

I think the approach is good.

Labels should be generated on the CRI side because you will have to make sure the mount labels match up for various containers in a pod.

I'll add a couple of helper Opts in containerd for setting the labels but I think this is the right approach by generating them here.

"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"

containerstore "github.com/kubernetes-incubator/cri-containerd/pkg/store/container"
"syscall"
Copy link
Member

Choose a reason for hiding this comment

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

Use golang.org/x/sys/unix and move this to the first group, syscall is deprecated.


if mount.GetSelinuxRelabel() {
if err := label.Relabel(src, mountLabel, true); err != nil && err != syscall.ENOTSUP {
return fmt.Errorf("relabel failed %s: %v", src, err)
Copy link
Member

Choose a reason for hiding this comment

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

also include mountlabel in the error message.


securityContext := config.GetLinux().GetSecurityContext()

processLabel, mountLabel, err := initSelinuxOpts(securityContext.GetSelinuxOptions())
Copy link
Member

Choose a reason for hiding this comment

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

nit: Create a local variable for securityContext.GetSelinuxOptions(), so that we could make the next line shorter. :p

Copy link
Member

Choose a reason for hiding this comment

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

Please add unit test for this. Basically, just set selinux options, and check whether ProcessSelinuxLabel and LinuxMountLabel are set correctly.

We don't need to add SelinuxRelabel for any mount, so that Relabel won't be actually run in the unit test.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Random-Liu I have tried to add unit test for this, but the result of test depends on whether
selinux have been enabled, see https://github.com/opencontainers/selinux/blob/4a2974bf1ee960774ffd517717f1f45325af0206/go-selinux/label/label_selinux.go#L28.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Random-Liu I have add the unit test with build tag selinux.

securityContext.GetCapabilities(), err)
}

// TODO(random-liu): [P1] Set selinux options.
Copy link
Member

Choose a reason for hiding this comment

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

I think we should also set this for privileged container, let's keep it consistent with docker. https://github.com/moby/moby/blob/master/daemon/oci_linux.go#L831-L834

}

func initSelinuxOpts(selinuxOpt *runtime.SELinuxOption) (string, string, error) {
var labelOpts []string
Copy link
Member

Choose a reason for hiding this comment

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

nit: Move this down.

Copy link
Member

Choose a reason for hiding this comment

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


// TODO(random-liu): [P1] Apply SeLinux options.
securityContext := config.GetLinux().GetSecurityContext()

Copy link
Member

Choose a reason for hiding this comment

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

nit: unnecessary empty line.

if err != nil {
return nil, fmt.Errorf("failed to init selinux options %+v: %v", securityContext.GetSelinuxOptions(), err)
}

Copy link
Member

Choose a reason for hiding this comment

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

nit: ditto.

@Random-Liu
Copy link
Member

Random-Liu commented Aug 30, 2017

@miaoyq Please rebase the PR and address comments.

We don't have selinux test and test environment for CRI validation test.
We do have cluster e2e test for it, but we are not running them in any of our own environment https://github.com/kubernetes/kubernetes/blob/master/test/e2e/node/security_context.go#L98-L108.

If possible, could you try to verify this in a selinux environment? If it's hard for you, please file an issue, and we could get back to verify this later.

@Random-Liu Random-Liu mentioned this pull request Aug 30, 2017
42 tasks
@miaoyq
Copy link
Member Author

miaoyq commented Aug 30, 2017

@Random-Liu Thanks for review!
Sorry for my late reply, I was busy with other things.
Now I'm free. I'll rebase the PR and address comments.
It's hard for you to verify this actually, but I have built a selinux environment, if it is not urgent, I would like to complete this verification with your guidance. :-)

@Random-Liu
Copy link
Member

@miaoyq Thanks! Feel free to comment, file issue or ping me if you encountered any problem on that distro.

@miaoyq
Copy link
Member Author

miaoyq commented Aug 31, 2017

@Random-Liu OK, I will, thanks!

Support selinux optios/label

Signed-off-by: Yanqiang Miao <[email protected]>
@miaoyq
Copy link
Member Author

miaoyq commented Aug 31, 2017

@Random-Liu Rebased and addressed comments, PTAL

@Random-Liu
Copy link
Member

LGTM. @miaoyq Please help validate this after merged. Thanks! :)

@Random-Liu Random-Liu merged commit 9c49624 into containerd:master Aug 31, 2017
@miaoyq miaoyq deleted the apply-selinux-opt branch September 1, 2017 00:19
lanchongyizu pushed a commit to lanchongyizu/cri-containerd that referenced this pull request Sep 3, 2017
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.

5 participants