NOTE: This guide is assuming a Google Gsuite Business/Workspace account.
IF YOU HAVE DONE THIS BEFORE, THERE IS NO REASON TO REPEAT IT. USE THE SAME 300 SERVICE ACCOUNTS CREATED THE FIRST TIME.
IF YOU HAVE SERVICE ACCOUNTS CREATED IN ANOTHER CONTEXT [CLOUDBOX, PTS, ETC.] YOU CAN USE THOSE. THERE IS NO REQUIREMENT TO CREATE MORE.
sa-gen has recently [May 2023] changed; these instructions are assuming the older version, and the paths and commands below have been updated to reflect that.
IMPORTANT: Google has made changes to the service account infrastructure on their side. When running this script you may see a message like:
A quota has been reached for project number PROJECT_NUMBER: Service accounts created per minute per project.
This is due to a change on Google's side, and there's not a simnple way around it. The simplest solution is to just ignore tha error, then after the script has run delete the empty files that got created. The final step is going to try to use service account file 150.json; if that one is empty either copy another one to that name or change the config in the final step to use a file that is present.
Create /opt/sa and make sure it's writable by you.
What do I put in for `user` and `group`?
Enter the user name that you entered in `accounts.yml`; group is the same as the user.
Don't enter the `<` and `>`.
Verify that the google project has the right APIs enabled:
[copy-paste this into your terminal window]
gcloudserviceslist--enabled
You should see:
NAME TITLE
admin.googleapis.com Admin SDK API
bigquery.googleapis.com BigQuery API
bigquerystorage.googleapis.com BigQuery Storage API
cloudapis.googleapis.com Google Cloud APIs
clouddebugger.googleapis.com Cloud Debugger API
cloudresourcemanager.googleapis.com Cloud Resource Manager API
cloudtrace.googleapis.com Cloud Trace API
datastore.googleapis.com Cloud Datastore API
drive.googleapis.com Google Drive API
iam.googleapis.com Identity and Access Management (IAM) API
iamcredentials.googleapis.com IAM Service Account Credentials API
logging.googleapis.com Cloud Logging API
monitoring.googleapis.com Cloud Monitoring API
servicemanagement.googleapis.com Service Management API
serviceusage.googleapis.com Service Usage API
sheets.googleapis.com Google Sheets API
sql-component.googleapis.com Cloud SQL
storage-api.googleapis.com Google Cloud Storage JSON API
storage-component.googleapis.com Cloud Storage
storage.googleapis.com Cloud Storage API
If any of these are missing from your list, go back to the project setup and add all the APIs shown there to the project.
Edit the beginning of the script as indicated by <<<< below:
For these edits, you will need: the "Organization ID" from gcloud SDK step, the full email address of the group you created a couple steps ago, and the prefix you generated earlier.
#!/bin/bash# Running this script requires gcloud command line tools. To install go to https://cloud.google.com/sdk/docs/quickstarts# See readme.md to understand the variables used in this scriptKEYS_DIR=/opt/sa/all
ORGANIZATION_ID="123456789098"<<<<organizationIDfromgcloudSDKstep
GROUP_NAME="mygroup@mydomain.com"<<<<thegroup[fullemailaddressasshown]youcreatedpreviously
PROJECT_BASE_NAME="mgbtbnfkkt"<<<<theprefixyougeneratedpreviously
FIRST_PROJECT_NUM=1LAST_PROJECT_NUM=3SA_EMAIL_BASE_NAME="mgbtbnfkkt"<<<<theprefixyougeneratedpreviously
FIRST_SA_NUM=1NUM_SAS_PER_PROJECT=100
...
Save the file with control-x, y, enter
Run the sa-gen script:
./sa-gen_2022
sa-gen_2022 will create three projects, 300 SAs, and download them to /opt/sa:
Total SA json keys before running sa-gen = 0
Creating project = mgbtbnfkkt1
++ gcloud projects create mgbtbnfkkt1 --organization=
Create in progress for [https://cloudresourcemanager.googleapis.com/v1/projects/mgbtbnfkkt1].
Waiting for [operations/cp.5950654100828535641] to finish...done.
Enabling service [cloudapis.googleapis.com] on project [mgbtbnfkkt1]...
Operation "operations/acf.p2-672393700722-9443eda2-69db-46a9-8952-5cdaa3b6ed2f" finished successfully.
++ set +x
...
Total SA json keys BEFORE running sa-gen = 0
Total SA json keys AFTER running sa-gen = 300
Total SA jsons CREATED = 300
Download the members.csv file that sa-gen created next to the service account files to your local computer using sftp or whatever other means.
Open the Google Admin site: https://admin.google.com/ and login with your Google account. Click on the groups heading:
Click on your group:
Click on "BULK UPLOAD MEMBERS":
Click on "ATTACH CSV", and find the members.csv you downloaded a moment ago:
Click "UPLOAD". Status will appear in the upper right:
You're done.
Warning
If you see errors that leave some of the service account JSON files empty, the simplest thing to do is to jsut delete those empty files and carry on. 300 was overkill even when this was a useful setup, so 240 or so will be more than sufficient now.