Skip to content

Commit

Permalink
Enable netns mount for privileged pods
Browse files Browse the repository at this point in the history
Signed-off-by: msherif1234 <mmahmoud@redhat.com>
  • Loading branch information
msherif1234 committed Aug 28, 2023
1 parent 3e5454d commit 9c1f980
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions controllers/ebpf/agent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const (
averageMessageSize = 100
bpfTraceMountName = "bpf-kernel-debug"
bpfTraceMountPath = "/sys/kernel/debug"
bpfNetNSMountName = "var-run-netns"
bpfNetNSMountPath = "/var/run/netns"
)

type reconcileAction int
Expand Down Expand Up @@ -185,6 +187,25 @@ func (c *AgentController) desired(ctx context.Context, coll *flowslatest.FlowCol
volumeMounts := c.volumes.GetMounts()
volumes := c.volumes.GetVolumes()

if coll.Spec.Agent.EBPF.Privileged {
volume := corev1.Volume{
Name: bpfNetNSMountName,
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Type: newHostPathType(corev1.HostPathDirectory),
Path: bpfNetNSMountPath,
},
},
}
volumes = append(volumes, volume)
volumeMount := corev1.VolumeMount{
Name: bpfNetNSMountName,
MountPath: bpfNetNSMountPath,
MountPropagation: newMountPropagationMode(corev1.MountPropagationBidirectional),
}
volumeMounts = append(volumeMounts, volumeMount)
}

if helper.IsPktDropEnabled(&coll.Spec) || helper.IsDNSTrackingEnabled(&coll.Spec) {
if !coll.Spec.Agent.EBPF.Privileged {
rlog.Error(fmt.Errorf("invalid configuration"),
Expand Down
1 change: 1 addition & 0 deletions controllers/ebpf/internal/permissions/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (c *Reconciler) reconcileOpenshiftPermissions(
}
if desired.Privileged {
scc.AllowPrivilegedContainer = true
scc.AllowHostDirVolumePlugin = true
} else {
scc.AllowedCapabilities = AllowedCapabilities
}
Expand Down

0 comments on commit 9c1f980

Please sign in to comment.