Skip to content

TLS certificate lookup fails for server aliases unless specified host is loaded at least once #4832

@migueloller

Description

@migueloller

NGINX Ingress controller version: v0.26.1

Kubernetes version (use kubectl version): v1.12.10-gke.17

Environment:

  • Cloud provider or hardware configuration: GKE

What happened:
I defined an ingress resource with a server alias with a regular expression, using the nginx.ingress.kubernetes.io/server-alias, and a certificate with a wildcard host that matches the alias. When sending a request that matches the alias but not the primary host, the fake self-signed certificate is used. When sending a request that matches the primary host, the configured certificate is used. Interestingly enough, subsequent request to hosts that match the alias will then use the configured certificate. After having requested the main host and "fixing" the issue, I can get back to the erroneous state by re-applying the ingress resource.

What you expected to happen:

I expected to receive the configured certificate for the ingress, without having to request the main host.

How to reproduce it (as minimally and precisely as possible):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: site
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/server-alias: '~.+.example.com'
spec:
  tls:
    - hosts:
        - primary.example.com
      secretName: star-example-com-tls
  rules:
    - host: primary.example.com
      http:
        paths:
          - path: /
            backend:
              serviceName: app
              servicePort: 80

Visit foo.example.com or any other subdomain for example.com and notice the self-signed cert is returned, then visit primary.example.com and notice the wildcard provided cert is returned, then go back to foo.example.com or any other subdomain for example.com and see that now the provided cert is being used.

Anything else we need to know:
I was able to get around this issue by using a wildcard in the hosts. Most conversations online mention that this is not supported by Kubernetes but it seems to be working without any issues, like this:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: site
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  tls:
    - hosts:
        - '*.example.com'
      secretName: star-example-com-tls
  rules:
    - host: '*.example.com'
      http:
        paths:
          - path: /
            backend:
              serviceName: app
              servicePort: 80

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions