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

Read GCP key content from environment? #681

Open
reidab opened this issue Jun 16, 2020 · 7 comments
Open

Read GCP key content from environment? #681

reidab opened this issue Jun 16, 2020 · 7 comments

Comments

@reidab
Copy link

reidab commented Jun 16, 2020

The GCP KMS implementation uses Google's Application Default Credentials scheme, which requires the path to a key file to be passed set as GOOGLE_APPLICATION_CREDENTIALS.

We've run into a few places in our build process where we'd like to use sops with the GCP KMS, but where it's not feasible for us to write credentials to a file beforehand. Would it make sense for sops to provide an environment variable to accept Google credentials as content instead of as a path?

The Google API client offers an initialization method using credentials content: https://pkg.go.dev/google.golang.org/api/option?tab=doc#WithCredentialsJSON

@autrilla
Copy link
Contributor

autrilla commented Jun 16, 2020 via email

@reidab
Copy link
Author

reidab commented Jun 23, 2020

It's definitely something that should be added to the GCP SDK, but every discussion I've ever seen about it has ended with "we implement Application Default Credentials, that's just how it works". 😞

The specific use case that I was trying to make work is:

  • We're using Terraform to manage infrastructure and the hosted Terraform Cloud environment to apply changes.

  • We have existing secrets managed in sops files that I'd like to read as part of the Terraform run. These sops files would be checked in to git alongside the terraform config.

  • https://github.com/carlpett/terraform-provider-sops uses sops as a library to decrypt sops files and expose them to Terraform.

  • In the context of the Terraform Cloud runner, I can set environment vars and terraform input vars, but I can't execute arbitrary setup code (e.g. to write the contents of an environment variable to a file).

  • I'd like to patch terraform-provider-sops so that it can accept credentials directly in a terraform input var and pass them on to sops. I don't think I can do that without a change to sops to add an option that will initialize a Google client with explicit params instead of the defaults here:

    https://github.com/mozilla/sops/blob/4bc27f6eb72b1b4090753e9f3dba1d094544e1c3/gcpkms/keysource.go#L134

@farant
Copy link

farant commented Feb 4, 2021

I might be wrong but my understanding is that GOOGLE_APPLICATION_CREDENTIALS can either be a path to the json credentials or the actual json credential contents?

Could be worth testing if that would help your use case.

@reidab
Copy link
Author

reidab commented Feb 5, 2021

The Application Default Credentials spec says it's a file path, and that's how the Go library implements it:

https://github.com/golang/oauth2/blob/5d25da1a8d43b66f2898c444f899c7bcfd6a407e/google/default.go#L78-L85

The Google Auth clients for some other languages implement a way to pass credentials directly as a different environment variable, but there's no equivalent in Go.

The official recommendation from the Go OAuth2 team is to use CredentialsFromJSON to construct a client if you want to pass JSON directly, which would have to be implemented as part of sops.

@Morriz
Copy link

Morriz commented May 12, 2021

Since a gcloud update we now see that GOOGLE_APPLICATION_CREDENTIALS is used for kubectl access, which stopped working as it points to a service account that only has decrypt perms.

Blocker

@Morriz
Copy link

Morriz commented May 12, 2021

If we need to combine perms in one account we can (even tho its a pita), but is that documented?

@shyukri
Copy link

shyukri commented Sep 13, 2021

Any progress on this ?

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

No branches or pull requests

5 participants