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

add support for TLS route #2211

Conversation

sarthyparty
Copy link
Contributor

@sarthyparty sarthyparty commented Jul 9, 2024

Proposed changes

Problem: TLSRoute was not supported by NGF.

Solution: Watched for changes to TLSRoutes, added validation and tests, added TLSRoute to graph, and converted Kubernetes TLSRoute spec to nginx config.

Testing: Full code coverage to all code added and enabled one of the TLS Passthrough tests.

Closes #686

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.


@github-actions github-actions bot added the enhancement New feature or request label Jul 9, 2024
@sarthyparty
Copy link
Contributor Author

sarthyparty commented Jul 9, 2024

@pleshakov @kate-osborn

Is there a need for separate nginx servers for each hostname? For example, if the graph has a L4Route with hostnames "app.example.com" and "cafe.example.com", the code will currently create a map and two nginx servers like this:

map {
    app.example.com app.example.com443.sock
    cafe.example.com cafe.example.com443.sock
}

server {
    listen app.example.com443.sock
    proxy_pass upstream_1
}

server {
    listen cafe.example.com443.sock
    proxy_pass upstream_1
}

Rather it might be better to do it like this

map {
    app.example.com upstream_1.sock
    cafe.example.com upstream_1.sock
}

server {
    listen upstream_1.sock
    proxy_pass upstream_1
}

@pleshakov
Copy link
Contributor

pleshakov commented Jul 9, 2024

@sarthyparty

having separate servers will help with handling edge cases like below.

Let's say an application developer creates this TLSRoute:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TLSRoute
metadata:
  name:  first
spec:
  parentRefs:
  - name: gateway
  hostnames:
  - app.example.com
  rules:
  - backendRefs:
    - name: my-backend-1
      port: 443

Another application developer creates this TLSRoute after the first one was created:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TLSRoute
metadata:
  name:  second
spec:
  parentRefs:
  - name: gateway
  hostnames:
  - app.example.com
  - cafe.example.com
  rules:
  - backendRefs:
    - name: my-backend-2
      port: 443

Based on this https://gateway-api.sigs.k8s.io/guides/api-design/#conflicts,

NGF needs to be configured
app.example.com -> my-backend-1
cafe.example.com -> my-backend-2

Having a server per hostname makes handling this edge case easy

@sarthyparty
Copy link
Contributor Author

thanks!

@kate-osborn
Copy link
Contributor

@sarthyparty

having separate servers will help with handling edge cases like below.

Let's say an application developer creates this TLSRoute:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TLSRoute
metadata:
  name:  first
spec:
  parentRefs:
  - name: gateway
  hostnames:
  - app.example.com
  rules:
  - backendRefs:
    - name: my-backend-1
      port: 443

Another application developer creates this TLSRoute after the first one was created:

apiVersion: gateway.networking.k8s.io/v1alpha2
kind: TLSRoute
metadata:
  name:  first
spec:
  parentRefs:
  - name: gateway
  hostnames:
  - app.example.com
  - cafe.example.com
  rules:
  - backendRefs:
    - name: my-backend-2
      port: 443

Based on this https://gateway-api.sigs.k8s.io/guides/api-design/#conflicts,

NGF needs to be configured app.example.com -> my-backend-1 cafe.example.com -> my-backend-2

Having a server per hostname makes handling this edge case easy

@pleshakov I'm assuming the second TLSRoute in this example would be created with a different name? Otherwise, the second TLSRoute would just update the first...

@pleshakov
Copy link
Contributor

@kate-osborn

@pleshakov I'm assuming the second TLSRoute in this example would be created with a different name? Otherwise, the second TLSRoute would just update the first...

good catch. updated

@sarthyparty sarthyparty marked this pull request as ready for review July 10, 2024 15:50
@sarthyparty sarthyparty requested a review from a team as a code owner July 10, 2024 15:50
Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sarthyparty can you also add a test case, or modify an existing test case, to TestBuildConfiguration? Anytime we modify the BuildConfiguration function, we update or add to TestBuildConfiguration. This ensures that we don't have any regressions when we add something new to the config.

