-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Allow specifying the name of the header for forwarding client certificates #10359
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,13 @@ const ( | |
defaultAuthTLSDepth = 1 | ||
defaultAuthVerifyClient = "on" | ||
|
||
annotationAuthTLSSecret = "auth-tls-secret" //#nosec G101 | ||
annotationAuthTLSVerifyClient = "auth-tls-verify-client" | ||
annotationAuthTLSVerifyDepth = "auth-tls-verify-depth" | ||
annotationAuthTLSErrorPage = "auth-tls-error-page" | ||
annotationAuthTLSPassCertToUpstream = "auth-tls-pass-certificate-to-upstream" //#nosec G101 | ||
annotationAuthTLSMatchCN = "auth-tls-match-cn" | ||
annotationAuthTLSSecret = "auth-tls-secret" //#nosec G101 | ||
annotationAuthTLSVerifyClient = "auth-tls-verify-client" | ||
annotationAuthTLSVerifyDepth = "auth-tls-verify-depth" | ||
annotationAuthTLSErrorPage = "auth-tls-error-page" | ||
annotationAuthTLSPassCertToUpstream = "auth-tls-pass-certificate-to-upstream" //#nosec G101 | ||
annotationAuthTLSPassCertToUpstreamHeader = "auth-tls-pass-certificate-to-upstream-header" //#nosec G101 | ||
annotationAuthTLSMatchCN = "auth-tls-match-cn" | ||
) | ||
|
||
var ( | ||
|
@@ -80,6 +81,12 @@ var authTLSAnnotations = parser.Annotation{ | |
Risk: parser.AnnotationRiskLow, | ||
Documentation: `This annotation defines if the received certificates should be passed or not to the upstream server in the header "ssl-client-cert"`, | ||
}, | ||
annotationAuthTLSPassCertToUpstreamHeader: { | ||
Validator: parser.ValidateNull, | ||
Scope: parser.AnnotationScopeLocation, | ||
Risk: parser.AnnotationRiskLow, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is Low, as you are allowing users to:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I don't know the implications of the risk levels. What do you recommend? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO we can set it to high level |
||
Documentation: `This annotation defines the header name in which the client certificate will be passed to the upstream server`, | ||
}, | ||
annotationAuthTLSMatchCN: { | ||
Validator: parser.ValidateRegex(commonNameRegex, true), | ||
Scope: parser.AnnotationScopeLocation, | ||
|
@@ -93,12 +100,13 @@ var authTLSAnnotations = parser.Annotation{ | |
// and the configured ValidationDepth | ||
type Config struct { | ||
resolver.AuthSSLCert | ||
VerifyClient string `json:"verify_client"` | ||
ValidationDepth int `json:"validationDepth"` | ||
ErrorPage string `json:"errorPage"` | ||
PassCertToUpstream bool `json:"passCertToUpstream"` | ||
MatchCN string `json:"matchCN"` | ||
AuthTLSError string | ||
VerifyClient string `json:"verify_client"` | ||
ValidationDepth int `json:"validationDepth"` | ||
ErrorPage string `json:"errorPage"` | ||
PassCertToUpstream bool `json:"passCertToUpstream"` | ||
PassCertToUpstreamHeader string `json:"passCertToUpstreamHeader"` | ||
MatchCN string `json:"matchCN"` | ||
AuthTLSError string | ||
} | ||
|
||
// Equal tests for equality between two Config types | ||
|
@@ -125,6 +133,10 @@ func (assl1 *Config) Equal(assl2 *Config) bool { | |
return false | ||
} | ||
|
||
if assl1.PassCertToUpstreamHeader != assl2.PassCertToUpstreamHeader { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
|
@@ -200,6 +212,14 @@ func (a authTLS) Parse(ing *networking.Ingress) (interface{}, error) { | |
config.PassCertToUpstream = false | ||
} | ||
|
||
config.PassCertToUpstreamHeader, err = parser.GetStringAnnotation(annotationAuthTLSPassCertToUpstreamHeader, ing, a.annotationConfig.Annotations) | ||
if err != nil { | ||
if ing_errors.IsValidationError(err) { | ||
return &Config{}, err | ||
} | ||
config.PassCertToUpstreamHeader = "ssl-client-cert" | ||
} | ||
|
||
config.MatchCN, err = parser.GetStringAnnotation(annotationAuthTLSMatchCN, ing, a.annotationConfig.Annotations) | ||
if err != nil { | ||
if ing_errors.IsValidationError(err) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't ignore the validation, as you are passing a string, you should add what is the possible value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought so too. Is there any existing example I can follow?