I have some code to upload and download files from Google Cloud Storage. Below is an abbreviated example:
import (
"context"
"io"
"cloud.google.com/go/storage"
)
func upload(bucket, keyName, path string, reader io.Reader) error {
ctx := context.Background()
client, err := storage.NewClient(ctx)
if err != nil {
return err
}
defer client.Close()
obj := client.Bucket(bucket).Object(path)
writer := obj.NewWriter(ctx)
defer writer.Close()
writer.KMSKeyName = keyName
if _, err = io.Copy(writer, reader); err != nil {
return err
}
if err = writer.Close(); err != nil {
return err
}
return nil
}
The tricky part is that I'm using Google KMS to manage the keys I'm using to encrypt files (Google's so-called "customer-managed encryption key" scheme). My understanding is that this encryption happens on Google's end.
The only solution I found using the Go CDK was to encrypt the files using Google KMS and then upload the encrypted blob. Is there no way to specify the encryption key in the same manner I was doing before with the Go CDK?
Thanks