internal/mode/static/state/dataplane/configuration.go Outdated Show resolved Hide resolved
internal/mode/static/state/dataplane/configuration.go Outdated Show resolved Hide resolved
internal/mode/static/state/dataplane/configuration.go Outdated Show resolved Hide resolved
internal/mode/static/state/dataplane/configuration.go Outdated Show resolved Hide resolved
internal/mode/static/state/dataplane/configuration.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/gateway_listener.go Outdated Show resolved Hide resolved
internal/mode/static/state/dataplane/configuration_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/dataplane/configuration_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/dataplane/configuration_test.go Outdated Show resolved Hide resolved
@sarthyparty sarthyparty marked this pull request as draft July 12, 2024 15:58
@sarthyparty sarthyparty marked this pull request as ready for review July 23, 2024 17:17
@sarthyparty sarthyparty requested a review from a team as a code owner July 23, 2024 19:41
@github-actions github-actions bot added documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file helm-chart Relates to helm chart labels Jul 23, 2024
@sarthyparty sarthyparty force-pushed the feature/tls-passthrough branch 2 times, most recently from 878a2d4 to 3298bb9 Compare July 23, 2024 19:45
@github-actions github-actions bot removed documentation Improvements or additions to documentation dependencies Pull requests that update a dependency file labels Jul 23, 2024
@github-actions github-actions bot removed the helm-chart Relates to helm chart label Jul 23, 2024
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Jul 23, 2024
@github-actions github-actions bot added the helm-chart Relates to helm chart label Jul 25, 2024
@sarthyparty sarthyparty marked this pull request as draft July 26, 2024 21:05
@sarthyparty sarthyparty marked this pull request as ready for review July 30, 2024 16:19
@github-actions github-actions bot removed the dependencies Pull requests that update a dependency file label Jul 30, 2024
@sjberman
Copy link
Contributor

sjberman commented Aug 7, 2024

I'm guessing the feature/tls-passthrough branch probably needs to be rebased on main if it hasn't recently, but does this work account for the fix in #2314 to ensure TLSRoutes are considered as well?

@kate-osborn
Copy link
Contributor

I'm guessing the feature/tls-passthrough branch probably needs to be rebased on main if it hasn't recently, but does this work account for the fix in #2314 to ensure TLSRoutes are considered as well?

It will after the rebase and some additional work. @sarthyparty is working on that now

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 7, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Aug 7, 2024
@sjberman
Copy link
Contributor

sjberman commented Aug 7, 2024

Before merging, can we give this PR a better title? Focus on the fact that it's related to TLSRoute

@kate-osborn
Copy link
Contributor

Before merging, can we give this PR a better title? Focus on the fact that it's related to TLSRoute

Yep, but keep in mind this is just going to be merged to the feature branch.

@sarthyparty sarthyparty changed the title add graph to dataplane conversion add support for TLS route Aug 7, 2024
Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving a partial review

internal/mode/static/nginx/config/maps.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/config/maps.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/config/maps_test.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/config/maps_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/tlsroute_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/tlsroute_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/tlsroute_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more test changes

internal/mode/static/nginx/config/stream_servers_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/gateway_listener.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/gateway_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common_test.go Outdated Show resolved Hide resolved
internal/mode/static/nginx/config/stream_servers_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/dataplane/configuration.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/gateway_listener.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/gateway_listener.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/gateway_test.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common.go Outdated Show resolved Hide resolved
internal/mode/static/state/graph/route_common.go Outdated Show resolved Hide resolved
Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀

@sindhushiv
Copy link
Contributor

Good Work @sarthyparty

@bjee19
Copy link
Contributor

bjee19 commented Aug 8, 2024

🚀 🚀 🎉 🎉

@sarthyparty sarthyparty merged commit eea2a72 into nginxinc:feature/tls-passthrough Aug 8, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request helm-chart Relates to helm chart
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

8 participants