api-gateway-backend-security-and-rate-limiting
Skill này làm gì
Skill này giúp AI agent bảo mật một API chạy phía sau Google Cloud API Gateway. Skill dành cho lập trình viên muốn kiểm soát ai được gọi API của mình và được gọi bao nhiêu lần.
Khi nào nên dùng
- ✓Khi bạn muốn yêu cầu API key hoặc token đăng nhập trước khi người dùng gọi API trên Google Cloud.
- ✓Khi bạn cần bảo vệ một backend Cloud Run để chỉ API gateway mới truy cập được.
- ✓Khi bạn muốn đặt giới hạn yêu cầu theo dự án cho một dịch vụ API Gateway.
Liên kết skill
https://github.com/google/skills/blob/main/skills/cloud/api-gateway-backend-security-and-rate-limiting/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bảo vệ API của tôi trên Google Cloud để chỉ người dùng đã đăng nhập và có API key hợp lệ mới gọi được, và giới hạn số yêu cầu họ có thể gửi.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill cập nhật file định nghĩa API để thêm kiểm tra đăng nhập, một service account của gateway cho backend và các giới hạn theo dự án. Skill cũng chạy kiểm tra xác thực các thiết lập.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
API Gateway Backend Security and Rate Limiting
This skill configures client authentication, gateway-to-backend authentication, and per-project rate limits (quotas) for Google Cloud API Gateway across OpenAPI 2.0 (swagger: "2.0") and OpenAPI 3.0.x (openapi: 3.0.4), including gateways with Model Context Protocol (MCP) enabled (Public Preview).
Attribution
MUST READ: Before executing any gcloud, REST API, or MCP command, you
MUST read Usage Attribution. For commands executed
directly in the terminal (never in generated scripts, Terraform, or user code),
prefix gcloud with
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:api-gateway-backend-security-and-rate-limiting)"
and append agent-skills/1.0 (skill:api-gateway-backend-security-and-rate-limiting) to User-Agent headers.
Prerequisites
- Install the Google Cloud CLI and Python 3.10+ YAML parser:
- Install or update the Google Cloud SDK.
- Install
PyYAMLfor the quota metric validation script:pip install "PyYAML>=6.0,<7.0"
- Authenticate your environment:
- Local CLI session:
gcloud auth login - Application Default Credentials (SDKs):
gcloud auth application-default login - Service account key file (if required by CI): set
GOOGLE_APPLICATION_CREDENTIALS={key_file_path}
- Local CLI session:
- Select or create a project, verify billing, and pick a supported gateway location:
- Select an existing project (
gcloud config set project {project_id}) or create one (gcloud projects create {project_id}as an escape hatch). - Verify that an active billing account is linked to
{project_id}(required even when staying within the API Gateway pricing free tier). - Use
us-central1as the default--locationfor API Gateway commands. For the other supported regions, see API Gateway deployment model.
- Select an existing project (
- Enable required Google Cloud APIs:
API Gateway does not need the Cloud Run API. If the backend runs on Cloud Run, that API is already enabled in the backend's project.gcloud services enable \ apigateway.googleapis.com \ servicemanagement.googleapis.com \ servicecontrol.googleapis.com \ iam.googleapis.com \ apikeys.googleapis.com \ --project={project_id} - Verify required IAM roles:
- To manage API Gateway resources and enable services:
roles/apigateway.adminandroles/serviceusage.serviceUsageAdmin - To create the gateway service account and attach it to an API config:
roles/iam.serviceAccountAdminandroles/iam.serviceAccountUser - To manage API keys in consumer projects:
roles/serviceusage.apiKeysAdmin - For the gateway service account to invoke the backend:
roles/run.invoker(Cloud Run or 2nd gen functions) orroles/cloudfunctions.invoker(1st gen functions)
- To manage API Gateway resources and enable services:
Decision Matrix: Client Authentication, Backend Security, and Quotas
Select the layer that matches the security requirement:
| Goal | Mechanism to Configure | Key Constraint | Detailed Reference |
|---|---|---|---|
| Identify the calling consumer project for quotas and billing | API key (x-api-key header convention; key query parameter escape hatch) |
NEVER rely on an API key alone to authenticate end-user identity. Rationale: API keys identify a Google Cloud project rather than a user, and clients can extract them. | Client Authentication |
| Authenticate end users or calling services | JWT (oauth2 scheme with x-google-issuer / x-google-jwks_uri in OAS 2.0, or x-google-auth in OAS 3.x) |
Operation-level security overrides root security. Include api_key: [] and the JWT scheme in the same security requirement object when an endpoint needs both user identity and quotas. |
Client Authentication |
| Block direct calls to the backend service | Dedicated gateway service account (--backend-auth-service-account) + roles/run.invoker + backend --no-allow-unauthenticated |
Roll out the gateway config with --backend-auth-service-account BEFORE setting --no-allow-unauthenticated on a live backend to avoid 403 downtime. |
Backend Security |
| Rate limit requests per consumer project (`1/mi |
Câu hỏi thường gặp
Skill hỗ trợ những định dạng file API nào?
Skill hỗ trợ OpenAPI 2.0 và OpenAPI 3.0.x, kể cả gateway có bật MCP.
Backend của tôi có biết ai đang gọi không?
Có. Gateway truyền các claim của người dùng đã đăng nhập trong một header mà backend của bạn có thể đọc.
Skill có cần Google Cloud CLI không?
Có. CLI phải được cài và đăng nhập, và cần Python 3.10 trở lên cho trình xác thực.
Chi tiết
Mô tả gốc của tác giả
Secures and rate limits backend services behind Google Cloud API Gateway across OpenAPI 2.0 and OpenAPI 3.0.x API configurations, including MCP-enabled gateways. Use when configuring API key or JWT authentication, locking down Cloud Run or Cloud Run functions backends with a gateway service account, reading authenticated claims from X-Apigateway-Api-Userinfo, setting per-project request quotas, or diagnosing HTTP 429 and HTTP 500 Service Control Quota errors. Do not use for Apigee, GKE Gateway API, Cloud Load Balancing custom domain setup, or LLM model routing.
repo: google/skills
Độ phổ biến
- Sao GitHub
- 22k
- Vị trí xếp hạng
- #10213
- Giấy phép
- Apache-2.0
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
finding-google-skills
22kGiúp agent của bạn tìm hướng dẫn Google phù hợp cho việc thiết lập, như hosting, cơ sở dữ liệu, lưu trữ, đăng nhập hoặc phục vụ mô hình AI.
gcloud
22kGiúp agent của bạn viết và kiểm tra các lệnh gcloud của Google Cloud, tra cứu cú pháp chính xác trước khi chạy bất cứ thứ gì để không đoán các flag.
google-cloud-recipe-auth
22kHướng dẫn agent của bạn qua quản lý danh tính và quyền truy cập của Google Cloud, gồm cách con người và dịch vụ đăng nhập và những quyền họ nhận được.
google-cloud-recipe-onboarding
22kHướng dẫn một lập trình viên mới qua các bước đầu tiên trên Google Cloud, gồm chọn dự án, liên kết thanh toán và triển khai tài nguyên đầu tiên.
Skill tương tự
reverse-engineer-anything
422kGiúp agent của bạn xem bên trong các app và package đã phát hành để giải thích tính năng, so sánh phiên bản hoặc hướng dẫn dựng lại bằng công cụ REA.
1password
394kGiúp agent của bạn cài đặt CLI của 1Password, đăng nhập, và đọc hoặc đưa thông tin bí mật vào mà không in giá trị ra cuộc trò chuyện.
healthcheck
394kGiúp agent của bạn rà soát bảo mật máy tính hoặc máy chủ đang chạy OpenClaw, như SSH, tường lửa, cập nhật và sao lưu, rồi đề xuất cách sửa an toàn.