kubernetes-ingress icon indicating copy to clipboard operation
kubernetes-ingress copied to clipboard

`--namespace-whitelist` is bypassed if configmap namespace is empty

Open bm1216 opened this issue 8 months ago • 3 comments

Summary

--namespace-whitelist is bypassed if configmap namespace is empty, because configmap namespace "" is auto-whitelisted

Description

When --namespace-whitelist is set, the controller automatically adds the configmap namespace to the whitelist in getWhitelistedNS().

Today, if the configmap namespace is empty, the code still appends "" and logs: configmap Namespace '' not whitelisted. Whitelisting it anyway

https://github.com/haproxytech/kubernetes-ingress/blob/860bb756163b66f2507b72a8f839196f7f0cc68e/pkg/k8s/main.go#L404-L419

In the above, in L413 if cfgMapNS is empty it goes into the !ok block and adds the configmap namespace (i.e "") anyway. That is dangerous because "" basically tells the Kubernetes informers to do a cluster-wide LIST. In practice, this can turn a namespace-scoped controller into a cluster-wide watcher/listener and defeat --namespace-whitelist.

Expected behavior

If --namespace-whitelist is used, the controller should require a non-empty configmap namespace. It should either:

  • fail fast when the configmap namespace is empty, or
  • skip auto-whitelisting when the configmap namespace is empty

But it should never append "" to the whitelist.

Suggested fix

In getWhitelistedNS(), only auto-add the configmap namespace if cfgMapNS != "".

bm1216 avatar Mar 20 '26 15:03 bm1216

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 19 '26 15:04 stale[bot]

Think this is a sneaky bug that would be nice if documented or fixed

bm1216 avatar Apr 19 '26 16:04 bm1216

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar May 20 '26 18:05 stale[bot]