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

migration: match SELinux level of source pod on target pod #9246

Merged
merged 1 commit into from Jun 6, 2023

Conversation

jean-edouard
Copy link
Contributor

@jean-edouard jean-edouard commented Feb 14, 2023

What this PR does / why we need it:
When VMIs use RWX disks based on some storage classes, like cephfs, both the source and target pods of a migration need to have access to the files.
There are 2 ways to achieve that:

Both solutions have negative security implications, but they're the only way to deal with shared resources.
I believe this is the best approach, as it doesn't mess with the disk and doesn't expose files to the entire node/cluster for the duration of the migration.
The only downside here is that the target node could (have) create(d) a pod with the same categories.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Special notes for your reviewer:

Release note:

Fixed migration issue for VMIs that have RWX disks backed by filesystem storage classes.

@kubevirt-bot kubevirt-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. size/S labels Feb 14, 2023
@jean-edouard
Copy link
Contributor Author

/retest

@jean-edouard
Copy link
Contributor Author

/retest-required

@jean-edouard jean-edouard changed the title WIP: migration: match SELinux level of source pod on target pod migration: match SELinux level of source pod on target pod Feb 22, 2023
@kubevirt-bot kubevirt-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 22, 2023
@jean-edouard
Copy link
Contributor Author

A functest was added and this is now ready for reviews!

@jean-edouard
Copy link
Contributor Author

/retest

Copy link
Contributor

@akalenyu akalenyu left a comment

Choose a reason for hiding this comment

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

Looks good!

This does not happen in the RWX Block case, right?
I am just trying to understand why this was never an issue with our CI lanes
running ceph rbd migrations

templatePod.Spec.SecurityContext = &k8sv1.PodSecurityContext{}
}
templatePod.Spec.SecurityContext.SELinuxOptions = &k8sv1.SELinuxOptions{
Level: seFields[3],
Copy link
Contributor

@akalenyu akalenyu Mar 1, 2023

Choose a reason for hiding this comment

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

just a suggestion, may be worth to try construct the context and grab the level out of it?

func newContext(label string) (Context, error) {
c := make(Context)
if len(label) != 0 {
con := strings.SplitN(label, ":", 4)
if len(con) < 3 {
return c, InvalidLabel
}
c["user"] = con[0]
c["role"] = con[1]
c["type"] = con[2]
if len(con) > 3 {
c["level"] = con[3]
}
}
return c, nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, will do!

@jean-edouard
Copy link
Contributor Author

Looks good!

This does not happen in the RWX Block case, right? I am just trying to understand why this was never an issue with our CI lanes running ceph rbd migrations

This is actually specifically for RWX, but it's needed only for FS CSIs (at least from what I've seen so far). Ceph rbd shouldn't need this.

@akalenyu
Copy link
Contributor

akalenyu commented Mar 1, 2023

Looks good!
This does not happen in the RWX Block case, right? I am just trying to understand why this was never an issue with our CI lanes running ceph rbd migrations

This is actually specifically for RWX, but it's needed only for FS CSIs (at least from what I've seen so far). Ceph rbd shouldn't need this.

Yeah I am just trying to understand why this isn't a problem for ceph rbd, interesting

@jean-edouard
Copy link
Contributor Author

Looks good!
This does not happen in the RWX Block case, right? I am just trying to understand why this was never an issue with our CI lanes running ceph rbd migrations

This is actually specifically for RWX, but it's needed only for FS CSIs (at least from what I've seen so far). Ceph rbd shouldn't need this.

Yeah I am just trying to understand why this isn't a problem for ceph rbd, interesting

Don't quote me on that, but I think dev nodes for the block volumes get their own label inside the pod mount namespace thanks to overlayfs.
However, for FS volumes, the labels are handled at the filesystem level inside each volume, and there's not much k8s/overlayfs can do there.
As you can probably see I'm no k8s storage expert, but hopefully that helps!

@akalenyu
Copy link
Contributor

akalenyu commented Mar 5, 2023

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Mar 5, 2023
@jean-edouard
Copy link
Contributor Author

/cc @xpivarc @vladikr
/retest

@xpivarc
Copy link
Member

xpivarc commented Mar 24, 2023

Hey @jean-edouard ,
Did you have a chance to explore how this works in Kubernetes? I mean what happens if I want ReplicaSet with shared pvc? Will only one of these Pods get to read and write to pvc?

Also how is possible we did hit this only now? Is it possible this is a problem specific to a subset of CSIs?

Sorry for the delay I should be more available moving forward.

