Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/render/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (c *csiComponent) csiContainers() []corev1.Container {
VolumeMounts: []corev1.VolumeMount{
{
Name: "varrun",
MountPath: filepath.Clean("/var/run"),
MountPath: filepath.Clean("/var/run/nodeagent"),
},
{
Name: "socket-dir",
Expand Down Expand Up @@ -216,6 +216,8 @@ func (c *csiComponent) csiContainers() []corev1.Container {
},
},
},
// Privileged is required here for SELinux compat on OpenShift/RHEL: a non-privileged registrar
// (container_t) cannot connect to the UDS created by the privileged calico-csi container (spc_t).
SecurityContext: securitycontext.NewRootContext(true),
VolumeMounts: []corev1.VolumeMount{
{
Expand Down Expand Up @@ -243,7 +245,8 @@ func (c *csiComponent) csiVolumes() []corev1.Volume {
Name: "varrun",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: filepath.Clean("/var/run"),
Path: filepath.Clean("/var/run/nodeagent"),
Type: &hostPathTypeDirOrCreate,
},
},
},
Expand Down
33 changes: 33 additions & 0 deletions pkg/render/csi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,39 @@ var _ = Describe("CSI rendering tests", func() {
Type: corev1.SeccompProfileTypeRuntimeDefault,
}))
Expect(ds.Spec.Template.Spec.ServiceAccountName).To(Equal(render.CSIDaemonSetName))

// The varrun host-path mount must be narrowed to /var/run/nodeagent so
// the calico-csi container cannot reach the container runtime socket
// (e.g. /var/run/containerd/containerd.sock) on the node.
var varrunMount *corev1.VolumeMount
for i := range ds.Spec.Template.Spec.Containers[0].VolumeMounts {
vm := &ds.Spec.Template.Spec.Containers[0].VolumeMounts[i]
if vm.Name == "varrun" {
varrunMount = vm
break
}
}
Expect(varrunMount).NotTo(BeNil())
Expect(varrunMount.MountPath).To(Equal("/var/run/nodeagent"))

var varrunVol *corev1.Volume
for i := range ds.Spec.Template.Spec.Volumes {
v := &ds.Spec.Template.Spec.Volumes[i]
if v.Name == "varrun" {
varrunVol = v
break
}
}
Expect(varrunVol).NotTo(BeNil())
Expect(varrunVol.HostPath).NotTo(BeNil())
Expect(varrunVol.HostPath.Path).To(Equal("/var/run/nodeagent"))
Expect(varrunVol.HostPath.Type).NotTo(BeNil())
Expect(*varrunVol.HostPath.Type).To(Equal(corev1.HostPathDirectoryOrCreate))

// The csi-node-driver-registrar container must not mount varrun at all.
for _, vm := range ds.Spec.Template.Spec.Containers[1].VolumeMounts {
Expect(vm.Name).NotTo(Equal("varrun"))
}
})

It("should render properly when KubeletVolumePluginPath is set to 'None'", func() {
Expand Down
Loading