Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Google Cloud Run?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ashish7802-google-cloud-run)
# Google Cloud Run Skill
> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18
> **Official Docs:** https://cloud.google.com/run/docs/authenticating/service-to-service
## Overview
Google Cloud Run executes stateless HTTP containers with automatic scale-to-zero and IAM-enforced service-to-service authentication via Google-signed OIDC Identity Tokens.
## Installation
```bash
npm install google-auth-library
```
## Authentication (Service-to-Service OIDC)
For private Cloud Run services (`--no-allow-unauthenticated`):
1. Grant the caller's service account the `roles/run.invoker` IAM role on the target service.
2. Fetch a Google-signed OIDC Identity Token whose `audience` is set to the **exact target Cloud Run service root URL** (e.g., `https://billing-service-xyz.a.run.app`) using `google-auth-library` (`auth.getIdTokenClient(targetAudience)`) or the GCP metadata server.
3. Pass `Authorization: Bearer <ID_TOKEN>`.
## Core Concepts
- **Container Contract**: Listen on `0.0.0.0` and `Number(process.env.PORT) || 8080`. Never hardcode port `3000` ignoring `PORT`.
- **Graceful Shutdown (`SIGTERM`)**: Cloud Run sends `SIGTERM` and allows up to 10 seconds to drain in-flight requests and flush logs/DB connections before `SIGKILL`.
- **CPU Allocation**: Background async work after returning an HTTP response is throttled unless CPU is configured as always-allocated (`--no-cpu-throttling`).
## Error Handling & Rate Limits
- Retry transient `503` cold-start / scaling responses with jittered backoff.
- Use `gcloud run services proxy` for authenticated local testing against private services instead of opening them to `allUsers`.
## Security Best Practices
- Assign a dedicated least-privilege runtime service account per Cloud Run service (never use the overly broad Compute Engine default service account).
- Mount secrets via Google Secret Manager integration instead of committing secrets in container images.
## AI Pitfalls
- Sending an OAuth2 Access Token instead of an OIDC **Identity Token** with `audience = targetServiceUrl` (results in HTTP `401`/`403`).
- Binding HTTP servers to `localhost`/`127.0.0.1` instead of `0.0.0.0`, causing Cloud Run startup health checks to fail.
- Spawning fire-and-forget promises after sending the HTTP response with default request-based CPU throttling.
## Production Checklist
- [ ] Server binds to `0.0.0.0` on `process.env.PORT || 8080`
- [ ] `SIGTERM` handler closes HTTP server and flushes connections cleanly
- [ ] Private service callers hold `roles/run.invoker` and send OIDC ID tokens with exact target URL audience
- [ ] Dedicated least-privilege runtime service account attached
## References
- [Cloud Run Service-to-Service Auth](https://cloud.google.com/run/docs/authenticating/service-to-service)
- [Cloud Run Container Runtime Contract](https://cloud.google.com/run/docs/container-contract)
## Related skills
- [`docker`](../docker/SKILL.md) — depends on
- [`google-cloud-storage`](../google-cloud-storage/SKILL.md) — works well with
- [`google-maps-platform`](../google-maps-platform/SKILL.md) — works well with