Skip to content

Commit fc9bf80

Browse files
Merge pull request #8222 from barbacbd/CORS-3261
CORS-3261: GCP cluster api add disk encryption
2 parents 60c1650 + 6bbaa07 commit fc9bf80

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
@@ -18,7 +18,19 @@ import (
1818
gcptypes "github.com/openshift/installer/pkg/types/gcp"
1919
)
2020

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

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

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

0 commit comments

Comments
 (0)