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

Add google cloud KMS support #245

Merged
merged 12 commits into from Sep 19, 2017
Merged

Add google cloud KMS support #245

merged 12 commits into from Sep 19, 2017

Conversation

calind
Copy link

@calind calind commented Sep 11, 2017

Fixes #188.

@autrilla autrilla self-requested a review September 11, 2017 18:58
@codecov-io
Copy link

codecov-io commented Sep 11, 2017

Codecov Report

Merging #245 into master will decrease coverage by 1.17%.
The diff coverage is 28.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #245      +/-   ##
==========================================
- Coverage   44.94%   43.76%   -1.18%     
==========================================
  Files           6        7       +1     
  Lines        1048     1131      +83     
==========================================
+ Hits          471      495      +24     
- Misses        515      573      +58     
- Partials       62       63       +1
Impacted Files Coverage Δ
sops.go 41.29% <ø> (ø) ⬆️
config/config.go 77.27% <100%> (+2.27%) ⬆️
gcpkms/keysource.go 23.37% <23.37%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5caa68e...c7c94e9. Read the comment docs.

Copy link
Contributor

@autrilla autrilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the PR. Looks good, I've left a few minor comments that need to be address before we can merge this.


// this needs to be a global var for unit tests to work (mockKMS redefines
// it in keysource_test.go)
// var kmsSvc kmsiface.KMSAPI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover from copying from AWS KMS. This should probably have tests like the AWS KMS keysource does, so we'll probably need something like this for the GCP version.

return key.ResourceId
}

// NewMasterKeyFromResourceId takes an cloud KMS resource id string and returns a new MasterKey for that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an cloud KMS/a cloud KMS

cmd/sops/main.go Outdated
@@ -91,7 +92,7 @@ func main() {
cli.VersionPrinter = printVersion
app := cli.NewApp()
app.Name = "sops"
app.Usage = "sops - encrypted file editor with AWS KMS and GPG support"
app.Usage = "sops - encrypted file editor with AWS KMS, google cloud KMS and GPG support"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Capitalize Google Cloud

cmd/sops/main.go Outdated
@@ -104,17 +105,23 @@ func main() {
in the -k flag or in the SOPS_KMS_ARN environment variable.
(you need valid credentials in ~/.aws/credentials or in your env)

To encrypt or decrypt a document with google cloud KMS, specify the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Capitalize Google Cloud

cmd/sops/main.go Outdated
@@ -104,17 +105,23 @@ func main() {
in the -k flag or in the SOPS_KMS_ARN environment variable.
(you need valid credentials in ~/.aws/credentials or in your env)

To encrypt or decrypt a document with google cloud KMS, specify the
cloud KMS resource Id in the -c flag or in the SOPS_CLOUD_KMS_IDS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Capitalize Cloud

cmd/sops/main.go Outdated
@@ -141,6 +148,11 @@ func main() {
EnvVar: "SOPS_KMS_ARN",
},
cli.StringFlag{
Name: "cloud-kms, c",
Usage: "comma separated list of google cloud KMS resource IDs",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Capitalize Google Cloud

cmd/sops/main.go Outdated
@@ -104,17 +105,23 @@ func main() {
in the -k flag or in the SOPS_KMS_ARN environment variable.
(you need valid credentials in ~/.aws/credentials or in your env)

To encrypt or decrypt a document with google cloud KMS, specify the
cloud KMS resource Id in the -c flag or in the SOPS_CLOUD_KMS_IDS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/Id/ID for consistency, as you write it as ID in the docs

sops.go Outdated
@@ -385,6 +386,21 @@ func (m *Metadata) AddPGPMasterKeys(pgpFps string) {
}
}

// AddCloudKMSMasterKeys parses the input comma separated string of cloud KMS resource IDs, generates a KMS MasterKey for each resource ID, and then adds the keys to the cloud KMS KeySource
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalize Cloud

cmd/sops/main.go Outdated
@@ -428,7 +454,8 @@ func getKeySources(c *cli.Context, file string) ([]sops.KeySource, error) {
}
kmsKs := sops.KeySource{Name: "kms", Keys: kmsKeys}
pgpKs := sops.KeySource{Name: "pgp", Keys: pgpKeys}
return []sops.KeySource{kmsKs, pgpKs}, nil
cloudKmsKs := sops.KeySource{Name: "cloud-kms", Keys: cloudKmsKeys}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use cloud_kms for the key source name, as we currently use snake_case for YAML keys (e.g. unencrypted_suffix).

@jvehent
Copy link
Contributor

jvehent commented Sep 11, 2017

First there was only one kms, then google introduced their kms and things became confusing. I think we need to name Google's kms gcp-kms and provide aliases from the current kms to aws-kms. That way, if azure creates a kms service, we could just call it ma-kms and everyone would be happy :)

@calind
Copy link
Author

calind commented Sep 12, 2017

I think @jvehent has a point. I'll rename everything to gcp_kms since cloud_kms is a little too broad.

Naming things... :)

@autrilla
Copy link
Contributor

We've just merged #238 which was a very big PR and has caused conflicts with this one. I'll perform the merge myself, you shouldn't worry about it.

@autrilla
Copy link
Contributor

@calind I've performed the merge. I'd appreciate it if you could test this on your own workstation before we merge back to master.

@calind
Copy link
Author

calind commented Sep 15, 2017

@autrilla It's broken after rebase but I'll have a look in the following days.

Copy link
Contributor

@jvehent jvehent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the patch. The code looks good. It needs some README additions to tell people how to make use of it.

I'm a bit terrified by the size of the vendoring commit here. It vendors everything from xmpp to bigtable, just to call the KMS api. Is there a way to just vendor what we need?

@autrilla
Copy link
Contributor

I forgot, but because of the key service this is also going to need a protobuf message for this key type, and handling for that message type will have to be added to the key service server.

@calind
Copy link
Author

calind commented Sep 16, 2017

Thanks for the tip. I've managed to generate the protobuf stuff. I'll try finishing the PR this weekend.

Regarding @jvehent comment, I've manually added the go dependencies using govend and specifically included only the kms API stuff. I'll try find a way to reduce it but I'm pretty new to golang and any tip would be helpful.

@jvehent
Copy link
Contributor

jvehent commented Sep 16, 2017

We vendor using make vendor, which currently only calls govend -u, but could also be used to prune unnecessary packages and reduce the size of the vendor/ directory.

@calind calind force-pushed the gcloud-kms branch 3 times, most recently from 9b35f80 to 55271c1 Compare September 18, 2017 10:12
@calind
Copy link
Author

calind commented Sep 18, 2017

@autrilla, @jvehent I've updated the PR to take the keyservice into account and I've also added some docs.

Regarding the vendoring what I did was:

govend google.golang.org/api/cloudkms/v1
govend golang.org/x/oauth2/google

I've tried manually removing some folders from /vendor but any govend -u fetches them again.

cmd/sops/main.go Outdated
@@ -129,6 +129,10 @@ func main() {
Name: "kms",
Usage: "the KMS ARNs the new group should contain. Can be specified more than once",
},
cli.StringSliceFlag{
Name: "gcp-kms",
Usage: "the GCP KMS Resourece ID the new group should contain. Can be specified more than once",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resource

@calind
Copy link
Author

calind commented Sep 18, 2017

Fixed.

@autrilla
Copy link
Contributor

I've tested the functionality locally with my own GCP KMS key and it seems to be working.

@calind
Copy link
Author

calind commented Sep 18, 2017

🍾

@autrilla autrilla merged commit ec672ce into getsops:master Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants