ingress-nginx: webhook admission controller error - no validation for extensions/v1beta1 or networking.k8s.io/v1 ingresses

NGINX Ingress controller version: v0.41.2

Kubernetes version (use kubectl version):

Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.4", GitCommit:"e87da0bd6e03ec3fea7933c4b5263d151aafd07c", GitTreeState:"clean", BuildDate:"2021-02-18T16:12:00Z", GoVersion:"go1.15.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.7", GitCommit:"1dd5338295409edcfff11505e7bb246f0d325d15", GitTreeState:"clean", BuildDate:"2021-01-13T13:15:20Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"linux/amd64"}

Environment:

  • Cloud provider or hardware configuration: vanilla kubernetes 1.19 on centOS Azure vms
  • OS (e.g. from /etc/os-release): CentOS Linux 7
  • Kernel (e.g. uname -a): Linux lnx001617 3.10.0-1160.24.1.el7.x86_64 #1 SMP Thu Apr 8 19:51:47 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools: kubespray

What happened:

Here my ValidatingWebhookConfiguration rules:

    rules:
      - apiGroups: ["networking.k8s.io", "extensions"]
        apiVersions: ["*"]
        operations:
          - CREATE
          - UPDATE
        resources:
          - ingresses

Try to deploy diffrent ingresses api with the following incorrect annotation:

    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "Permissions-Policy: geolocation=(), microphone=(), camera=()";|

Webhook admission controller seems to validate configuration only for networking.k8s.io/v1beta1 ingress api version.

  1. Try to deploy an extensions/v1beta1 ingress

Deployment result ok (validation failure was expected here):

# k apply -f extensions_v1beta1_ingress_invalid_annotations.yaml 
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
ingress.extensions/extensions-v1beta1-ingress-invalid-annotations created

Admission controller result:

ingress-nginx-private-controller-8d55f ingress-nginx-private-controller 2021-04-21T09:32:03.624734151Z E0421 09:32:03.624446       6 server.go:84] "failed to process webhook request" err="rejecting admission review because the request does not contain an Ingress resource but extensions/v1beta1, Kind=Ingress with name extensions-v1beta1-ingress-invalid-annotations in namespace fx00964-1"
  1. Try to deploy a networking.k8s.io/v1beta1 ingress

Deployment result ko (expected behavior):

# k apply -f networking_v1beta1_ingress_invalid_annotations.yaml Warning: networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Error from server (BadRequest): error when creating "networking_v1beta1_ingress_invalid_annotations.yaml": admission webhook "validate.nginx.ingress.kubernetes.io" denied the request: 
-------------------------------------------------------------------------------
Error: exit status 1
2021/04/21 09:34:52 [emerg] 487#487: unknown directive "|" in /tmp/nginx-cfg949687373:5803
nginx: [emerg] unknown directive "|" in /tmp/nginx-cfg949687373:5803
nginx: configuration file /tmp/nginx-cfg949687373 test failed

-------------------------------------------------------------------------------
  1. Try to deploy a networking.k8s.io/v1

Deployment result ok (validation failure was expected here):

# k apply -f networking_v1_ingress_invalid_annotations.yaml 
ingress.networking.k8s.io/networking-v1-ingress-invalid-annotations created

Admission controller result:

ingress-nginx-private-controller-zwz52 ingress-nginx-private-controller 2021-04-21T09:38:58.070252966Z E0421 09:38:58.070074       7 server.go:84] "failed to process webhook request" err="rejecting admission review because the request does not contain an Ingress resource but networking.k8s.io/v1, Kind=Ingress with name networking-v1-ingress-invalid-annotations in namespace fx00964-1"

What you expected to happen:

At least networking.k8s.io/v1beta1 and networking.k8s.io/v1 are supported by ingress admission controller webhook. Ideally, kubernetes n and n-1 versions valid ingresses should be supported by admission controller.

How to reproduce it:

Deploy an v0.41.2 ingress controller with an ValidatingWebhookConfiguration rules targeting networking.k8s.io/v1beta1, networking.k8s.io/v1 and extensions/v1beta1 object and deploy the following ingresses:

extensions/v1beta1 test ingress
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: extensions-v1beta1-ingress-invalid-annotations
  annotations:
    # Annotation used to define a private access
    kubernetes.io/ingress.class: "private"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "Permissions-Policy: geolocation=(), microphone=(), camera=()";|
  labels:
    app: invalid-test
spec:
  rules:
  - host: "fake-host.com"
    http:
      paths:
      - path: /
        backend:
          serviceName: invalid-test-svc
          servicePort: http
networking.k8s.io/v1beta1 test ingress
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: networking-v1beta1-ingress-invalid-annotations
  annotations:
    # Annotation used to define a private access
    kubernetes.io/ingress.class: "private"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "Permissions-Policy: geolocation=(), microphone=(), camera=()";|
  labels:
    app: invalid-test
spec:
  rules:
  - host: "fake-host.com"
    http:
      paths:
      - path: /
        backend:
          serviceName: invalid-test-svc
          servicePort: http
networking.k8s.io/v1 test ingress
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: networking-v1-ingress-invalid-annotations
  annotations:
    # Annotation used to define a private access
    kubernetes.io/ingress.class: "private"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      more_set_headers "Permissions-Policy: geolocation=(), microphone=(), camera=()";|
  labels:
    app: invalid-test
spec:
  rules:
  - host: "fake-host.com"
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: invalid-test-svc
            port:
              name: http

Anything else we need to know:

I notice there are issues related to this admission controller errors:

that should be included in v0.41.2 version but i still have the problems as decribed above.

/kind bug

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

@arno-snop

EKS: 1.19 ingress-controller: 0.44.0, 0.46.0, 0.47.0 Try the next configuration. This works with 0.47.0 for both networking.k8s.io/v1beta1 and extensions/v1beta1 Ingresses.

matchPolicy should be set to Equivalent to allow ingress resource to be converted before validation. extensions should be removed from apiGroups.

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: ingress-nginx-admission
  namespace: ingress-nginx
webhooks:
  - name: validate.nginx.ingress.kubernetes.io
    matchPolicy: Equivalent
    rules:
      - apiGroups:
          - networking.k8s.io
        apiVersions:
          - v1beta1
        operations:
          - CREATE
          - UPDATE
        resources:
          - ingresses
    failurePolicy: Fail
    sideEffects: None
    admissionReviewVersions:
      - v1
      - v1beta1
    clientConfig:
      service:
        namespace: ingress-nginx
        name: ingress-nginx-controller-admission
        path: /networking/v1beta1/ingresses