@jean-edouard
Copy link
Contributor Author

Hey @jean-edouard , Did you have a chance to explore how this works in Kubernetes? I mean what happens if I want ReplicaSet with shared pvc? Will only one of these Pods get to read and write to pvc?

With cephfs, I believe so yes. Unless some privileged entity auto-relabels new files with the level s0 (removing the categories).

Also how is possible we did hit this only now? Is it possible this is a problem specific to a subset of CSIs?

Yes, so far this issue has only been seen with cephfs. It is discussed here:
ceph/ceph-csi#3562

@jean-edouard
Copy link
Contributor Author

/retest

@jean-edouard
Copy link
Contributor Author

@akalenyu could you please re-review and maybe re-lgtm? Thanks!
@xpivarc can we unhold?

@@ -631,6 +633,32 @@ func (c *MigrationController) createTargetPod(migration *virtv1.VirtualMachineIn
}
}

matchLevelOnTarget := c.clusterConfig.GetMigrationConfiguration().MatchSELinuxLevelOnMigration
if matchLevelOnTarget == nil || *matchLevelOnTarget {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this condition correct? If the tunable for this is omitted, it's an opt-in?
Also, just nitpicking, it may be nice to return early if the tunable is false, avoiding the extra indentation
Would probably mean this chunk needs to get extracted to it's own func

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's true by default, as discussed there: #9246 (comment)
I'll address the second part asap, thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, PTAL!

@xpivarc
Copy link
Member

xpivarc commented Jun 1, 2023

/hold cancel

@kubevirt-bot kubevirt-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 1, 2023
@akalenyu
Copy link
Contributor

akalenyu commented Jun 1, 2023

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 1, 2023
@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

2 similar comments
@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@kubevirt-commenter-bot
Copy link

/retest-required
This bot automatically retries required jobs that failed/flaked on approved PRs.
Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@brianmcarey
Copy link
Member

@jean-edouard - just a heads up. It looks like the SRIOV lane has never passed on this PR so there might be an issue there.
https://prow.ci.kubevirt.io/pr-history/?org=kubevirt&repo=kubevirt&pr=9246

Not sure if there is a point in leaving this to just retest.

Copy link
Member

@xpivarc xpivarc left a comment

Choose a reason for hiding this comment

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

/hold

// Therefore, it needs to share the same SELinux categories to inherit the same permissions
// Note: there is a small probablility that the target pod will share the same categories as another pod on its node.
// It is a slight security concern, but not as bad as removing categories on all shared objects for the duration of the migration.
if vmiSeContext == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Seems we do "selinuxContext": "none",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really nice catch, thank you! Should be fixed now.

Copy link
Member

Choose a reason for hiding this comment

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

I agree @brianmcarey

@kubevirt-bot kubevirt-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 2, 2023
Signed-off-by: Jed Lejosne <jed@redhat.com>
@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Jun 2, 2023
@xpivarc
Copy link
Member

xpivarc commented Jun 2, 2023

/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 2, 2023
@xpivarc
Copy link
Member

xpivarc commented Jun 2, 2023

@jean-edouard maybe we can introduce helpers for this so we don't get this wrong again in future

@jean-edouard
Copy link
Contributor Author

@jean-edouard maybe we can introduce helpers for this so we don't get this wrong again in future

@xpivarc good idea, ok to do in a later PR and unhold this one? Thanks you!

@xpivarc
Copy link
Member

xpivarc commented Jun 5, 2023

/hold cancel
@jean-edouard Sorry I have missed the hold!

@kubevirt-bot kubevirt-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 5, 2023
@jean-edouard
Copy link
Contributor Author

/test pull-kubevirt-e2e-kind-1.27-sriov

@kubevirt-bot
Copy link
Contributor

@jean-edouard: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubevirt-e2e-kind-1.23-sriov 7bbf98d link true /test pull-kubevirt-e2e-kind-1.23-sriov
pull-kubevirt-fossa cae7333 link false /test pull-kubevirt-fossa
pull-kubevirt-e2e-k8s-1.24-sig-compute 80254d4 link true /test pull-kubevirt-e2e-k8s-1.24-sig-compute
pull-kubevirt-e2e-k8s-1.26-sig-compute 8c11802 link unknown /test pull-kubevirt-e2e-k8s-1.26-sig-compute

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. I understand the commands that are listed here.

@jean-edouard
Copy link
Contributor Author

/retest

@kubevirt-bot kubevirt-bot merged commit 28a3e16 into kubevirt:main Jun 6, 2023
35 of 36 checks passed
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. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants