feat: support downstream TLS for Web App resources - #422
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #422 +/- ##
==========================================
+ Coverage 90.63% 90.70% +0.07%
==========================================
Files 41 41
Lines 2903 2915 +12
==========================================
+ Hits 2631 2644 +13
+ Misses 180 177 -3
- Partials 92 94 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Parse the tls flag in the GAT token's gateway_metadata.downstream and run the inner TLS upgrade for Web App connections when it is set, presenting the gateway certificate — the same mechanism Kubernetes connections use. The fake Twingate client gains a WithDownstreamTLS option and tools/local runs an extra Web App client with it for local HTTPS testing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X9Z4JjodvSrpkMw964Lcgx
2fd6a3b to
35f17f5
Compare
There was a problem hiding this comment.
Pull request overview
Adds support for terminating downstream TLS for Web App resources based on a new gateway_metadata.downstream.tls flag carried in the GAT, aligning Web App handling with the existing “inner TLS upgrade” path used for Kubernetes connections. Also extends local dev tooling to exercise both plaintext and TLS-enforced Web App flows.
Changes:
- Extend GAT claims with
gateway_metadata.downstream.tlsand include Web App resources inShouldUpgradeTLS()when the flag is set. - Add a
WithDownstreamTLS()option to the fake client and run an additional local Web App client configured for HTTPS testing. - Fix local gateway config template to use
webApp.requestHeaders(matching the existing config schema).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tools/local/main.go | Runs an additional fake Web App client for downstream TLS and updates local config/output instructions accordingly. |
| test/fake/client.go | Adds a client option to mark downstream TLS in the generated GAT and switch the downstream port to 443. |
| internal/token/gat_claims.go | Adds Downstream.TLS to GAT claims and updates TLS-upgrade decision logic for Web App resources. |
| internal/token/gat_claims_test.go | Expands unit tests to cover the new Web App TLS-upgrade behavior and JSON unmarshalling of the new flag. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This pull request is stale because it has been open 5 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
internal/token/gat_claims_test.go:48
- These cases only verify the metadata flag and the
ShouldUpgradeTLSboolean; they never exercise a Web App connection through the listener and HTTP proxy with the inner TLS handshake. A regression in the actual termination/routing path could therefore pass these tests. Please add an integration (or equivalent end-to-end) case that usesWithDownstreamTLS, truststls.crt, and verifies the proxied response and headers.
name: "Web app with downstream TLS should upgrade TLS",
resourceType: ResourceTypeWebApp,
downstreamTLS: true,
expected: true,
|
It seems that the gateway needs to add Without With: |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Suppressed comments (2)
internal/token/gat_claims.go:98
- This branch is what makes the existing listener perform the second TLS handshake, but the added tests only assert the boolean/header and the integration test still exercises a plaintext Web App. Add an end-to-end Web App case with
downstream.tls=truethat sends an inner TLS request and verifies the proxied response; otherwise the actual TLS termination/routing path can regress while these tests pass.
case ResourceTypeWebApp:
return p.Resource.GatewayMetadata.Downstream.TLS
test/integration/web_app_test.go:122
- The new TLS behavior is not exercised by this integration test: it still creates only the plaintext Web App client and only verifies
X-Forwarded-Proto: http. A regression in the inner TLS handshake, gateway certificate presentation, or routing of the decrypted request would therefore pass the suite. Add a TLS-enabled fake client and an HTTPS request that truststest/data/proxy/tls.crt, asserting the response andX-Forwarded-Proto: https.
// Downstream scheme
"X-Forwarded-Proto": "http",
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
internal/token/gat_claims.go:98
- The new Web App path is only exercised by the
ShouldUpgradeTLSand header-rewrite unit tests; the integration test still sends onlyhttp://..., so no test drives the listener's second TLS handshake and HTTP server with a GAT containingdownstream.tls: true. Please add an HTTPS Web App integration case and assert the proxied response (includingX-Forwarded-Proto) to cover the end-to-end behavior advertised by this change.
return p.Resource.GatewayMetadata.Downstream.TLS
Related Tickets & Documents
Changes
tlsflag in the GAT token'sgateway_metadata.downstream; tokens without the flag keep today's plaintext behavior.X-Forwarded-Protowith the downstream scheme before forwarding the requestWithDownstreamTLS()option andtools/localruns an extra Web App client with it, testable viacurl --cacert ./test/data/proxy/tls.crt https://<client-address>.