-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add TLS version annotation support for per-rule configuration
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package annotations | ||
|
||
import ( | ||
networking "istio.io/api/networking/v1alpha3" | ||
) | ||
|
||
const ( | ||
tlsMinVersion = "tls-min-version" | ||
tlsMaxVersion = "tls-max-version" | ||
) | ||
|
||
var ( | ||
_ Parser = tls{} | ||
_ TrafficPolicyHandler = tls{} | ||
) | ||
|
||
type tls struct{} | ||
|
||
func (t tls) Parse(annotations Annotations, config *Ingress, _ *GlobalContext) error { | ||
if !needTLSConfig(annotations) { | ||
return nil | ||
} | ||
|
||
tlsConfig := &TLSConfig{} | ||
defer func() { | ||
config.UpstreamTLS = tlsConfig | ||
}() | ||
|
||
// Parse minimum TLS version | ||
if minVersion, err := annotations.ParseStringASAP(tlsMinVersion); err == nil { | ||
tlsConfig.MinVersion = minVersion | ||
} | ||
|
||
// Parse maximum TLS version | ||
if maxVersion, err := annotations.ParseStringASAP(tlsMaxVersion); err == nil { | ||
tlsConfig.MaxVersion = maxVersion | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (t tls) ApplyTrafficPolicy(trafficPolicy *networking.TrafficPolicy, _ *networking.TrafficPolicy_PortTrafficPolicy, config *Ingress) { | ||
tlsConfig := config.UpstreamTLS | ||
if tlsConfig == nil { | ||
return | ||
} | ||
|
||
if trafficPolicy.Tls == nil { | ||
trafficPolicy.Tls = &networking.ClientTLSSettings{} | ||
} | ||
|
||
// Apply min version | ||
if tlsConfig.MinVersion != "" { | ||
trafficPolicy.Tls.MinProtocolVersion = convertTLSVersion(tlsConfig.MinVersion) | ||
Check failure on line 54 in pkg/ingress/kube/annotations/tls.go GitHub Actions / coverage-test
|
||
} | ||
|
||
// Apply max version | ||
if tlsConfig.MaxVersion != "" { | ||
trafficPolicy.Tls.MaxProtocolVersion = convertTLSVersion(tlsConfig.MaxVersion) | ||
Check failure on line 59 in pkg/ingress/kube/annotations/tls.go GitHub Actions / coverage-test
|
||
} | ||
} | ||
|
||
func needTLSConfig(annotations Annotations) bool { | ||
return annotations.HasASAP(tlsMinVersion) || annotations.HasASAP(tlsMaxVersion) | ||
} | ||
|
||
// Helper to convert TLS version string to istio enum | ||
func convertTLSVersion(version string) networking.ClientTLSSettings_TLSProtocol { | ||
switch version { | ||
case "TLSv1_0": | ||
return networking.ClientTLSSettings_TLSV1_0 | ||
case "TLSv1_1": | ||
return networking.ClientTLSSettings_TLSV1_1 | ||
case "TLSv1_2": | ||
return networking.ClientTLSSettings_TLSV1_2 | ||
case "TLSv1_3": | ||
return networking.ClientTLSSettings_TLSV1_3 | ||
default: | ||
return networking.ClientTLSSettings_TLS_AUTO | ||
} | ||
} |