gateway icon indicating copy to clipboard operation
gateway copied to clipboard

Support a CA certificate for Redis TLS in the global rate limit backend

Open dragon3 opened this issue 1 month ago • 5 comments

Description:

Allow configuring a CA certificate for TLS connections from the global rate limit service to Redis.

RateLimitRedisSettings.tls currently only accepts a client certificate (certificateRef). When tls is set, Envoy Gateway sets REDIS_TLS=true on the rate limit deployment. envoyproxy/ratelimit then verifies the Redis server certificate against the system roots, unless REDIS_TLS_CACERT is set. Envoy Gateway has no way to set that variable.

Managed Redis services that issue server certificates from a private CA can't be used as the backend:

  • Google Cloud Memorystore with in-transit encryption: server certificates come from a Google-managed private CA, whose CA certificate is published per instance.
  • Self-hosted Redis with an internal CA.

The handshake fails with x509: certificate signed by unknown authority.

A related detail: with tls: {} and no certificateRef, the rate limit container still gets a redis-certs volume mount at /redis-certs, but no redis-certs volume is added to the pod. The only workaround we found depends on that: users define a redis-certs volume themselves through rateLimitDeployment.pod.volumes, then add REDIS_TLS_CACERT=/redis-certs/<file> through rateLimitDeployment.container.env. This relies on internal naming and could break silently on upgrade.

Proposed API, mirroring how BackendTLSPolicy references CA certificates:

rateLimit:
  backend:
    type: Redis
    redis:
      url: redis.example.internal:6378
      tls:
        caCertificateRefs:     # new, optional
          - kind: ConfigMap    # or Secret
            name: redis-ca
        certificateRef:        # existing, optional (client certificate)
          name: redis-client-cert

Behavior:

  • When caCertificateRefs is set, Envoy Gateway mounts the referenced CA certificate (the ca.crt key, as in BackendTLSPolicy) into the rate limit container, and sets REDIS_TLS_CACERT to its path.
  • The pod volume behind the /redis-certs mount is only created when there is something to mount, so tls: {} alone no longer produces a mount without a volume.
  • Validation checks that the referenced ConfigMap or Secret exists, as is already done for certificateRef.

If a single reference is preferred over a list (ratelimit takes one CA file), caCertificateRef works just as well.

I'm happy to send a PR once the API shape is agreed.

Relevant Links:

  • RedisTLSSettings: https://github.com/envoyproxy/gateway/blob/main/api/v1alpha1/envoygateway_types.go
  • Rate limit deployment env and volumes: https://github.com/envoyproxy/gateway/blob/main/internal/infrastructure/kubernetes/ratelimit/resource.go
  • envoyproxy/ratelimit Redis TLS settings (REDIS_TLS_CACERT, REDIS_TLS_SKIP_HOSTNAME_VERIFICATION): https://github.com/envoyproxy/ratelimit/blob/main/src/settings/settings.go
  • Memorystore for Redis in-transit encryption: https://cloud.google.com/memorystore/docs/redis/in-transit-encryption
  • Related: #1217, #8770

dragon3 avatar Oct 13 '26 07:10 dragon3

I've opened a draft PR with an implementation: #10261

It adds a single optional caCertificateRef (ConfigMap or Secret, key ca.crt) under rateLimit.backend.redis.tls and sets REDIS_TLS_CACERT. The PR is a draft until the API shape is agreed, so feedback on single caCertificateRef vs caCertificateRefs would be very welcome. @dragon3, happy to adjust or hand this over if you'd rather send the PR yourself.

souvik-biswas-dev avatar Oct 13 '26 16:10 souvik-biswas-dev

Thanks @souvik-biswas-dev!

I had an implementation ready too, but I was waiting for maintainers to agree on the API shape (single caCertificateRef vs caCertificateRefs) before opening a PR. For what it's worth, I agree with a single caCertificateRef, since ratelimit only reads one CA file. Happy for #10261 to carry this forward once maintainers confirm.

One thing I noticed in the draft: when only the CA ref is set, the container still mounts /redis-certs without a matching redis-certs volume (see testdata/deployments/redis-tls-ca-configmap.yaml), so the Deployment would be rejected. Mounting redis-certs only when certificateRef is set fixes that. Since the CA-only case depends on it, I think it needs to be in this PR rather than a follow-up.

dragon3 avatar Oct 13 '26 23:10 dragon3

Thanks @dragon3, good catch. I've pushed a fix to #10261: redis-certs is now mounted only when certificateRef is set, and the CA-only golden files are updated. This also covers the tls: {} case you mentioned.

souvik-biswas-dev avatar Oct 14 '26 07:10 souvik-biswas-dev

Hi, @souvik-biswas-dev Why did you close the PR?

dragon3 avatar Nov 10 '26 01:11 dragon3

Hi @dragon3, sorry for the confusion. The PR closed automatically because I deleted my fork. I’ve reopened it as a draft in #10577 with the same changes (single caCertificateRef, plus the redis-certs mount fix you spotted), rebased on the latest main. Happy to switch to caCertificateRefs if the maintainers prefer.

souvik-biswas-dev avatar Nov 10 '26 04:11 souvik-biswas-dev