Skip to content
Back to skills

Google Cloud Run

ASecurity

> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18 > **Official Docs:** https://cloud.google.com/run/docs/authenticating/service-to-service

  • 13 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
ai-agentsgobashdockergcptestingsecurity

Works with

  • cli

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 2 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add ashish7802/awesome-api-skills --skill google-cloud-run --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Google Cloud Run?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Google Cloud Run
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ashish7802-google-cloud-run/badge)](https://www.skillsdirectory.com/skills/ashish7802-google-cloud-run)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 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

Files in this skill

  • SKILL.md3 KB
  • examples/quickstart.ts745 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.