kubernetes: ingress doesn't works well for namespaced scenario

What happened?

with latest ingress/ingressClass design, there is no way to run application without requesting read permission on cluster level resource “IngressClass”

This is how issue happens ==As k8s administrator==

  1. create the namespace for application “demoapp1” to be installed
kubectl create ns demoapp1
  1. create the role and rolebinding for application “demoapp1”
kubectl create role demoapp1-admin --resource="*" --verb="*"
  1. genenate the kubeconfig file “demoapp1-kubeconfig.yaml” from role “demoapp1-admin”

===As application administrator===

  1. get the kubeconfig file of “demoapp1-admin” from k8s administrator
  2. install demoapp1 such as “helm install demoapp1 demoapp1.tgz --kube-config demoapp1-kubeconfig.yaml” in demoapp1, there is some ingresses as below
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-class-name-no-perm
  namespace: ingress-nginx
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx

in demoapp1, there is one ingress-controller deployed which watch all of ingress whose ingressClassName is “nginx”. this ingress-controller should start and run without any error

as shown above, there is no cluster role binding for “application administrator” to install “demoapp1”, it means any attempt to access k8s cluster resource will be denied

unfortunately, k8s reference doesn’t provide clear guidance on how to valid the <ingress>.spec.ingressClassName, so most of ingress-controller implementation will try to read the IngressClass object from <ingress>.spec.ingressClassName. obvisously, it will fail

in big shared k8s cluster, k8s administrator don’t want to shared cluster level resource permission to applications running the namespace. so typically, they just provide least privileged kubeconfig for application installation

What did you expect to happen?

ingress-controller/ingress can works without read permission on cluster reosurce “IngressClass”

How can we reproduce it (as minimally and precisely as possible)?

check details in “what happend” section

Anything else we need to know?

it is ingress/ingressclass design issue, had a long discussion with @aojea https://kubernetes.slack.com/archives/C09QYUH5W/p1727081948800529

Kubernetes version

$ kubectl version
# paste output here

Client Version: v1.30.4 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.30.4

Cloud provider

on-premise

OS version

# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

irrelevant

Install tools

irrelevant

Container runtime (CRI) and version (if applicable)

irrelevant

Related plugins (CNI, CSI, …) and versions (if applicable)

irrelevant

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 34 (23 by maintainers)

Most upvoted comments

Option 4: build an argument for extending the validation on this field to include values that can’t possibly be real, and document them as reserved for private implementations, or something. To make this argument we would have to bring the gateway API in alignment. I can’t see why doing it for one and not the other would make sense

The gap is rather on the side of how the controller can determine the ingressClassNames it shall handle.

your-controller --this-namespace-only --class-pattern=^private-NS.*

Controller looks up its own namespace and looks for Ingresses that match that pattern. This is entirely under the controller’s purvey.

If the spec allowed a namespaced ingress controller to … avoid the need to read all ingressClass resources

The spec doesn’t need to allow it. You can do anything you want, as long as the name you pick is a) valid and b) not being used by a real class.