fix(ssl): inherit upstream ssl ctx from main request in subrequests - #121
Closed
tzssangglass wants to merge 2 commits into
Closed
fix(ssl): inherit upstream ssl ctx from main request in subrequests#121tzssangglass wants to merge 2 commits into
tzssangglass wants to merge 2 commits into
Conversation
`ngx_http_lua_kong_set_upstream_ssl` is invoked with the request that initiates the upstream connection. For requests issued via `ngx.location.capture`, this is the subrequest, whose module ctx is not initialized even when the main request has configured upstream SSL via `resty.kong.tls.set_upstream_cert_and_key` and friends. Fall back to `r->main`'s ctx when the current (sub)request has none, so SSL overrides set on the main request propagate to subrequests' upstream handshakes. Fix: [FTI-7709](https://konghq.atlassian.net/browse/FTI-7709)
There was a problem hiding this comment.
Pull request overview
This PR fixes upstream TLS override behavior for subrequests created via ngx.location.capture by allowing ngx_http_lua_kong_set_upstream_ssl to reuse the main request’s ngx_http_lua_kong_module context when the subrequest has none, ensuring upstream client cert/key overrides propagate to subrequest handshakes.
Changes:
- Update upstream-SSL hook to fall back to
r->mainmodule ctx whenrhas no ctx (subrequest case). - Add a regression test that sets upstream cert/key in the main request and verifies the subrequest handshake presents the expected client certificate.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/ngx_http_lua_kong_ssl.c |
Falls back to the main request’s module ctx so upstream SSL overrides apply to subrequests. |
t/002-upstream-tls.t |
Adds a test validating main-request upstream cert/key settings are inherited by ngx.location.capture subrequests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ngx_http_lua_kong_set_upstream_sslis invoked with the request that initiates the upstream connection. For requests issued viangx.location.capture, this is the subrequest, whose module ctx is not initialized even when the main request has configured upstream SSL viaresty.kong.tls.set_upstream_cert_and_keyand friends.Fall back to
r->main's ctx when the current (sub)request has none, so SSL overrides set on the main request propagate to subrequests' upstream handshakes.Fix: FTI-7709