Closed obriensystems closed 3 months ago
michael@cloudshell:~$ gcloud config set project sa-old
Updated property [core/project].
michael@cloudshell:~ (sa-old)$ gcloud services enable iamcredentials.googleapis.com
Operation "operations/acat.p2-971541578014-640b7729-23f8-44f0-bcdb-1577afafc93c" finished successfully.
michael@cloudshell:~ (sa-old)$
1431 gcloud auth
1432 gcloud init
1433 gcloud config set project service-accounts-old
1434 gcloud auth login
1435 gcloud auth application-default login --impersonate-service-account sa-g...z-tef@sa-test-gcp.iam.gserviceaccount.com
1436 gcloud auth application-default login --impersonate-service-account sa-...s-lz-tef@sa-test-gcp.iam.gserviceaccount.com
1437 gcloud config set project sa-test-gcp
1438 gcloud config get project
The issue seems to be related to the execution of gcloud commands. As long as it's just about Terraform execution there is no need for the user to directly impersonate an SA - terraform will do it if specifying an export GOOGLE_IMPERSONATE_SERVICE_ACCOUNT =SA-to-use-with-required permissions
There aren't many gcloud commands in the localized procedure and in fact their outcomes are independent of the progress of TF deployment. Specifically in 1-org gcloud scc notifications describe "scc-notify" --organization=${ORGANIZATION_ID} export ACCESS_CONTEXT_MANAGER_ID=$(gcloud access-context-manager policies list --organization ${ORGANIZATION_ID} --format="value(name)") in 3-networks-hub-and-spoke export ACCESS_CONTEXT_MANAGER_ID=$(gcloud access-context-manager policies list --organization ${ORGANIZATION_ID} --format="value(name)")
These could be executed even before starting 0-bootstrap and thereafter rely only on TF impersonation
Will test
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days
see - https://github.com/GoogleCloudPlatform/pubsec-declarative-toolkit/wiki/DevOps#google-api-calls-using-service-account-impersonation
Steps
on the client
Enabling service [cloudresourcemanager.googleapis.com] on project [boot-proj-old]... Operation "operations/acat.p2-480508879674-b955b8a6-4f61-4fc1-9504-d8895c8bc107" finished successfully.
Credentials saved to file: [C:\Users\micha\AppData\Roaming\gcloud\application_default_credentials.json] C:\soft\gcloud>gcloud config get project boot-proj-old
michael@cloudshell:~/tef-olapp-p1gen6$ gcloud config set project boot-proj-olapp Updated property [core/project]. michael@cloudshell:~/tef-olapp-p1gen6 (boot-proj-olapp)$
michael@cloudshell:~/tef-olapp-p1gen6 (boot-proj-olapp)$ BOOT_PROJECT_ID=boot-proj-olapp michael@cloudshell:~/tef-olapp-p1gen6 (boot-proj-olapp)$ BILLING_FORMAT="--format=value(billingAccountName)" michael@cloudshell:~/tef-olapp-p1gen6 (boot-proj-olapp)$ BILLING_ID=$(gcloud billing projects describe $BOOT_PROJECT_ID $BILLING_FORMAT | sed 's/.*\///') michael@cloudshell:~/tef-olapp-p1gen6 (boot-proj-olapp)$ ORG_ID=$(gcloud projects get-ancestors $BOOT_PROJECT_ID --format='get(id)' | tail -1) michael@cloudshell:~/tef-olapp-p1gen6 (boot-proj-olapp)$ echo $ORG_ID 630...
gcloud projects create "service-account-olapp" --name="service-account-olapp" --set-as-default --folder="865611452734" gcloud beta billing projects link "service-account-olapp" --billing-account "${BILLING_ID}"
gcloud iam service-accounts create sa-external --description="sa-external" --display-name="sa-external"
export SA_EMAIL=sa-external@service-account-olapp.iam.gserviceaccount.com gcloud projects add-iam-policy-binding service-account-olapp --member="serviceAccount:sa-external@service-account-olapp.iam.gserviceaccount.com" --role="roles/owner"
gcloud services enable cloudresourcemanager.googleapis.com gcloud services enable cloudidentity.googleapis.com gcloud identity groups create sa-external@obrienlabs.app --organization="obrienlabs.app"
gcloud services enable cloudidentity.googleapis.com gcloud identity groups memberships add --group-email="sa-external@obrienlabs.app" --member-email="michael@obrienlabs.dev" ERROR: (gcloud.identity.groups.memberships.add) FAILED_PRECONDITION: Error(4023): Cannot create membership in group 'groups/00pkwqa14lbq4ir' for member 'michael@obrienlabs.dev' because the group does not allow members outside the organization
export GROUP_EMAIL=sa-external@obrienlabs.app gcloud organizations add-iam-policy-binding "${ORG_ID}" --member=group:${GROUP_EMAIL} --role=roles/iam.serviceAccountTokenCreator --condition=None
gcloud organizations add-iam-policy-binding "${ORG_ID}" --member="serviceAccount:${SA_EMAIL}" --role=roles/resourcemanager.organizationAdmin --condition=None
gcloud init gcloud services enable iamcredentials.googleapis.com
C:\soft\gcloud>gcloud config set auth/impersonate_service_account sa-external@service-account-olapp.iam.gserviceaccount.com Updated property [auth/impersonate_service_account].
C:\soft\gcloud>gcloud auth application-default set-quota-project service-account-olapp WARNING: This command is using service account impersonation. All API calls will be executed as [sa-external@service-account-olapp.iam.gserviceaccount.com]. ERROR: (gcloud.auth.application-default.set-quota-project) Failed to impersonate [sa-external@service-account-olapp.iam.gserviceaccount.com]. Make sure the account that's trying to impersonate it has access to the service account itself and the "roles/iam.serviceAccountTokenCreator" role.
michael@cloudshell:~/tef-olapp-p1gen6 (service-account-olapp)$ gcloud organizations get-iam-policy "${ORG_ID}"
TODO