fix non tls ingress still able to listen on a https port
What this PR does / why we need it:
In the ingress resource if tls section is not defined, then the current behaviour of the controller is to expose even the https port for that ingress path. This is not correct.
When we create an ingress resource without tls section, below is the kubectl get ingress output. As we can see only port 80 is defined indicating only http. However ingress-nginx controller exposes the https port
$ kubectl get ingress -n deepak
NAME CLASS HOSTS ADDRESS PORTS AGE
backend-nginx-server deepak deep.example.com 10.72.115.158,10.72.115.159 80 37m
This is not the expected behaviour.
This PR fixes this bug by not rendering the https port when ingress resource is not having the tls section.
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] CVE Report (Scanner found CVE and adding report)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation only
Which issue/s this PR fixes
- NA. This fixes the issue related to the invalid tls port being exposed when ingress resource is created without tls section.
How Has This Been Tested?
$ kubectl get ingress -n deepak
NAME CLASS HOSTS ADDRESS PORTS AGE
backend-nginx-server deepak deep.example.com 10.72.115.158,10.72.115.159 80 37m
$ kubectl apply -f ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
name: backend-nginx-server
namespace: deepak
spec:
ingressClassName: deepak
rules:
- host: deep.example.com
http:
paths:
- backend:
service:
name: backend-nginx-server
port:
number: 8080
path: /server1/(.*)
pathType: Prefix
ingress.networking.k8s.io/backend-nginx-server created
$ cat /etc/nginx/nginx.conf | grep "deep.example.com" -C 10
## start server deep.example.com
server {
server_name deep.example.com ;
listen 50001 ;
listen [::]:50001 ;
listen 50003 ssl http2 ;
listen [::]:50003 ssl http2 ;
set $proxy_upstream_name "-";
With fix:
This changes fixes the above issue.
nginx.conf when ingress resource consists of tls section
## start server deep.example.com
server {
server_name deep.example.com ;
listen 50001 ;
listen [::]:50001 ;
listen 50003 ssl http2 ;
listen [::]:50003 ssl http2 ;
set $proxy_upstream_name "-";
ssl_certificate_by_lua_block {
certificate.call()
}
nginx.conf when ingress resource doesn't consists of tls section
## start server deep.example.com
server {
server_name deep.example.com ;
listen 50001 ;
listen [::]:50001 ;
set $proxy_upstream_name "-";
ssl_certificate_by_lua_block {
certificate.call()
}
Checklist:
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I've read the CONTRIBUTION guide
- [ ] I have added unit and/or e2e tests to cover my changes.
- [ ] All new and existing tests passed.
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: izanami-01 / name: DEEPAK RAWTE (c5cadcc120e63bbed5dc52cd1a4da2d8524f174d, e0ee1c1a55d9fe80275373630620c1c7cbfbf6df, c525936940eb4fd9dde9245098f4b647c4897c6c)
Deploy Preview for kubernetes-ingress-nginx canceled.
| Name | Link |
|---|---|
| Latest commit | c525936940eb4fd9dde9245098f4b647c4897c6c |
| Latest deploy log | https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/65842519a0a8b700089660b8 |
Welcome @izanami-01!
It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.
You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.
You can also check if kubernetes/ingress-nginx has its own contribution guidelines.
You may want to refer to our testing guide if you run into trouble with your tests not passing.
If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!
Thank you, and welcome to Kubernetes. :smiley:
Hi @izanami-01. Thanks for your PR.
I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test label.
I understand the commands that are listed here.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: izanami-01 Once this PR has been reviewed and has the lgtm label, please assign strongjz for approval. For more information see the Kubernetes Code Review Process.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment
@rikatz @strongjz @tao12345666333 FYI
Something is off with golangci-lint and the k8s e2e don't even start, can you rebase and try the test locally and then push that change.
Can you also check that there is an e2e test for this case.
/triage accepted /priority backlog /ok-to-test
Hi @rikatz @strongjz could you provide suggestion on the below scenario:
I tried updating test/e2e/lua/dynamic_certificates.go and tested it locally and for
ginkgo.It("picks up the certificate when we add TLS spec to existing ingress", func() {
- after my code changes ingress resource without TLS section won't be having https listen directive
- in that particular e2e test when ingress resource is updated with TLS section by some reason sync event isn't happening because of which nginx.conf isn't getting updated.
- Lua is working fine which I have validated via
./dbg certs get foo.com - I tried updating the ingress resource by adding some annotations post the TLS section is updated and nginx.conf was updated correctly with that change and e2e got passed.
Hi @strongjz / @rikatz, Could you please help/suggest me on the above query ?