feat(gke-edge): TLS policy, Cloud Armor on every backend, TLS from a Secret (agent-relay 0.7.59)

Merged
MI
3d ago
+1661-5

Why

Two findings from the GCP self-host hardening review:

  1. TLS policy. The GKE Ingress FrontendConfig only set redirectToHttps, so Google's default SSL policy applied and the load balancer accepted TLS 1.0 and 1.1. The EKS path pins ELBSecurityPolicy-TLS13-1-2-2021-06.
  2. No edge WAF. No backend had a Cloud Armor policy.

It also adds what an install behind a fronting proxy (Cloudflare) needs: a certificate from a Secret, and a policy that only admits the proxy.

What changes

Chart agent-relay 0.7.59

Three new gkeIngress values, all empty by default. Default renders are unchanged apart from the helm.sh/chart labels.

ValueEffect
gkeIngress.sslPolicyCompute SSL policy name โ†’ FrontendConfig.spec.sslPolicy
gkeIngress.securityPolicyCloud Armor policy name โ†’ spec.securityPolicy.name on the BackendConfig of every backend behind the Ingress
gkeIngress.tlsSecretNamekubernetes.io/tls Secret in spec.tls instead of the ManagedCertificate (not rendered)

"Every backend" means: api, cast, history read, history ingest, actors edge and relaygate edge (their existing BackendConfigs keep timeouts and health checks), plus new policy-only BackendConfigs <name>-dashboard, <name>-edge-deny and <name>-files. The dashboard and Relayfile Services belong to child charts, so the render refuses until their cloud.google.com/backend-config annotation names the derived BackendConfig, and prints the value to set. No child chart changes.

Terraform

  • New terraform/modules/gcp/edge-security:
    • google_compute_ssl_policy (MODERN or RESTRICTED, TLS 1.2 minimum; COMPATIBLE/TLS 1.0 are refused by validation).
    • Optional Cloud Armor policy (security_policy.create): OWASP preconfigured rules at sensitivity 1, a per-client rate limit on sign-in paths, a source-IP allowlist with default deny (also usable alone, as a pure allowlist), Cloudflare origin lockdown (published ranges only), a shared-secret origin header rule, and path rules keyed on the proxy's client-IP header (origin.user_ip). Labels on the policy.
  • terraform/examples/gcp calls it: the SSL policy is created by default and exported as gkeIngress.sslPolicy in chart_values; Cloud Armor is opt-in (edge_security_policy).

Docs

docs/gcp-install/3-EDGE-HARDENING.md (steps and "Done when" checks for TLS policy, Cloud Armor, Cloudflare in front, including trustedProxies: 2 and which hostnames a Cloudflare Universal certificate covers), chart README "GKE edge hardening", module README, GKE skill inputs, registry entry opt.agent-relay.gke-edge-hardening.

Defaults chosen, and why

  • gkeIngress.sslPolicy: empty in the chart, on by default through Terraform. The chart cannot create a Compute resource, and a name that does not exist in the project stops the Ingress from syncing, so a chart default would break every install that upgrades. Instead terraform/examples/gcp creates the policy and puts its name in managed-values.json, which the guide already passes to helm upgrade. New guided installs get TLS 1.2+ with no extra step; an existing install gets it the next time it re-applies step 4 and upgrades (plan shows one resource to add; the documented plan count goes from 29 to 30). Opt out with edge_ssl_policy = { create = false }. Bring-your-own installs create it with one gcloud command.
  • Cloud Armor: off. As asked. It needs the customer to review the rules against their traffic first.
  • OWASP rules: preview by default. Transcripts, messages and flows carry code, SQL and shell text, which is what those signatures match. Preview logs without blocking; the guide gives the log query and the switch to enforce.
  • Sensitivity 1, and methodenforcement plus the language-specific rule sets are left out (the API uses PUT/PATCH/DELETE).

Design notes for review

  • Cloud Armor expressions take five subexpressions, and a throttle rule admits conforming requests. So when an allowlist is set, each throttle rule also requires an allowlisted connecting address, in groups of four ranges. Deny rules always precede rules that admit.
  • Cloudflare's ranges are shared by all Cloudflare customers and cannot be conjoined with a second address list in one expression, so client_ip_rules (which trust CF-Connecting-IP) require origin_secret_header. That value is in Terraform state and readable in the policy; the docs say so.
  • 0.7.58 is taken by #474; this PR uses 0.7.59 and will be rebased on whichever lands first.

Tests

  • ci/agent-relay/render.sh: defaults render none of the three; with them set, the FrontendConfig carries sslPolicy and keeps the redirect, every BackendConfig carries the policy, every Service the Ingress routes to is bound to a BackendConfig that has it, timeouts and health checks survive; actors/files overlay; tlsSecretName drops the ManagedCertificate and annotation; each refusal.
  • terraform test (mock provider): 10 runs in the module, 3 new runs in examples/gcp.
  • Local: scripts/ci/charts.sh static agent-relay, ci/agent-relay/render.sh, scripts/ci/version-bump.sh, node ci/self-hosted-requirements/registry.mjs check, terraform fmt/validate/test, tflint, terraform-docs, checkov on the changed module and example: all pass. Local Helm is 4.1.3, so the subdomain golden hash check was skipped locally and runs in CI.

Not proven

Nothing here has run against a live GCP project: no terraform apply, no real load balancer. Unproven until a live install: that GKE attaches the policies as rendered, the Cloud Armor rule expressions and quotas (seven advanced rules with Cloudflare on), trustedProxies: 2 behind Cloudflare, and long-lived WebSocket/SSE connections through Cloudflare.

๐Ÿค– Generated with Claude Code


Autofix with [code]smith
Open in [code]smith ยท Need help on this PR? Tag @codesmith-bot with what you need.