Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TT-13186/TT-13199] implement upstream basic authentication (#6596)
### **User description** <details open> <summary><a href="https://tyktech.atlassian.net/browse/TT-13199" title="TT-13199" target="_blank">TT-13199</a></summary> <br /> <table> <tr> <th>Summary</th> <td>Implement upstream basic authentication as a gateway middleware</td> </tr> <tr> <th>Type</th> <td> <img alt="Sub-task" src="https://tyktech.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10316?size=medium" /> Sub-task </td> </tr> <tr> <th>Status</th> <td>In Dev</td> </tr> <tr> <th>Points</th> <td>N/A</td> </tr> <tr> <th>Labels</th> <td>-</td> </tr> </table> </details> <!-- do not remove this marker as it will break jira-lint's functionality. added_by_jira_lint --> --- <!-- Provide a general summary of your changes in the Title above --> ## Description Implement upstream basic authentication as a middleware. Now users can configure upstream authentication using basic auth in - `upstream_auth.basic_auth` in Tyk classic API def. - `upstream.authentication.basicAuth` in Tyk OAS API def. ## Related Issue Parent: https://tyktech.atlassian.net/browse/TT-13186 Subtask: https://tyktech.atlassian.net/browse/TT-13199 ## 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 ___ ### **PR Type** Enhancement, Tests ___ ### **Description** - Implemented upstream basic authentication as a middleware, allowing users to configure authentication using basic auth in Tyk API definitions. - Added `UpstreamAuth` and `UpstreamBasicAuth` structs to manage authentication details. - Integrated upstream authentication into the OAS upstream configuration and reverse proxy handling. - Developed `UpstreamBasicAuth` middleware to handle basic authentication for upstream connections. - Added comprehensive tests to verify the functionality of the `UpstreamBasicAuth` middleware. ___ ### **Changes walkthrough** 📝 <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>api_definitions.go</strong><dd><code>Add upstream authentication structures and methods</code> </dd></summary> <hr> apidef/api_definitions.go <li>Added <code>UpstreamAuth</code> struct to store upstream authentication <br>information.<br> <li> Introduced <code>UpstreamBasicAuth</code> struct for basic authentication details.<br> <li> Added methods to check if upstream authentication is enabled.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6596/files#diff-9961ccc89a48d32db5b47ba3006315ef52f6e5007fb4b09f8c5d6d299c669d67">+19/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>upstream.go</strong><dd><code>Integrate upstream authentication into OAS upstream configuration</code></dd></summary> <hr> apidef/oas/upstream.go <li>Added <code>Authentication</code> field to <code>Upstream</code> struct for upstream <br>authentication configuration.<br> <li> Implemented methods to fill and extract authentication data.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6596/files#diff-7b0941c7f37fe5a2a23047e0822a65519ca11c371660f36555b59a60f000e3f4">+78/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>ctx.go</strong><dd><code>Add context management for upstream authentication</code> </dd></summary> <hr> ctx/ctx.go <li>Added constants for upstream authentication header and value.<br> <li> Implemented functions to set and get upstream authentication header <br>and value.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6596/files#diff-600f5f552779994b15324fda108549eec7e7be30b1d8a1a16ee8344243e0cbc7">+35/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>api_loader.go</strong><dd><code>Append UpstreamBasicAuth middleware to chain</code> </dd></summary> <hr> gateway/api_loader.go - Appended `UpstreamBasicAuth` middleware to the middleware chain. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6596/files#diff-cdf0b7f176c9d18e1a314b78ddefc2cb3a94b3de66f1f360174692c915734c68">+2/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>mw_upstream_basic_auth.go</strong><dd><code>Implement UpstreamBasicAuth middleware for basic authentication</code></dd></summary> <hr> gateway/mw_upstream_basic_auth.go <li>Implemented <code>UpstreamBasicAuth</code> middleware for basic authentication.<br> <li> Added logic to inject basic auth info into request context.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6596/files#diff-ba603a8b249fdf72522258e825b7f9c64064203129c167795b206d66e9ebcda7">+49/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>reverse_proxy.go</strong><dd><code>Integrate upstream authentication into reverse proxy</code> </dd></summary> <hr> gateway/reverse_proxy.go <li>Added method to add authentication info to outgoing requests.<br> <li> Integrated upstream authentication into request handling.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6596/files#diff-e6e07722257f7e41691e471185ad6d84fd56dc9e5459526ea32e9a5e8fa1a01b">+16/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>mw_upstream_basic_auth_test.go</strong><dd><code>Add tests for UpstreamBasicAuth middleware functionality</code> </dd></summary> <hr> gateway/mw_upstream_basic_auth_test.go <li>Added tests for <code>UpstreamBasicAuth</code> middleware.<br> <li> Verified basic authentication with default and custom headers.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6596/files#diff-15f78fac7fd4c8c0a1dcbd86ac6068e5a1a39f948f40afba6a6081e5f90f0ecd">+143/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>http.go</strong><dd><code>Add TestCases type for test management</code> </dd></summary> <hr> test/http.go - Introduced `TestCases` type for managing multiple test cases. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6596/files#diff-a5530e34c740ce6fe2efe8dda5a356463c450696b39b97b91228f1be2491e05e">+1/-0</a> </td> </tr> </table></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull request to receive relevant information
- Loading branch information