Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SElinux experiences for who wants to know #107

Closed
coeki opened this issue Jan 10, 2017 · 85 comments
Closed

SElinux experiences for who wants to know #107

coeki opened this issue Jan 10, 2017 · 85 comments

Comments

@coeki
Copy link

coeki commented Jan 10, 2017

Hi all,

So been battling with my special setup all weekend, but I have to give up and let other folks look at it.
So on windows, vagrant and ansible, I can share my stuff if you like.

Facts:
latest version from repo in the guide.
using fedora 24 as images in virtualbox with vagrant

So following the guide, I got it working, with setenforce permissive, kubeadm runs with calico. In my case I have a small machine for running ansible, setting up a master and a node.

First I tried with setenforce enforcing, and got stuck at the famous, "waiting for the control plane to become ready" , and then used new terminal to look at it. It seems that actually etcd is clashing with selinux due to diff types. In the static manifest, in the code in kubernetes/cmd/kubeadm/app/master/manifest.go, I can see that it's run with type spc_t, while everything run from docker, etcd itself is run under svirt_sandbox_file_t, so yes it clashes. I think it has to to do with the volumes attached or the process actually trying to write to the volume on the master host.

I see similar problems with the pod networking scripts.

So anyone any ideas?

Just trying to get this working with SElinux from the get go ;)

Thanks,

@mikedanese
Copy link
Member

@dgoodwin

@dgoodwin
Copy link

@coeki I don't think we technically document Fedora installations, I assume you used the Centos7 repos? Which docker did you use, the one in Fedora or one from Docker Inc? Could you include details on the denials?

spc_t should be correct per http://danwalsh.livejournal.com/2016/10/03/

@jasonbrooks do you have any thoughts on this, potential fallout from kubernetes/kubernetes#37327

I will try to find some time to see if I can reproduce this week.

@dgoodwin
Copy link

Reproduced:

type=AVC msg=audit(1484057408.459:2715): avc:  denied  { entrypoint } for  pid=16812 comm="exe" path="/usr/local/bin/etcd" dev="dm-6" ino=4194436 scontext=system_u:system_r:spc_t:s0:c133,c303 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c133,c303 tclass=file permissive=0

Does not happen on CentOS 7 as far as I know.

@coeki
Copy link
Author

coeki commented Jan 10, 2017

Hi,

Yes, that are the type of errors I'm seeing. For clarification, yes I used the Centos repos and I used the docker from Fedoras repo.

I will do a quick check if this happens with Centos7 later today.

Thanks,

@coeki
Copy link
Author

coeki commented Jan 10, 2017

Hi,

Actually happens on centos7 too:

type=AVC msg=audit(1484065309.021:634): avc: denied { entrypoint } for pid=12204 comm="exe" path="/usr/local/bin/etcd" dev="dm-9" ino=4194436 scontext=system_u:system_r:spc_t:s0:c390,c679 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c390,c679 tclass=file
type=AVC msg=audit(1484065310.113:637): avc: denied { entrypoint } for pid=12263 comm="exe" path="/usr/local/bin/etcd" dev="dm-9" ino=4194436 scontext=system_u:system_r:spc_t:s0:c220,c274 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c220,c274 tclass=file
type=AVC msg=audit(1484065323.851:661): avc: denied { entrypoint } for pid=12550 comm="exe" path="/usr/local/bin/etcd" dev="dm-9" ino=4194436 scontext=system_u:system_r:spc_t:s0:c425,c863 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c425,c863 tclass=file

Regarding Dan Walsh's post, I also saw this http://danwalsh.livejournal.com/75011.html, so I think stuff changed.

Further things I'm seeing:

[root@localhost vagrant]# ls -Z /var/lib/ |grep container
drwx-----x. root root system_u:object_r:container_var_lib_t:s0 docker
drwxr-xr-x. root root system_u:object_r:container_var_lib_t:s0 etcd
[root@localhost vagrant]# ls -Z /var/lib/ |grep kubelet
drwxr-x---. root root system_u:object_r:var_lib_t:s0 kubelet

