mirror of https://github.com/grafana/loki
operator: Set seccomp profile to runtime default for all variants (#9457)
parent
1b3f97fde4
commit
7b706eea8c
@ -0,0 +1,18 @@ |
||||
apiVersion: apps/v1 |
||||
kind: Deployment |
||||
metadata: |
||||
name: controller-manager |
||||
spec: |
||||
template: |
||||
spec: |
||||
containers: |
||||
- name: manager |
||||
securityContext: |
||||
allowPrivilegeEscalation: false |
||||
capabilities: |
||||
drop: |
||||
- ALL |
||||
securityContext: |
||||
runAsNonRoot: true |
||||
seccompProfile: |
||||
type: RuntimeDefault |
||||
@ -0,0 +1,43 @@ |
||||
package manifests |
||||
|
||||
import ( |
||||
"github.com/ViaQ/logerr/v2/kverrors" |
||||
|
||||
corev1 "k8s.io/api/core/v1" |
||||
"k8s.io/utils/pointer" |
||||
|
||||
"github.com/imdario/mergo" |
||||
) |
||||
|
||||
func configurePodSpecForRestrictedStandard(podSpec *corev1.PodSpec) error { |
||||
podSecurityContext := corev1.PodSpec{ |
||||
SecurityContext: &corev1.PodSecurityContext{ |
||||
RunAsNonRoot: pointer.Bool(true), |
||||
SeccompProfile: &corev1.SeccompProfile{ |
||||
Type: corev1.SeccompProfileTypeRuntimeDefault, |
||||
}, |
||||
}, |
||||
} |
||||
|
||||
containerSecurityContext := corev1.Container{ |
||||
SecurityContext: &corev1.SecurityContext{ |
||||
AllowPrivilegeEscalation: pointer.Bool(false), |
||||
Capabilities: &corev1.Capabilities{ |
||||
Drop: []corev1.Capability{"ALL"}, |
||||
}, |
||||
}, |
||||
} |
||||
|
||||
for i, container := range podSpec.Containers { |
||||
if err := mergo.Merge(&container, containerSecurityContext, mergo.WithOverride); err != nil { |
||||
return err |
||||
} |
||||
podSpec.Containers[i] = container |
||||
} |
||||
|
||||
if err := mergo.Merge(podSpec, podSecurityContext, mergo.WithOverride); err != nil { |
||||
return kverrors.Wrap(err, "failed to merge pod security context") |
||||
} |
||||
|
||||
return nil |
||||
} |
||||
Loading…
Reference in new issue