-
Notifications
You must be signed in to change notification settings - Fork 1.5k
GCP: populate encryption values into tf and machines #4397
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,3 +115,8 @@ variable "gcp_image_licenses" { | |
| default = [] | ||
| } | ||
|
|
||
| variable "gcp_root_volume_kms_key_link" { | ||
| type = string | ||
| description = "The GCP self link of KMS key to encrypt the volume." | ||
| default = null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. column alignment is off and causing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
weird, tf-fmt seems to be suggesting different alignment for this file than the other two: |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,20 @@ func provider(clusterID string, platform *gcp.Platform, mpool *gcp.MachinePool, | |
| return nil, err | ||
| } | ||
|
|
||
| var encryptionKey *gcpprovider.GCPEncryptionKeyReference | ||
|
|
||
| if mpool.OSDisk.EncryptionKey != nil { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason that OSDisk.EncryptionKey can't just be an imported type from the GCP provider? That should allow us to a do a straight assignment here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. |
||
| encryptionKey = &gcpprovider.GCPEncryptionKeyReference{ | ||
| KMSKey: &gcpprovider.GCPKMSKeyReference{ | ||
| Name: mpool.OSDisk.EncryptionKey.KMSKey.Name, | ||
| KeyRing: mpool.OSDisk.EncryptionKey.KMSKey.KeyRing, | ||
| ProjectID: mpool.OSDisk.EncryptionKey.KMSKey.ProjectID, | ||
| Location: mpool.OSDisk.EncryptionKey.KMSKey.Location, | ||
| }, | ||
| KMSKeyServiceAccount: mpool.OSDisk.EncryptionKey.KMSKeyServiceAccount, | ||
| } | ||
| } | ||
|
|
||
| return &gcpprovider.GCPMachineProviderSpec{ | ||
| TypeMeta: metav1.TypeMeta{ | ||
| APIVersion: "gcpprovider.openshift.io/v1beta1", | ||
|
|
@@ -85,11 +99,12 @@ func provider(clusterID string, platform *gcp.Platform, mpool *gcp.MachinePool, | |
| UserDataSecret: &corev1.LocalObjectReference{Name: userDataSecret}, | ||
| CredentialsSecret: &corev1.LocalObjectReference{Name: "gcp-cloud-credentials"}, | ||
| Disks: []*gcpprovider.GCPDisk{{ | ||
| AutoDelete: true, | ||
| Boot: true, | ||
| SizeGb: mpool.OSDisk.DiskSizeGB, | ||
| Type: mpool.OSDisk.DiskType, | ||
| Image: osImage, | ||
| AutoDelete: true, | ||
| Boot: true, | ||
| SizeGb: mpool.OSDisk.DiskSizeGB, | ||
| Type: mpool.OSDisk.DiskType, | ||
| Image: osImage, | ||
| EncryptionKey: encryptionKey, | ||
| }}, | ||
| NetworkInterfaces: []*gcpprovider.GCPNetworkInterface{{ | ||
| Network: network, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,17 @@ package gcp | |
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| gcpprovider "github.com/openshift/cluster-api-provider-gcp/pkg/apis/gcpprovider/v1beta1" | ||
|
|
||
| "github.com/openshift/installer/pkg/types" | ||
| ) | ||
|
|
||
| const ( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this belongs in GCP provider in a util package? |
||
| kmsKeyNameFmt = "projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s" | ||
| ) | ||
|
|
||
| // Auth is the collection of credentials that will be used by terrform. | ||
| type Auth struct { | ||
| ProjectID string `json:"gcp_project_id,omitempty"` | ||
|
|
@@ -26,6 +31,7 @@ type config struct { | |
| ImageLicenses []string `json:"gcp_image_licenses,omitempty"` | ||
| VolumeType string `json:"gcp_master_root_volume_type"` | ||
| VolumeSize int64 `json:"gcp_master_root_volume_size"` | ||
| VolumeKMSKeyLink string `json:"gcp_root_volume_kms_key_link"` | ||
| PublicZoneName string `json:"gcp_public_dns_zone_name,omitempty"` | ||
| PublishStrategy string `json:"gcp_publish_strategy,omitempty"` | ||
| PreexistingNetwork bool `json:"gcp_preexisting_network,omitempty"` | ||
|
|
@@ -78,5 +84,17 @@ func TFVars(sources TFVarsSources) ([]byte, error) { | |
| cfg.PreexistingImage = false | ||
| } | ||
|
|
||
| if masterConfig.Disks[0].EncryptionKey != nil { | ||
| cfg.VolumeKMSKeyLink = generateDiskEncryptionKeyLink(masterConfig.Disks[0].EncryptionKey, masterConfig.ProjectID) | ||
| } | ||
|
|
||
| return json.MarshalIndent(cfg, "", " ") | ||
| } | ||
|
|
||
| func generateDiskEncryptionKeyLink(keyRef *gcpprovider.GCPEncryptionKeyReference, projectID string) string { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this belongs in GCP provider in a util package?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To echo our conversation on slack, I would handle this in terraform:
I'm also fine with this approach and think it's OK to have this logic live here. |
||
| if keyRef.KMSKey.ProjectID != "" { | ||
| projectID = keyRef.KMSKey.ProjectID | ||
| } | ||
|
|
||
| return fmt.Sprintf(kmsKeyNameFmt, projectID, keyRef.KMSKey.Location, keyRef.KMSKey.KeyRing, keyRef.KMSKey.Name) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to add this to the "bootstrap" module, too.
https://github.com/openshift/installer/pull/4397/files#diff-c9542c57acc94c4d250fd8d806ac9cf57c9ccd52c3c8e282a34527198949ff57R35
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that not done as the change in
data/data/gcp/bootstrap/main.tf, or does that need to go intodata/data/bootstrapsomewhere?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
/data/data/gcp/main.tfas linked above. It is currently only passing the variable from main to master, but needs to do the same for bootstrap.