Skip to content

Commit

Permalink
Implement privileged namespace security policy update for tilt-prepare
Browse files Browse the repository at this point in the history
This commit updates the updateNamespaceSecurityPolicy function to set the
pod-security.kubernetes.io/enforce label to 'privileged' for Namespace objects.

Signed-off-by: Max Rantil <max.rantil@est.tech>
  • Loading branch information
Max Rantil committed Feb 20, 2024
1 parent d28a1c9 commit 6d65534
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion hack/tools/internal/tilt-prepare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,11 @@ func writeIfChanged(prefix string, path string, yaml []byte) error {
// This has the affect that the appended ones will take precedence, as those are read last.
// Finally, we modify the deployment to enable prometheus metrics scraping.
func prepareWorkload(name, prefix, binaryName, containerName string, objs []unstructured.Unstructured, ts *tiltSettings) error {
return updateDeployment(prefix, objs, func(deployment *appsv1.Deployment) {
updatedObjs, err := updateNamespaceSecurityPolicy(objs)
if err != nil {
return errors.Wrapf(err, "[%s] failed to update Namespace security policy", prefix)
}
return updateDeployment(prefix, updatedObjs, func(deployment *appsv1.Deployment) {
for j, container := range deployment.Spec.Template.Spec.Containers {
if container.Name != containerName {
continue
Expand Down Expand Up @@ -957,3 +961,16 @@ func getProviderObj(version *string) func(prefix string, objs []unstructured.Uns
return providerObj, nil
}
}

// updateNamespaceSecurityPolicy updates the pod-security.kubernetes.io/enforce label to "privileged" for Namespace objects.
func updateNamespaceSecurityPolicy(objs []unstructured.Unstructured) ([]unstructured.Unstructured, error) {
for i, obj := range objs {
if obj.GetKind() == "Namespace" {
labels := obj.GetLabels()
labels["pod-security.kubernetes.io/enforce"] = "privileged"
obj.SetLabels(labels)
objs[i] = obj
return objs, nil
}
return objs, fmt.Errorf("no Namespace object found to update")
}

Check failure on line 976 in hack/tools/internal/tilt-prepare/main.go

View workflow job for this annotation

GitHub Actions / lint (hack/tools)

expected '}', found 'EOF' (typecheck)

Check failure on line 976 in hack/tools/internal/tilt-prepare/main.go

View workflow job for this annotation

GitHub Actions / lint (hack/tools)

expected '}', found 'EOF' (typecheck)

0 comments on commit 6d65534

Please sign in to comment.