Skip to content
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

fix non tls ingress still able to listen on a https port #10685

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

izanami-01
Copy link

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

  • 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.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

Copy link

linux-foundation-easycla bot commented Nov 28, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

netlify bot commented Nov 28, 2023

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit c525936
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/65842519a0a8b700089660b8

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 28, 2023
@k8s-ci-robot
Copy link
Contributor

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. 😃

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 28, 2023
@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added needs-priority size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 28, 2023
@k8s-ci-robot
Copy link
Contributor

[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.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 28, 2023
@izanami-01
Copy link
Author

izanami-01 commented Nov 28, 2023

@rikatz @strongjz @tao12345666333
FYI

@strongjz
Copy link
Member

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

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority labels Nov 28, 2023
@izanami-01
Copy link
Author

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.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 21, 2023
@izanami-01
Copy link
Author

Hi @strongjz / @rikatz,
Could you please help/suggest me on the above query ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/backlog Higher priority than priority/awaiting-more-evidence. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants