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

e2e: support admissionapi.LevelRestricted in test/e2e/framework/pod #118134

Merged
merged 1 commit into from Jul 5, 2023

Conversation

pohly
Copy link
Contributor

@pohly pohly commented May 19, 2023

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

CreatePod and MakePod only accepted an isPrivileged boolean, which made it impossible to write tests using those helpers which work in a default framework.Framework, because the default there is LevelRestricted.

The simple boolean gets replaced with admissionapi.Level. Passing LevelRestricted does the same as calling e2epod.MixinRestrictedPodSecurity.

Special notes for your reviewer:

Instead of explicitly passing a constant to these modified helpers, most tests get updated to pass f.NamespacePodSecurityEnforceLevel. This has the advantage that if that level gets lowered in the future, tests only need to be updated in one place.

In some cases, helpers taking client+namespace+timeouts parameters get replaced with passing the Framework instance to get access to f.NamespacePodSecurityEnforceLevel. These helpers don't need separate parameters because in practice all they ever used where the values from the Framework instance.

See also https://kubernetes.slack.com/archives/C019LFTGNQ3/p1684501567057229

Does this PR introduce a user-facing change?

NONE

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels May 19, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test sig/node Categorizes an issue or PR as relevant to SIG Node. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 19, 2023
@bart0sh bart0sh added this to WIP in SIG Node PR Triage May 19, 2023
@pohly pohly force-pushed the e2e-pod-security-levels branch 2 times, most recently from 865b289 to c1ecff5 Compare May 22, 2023 05:41
@pohly pohly changed the title WIP: e2e: support admissionapi.LevelRestricted in test/e2e/framwork/pod e2e: support admissionapi.LevelRestricted in test/e2e/framwork/pod May 22, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 22, 2023
@pohly
Copy link
Contributor Author

pohly commented May 22, 2023

@chrishenzie, @humblec: tests should be passing now, please take a look.

/hold

For approval by some other test/e2e approver.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 22, 2023
@humblec
Copy link
Contributor

humblec commented May 22, 2023

Ack.. will review this soon. thanks 👍

@aojea
Copy link
Member

aojea commented May 22, 2023

/cc @liggitt @s-urbaniak

since they authored the initial implementation #106454

@humblec
Copy link
Contributor

humblec commented May 22, 2023

/retitle e2e: support admissionapi.LevelRestricted in test/e2e/framework/pod

@k8s-ci-robot k8s-ci-robot changed the title e2e: support admissionapi.LevelRestricted in test/e2e/framwork/pod e2e: support admissionapi.LevelRestricted in test/e2e/framework/pod May 22, 2023
@humblec
Copy link
Contributor

humblec commented May 22, 2023

it looks good to me. In many e2e test cases, we have been taking seperate args/params for client+namespace+timeouts, I am not sure were there any specific reason to stick to this model instead of using it from framework..

