Skip to content

Commit

Permalink
Fix nginx breaking & remove unused code for ProxySetHeaders annotation (
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexFenlon committed Apr 29, 2024
1 parent 3b7340b commit 6a69e8d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
16 changes: 0 additions & 16 deletions internal/configs/configmaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package configs
import (
"strings"

"github.com/nginxinc/kubernetes-ingress/internal/configs/version2"

"github.com/golang/glog"
v1 "k8s.io/api/core/v1"

Expand Down Expand Up @@ -68,20 +66,6 @@ func ParseConfigMap(cfgm *v1.ConfigMap, nginxPlus bool, hasAppProtect bool, hasA
cfgParams.ProxyPassHeaders = proxyPassHeaders
}

if proxySetHeaders, exists := GetMapKeyAsStringSlice(cfgm.Data, "proxy-set-headers", cfgm, ","); exists {
var headers []version2.Header
for _, headerAndValue := range proxySetHeaders {
parts := strings.SplitN(headerAndValue, " ", 2)
name := strings.TrimSpace(parts[0])
var value string
if len(parts) > 1 {
value = strings.TrimSpace(parts[1])
}
headers = append(headers, version2.Header{Name: name, Value: value})
}
cfgParams.ProxySetHeaders = headers
}

if clientMaxBodySize, exists := cfgm.Data["client-max-body-size"]; exists {
cfgParams.ClientMaxBodySize = clientMaxBodySize
}
Expand Down
6 changes: 6 additions & 0 deletions internal/configs/version1/template_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,12 @@ func TestGenerateProxySetHeadersForInvalidHeadersForErrorsInMaster(t *testing.T)
"nginx.org/proxy-set-headers": "X-Forwarded-ABC!,BVC§",
},
},
{
name: "Header Value With invalid Characters",
annotations: map[string]string{
"nginx.org/proxy-set-headers": "X-Forwarded ABC$",
},
},
{
name: "Headers with invalid Format",
annotations: map[string]string{
Expand Down
4 changes: 4 additions & 0 deletions internal/k8s/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ func validateProxySetHeaderAnnotation(context *annotationValidationContext) fiel

value := strings.TrimSpace(parts[1])

if strings.Contains(value, "$") {
allErrs = append(allErrs, field.Invalid(context.fieldPath, header, "invalid character in value: $"))
}

if name == "" {
allErrs = append(allErrs, field.Invalid(context.fieldPath, header, "empty header name: "+header))
continue
Expand Down

0 comments on commit 6a69e8d

Please sign in to comment.