Skip to content

feat: add trustedProxies support for Caddy reverse proxy#212

Merged
Cre-eD merged 4 commits intomainfrom
feat/caddy-trusted-proxies
Apr 4, 2026
Merged

feat: add trustedProxies support for Caddy reverse proxy#212
Cre-eD merged 4 commits intomainfrom
feat/caddy-trusted-proxies

Conversation

@Cre-eD
Copy link
Copy Markdown
Contributor

@Cre-eD Cre-eD commented Apr 1, 2026

Adds trustedProxies field to CaddyConfig. When set, injects Caddy servers { trusted_proxies static <CIDRs> } into the global options block alongside GCS storage config.

This preserves X-Forwarded-For headers from trusted upstream proxies (e.g., Cloudflare, GKE LB) instead of overwriting them with the immediate client IP.

Usage in server.yaml:

caddy:
  enable: true
  trustedProxies:
    - "10.0.0.0/8"       # GKE internal
    - "172.16.0.0/12"    # GKE internal
    - "173.245.48.0/20"  # Cloudflare
    - "103.21.244.0/22"  # Cloudflare

Adds `trustedProxies` field to CaddyConfig. When set, injects Caddy
`servers { trusted_proxies static <CIDRs> }` into the global options
block alongside GCS storage config.

This preserves X-Forwarded-For headers from trusted upstream proxies
(e.g., Cloudflare, GKE LB) instead of overwriting them with the
immediate client IP.

Usage in server.yaml:
```yaml
caddy:
  enable: true
  trustedProxies:
    - "10.0.0.0/8"       # GKE internal
    - "172.16.0.0/12"    # GKE internal
    - "173.245.48.0/20"  # Cloudflare
    - "103.21.244.0/22"  # Cloudflare
```
@Cre-eD Cre-eD self-assigned this Apr 1, 2026
@blacksmith-sh

This comment has been minimized.

Adds `trustedProxies` field to CaddyConfig. When set, injects Caddy
`servers { trusted_proxies static <CIDRs> }` into the global options
block alongside storage config.

This preserves X-Forwarded-For headers from trusted upstream proxies
(e.g., Cloudflare, GKE LB) instead of overwriting them with the
immediate connecting IP.

Changes:
- pkg/clouds/k8s/types.go: add TrustedProxies []string to CaddyConfig
- pkg/clouds/pulumi/kubernetes/caddy_global_opts.go: extracted testable
  BuildTrustedProxiesBlock (with CIDR validation) and
  BuildCaddyfileGlobalOptions helpers
- pkg/clouds/pulumi/kubernetes/caddy.go: support trustedProxies in
  non-GKE (standalone K8s) code path
- pkg/clouds/pulumi/gcp/gke_autopilot.go: use extracted helpers,
  validate CIDRs before Pulumi apply
- pkg/clouds/pulumi/kubernetes/caddy_global_opts_test.go: 9 test cases
  covering empty, valid, invalid, and combination scenarios
smecsia
smecsia previously approved these changes Apr 1, 2026
… fixtures

ConvertDescriptor (yaml round-trip) produces []string{} instead of nil
for unset slice fields. Normalize in CaddyReadConfig and update test
expected values to match deserialization behavior.
- Unresolved fixture (RefappKubernetesServerResources): nil — matches
  CaddyReadConfig normalization after ReadServerDescriptor
- Resolved fixture (ResolvedRefappKubernetesServerResources): []string{}
  — matches placeholder resolution which converts nil slices to empty
  via reflect deep-copy
- CaddyReadConfig normalizes []string{} → nil after ConvertConfig
@Cre-eD Cre-eD requested a review from smecsia April 1, 2026 17:41
@Cre-eD Cre-eD merged commit 63701e2 into main Apr 4, 2026
9 checks passed
@Cre-eD Cre-eD deleted the feat/caddy-trusted-proxies branch April 4, 2026 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants