Skip to content

Commit 6bbaa07

Browse files
committed
CORS-3261: GCP cluster api add disk encryption
** Add the disk encryption key information for the CAPG machines. The new feature includes the encryption for bootstrap as well as control plane machines created by the gcp cluster api provider. ** Note: CAPG supports Customer Managed (CMEK) and Customer Supplied (CSEK) Keys. The installer only supports Customer Supplied Keys. ** Note: CAPG supports multiple disks through the GCPMachine.Spec.AdditionDisks, but the installer only uses a single disk, so this PR will not fill out the disk encryption data for multiple disks.
1 parent bc9836a commit 6bbaa07

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

pkg/asset/machines/gcp/gcpmachines.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,19 @@ import (
1717
gcptypes "github.com/openshift/installer/pkg/types/gcp"
1818
)
1919

20-
const masterRole = "master"
20+
const (
21+
masterRole = "master"
22+
23+
kmsKeyNameFmt = "projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s"
24+
)
25+
26+
func generateDiskEncryptionKeyLink(kmsKey *gcptypes.KMSKeyReference, projectID string) string {
27+
if kmsKey.ProjectID != "" {
28+
projectID = kmsKey.ProjectID
29+
}
30+
31+
return fmt.Sprintf(kmsKeyNameFmt, projectID, kmsKey.Location, kmsKey.KeyRing, kmsKey.Name)
32+
}
2133

2234
// GenerateMachines returns manifests and runtime objects to provision control plane nodes using CAPI.
2335
func GenerateMachines(installConfig *installconfig.InstallConfig, infraID string, pool *types.MachinePool, imageName string) ([]*asset.RuntimeFile, error) {
@@ -160,6 +172,17 @@ func createGCPMachine(name string, installConfig *installconfig.InstallConfig, i
160172
}
161173
gcpMachine.Spec.ServiceAccount = serviceAccount
162174

175+
if mpool.OSDisk.EncryptionKey != nil {
176+
encryptionKey := &capg.CustomerEncryptionKey{
177+
KeyType: capg.CustomerManagedKey,
178+
KMSKeyServiceAccount: ptr.To(mpool.OSDisk.EncryptionKey.KMSKeyServiceAccount),
179+
ManagedKey: &capg.ManagedKey{
180+
KMSKeyName: generateDiskEncryptionKeyLink(mpool.OSDisk.EncryptionKey.KMSKey, installConfig.Config.GCP.ProjectID),
181+
},
182+
}
183+
gcpMachine.Spec.RootDiskEncryptionKey = encryptionKey
184+
}
185+
163186
return gcpMachine
164187
}
165188

0 commit comments

Comments
 (0)