[root@localhost vagrant]# ls -Z /var/lib/kubelet/pods/3a26566bb004c61cd05382212e3f978f/containers/etcd/
-rw-r--r--. root root system_u:object_r:svirt_sandbox_file_t:s0:c425,c863 00cb813c
-rw-r--r--. root root system_u:object_r:svirt_sandbox_file_t:s0:c220,c274 066b8a86
-rw-r--r--. root root system_u:object_r:svirt_sandbox_file_t:s0:c390,c679 0c8e84af
-rw-r--r--. root root system_u:object_r:svirt_sandbox_file_t:s0:c12,c477 342bd480
-rw-r--r--. root root system_u:object_r:svirt_sandbox_file_t:s0:c215,c768 995f6946
-rw-r--r--. root root system_u:object_r:svirt_sandbox_file_t:s0:c23,c405 e184aa90
-rw-r--r--. root root system_u:object_r:svirt_sandbox_file_t:s0:c65,c469 eb05320c

The same on Centos and Fedora. Not sure what the way to go is, but I think we don't need to specify SElinux types anymore in any manifests. At least for kubeadm, the pod networking is another story.

Thoughts?

Thanks,

@jasonbrooks
Copy link

I'm poking at this now.

@dgoodwin
Copy link

Thanks @jasonbrooks.

FWIW CentOS7 was clean for me with:

(root@centos1 ~) $ kubeadm reset
[preflight] Running pre-flight checks
[reset] Stopping the kubelet service
[reset] Unmounting mounted directories in "/var/lib/kubelet"
[reset] Removing kubernetes-managed containers
[reset] No etcd manifest found in "/etc/kubernetes/manifests/etcd.json", assuming external etcd.
[reset] Deleting contents of stateful directories: [/var/lib/kubelet /etc/cni/net.d]
[reset] Deleting contents of config directories: [/etc/kubernetes/manifests /etc/kubernetes/pki]
[reset] Deleting files: [/etc/kubernetes/admin.conf /etc/kubernetes/kubelet.conf]
(root@centos1 ~) $ getenforce
Enforcing
(root@centos1 ~) $ rpm -qa | grep kube
kubelet-1.5.1-0.x86_64
kubeadm-1.6.0-0.alpha.0.2074.a092d8e0f95f52.x86_64
kubectl-1.5.1-0.x86_64
kubernetes-cni-0.3.0.1-0.07a8a2.x86_64
(root@centos1 ~) $ ls -lZ /var/lib | grep docker
drwx-----x. root    root    system_u:object_r:docker_var_lib_t:s0 docker/
drwxr-xr-x. root    root    system_u:object_r:docker_var_lib_t:s0 etcd/
drwxr-xr-x. root    root    system_u:object_r:docker_var_lib_t:s0 kubeadm-etcd/
(root@centos1 ~) $ rpm -qa | grep selinux
selinux-policy-targeted-3.13.1-60.el7_2.3.noarch
libselinux-2.2.2-6.el7.x86_64
docker-selinux-1.10.3-46.el7.centos.10.x86_64
libselinux-utils-2.2.2-6.el7.x86_64
libselinux-python-2.2.2-6.el7.x86_64
selinux-policy-3.13.1-60.el7_2.3.noarch

kubeadm init was working and this was the env I was doing my testing with to verify things were ok.

I then thought to check if my vagrant machines were running latest policy and that picked up a bunch of selinux updates, after which kubeadm init now fails with the denial provided by @coeki. So something has gone wrong with the latest policy. After my update:

(root@centos1 ~) $ rpm -qa | grep selinux
libselinux-2.5-6.el7.x86_64
docker-selinux-1.10.3-46.el7.centos.14.x86_64
selinux-policy-targeted-3.13.1-102.el7_3.7.noarch
libselinux-python-2.5-6.el7.x86_64
selinux-policy-3.13.1-102.el7_3.7.noarch
libselinux-utils-2.5-6.el7.x86_64
container-selinux-1.10.3-59.el7.centos.x86_64

@jasonbrooks
Copy link

Look at this. CentOS 7 w/ docker-selinux:

