`--namespace-whitelist` is bypassed if configmap namespace is empty
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 != "".
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.
Think this is a sneaky bug that would be nice if documented or fixed
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.