Skip to content

Commit 81ca457

Browse files
Add Safe Proxy Buffer Configuration Adjustments (#8133)
Signed-off-by: AlexFenlon <[email protected]> Co-authored-by: Alex Fenlon <[email protected]>
1 parent d0803de commit 81ca457

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2300
-83
lines changed

charts/nginx-ingress/templates/_helpers.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,9 @@ Build the args for the service binary.
338338
- -enable-custom-resources={{ .Values.controller.enableCustomResources }}
339339
- -enable-snippets={{ .Values.controller.enableSnippets }}
340340
- -disable-ipv6={{ .Values.controller.disableIPV6 }}
341+
{{- if .Values.controller.directiveAutoAdjust }}
342+
- -enable-directive-autoadjust={{ .Values.controller.directiveAutoAdjust }}
343+
{{- end }}
341344
{{- if .Values.controller.enableCustomResources }}
342345
- -enable-tls-passthrough={{ .Values.controller.enableTLSPassthrough }}
343346
{{- if .Values.controller.enableTLSPassthrough }}

charts/nginx-ingress/values.schema.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,15 @@
657657
"json"
658658
]
659659
},
660+
"directiveAutoAdjust": {
661+
"type": "boolean",
662+
"default": false,
663+
"title": "Enables automatic adjustment of the NGINX buffers directives",
664+
"examples": [
665+
false,
666+
true
667+
]
668+
},
660669
"customPorts": {
661670
"type": "array",
662671
"default": [],

charts/nginx-ingress/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ controller:
164164
## Sets the log format of Ingress Controller. Options include: glog, json, text
165165
logFormat: glog
166166

167+
## Enables auto adjusting some of the NGINX directives to help with safe configuration and prevent NGINX misconfigurations.
168+
## See https://docs.nginx.com/nginx-ingress-controller/configuration/proxy-buffers-configuration/ for more details of which configuration options are affected
169+
directiveAutoAdjust: false
170+
167171
## Cache configuration options
168172
cache:
169173
## Enables shared cache across multiple pods using an external persistent volume

cmd/nginx-ingress/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ var (
225225

226226
enableDynamicWeightChangesReload = flag.Bool(dynamicWeightChangesParam, false, "Enable changing weights of split clients without reloading NGINX. Requires -nginx-plus")
227227

228+
enableDirectiveAutoadjust = flag.Bool("enable-directive-autoadjust", false, "Enable automatic adjustment of NGINX directives to avoid conflicting NGINX configuration. Results may vary and might not be ideal in all cases.")
229+
228230
startupCheckFn func() error
229231
)
230232

cmd/nginx-ingress/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ func main() {
221221
EnableCertManager: *enableCertManager,
222222
DynamicSSLReload: *enableDynamicSSLReload,
223223
DynamicWeightChangesReload: *enableDynamicWeightChangesReload,
224+
IsDirectiveAutoadjustEnabled: *enableDirectiveAutoadjust,
224225
StaticSSLPath: staticSSLPath,
225226
NginxVersion: nginxVersion,
226227
AppProtectBundlePath: appProtectBundlePath,
@@ -274,6 +275,7 @@ func main() {
274275
cr_validation.IsDosEnabled(*appProtectDos),
275276
cr_validation.IsCertManagerEnabled(*enableCertManager),
276277
cr_validation.IsExternalDNSEnabled(*enableExternalDNS),
278+
cr_validation.IsDirectiveAutoadjustEnabled(*enableDirectiveAutoadjust),
277279
)
278280

279281
if *enableServiceInsight {
@@ -324,6 +326,7 @@ func main() {
324326
CertManagerEnabled: *enableCertManager,
325327
ExternalDNSEnabled: *enableExternalDNS,
326328
IsIPV6Disabled: *disableIPV6,
329+
IsDirectiveAutoadjustEnabled: *enableDirectiveAutoadjust,
327330
WatchNamespaceLabel: *watchNamespaceLabel,
328331
EnableTelemetryReporting: *enableTelemetryReporting,
329332
TelemetryReportingEndpoint: telemetryEndpoint,
@@ -996,7 +999,7 @@ func processConfigMaps(kubeClient *kubernetes.Clientset, cfgParams *configs.Conf
996999
if err != nil {
9971000
nl.Fatalf(l, "Error when getting %v: %v", *nginxConfigMaps, err)
9981001
}
999-
cfgParams, _ = configs.ParseConfigMap(cfgParams.Context, cfm, *nginxPlus, *appProtect, *appProtectDos, *enableTLSPassthrough, eventLog)
1002+
cfgParams, _ = configs.ParseConfigMap(cfgParams.Context, cfm, *nginxPlus, *appProtect, *appProtectDos, *enableTLSPassthrough, *enableDirectiveAutoadjust, eventLog)
10001003
if cfgParams.MainServerSSLDHParamFileContent != nil {
10011004
fileName, err := nginxManager.CreateDHParam(*cfgParams.MainServerSSLDHParamFileContent)
10021005
if err != nil {

config/crd/bases/k8s.nginx.org_virtualserverroutes.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,12 @@ spec:
872872
is set in the proxy-buffers ConfigMap key.
873873
type: string
874874
type: object
875+
busy-buffers-size:
876+
description: Sets the size of the buffers used for reading a
877+
response from the upstream server when the proxy_buffering
878+
is enabled. The default is set in the proxy-busy-buffers-size
879+
ConfigMap key.'
880+
type: string
875881
client-max-body-size:
876882
description: Sets the maximum allowed size of the client request
877883
body. The default is set in the client-max-body-size ConfigMap

config/crd/bases/k8s.nginx.org_virtualservers.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,12 @@ spec:
10611061
is set in the proxy-buffers ConfigMap key.
10621062
type: string
10631063
type: object
1064+
busy-buffers-size:
1065+
description: Sets the size of the buffers used for reading a
1066+
response from the upstream server when the proxy_buffering
1067+
is enabled. The default is set in the proxy-busy-buffers-size
1068+
ConfigMap key.'
1069+
type: string
10641070
client-max-body-size:
10651071
description: Sets the maximum allowed size of the client request
10661072
body. The default is set in the client-max-body-size ConfigMap

deploy/crds.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,12 @@ spec:
18911891
is set in the proxy-buffers ConfigMap key.
18921892
type: string
18931893
type: object
1894+
busy-buffers-size:
1895+
description: Sets the size of the buffers used for reading a
1896+
response from the upstream server when the proxy_buffering
1897+
is enabled. The default is set in the proxy-busy-buffers-size
1898+
ConfigMap key.'
1899+
type: string
18941900
client-max-body-size:
18951901
description: Sets the maximum allowed size of the client request
18961902
body. The default is set in the client-max-body-size ConfigMap
@@ -3303,6 +3309,12 @@ spec:
33033309
is set in the proxy-buffers ConfigMap key.
33043310
type: string
33053311
type: object
3312+
busy-buffers-size:
3313+
description: Sets the size of the buffers used for reading a
3314+
response from the upstream server when the proxy_buffering
3315+
is enabled. The default is set in the proxy-busy-buffers-size
3316+
ConfigMap key.'
3317+
type: string
33063318
client-max-body-size:
33073319
description: Sets the maximum allowed size of the client request
33083320
body. The default is set in the client-max-body-size ConfigMap

docs/crd/k8s.nginx.org_virtualserverroutes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ The `.spec` object supports the following fields:
168168
| `upstreams[].buffers` | `object` | Configures the buffers used for reading a response from the upstream server for a single connection. |
169169
| `upstreams[].buffers.number` | `integer` | Configures the number of buffers. The default is set in the proxy-buffers ConfigMap key. |
170170
| `upstreams[].buffers.size` | `string` | Configures the size of a buffer. The default is set in the proxy-buffers ConfigMap key. |
171+
| `upstreams[].busy-buffers-size` | `string` | Sets the size of the buffers used for reading a response from the upstream server when the proxy_buffering is enabled. The default is set in the proxy-busy-buffers-size ConfigMap key.' |
171172
| `upstreams[].client-max-body-size` | `string` | Sets the maximum allowed size of the client request body. The default is set in the client-max-body-size ConfigMap key. |
172173
| `upstreams[].connect-timeout` | `string` | The timeout for establishing a connection with an upstream server. The default is specified in the proxy-connect-timeout ConfigMap key. |
173174
| `upstreams[].fail-timeout` | `string` | The time during which the specified number of unsuccessful attempts to communicate with an upstream server should happen to consider the server unavailable. The default is set in the fail-timeout ConfigMap key. |

docs/crd/k8s.nginx.org_virtualservers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ The `.spec` object supports the following fields:
203203
| `upstreams[].buffers` | `object` | Configures the buffers used for reading a response from the upstream server for a single connection. |
204204
| `upstreams[].buffers.number` | `integer` | Configures the number of buffers. The default is set in the proxy-buffers ConfigMap key. |
205205
| `upstreams[].buffers.size` | `string` | Configures the size of a buffer. The default is set in the proxy-buffers ConfigMap key. |
206+
| `upstreams[].busy-buffers-size` | `string` | Sets the size of the buffers used for reading a response from the upstream server when the proxy_buffering is enabled. The default is set in the proxy-busy-buffers-size ConfigMap key.' |
206207
| `upstreams[].client-max-body-size` | `string` | Sets the maximum allowed size of the client request body. The default is set in the client-max-body-size ConfigMap key. |
207208
| `upstreams[].connect-timeout` | `string` | The timeout for establishing a connection with an upstream server. The default is specified in the proxy-connect-timeout ConfigMap key. |
208209
| `upstreams[].fail-timeout` | `string` | The time during which the specified number of unsuccessful attempts to communicate with an upstream server should happen to consider the server unavailable. The default is set in the fail-timeout ConfigMap key. |

0 commit comments

Comments
 (0)