Skip to content

Secure Web Proxy — Egress Filtering Cho Workloads

Tại sao quan trọng trong production

Outbound HTTP/HTTPS traffic từ workloads là một attack surface thường bị overlooked. Malware, supply chain attacks, và data exfiltration thường dùng HTTPS để bypass firewall (vì TCP 443 thường được allow outbound). Cloud NAT cho phép egress traffic nhưng không inspect nội dung.

Secure Web Proxy (SWP) là một Envoy-based forward proxy mandatory cho outbound HTTP/HTTPS traffic, cho phép:

  • Inspect và filter dựa trên URL, hostname, path.
  • Enforce allow-list (default deny) cho egress destinations.
  • Log tất cả outbound web traffic cho audit.

Internal Model — Kiến Trúc Bên Trong

Envoy-based Proxy

SWP chạy trên Envoy proxy managed bởi Google (tương tự Cloud Load Balancing dùng Envoy). Đây là forward proxy — client explicitly forward requests đến SWP, SWP forward đến destination thay mặt client.

Điều này khác với transparent proxy: workloads phải configure để dùng SWP (qua HTTP_PROXY/HTTPS_PROXY environment variables hoặc GKE's built-in support).

Deployment Modes

Explicit proxy mode: Workload configure HTTP_PROXY=http://<swp-ip>:<port>. Phổ biến nhất. HTTP traffic: SWP là explicit intermediary. HTTPS traffic: SWP handle CONNECT tunneling.

Next-hop routing (transparent mode): Không cần configure workload. Traffic route đến SWP qua policy-based route. Khó hơn để deploy vì cần network-level changes.

Private Service Connect (PSC) endpoint: SWP expose qua PSC endpoint, cho phép workloads từ nhiều VPCs kết nối qua SWP centralized.

Policy Framework

SWP sử dụng hai resource types:

GatewaySecurityPolicy: Container policy, attach vào SWP gateway instance.

GatewaySecurityPolicyRule: Mỗi rule define:

  • Match condition: hostname, URL path, request method.
  • Action: ALLOW hoặc DENY.
  • Priority: thứ tự evaluation (lower number = higher priority).

Default behavior: Deny-all. Nếu không có rule nào match, traffic bị deny. Phải explicitly allow destinations.


mTLS Client Authentication

SWP có thể require workloads present TLS client certificate để authenticate. Cấu hình:

  1. Define TrustConfig với root CA.
  2. Attach TrustConfig vào SWP gateway.
  3. Workloads phải có client certificate signed bởi CA đó.

Điều này cho phép SWP biết workload nào đang request — và apply policy per-workload (không phải chỉ per-source-IP).


Constraints

  • IPv4 only: Không hỗ trợ IPv6.
  • HTTP 1.x và HTTP/2 only: HTTP/3 (QUIC) không được support. Traffic dùng QUIC sẽ bị block hoặc fallback về HTTP/2.
  • Không phải full inspection: SWP inspect URL/hostname nhưng không decrypt HTTPS content (no TLS inspection như NGFW Enterprise). Chỉ inspect CONNECT tunnel metadata.
  • Regional resource: SWP gateway là regional. Workloads ở nhiều regions cần SWP riêng hoặc cần route traffic cross-region.
  • Throughput: Capacity planning quan trọng — nếu tất cả egress traffic đi qua một SWP instance, nó có thể trở thành bottleneck.

GKE Integration

Trong GKE, configure outbound proxy cho workloads:

yaml
# Inject HTTP_PROXY vào Pod qua environment variables
env:
- name: HTTP_PROXY
  value: "http://10.128.0.5:8080"
- name: HTTPS_PROXY
  value: "http://10.128.0.5:8080"
- name: NO_PROXY
  value: "169.254.169.254,metadata.google.internal,10.0.0.0/8"

NO_PROXY phải include GKE metadata server (169.254.169.254) và cluster-internal IPs để tránh routing metadata requests qua SWP.


GCP-native Implementation Guidance

bash
# Tạo Gateway Security Policy
gcloud network-security gateway-security-policies create my-policy \
  --location=us-central1

# Tạo rule allow Google APIs
gcloud network-security gateway-security-policy-rules create allow-google-apis \
  --policy=my-policy \
  --location=us-central1 \
  --priority=100 \
  --action=ALLOW \
  --session-matcher='host() == "googleapis.com" || host().endsWith(".googleapis.com")'

# Tạo SWP gateway
gcloud network-services gateways create my-swp \
  --type=SECURE_WEB_GATEWAY \
  --location=us-central1 \
  --network=my-vpc \
  --subnetwork=my-subnet \
  --ports=8080 \
  --gateway-security-policy=my-policy

References