Extend SCC tests with their corresponding service account variants#27491
Conversation
9f9f09b to
e103e1f
Compare
| g.It("TestPodUpdateSCCEnforcement with service account", func() { | ||
| t := g.GinkgoT() | ||
|
|
||
| clusterAdminKubeClientset := oc.AdminKubeClient() | ||
|
|
||
| projectName := oc.Namespace() | ||
|
|
||
| sa := createServiceAccount(ctx, oc, projectName) | ||
| createPodAdminRoleOrDie(ctx, oc, sa) | ||
| restrictedClient, _ := createClientFromServiceAccount(oc, sa) | ||
|
|
||
| // so cluster-admin can create privileged pods, but harold cannot. This means that harold should not be able | ||
| // to update the privileged pods either, even if he lies about its privileged nature | ||
| privilegedPod := getPrivilegedPod("unsafe") | ||
|
|
||
| if _, err := restrictedClient.CoreV1().Pods(projectName).Create(ctx, privilegedPod, metav1.CreateOptions{}); !isForbiddenBySCC(err) { | ||
| t.Fatalf("missing forbidden: %v", err) | ||
| } | ||
|
|
||
| actualPod, err := clusterAdminKubeClientset.CoreV1().Pods(projectName).Create(ctx, privilegedPod, metav1.CreateOptions{}) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
|
|
||
| actualPod.Spec.Containers[0].Image = "something-nefarious" | ||
| if _, err := restrictedClient.CoreV1().Pods(projectName).Update(ctx, actualPod, metav1.UpdateOptions{}); !isForbiddenBySCC(err) { | ||
| t.Fatalf("missing forbidden: %v", err) | ||
| } | ||
|
|
||
| // try to connect to /exec subresource as harold | ||
| restrictedClientCorev1Rest := restrictedClient.CoreV1().RESTClient() | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| result := &metav1.Status{} | ||
| err = restrictedClientCorev1Rest.Post(). | ||
| Resource("pods"). | ||
| Namespace(projectName). | ||
| Name(actualPod.Name). | ||
| SubResource("exec"). | ||
| Param("container", "first"). | ||
| Do(ctx). | ||
| Into(result) | ||
| if !isForbiddenBySCCExecRestrictions(err) { | ||
| t.Fatalf("missing forbidden by SCCExecRestrictions: %v", err) | ||
| } | ||
|
|
||
| // try to lie about the privileged nature | ||
| actualPod.Spec.HostPID = false | ||
| if _, err := restrictedClient.CoreV1().Pods(projectName).Update(context.Background(), actualPod, metav1.UpdateOptions{}); err == nil { | ||
| t.Fatalf("missing error: %v", err) | ||
| } | ||
| }) |
There was a problem hiding this comment.
This looks like a copy-pasta of the above. Could you just derive the variables (I believe it's just the restConfig for the user?) from the code and turn this into a function that's run from the two tests?
e103e1f to
94e1dc1
Compare
|
/retest-required |
94e1dc1 to
77ca6e1
Compare
|
/retest-required |
| } | ||
|
|
||
| func createPodsecuritypolicyselfsubjectreviewsRoleBindingOrDie(ctx context.Context, oc *exutil.CLI, sa *corev1.ServiceAccount) { | ||
| framework.Logf("Creating pspssr role") |
There was a problem hiding this comment.
createPodSecurityPolicySelfSubjectReviewsRoleBindingOrDie :D
There was a problem hiding this comment.
my point is - please expand the shortcut in the log, otherwise people will hate you whenever they will be trying to understand what's going on in here :)
d04fe0d to
f9aa361
Compare
|
/lgtm |
f9aa361 to
8304466
Compare
|
/aprove |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ingvagabund, mfojtik, soltysh, stlaz The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@ingvagabund: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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/test-infra repository. I understand the commands that are listed here. |
|
/retest-required |
…irror-scc-with-service-account"" This reverts commit 6a8ff38.
…irror-scc-with-service-account"" This reverts commit 6a8ff38.
…irror-scc-with-service-account"" This reverts commit 6a8ff38.
Duplicate existing
TestPodUpdateSCCEnforcementandTestAllowedSCCViaRBACe2e tests with their corresponding service account equivalents to drop api group dependency onapigroup:user.openshift.ioandapigroup:authorization.openshift.io.