Hi Community,
I’m facing a persistent and baffling issue accessing a private Cloud Run service and would appreciate any insights, as I seem to have exhausted the standard troubleshooting paths.
Goal: Successfully invoke a deployed private Cloud Run service (requires authentication) using my authenticated Google Cloud user account via standard methods like curl with a gcloud access token.
Problem: After deploying the Cloud Run service configured to require authentication, attempts to access the service URL fail:
-
Browser Access: When logged into Google (tested in Incognito window), accessing the service URL results in 403 Forbidden.
-
curl with Access Token: Running the following commands in gcloud (authenticated):
Consistently results in a 401 Unauthorized response page with the text “Error: Forbidden Your client does not have permission to the requested URL / from this server.”
Troubleshooting Steps Performed:
- Deployment: Confirmed services deploy successfully via gcloud run deploy … without the --allow-unauthenticated flag (answered ‘N’ to the prompt). Container logs show successful startup.
- IAM run.invoker Role: Confirmed via gcloud run services get-iam-policy my-cloud-run-service --region=us-east1 that user definitively has the roles/run.invoker role granted on the service.
- Unauthenticated Access: Confirmed that attempting --allow-unauthenticated fails with a FAILED_PRECONDITION error, indicating an Organization Policy correctly prevents public access via allUsers. This is expected.
- IAP: Confirmed via Cloud Console (Service → Security tab) that Identity-Aware Proxy (IAP) is Disabled for the service.
- IAM Deny Policies: Granted my user the roles/iam.denyReviewer at the Org level and confirmed no Deny Policies exist at Org/Folder/Project levels that would block run.services.invoke or target my user/service.
- Organization Policies: Checked effective policies for the project:
- constraints/run.allowedIngress: Confirmed this is Inactive / Inheriting, likely defaulting to allow-all traffic.
- Reviewed other Org Policies; none seemed likely to block authenticated access.
- VPC Service Controls: Confirmed via Cloud Console (Security → VPC Service Controls) that the project is not part of any VPC-SC perimeter.
- Test Container: Deployed Google’s standard us-docker.pkg.dev/cloudrun/container/hello container to a new private service (test-hello-service), granted run.invoker to my user, and tested via curl with access token → Still resulted in 401 Unauthorized. This rules out issues with my specific application/container.
- Service Recreation: Completely deleted my-cloud-run-service using gcloud run services delete and redeployed it (privately); the 401 Unauthorized issue persists on the recreated service.
- Identity Token Attempt: Briefly attempted using OIDC Identity Tokens, but ran into separate issues generating them (Invalid account Type error for user, NOT_FOUND / PERMISSION_DENIED issues when trying to set up SA impersonation, possibly due to inconsistent Cloud Build SA state).
Summary: Despite confirming the necessary run.invoker IAM role is present for my user, and ruling out standard blockers like IAP, Deny Policies, Org Policy ingress restrictions, and VPC-SC, authenticated requests using standard gcloud access tokens are consistently failing with 401 Unauthorized at the Cloud Run infrastructure level (logs confirm “request was not authenticated”).
Question: Given this extensive troubleshooting, what other configurations, policies (perhaps less common Org Policies?), or potential environmental factors within Google Cloud could be causing this consistent 401 Unauthorizedresponse for authenticated users who demonstrably possess the run.invoker role? We do not have a paid support plan to open a direct technical case.
Any suggestions for further investigation would be extremely helpful!
Thank you.