Skip to content
Merged
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
3 changes: 3 additions & 0 deletions operator/internal/controllers/controlplane/managementapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func webAPIDeployment(cp *simplyblockv1alpha2.ControlPlane) *appsv1.Deployment {
spec := corev1.PodSpec{
ServiceAccountName: serviceAccountName,
Affinity: spreadAcrossHosts(ComponentWebAPI),
SecurityContext: pingSecurityContext(),
Containers: []corev1.Container{{
Name: "webappapi",
Image: localImage(cp),
Expand Down Expand Up @@ -570,6 +571,7 @@ func servicePoolDeployment(
spec := corev1.PodSpec{
ServiceAccountName: serviceAccountName,
Containers: containers(services, managed, localImage(cp), pullPolicyOf(managed)),
SecurityContext: pingSecurityContext(),
Volumes: append([]corev1.Volume{clusterFileVolumeSource()},
tlsVolume(managed)...),
}
Expand Down Expand Up @@ -615,6 +617,7 @@ func adminControlDeployment(cp *simplyblockv1alpha2.ControlPlane) *appsv1.Deploy
spec := corev1.PodSpec{
ServiceAccountName: serviceAccountName,
Affinity: spreadAcrossHosts(ComponentAdminControl),
SecurityContext: pingSecurityContext(),
Containers: []corev1.Container{{
Name: "simplyblock-control",
Image: localImage(cp),
Expand Down
9 changes: 9 additions & 0 deletions operator/internal/controllers/controlplane/podspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ func serviceResources() corev1.ResourceRequirements {
}
}

// pingSecurityContext lets any group ping without sudo or CAP_NET_RAW. Despite
// its name, the sysctl covers ICMPv6 as well. OpenShift's CRI-O and containerd
// 2.0+ set it by default. containerd 1.x and upstream CRI-O do not.
func pingSecurityContext() *corev1.PodSecurityContext {
return &corev1.PodSecurityContext{
Sysctls: []corev1.Sysctl{{Name: "net.ipv4.ping_group_range", Value: "0 2147483647"}},
}
}

// logLevelEnv reads the shared log level, which is what makes changing it one
// ConfigMap edit rather than a rebuild of every workload.
func logLevelEnv() corev1.EnvVar {
Expand Down
24 changes: 24 additions & 0 deletions operator/internal/controllers/controlplane/workloads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,30 @@ func TestNoControlPlaneWorkloadRunsOnTheHostNetwork(t *testing.T) {
}
}

// The control plane's image pings storage nodes as an unprivileged user, which
// the kernel allows only for groups in ping_group_range. Every pod that runs the
// image opens the range to all groups, so no sudo, setuid bit, or CAP_NET_RAW is
// needed.
func TestEveryControlPlaneImageWorkloadMayPingUnprivileged(t *testing.T) {
objects := managementAPIObjects(localControlPlane())

for _, name := range controlPlaneImageWorkloads {
spec := findDeployment(t, objects, name).Spec.Template.Spec
var sysctls []corev1.Sysctl
if spec.SecurityContext != nil {
sysctls = spec.SecurityContext.Sysctls
}
want := corev1.Sysctl{Name: "net.ipv4.ping_group_range", Value: "0 2147483647"}
found := false
for _, s := range sysctls {
found = found || s == want
}
if !found {
t.Errorf("%s: sysctls %v, want %v among them", name, sysctls, want)
}
}
}

// Regression: the tasks-runner-backup-merge container must name the module the
// control-plane image ships, or it crash-loops ("python3: can't open file") and
// pins the whole tasks pod. sbcli main's task-runner rework (#1226) ships it as
Expand Down
Loading