Skip to content
Draft
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
10 changes: 3 additions & 7 deletions pkg/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ func NewNamespace(ns string) *corev1.Namespace {
ObjectMeta: metav1.ObjectMeta{
Name: ns,
Labels: CommonLabels.Merge(k8s.StringMap{
// NOTE: Fixes the following error On Openshift 4.14
// Warning FailedCreate daemonset-controller
// Error creating: pods "kepler-exporter-ds-d6f28" is forbidden:
// violates PodSecurity "restricted:latest":
// privileged (container "kepler-exporter" must not set securityContext.privileged=true),
// allowPrivilegeEscalation != false (container "kepler-exporter" must set
// securityContext.allowPrivilegeEscalation=false),
// NOTE: Kepler requires hostPID and hostPath volumes for /proc and /sys access
// Only the "privileged" PSA level allows these host-level features
// However, the Kepler container itself does NOT run as privileged (privileged: false)
"pod-security.kubernetes.io/enforce": "privileged",
}),
//TODO: ensure in-cluster monitoring ignores this ns
Expand Down
27 changes: 21 additions & 6 deletions pkg/components/power-monitor/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,17 @@ func NewPowerMonitorSCC(d components.Detail, pmi *v1alpha1.PowerMonitorInternal)
Labels: labels(pmi),
},

AllowPrivilegedContainer: true,
AllowHostDirVolumePlugin: true,
AllowHostPID: true,
ReadOnlyRootFilesystem: true,
// NOTE: Kepler requires CAP_SYS_PTRACE to read /proc
// Hence drop ALL capabilities, and set Privileged to false
// and ReadOnlyRootFilesystem to true
AllowPrivilegedContainer: false,
AllowPrivilegeEscalation: ptr.To(false),
DefaultAllowPrivilegeEscalation: ptr.To(false),
AllowHostDirVolumePlugin: true,
AllowHostPID: true,
ReadOnlyRootFilesystem: true,
RequiredDropCapabilities: []corev1.Capability{"ALL"},
AllowedCapabilities: []corev1.Capability{"SYS_PTRACE"},
Comment on lines +353 to +354
Copy link
Collaborator

Choose a reason for hiding this comment

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

perfect


FSGroup: secv1.FSGroupStrategyOptions{
Type: secv1.FSGroupStrategyRunAsAny,
Expand Down Expand Up @@ -707,8 +714,16 @@ func newKeplerContainer(pmi *v1alpha1.PowerMonitorInternal) corev1.Container {
volumeMounts := buildVolumeMounts(deployment)

return corev1.Container{
Name: pmi.DaemonsetName(),
SecurityContext: &corev1.SecurityContext{Privileged: ptr.To(true)},
Name: pmi.DaemonsetName(),
SecurityContext: &corev1.SecurityContext{
Privileged: ptr.To(false),
AllowPrivilegeEscalation: ptr.To(false),
ReadOnlyRootFilesystem: ptr.To(true),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
Add: []corev1.Capability{"SYS_PTRACE"},
},
},
Image: deployment.Image,
ImagePullPolicy: corev1.PullAlways,
Env: []corev1.EnvVar{{
Expand Down
2 changes: 1 addition & 1 deletion pkg/components/power-monitor/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestSCCAllows(t *testing.T) {
}{
{
sccAllows: k8s.SCCAllows{
AllowPrivilegedContainer: true,
AllowPrivilegedContainer: false,
AllowHostDirVolumePlugin: true,
AllowHostIPC: false,
AllowHostNetwork: false,
Expand Down
Loading