-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Referring to TLS secret from other namespace (i.e. not the namespace in which ingress is created) #2170
Comments
The standard security model for Kubernetes is that secrets are only accessible from within the current Namespace. As per the API definition, the |
True enough, but I think there is a catch-22 when trying to use wildcard certificate in cluster and keeping the certificate private key secure.
Since it will be the Ingress controller reading the secret, rather than something in the ingress namespace, I think your statement will still remain true. |
Closing. This should be allowed in the Ingress spec first. We are are not going to break this rule. |
@aledbf Is there a followup issue for changing the spec? |
@sheerun not yet |
@aledbf @sheerun @aku105
The ingress will be registered :80,:443 and use the default (wildcard certificate). |
Thanks @mattalberts. While this is far from ideal (you can only have one default certificate), it's better than nothing. That said, the spec should be updated to address the issue of using secrets from different namespaces. Wildcard certificates should be stored in the ingress controller's namespace, and Ingress resources from different namespaces should be allowed to reference them. What is the process of bringing up the spec discussion? Thanks! @sheerun @aledbf |
I look forward to an official fix coming in terms of a spec change that allows for referring to Secrets across namespace boundaries. In the meantime, I am using a deployment that runs 2 |
UPDATE: in nginxinc/nginx-ingress default-ssl-certificate is default-server-tls-secret @mattalberts I've tried to drop Dropping it in the spec gives my 1.2.0 controller spec
|
You are using a different ingress controller https://github.com/nginxinc/kubernetes-ingress where that flag is not supported |
@mattalberts could you show me an example ingress you have that this works with? I've setup as you suggested but when trying to access on https I get 404 but http works. Checking the nginx.conf file on nginx it only registers port 80. |
Does your ingress that's 404ing for https have a tls section with the hostname in it but without secretName? the tls section needs to be there so it knows to bind the service to https too. |
That did the trick! Thank you. |
i tried the below work around and it worked for me
it seems nginx load the ingress and associated secrets, and if there any other ingress in different namespace referenced the same shared secret by name it will be already loaded by the dummy ingress so nginx will use it. |
@mohamedfarouk Wow. Thanks for sharing this. |
@mohamedfarouk I'm wondering how do you reference same shared secret by name from different namespace? Could you please share your configs? |
@mohamedfarouk ok, I've figured it out and it also worked for me with following config:
|
@aledbf would you consider an annotation like |
@janosi no, sorry. This is one of the rules defined in the ingress spec that we are not going to bend/break. |
Note that the above workaround only works if the ingress containing the actual secret is the oldest one including that host. It will fall back to the default certificate and ignore all others. See also: |
@aledbf I have hard times with finding the restriction in the Ingress specification https://kubernetes.io/docs/concepts/services-networking/ingress/ |
@janosi Ingress predates the KEP process. For that reason, the are no formal documents besides the code. You can see the definitions and comments in types.go#L102. From the code, you can get two clear rules, service and secret are located in the same namespace. There is no way to reference a different one. These issues are being tackled in Ingress V2 https://github.com/kubernetes-sigs/service-apis where there is a clear delegation model and clear Roles and personas |
Anyone else noticed that using a hack proposed by @mohamedfarouk and @nanorobocop results in broken prometheus exporter metrics? |
@glothriel Do you mean broken metrics on (1.) the ingress controller and/or cert manager pods or (2.) on all the deployments linked to that ingress (or 3. both...)? I'm contemplating using their hack as a method for getting around LetsEncrypt limits and I can theoretically tolerate 1 but, 2 or 3 are kind of deal breakers if it means no metrics from any of the workloads in the cluster that use this method... |
@countablecloud only some ingress controller metrics, afair it was connected to using wildcard hostname, not to the hack itself. We switched to haproxy due to that as ingress metrics were a must for us. |
Hello there I'm just wondering whether it's possible to support configure certificates in the same namespace where The scenario is like, say, we have a lot of microservices, and a lot of tls certificates for each one. But we don't want them to be accessible to application engineers who usually have access to the microservice namespace. Because they don't need to access the TLS certificate key. So we just want to deploy all the certificates in the |
You can create a dummy ingress that specifies a secret in the ingress-nginx namespace, and then elsewhere use ingresses for those domains without specifiying the secret reference. The only caveats are that this is allegedly not supported by the spec, and the ingress referencing the secret needs to be the oldest (#4926). |
I'd rather do it properly than make this hack. That's why I asked despite I saw this workaround in previous comments. My point is, ingress nginx is built on top of nginx. Supporting to configure it in a more nginx way doesn't sound like a bad idea to me. I might be wrong but this doesn't sound very hard to implement. Just need to define which cert maps to which host and merges it with the ingress definition. Or this still falls into the category of "changing the ingress spec"? |
Any updates on this issue? As i am using cert-manager to generate certificates (in namespace cert-manager, not default, for security reasons) for my cluster, this problem is causing me a lot of headaches. |
The Contour ingress controller has explicit support for referencing certificates from other namespaces, specifically to allow a cluster administrator to create wildcard certificates to be used by other namespaces. They achieve this via a custom resource called |
@CyanoKobalamyne agreed, I have seen support for this common use case in several ingress controller implementations. I do understand the security and K8s ingress spec concerns, but the resistance is a bit strange to me considering how common this use case is. It is unfortunate that the recommended approach is to install a third-party secret syncing solution (although I respect it, in a way, in the name of separation of concerns). Although not a direct solution, it is worth mentioning that the budding Kubernetes Gateway API has native support for cross-namespace TLS cert references. Something to keep an eye on! Lots of projects are building out implementations based on this spec (see here). |
Any news about this? Is end of 2023 and this is still a problem. |
using @aledbf you mention that it is a ingress defined rule that would not be broken, but when I use the ingress annotation |
Any news on this? |
The problem mentioned should be solved by However, I'm not sure if the kubernetes-nginx controller supports this. Maybe somebody knows that. |
this controller has a flag to set the global default-cert but user going across namespace is not supported and will not be supported in future also because of security reasons. |
Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see https://kubernetes.io/docs/tasks/debug-application-cluster/troubleshooting/.): No
What keywords did you search in NGINX Ingress controller issues before filing this one? (If you have found any duplicates, you should instead reply there.): "Secret namespace"
Is this a BUG REPORT or FEATURE REQUEST? (choose one): Feature
NGINX Ingress controller version: "0.10.2"
Kubernetes version (use
kubectl version
): v1.8.7Environment:
uname -a
): 4.11.0-1016-azureWhat happened:
When trying to use a TLS certificate using
<namespace>/<secretName>
pattern intls
section of ingress definition, Nginx controller still tries to get the details from the namespace where ingress was created.What you expected to happen:
When TLS secret referred when creating an ingress is of pattern
<namespace>/<secretName>
, ingress controller shouldn't check only in ingress' namespace.How to reproduce it (as minimally and precisely as possible):
secret-store
andingress-store
.secret-store
namespace, saymy-tls
.ingress-store
namespace with TLS enabled and in the.spec.tls.hosts[].secretName
field putsecret-store/my-tls
to refer to the secret insecret-store
namespace.secret-store
namespace:Anything else we need to know:
Initial glance on the code suggests that in below snippet, in the if block, we check if the secret has a
/
in it, and try to extract the secret from the namespace provided in ingress.spec.tls
definition, it could work.ingress-nginx/internal/ingress/controller/controller.go
Lines 1000 to 1005 in 164bb7b
The text was updated successfully, but these errors were encountered: