Updated gam create|use|update project

This commit is contained in:
Ross Scroggs 2025-04-22 13:50:04 -07:00
parent c5d194489f
commit 73333f921d
No known key found for this signature in database
GPG Key ID: 54585EA0887857D5
6 changed files with 52 additions and 22 deletions

View File

@ -1,3 +1,14 @@
7.06.07
Updated private key rotation progress messages in `gam create|use|update project`
and `gam upload sakey`.
Updated `gam use project` to display the following error message when the specifed project
already has a service account.
```
Re-run the command specify a new service account name with: saname <ServiceAccountName>'
```
7.06.06 7.06.06
Native support for Windows 11 Arm-based devices. Native support for Windows 11 Arm-based devices.

View File

@ -11384,25 +11384,26 @@ def _waitForSvcAcctCompletion(i):
sys.stdout.write(Msg.WAITING_FOR_ITEM_CREATION_TO_COMPLETE_SLEEPING.format(Ent.Singular(Ent.SVCACCT), sleep_time)) sys.stdout.write(Msg.WAITING_FOR_ITEM_CREATION_TO_COMPLETE_SLEEPING.format(Ent.Singular(Ent.SVCACCT), sleep_time))
time.sleep(sleep_time) time.sleep(sleep_time)
def _grantRotateRights(iam, projectId, service_account, email, account_type='serviceAccount'): def _grantRotateRights(iam, projectId, service_account, account_type='serviceAccount'):
body = {'policy': {'bindings': [{'role': 'roles/iam.serviceAccountKeyAdmin', body = {'policy': {'bindings': [{'role': 'roles/iam.serviceAccountKeyAdmin',
'members': [f'{account_type}:{email}']}]}} 'members': [f'{account_type}:{service_account}']}]}}
maxRetries = 10 maxRetries = 10
printEntityMessage([Ent.PROJECT, projectId, Ent.SVCACCT, email], kvList = [Ent.PROJECT, projectId, Ent.SVCACCT, service_account]
Msg.HAS_RIGHTS_TO_ROTATE_OWN_PRIVATE_KEY.format(email, service_account)) printEntityMessage(kvList, Msg.GRANTING_RIGHTS_TO_ROTATE_ITS_OWN_PRIVATE_KEY.format('Granting'))
for retry in range(1, maxRetries+1): for retry in range(1, maxRetries+1):
try: try:
callGAPI(iam.projects().serviceAccounts(), 'setIamPolicy', callGAPI(iam.projects().serviceAccounts(), 'setIamPolicy',
throwReasons=[GAPI.INVALID_ARGUMENT], throwReasons=[GAPI.INVALID_ARGUMENT],
resource=f'projects/{projectId}/serviceAccounts/{service_account}', body=body) resource=f'projects/{projectId}/serviceAccounts/{service_account}', body=body)
printEntityMessage(kvList, Msg.GRANTING_RIGHTS_TO_ROTATE_ITS_OWN_PRIVATE_KEY.format('Granted'))
return True return True
except GAPI.invalidArgument as e: except GAPI.invalidArgument as e:
entityActionFailedWarning([Ent.PROJECT, projectId, Ent.SVCACCT, service_account], str(e)) entityActionFailedWarning(kvList, str(e))
if 'does not exist' not in str(e) or retry == maxRetries: if 'does not exist' not in str(e) or retry == maxRetries:
return False return False
_waitForSvcAcctCompletion(retry) _waitForSvcAcctCompletion(retry)
except Exception as e: except Exception as e:
entityActionFailedWarning([Ent.PROJECT, projectId, Ent.SVCACCT, service_account], str(e)) entityActionFailedWarning(kvList, str(e))
return False return False
def _createOauth2serviceJSON(httpObj, projectInfo, svcAcctInfo, create_key=True): def _createOauth2serviceJSON(httpObj, projectInfo, svcAcctInfo, create_key=True):
@ -11420,6 +11421,7 @@ def _createOauth2serviceJSON(httpObj, projectInfo, svcAcctInfo, create_key=True)
return False return False
except GAPI.alreadyExists as e: except GAPI.alreadyExists as e:
entityActionFailedWarning([Ent.PROJECT, projectInfo['projectId'], Ent.SVCACCT, svcAcctInfo['name']], str(e)) entityActionFailedWarning([Ent.PROJECT, projectInfo['projectId'], Ent.SVCACCT, svcAcctInfo['name']], str(e))
writeStderr(Msg.RERUN_THE_COMMAND_AND_SPECIFY_A_NEW_SANAME)
return False return False
GM.Globals[GM.SVCACCT_SCOPES_DEFINED] = False GM.Globals[GM.SVCACCT_SCOPES_DEFINED] = False
if create_key and not doProcessSvcAcctKeys(mode='retainexisting', iam=iam, if create_key and not doProcessSvcAcctKeys(mode='retainexisting', iam=iam,
@ -11428,7 +11430,7 @@ def _createOauth2serviceJSON(httpObj, projectInfo, svcAcctInfo, create_key=True)
clientId=service_account['uniqueId']): clientId=service_account['uniqueId']):
return False return False
sa_email = service_account['name'].rsplit('/', 1)[-1] sa_email = service_account['name'].rsplit('/', 1)[-1]
return _grantRotateRights(iam, projectInfo['projectId'], sa_email, sa_email) return _grantRotateRights(iam, projectInfo['projectId'], sa_email)
def _createClientSecretsOauth2service(httpObj, login_hint, appInfo, projectInfo, svcAcctInfo, create_key=True): def _createClientSecretsOauth2service(httpObj, login_hint, appInfo, projectInfo, svcAcctInfo, create_key=True):
def _checkClientAndSecret(csHttpObj, client_id, client_secret): def _checkClientAndSecret(csHttpObj, client_id, client_secret):
@ -11921,9 +11923,7 @@ def doUpdateProject():
continue continue
iam = getAPIService(API.IAM, httpObj) iam = getAPIService(API.IAM, httpObj)
_getSvcAcctData() # needed to read in GM.OAUTH2SERVICE_JSON_DATA _getSvcAcctData() # needed to read in GM.OAUTH2SERVICE_JSON_DATA
_grantRotateRights(iam, projectId, _grantRotateRights(iam, projectId, GM.Globals[GM.OAUTH2SERVICE_JSON_DATA]['client_email'])
GM.Globals[GM.OAUTH2SERVICE_JSON_DATA]['client_email'],
GM.Globals[GM.OAUTH2SERVICE_JSON_DATA]['client_email'])
Ind.Decrement() Ind.Decrement()
# gam delete project [[admin] <EmailAddress>] [<ProjectIDEntity>] # gam delete project [[admin] <EmailAddress>] [<ProjectIDEntity>]
@ -12786,7 +12786,7 @@ def doUploadSvcAcctKeys():
iam = getAPIService(API.IAM, httpObj) iam = getAPIService(API.IAM, httpObj)
if doProcessSvcAcctKeys(mode='upload', iam=iam): if doProcessSvcAcctKeys(mode='upload', iam=iam):
sa_email = GM.Globals[GM.OAUTH2SERVICE_JSON_DATA]['client_email'] sa_email = GM.Globals[GM.OAUTH2SERVICE_JSON_DATA]['client_email']
_grantRotateRights(iam, GM.Globals[GM.OAUTH2SERVICE_JSON_DATA]['project_id'], sa_email, sa_email) _grantRotateRights(iam, GM.Globals[GM.OAUTH2SERVICE_JSON_DATA]['project_id'], sa_email)
sys.stdout.write(Msg.YOUR_GAM_PROJECT_IS_CREATED_AND_READY_TO_USE) sys.stdout.write(Msg.YOUR_GAM_PROJECT_IS_CREATED_AND_READY_TO_USE)
# gam delete sakeys <ServiceAccountKeyList> # gam delete sakeys <ServiceAccountKeyList>

View File

@ -72,7 +72,7 @@ Please go to:
24. Paste it at the "Enter your Client Secret: " prompt in your terminal 24. Paste it at the "Enter your Client Secret: " prompt in your terminal
25. Press return/enter in your terminal 25. Press return/enter in your terminal
26. Switch back to the browser 26. Switch back to the browser
27. Click "CANCEL" 27. Click "OK"
28. These steps are complete 28. These steps are complete
''' '''
ENTER_YOUR_CLIENT_ID = '\nEnter your Client ID: ' ENTER_YOUR_CLIENT_ID = '\nEnter your Client ID: '
@ -287,6 +287,7 @@ GAM_OUT_OF_MEMORY = 'GAM has run out of memory. If this is a large Google Worksp
GENERATING_NEW_PRIVATE_KEY = 'Generating new private key' GENERATING_NEW_PRIVATE_KEY = 'Generating new private key'
GETTING = 'Getting' GETTING = 'Getting'
GETTING_ALL = 'Getting all' GETTING_ALL = 'Getting all'
GRANTING_RIGHTS_TO_ROTATE_ITS_OWN_PRIVATE_KEY = '{0} rights to rotate its own private key'
GOOGLE_DELEGATION_ERROR = 'Google delegation error, delegator and delegate both exist and are valid for delegation' GOOGLE_DELEGATION_ERROR = 'Google delegation error, delegator and delegate both exist and are valid for delegation'
GOT = 'Got' GOT = 'Got'
GROUP_MAPS_TO_MULTIPLE_OUS = 'File: {0}, Group: {1} references multiple OUs: {2}' GROUP_MAPS_TO_MULTIPLE_OUS = 'File: {0}, Group: {1} references multiple OUs: {2}'
@ -294,13 +295,12 @@ GROUP_MAPS_TO_OU_INVALID_ROW = 'File: {0}, Invalid row, must contain non-blank <
GUARDIAN_INVITATION_STATUS_NOT_PENDING = 'Guardian invitation status is not PENDING' GUARDIAN_INVITATION_STATUS_NOT_PENDING = 'Guardian invitation status is not PENDING'
HAS_CHILD_ORGS = 'Has child {0}' HAS_CHILD_ORGS = 'Has child {0}'
HAS_INVALID_FORMAT = '{0}: {1}, Has invalid format' HAS_INVALID_FORMAT = '{0}: {1}, Has invalid format'
HAS_RIGHTS_TO_ROTATE_OWN_PRIVATE_KEY = 'Giving account {0} rights to rotate {1} private key'
HEADER_NOT_FOUND_IN_CSV_HEADERS = 'Header "{0}" not found in CSV headers of "{1}".' HEADER_NOT_FOUND_IN_CSV_HEADERS = 'Header "{0}" not found in CSV headers of "{1}".'
HELP_SYNTAX = 'Help: Syntax in file {0}\n' HELP_SYNTAX = 'Help: Syntax in file {0}\n'
HELP_WIKI = 'Help: Documentation is at {0}\n' HELP_WIKI = 'Help: Documentation is at {0}\n'
IGNORED = 'Ignored' IGNORED = 'Ignored'
INSTRUCTIONS_CLIENT_SECRETS_JSON = 'Please run\n\ngam create|use project\ngam oauth create\n\nto create and authorize a Client account.\n' INSTRUCTIONS_CLIENT_SECRETS_JSON = 'Please run\n\ngam create|use project\ngam oauth create\n\nto create and authorize a Client account.\n'
INSTRUCTIONS_OAUTH2SERVICE_JSON = 'Please run\n\ngam create|use project\ngam user <user> check serviceaccount\n\nto create and authorize a Service account.\n' INSTRUCTIONS_OAUTH2SERVICE_JSON = 'Please run\n\ngam create|use project\ngam user <user> update serviceaccount\n\nto create and authorize a Service account.\n'
INSUFFICIENT_PERMISSIONS_TO_PERFORM_TASK = 'Insufficient permissions to perform this task' INSUFFICIENT_PERMISSIONS_TO_PERFORM_TASK = 'Insufficient permissions to perform this task'
INTER_BATCH_WAIT_INCREASED = 'inter_batch_wait increased to {0:.2f}' INTER_BATCH_WAIT_INCREASED = 'inter_batch_wait increased to {0:.2f}'
INVALID = 'Invalid' INVALID = 'Invalid'
@ -468,6 +468,10 @@ REFUSING_TO_DEPROVISION_DEVICES = 'Refusing to deprovision {0} devices because a
REPLY_TO_CUSTOM_REQUIRES_EMAIL_ADDRESS = 'replyto REPLY_TO_CUSTOM requires customReplyTo <EmailAddress>' REPLY_TO_CUSTOM_REQUIRES_EMAIL_ADDRESS = 'replyto REPLY_TO_CUSTOM requires customReplyTo <EmailAddress>'
REQUEST_COMPLETED_NO_FILES = 'Request completed but no results/files were returned, try requesting again' REQUEST_COMPLETED_NO_FILES = 'Request completed but no results/files were returned, try requesting again'
REQUEST_NOT_COMPLETE = 'Request needs to be completed before downloading, current status is: {0}' REQUEST_NOT_COMPLETE = 'Request needs to be completed before downloading, current status is: {0}'
RERUN_THE_COMMAND_AND_SPECIFY_A_NEW_SANAME = """
Re-run the command specify a new service account name with: saname <ServiceAccountName>
See: https://github.com/GAM-team/GAM/wiki/Authorization#advanced-use
"""
RESOURCE_CAPACITY_FLOOR_REQUIRED = 'Options "capacity <Number>" (<Number> > 0) and "floor <String>" required' RESOURCE_CAPACITY_FLOOR_REQUIRED = 'Options "capacity <Number>" (<Number> > 0) and "floor <String>" required'
RESOURCE_FLOOR_REQUIRED = 'Option "floor <String>" required' RESOURCE_FLOOR_REQUIRED = 'Option "floor <String>" required'
RESULTS_TOO_LARGE_FOR_GOOGLE_SPREADSHEET = 'Results are too large for Google Spreadsheets. Uploading as a regular CSV file.' RESULTS_TOO_LARGE_FOR_GOOGLE_SPREADSHEET = 'Results are too large for Google Spreadsheets. Uploading as a regular CSV file.'

