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

feat: Add VM delete protection #1199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jcanocan
Copy link
Contributor

@jcanocan jcanocan commented Jan 8, 2025

What this PR does / why we need it:
VirtualMachine objects are often managed by automation, CLI commands, 3rd party tools, etc. These automations may result in deleting accidentally VMs that should have not been deleted. These deletions may lead to a service degradation or out of service. Moreover, the deleted VMs may lead to information loss if the underlining PVC is deleted as a result of a cascaded delete.

It adds the ability to protect VirtualMachine objects from being deleted. If the label kubevirt.io/vm-delete-protection is set to True, any attempt to delete the VM will be rejected by a VAP policy.

This protection enables a protection against non-intended VM deletions, providing security and confidence to users.

Which issue(s) this PR fixes:

Fixes # CNV-50741

Special notes for your reviewer:

Release note:

Enables delete protection to VirtualMachine objects

@kubevirt-bot kubevirt-bot added 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. labels Jan 8, 2025
@kubevirt-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign 0xfelix for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link
Collaborator

@akrejcir akrejcir left a comment

Choose a reason for hiding this comment

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

Why did you create a separate controllers instead of adding these new resources into an operand? We usually add new resources in operands. That way, they can be configured in the SSP resource.

Can you rename this PR and the commit? This is definitely not a chore.
Maybe something like:

