Skip to content
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

Merged

Conversation

saumeya
Copy link
Member

@saumeya saumeya commented Aug 28, 2024

What type of PR is this?

Uncomment only one /kind line, and delete the rest.
For example, > /kind bug would simply become: /kind bug

/kind bug
/kind cleanup
/kind failing-test
/kind enhancement
/kind documentation
/kind code-refactoring

What does this PR do / why we need it:

Have you updated the necessary documentation?

  • Documentation update is required by this PR.
  • Documentation has been updated.

Which issue(s) this PR fixes:

Fixes #?

Test acceptance criteria:

  • Unit Test
  • E2E Test

How to test changes / Special notes to the reviewer:

@saumeya saumeya requested a review from svghadi August 28, 2024 09:59
@openshift-ci openshift-ci bot requested a review from chetan-rns August 28, 2024 09:59
@saumeya saumeya force-pushed the ensure-pod-security-label branch from 3e24e11 to 0b17b20 Compare August 28, 2024 10:11
@svghadi
Copy link
Member

svghadi commented Aug 29, 2024

/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.

Copy link
Member

@svghadi svghadi left a 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

Comment on lines 941 to 961
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
}
Copy link
Member

@svghadi svghadi Sep 2, 2024

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...

Suggested change
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
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

@svghadi
Copy link
Member

svghadi commented Sep 2, 2024

/remove-hold

@saumeya saumeya force-pushed the ensure-pod-security-label branch from 0b17b20 to ff7bcbe Compare September 3, 2024 11:35
Copy link
Member

@svghadi svghadi left a 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)
Copy link
Collaborator

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.

Copy link
Collaborator

@iam-veeramalla iam-veeramalla left a 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.

@iam-veeramalla
Copy link
Collaborator

/lgtm
/approve

Copy link

openshift-ci bot commented Sep 4, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Sep 4, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit b50e9e1 into redhat-developer:master Sep 4, 2024
20 checks passed
@saumeya
Copy link
Member Author

saumeya commented Sep 4, 2024

/cherry-pick v1.14

@saumeya
Copy link
Member Author

saumeya commented Sep 4, 2024

/cherry-pick v1.13

@openshift-cherrypick-robot

@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:

/cherry-pick v1.14

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.

@openshift-cherrypick-robot

@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:

/cherry-pick v1.13

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
Copy link
Member Author

saumeya commented Sep 4, 2024

/cherry-pick v1.14

@saumeya
Copy link
Member Author

saumeya commented Sep 4, 2024

/cherry-pick v1.13

@openshift-cherrypick-robot

@saumeya: #774 failed to apply on top of branch "v1.14":

Patch is empty.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To record the empty patch as an empty commit, run "git am --allow-empty".
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherry-pick v1.14

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.

@openshift-cherrypick-robot

@saumeya: new pull request created: #777

In response to this:

/cherry-pick v1.13

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants