sync with master#7533
Conversation
# Summary Fixes mTLS authentication when certificate chains are used and improves certificate matching to support hosts with port numbers. # Problem ## Issue 1 - Certificate Chains Broken: When a certificate chain (containing both leaf certificate and CA certificate) was configured for mTLS, the system incorrectly added the entire chain, including the leaf certificate, to the CA pool. This caused TLS handshake failures because leaf certificates should be verified against the CA pool, not added to it. ## Issue 2 - Port Handling: Certificate matching failed when the target host included a port number (e.g., api.example.com:8443). Configuratio entries like "api.example.com": "cert-id" would not match requests to api.example.com:8443. # Solution ## 1. Certificate Chain Handling Created a new helper function `AddCACertificatesFromChainToPool()` that intelligently extracts only CA certificates from chains: - For certificate chains (length > 1): Skips index 0 (leaf cert) and adds only certificates where IsCA=true - For single certificates (length = 1): Maintains backward compatibility by adding the certificate regardless of IsCA flag (supports certificate pinning) Updated two critical locations to use this function: - `certs/manager.go:601` - Certificate pool management - `gateway/cert.go:466` - Client CA configuration for mTLS APIs ## 2. Port Handling Refactored certificate matching logic into a testable function getCertificateIDForHost() that: - Uses Go's `net.SplitHostPort()` to properly handle hosts with ports - Implements priority-based matching (most specific match wins) - Supports IPv4, IPv6, and hostnames with or without ports Matching Priority (low to high): 1. `*` (wildcard) 2. `*.example.com:8443` (wildcard with port) 3. `*.example.com` (wildcard without port) 4. `example.com` (exact without port) 5. `example.com:8443` (exact with port - highest priority) # Changes - `internal/crypto/helpers.go` - New AddCACertificatesFromChainToPool() function - `internal/crypto/helpers_test.go` - 8 unit tests for chain handling - `gateway/cert.go` - Refactored certificate matching with port support - `gateway/cert_test.go` - 20 new unit tests + end-to-end mTLS test with chains - `certs/manager.go` - Updated to use new chain handling function ## Backward Compatibility ✅ Fully backward compatible: - Existing certificate configurations (with or without ports) continue to work - Single certificate configurations unchanged - Certificate chains now work correctly (previously broken) - No configuration migration required # Reviewer Focus Areas ## Critical: 1. internal/crypto/helpers.go:156-212 - Core certificate chain extraction logic 2. End-to-end test in gateway/cert_test.go:2203-2309 - Validates the fix works ## Important: 3. gateway/cert.go:72-138 - Certificate matching with priority handling 4. Port handling logic using net.SplitHostPort() ## Security Considerations - Follows TLS RFC 5246 (leaf certificate at index 0 in chains) - Only certificates with IsCA=true are added to CA pools - More specific certificate matches override general wildcards - Comprehensive negative testing ensures invalid clients are rejected <!---TykTechnologies/jira-linter starts here--> ### Ticket Details <details> <summary> <a href="https://tyktech.atlassian.net/browse/TT-15606" title="TT-15606" target="_blank">TT-15606</a> </summary> | | | |---------|----| | Status | In Dev | | Summary | Tyk mTLS Advertises Leaf Subject DNs Instead of CA DNs | Generated at: 2025-11-06 09:42:00 </details> <!---TykTechnologies/jira-linter ends here-->
<!-- Provide a general summary of your changes in the Title above --> ## Description <!-- Describe your changes in detail --> ## Related Issue <!-- This project only accepts pull requests related to open issues. --> <!-- If suggesting a new feature or change, please discuss it in an issue first. --> <!-- If fixing a bug, there should be an issue describing it with steps to reproduce. --> <!-- OSS: Please link to the issue here. Tyk: please create/link the JIRA ticket. --> ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why <!---TykTechnologies/jira-linter starts here--> ### Ticket Details <details> <summary> <a href="https://tyktech.atlassian.net/browse/TT-15793" title="TT-15793" target="_blank">TT-15793</a> </summary> | | | |---------|----| | Status | In Dev | | Summary | Implement Intelligent Branch Merge Recommendations | Generated at: 2025-11-05 14:15:34 </details> <!---TykTechnologies/jira-linter ends here--> Co-authored-by: sredny buitrago <sredny@srednys-MacBook-Pro.local>
Implements TT-15473
The Tyk Gateway's OpenAPI specifications didn't accurately reflect how
to access versioned APIs. Server URLs in the OAS didn't show:
- Correct paths for versioned child APIs
- Versioning methods (URL path, query param, header)
- How to actually invoke different API versions
This created inconsistency between the Gateway and Dashboard and
provided inaccurate API documentation to users.
### What This PR Does
This PR implements proper OpenAPI server URL generation in the Gateway,
ensuring that the OAS specifications accurately reflect how APIs can be
accessed. This brings the Gateway's behavior in line with the Dashboard
implementation.
### Key Features
1. Accurate Server URLs for All Versioning Methods
- URL path versioning: http://host/api/v2
- Query parameter versioning: http://host/api?version=v2
- Header versioning: http://host/api (version in header)
2. Proper Handling of Internal vs External APIs
- Internal child APIs: Only show base API path with version
- External child APIs: Show both versioned and direct access paths
3. Automatic Updates
- When a base API's versioning configuration changes, all child API
server URLs are updated automatically
- Ensures consistency across all loaded API specifications
4. Preserves User Customizations
- User-provided server entries in OpenAPI specs are preserved
- Only Tyk-generated URLs are updated/regenerated
<!---TykTechnologies/jira-linter starts here-->
### Ticket Details
<details>
<summary>
<a href="https://tyktech.atlassian.net/browse/TT-15473" title="TT-15473"
target="_blank">TT-15473</a>
</summary>
| | |
|---------|----|
| Status | In Dev |
| Summary | [BE] Improve visibility of the API version identifier |
Generated at: 2025-11-05 18:50:32
</details>
<!---TykTechnologies/jira-linter ends here-->
) <!-- Provide a general summary of your changes in the Title above --> ## Description This PR adds validation to prevent creating or updating APIs with load balancing enabled where all targets have weight 0. Previously, this configuration would be accepted but cause runtime errors (index out of range) when traffic was sent to the API. The new RuleLoadBalancingTargets validation rule is added to the DefaultValidationRuleSet and checks if load balancing is enabled with an empty targets list (which occurs when all weights are 0). The validation triggers on both Classic and OAS API endpoints (POST/PUT) and returns a clear HTTP 400 error: "all load balancing targets have weight 0, at least one target must have weight > 0". This catches the edge case at API configuration time rather than failing at request time, improving the developer experience and preventing invalid configurations from being saved. <!-- Describe your changes in detail --> ## Related Issue <!-- This project only accepts pull requests related to open issues. --> <!-- If suggesting a new feature or change, please discuss it in an issue first. --> <!-- If fixing a bug, there should be an issue describing it with steps to reproduce. --> <!-- OSS: Please link to the issue here. Tyk: please create/link the JIRA ticket. --> ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why <!---TykTechnologies/jira-linter starts here--> ### Ticket Details <details> <summary> <a href="https://tyktech.atlassian.net/browse/TT-15595" title="TT-15595" target="_blank">TT-15595</a> </summary> | | | |---------|----| | Status | In Dev | | Summary | Temporarily remove upstream target from load balancing | Generated at: 2025-11-07 15:07:19 </details> <!---TykTechnologies/jira-linter ends here-->
<!-- Provide a general summary of your changes in the Title above --> ## Description This PR fixes TT-14359 by adding support for nested JWT claims in the JWTIdentityBaseField and JWTPolicyFieldName configuration fields, allowing users to specify claim paths like user.id or authorization.policy to extract values from nested JSON structures in JWT tokens. The implementation maintains full backward compatibility by first checking for literal claim keys (including keys that contain actual dots in their names) before attempting nested lookup, and includes proper fallback behavior to the sub claim when nested identity fields are not found. The changes extend the existing nestedMapLookup function (previously only used for scopes) to also support identity base field and policy field resolution, with comprehensive test coverage including single-level nesting, multi-level nesting, fallback scenarios, empty string handling, non-string value handling, multiple policy claim priority, backward compatibility verification, and the specific customer scenario from the ticket where claims are nested under a test object. <!-- Describe your changes in detail --> ## Related Issue <!-- This project only accepts pull requests related to open issues. --> <!-- If suggesting a new feature or change, please discuss it in an issue first. --> <!-- If fixing a bug, there should be an issue describing it with steps to reproduce. --> <!-- OSS: Please link to the issue here. Tyk: please create/link the JIRA ticket. --> ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why <!---TykTechnologies/jira-linter starts here--> ### Ticket Details <details> <summary> <a href="https://tyktech.atlassian.net/browse/TT-14359" title="TT-14359" target="_blank">TT-14359</a> </summary> | | | |---------|----| | Status | In Refinement | | Summary | Support nested locations for JWT policy and subject claims | Generated at: 2025-11-07 11:26:52 </details> <!---TykTechnologies/jira-linter ends here-->
…PI (#7532) ## Description Exposese `GenerateTykServers` so that Dashboard can use it when generating the tyk OAS urls and return them via /api/apis/oas/{:apiId}/urls implemented here TykTechnologies/tyk-analytics#5030 ## Related Issue <!-- This project only accepts pull requests related to open issues. --> <!-- If suggesting a new feature or change, please discuss it in an issue first. --> <!-- If fixing a bug, there should be an issue describing it with steps to reproduce. --> <!-- OSS: Please link to the issue here. Tyk: please create/link the JIRA ticket. --> ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why <!---TykTechnologies/jira-linter starts here--> ### Ticket Details <details> <summary> <a href="https://tyktech.atlassian.net/browse/TT-16109" title="TT-16109" target="_blank">TT-16109</a> </summary> | | | |---------|----| | Status | In Dev | | Summary | Add a new Dashboard API endpoint to retrieve Tyk-generated URLs from Tyk OAS API definitions | Generated at: 2025-11-11 12:05:08 </details> <!---TykTechnologies/jira-linter ends here-->
…e-to-policy mapping is used (#7504) <!-- Provide a general summary of your changes in the Title above --> ## Description - Added tests to validate JWT authentication behavior with only scope-to-policy mapping and no default policies. - Included scenarios for valid and invalid scopes, as well as cases with multiple scopes. - Enhanced existing JWT processing logic to ensure proper handling of cases with no default policies configured. - Ensured backward compatibility with existing behavior when default policies are present. This update improves test coverage and ensures the system behaves as expected under various JWT configurations. <!-- Describe your changes in detail --> ## Related Issue <!-- This project only accepts pull requests related to open issues. --> <!-- If suggesting a new feature or change, please discuss it in an issue first. --> <!-- If fixing a bug, there should be an issue describing it with steps to reproduce. --> <!-- OSS: Please link to the issue here. Tyk: please create/link the JIRA ticket. --> https://tyktech.atlassian.net/browse/TT-6613 ## Motivation and Context https://tyktech.atlassian.net/browse/TT-6613 <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> Manual testing and integration tests ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why <!---TykTechnologies/jira-linter starts here--> ### Ticket Details <details> <summary> <a href="https://tyktech.atlassian.net/browse/TT-6613" title="TT-6613" target="_blank">TT-6613</a> </summary> | | | |---------|----| | Status | Ready for Testing | | Summary | JWT authentication should not require a base policy if scope-to-policy mapping is used | Generated at: 2025-11-11 11:58:13 </details> <!---TykTechnologies/jira-linter ends here-->
56859de
into
fix/pipline-build-errors-TT-16060
🚨 Jira Linter FailedCommit: The Jira linter failed to validate your PR. Please check the error details below: 🔍 Click to view error detailsNext Steps
This comment will be automatically deleted once the linter passes. |
|
API Changes no api changes detected |
🔍 Code Analysis ResultsThis pull request, despite its title, is not a simple synchronization but a major feature and enhancement release. It introduces significant improvements to OAS API management, JWT authentication, and mTLS certificate handling. Files Changed AnalysisThe changes are substantial, with 6 new files added and 16 files modified. The vast majority of the 6266 new lines are dedicated to new functionality and comprehensive test suites, particularly for OAS server regeneration and JWT nested claims. The changes are concentrated in core gateway components:
Architecture & Impact AssessmentWhat this PR accomplishesThis PR delivers several key enhancements:
Key Technical Changes
Affected System Components
Scope Discovery & Context ExpansionThe scope of this PR is extensive and touches multiple core functionalities:
Metadata
Powered by Visor from Probelabs Last updated: 2025-11-11T15:38:10.939Z | Triggered by: opened | Commit: 6cc0c35 💡 TIP: You can chat with Visor using |
🔍 Code Analysis ResultsSecurity Issues (1)
Architecture Issues (1)
Performance Issues (1)
Quality Issues (3)
Dependency Issues (7)
✅ Connectivity Check PassedNo connectivity issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2025-11-11T15:38:12.010Z | Triggered by: opened | Commit: 6cc0c35 💡 TIP: You can chat with Visor using |
No description provided.