Skip to content

Commit 1ec7ede

Browse files
committed
[release/1.4 backport] selinux: relabel /dev/shm
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]>
1 parent 61363b3 commit 1ec7ede

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

pkg/server/container_create_unix.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ func (c *criService) containerMounts(sandboxID string, config *runtime.Container
101101
sandboxDevShm = devShm
102102
}
103103
mounts = append(mounts, &runtime.Mount{
104-
ContainerPath: devShm,
105-
HostPath: sandboxDevShm,
106-
Readonly: false,
104+
ContainerPath: devShm,
105+
HostPath: sandboxDevShm,
106+
Readonly: false,
107+
SelinuxRelabel: sandboxDevShm != devShm,
107108
})
108109
}
109110
return mounts

pkg/server/container_create_unix_test.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,10 @@ func TestContainerMounts(t *testing.T) {
457457
Readonly: true,
458458
},
459459
{
460-
ContainerPath: "/dev/shm",
461-
HostPath: filepath.Join(testStateDir, sandboxesDir, testSandboxID, "shm"),
462-
Readonly: false,
460+
ContainerPath: "/dev/shm",
461+
HostPath: filepath.Join(testStateDir, sandboxesDir, testSandboxID, "shm"),
462+
Readonly: false,
463+
SelinuxRelabel: true,
463464
},
464465
},
465466
},
@@ -482,9 +483,10 @@ func TestContainerMounts(t *testing.T) {
482483
Readonly: false,
483484
},
484485
{
485-
ContainerPath: "/dev/shm",
486-
HostPath: filepath.Join(testStateDir, sandboxesDir, testSandboxID, "shm"),
487-
Readonly: false,
486+
ContainerPath: "/dev/shm",
487+
HostPath: filepath.Join(testStateDir, sandboxesDir, testSandboxID, "shm"),
488+
Readonly: false,
489+
SelinuxRelabel: true,
488490
},
489491
},
490492
},
@@ -555,9 +557,10 @@ func TestContainerMounts(t *testing.T) {
555557
Readonly: false,
556558
},
557559
{
558-
ContainerPath: "/dev/shm",
559-
HostPath: filepath.Join(testStateDir, sandboxesDir, testSandboxID, "shm"),
560-
Readonly: false,
560+
ContainerPath: "/dev/shm",
561+
HostPath: filepath.Join(testStateDir, sandboxesDir, testSandboxID, "shm"),
562+
Readonly: false,
563+
SelinuxRelabel: true,
561564
},
562565
},
563566
},

0 commit comments

Comments
 (0)