The CryptoManager.java code to add a KMS and set the default KMS cluster appears in
Example: CryptoManager Java program to add KMS and set default cluster. The user running this program must have
Cryptographic operations.Manage key servers privileges.
The Web Services SDK provides Java and C# code to create a virtual machine. The Java code can be modified to create an encrypted virtual machine. Steps below show how to implement virtual machine encryption in the VMCreate.java sample program. The
crypto property in
VirtualMachineConfigSpec should be set to
CryptoSpecEncrypt, and an encryption key provided. The storage profile must have been previously set to specify encryption. If the
CryptoSpec is unset, but a storage profile with encryption is set, vCenter Server automatically generates new keys and sets
CryptoSpec, if a default KMS has been configured.
To enhance the com.vmware.spbm.samples.VMCreate program for encryption, follow these steps:
Set the crypto property in
RelocateSpec at
cloneSpec.location. The virtual machine must be powered off, with no existing snapshots. The encrypted virtual machine will be cloned, still encrypted.
First set the crypto property in the
VirtualMachineConfigSpec to
CryptoSpecEncrypt and provide a key. The virtual machine must be powered off, with no existing snapshots.
Storage profiles must also be set to specify encryption. If the CryptoSpec is unset, but a storage profile with encryption is set, the vCenter Server automatically generates new keys and sets
CryptoSpec, if the default KMS cluster has been configured.
This is similar to encrypting an existing virtual machine, but with a different CryptoSpec. First set the
crypto property in the
VirtualMachineConfigSpec to
CryptoSpecDecrypt. The virtual machine must be powered off, and the storage profiles must be set
not to specify encryption.
If the CryptoSpec is unset, but a storage profile without encryption is set, the vCenter Server sets
CryptoSpecDecrypt. The
ConfigSpec.crypto parameter must be set explicitly – only encryption is deduced from the storage profile.
The enumeration VirtualMachineConfigSpecEncryptedVMotionModes controls whether encrypted vMotion is disabled,
opportunistic (fall back to unencrypted vMotion if necessary, the default option), or
required.
If encrypted vMotion is
required, or opportunistic and available, the vCenter Server can migrate either encrypted or unencrypted virtual machines within a disk cluster, or from one disk cluster to another using Storage vMotion.
The following methods in managed object VirtualDiskManager are affected by encryption:
copyVirtualDisk – If the source disk is encrypted, its copied disk is encrypted with the same key, regardless of the
crypto spec. When calling
copyVirtualDisk_Task on vCenter Server, do not specify the
destSpec parameter, which throws a Not Implemented fault;
destSpec is supported only on ESXi hosts.
createVirtualDisk – Given a valid
crypto spec, this task directly creates an encrypted virtual disk.
moveVirtualDisk – An encrypted virtual disk cannot be moved to an unencrypted virtual machine.
createChildDisk – The child disk of an encrypted disk remains encrypted with the same key.
reparentDisks – Encrypted child disk cannot be reparented to a new disk that is not in the same disk chain.