본문으로 건너뛰기
cccskills
무료GitHub에 공개

cloud-run-static-outbound-ip

Configure static outbound IP addresses for Google Cloud Run jobs/services. Use when: (1) External service needs to whitelist your IP (archive.org, APIs, firewalls), (2) Cloud Run requests appear from random/changing IPs, (3) Need consistent source IP for crawlers, scrapers, or API clients running on Cloud Run. Requires VPC connector + Cloud NAT + static IP reservation. Works for both Cloud Run services and jobs.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

연동 도구Google Cloud
설치 방법 보기

포함된 파일(1)

  • SKILL.md5.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Cloud Run Static Outbound IP Address

Problem

Cloud Run uses a shared pool of dynamic outbound IP addresses that change frequently and are shared across all Google Cloud customers. When external services need to whitelist your IP (for rate limit exemptions, firewall rules, or special access), you need a static, predictable outbound IP.

Context / Trigger Conditions

  • External service asks for IP address to whitelist
  • Cloud Run requests are being blocked by IP-based rate limiting
  • Need to identify your traffic to external APIs
  • Running crawlers/scrapers that need consistent source IP
  • Error messages about "IP not whitelisted" or similar

Solution

Architecture

Cloud Run → VPC Connector → VPC Network → Cloud NAT (static IP) → Internet

Step 1: Reserve Static IP Address

gcloud compute addresses create [NAME]-nat-ip \
  --region=[REGION] \
  --description="Static IP for Cloud Run outbound traffic"

# Get the actual IP address
gcloud compute addresses describe [NAME]-nat-ip \
  --region=[REGION] \
  --format="value(address)"

Step 2: Create Cloud Router

gcloud compute routers create [NAME]-router \
  --network=default \
  --region=[REGION]

Step 3: Create Cloud NAT with Static IP

gcloud compute routers nats create [NAME]-nat \
  --router=[NAME]-router \
  --region=[REGION] \
  --nat-external-ip-pool=[NAME]-nat-ip \
  --nat-all-subnet-ip-ranges

Step 4: Enable VPC Access API

gcloud services enable vpcaccess.googleapis.com

Step 5: Create Serverless VPC Access Connector

gcloud compute networks vpc-access connectors create [NAME]-connector \
  --region=[REGION] \
  --network=default \
  --range=10.8.0.0/28 \
  --min-instances=2 \
  --max-instances=3 \
  --machine-type=e2-micro

Note: The IP range must not conflict with existing subnets. Use a /28 CIDR block.

Step 6: Update Cloud Run to Use VPC Connector

For Cloud Run Jobs:

gcloud run jobs deploy [JOB-NAME] \
  --image=[IMAGE] \
  --region=[REGION] \
  --vpc-connector=[NAME]-connector \
  --vpc-egress=all-traffic \
  [... other flags ...]

For Cloud Run Services:

gcloud run deploy [SERVICE-NAME] \
  --image=[IMAGE] \
  --region=[REGION] \
  --vpc-connector=[NAME]-connector \
  --vpc-egress=all-traffic \
  [... other flags ...]

Critical: --vpc-egress=all-traffic is required to route ALL outbound traffic through the VPC/NAT. Without this, only traffic to internal IPs uses the connector.

Verification

Test that outbound traffic uses the static IP:

# Run a container that checks its external IP
gcloud run jobs execute [JOB-NAME] --region=[REGION] \
  --args="curl,-s,https://api.ipify.org"

Or add a test endpoint to your service that calls an IP echo service.

Example: Complete Setup Script

#!/bin/bash
set -e

PROJECT_ID="my-project"
REGION="us-central1"
NAME="my-crawler"

# Reserve static IP
gcloud compute addresses create ${NAME}-nat-ip --region=$REGION

# Get and display the IP
STATIC_IP=$(gcloud compute addresses describe ${NAME}-nat-ip \
  --region=$REGION --format="value(address)")
echo "Static IP: $STATIC_IP"

# Create router
gcloud compute routers create ${NAME}-router \
  --network=default --region=$REGION

# Create NAT
gcloud compute routers nats create ${NAME}-nat \
  --router=${NAME}-router \
  --region=$REGION \
  --nat-external-ip-pool=${NAME}-nat-ip \
  --nat-all-subnet-ip-ranges

# Enable API and create connector
gcloud services enable vpcaccess.googleapis.com
gcloud compute networks vpc-access connectors create ${NAME}-connector \
  --region=$REGION \
  --network=default \
  --range=10.8.0.0/28 \
  --min-instances=2 \
  --max-instances=3 \
  --machine-type=e2-micro

echo "Setup complete! Use these flags in Cloud Run deployments:"
echo "  --vpc-connector=${NAME}-connector"
echo "  --vpc-egress=all-traffic"
echo ""
echo "Static IP for whitelisting: $STATIC_IP"

Cost Considerations

  • Static IP: Free while in use, ~$7/month if reserved but unused
  • VPC Connector: ~$7-20/month (2-3 e2-micro instances minimum)
  • Cloud NAT: ~$1/month + $0.045/GB processed

Total: ~$10-30/month depending on traffic volume.

Notes

  • All Cloud Run instances/jobs using the same VPC connector share the static IP
  • You can scale Cloud Run horizontally without changing IPs
  • VPC connector has throughput limits (~200-1000 Mbps depending on instance count)
  • For high-throughput needs, increase max-instances on the connector
  • Cloud SQL connections don't need to go through NAT (use Cloud SQL connector instead)
  • The VPC connector adds ~1-5ms latency to requests

Cleanup

To remove the setup:

gcloud compute networks vpc-access connectors delete ${NAME}-connector --region=$REGION
gcloud compute routers nats delete ${NAME}-nat --router=${NAME}-router --region=$REGION
gcloud compute routers delete ${NAME}-router --region=$REGION
gcloud compute addresses delete ${NAME}-nat-ip --region=$REGION

References

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Fix ArgoCD ExternalSecret deployment failing with "namespace X is not permitted in project Y". Use when: (1) ExternalSecret shows OutOfSync in ArgoCD but won't sync, (2) ArgoCD application status shows "namespace X is not permitted in project 'infrastructure'", (3) ExternalSecret targets a namespace managed by a different ArgoCD project, (4) Using apps-of-apps pattern with separate infrastructure and application projects.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Art direction for any content — reads text, PDF, Word, HTML, PPT, then proposes 2-3 creative directions with photography style, mood, and visual language. After selection, generates AI image prompts and visual briefs section-by-section. Use when the user shares content and needs visual direction, image sourcing, or creative direction for any material.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix "Null check operator used on a null value" errors when an object is set to null during an async await. Use when: (1) Object reference is nullified while awaiting, (2) Code accesses object with ! after await returns, (3) Cancel/dispose operations run concurrently with async operations on same object. Solution: capture local reference before await.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Add custom metadata headers (x-amz-meta-*) to AWS v4 signed requests for GCS S3-compatible API. Use when: (1) Adding custom metadata to GCS uploads via S3 API, (2) Getting signature mismatch errors after adding new headers, (3) x-amz-meta-* headers being ignored or causing 403 errors. Custom headers MUST be included in canonical headers and signed headers list.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix password/secret authentication failures caused by trailing newlines when creating Google Cloud secrets (or similar) with bash here-strings. Use when: (1) Password authentication fails with correct password, (2) Secret created with `<<< "value"` syntax, (3) Error like "password authentication failed" or "invalid token" despite correct value. Bash here-strings (`<<<`) add a trailing newline that corrupts secrets.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

Fix silent video/media processing failures caused by URL extraction code that filters on file extensions (.mp4, .webm, .webp). Use when: (1) Media moderation, transcoding, or analysis silently skips files from Blossom or content-addressed storage servers, (2) URL extraction from Nostr event tags (imeta, r tags) drops URLs without recognized extensions, (3) CDN fallback URLs append .mp4 but the actual server uses extensionless content-addressed paths like /{sha256}. Common in Nostr video events (kind 34236) where different clients use different URL formats.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

divinevideo/divine-mobile2662026년 10월 19일 업데이트

divinevideo의 스킬 모두 보기

이 스킬의 문제 신고