Greetings Everyone,
"I’m encountering a ‘403 Permission Denied’ error when attempting to create a new serviceAccountKey using a Cloud Function in Python 3.7. The error message I’m receiving is as follows:
googleapiclient.errors.HttpError:
<HttpError 403 when requesting https://iam.googleapis.com/v1/projects/*/serviceAccounts/@iam.gserviceaccount.com/keys?alt=json
returned "Permission 'iam.serviceAccountKeys.create' denied on resource (or it may not exist).".
Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'IAM_PERMISSION_DENIED', 'domain': 'iam.googleapis.com', 'metadata': {'permission': 'iam.serviceAccountKeys.create'}}]">
Pub/Sub topic is used for triggering this function and here’s the relevant part of the code I’m using:
iam_service = googleapiclient.discovery.build('iam', 'v1')
response = iam_service.projects().serviceAccounts().keys().create(name='projects/%s/serviceAccounts/%s' % (project_id,service_account_email_id), body=key_body).execute()
Can anyone provide guidance on how to address this “Iam Permission Denied” error when attempting to create a Service Account Key with a default service account that has the “Service Account Key Admin” role? Are there any additional steps or considerations I might be missing? Your insights and help would be greatly appreciated!