View File

@ -10,6 +10,21 @@ Add the `-s` option to the end of the above commands to suppress creating the `g
See [Downloads-Installs-GAM7](https://github.com/GAM-team/GAM/wiki/Downloads-Installs) for Windows or other options, including manual installation See [Downloads-Installs-GAM7](https://github.com/GAM-team/GAM/wiki/Downloads-Installs) for Windows or other options, including manual installation
### 7.06.07
Updated private key rotation progress messages in `gam create|use|update project`
and `gam upload sakey`.
Updated `gam use project` to display the following error message when the specifed project
already has a service account.
```
Re-run the command specify a new service account name with: saname <ServiceAccountName>'
```
### 7.06.06
Native support for Windows 11 Arm-based devices.
### 7.06.05 ### 7.06.05
Updated code in `gam delete|update chromepolicy` to handle the `policyTargetKey[additionalTargetKeys]` Updated code in `gam delete|update chromepolicy` to handle the `policyTargetKey[additionalTargetKeys]`

View File

@ -251,7 +251,7 @@ writes the credentials into the file oauth2.txt.
admin@server:/Users/admin$ rm -f /Users/admin/GAMConfig/oauth2.txt admin@server:/Users/admin$ rm -f /Users/admin/GAMConfig/oauth2.txt
admin@server:/Users/admin$ gam version admin@server:/Users/admin$ gam version
WARNING: Config File: /Users/admin/GAMConfig/gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: /Users/admin/GAMConfig/oauth2.txt, Not Found WARNING: Config File: /Users/admin/GAMConfig/gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: /Users/admin/GAMConfig/oauth2.txt, Not Found
GAM 7.06.05 - https://github.com/GAM-team/GAM - pyinstaller GAM 7.06.07 - https://github.com/GAM-team/GAM - pyinstaller
GAM Team <google-apps-manager@googlegroups.com> GAM Team <google-apps-manager@googlegroups.com>
Python 3.13.3 64-bit final Python 3.13.3 64-bit final
MacOS Sequoia 15.4.1 x86_64 MacOS Sequoia 15.4.1 x86_64
@ -989,7 +989,7 @@ writes the credentials into the file oauth2.txt.
C:\>del C:\GAMConfig\oauth2.txt C:\>del C:\GAMConfig\oauth2.txt
C:\>gam version C:\>gam version
WARNING: Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\GAMConfig\oauth2.txt, Not Found WARNING: Config File: C:\GAMConfig\gam.cfg, Section: DEFAULT, Item: oauth2_txt, Value: C:\GAMConfig\oauth2.txt, Not Found
GAM 7.06.05 - https://github.com/GAM-team/GAM - pythonsource GAM 7.06.07 - https://github.com/GAM-team/GAM - pythonsource
GAM Team <google-apps-manager@googlegroups.com> GAM Team <google-apps-manager@googlegroups.com>
Python 3.13.3 64-bit final Python 3.13.3 64-bit final
Windows-10-10.0.17134 AMD64 Windows-10-10.0.17134 AMD64

View File

@ -4,7 +4,7 @@ k
Print the current version of Gam with details Print the current version of Gam with details
``` ```
gam version gam version
GAM 7.06.05 - https://github.com/GAM-team/GAM - pyinstaller GAM 7.06.07 - https://github.com/GAM-team/GAM - pyinstaller
GAM Team <google-apps-manager@googlegroups.com> GAM Team <google-apps-manager@googlegroups.com>
Python 3.13.3 64-bit final Python 3.13.3 64-bit final
MacOS Sequoia 15.4.1 x86_64 MacOS Sequoia 15.4.1 x86_64
@ -16,7 +16,7 @@ Time: 2023-06-02T21:10:00-07:00
Print the current version of Gam with details and time offset information Print the current version of Gam with details and time offset information
``` ```
gam version timeoffset gam version timeoffset
GAM 7.06.05 - https://github.com/GAM-team/GAM - pyinstaller GAM 7.06.07 - https://github.com/GAM-team/GAM - pyinstaller
GAM Team <google-apps-manager@googlegroups.com> GAM Team <google-apps-manager@googlegroups.com>
Python 3.13.3 64-bit final Python 3.13.3 64-bit final
MacOS Sequoia 15.4.1 x86_64 MacOS Sequoia 15.4.1 x86_64
@ -28,7 +28,7 @@ Your system time differs from www.googleapis.com by less than 1 second
Print the current version of Gam with extended details and SSL information Print the current version of Gam with extended details and SSL information
``` ```
gam version extended gam version extended
GAM 7.06.05 - https://github.com/GAM-team/GAM - pyinstaller GAM 7.06.07 - https://github.com/GAM-team/GAM - pyinstaller
GAM Team <google-apps-manager@googlegroups.com> GAM Team <google-apps-manager@googlegroups.com>
Python 3.13.3 64-bit final Python 3.13.3 64-bit final
MacOS Sequoia 15.4.1 x86_64 MacOS Sequoia 15.4.1 x86_64
@ -65,7 +65,7 @@ MacOS High Sierra 10.13.6 x86_64
Path: /Users/Admin/bin/gam7 Path: /Users/Admin/bin/gam7
Version Check: Version Check:
Current: 5.35.08 Current: 5.35.08
Latest: 7.06.05 Latest: 7.06.07
echo $? echo $?
1 1
``` ```
@ -73,7 +73,7 @@ echo $?
Print the current version number without details Print the current version number without details
``` ```
gam version simple gam version simple
7.06.05 7.06.07
``` ```
In Linux/MacOS you can do: In Linux/MacOS you can do:
``` ```
@ -83,7 +83,7 @@ echo $VER
Print the current version of Gam and address of this Wiki Print the current version of Gam and address of this Wiki
``` ```
gam help gam help
GAM 7.06.05 - https://github.com/GAM-team/GAM GAM 7.06.07 - https://github.com/GAM-team/GAM
GAM Team <google-apps-manager@googlegroups.com> GAM Team <google-apps-manager@googlegroups.com>
Python 3.13.3 64-bit final Python 3.13.3 64-bit final
MacOS Sequoia 15.4.1 x86_64 MacOS Sequoia 15.4.1 x86_64