-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Merging to release-5.10: [TT-15956] Proprietary auth methods are auto populated to OAS Security when changing to compliant mode (#7425) #7438
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
Conversation
…y when changing to compliant mode (#7425) <!-- Provide a general summary of your changes in the Title above --> When switching between Legacy and Compliant security processing modes, authentication methods are being incorrectly placed in security fields, causing proprietary auth (like customAuth) to appear in the OAS security section and preventing users from adding new auth methods. <!-- Describe your changes in detail --> https://tyktech.atlassian.net/browse/TT-15956?atlOrigin=eyJpIjoiNjE0ZGRmYWExNmExNGRiMmIyZDI3ZDJhOTRmNGFjZDMiLCJwIjoiaiJ9 <!-- 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-15956?atlOrigin=eyJpIjoiNjE0ZGRmYWExNmExNGRiMmIyZDI3ZDJhOTRmNGFjZDMiLCJwIjoiaiJ9 <!-- Why is this change required? What problem does it solve? --> <!-- 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. --> <!-- 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) <!-- 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 ___ Bug fix, Tests, Enhancement ___ - Separate proprietary vs standard auth storage - Add proprietary scheme detection helpers - Filter proprietary auth in legacy mode - Extensive tests for mixed auth scenarios ___ ```mermaid flowchart LR OAS["OAS.fillSecurity/extractSecurityTo"] Detect["Proprietary scheme detection helpers"] Split["Split into OAS security vs vendor security"] Legacy["Legacy mode filtering (storage only)"] Tests["New tests for detection and modes"] OAS -- "calls" --> Detect Detect -- "classify scheme" --> Split OAS -- "applies" --> Split OAS -- "applies" --> Legacy Split -- "verified by" --> Tests Legacy -- "verified by" --> Tests ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>security.go</strong><dd><code>Proprietary auth detection and security splitting</code> </dd></summary> <hr> apidef/oas/security.go <ul><li>Add helper methods to detect proprietary schemes.<br> <li> Use detection to split security into OAS vs vendor.<br> <li> Filter proprietary schemes in legacy mode storage.<br> <li> Adjust extraction to honor vendor security in compliant mode.</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7425/files#diff-15e7d47137452ca4f3f6139aa8c007cdb426152c41846f712f8bf5dfb607afcc">+135/-15</a></td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>security_test.go</strong><dd><code>Tests for auth separation and mode handling</code> </dd></summary> <hr> apidef/oas/security_test.go <ul><li>Add tests for proprietary scheme detection helpers.<br> <li> Update legacy mode to exclude proprietary from OAS.<br> <li> Add mode switching and mixed auth scenarios.<br> <li> Validate OAS vs vendor security separation.</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7425/files#diff-5184167309db0462243e424baca87b5bb668962d8cc1076629fdcf11f00487e5">+748/-10</a></td> </tr> </table></td></tr></tr></tbody></table> </details> ___ (cherry picked from commit 13aeda2)
🔍 Code Analysis ResultsChange Impact AnalysisWhat this PR accomplishesThis pull request resolves a critical bug where Tyk-proprietary authentication methods (e.g., HMAC, custom plugins) were incorrectly bleeding into the standard OpenAPI Specification (OAS) The solution establishes a strict and permanent separation between standard OAS-compliant security schemes and Tyk's proprietary ones. Proprietary schemes are now exclusively managed within the Additionally, a new validation layer is introduced for "compliant" mode, which prevents misconfigurations by ensuring any enabled authentication method is explicitly listed in a security requirement. Key Technical Changes
Affected System Components
Architecture VisualizationThe following diagrams illustrate the key architectural changes introduced by this pull request. 1. Authentication Scheme Segregation FlowThis diagram shows how the updated flowchart TD
subgraph "Tyk API Definition"
A["Security Requirements: [jwt], [hmac, basic]"]
end
subgraph "OAS Processing Logic (fillSecurity)"
B{For each requirement}
C{Contains proprietary scheme?}
B --> C
C -- Yes --> D[Move ENTIRE requirement to Vendor Extension]
C -- No --> E[Add requirement to OAS Security]
end
subgraph "Final OAS Document"
F["OAS `security` field"]
G["`x-tyk-api-gateway.security` field"]
end
A --> B
D --> G
E --> F
style F fill:#d4edda,stroke:#c3e6cb
style G fill:#f8d7da,stroke:#f5c6cb
Explanation: The logic iterates through each security requirement. The 2. Compliant Mode Validation SequenceThis diagram illustrates the new validation process that runs when an API definition is saved in "compliant" mode. sequenceDiagram
participant Client
participant TykGateway as Tyk Gateway
participant OAS_Validator as OAS Validator
participant TykExtension as "x-tyk-api-gateway"
Client->>TykGateway: Save API Definition (Compliant Mode)
TykGateway->>OAS_Validator: Validate()
OAS_Validator->>TykExtension: Get all enabled auth schemes (e.g., JWT, HMAC)
OAS_Validator->>OAS_Validator: Collect schemes from OAS `security`
OAS_Validator->>TykExtension: Collect schemes from vendor `security`
OAS_Validator->>OAS_Validator: For each enabled scheme...
alt Is scheme configured in a security requirement?
OAS_Validator-->>OAS_Validator: Yes, continue
else No, it's misconfigured
OAS_Validator-->>TykGateway: Return Validation Error
TykGateway-->>Client: Reject with Error ("hmac auth enabled but not configured")
end
OAS_Validator-->>TykGateway: Validation Success
TykGateway-->>Client: Acknowledge Success
Explanation: This flow ensures that if a developer enables an authentication method like HMAC in the Tyk extension, they cannot forget to add it to a security requirement. This prevents "dead" or misconfigured authentication rules and improves the reliability of multi-auth APIs. Powered by Visor from Probelabs Last updated: 2025-10-11T14:48:16.099Z | Triggered by: synchronize | Commit: 3ced380 |
🔍 Code Analysis ResultsSecurity Issues (2)
Performance Issues (4)
Quality Issues (4)
Style Issues (2)
✅ Dependency Check PassedNo dependency issues found – changes LGTM. ✅ Connectivity Check PassedNo connectivity issues found – changes LGTM. Powered by Visor from Probelabs Last updated: 2025-10-11T14:48:17.339Z | Triggered by: synchronize | Commit: 3ced380 |
PR Code Suggestions ✨Explore these optional code suggestions:
|
User description
TT-15956 Proprietary auth methods are auto populated to OAS Security when changing to compliant mode (#7425)
User description
Description
When switching between Legacy and Compliant security processing modes,
authentication methods are being incorrectly placed in security fields,
causing proprietary auth (like customAuth) to appear in the OAS security
section and preventing users from adding new auth methods.
Related Issue
https://tyktech.atlassian.net/browse/TT-15956?atlOrigin=eyJpIjoiNjE0ZGRmYWExNmExNGRiMmIyZDI3ZDJhOTRmNGFjZDMiLCJwIjoiaiJ9
Motivation and Context
https://tyktech.atlassian.net/browse/TT-15956?atlOrigin=eyJpIjoiNjE0ZGRmYWExNmExNGRiMmIyZDI3ZDJhOTRmNGFjZDMiLCJwIjoiaiJ9
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
functionality to change)
coverage to functionality)
Checklist
why it's required
explained why
PR Type
Bug fix, Tests, Enhancement
Description
Separate proprietary vs standard auth storage
Add proprietary scheme detection helpers
Filter proprietary auth in legacy mode
Extensive tests for mixed auth scenarios
Diagram Walkthrough
File Walkthrough
security.go
Proprietary auth detection and security splitting
apidef/oas/security.go
security_test.go
Tests for auth separation and mode handling
apidef/oas/security_test.go
PR Type
Bug fix, Enhancement, Tests
Description
Validate compliant-mode auth configuration
Split OAS vs vendor auth consistently
Filter proprietary auth in legacy storage
Add extensive auth mode tests
Diagram Walkthrough
File Walkthrough
oas.go
Compliant-mode authentication validation in OAS
apidef/oas/oas.go
security.go
Security splitting and proprietary detection
apidef/oas/security.go
oas_test.go
Tests for compliant-mode auth validation
apidef/oas/oas_test.go
security_test.go
Comprehensive tests for auth separation and modes
apidef/oas/security_test.go
mw_auth_or_wrapper_test.go
Fix expected status in compliant-mode test
gateway/mw_auth_or_wrapper_test.go