Add annotation ssl-prefer-server-ciphers.
This commit is contained in:
parent
0e785a0bf2
commit
41d82005ec
8 changed files with 54 additions and 9 deletions
|
@ -100,6 +100,7 @@ You can add these Kubernetes annotations to specific Ingress objects to customiz
|
||||||
|[nginx.ingress.kubernetes.io/proxy-buffer-size](#proxy-buffer-size)|string|
|
|[nginx.ingress.kubernetes.io/proxy-buffer-size](#proxy-buffer-size)|string|
|
||||||
|[nginx.ingress.kubernetes.io/proxy-max-temp-file-size](#proxy-max-temp-file-size)|string|
|
|[nginx.ingress.kubernetes.io/proxy-max-temp-file-size](#proxy-max-temp-file-size)|string|
|
||||||
|[nginx.ingress.kubernetes.io/ssl-ciphers](#ssl-ciphers)|string|
|
|[nginx.ingress.kubernetes.io/ssl-ciphers](#ssl-ciphers)|string|
|
||||||
|
|[nginx.ingress.kubernetes.io/ssl-prefer-server-ciphers](#ssl-ciphers)|"true" or "false"|
|
||||||
|[nginx.ingress.kubernetes.io/connection-proxy-header](#connection-proxy-header)|string|
|
|[nginx.ingress.kubernetes.io/connection-proxy-header](#connection-proxy-header)|string|
|
||||||
|[nginx.ingress.kubernetes.io/enable-access-log](#enable-access-log)|"true" or "false"|
|
|[nginx.ingress.kubernetes.io/enable-access-log](#enable-access-log)|"true" or "false"|
|
||||||
|[nginx.ingress.kubernetes.io/enable-opentracing](#enable-opentracing)|"true" or "false"|
|
|[nginx.ingress.kubernetes.io/enable-opentracing](#enable-opentracing)|"true" or "false"|
|
||||||
|
@ -646,6 +647,12 @@ Using this annotation will set the `ssl_ciphers` directive at the server level.
|
||||||
nginx.ingress.kubernetes.io/ssl-ciphers: "ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP"
|
nginx.ingress.kubernetes.io/ssl-ciphers: "ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The following annotation will set the `ssl_prefer_server_ciphers` directive at the server level. This configuration specifies that server ciphers should be preferred over client ciphers when using the SSLv3 and TLS protocols.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
nginx.ingress.kubernetes.io/ssl-prefer-server-ciphers: "true"
|
||||||
|
```
|
||||||
|
|
||||||
### Connection proxy header
|
### Connection proxy header
|
||||||
|
|
||||||
Using this annotation will override the default connection header set by NGINX.
|
Using this annotation will override the default connection header set by NGINX.
|
||||||
|
|
|
@ -108,7 +108,7 @@ type Ingress struct {
|
||||||
UpstreamVhost string
|
UpstreamVhost string
|
||||||
Whitelist ipwhitelist.SourceRange
|
Whitelist ipwhitelist.SourceRange
|
||||||
XForwardedPrefix string
|
XForwardedPrefix string
|
||||||
SSLCiphers string
|
SSLCipher sslcipher.Config
|
||||||
Logs log.Config
|
Logs log.Config
|
||||||
InfluxDB influxdb.Config
|
InfluxDB influxdb.Config
|
||||||
ModSecurity modsecurity.Config
|
ModSecurity modsecurity.Config
|
||||||
|
@ -156,7 +156,7 @@ func NewAnnotationExtractor(cfg resolver.Resolver) Extractor {
|
||||||
"UpstreamVhost": upstreamvhost.NewParser(cfg),
|
"UpstreamVhost": upstreamvhost.NewParser(cfg),
|
||||||
"Whitelist": ipwhitelist.NewParser(cfg),
|
"Whitelist": ipwhitelist.NewParser(cfg),
|
||||||
"XForwardedPrefix": xforwardedprefix.NewParser(cfg),
|
"XForwardedPrefix": xforwardedprefix.NewParser(cfg),
|
||||||
"SSLCiphers": sslcipher.NewParser(cfg),
|
"SSLCipher": sslcipher.NewParser(cfg),
|
||||||
"Logs": log.NewParser(cfg),
|
"Logs": log.NewParser(cfg),
|
||||||
"InfluxDB": influxdb.NewParser(cfg),
|
"InfluxDB": influxdb.NewParser(cfg),
|
||||||
"BackendProtocol": backendprotocol.NewParser(cfg),
|
"BackendProtocol": backendprotocol.NewParser(cfg),
|
||||||
|
|
|
@ -27,13 +27,35 @@ type sslCipher struct {
|
||||||
r resolver.Resolver
|
r resolver.Resolver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
SSLCiphers string
|
||||||
|
SSLPreferServerCiphers string
|
||||||
|
}
|
||||||
|
|
||||||
// NewParser creates a new sslCipher annotation parser
|
// NewParser creates a new sslCipher annotation parser
|
||||||
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
|
||||||
return sslCipher{r}
|
return sslCipher{r}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse parses the annotations contained in the ingress rule
|
// Parse parses the annotations contained in the ingress rule
|
||||||
// used to add ssl-ciphers to the server name
|
// used to add ssl-ciphers & ssl-prefer-server-ciphers to the server name
|
||||||
func (sc sslCipher) Parse(ing *networking.Ingress) (interface{}, error) {
|
func (sc sslCipher) Parse(ing *networking.Ingress) (interface{}, error) {
|
||||||
return parser.GetStringAnnotation("ssl-ciphers", ing)
|
config := &Config{}
|
||||||
|
var err error
|
||||||
|
var sslPreferServerCiphers bool
|
||||||
|
|
||||||
|
sslPreferServerCiphers, err = parser.GetBoolAnnotation("ssl-prefer-server-ciphers", ing)
|
||||||
|
if err != nil {
|
||||||
|
config.SSLPreferServerCiphers = ""
|
||||||
|
} else {
|
||||||
|
if sslPreferServerCiphers {
|
||||||
|
config.SSLPreferServerCiphers = "on"
|
||||||
|
} else {
|
||||||
|
config.SSLPreferServerCiphers = "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
config.SSLCiphers, _ = parser.GetStringAnnotation("ssl-ciphers", ing)
|
||||||
|
|
||||||
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestParse(t *testing.T) {
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
ing.SetAnnotations(testCase.annotations)
|
ing.SetAnnotations(testCase.annotations)
|
||||||
result, _ := ap.Parse(ing)
|
result, _ := ap.Parse(ing)
|
||||||
if result != testCase.expected {
|
if result.SSLCiphers != testCase.expected {
|
||||||
t.Errorf("expected %v but returned %v, annotations: %s", testCase.expected, result, testCase.annotations)
|
t.Errorf("expected %v but returned %v, annotations: %s", testCase.expected, result, testCase.annotations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1052,7 +1052,8 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
|
||||||
loc,
|
loc,
|
||||||
},
|
},
|
||||||
SSLPassthrough: anns.SSLPassthrough,
|
SSLPassthrough: anns.SSLPassthrough,
|
||||||
SSLCiphers: anns.SSLCiphers,
|
SSLCiphers: anns.SSLCipher.SSLCiphers,
|
||||||
|
SSLPreferServerCiphers: anns.SSLCipher.SSLPreferServerCiphers,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1092,8 +1093,13 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
|
||||||
}
|
}
|
||||||
|
|
||||||
// only add SSL ciphers if the server does not have them previously configured
|
// only add SSL ciphers if the server does not have them previously configured
|
||||||
if servers[host].SSLCiphers == "" && anns.SSLCiphers != "" {
|
if servers[host].SSLCiphers == "" && anns.SSLCipher.SSLCiphers != "" {
|
||||||
servers[host].SSLCiphers = anns.SSLCiphers
|
servers[host].SSLCiphers = anns.SSLCipher.SSLCiphers
|
||||||
|
}
|
||||||
|
|
||||||
|
// only add SSLPreferServerCiphers if the server does not have them previously configured
|
||||||
|
if servers[host].SSLPreferServerCiphers == "" && anns.SSLCipher.SSLPreferServerCiphers != "" {
|
||||||
|
servers[host].SSLPreferServerCiphers = anns.SSLCipher.SSLPreferServerCiphers
|
||||||
}
|
}
|
||||||
|
|
||||||
// only add a certificate if the server does not have one previously configured
|
// only add a certificate if the server does not have one previously configured
|
||||||
|
|
|
@ -200,6 +200,9 @@ type Server struct {
|
||||||
ServerSnippet string `json:"serverSnippet"`
|
ServerSnippet string `json:"serverSnippet"`
|
||||||
// SSLCiphers returns list of ciphers to be enabled
|
// SSLCiphers returns list of ciphers to be enabled
|
||||||
SSLCiphers string `json:"sslCiphers,omitempty"`
|
SSLCiphers string `json:"sslCiphers,omitempty"`
|
||||||
|
// SSLPreferServerCiphers indicates that server ciphers should be preferred
|
||||||
|
// over client ciphers when using the SSLv3 and TLS protocols.
|
||||||
|
SSLPreferServerCiphers string `sslPreferServerCiphers,omitempty`
|
||||||
// AuthTLSError contains the reason why the access to a server should be denied
|
// AuthTLSError contains the reason why the access to a server should be denied
|
||||||
AuthTLSError string `json:"authTLSError,omitempty"`
|
AuthTLSError string `json:"authTLSError,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,6 +308,9 @@ func (s1 *Server) Equal(s2 *Server) bool {
|
||||||
if s1.SSLCiphers != s2.SSLCiphers {
|
if s1.SSLCiphers != s2.SSLCiphers {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if s1.SSLPreferServerCiphers != s2.SSLPreferServerCiphers {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if s1.AuthTLSError != s2.AuthTLSError {
|
if s1.AuthTLSError != s2.AuthTLSError {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -875,6 +875,10 @@ stream {
|
||||||
ssl_ciphers {{ $server.SSLCiphers }};
|
ssl_ciphers {{ $server.SSLCiphers }};
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if not (empty $server.SSLPreferServerCiphers) }}
|
||||||
|
ssl_prefer_server_ciphers {{ $server.SSLPreferServerCiphers }};
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
{{ if not (empty $server.ServerSnippet) }}
|
{{ if not (empty $server.ServerSnippet) }}
|
||||||
{{ $server.ServerSnippet }}
|
{{ $server.ServerSnippet }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in a new issue