-
Notifications
You must be signed in to change notification settings - Fork 347
Conversation
|
@miaoyq Thanks! We do need this, but haven't got time to work on it. Will review it. |
|
Also assign @mikebrow because he's recently working on security related stuff. :) |
|
@miaoyq Do you have a selinux environment? Have you tested this? :) |
|
@Random-Liu Not yet:pensive:, I will add this part |
|
I'm rooting for ya! |
|
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. |
pkg/server/container_create.go
Outdated
| "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime" | ||
|
|
||
| containerstore "github.com/kubernetes-incubator/cri-containerd/pkg/store/container" | ||
| "syscall" |
There was a problem hiding this comment.
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.
pkg/server/container_create.go
Outdated
|
|
||
| if mount.GetSelinuxRelabel() { | ||
| if err := label.Relabel(src, mountLabel, true); err != nil && err != syscall.ENOTSUP { | ||
| return fmt.Errorf("relabel failed %s: %v", src, err) |
There was a problem hiding this comment.
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.
pkg/server/container_create.go
Outdated
|
|
||
| securityContext := config.GetLinux().GetSecurityContext() | ||
|
|
||
| processLabel, mountLabel, err := initSelinuxOpts(securityContext.GetSelinuxOptions()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/server/container_create.go
Outdated
| securityContext.GetCapabilities(), err) | ||
| } | ||
|
|
||
| // TODO(random-liu): [P1] Set selinux options. |
There was a problem hiding this comment.
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
pkg/server/helpers.go
Outdated
| } | ||
|
|
||
| func initSelinuxOpts(selinuxOpt *runtime.SELinuxOption) (string, string, error) { | ||
| var labelOpts []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Move this down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this seems cleaner https://github.com/opencontainers/selinux/blob/63bd19516561f1973f86c9f777b263ee1e0db140/go-selinux/selinux.go#L572
label.InitLabels(label.DupSecOpt("user:role:type:level")).
pkg/server/sandbox_run.go
Outdated
|
|
||
| // TODO(random-liu): [P1] Apply SeLinux options. | ||
| securityContext := config.GetLinux().GetSecurityContext() | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: unnecessary empty line.
pkg/server/sandbox_run.go
Outdated
| if err != nil { | ||
| return nil, fmt.Errorf("failed to init selinux options %+v: %v", securityContext.GetSelinuxOptions(), err) | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: ditto.
|
@miaoyq Please rebase the PR and address comments. We don't have selinux test and test environment for CRI validation test. 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 Thanks for review! |
|
@miaoyq Thanks! Feel free to comment, file issue or ping me if you encountered any problem on that distro. |
|
@Random-Liu OK, I will, thanks! |
Support selinux optios/label Signed-off-by: Yanqiang Miao <[email protected]>
45f72b0 to
0c3304e
Compare
|
@Random-Liu Rebased and addressed comments, PTAL |
|
LGTM. @miaoyq Please help validate this after merged. Thanks! :) |
Support selinux options/label
Support selinux optios/label
Signed-off-by: Yanqiang Miao [email protected]
/cc @Random-Liu