Updated Nov 23, 20265 min read

Cloud Run "Permission denied on secret": How to Fix It

Why a Cloud Run deploy or revision fails with Permission denied on secret, which service account needs the Secret Manager Secret Accessor role, how to grant it at the right level, and the version and startup rules that cause the same error by other routes.

Illustration for Cloud Run "Permission denied on secret": How to Fix It

The error appears when you deploy a revision that references a Secret Manager secret and the revision's service account is not allowed to read it. The message starts with "Permission denied on secret" and names the secret version and the service account that was refused.

The fix is one IAM binding, and most of the time spent on this error goes into finding which service account needs it.

Why does Cloud Run reject the revision?

Per the Cloud Run secrets documentation, checked on November 23, 2026, Cloud Run checks every secret a service uses during deployment, to confirm the service account that runs the container can access it. A revision whose account lacks the permission fails to deploy, before any instance starts, so you see it in the deploy output and not in the application logs.

The same page describes how secrets behave at runtime. A secret exposed as an environment variable is retrieved before the instance starts, and if retrieval fails the instance does not start. A secret mounted as a volume is not checked at startup, and reads fail later if the secret becomes inaccessible. Which one you chose decides whether the failure is loud or silent.

How do you fix it?

Find the account the service runs as, then grant it the Secret Manager Secret Accessor role on the secret.

# Which service account does the service run as? gcloud run services describe api --region=europe-west1 \ --format='value(spec.template.spec.serviceAccountName)' # Grant read access on this one secret gcloud secrets add-iam-policy-binding stripe-key \ --member="serviceAccount:api-runtime@my-project.iam.gserviceaccount.com" \ --role="roles/secretmanager.secretAccessor"

If the first command prints nothing, the service uses the default Compute Engine service account, which is the account most people forget to grant. The better fix is a dedicated service account per service, created and named in the deploy command with --service-account, so the grant is deliberate.

Grant the role on the secret and not on the project. Per the Secret Manager access control documentation, a grant at the project level gives access to every secret in the project, a folder grant reaches every project in the folder, and the secret-level grant reaches only that secret. Note that roles/editor and roles/viewer do not include secretmanager.versions.access, so a service account with broad project roles can still be refused.

Which other causes look the same?

The wrong secret path or version. A typo in the secret name or a version that was disabled or destroyed fails differently from a permission error, but both stop the revision from starting, so check gcloud secrets versions list before changing IAM.

latest in an environment variable. Environment variables are resolved at instance startup, so a service that references latest picks up a new version only when an instance starts, and Google recommends pinning a version for that reason. A rotation then needs a new revision, and rolling back means pointing at the old version number.

A network perimeter. If the project uses VPC Service Controls or firewall rules, egress to secretmanager.googleapis.com has to be allowed, per the Cloud Run troubleshooting guide. This one appears as a start failure with a timeout, and not as a permission message.

Another project. A secret in a different project needs the binding in that project, and the Secret Manager API enabled for the project that owns the service.

How does Encore handle secret access on Cloud Run?

Encore brings infrastructure from code, and a secret is declared in the service that uses it. Per the GCP infrastructure docs, Encore provisions an IAM role for the service, or a service account on GCP, secrets are injected as environment variables from Secret Manager, and that account is granted permission to read them, so there is no binding to find or write by hand.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

A payments service that reads one secret, with no IAM binding to write:

// payments/payments.ts import { api, APIError } from "encore.dev/api"; import { secret } from "encore.dev/config"; const stripeKey = secret("StripeSecretKey"); interface RefundRequest { paymentIntent: string; } // Internal only: the admin service calls this after checking the operator role and the order. export const refund = api( { expose: false, method: "POST", path: "/refunds" }, async ({ paymentIntent }: RefundRequest): Promise<{ id: string; status: string }> => { if (!/^pi_[A-Za-z0-9]+$/.test(paymentIntent)) throw APIError.invalidArgument("invalid payment intent"); const resp = await fetch("https://api.stripe.com/v1/refunds", { method: "POST", headers: { Authorization: `Bearer ${stripeKey()}`, "Content-Type": "application/x-www-form-urlencoded", "Idempotency-Key": `refund-${paymentIntent}`, }, body: new URLSearchParams({ payment_intent: paymentIntent }), }); if (!resp.ok) throw APIError.unavailable("refund failed"); return (await resp.json()) as { id: string; status: string }; }, );

Set the value with encore secret set --type prod StripeSecretKey, as described in the secrets docs. A deploy fails when a declared secret has no value, which turns a startup failure on Cloud Run into an error before any revision is created, and secret values are not stored in the repo, so an AI coding agent working in it can see the names but not the values. Locally, a missing secret produces a warning when encore run starts the service.

To deploy, connect your GCP project as described in Connect your cloud account and push with git push encore.

A coding agent that adds a new provider key declares it next to the code that calls it, and the Cloud Run side needs no IAM change from the agent or from you.

Best fit: Teams on Cloud Run that keep hitting secret permission errors when they add services or keys and want access granted per service from the code.

What should you check first?

Read the service account named in the error message, grant it the role on that one secret, and redeploy. If the error persists, compare the project and secret path in the message with what the service references.

Frequently asked questions

What does Permission denied on secret mean in Cloud Run?

The service account that runs the revision is not allowed to read the secret version it references. Cloud Run checks this at deploy time, so the revision is rejected before any instance starts.

Which role does Cloud Run need to read a secret?

The service account that runs the container needs Secret Manager Secret Accessor (roles/secretmanager.secretAccessor) on the secret. Grant it on that single secret rather than the whole project, since a project-level grant gives access to every secret in it.

Why does the service work in the console but fail in gcloud or Terraform?

The revision may run as a different service account, usually the default Compute Engine one, than the one you granted access to. Check the service account on the service with gcloud run services describe and grant the role to that account.

How do I give each service access to only its secrets on Cloud Run?

Encore provisions an IAM role for the service, or a service account on GCP, and secrets declared in code are injected from Secret Manager with read access granted to that account by the platform. A deploy fails with a clear message when a declared secret has no value.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders