Skip to content
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

disable emitting nginx version #108

Merged
merged 1 commit into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,14 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
if cfgmExists {
cfgm := obj.(*api.ConfigMap)

if serverTokens, exists, err := nginx.GetMapKeyAsBool(cfgm.Data, "server-tokens", cfgm); exists {
if err != nil {
glog.Error(err)
} else {
cfg.ServerTokens = serverTokens
}
}

if proxyConnectTimeout, exists := cfgm.Data["proxy-connect-timeout"]; exists {
cfg.ProxyConnectTimeout = proxyConnectTimeout
}
Expand Down
2 changes: 2 additions & 0 deletions nginx-controller/nginx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nginx

// Config holds NGINX configuration parameters
type Config struct {
ServerTokens bool
ProxyConnectTimeout string
ProxyReadTimeout string
ClientMaxBodySize string
Expand Down Expand Up @@ -35,6 +36,7 @@ type Config struct {
// NewDefaultConfig creates a Config with default values
func NewDefaultConfig() *Config {
return &Config{
ServerTokens: true,
ProxyConnectTimeout: "60s",
ProxyReadTimeout: "60s",
ClientMaxBodySize: "1m",
Expand Down
9 changes: 9 additions & 0 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri

server := Server{
Name: serverName,
ServerTokens: ingCfg.ServerTokens,
HTTP2: ingCfg.HTTP2,
ProxyProtocol: ingCfg.ProxyProtocol,
HSTS: ingCfg.HSTS,
Expand Down Expand Up @@ -159,6 +160,7 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri
if len(ingEx.Ingress.Spec.Rules) == 0 && ingEx.Ingress.Spec.Backend != nil {
server := Server{
Name: emptyHost,
ServerTokens: ingCfg.ServerTokens,
HTTP2: ingCfg.HTTP2,
ProxyProtocol: ingCfg.ProxyProtocol,
HSTS: ingCfg.HSTS,
Expand Down Expand Up @@ -193,6 +195,13 @@ func (cnf *Configurator) generateNginxCfg(ingEx *IngressEx, pems map[string]stri

func (cnf *Configurator) createConfig(ingEx *IngressEx) Config {
ingCfg := *cnf.config
if serverTokens, exists, err := GetMapKeyAsBool(ingEx.Ingress.Annotations, "nginx.org/server-tokens", ingEx.Ingress); exists {
if err != nil {
glog.Error(err)
} else {
ingCfg.ServerTokens = serverTokens
}
}
if proxyConnectTimeout, exists := ingEx.Ingress.Annotations["nginx.org/proxy-connect-timeout"]; exists {
ingCfg.ProxyConnectTimeout = proxyConnectTimeout
}
Expand Down
2 changes: 2 additions & 0 deletions nginx-controller/nginx/ingress.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ server {
{{if $server.RealIPHeader}}real_ip_header {{$server.RealIPHeader}};{{end}}
{{if $server.RealIPRecursive}}real_ip_recursive on;{{end}}

{{if not $server.ServerTokens}}server_tokens off;{{end}}

{{if $server.Name}}
server_name {{$server.Name}};
{{end}}
Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type UpstreamServer struct {
// Server describes an NGINX server
type Server struct {
Name string
ServerTokens bool
Locations []Location
SSL bool
SSLCertificate string
Expand Down