Skip to content
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

GCP: support specifying Cloud KMS key name for backup storage locations #1879

Merged
merged 3 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@

[[constraint]]
name = "cloud.google.com/go"
version = "0.11.0"
version = "0.46.0"

[[constraint]]
name = "google.golang.org/api"
version = "~v0.3.2"
version = "~v0.9.0"

[[constraint]]
name = "golang.org/x/oauth2"
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/1879-skriss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GCP: add support for specifying a Cloud KMS key name to use for encrypting backups in a storage location.
20 changes: 15 additions & 5 deletions pkg/cloudprovider/gcp/object_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import (
"github.com/heptio/velero/pkg/cloudprovider"
)

const credentialsEnvVar = "GOOGLE_APPLICATION_CREDENTIALS"
const (
credentialsEnvVar = "GOOGLE_APPLICATION_CREDENTIALS"
kmsKeyNameConfigKey = "kmsKeyName"
)

// bucketWriter wraps the GCP SDK functions for accessing object store so they can be faked for testing.
type bucketWriter interface {
Expand All @@ -43,11 +46,15 @@ type bucketWriter interface {
}

type writer struct {
client *storage.Client
client *storage.Client
kmsKeyName string
}

func (w *writer) getWriteCloser(bucket, key string) io.WriteCloser {
return w.client.Bucket(bucket).Object(key).NewWriter(context.Background())
writer := w.client.Bucket(bucket).Object(key).NewWriter(context.Background())
writer.KMSKeyName = w.kmsKeyName

return writer
}

func (w *writer) getAttrs(bucket, key string) (*storage.ObjectAttrs, error) {
Expand All @@ -67,7 +74,7 @@ func NewObjectStore(logger logrus.FieldLogger) *ObjectStore {
}

func (o *ObjectStore) Init(config map[string]string) error {
if err := cloudprovider.ValidateObjectStoreConfigKeys(config); err != nil {
if err := cloudprovider.ValidateObjectStoreConfigKeys(config, kmsKeyNameConfigKey); err != nil {
return err
}

Expand Down Expand Up @@ -101,7 +108,10 @@ func (o *ObjectStore) Init(config map[string]string) error {
}
o.client = client

o.bucketWriter = &writer{client: o.client}
o.bucketWriter = &writer{
client: o.client,
kmsKeyName: config[kmsKeyNameConfigKey],
}

return nil
}
Expand Down
4 changes: 3 additions & 1 deletion site/docs/master/api-types/backupstoragelocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ The configurable parameters are as follows:

#### GCP

No parameters required.
| Key | Type | Default | Meaning |
| --- | --- | --- | --- |
| `kmsKeyName` | string | Empty | Name of the Cloud KMS key to use to encrypt backups stored in this location, in the form `projects/P/locations/L/keyRings/R/cryptoKeys/K`. See [customer-managed Cloud KMS keys](https://cloud.google.com/storage/docs/encryption/using-customer-managed-keys) for details. |

[0]: #aws
[1]: #gcp
Expand Down
15 changes: 0 additions & 15 deletions vendor/cloud.google.com/go/AUTHORS

This file was deleted.

37 changes: 0 additions & 37 deletions vendor/cloud.google.com/go/CONTRIBUTORS

This file was deleted.

2 changes: 1 addition & 1 deletion vendor/cloud.google.com/go/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading