Skip to content

Commit e3c0430

Browse files
authored
🐛 Do not attempt to encrypt VMs erroneously (vmware-tanzu#1396)
We have a bug where if a native key provider is configured, VM operator will attempt to encrypt that VM. This is incorrect. The only scenarios where a VM should be encrypted is: - if it specifies an encryption storage class - uses a vTPM (existing, or new device being added) (and a native key provider, or a custom one is specified via BYOK). This results in the VM reporting the following Condition erroneously: ``` k get vm -n parunesh-ns parunesh-vm -o=json | jq -r '.status.conditions[] | select(.type == "VirtualMachineEncryptionSynced")' { "lastTransitionTime": "2025-12-15T21:31:37Z", "message": "Must use encryption storage class or have vTPM when encrypting vm", "reason": "InvalidState", "status": "False", "type": "VirtualMachineEncryptionSynced" } ``` This change fixes this bug.
1 parent 2d83d58 commit e3c0430

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pkg/vmconfig/crypto/crypto_reconciler_pre.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,15 @@ func (r reconciler) reconcileUpdateDefaultKeyProvider(
352352
// There is a default key provider.
353353
//
354354

355-
// Encrypt the existing VM.
356-
return true, doOp(ctx, args, doEncrypt)
355+
if args.hasVTPM || args.addVTPM || args.isEncStorClass {
356+
357+
//
358+
// The existing VM meets the requirements to be encrypted.
359+
//
360+
361+
// Encrypt the existing VM.
362+
return true, doOp(ctx, args, doEncrypt)
363+
}
357364
}
358365

359366
} else {

pkg/vmconfig/crypto/crypto_reconciler_pre_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,13 @@ var _ = Describe("Reconcile", Label(testlabels.Crypto), func() {
614614
When("the vm is not already encrypted", func() {
615615
BeforeEach(func() {
616616
moVM.Config.KeyId = nil
617+
vm.Spec.StorageClass = storageClass1.Name
617618
})
618-
It("should encrypt the vm", func() {
619+
It("should not encrypt the vm", func() {
619620
Expect(err).ToNot(HaveOccurred())
620621
c := conditions.Get(vm, vmopv1.VirtualMachineEncryptionSynced)
621622
Expect(c).To(BeNil())
622-
cryptoSpec, ok := configSpec.Crypto.(*vimtypes.CryptoSpecEncrypt)
623-
Expect(ok).To(BeTrue())
624-
Expect(cryptoSpec.CryptoKeyId.KeyId).To(BeEmpty())
625-
Expect(cryptoSpec.CryptoKeyId.ProviderId.Id).To(Equal(provider1ID))
623+
Expect(configSpec.Crypto).To(BeNil())
626624
})
627625
When("the vm has a vtpm but not encrypted storage class", func() {
628626
BeforeEach(func() {

0 commit comments

Comments
 (0)