Skip to content

ClientTrafficPolicy: caCertificateRefs foreign namespaces not supported #7895

@BernhardGruen

Description

@BernhardGruen

Description
I tried to configure an mTLS secret for client connections. I wanted to use a secret from another namespace. Therefore I created a ReferenceGrant for it.
But unfortunately this did not work even though it is documented as possible: https://gateway.envoyproxy.io/docs/api/extension_types/#clientvalidationcontext

References to a resource in different namespace are invalid UNLESS there is a ReferenceGrant in the target namespace that allows the certificate to be attached.

It seems the code that handles the ClientTrafficPolicy does not allow foreign namespaces as the following code shows:

secret, err := t.validateSecretRef(false, from, ref, resources)

The first parameter would have to be true in this case to allow foreign namespaces. I don't know the software therefore I am not sure if this is the only place.

It would be great if a future version would support this case.

Repro steps
Create the following objects:

apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
  name: eg
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: gw-eg
  namespace: test-01
spec:
  gatewayClassName: eg
  listeners:
    - allowedRoutes:
        namespaces:
          from: Same
      hostname: "test-01.example.eu"
      name: http
      protocol: HTTP
      port: 80
    - allowedRoutes:
        namespaces:
          from: Same
      hostname: "test-01.example.eu"
      name: https
      port: 443
      protocol: HTTPS
      tls:
        certificateRefs:
        - group: ""
          kind: Secret
          name: tls-sec
        mode: Terminate
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: test-httproute-eg
  namespace: test-01
spec:
  hostnames:
  - "test-01.example.eu"
  parentRefs:
    - name: gw-eg
  rules:
  - backendRefs:
    - group: ""
      kind: Service
      name: my-service
      port: 80
      weight: 1
    matches:
    - path:
        type: PathPrefix
        value: /
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: ClientTrafficPolicy
metadata:
  name: enable-mtls
  namespace: test-01
spec:
  targetRefs:
  - group: gateway.networking.k8s.io
    kind: Gateway
    name: gw-eg
  tls:
    clientValidation:
      optional: false

      caCertificateRefs:
      - kind: "Secret"
        group: ""
        namespace: pki
        name: "ca-client-auth-secret"
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: client-auth-secret
  namespace: pki
spec:
  from:
  - group: gateway.envoyproxy.io
    kind: ClientTrafficPolicy
    namespace: test-01
  to:
  - group: ""
    kind: Secret
    name: "ca-client-auth-secret"

As you can see the ReferenceGrant was generated in the pki namespace as it is written in the documentation.

Environment
Kubernetes 1.33.4, Envoy Gateway 1.6.1, Gateway-API 1.4.1 (standard)

Logs
This error message is shown in the logs and also in the status of ClientTrafficPolicy:

TLS: failed to get certificate from ref: secret ref namespace must  be unspecified/empty or test-01

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions