unable to access secrets from correct projects

We have added new secrets in our code and in cloudbuild.yaml mentioning same as other secrets

  • ‘–update-secrets=secretname=projects/${_SECRET_PROJECT_NUMBER}/secrets/secretname:latest’
  • ‘–region=${_LOCATION}’
    It is trying to access secrets from the project where my cloud build and source repo is there not from
    _SECRET_PROJECT_NUMBER and giving below error.

com.google.api.gax.rpc.PermissionDeniedException: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Permission ‘secretmanager.versions.access’ denied for resource ‘projects/cloudbuildproj/secrets/secretname/versions/latest’ (or it may not exist).

FYI Other secrets working fine

Hi @Monalisa123 ,

Welcome to the Google Cloud Community!

Are these secrets located within the same project where you’re experiencing the error?

It’s possible that the secret is being referenced incorrectly in ${_SECRET_PROJECT_NUMBER}. Could you try entering the project number directly instead?

Also, kindly check that the service account has the appropriate roles, specifically the secretmanager.secretAccessor and secretmanager.viewer roles. You may view this Stack Overflow thread for further solutions.

Let me know if it worked so we can troubleshoot further. Thank you.