-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ensure pod security label on namespace #774
fix: ensure pod security label on namespace #774
Conversation
3e24e11
to
0b17b20
Compare
/hold We need to revisit this. Adding a restrictive pod security standard to an existing namespace (during an upgrade) will result in failure because the existing pods in the namespace won't be compliant with the restricted policy. The required policy configurations were added in argoproj-labs/argocd-operator#1288 and argoproj-labs/argocd-operator#1493, but these changes only work for fresh installs. Existing pods are not configured with the new policy settings unless the corresponding deployments are manually deleted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenShift automatically handles the securityContext
if it is missing. After running some tests, my previous concerns have been addressed, and there shouldn’t be any issues during the upgrade. I also have PR #1533 to handle existing deployments, but it’s not a blocker for this PR.
/remove-hold
func ensurePodSecurityLabels(namespace *corev1.Namespace) (bool, *corev1.Namespace) { | ||
for key := range namespace.Labels { | ||
if strings.HasPrefix(key, "pod-security") { | ||
return false, namespace | ||
} | ||
} | ||
|
||
namespace.Labels["pod-security.kubernetes.io/enforce"] = "restricted" | ||
namespace.Labels["pod-security.kubernetes.io/enforce-version"] = "v1.29" | ||
namespace.Labels["pod-security.kubernetes.io/audit"] = "restricted" | ||
namespace.Labels["pod-security.kubernetes.io/audit-version"] = "latest" | ||
namespace.Labels["pod-security.kubernetes.io/warn"] = "restricted" | ||
namespace.Labels["pod-security.kubernetes.io/warn-version"] = "latest" | ||
|
||
return true, namespace | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do a strict check here? The current logic won't detect changes if the label value is modified. Something like...
func ensurePodSecurityLabels(namespace *corev1.Namespace) (bool, *corev1.Namespace) { | |
for key := range namespace.Labels { | |
if strings.HasPrefix(key, "pod-security") { | |
return false, namespace | |
} | |
} | |
namespace.Labels["pod-security.kubernetes.io/enforce"] = "restricted" | |
namespace.Labels["pod-security.kubernetes.io/enforce-version"] = "v1.29" | |
namespace.Labels["pod-security.kubernetes.io/audit"] = "restricted" | |
namespace.Labels["pod-security.kubernetes.io/audit-version"] = "latest" | |
namespace.Labels["pod-security.kubernetes.io/warn"] = "restricted" | |
namespace.Labels["pod-security.kubernetes.io/warn-version"] = "latest" | |
return true, namespace | |
} | |
func ensurePodSecurityLabels(namespace *corev1.Namespace) (bool, *corev1.Namespace) { | |
pssLabels := map[string]string{ | |
"pod-security.kubernetes.io/enforce": "restricted", | |
"pod-security.kubernetes.io/enforce-version": "v1.29", | |
"pod-security.kubernetes.io/audit": "restricted", | |
"pod-security.kubernetes.io/audit-version": "latest", | |
"pod-security.kubernetes.io/warn": "restricted", | |
"pod-security.kubernetes.io/warn-version": "latest", | |
} | |
changed := false | |
for pssKey, pssVal := range pssLabels { | |
if nsVal, exists := namespace.Labels[pssKey]; !exists || nsVal != pssVal { | |
namespace.Labels[pssKey] = pssVal | |
changed = true | |
} | |
} | |
return changed, namespace | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
/remove-hold |
Signed-off-by: saumeya <[email protected]>
Signed-off-by: saumeya <[email protected]>
Signed-off-by: saumeya <[email protected]>
0b17b20
to
ff7bcbe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Thanks
@@ -369,6 +377,15 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli | |||
return reconcile.Result{}, err | |||
} | |||
} | |||
|
|||
needUpdate, updateNameSpace := ensurePodSecurityLabels(argocdNS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a NIT, I would change the word needUpdate
to needsUpdate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, LGTM except for the NIT.
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: iam-veeramalla The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
b50e9e1
into
redhat-developer:master
/cherry-pick v1.14 |
/cherry-pick v1.13 |
@saumeya: only redhat-developer org members may request cherry picks. If you are already part of the org, make sure to change your membership to public. Otherwise you can still do the cherry-pick manually. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
@saumeya: only redhat-developer org members may request cherry picks. If you are already part of the org, make sure to change your membership to public. Otherwise you can still do the cherry-pick manually. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/cherry-pick v1.14 |
/cherry-pick v1.13 |
@saumeya: #774 failed to apply on top of branch "v1.14":
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
@saumeya: new pull request created: #777 In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What type of PR is this?
What does this PR do / why we need it:
Have you updated the necessary documentation?
Which issue(s) this PR fixes:
Fixes #?
Test acceptance criteria:
How to test changes / Special notes to the reviewer: