The problem with Cloud Run and static IPs
Google Cloud Run services, functions, and jobs use dynamic outbound IP addresses by default. Requests use a shared IP pool; the source IP is not guaranteed to stay fixed. If the API or database you're calling requires IP allowlisting, that's immediately a problem.
The official Google solution is to connect your Cloud Run service to a VPC using Direct VPC egress or a Serverless VPC Access connector, route all outbound traffic into that VPC, and configure Cloud NAT with reserved static IPs. See Google's static outbound IP guide. It works, but Google documents startup delays with Direct VPC egress, including when Cloud NAT is involved.
This post explains those documented delays, what the native options do, and how a proxy-based approach can simplify static egress for your API calls.
Why Cloud Run with Cloud NAT can time out at startup
Cloud NAT is designed for outbound connections and supports their response traffic. It does not allow unsolicited inbound connections. A new outbound connection establishes the translation needed for its replies; a cold start does not inherently leave return packets without a mapping. See Google's Cloud NAT overview.
There are real startup caveats. Google's Direct VPC egress limitations describe connection-establishment delays of a minute or more at instance startup. With Cloud NAT, Google also documents cold-start delays of 30 seconds or more and recommends considering a Serverless VPC Access connector with Cloud NAT for better startup performance.
If requests fail mainly on startup, Google recommends an HTTP startup probe that checks a real egress destination, with retries in the check or suitable probe thresholds. Use bounded retries for transient failures; retry writes only when the operation is safe to repeat or uses an idempotency key.
For failures after startup, check routing, firewall rules, the destination's allowlist, and NAT capacity. Google documents port exhaustion and allocation-related packet drops. Removing NAT changes the network path; success on that different path does not by itself identify the cause.
The native inbound option: Serverless NEG and a Load Balancer
For inbound traffic, Google's approach involves a Serverless Network Endpoint Group (NEG) fronted by an external Application Load Balancer with a reserved static external IP. This gives external systems a stable destination for requests to your service. It does not give Cloud Run a static source IP for outbound API calls. See Google's serverless load balancer setup.
It also involves creating a load balancer, a backend service, a URL map, a target HTTPS proxy, a global forwarding rule, and an SSL certificate. If you need to prevent direct internet access to the service, configure Cloud Run ingress to accept internal traffic and Cloud Load Balancing.
For teams that already need a load balancer for inbound traffic, this setup makes sense. For teams that just want their Cloud Run function to call an external API from a known IP, use Cloud NAT or an outbound proxy instead.
The proxy approach
A simpler path is to route outbound requests through a static IP proxy. Your Cloud Run application connects to the proxy, which exits to the internet from its assigned static IPs. On Cloud Run's default internet egress path, this needs no VPC or load balancer setup. It avoids the Direct VPC/Cloud NAT startup path, but does not eliminate application cold starts or every possible timeout.
QuotaGuard is built specifically for this use case. You set an environment variable with your proxy URL, update your HTTP client to use it, and those requests come from static IPs you can share with your API vendor or firewall administrator. Raw database connections need a compatible SOCKS5 client or tunnel; the HTTP examples below cover HTTPS APIs.
Setup
After signing up, copy your HTTP URL and assigned IPs from Subscription Setup > Outbound Proxy > Connection Information. A QuotaGuard Static URL has this format:
http://username:password@<your-quotaguard-proxy-host>:9293
Your application reads this environment variable (illustrative format):
QUOTAGUARDSTATIC_URL=http://username:password@<your-quotaguard-proxy-host>:9293
Create a Secret Manager secret named quotaguard-static-url containing only the URL. In Cloud Run, use Containers > Variables and Secrets > Reference a secret to expose it as QUOTAGUARDSTATIC_URL. Pin a numeric version and grant the runtime service account Secret Accessor on that secret. If replacing a plain environment variable, remove its old entry before adding the secret reference.
Alternatively, after creating the secret in the console, deploy via CLI. Replace the uppercase placeholders with your project, runtime account, application image, and region; use your secret version (shown as 1):
gcloud secrets add-iam-policy-binding quotaguard-static-url \
--project=PROJECT_ID \
--member=serviceAccount:SERVICE_ACCOUNT_EMAIL \
--role=roles/secretmanager.secretAccessor
gcloud run deploy my-service \
--project=PROJECT_ID --region=REGION \
--image=IMAGE_URL --service-account=SERVICE_ACCOUNT_EMAIL \
--update-secrets=QUOTAGUARDSTATIC_URL=quotaguard-static-url:1
Keep credentials out of source, command arguments, and logs. Static tunnels destination HTTPS through CONNECT; proxy credentials use a plain HTTP hop. Shield encrypts that hop with compatible clients. An existing all-traffic VPC route still applies to connections to the proxy.
Integrate these outbound clients into your Cloud Run application and replace the example API URL. The IP test below uses a real endpoint.
Python
Install with python3 -m pip install requests. Configure both URL schemes, timeouts, and HTTP error handling:
import os
import requests
proxy_url = os.environ["QUOTAGUARDSTATIC_URL"].strip()
if not proxy_url:
raise ValueError("QUOTAGUARDSTATIC_URL is empty")
proxies = {"http": proxy_url, "https": proxy_url}
with requests.Session() as session:
session.trust_env = False
response = session.get(
"https://api.example.com/endpoint",
proxies=proxies, timeout=(10, 30),
)
response.raise_for_status()
print(response.status_code)
Node.js
Install npm install axios@1 https-proxy-agent@7 and save as request.cjs. The async function supports CommonJS; proxy: false lets the explicit agent handle proxying. Redirects are disabled in this HTTPS example.
const axios = require("axios");
const { HttpsProxyAgent } = require("https-proxy-agent");
async function main() {
const proxyUrl = process.env.QUOTAGUARDSTATIC_URL?.trim();
if (!proxyUrl) throw new Error("QUOTAGUARDSTATIC_URL is required");
const agent = new HttpsProxyAgent(proxyUrl);
const response = await axios.get("https://api.example.com/endpoint", {
httpsAgent: agent,
proxy: false,
timeout: 30000,
maxRedirects: 0,
});
console.log(response.status);
}
main().catch(() => {
console.error("Proxied request failed; check configuration and destination");
process.exitCode = 1;
});
Go
Save as main.go; run go run main.go. The transport uses the URL's proxy credentials. Check errors before accessing the body:
package main
import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"strings"
"time"
)
func main() {
proxyStr := strings.TrimSpace(os.Getenv("QUOTAGUARDSTATIC_URL"))
proxyURL, err := url.Parse(proxyStr)
if err != nil || proxyURL.Hostname() == "" || proxyURL.Scheme != "http" {
log.Fatal("QUOTAGUARDSTATIC_URL must be a valid Static HTTP proxy URL")
}
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.Proxy = http.ProxyURL(proxyURL)
client := &http.Client{Transport: transport, Timeout: 30 * time.Second}
resp, err := client.Get("https://api.example.com/endpoint")
if err != nil {
log.Fatal("Proxied request failed; check configuration and destination")
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
log.Fatalf("Unexpected HTTP status: %d", resp.StatusCode)
}
fmt.Println(resp.StatusCode)
}
Java
Save as Main.java (JDK 11+). An authenticator supplies credentials only to the configured proxy. OpenJDK disables Basic CONNECT authentication by default; run java -Djdk.http.auth.tunneling.disabledSchemes= Main.java to permit it for this JVM. Use this Static configuration only where plain HTTP proxy authentication is acceptable. See the JDK property reference and default restriction.
import java.net.*;
import java.net.http.*;
import java.time.Duration;
public class Main {
public static void main(String[] args) throws Exception {
String proxyUrl = System.getenv("QUOTAGUARDSTATIC_URL");
if (proxyUrl == null || proxyUrl.isBlank()) {
throw new IllegalStateException("QUOTAGUARDSTATIC_URL is required");
}
URI proxy = URI.create(proxyUrl.trim());
if (!"http".equals(proxy.getScheme()) || proxy.getHost() == null
|| proxy.getPort() < 1 || proxy.getUserInfo() == null) {
throw new IllegalArgumentException("Use the Static HTTP proxy URL");
}
String[] credentials = proxy.getUserInfo().split(":", 2);
if (credentials.length != 2) {
throw new IllegalArgumentException("Proxy username and password required");
}
Authenticator auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType() == RequestorType.PROXY
&& proxy.getHost().equalsIgnoreCase(getRequestingHost())
&& proxy.getPort() == getRequestingPort()) {
return new PasswordAuthentication(
credentials[0], credentials[1].toCharArray());
}
return null;
}
};
HttpClient client = HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress(
proxy.getHost(), proxy.getPort())))
.authenticator(auth)
.connectTimeout(Duration.ofSeconds(10))
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.example.com/endpoint"))
.timeout(Duration.ofSeconds(30)).build();
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() < 200 || response.statusCode() >= 300) {
throw new IllegalStateException("HTTP status: " + response.statusCode());
}
System.out.println(response.statusCode());
}
}
Inbound traffic: the reverse problem
Cloud Run's HTTPS service URL is stable across revisions. Static inbound IPs help when a partner's firewall requires fixed destination IPs; a forwarding endpoint can also insulate partners from URL changes when you move projects or regions.
QuotaGuard's inbound proxy provides a hostname backed by static IPs that forwards to your Cloud Run URL. Use Subscription Setup > Inbound Proxy > Configure Inbound Proxies to enter the forwarding URL, then follow the HTTPS/domain setup. Cloud Run must accept the forwarded request under its ingress and authentication settings; retain webhook signature checks. Update the forwarding URL when the origin moves. Region, product, and shared/dedicated changes can require new IPs.
Common inbound use cases:
- Payment webhooks when the sender's firewall requires fixed destination IPs, rather than as a general payment-provider requirement
- Partner API callbacks from corporate systems with strict firewall rules
- HTTPS callbacks from IoT systems whose network policy requires a fixed destination IP
- EDI and B2B integrations that require stable, known IP endpoints
Comparison: Cloud NAT vs Load Balancer vs QuotaGuard
| Feature | Cloud NAT | Load Balancer + NEG | QuotaGuard |
|---|---|---|---|
| Static egress IP | Yes, with VPC egress + reserved IPs | No; inbound only | Yes, for proxied traffic |
| Startup behavior | Direct VPC + NAT has documented delays | Inbound only | Avoids that path on default egress; no universal timeout guarantee |
| Cost basis | Gateway + processing + IPs + transfer | Forwarding rules + processing + network charges | Static from $19/month; plan usage limits apply |
| VPC changes required | Yes | No service VPC attachment needed | No, on default internet egress |
| Setup work | VPC routing, subnet, router, NAT, IPs | NEG, load balancer, frontend IP, TLS | Secret, client, allowlist |
| Static inbound IP | No | Yes | Yes, separate inbound proxy configuration |
| Works across GCP, AWS, other clouds | Native Google Cloud egress | Google serverless backends | Compatible clients on any cloud |
Compare current NAT costs, load balancing costs, and QuotaGuard plans, plus Cloud Run and applicable network charges. Native networking can suit policies disallowing external proxies; external API calls still leave Google's network. Setup effort depends on existing infrastructure.
When to use each approach
Use Cloud NAT if you need static IPs for eligible outbound TCP/UDP traffic routed through your VPC, not just HTTP/HTTPS calls, and your team is comfortable managing VPC infrastructure.
Use the Load Balancer + NEG approach if you need a native Google inbound static IP, TLS frontend, or other load balancing features. Add Cloud NAT or an outbound proxy separately if you also need static egress.
Use QuotaGuard if you need static egress for proxy-compatible clients and/or a separately configured inbound endpoint for your Cloud Run service, and want a managed proxy without setting up VPC egress solely for that integration.
Testing your static IP
With requests installed, run this check from your deployed Cloud Run application with its secret-backed variable available. A local run tests only the local route. ipify returns the source IPv4 address:
# Save as check_ip.py; run with: python3 check_ip.py
import os
import requests
proxy_url = os.environ["QUOTAGUARDSTATIC_URL"].strip()
if not proxy_url:
raise ValueError("QUOTAGUARDSTATIC_URL is empty")
proxies = {"http": proxy_url, "https": proxy_url}
with requests.Session() as session:
session.trust_env = False
response = session.get(
"https://api.ipify.org?format=json",
proxies=proxies, timeout=(10, 30),
)
response.raise_for_status()
print(response.json()["ip"])
Match the returned IP against your dashboard. Give your API vendor all assigned outbound IPs, not just one observed address. Test the actual API client from Cloud Run, including after instance startup. A proxy 407 response means proxy authentication failed.
Get started
QuotaGuard Static starts at $19/month with a free trial. See pricing and sign up here. Configure your proxy URL as a secret, update your client, and give your API vendor the assigned IP pair.
For more detail on the integration, including inbound proxy configuration and environment variable setup, see the QuotaGuard documentation.
QuotaGuard Static IP Blog
Practical notes on routing cloud and AI traffic through Static IPs.







