Skip to content

cri: selinux relabel /dev/shm#4699

Merged
crosbymichael merged 1 commit intocontainerd:masterfrom
dweomer:selinx-relabel-dev-shm
Nov 9, 2020
Merged

cri: selinux relabel /dev/shm#4699
crosbymichael merged 1 commit intocontainerd:masterfrom
dweomer:selinx-relabel-dev-shm

Conversation

@dweomer
Copy link
Copy Markdown
Contributor

@dweomer dweomer commented Nov 6, 2020

Address an issue originally seen in the k3s 1.3 and 1.4 forks of containerd/cri, k3s-io/k3s#2240

Even with updated container-selinux policy, container-local /dev/shm
will get mounted with container_runtime_tmpfs_t because it is a tmpfs
created by the runtime and not the container (thus, container_runtime_t
transition rules apply). The relabel mitigates such, allowing envoy
proxy to work correctly (and other programs that wish to write to their
/dev/shm) under selinux.

Tested locally with:

  • SELINUX=Enforcing vagrant up --provision-with=shell,selinux,test-integration
  • SELINUX=Enforcing CRITEST_ARGS=--ginkgo.skip='HostIpc is true' vagrant up --provision-with=shell,selinux,test-cri
  • SELINUX=Permissive CRITEST_ARGS=--ginkgo.focus='HostIpc is true' vagrant up --provision-with=shell,selinux,test-cri

Signed-off-by: Jacob Blain Christen [email protected]

Address an issue originally seen in the k3s 1.3 and 1.4 forks of containerd/cri, k3s-io/k3s#2240

Even with updated container-selinux policy, container-local /dev/shm
will get mounted with container_runtime_tmpfs_t because it is a tmpfs
created by the runtime and not the container (thus, container_runtime_t
transition rules apply). The relabel mitigates such, allowing envoy
proxy to work correctly (and other programs that wish to write to their
/dev/shm) under selinux.

Tested locally with:
- SELINUX=Enforcing vagrant up --provision-with=shell,selinux,test-integration
- SELINUX=Enforcing CRITEST_ARGS=--ginkgo.skip='HostIpc is true' vagrant up --provision-with=shell,selinux,test-cri
- SELINUX=Permissive CRITEST_ARGS=--ginkgo.focus='HostIpc is true' vagrant up --provision-with=shell,selinux,test-cri

Signed-off-by: Jacob Blain Christen <[email protected]>
@k8s-ci-robot
Copy link
Copy Markdown

Hi @dweomer. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Nov 6, 2020

Build succeeded.

dweomer added a commit to dweomer/cri that referenced this pull request Nov 6, 2020
Address an issue originally seen in the k3s 1.3 and 1.4 forks of
containerd/cri, k3s-io/k3s#2240.

This is a backport of containerd/containerd#4699

Even with updated container-selinux policy, container-local /dev/shm will get
mounted with container_runtime_tmpfs_t because it is a tmpfs created by the
runtime and not the container (thus, container_runtime_t transition rules apply).
The relabel mitigates such, allowing envoy proxy to work correctly (and other
programs that wish to write to their /dev/shm) under selinux.
@crosbymichael
Copy link
Copy Markdown
Member

LGTM

@crosbymichael
Copy link
Copy Markdown
Member

/ok-to-test

@crosbymichael
Copy link
Copy Markdown
Member

Should we also reliable resolvconf and the other shared files?

Copy link
Copy Markdown
Member

@mxpv mxpv left a comment

Choose a reason for hiding this comment

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

LGTM

@dweomer
Copy link
Copy Markdown
Contributor Author

dweomer commented Nov 9, 2020

Should we also reliable resolvconf and the other shared files?

@crosbymichael good question. I have no reports of folks needing to write to /etc/resolv.conf and /etc/hosts in-container in k3s or rke2. Is there a common-ish use-case for such that I am not aware of? If not, I am content to leave it alone until someone needs it.

@crosbymichael
Copy link
Copy Markdown
Member

ok, i think its fine as these are not in /run

@crosbymichael crosbymichael merged commit 293b08d into containerd:master Nov 9, 2020
dweomer added a commit to dweomer/cri that referenced this pull request Nov 9, 2020
Address an issue originally seen in the k3s 1.3 and 1.4 forks of
containerd/cri, k3s-io/k3s#2240.

This is a backport of containerd/containerd#4699

Even with updated container-selinux policy, container-local /dev/shm will get
mounted with container_runtime_tmpfs_t because it is a tmpfs created by the
runtime and not the container (thus, container_runtime_t transition rules apply).
The relabel mitigates such, allowing envoy proxy to work correctly (and other
programs that wish to write to their /dev/shm) under selinux.
dweomer added a commit to dweomer/cri that referenced this pull request Nov 9, 2020
Address an issue originally seen in the k3s 1.3 and 1.4 forks of
containerd/cri, k3s-io/k3s#2240.

This is a backport of containerd/containerd#4699

Even with updated container-selinux policy, container-local /dev/shm will get
mounted with container_runtime_tmpfs_t because it is a tmpfs created by the
runtime and not the container (thus, container_runtime_t transition rules apply).
The relabel mitigates such, allowing envoy proxy to work correctly (and other
programs that wish to write to their /dev/shm) under selinux.

Signed-off-by: Jacob Blain Christen <[email protected]>
@dweomer
Copy link
Copy Markdown
Contributor Author

dweomer commented Nov 9, 2020

@crosbymichael it looks like the containerd/cri unit tests caught something that I missed: https://github.com/containerd/cri/pull/1605/files#diff-17a83af23eb8f578286e12d2b7537efb119bbb6a046235b59fc10b3f0ac04fa5

I am looking into why the refactored, containerd/cri -> containerd/containerd/pkg/cri, unit tests didnt catch it and will be submitting a followup fix (if necessary).

dweomer added a commit to dweomer/containerd that referenced this pull request Nov 11, 2020
This is a followup to containerd#4699 that addresses an oversight that could cause
the CRI to relabel the host /dev/shm, which should be a no-op in most
cases. Additionally, fixes unit tests to make correct assertions for
/dev/shm relabeling.

Discovered while applying the changes for containerd#4699 to containerd/cri 1.4:
containerd/cri#1605

Signed-off-by: Jacob Blain Christen <[email protected]>
dweomer added a commit to dweomer/cri that referenced this pull request Nov 11, 2020
Address an issue originally seen in the k3s 1.3 and 1.4 forks of
containerd/cri, k3s-io/k3s#2240.

This is a backport of containerd/containerd#4699

Even with updated container-selinux policy, container-local /dev/shm will get
mounted with container_runtime_tmpfs_t because it is a tmpfs created by the
runtime and not the container (thus, container_runtime_t transition rules apply).
The relabel mitigates such, allowing envoy proxy to work correctly (and other
programs that wish to write to their /dev/shm) under selinux.

Signed-off-by: Jacob Blain Christen <[email protected]>
@dweomer dweomer deleted the selinx-relabel-dev-shm branch November 17, 2020 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants