GCP Vertex AI Service Agent access to GCR image Error - google-cloud-platform

I am getting the below error.
Does anyone have any idea how to solve it?
Failed to create pipeline job. Error: Vertex AI Service Agent
'XXXXX#gcp-sa-aiplatform-cc.iam.gserviceaccount.com' should be granted
access to the image gcr.io/gcp-project-id/application:latest

{PROJECT_NUMBER}#gcp-sa-aiplatform-cc.iam.gserviceaccount.com is google's AI Platform service agent.
This Service agent requires access to read/pull the docker image from your project's gcr to create container for pipeline run.
If You have permission to edit IAM roles, You can try adding Artifact Registry roles to the above service agent.
You can start with adding roles/artifactregistry.reader.
Hope this helps :)

This error may have occurred due to missing roles or permissions for pulling and pushing images into Container Registry. All the users and service accounts must be given appropriate permissions for Cloud Storage who interact with Container Registry. You can give roles/storage.objectViewer, roles/storage.legacyBucketWriter and roles/storage.admin to your service account to access your image in Container Registry using the service-account. You can follow this doc for giving appropriate roles and permissions to the Service Account.

Related

GCP cloud build: CLOUD_BUILD_UNAVAILABLE

I try to run cloud deploy on existing project where also run Cloud Build and
I have the following error:
targetRenders:
qsdev:
failureCause: CLOUD_BUILD_UNAVAILABLE
renderingState: FAILED
I try to use this article when I try to run a cloud deploy on a new empty project everything works as expected.
I understand that the problem is with the permissions but can’t find where exactly.
I used this help
What could be the problem?
As shown in the FailureCause documentation, this error is caused by insufficient permissions.
CLOUD_BUILD_UNAVAILABLE: Cloud Build is not available, either because it is not enabled or because Google Cloud Deploy has insufficient permissions. See Required permission.
In the required permission documentation, it shows some troubleshoot steps to follow in order to ensure that the correct permissions are set:
The service account used for rendering configurations must have sufficient permissions to access the Cloud Storage bucket where your Google Cloud Deploy resources are stored (delivery pipelines, releases, rollouts).
The role roles/clouddeploy.jobRunner includes all permissions the render service account (privatePool or defaultPool) needs.
The service account used for deploying must have sufficient permissions to deploy to the target cluster, and permission to access the Cloud Storage bucket.
Note: If you use a custom Cloud Storage bucket, you can put it anywhere. (It doesn't need to be in the same region, for example, as the delivery pipeline.)
The service account that calls Google Cloud Deploy to create a release must have the clouddeploy.releaser role. It must also have the iam.serviceAccount.actAs permission to use the service account that renders manifests (for example through the roles/iam.serviceAccountUser role).
The service account that calls Google Cloud Deploy to promote a release or create a rollout must have the iam.serviceAccount.actAs permission to use the service account that deploys to targets.

IAM issue with Google Cloud Run service account

I am trying to deploy my AutoML trained model using Cloud Run, but am having difficulties with IAM permissions. I'm using this as a guide, and keep getting the following error at the build step. I'm new to Cloud Run/GCP but as far as I can see, I have granted the right roles to the right accounts. I appreciate any assistance you can provide as I'm really stumped.
Error message:
Step #3: ERROR: (gcloud.run.deploy) User [REDACTED#cloudbuild.gserviceaccount.com] does not have permission to access namespaces instance [REDACTED] (or it may not exist):
Google Cloud Run Service Agent does not have permission to get access tokens for the service account REDACTED#cloudbuild.gserviceaccount.com.
Please give service-REDACTED#serverless-robot-prod.iam.gserviceaccount.com permission iam.serviceAccounts.getAccessToken on the service account.
Alternatively, if the service account is unspecified or in the same project you are deploying in, ensure that the Service Agent is assigned the Google Cloud Run Service Agent role roles/run.serviceAgent.
Here are the roles assigned to the Cloud Run Service Agent
Default service account has the Cloud Run Admin Role
Here are the accounts to which I've given access to the Default compute service account, the Cloud Build Service Agent and Cloud Run Service Agent are added:

Permission problem when deploying Cloud Run service to GCP

ERROR: (gcloud.run.deploy) User [my#email.com] does not have permission to access namespaces instance [my-project] (or it may not exist): Google Cloud Run Service Agent does not have permission to get access tokens for the service account 112233445566-compute#developer.gserviceaccount.com. Please give service-112233445566#serverless-robot-prod.iam.gserviceaccount.com permission iam.serviceAccounts.getAccessToken on the service account. Alternatively, if the service account is unspecified or in the same project you are deploying in, ensure that the Service Agent is assigned the Google Cloud Run Service Agent role roles/run.serviceAgent.
For a non-GCP savvy, what should I enable exactly? I added Access Creator Token to all relevant service accounts and it didn't help. I followed all suggestions from other similar questions and nothing worked.
How come it's so complex to enable something like that?
Thank you

Cloud build service account permission to build

I have my env set as Cloud build app (Github app) to provision terraform through cloud build
to Google Cloud Platform. The build is a simple cloud composer with cloud functions, that creates these resources along with the right service accounts and members.
However, only the owner permission can execute this successfully, I want to have least privilege for the cloud build service account. I have used a lot of roles and nothing seems to be successful. i.e. create service account, editor, access context manager admin, access approval approver. When I run the build via github commit, I receive this error other than having the owner set as role
Error: Error applying IAM policy for cloudfunctions cloudfunction
googleapi: Error 403: Permission
Error: Batch "iam-project-redacted modifyIamPolicy" for request
"Create IAM Members roles/composer.worker
serviceAccount:composer-env-account#redacted.iam.gserviceaccount.com
for \"project \\"redacted\\"\"" returned error: Error applying IAM
policy for project "redacted": Error setting IAM policy for project
"redacted": googleapi: Error 403: The caller does not have permission,
forbidden. To debug individual requests, try disabling batching:
https://www.terraform.io/docs/providers/google/guides/provider_reference.html#enable_batching
Is there a IAM policy/role that allows for service accounts to successfully build through cloud build?
With Owner role set to cloudbuild service account, everything build successfully
The Cloud Build service account has assigned by default the Cloud Build Service Account role which has the permissions referred here. Notice that you'll only be limited to perform the following tasks: which include doing the pertinent activities in order to make a build successful (accessing Cloud Source Repository, Cloud Storage and Container Registry).
Along with the Cloud Build Service Account role, you'll need to grant additional roles depending on what else you are doing with Cloud Build.
In the particular case of your error message you'll need to add the Cloud Functions Developer role in order to be able to get full access to Cloud Functions. The whole procedure is documented here.
There are similar roles if you are also deploying to App Engine, or managing Google Kubernetes Engine, etc. Find all the list of available roles here.

GCR service account has admin privileges

Cannot use more granular roles to google managed container registry account - service-[PROJECT_NUMBER]#containerregistry.iam.gserviceaccount.com. Not sure if anyone can shed some lights on this.
It seems this service account is assigned with a primitive role "editor" by default when you enable google container registry API and you cannot change it to something more granular like cloudbuild.gserviceaccount.com
Google's doc on cloudbuild
https://cloud.google.com/cloud-build/docs/securing-builds/set-service-account-permissions
But not much info on container registry
https://cloud.google.com/container-registry/docs/overview
Our compliance tool picked up editor role are used by GCR service account. This is too much permission for just GCR access.