Skip to content

Commit

Permalink
Merge pull request #10178 from Nordix/tilt-prepare-update-namespace-s…
Browse files Browse the repository at this point in the history
…ecurity-policy/max

🌱 Implement privileged namespace security policy update for tilt-prepare
  • Loading branch information
k8s-ci-robot committed Mar 21, 2024
2 parents 09415e6 + 8be5d93 commit 84aa52a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions hack/tools/internal/tilt-prepare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,9 @@ 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(prefix, binaryName, containerName string, objs []unstructured.Unstructured, liveReloadDeps []string, debugConfig *tiltSettingsDebugConfig, extraArgs tiltSettingsExtraArgs) error {
// Update provider namespaces to have the pod security standard enforce label set to privileged.
// This is required because we remove the SecurityContext from provider deployments below to make tilt work.
updateNamespacePodSecurityStandard(objs)
return updateDeployment(prefix, objs, func(deployment *appsv1.Deployment) {
for j, container := range deployment.Spec.Template.Spec.Containers {
if container.Name != containerName {
Expand Down Expand Up @@ -968,3 +971,19 @@ func getProviderObj(version *string) func(prefix string, objs []unstructured.Uns
return providerObj, nil
}
}

func updateNamespacePodSecurityStandard(objs []unstructured.Unstructured) {
for i, obj := range objs {
if obj.GetKind() != "Namespace" {
continue
}
// Ignore Deployments that are not part of the provider, eg. ASO in CAPZ.
if _, exists := obj.GetLabels()[clusterv1.ProviderNameLabel]; !exists {
continue
}
labels := obj.GetLabels()
labels["pod-security.kubernetes.io/enforce"] = "privileged"
obj.SetLabels(labels)
objs[i] = obj
}
}

0 comments on commit 84aa52a

Please sign in to comment.