@@ -72,7 +73,8 @@ func NewDeployment(deploymentName string, replicas int32, podLabels map[string]s

// CreateDeployment creates a deployment.
func CreateDeployment(ctx context.Context, client clientset.Interface, replicas int32, podLabels map[string]string, nodeSelector map[string]string, namespace string, pvclaims []*v1.PersistentVolumeClaim, command string) (*appsv1.Deployment, error) {
deploymentSpec := testDeployment(replicas, podLabels, nodeSelector, namespace, pvclaims, false, command)
// TODO: let the caller decide about the security level.
Copy link
Member

Choose a reason for hiding this comment

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

mark the todo with a name or an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I started writing an issue and then noticed that the function is only called in three places. Addressing the TODO by passing admissionapi.LevelRestricted is now in this PR.

@@ -398,8 +399,9 @@ func runVolumeTesterPod(ctx context.Context, client clientset.Interface, timeout
When SELinux is enabled on the host, client-pod can not read the content, with permission denied.
Invoking client-pod as privileged, so that it can access the volume content, even when SELinux is enabled on the host.
*/
if config.Prefix == "hostpathsymlink" || config.Prefix == "hostpath" {
privileged = true
securityLevel := admissionapi.LevelBaseline // TODO: also support LevelRestricted
Copy link
Member

Choose a reason for hiding this comment

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

associate the todo with a github user or an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -178,7 +178,7 @@ var _ = utils.SIGDescribe("NFSPersistentVolumes[Disruptive][Flaky]", func() {
framework.ExpectNoError(e2epv.WaitOnPVandPVC(ctx, c, f.Timeouts, ns, pv2, pvc2))

ginkgo.By("Attaching both PVC's to a single pod")
clientPod, err = e2epod.CreatePod(ctx, c, ns, nil, []*v1.PersistentVolumeClaim{pvc1, pvc2}, true, "")
clientPod, err = e2epod.CreatePod(ctx, c, ns, nil, []*v1.PersistentVolumeClaim{pvc1, pvc2}, f.NamespacePodSecurityEnforceLevel, "")
Copy link
Member

Choose a reason for hiding this comment

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

f.NamespacePodSecurityEnforceLevel is not obviously equivalent to privileged... is it supposed to be? comment applied everywhere this replacement was made

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reasoning is this: if the function had been used to create a privileged pod in a namespace that only had LevelBaseline, then creating that pod would have failed. Therefore those namespaces must have been configured with LevelPrivileged and thus this change is valid.

@pohly
Copy link
Contributor Author

pohly commented May 22, 2023

it looks good to me. In many e2e test cases, we have been taking seperate args/params for client+namespace+timeouts, I am not sure were there any specific reason to stick to this model instead of using it from framework

These helper functions are unnecessarily complex: in theory, they could be used with different combination of parameters, but in practice, that flexibility is never used. But the complexity comes at a cost when reading the code ("where do these values come from?"), when calling them (need to pass several parameters in the right order), or when extending them (adding another value in this PR). I think the helpers should be as simple as possible.

@BenTheElder
Copy link
Member

BenTheElder commented May 23, 2023

/retest
[debugging https://github.com//issues/118201, have not had a chance to look at this PR]

@SergeyKanzhelev SergeyKanzhelev moved this from Triage to Archive-it in SIG Node CI/Test Board May 24, 2023
@bart0sh bart0sh moved this from WIP to Needs Reviewer in SIG Node PR Triage Jun 1, 2023
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 29, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 3, 2023
CreatePod and MakePod only accepted an `isPrivileged` boolean, which made it
impossible to write tests using those helpers which work in a default
framework.Framework, because the default there is LevelRestricted.

The simple boolean gets replaced with admissionapi.Level. Passing
LevelRestricted does the same as calling e2epod.MixinRestrictedPodSecurity.

Instead of explicitly passing a constant to these modified helpers, most tests
get updated to pass f.NamespacePodSecurityLevel. This has the advantage
that if that level gets lowered in the future, tests only need to be updated in
one place.

In some cases, helpers taking client+namespace+timeouts parameters get replaced
with passing the Framework instance to get access to
f.NamespacePodSecurityEnforceLevel. These helpers don't need separate
parameters because in practice all they ever used where the values from the
Framework instance.
@liggitt
Copy link
Member

liggitt commented Jul 5, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 5, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 342dbda0f62df098072f1fb5086670bb9c991d45

@liggitt
Copy link
Member

liggitt commented Jul 5, 2023

/approve
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 5, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, pohly

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

@k8s-ci-robot k8s-ci-robot merged commit ce7fd46 into kubernetes:master Jul 5, 2023
19 checks passed
SIG Node CI/Test Board automation moved this from Archive-it to Done Jul 5, 2023
SIG Node PR Triage automation moved this from Needs Reviewer to Done Jul 5, 2023
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/e2e-test-framework Issues or PRs related to refactoring the kubernetes e2e test framework area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/storage Categorizes an issue or PR as relevant to SIG Storage. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Development

Successfully merging this pull request may close these issues.

None yet

6 participants