Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/crd/bases/k8s.nginx.org_virtualserverroutes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,10 @@ spec:
is enabled. The default is set in the proxy-busy-buffers-size
ConfigMap key.'
type: string
client-body-buffer-size:
description: Sets the size of the buffer used for reading the
client request body.
type: string
client-max-body-size:
description: Sets the maximum allowed size of the client request
body. The default is set in the client-max-body-size ConfigMap
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/k8s.nginx.org_virtualservers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,10 @@ spec:
is enabled. The default is set in the proxy-busy-buffers-size
ConfigMap key.'
type: string
client-body-buffer-size:
description: Sets the size of the buffer used for reading the
client request body.
type: string
client-max-body-size:
description: Sets the maximum allowed size of the client request
body. The default is set in the client-max-body-size ConfigMap
Expand Down
8 changes: 8 additions & 0 deletions deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,10 @@ spec:
is enabled. The default is set in the proxy-busy-buffers-size
ConfigMap key.'
type: string
client-body-buffer-size:
description: Sets the size of the buffer used for reading the
client request body.
type: string
client-max-body-size:
description: Sets the maximum allowed size of the client request
body. The default is set in the client-max-body-size ConfigMap
Expand Down Expand Up @@ -3335,6 +3339,10 @@ spec:
is enabled. The default is set in the proxy-busy-buffers-size
ConfigMap key.'
type: string
client-body-buffer-size:
description: Sets the size of the buffer used for reading the
client request body.
type: string
client-max-body-size:
description: Sets the maximum allowed size of the client request
body. The default is set in the client-max-body-size ConfigMap
Expand Down
1 change: 1 addition & 0 deletions docs/crd/k8s.nginx.org_virtualserverroutes.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ The `.spec` object supports the following fields:
| `upstreams[].buffers.number` | `integer` | Configures the number of buffers. The default is set in the proxy-buffers ConfigMap key. |
| `upstreams[].buffers.size` | `string` | Configures the size of a buffer. The default is set in the proxy-buffers ConfigMap key. |
| `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.' |
| `upstreams[].client-body-buffer-size` | `string` | Sets the size of the buffer used for reading the client request body. |
| `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. |
| `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. |
| `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. |
Expand Down
1 change: 1 addition & 0 deletions docs/crd/k8s.nginx.org_virtualservers.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ The `.spec` object supports the following fields:
| `upstreams[].buffers.number` | `integer` | Configures the number of buffers. The default is set in the proxy-buffers ConfigMap key. |
| `upstreams[].buffers.size` | `string` | Configures the size of a buffer. The default is set in the proxy-buffers ConfigMap key. |
| `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.' |
| `upstreams[].client-body-buffer-size` | `string` | Sets the size of the buffer used for reading the client request body. |
| `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. |
| `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. |
| `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. |
Expand Down
1 change: 1 addition & 0 deletions internal/configs/config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type ConfigParams struct {
Context context.Context
ClientMaxBodySize string
ClientBodyBufferSize string
DefaultServerAccessLogOff bool
DefaultServerReturn string
FailTimeout string
Expand Down
51 changes: 51 additions & 0 deletions internal/configs/version2/__snapshots__/templates_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,56 @@ server {

---

[TestExecuteVirtualServerTemplate_RendersTemplateWithClientBodyBufferSize - 1]


server {
listen 80;
listen [::]:80;


server_name example.com;
status_zone example.com;
set $resource_type "virtualserver";
set $resource_name "";
set $resource_namespace "";

server_tokens "";




location / {
set $service "";
status_zone "";


set $default_connection_header close;
proxy_connect_timeout ;
proxy_read_timeout ;
proxy_send_timeout ;
client_max_body_size ;
client_body_buffer_size 16k;

proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $vs_connection_header;
proxy_pass_request_headers off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://test-upstream;
proxy_next_upstream ;
proxy_next_upstream_timeout ;
proxy_next_upstream_tries 0;
}
}

---

[TestExecuteVirtualServerTemplate_RendersTemplateWithCustomListener - 1]


Expand Down Expand Up @@ -3052,6 +3102,7 @@ server {
proxy_read_timeout 31s;
proxy_send_timeout 32s;
client_max_body_size 1m;
client_body_buffer_size 8k;
proxy_max_temp_file_size 1024m;

proxy_buffering on;
Expand Down
1 change: 1 addition & 0 deletions internal/configs/version2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ type Location struct {
ProxyReadTimeout string
ProxySendTimeout string
ClientMaxBodySize string
ClientBodyBufferSize string
ProxyMaxTempFileSize string
ProxyBuffering bool
ProxyBuffers string
Expand Down
3 changes: 3 additions & 0 deletions internal/configs/version2/nginx-plus.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ server {
{{ $proxyOrGRPC }}_read_timeout {{ $l.ProxyReadTimeout }};
{{ $proxyOrGRPC }}_send_timeout {{ $l.ProxySendTimeout }};
client_max_body_size {{ $l.ClientMaxBodySize }};
{{- if $l.ClientBodyBufferSize }}
client_body_buffer_size {{ $l.ClientBodyBufferSize }};
{{- end }}

{{- if $l.ProxyMaxTempFileSize }}
proxy_max_temp_file_size {{ $l.ProxyMaxTempFileSize }};
Expand Down
3 changes: 3 additions & 0 deletions internal/configs/version2/nginx.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ server {
{{ $proxyOrGRPC }}_read_timeout {{ $l.ProxyReadTimeout }};
{{ $proxyOrGRPC }}_send_timeout {{ $l.ProxySendTimeout }};
client_max_body_size {{ $l.ClientMaxBodySize }};
{{- if $l.ClientBodyBufferSize }}
client_body_buffer_size {{ $l.ClientBodyBufferSize }};
{{- end }}

{{- if $l.ProxyMaxTempFileSize }}
proxy_max_temp_file_size {{ $l.ProxyMaxTempFileSize }};
Expand Down
30 changes: 30 additions & 0 deletions internal/configs/version2/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,21 @@ func TestExecuteVirtualServerTemplate_RendersPlusTemplateWithHTTP2Off(t *testing
t.Log(string(got))
}

func TestExecuteVirtualServerTemplate_RendersTemplateWithClientBodyBufferSize(t *testing.T) {
t.Parallel()
executor := newTmplExecutorNGINXPlus(t)

got, err := executor.ExecuteVirtualServerTemplate(&virtualServerCfgWithClientBodyBufferSize)
if err != nil {
t.Error(err)
}
if !bytes.Contains(got, []byte("client_body_buffer_size 16k;")) {
t.Error("want `client_body_buffer_size 16k;` directive in generated template")
}
snaps.MatchSnapshot(t, string(got))
t.Log(string(got))
}

func TestExecuteVirtualServerTemplate_RendersOSSTemplateWithHTTP2On(t *testing.T) {
t.Parallel()
executor := newTmplExecutorNGINX(t)
Expand Down Expand Up @@ -1594,6 +1609,7 @@ var (
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ClientBodyBufferSize: "8k",
ProxyBuffering: true,
ProxyBuffers: "8 4k",
ProxyBufferSize: "4k",
Expand Down Expand Up @@ -2171,6 +2187,20 @@ var (
},
}

virtualServerCfgWithClientBodyBufferSize = VirtualServerConfig{
Server: Server{
ServerName: "example.com",
StatusZone: "example.com",
Locations: []Location{
{
Path: "/",
ProxyPass: "http://test-upstream",
ClientBodyBufferSize: "16k",
},
},
},
}

virtualServerCfgWithRateLimitJWTClaim = VirtualServerConfig{
LimitReqZones: []LimitReqZone{
{
Expand Down
1 change: 1 addition & 0 deletions internal/configs/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2647,6 +2647,7 @@ func generateLocationForProxying(path string, upstreamName string, upstream conf
ProxyReadTimeout: generateTimeWithDefault(upstream.ProxyReadTimeout, cfgParams.ProxyReadTimeout),
ProxySendTimeout: generateTimeWithDefault(upstream.ProxySendTimeout, cfgParams.ProxySendTimeout),
ClientMaxBodySize: generateString(upstream.ClientMaxBodySize, cfgParams.ClientMaxBodySize),
ClientBodyBufferSize: generateString(upstream.ClientBodyBufferSize, cfgParams.ClientBodyBufferSize),
ProxyMaxTempFileSize: cfgParams.ProxyMaxTempFileSize,
ProxyBuffering: generateBool(upstream.ProxyBuffering, cfgParams.ProxyBuffering),
ProxyBuffers: generateBuffers(upstream.ProxyBuffers, cfgParams.ProxyBuffers),
Expand Down
4 changes: 4 additions & 0 deletions internal/configs/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16221,6 +16221,7 @@ func TestGenerateLocationForProxying(t *testing.T) {
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ClientBodyBufferSize: "16k",
ProxyMaxTempFileSize: "1024m",
ProxyBuffering: true,
ProxyBuffers: "8 4k",
Expand All @@ -16238,6 +16239,7 @@ func TestGenerateLocationForProxying(t *testing.T) {
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ClientBodyBufferSize: "16k",
ProxyMaxTempFileSize: "1024m",
ProxyBuffering: true,
ProxyBuffers: "8 4k",
Expand Down Expand Up @@ -16269,6 +16271,7 @@ func TestGenerateLocationForGrpcProxying(t *testing.T) {
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ClientBodyBufferSize: "16k",
ProxyMaxTempFileSize: "1024m",
ProxyBuffering: true,
ProxyBuffers: "8 4k",
Expand All @@ -16288,6 +16291,7 @@ func TestGenerateLocationForGrpcProxying(t *testing.T) {
ProxyReadTimeout: "31s",
ProxySendTimeout: "32s",
ClientMaxBodySize: "1m",
ClientBodyBufferSize: "16k",
ProxyMaxTempFileSize: "1024m",
ProxyBuffering: true,
ProxyBuffers: "8 4k",
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/configuration/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ type Upstream struct {
ProxyBusyBuffersSize string `json:"busy-buffers-size"`
// Sets the maximum allowed size of the client request body. The default is set in the client-max-body-size ConfigMap key.
ClientMaxBodySize string `json:"client-max-body-size"`
// Sets the size of the buffer used for reading the client request body.
ClientBodyBufferSize string `json:"client-body-buffer-size"`
// The TLS configuration for the Upstream.
TLS UpstreamTLS `json:"tls"`
// The health check configuration for the Upstream. Note: this feature is supported only in NGINX Plus.
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/configuration/validation/virtualserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ func (vsv *VirtualServerValidator) validateUpstreams(upstreams []v1.Upstream, fi
allErrs = append(allErrs, validatePositiveIntOrZeroFromPointer(u.Keepalive, idxPath.Child("keepalive"))...)
allErrs = append(allErrs, validatePositiveIntOrZeroFromPointer(u.MaxConns, idxPath.Child("max-conns"))...)
allErrs = append(allErrs, validateOffset(u.ClientMaxBodySize, idxPath.Child("client-max-body-size"))...)
allErrs = append(allErrs, validateSize(u.ClientBodyBufferSize, idxPath.Child("client-body-buffer-size"))...)
allErrs = append(allErrs, validateUpstreamHealthCheck(u.HealthCheck, u.Type, idxPath.Child("healthCheck"))...)
allErrs = append(allErrs, validateTime(u.SlowStart, idxPath.Child("slow-start"))...)
allErrs = append(allErrs, validateBuffer(u.ProxyBuffers, idxPath.Child("buffers"))...)
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/configuration/validation/virtualserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ func TestValidateUpstreams(t *testing.T) {
ProxyNextUpstreamTries: 5,
MaxConns: createPointerFromInt(16),
Type: "grpc",
ClientBodyBufferSize: "16k",
},
{
Name: "upstream2",
Expand Down Expand Up @@ -743,6 +744,20 @@ func TestValidateUpstreamsFails(t *testing.T) {
},
msg: "invalid value for ClientMaxBodySize",
},
{
upstreams: []v1.Upstream{
{
Name: "upstream1",
Service: "test-1",
Port: 80,
ClientBodyBufferSize: "10hello",
},
},
expectedUpstreamNames: map[string]sets.Empty{
"upstream1": {},
},
msg: "invalid value for ClientBodyBufferSize",
},
{
upstreams: []v1.Upstream{
{
Expand Down
Loading