-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix: Add mutual TLS support for dedicated rate limiter Redis connection #7301
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
base: master
Are you sure you want to change the base?
Conversation
## Problem The dedicated Redis connection for the rate limiter (when configured with `rate_limiter.storage.type: redis`) was not properly implementing mutual TLS authentication. When `UseSSL` was enabled, the code only set `InsecureSkipVerify` and ignored the client certificate configuration (`CertFile`, `KeyFile`, `CAFile`). This created a security vulnerability where even if administrators configured mTLS for all Redis connections, the rate limiter's dedicated connection would bypass these security controls. ## Solution Enhanced the `NewStorage` function in `internal/rate/storage.go` to properly handle TLS configuration with full mutual TLS support: - Added `createTLSConfig` helper function that loads CA certificates, client certificates, and keys - Added support for TLS version configuration (`TLSMinVersion`, `TLSMaxVersion`) - Properly handles certificate loading errors with appropriate logging - Maintains backward compatibility with existing configurations ## Testing - Added comprehensive unit tests for all TLS configuration scenarios - Tests cover: basic SSL, mTLS, CA certificates, TLS versions, and error cases - All existing rate limiter tests continue to pass ## Impact This fix ensures that when administrators configure mutual TLS for Redis connections, the rate limiter's dedicated connection will properly authenticate using client certificates, maintaining consistent security across all Redis connections. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
API Changes no api changes detected |
PR Code Suggestions ✨Explore these optional code suggestions:
|
🚀 Performance Snapshot
## Performance Impact AnalysisThe PR adds proper mTLS support to the dedicated rate limiter Redis connection by implementing a ## Critical AreasThe most performance-sensitive area affected is the Redis connection initialization for the rate limiter. The added code loads certificates and configures TLS parameters during startup, which adds a small one-time overhead. Since this happens during initialization and not in the request path, the impact on runtime performance is negligible. The TLS handshake itself adds some latency to connection establishment, but this is standard for secure connections and only happens during connection setup. ## Optimization RecommendationsThe implementation appears well-optimized with no significant performance concerns. The certificate loading is done once during initialization rather than per request. One minor suggestion would be to consider adding error metrics for certificate loading failures to monitor any potential issues in production. Additionally, ensuring proper certificate caching and reuse across reconnection attempts would help minimize the overhead during connection reestablishment. ## Summary
Tip: Mention me again using |
📦 Impact Review Snapshot
## Impact AssessmentThis PR adds proper mutual TLS (mTLS) support for the dedicated rate limiter Redis connection, fixing a security vulnerability. The change is self-contained within the Gateway codebase and doesn't modify any API schemas, protocols, or configuration structures. It simply ensures that existing TLS configuration options are properly applied to the rate limiter Redis connection, which previously only set ## Required UpdatesNo code changes are required in downstream repositories:
Documentation updates should mention that mTLS is now properly supported for the rate limiter Redis connection when ## Compatibility ConcernsThe change is fully backward compatible:
The PR includes comprehensive test coverage for all TLS configuration scenarios, ensuring reliability. ## Summary & Recommendations
No suggestions to provide – change LGTM. Tip: Mention me again using |
…ad failures Based on PR feedback, improved the TLS configuration to be more resilient: - Removed early returns when CA certificate or client certificate loading fails - Other TLS settings (versions, InsecureSkipVerify, etc.) are still applied even if one component fails - This allows connections that don't strictly require mTLS to still work with partial configuration - Added test case to verify resilient behavior when CA loading fails but client certs still load This change makes the rate limiter Redis connection more robust in edge cases where certificate files might be temporarily unavailable or misconfigured. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🚦 Connectivity Review Snapshot
## Connectivity Assessment
## Test Coverage Validation
## Security & Performance Impact
## Summary & Recommendations
Tip: Mention me again using |
Performance Impact Reviewer Analysis: PR #7301 - Add mTLS Support for Rate Limiter Redis ConnectionThis PR addresses a critical security issue where the dedicated Redis connection for the rate limiter wasn't properly implementing mutual TLS (mTLS) authentication, even when configured. The fix adds proper mTLS support to the rate limiter's Redis connection. Security ImpactThe PR fixes a significant security vulnerability where:
The implementation now properly loads CA certificates, client certificates, and respects TLS version configurations. Performance ImpactThe performance impact of this change is minimal:
Code QualityThe implementation is well-structured:
RecommendationsThe implementation is solid, but there are a few minor suggestions:
Overall, this is a critical security fix with minimal performance impact that should be approved. Tip: Mention me again using |
📦 Impact Review Snapshot
## Impact AssessmentThis PR addresses a critical security vulnerability by properly implementing mutual TLS (mTLS) for the dedicated rate limiter Redis connection. Previously, when ## Required UpdatesNo code changes are required in downstream repositories as this is a self-contained security fix within the Tyk Gateway codebase. The fix doesn't modify any API schemas, protocols, or configuration structures - it simply ensures that existing TLS configuration options are properly applied to the rate limiter Redis connection. Documentation updates should mention that mTLS is now properly supported for the rate limiter Redis connection when ## Compatibility ConcernsThe change is fully backward compatible:
The PR includes comprehensive test coverage for all TLS configuration scenarios, including error cases, ensuring reliability across different configuration patterns. ## Summary & Recommendations
No suggestions to provide – change LGTM. Tip: Mention me again using |
🛡️ Security Snapshot
## Security Impact AnalysisThis PR addresses a critical security vulnerability where the dedicated Redis connection for the rate limiter did not properly implement mutual TLS (mTLS) authentication even when configured. The fix properly implements mTLS support by adding certificate loading, TLS version configuration, and proper error handling. The implementation is similar to the main Redis connection handler but differs in error handling approach. ## Identified VulnerabilitiesHigh Severity (Fixed):
Medium Severity (Remaining):
## Security Recommendations
## OWASP ComplianceThis change improves compliance with several OWASP security principles:
## Summary
Tip: Mention me again using |
🛡️ Security Snapshot
## Security Impact AnalysisThis PR fixes a critical security vulnerability where the dedicated Redis connection for the rate limiter did not properly implement mutual TLS (mTLS) authentication. The implementation now correctly loads and applies CA certificates, client certificates, and TLS version configurations. The fix ensures that security controls configured by administrators are consistently applied across all Redis connections, eliminating a potential security bypass. ## Identified VulnerabilitiesHigh Severity:
Medium Severity:
## Security Recommendations
## OWASP ComplianceThis PR directly addresses OWASP Top 10 concerns:
## Summary
Tip: Mention me again using |
🚦 Connectivity Review Snapshot
## Connectivity Assessment
## Test Coverage Validation
## Security & Performance Impact
## Summary & Recommendations
Tip: Mention me again using |
User description
Summary
This PR fixes a critical security issue where the dedicated Redis connection for the rate limiter does not properly implement mutual TLS (mTLS) authentication, even when configured.
Problem Statement
The Tyk Gateway has two distinct code paths for establishing Redis connections:
storage.ConnectionHandler
- correctly implements mTLSrate.NewStorage
whenrate_limiter.storage.type
is set toredis
The rate limiter's dedicated Redis connection code in
internal/rate/storage.go
had a critical flaw. WhenUseSSL
was enabled, it only set theInsecureSkipVerify
field and completely ignored the client certificate configuration (CertFile
,KeyFile
,CAFile
).Security Impact
This creates a security vulnerability where:
Solution
Enhanced the
NewStorage
function ininternal/rate/storage.go
with proper mTLS support:Key Changes:
createTLSConfig
helper function that properly constructs TLS configurationTLSMinVersion
,TLSMaxVersion
)Testing
✅ Comprehensive test coverage added:
Test Results:
Configuration Example
With this fix, the rate limiter now properly respects the following configuration:
Backward Compatibility
✅ This change is fully backward compatible:
InsecureSkipVerify
are preservedChecklist
🤖 Generated with Claude Code
PR Type
Bug fix, Tests
Description
Add proper mTLS to rate limiter Redis
Introduce TLS version configuration support
Improve TLS error handling and logging
Add comprehensive unit tests for TLS paths
Diagram Walkthrough
File Walkthrough
storage.go
Add mTLS-capable TLS builder and integrate
internal/rate/storage.go
createTLSConfig
whenUseSSL
is truecreateTLSConfig
for mTLS and TLS versionsgetTLSVersion
helper with warningsstorage_tls_test.go
Unit tests for TLS config and mTLS paths
internal/rate/storage_tls_test.go