feat: Add VM delete protection

},
Validations: []admissionregistrationv1.Validation{
{
Expression: `(!has(oldObject.metadata.labels) || !(variables.label in oldObject.metadata.labels) || !oldObject.metadata.labels[variables.label].matches('^(true|True)$'))`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be enough to test that the label exists, instead of checking its value?

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've considered clearer from the user point of view. My idea is: by forcing the user to add the "True" value, we make sure that user really wants the protection enabled, and I think it will avoid confusions. That being said, I'm not against it if we find it out better.

@akrejcir
Copy link
Collaborator

akrejcir commented Jan 8, 2025

/hold

@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 Jan 8, 2025
@jcanocan
Copy link
Contributor Author

jcanocan commented Jan 8, 2025

Why did you create a separate controllers instead of adding these new resources into an operand? We usually add new resources in operands. That way, they can be configured in the SSP resource.

It is my understanding that operands are better fit when you are using CRD than controllers. In this case, we are just using a build-in feature such as VAP and VAPB. Given that, I'm not particularly against adding it though an operand. In fact, I question this myself multiple times. As we consider best.

Can you rename this PR and the commit? This is definitely not a chore. Maybe something like:

feat: Add VM delete protection

You are absolutely right. Thanks.

@jcanocan jcanocan force-pushed the vm-delete-protection branch from 57c3cc2 to e4f96d2 Compare January 8, 2025 13:51
@jcanocan jcanocan changed the title chore(vm-delete-protection): Add VM delete protection controller feat: Add VM delete protection Jan 8, 2025
@akrejcir
Copy link
Collaborator

akrejcir commented Jan 8, 2025

Why did you create a separate controllers instead of adding these new resources into an operand? We usually add new resources in operands. That way, they can be configured in the SSP resource.

It is my understanding that operands are better fit when you are using CRD than controllers. In this case, we are just using a build-in feature such as VAP and VAPB. Given that, I'm not particularly against adding it though an operand. In fact, I question this myself multiple times. As we consider best.

I'm not sure what do you mean by "operands are better fit when you are using CRD than controllers". Can you explain it more?

The SSP controller deploys various resources based on what is configured in the SSP CR. VAP and VAPB are one of these resources. Currently we don't configure them, but maybe we can. Operands are an abstraction used to group related resources together in the code, so it is easier to understand. For example we deploy multiple ClusterRole objects, and it would be harder to understand if they were all in one package.

I would say that this is the exact use case to add a new operand.

@jcanocan
Copy link
Contributor Author

jcanocan commented Jan 8, 2025

Why did you create a separate controllers instead of adding these new resources into an operand? We usually add new resources in operands. That way, they can be configured in the SSP resource.

It is my understanding that operands are better fit when you are using CRD than controllers. In this case, we are just using a build-in feature such as VAP and VAPB. Given that, I'm not particularly against adding it though an operand. In fact, I question this myself multiple times. As we consider best.

I'm not sure what do you mean by "operands are better fit when you are using CRD than controllers". Can you explain it more?

The SSP controller deploys various resources based on what is configured in the SSP CR. VAP and VAPB are one of these resources. Currently we don't configure them, but maybe we can. Operands are an abstraction used to group related resources together in the code, so it is easier to understand. For example we deploy multiple ClusterRole objects, and it would be harder to understand if they were all in one package.

I would say that this is the exact use case to add a new operand.

All right! You convinced me! Thanks. Let's create an operand.

@jcanocan jcanocan force-pushed the vm-delete-protection branch from e4f96d2 to 03ff41f Compare January 9, 2025 11:29
@jcanocan
Copy link
Contributor Author

jcanocan commented Jan 9, 2025

v2:

  • Dropped vap and vapb controllers.
  • Added a new operand to handle both vap and vapb resources.

internal/common/labels.go Outdated Show resolved Hide resolved
internal/operands/vm-delete-protection/reconcile.go Outdated Show resolved Hide resolved
internal/operands/vm-delete-protection/reconcile.go Outdated Show resolved Hide resolved
internal/operands/vm-delete-protection/reconcile.go Outdated Show resolved Hide resolved
internal/operands/vm-delete-protection/reconcile.go Outdated Show resolved Hide resolved
tests/vm_deletion_protection_test.go Outdated Show resolved Hide resolved
tests/vm_deletion_protection_test.go Outdated Show resolved Hide resolved
tests/vm_deletion_protection_test.go Outdated Show resolved Hide resolved
tests/vm_deletion_protection_test.go Outdated Show resolved Hide resolved
tests/vm_deletion_protection_test.go Outdated Show resolved Hide resolved
@akrejcir
Copy link
Collaborator

akrejcir commented Jan 9, 2025

Please also add the new operand to the tests/cleanup_test.go, so it will check that cleanup works.

@jcanocan jcanocan force-pushed the vm-delete-protection branch from 03ff41f to e4d02a8 Compare January 9, 2025 16:37
@jcanocan
Copy link
Contributor Author

jcanocan commented Jan 9, 2025

Please also add the new operand to the tests/cleanup_test.go, so it will check that cleanup works.

Added.

@jcanocan jcanocan force-pushed the vm-delete-protection branch from e4d02a8 to 2c8aa38 Compare January 10, 2025 11:54
@akrejcir
Copy link
Collaborator

/unhold

@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 Jan 10, 2025
@jcanocan jcanocan force-pushed the vm-delete-protection branch from 2c8aa38 to 4ff65b3 Compare January 10, 2025 13:48

func New() operands.Operand {
if err := checkCelExpression(); err != nil {
panic("Invalid VM delete protection CEL expression")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Show also the error message in panic. It will be useful for debugging.

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.

@akrejcir
Copy link
Collaborator

Can you also remove unneeded text from the PR's description?

It adds the ability to protect VirtualMachine objects from being
deleted. If the label `kubevirt.io/vm-delete-protection` is set to
`True`, any attempt to delete the VM will be rejected by a VAP policy.

Signed-off-by: Javier Cano Cano <[email protected]>
@jcanocan jcanocan force-pushed the vm-delete-protection branch from 4ff65b3 to 886d79d Compare January 10, 2025 15:25
@jcanocan
Copy link
Contributor Author

Can you also remove unneeded text from the PR's description?

Adjusted.
Is it better now?

Copy link

openshift-ci bot commented Jan 10, 2025

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

Test name Commit Details Required Rerun command
ci/prow/e2e-upgrade-functests 886d79d link true /test e2e-upgrade-functests

Full PR test history. Your PR dashboard.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. 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.

3 participants