$ sesearch -T -s docker_t | grep spc_t
   type_transition docker_t docker_share_t : process spc_t; 
   type_transition docker_t unlabeled_t : process spc_t; 
   type_transition docker_t docker_var_lib_t : process spc_t;

And after installing container-selinux:

$ sesearch -T -s docker_t | grep spc_t
   type_transition container_runtime_t container_var_lib_t : process spc_t; 
   type_transition container_runtime_t container_share_t : process spc_t;

@jasonbrooks
Copy link

Yep, I added exclude=container-selinux to my fedora-updates repo and the kubeadm init completes as expected.

@jberkus
Copy link

jberkus commented Jan 11, 2017

ping @rhatdan

@luxas
Copy link
Member

luxas commented Jan 11, 2017

So we should document exclude=container-selinux as a solution to having SELinux on (setenforce 1) and running kubeadm?

@jasonbrooks
Copy link

jasonbrooks commented Jan 11, 2017 via email

@coeki
Copy link
Author

coeki commented Jan 11, 2017

After reading mentioned post from Dan Walsh ( http://danwalsh.livejournal.com/75011.html) a little better, either there's en error in typealiasing the docker_t types to the new generic name for container types container_t, or it didn't get pulled yet.

Another train of thought. I'm not sure how docker containers are launched by kubernetes, but a fix could also be to launch the containers with the new container types.

@coeki
Copy link
Author

coeki commented Jan 11, 2017

Ingnore the last remark, it's the OS contianer runtime of course, so yes @jasonbrooks remark is right, we need a selinux fix.

@rhatdan
Copy link

rhatdan commented Jan 11, 2017

@lsm5 can we get an updated version of container-selinux for Fedora 24. Seems to be a little out of date there.

@dgoodwin
Copy link

dgoodwin commented Jan 11, 2017

@rhatdan @lsm5 it's bad in latest CentOS 7 as well

@rhatdan
Copy link

rhatdan commented Jan 11, 2017

What version of docker, docker-selinux, container-selinux does Centos 7 have?

@dgoodwin
Copy link

From above:

(root@centos1 ~) $ rpm -qa | grep selinux
libselinux-2.5-6.el7.x86_64
docker-selinux-1.10.3-46.el7.centos.14.x86_64
selinux-policy-targeted-3.13.1-102.el7_3.7.noarch
libselinux-python-2.5-6.el7.x86_64
selinux-policy-3.13.1-102.el7_3.7.noarch
libselinux-utils-2.5-6.el7.x86_64
container-selinux-1.10.3-59.el7.centos.x86_64

In my comment above you can also see the previous versions I had where everything was working, and then it starts failing after a yum update to these versions.

@lsm5
Copy link

lsm5 commented Jan 11, 2017

@dgoodwin can you try the latest container-selinux for CentOS 7? You can get it using this repo:

[virt7-docker-common-candidate]
name=virt7-docker-common-candidate
baseurl=https://cbs.centos.org/repos/virt7-docker-common-candidate/x86_64/os/
enabled=1
gpgcheck=0

See: https://wiki.centos.org/Cloud/Docker

@lsm5
Copy link

lsm5 commented Jan 11, 2017

@dgoodwin
Copy link

Still failing @lsm5

(root@centos1 ~) $ rpm -qa | grep selinux                                                                                                     
libselinux-2.5-6.el7.x86_64
selinux-policy-targeted-3.13.1-102.el7_3.7.noarch
libselinux-python-2.5-6.el7.x86_64
selinux-policy-3.13.1-102.el7_3.7.noarch
container-selinux-2.2-3.el7.noarch
libselinux-utils-2.5-6.el7.x86_64

type=AVC msg=audit(1484146410.625:156): avc:  denied  { entrypoint } for  pid=2831 comm="exe" path="/usr/local/bin/etcd" dev="dm-8" ino=8388868 scontext=system_u:system_r:spc_t:s0:c590,c748 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c590,c748 tclass=file
type=AVC msg=audit(1484146437.147:168): avc:  denied  { entrypoint } for  pid=3102 comm="exe" path="/usr/local/bin/etcd" dev="dm-9" ino=8388868 scontext=system_u:system_r:spc_t:s0:c73,c888 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c73,c888 tclass=file
type=AVC msg=audit(1484146454.690:174): avc:  denied  { entrypoint } for  pid=3269 comm="exe" path="/usr/local/bin/etcd" dev="dm-9" ino=8388868 scontext=system_u:system_r:spc_t:s0:c184,c206 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c184,c206 tclass=file
type=AVC msg=audit(1484146479.755:179): avc:  denied  { entrypoint } for  pid=3375 comm="exe" path="/usr/local/bin/etcd" dev="dm-9" ino=8388868 scontext=system_u:system_r:spc_t:s0:c245,c784 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c245,c784 tclass=file
type=AVC msg=audit(1484146529.400:190): avc:  denied  { entrypoint } for  pid=3637 comm="exe" path="/usr/local/bin/etcd" dev="dm-9" ino=8388868 scontext=system_u:system_r:spc_t:s0:c893,c1013 tcontext=system_u:object_r:svirt_sandbox_file_t:s0:c893,c1013 tclass=file

@rhatdan
Copy link

rhatdan commented Jan 11, 2017

Could you make sure container-selinux successfully installed?

dnf reinstall container-selinux

@jasonbrooks
Copy link

jasonbrooks commented Jan 11, 2017 via email

@rhatdan
Copy link

rhatdan commented Jan 11, 2017

I think this block is silently failing.

optional_policy(`
virt_stub_svirt_sandbox_file()
virt_transition_svirt_sandbox(spc_t, system_r)
virt_sandbox_entrypoint(spc_t)
virt_sandbox_domtrans(container_runtime_t, spc_t)
')

@dgoodwin
Copy link

Still failing after reinstall.

@rhatdan
Copy link

rhatdan commented Jan 11, 2017

I am setting up a CENTOS machine to check what is going wrong.

@luxas
Copy link
Member

luxas commented Jan 13, 2017

Thanks for the help everyone, it would be cool if we would be able to have setenforce 1 working with kubeadm in the next release ;)

@coeki
Copy link
Author

coeki commented Jan 21, 2017

Hi,

I tried with fedora 25 cloud base, the same result as in, it not installing, but different messages:

time->Sat Jan 21 13:55:37 2017
type=AVC msg=audit(1485006937.554:8062): avc: denied { create } for pid=676 comm="etcd" name="data" scontext=system_u:system_r:container_t:s0:c358,c612 tcontext=system_u:object_r:container_var_lib_t:s0 tclass=dir permissive=0

time->Sat Jan 21 13:57:08 2017
type=AVC msg=audit(1485007028.572:8075): avc: denied { create } for pid=1181 comm="etcd" name="data" scontext=system_u:system_r:container_t:s0:c358,c612 tcontext=system_u:object_r:container_var_lib_t:s0 tclass=dir permissive=0

time->Sat Jan 21 13:59:53 2017
type=AVC msg=audit(1485007193.515:8088): avc: denied { create } for pid=1780 comm="etcd" name="data" scontext=system_u:system_r:container_t:s0:c358,c612 tcontext=system_u:object_r:container_var_lib_t:s0 tclass=dir permissive=0

[root@master-01 vagrant]# rpm -qa |grep selinux
libselinux-python3-2.5-13.fc25.x86_64
selinux-policy-3.13.1-225.6.fc25.noarch
libselinux-2.5-13.fc25.x86_64
libselinux-utils-2.5-13.fc25.x86_64
rpm-plugin-selinux-4.13.0-6.fc25.x86_64
selinux-policy-targeted-3.13.1-225.6.fc25.noarch
libselinux-python-2.5-13.fc25.x86_64
container-selinux-2.2-2.fc25.noarch

@coeki
Copy link
Author

coeki commented Jan 21, 2017

Oops, sorry for the markup in the last post, have no clue how that happened ;)

@jberkus
Copy link

jberkus commented Jan 22, 2017

@coeki it's because of the # at the beginning of those lines. I suggest indenting the lines with four spaces, which lets GH know that it's code.

@luxas
Copy link
Member

luxas commented Jan 30, 2017

Yes, many thanks for this investigation! I'm a noob at selinux (haven't ever used it, I'm more of a debian guy), so this effort is worth its weight in gold.

I guess we're hoping for a resolution to this in k8s v1.6, right?

Also, do network providers like weave, flannel, etc. add these selinux rules as well in order for their hostpath mounts to work properly as well? If that's the case, we have to inform them in time for the next release.

@coeki
Copy link
Author

coeki commented Jan 30, 2017

Thanks all for having a look at this. So to recap, tell me if I read it wrong:

1 Issue with the format of the label ":" vs"=" worked on here: #kubernetes/kubernetes#40179
2 Issue with labels getting attached twice, also handled in above PR
3 Parsing of labels as reported by @runcom, handled here #opencontainers/runc#1303
4 Wider discussion on whether security ops should work on container level inside a pod or just pod wise.

@luxas I was first trying to fix kubeadm and then have a look at what exactly goes wrong with the network providers like weave, flannel, canal, calico and romana, probably the same isssues, but we'll have to pinpoint first I think, so we can tell them what to fix.

@runcom
Copy link

runcom commented Jan 30, 2017

3 Parsing of labels as reported by @runcom, handled here #opencontainers/runc#1303

this is just for docker > 1.12.6 - docker in Fedora/RHEL has 1.12.6 which correctly applies label

k8s-github-robot pushed a commit to kubernetes/kubernetes that referenced this issue Jan 31, 2017
Automatic merge from submit-queue (batch tested with PRs 38443, 40145, 40701, 40682)

Move kubeadm etcd SELinux options from container to pod.

**What this PR does / why we need it**:

Works around a bug that surfaces in Docker 1.12+ related to the pause
container's namespace and selinux labels being transferred to the etcd
container when it runs.

At present it appears that applying selinux options to a container may
be broken, or perhaps shouldn't be supported at all. Moving these to the
pod causes all containers (including pause) to run with the correct
labels.



**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

Related to and partial fix for kubernetes/kubeadm#107

This is one of several selinux related fixes in flight for upcoming releases, and newer versions of Docker. To successfully run kubeadm with selinux enforcing right now would like require a recent container-selinux build as uncovered in kubernetes/kubeadm#107, a bugfix for the format labels in #40179, and finally this fix.

**Release note**:

```release-note
Fixed an SELinux issue in kubeadm on Docker 1.12+ by moving etcd SELinux options from container to pod.
```
@pweil-
Copy link

pweil- commented Feb 1, 2017

I believe today the pod level security context (if defined) is applied to all containers. If a container level security context is defined kube attempts to overwrite the pod level context

This is correct. It is done in the security context provider by the DetermineEffectiveSecurityContext method.

Basically container level selinux definitions have worked in the past but were broken by 1.12.5 and 1.13

Yeah, we can tighten up docker to reject invalid SELinux config if there are shared namespaces.

@pmorie @mrunalp @eparis - help me understand the correct direction for the SC provider in this scenario. It sounds like since we always share the IPC namespace with the pause container that:

  1. if there is any selinux label on the a container it needs applied to the pause container in order to share the IPC namespace
  2. per-container settings don't really make sense if there is more than one container in the pod with SELinux settings and those settings do not match?

if item 2 is true then I think that is a strong argument to only have pod level settings.

@eparis
Copy link

eparis commented Feb 1, 2017

I'd argue that docker needs to start the pause container with the pod level security context (if defined). It needs to start the actual containers with the container security context (if defined) fallback to the pod level context (if defined) and then fall back to 'shared with pause'. (if undefined)

I do not understand why the shared IPC namespace should be relevant to this discussion. If the user defines a combination of contexts that selinux won't allow to work, then things shouldn't work. But docker should never 'overwrite' anything the user asked for.

@pweil-
Copy link

pweil- commented Feb 1, 2017

I'd argue that docker needs to start the pause container with the pod level security context (if defined). It needs to start the actual containers with the container security context (if defined) fallback to the pod level context (if defined) and then fall back to 'shared with pause'. (if undefined)

Then I think that there isn't anything to do on the provider side. It should already be setting the pause container settings to the pod level SC if defined and actual containers get the merge of pod + container overrides which means it should share settings with pause if things are defined on the pod level and not the container level.

If the user defines a combination of contexts that selinux won't allow to work, then things shouldn't work. But docker should never 'overwrite' anything the user asked for.

Agree. Thanks!

@rhatdan
Copy link

rhatdan commented Feb 1, 2017

Yes @eparis is correct. I have to get a patch to docker to handle the labeling correctly. We need to allow user flexibility (IE The ability to break his system if he so chooses.)

The default case should be that all container processes sharing the same IPC namespace have share the same SELinux label, but if a user asks to override the label, it should be allowed.

@coeki
Copy link
Author

coeki commented Feb 1, 2017

The problem in this case, although I can't put my finger on it, seems a little bit more complex.
The security options are not overwritten but added twice.

You can actually see it a little when this fix is not applied:

1 Issue with the format of the label ":" vs"=" worked on here: #kubernetes/kubernetes#40179

docker inspect the pause container:

"SecurityOpt": [
            "seccomp=unconfined",
            "label:type:spc_t"
        ],

Docker inspect the etcd container:

  "SecurityOpt": [
            "seccomp=unconfined",
            "label:type:spc_t",
            "label=user:system_u",
            "label=role:system_r",
            "label=type:spc_t",
            "label=level:s0:c23,c719"

The label with the format "label:" is coming from the manifest with which we started the deployment of the etcd pod. At least I think so.

Kubelet or docker seems to add the others, which kinda make sense as they are for the image files placed in /var/lib/docker/containers and /var/lib/kubelet/pods

From the discussion in #kubernetes/kubernetes#40179 we know docker is not preventing adding more security opts then actually should be allowed.
But where or how this add is taking place I can't tell.

@mdshuai
Copy link

mdshuai commented Feb 3, 2017

@eparis @rhatdan Could you help check this issue too? Why seLinuxOptions in pod level and container level has different result ? thanks kubernetes/kubernetes#37809

@rhatdan
Copy link

rhatdan commented Feb 3, 2017

I have a pull request to help fix this issue in for docker
moby/moby#30652

We have already described the issue.

In standard docker if you add a container with one label and then add another container which you want to join the same IPC Namespace, docker will take the label of the first container and assign it to the second container. This way SELinux will not block access to IPC created by the first container that needs to be used by the second container.

The SELinux type/mcs label at the Pod Level sets the label for the pause container. The SELinux Type/MCS Label at the container label sets it for each container that is joining the pause container.
If Kubernetes does not set a label for the pause container it will get labeled something like container_t:s0:c1,c2. Then kubernetes tries to add a container with a label like spc_t:s0. In older versions of docker, docker would see that the security-opt field was set and not call the code to merge the SELinux labels. But this was causing problems with people setting seccomp, basically we would not get the expected behaviour of two containers sharing the same SELinux label, if any non label field was set in the security-opt. A patch was merged upstream to take a way the security-opt check. This introduced a bug where if a user did specify an SELinux label security-opt of a container that was joining another container to ignore the security opt.

Bottom Line:

Old docker, if pause/POD container came in with no label it would start with container_t:s0:c1,c2. If new container was sent in to join the pause container, with spc_t:s0. Docker would launch the second container with spc_t:s0, and k8s was happy. After fix the second container ended up with the more restrictive container_t:s0:c1,c2 and k8s was unhappy. Correct fix to the problem on the k8s side is to set the pause/POD label to spc_t:s0 and the added container will match as spc_t:s0.

With my patch above we will allow users to specify alternate selinux labels for each container added, but this should only be done by people who understand how SELinux confinement works. IE You might want to set up a multi container pod where one container has more/less rights then the container it is joining.

The docker patch would have fixed the k8s problem, also but it does not eliminate the fact that the pause container probably should be running with the same SELinux label as the containers joining it.

@mdshuai
Copy link

mdshuai commented Feb 4, 2017

@rhatdan thanks so much

@coeki
Copy link
Author

coeki commented Feb 5, 2017

So.........how to test? @dgoodwin @jasonbrooks @rhatdan @jessfraz?

I'm sorry not well versed in building stuff, but willing to do so....I have some clue, but any help welcome.
kubernetes/kubernetes#40179 moved.....so how do I include that?

Thanks

@coeki
Copy link
Author

coeki commented Feb 5, 2017

Ok figured it out over the weekend, but it still not working.

@coeki
Copy link
Author

coeki commented Feb 9, 2017

Ok, build kubeadm and kubelet (this part I forgot, hence my latest comment) myself from master branch with kubernetes/kubernetes#40903 merged and it works with selinux enforcing, even with weave running, although weave is not running correctly. That's a weave issue to deal with later as well as the other providers I still have to test.
But at least no selinux denials with selinux enforcing.

Regarding the double entries referenced in kubernetes/kubernetes#37807:

  "SecurityOpt": [
            "seccomp=unconfined",
            "label=type:spc_t",
            "label=user:system_u",
            "label=role:system_r",
            "label=type:spc_t",
            "label=level:s0:c210,c552"

I think that stems from some validation when DetermineEffectiveSecurityContext is run, as @pweil- mentioned, and just added rather then replaced as docker security option. Since docker runs with all options passed to but only uses the last security options passed, this seems to work. Not sure if that is expected behavior for docker, but that's a diff matter. @rhatdan might want to take another look at that, regarding moby/moby#30652

Not sure if we should close the issue, till we get the rpms from official repo's, test again and so forth, test the pod networking first, and fix it, update docs etc, before closing. So let me know.

Thanks all for fixing this :)

@rhatdan
Copy link

rhatdan commented Feb 10, 2017

This looks correct, although with the patch I have for upstream docker you would end up with only one "label=type:spc_t" field.

@coeki
Copy link
Author

coeki commented Feb 10, 2017

@rhatdan question, because I build docker with your patch, well maybe I didn't do it right, but I think it did. And I still see this.

this behavior didn't change:
docker run -ti --security-opt label=type:container_t --security-opt label=type:spc_t fedora sleep 5

 "MountLabel": "system_u:object_r:container_file_t:s0:c118,c497",
    "ProcessLabel": "system_u:system_r:spc_t:s0:c118,c497",

snip

"SecurityOpt": [
"label=type:container_t",
"label=type:spc_t"

it runs with your patch, none the wiser.

Docker accepts that, is the patch breaking that? Is there a sane use case that docker should be able to do that?

From this issue, if docker changes that, seeing we (kubernetes pod runtime ) end up we double labels, which I think come from the validation in kubelet, if you break the fact docker accepts more options then it should...well it breaks again.

Look if sane, we should be able to run a pod with diff security options for containers within a pod, and I think that was the intention, which should be possible, but an alignment is needed. Docker and kubernetes can not have diff expectations about this.

I might be wrong, adding @eparis @dgoodwin @jasonbrooks @luxas @pweil- @pmorie

@rhatdan
Copy link

rhatdan commented Feb 12, 2017

My change was not to prevent that although we probably should. My change was to block on container joining the IPC Namespace or pid namespace of another

# docker run -d --name test fedora sleep 10
# docker run -d security-opt label=type:spc_t --ipc container:test fedora cat /proc/self/attr/current

The second container should be running as spc_t. Where the old code would have had it running as container_t. This basically would mimic two containers running in the same pod with different SELinux labels.

@coeki
Copy link
Author

coeki commented Feb 13, 2017

Thanks @rhatdan for clarying.

@coeki
Copy link
Author

coeki commented Feb 24, 2017

Closing this one, as the rbac enabled changes for pod networking are tracked #143

Not sure about the double labels, it seems interaction between kubernetes/kubelet and docker as mentioned above.

Anyway filed this for docker #moby/moby#31328

Thanks all,

@jayunit100
Copy link
Member

Im running with Enforcing and having no issues with flannel, FYI. Im wondering if specific SELinux configurations break it and others dont? Not an SELinux expert btw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests