-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Impersonating GCP service accounts #7064
Impersonating GCP service accounts #7064
Comments
There is a new feature being developed in the golang google api client that should make this much easier. googleapis/google-api-go-client#625 When this comes out, the provider should be able to accept this and use the ADC to acquire and renew an access token belonging to the impersonated service account.
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Community Note
Description
In a google provider configuration block, there isn't a good way to impersonate a service account within the scope of a single GCP provider. There are several options, but they all have substantial drawbacks, especially compared to the way the AWS provider implements assuming roles.
Workaround 1 - Multiple Credentials
In this workaround, you need to create local keys for any service accounts you would like to impersonate and put them at a file path where the terraform provider configuration is expecting them.
Example
The downside of this workaround is that you have to worry about creating local credentials files at a specific path for each service account you would like to use prior to running any terraform commands. The credentials can also be stored and passed in via environment variables, but this still has the same problems around needing to get, store, and pass in credentials for the service accounts you are trying to impersonate outside of terraform.
Example
When you have a more complicated terraform setup with multiple service accounts, this quickly falls apart unless you write your own custom wrapper or key provisioning script, which you then have to maintain and manage yourself. Even if you do write that additional tooling, you're still in a situation where you have a plethora of access keys that have been created and are living on disk, which is less than optimal from a security and manageability standpoint. This is a significantly worse experience than how AWS uses assume role to use a single set of access keys (which don't even need to be written to disk if you use aws-vault or an instance profile) to access an unlimited number of roles.
Workaround 2 - Access Tokens via Data Sources
Another workaround is described in this Google Cloud blog post so I won't rehash the implementation details.
The downsides of this workaround is that the access tokens the data sources generate are actually written to your terraform state file. This means that anyone who has access to view the state file could grab access tokens with the permissions required to apply the terraform, even if that person shouldn't be allowed to apply the terraform. This creates an unacceptable security risk even though the tokens have relatively short lifespans. It also prevents enabling less privileged users to plan locally since you can longer trust them to access the state file, which really hurts their ability to efficiently create their own terraform configurations via self service.
Proposed Solution
Implement a method for impersonating a service account that is similar to AWS' ability to assume a role just in the context of a single command or provider as described in this post without writing keys to disk or requiring an external to terraform wrapper or key provisioning script. I think this can be done in a similar manner to how
gcloud
uses the--impersonate-service-account
.New or Affected Resource(s)
Potential Terraform Configuration
References
The text was updated successfully, but these errors were encountered: