[TT-16050]: Added key use in dynamic mtls behind insecure flag - #7682
Conversation
|
This PR introduces a security enhancement for dynamic mTLS by adding a new configuration flag, Files Changed Analysis
Architecture & Impact Assessment
graph TD
A[Request Received] --> B{API uses dynamic mTLS?};
B -- No --> C[Proceed with other auth];
B -- Yes --> D{Is `allow_unsafe_dynamic_mtls_token` true?};
D --|No (Secure Default)|--> E{Client Certificate Present?};
E -- Yes --> F[Validate Certificate & Proceed];
E -- No --> G[Reject: 401 Unauthorized - Cert Required];
D --|Yes (Insecure Mode)|--> H{Token OR Certificate Present?};
H -- Yes --> I[Validate Credentials & Proceed];
H -- No --> J[Reject Request];
Scope Discovery & Context Expansion
Metadata
Powered by Visor from Probelabs Last updated: 2026-01-30T12:51:00.403Z | Triggered by: pr_updated | Commit: 8455940 💡 TIP: You can chat with Visor using |
|
API Changes --- prev.txt 2026-01-30 12:49:08.270714543 +0000
+++ current.txt 2026-01-30 12:48:58.059643516 +0000
@@ -7287,6 +7287,11 @@
// Specify public keys used for Certificate Pinning on global level.
PinnedPublicKeys map[string]string `json:"pinned_public_keys"`
+ // AllowUnsafeDynamicMTLSToken controls whether certificate presence is required for
+ // dynamic mTLS authentication. If set to false (default), requests with a token but
+ // no certificate will be rejected for APIs using dynamic mTLS.
+ AllowUnsafeDynamicMTLSToken bool `json:"allow_unsafe_dynamic_mtls_token"`
+
Certificates CertificatesConfig `json:"certificates"`
// CertificateExpiryMonitor configures the certificate expiry monitoring and notification feature
@@ -9070,6 +9075,7 @@
const (
MsgAuthFieldMissing = "Authorization field missing"
MsgApiAccessDisallowed = "Access to this API has been disallowed"
+ MsgAuthCertRequired = "Client certificate required"
MsgBearerMailformed = "Bearer token malformed"
MsgKeyNotAuthorized = "Key not authorised"
MsgOauthClientRevoked = "Key not authorised. OAuth client access was revoked"
@@ -9104,8 +9110,9 @@
ErrAuthKeyNotFound = "auth.key_not_found"
ErrAuthCertNotFound = "auth.cert_not_found"
ErrAuthCertExpired = "auth.cert_expired"
- ErrAuthCertMismatch = "auth.cert_mismatch"
ErrAuthKeyIsInvalid = "auth.key_is_invalid"
+ ErrAuthCertRequired = "auth.cert_required"
+ ErrAuthCertMismatch = "auth.cert_mismatch"
MsgNonExistentKey = "Attempted access with non-existent key."
MsgNonExistentCert = "Attempted access with non-existent cert." |
✅ Security Check PassedNo security issues found – changes LGTM. Architecture Issues (2)
Performance Issues (1)
Quality Issues (1)
Powered by Visor from Probelabs Last updated: 2026-01-30T12:51:03.132Z | Triggered by: pr_updated | Commit: 8455940 💡 TIP: You can chat with Visor using |
79ddf8a to
fc295ce
Compare
7f7777d to
b0609b6
Compare
b0609b6 to
dd4a15e
Compare
dd4a15e to
35a1af8
Compare
35a1af8 to
8455940
Compare
|
|
/release to release-5.8 |
|
|
…ind insecure flag (#7682) (#7750) ### **User description** Cherry-pick of `ebf13c17fb4611480d8b3e97dd9bda0b93b31845` from `master` to `release-5.8` requires manual resolution. **Conflicts detected:** 7 - gateway/mw_auth_key.go - gateway/mw_auth_key_certificate_binding_test.go - gateway/mw_auth_key_mtls_combined_test.go Tips: - Check out this branch locally and run: `git cherry-pick -x ebf13c1` - Resolve conflicts (including submodules if any), then push back to this branch. Original commit: ebf13c1 ___ ### **PR Type** Enhancement, Bug fix, Tests ___ ### **Description** - Add flag for unsafe dynamic mTLS - Enforce cert-required/mismatch 401 responses - Refactor dynamic mTLS session lookup logic - Update tests and config schema ___ ### Diagram Walkthrough ```mermaid flowchart LR cfg["`SecurityConfig.AllowUnsafeDynamicMTLSToken` flag"] mw["`gateway/mw_auth_key.go` dynamic mTLS flow"] errs["New auth errors: cert required/mismatch"] schema["`cli/linter/schema.json` config schema"] tests["Updated gateway tests (401 vs 403)"] cfg -- "controls" --> mw mw -- "returns 401 with messages" --> errs cfg -- "validated by" --> schema mw -- "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>Configuration changes</strong></td><td><table> <tr> <td> <details> <summary><strong>config.go</strong><dd><code>Add config flag for dynamic mTLS behavior</code> </dd></summary> <hr> config/config.go <ul><li>Add <code>SecurityConfig.AllowUnsafeDynamicMTLSToken</code><br> <li> Document default cert-required enforcement</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7750/files#diff-fe44f09c4d5977b5f5eaea29170b6a0748819c9d02271746a20d81a5f3efca17">+5/-0</a> </td> </tr> <tr> <td> <details> <summary><strong>schema.json</strong><dd><code>Expose unsafe dynamic mTLS flag in schema</code> </dd></summary> <hr> cli/linter/schema.json - Add `allow_unsafe_dynamic_mtls_token` boolean property </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7750/files#diff-103cec746d3e61d391c5a67c171963f66fea65d651d704d5540e60aa5d574f46">+3/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>auth_manager_test.go</strong><dd><code>Align auth tests with 401 responses</code> </dd></summary> <hr> gateway/auth_manager_test.go - Change expected status from 403 to 401 </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7750/files#diff-665d567ebb80f4c7bb6c683cc8ad317928a10b450468634506012a20a54153c9">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>cert_test.go</strong><dd><code>Update cert tests for unsafe mTLS flag</code> </dd></summary> <hr> gateway/cert_test.go <ul><li>Set <code>Security.AllowUnsafeDynamicMTLSToken = true</code><br> <li> Update “cert unknown” expectations to 401</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7750/files#diff-481696cb18de8c3880e0ca21318fe00fd4eb89bc48994e43b7c34729ef4a7ee2">+5/-4</a> </td> </tr> </table></td></tr><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>handler_error.go</strong><dd><code>Add client certificate required error message</code> </dd></summary> <hr> gateway/handler_error.go - Introduce `MsgAuthCertRequired` constant </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7750/files#diff-d3b05530ad23401f3b8f33bb1a467cd807a29a6b09c7430d01d069f626b20f77">+1/-0</a> </td> </tr> </table></td></tr><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>mw_auth_key.go</strong><dd><code>Gate dynamic mTLS token usage behind flag</code> </dd></summary> <hr> gateway/mw_auth_key.go <ul><li>Add <code>ErrAuthCertRequired</code> and <code>ErrAuthCertMismatch</code><br> <li> Map new errors to 401 responses<br> <li> Add <code>checkSessionWithCertFallback</code> helper<br> <li> Enforce cert presence unless flag enabled</ul> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/7750/files#diff-aeba053023a54c723dd9f83837e29ca0b2d9a212bc98fa6ad4bbb062669a1cf0">+72/-20</a> </td> </tr> </table></td></tr></tr></tbody></table> </details> ___ Co-authored-by: Kofo Okesola <okesolakofo@gmail.com>



Description
TT-16050
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
Ticket Details
TT-16050
Generated at: 2026-01-30 12:48:18