TL;DR. Can't figure out what APIs scope needs to be enabled on bastion instance. Also, any advise on building bastion instance?
I'm working on a bastion instance from which I'd like to run terraform plan
/ terraform apply
commands.
My plan for bastion instance is this:
- set up OS Login,
- set up two-factor authentication,
make sure default service account has access to GCP resources (for terraform to be able to access resources):
If you're running Terraform from a GCE instance, default credentials are automatically available. See Creating and Enabling Service Accounts for Instances for more details.
store terraform configs on the instance, be able
terraform plan
/terraform apply
After doing items 1, 3 and 4 from the list above I am having a problem with terraform accessing service account management API - running terraform plan
results in the following:
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
google_service_account.terraform_state_user: Refreshing state... [id=projects/xxxxxxxx-xxxxxx-xxxxxx/serviceAccounts/terraform-state-user@xxxxxxxx-xxxxxx-xxxxxx.iam.gserviceaccount.com]
google_storage_bucket.access_logs: Refreshing state... [id=xxxxxxxx-bucket-access-logs]
google_storage_bucket.terraform_state_storage: Refreshing state... [id=xxxxxxxx-terraform-state-storage]
Error: Error reading Service Account "projects/xxxxxxxx-xxxxxx-xxxxxx/serviceAccounts/terraform-state-user@xxxxxxxx-xxxxxx-xxxxxx.iam.gserviceaccount.com": googleapi: Error 403: Request had insufficient authentication scopes., forbidden
As PoC fix I have changed the list of Cloud API access scopes on the bastion VM to Allow full access to all Cloud APIs. After doing so, terraform plan
and terraform apply
commands succeeded. As a next step, I decided to limit the number of API scopes the instance has access to but found myself unable to find correct set of APIs scopes to access Service Account API (I get the error as indicated above).
After a couple of attempts to terraform plan
and terraform apply
to work. This is the list of API scopes I have on bastion right now:
Bigtable Admin Disabled
Bigtable Data Disabled
Cloud Datastore Disabled
Cloud Debugger Disabled
Cloud Pub/Sub Disabled
Cloud Source Repositories Disabled
Cloud SQL Disabled
Compute Engine Read Write
Service Control Enabled
Service Management Read Write
Stackdriver Logging API Write Only
Stackdriver Monitoring API Write Only
Stackdriver Trace Write Only
Storage Read Write
Task queue Disabled
User info Enabled
I'm trying to find answers to the following questions:
- what API scope should I enable to be able to read / write service account resources?
- provided I am SSHing into bastion via "OS Login" feature (which depends on IAM role my own user) is my own account used to access the APIs, or is it Default Service Account? (this is just to aid my understanding),
- any general advise on building bastion instance?