diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index 007487b7d..72d84cf27 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -133,36 +133,37 @@ var ( } return true }, - "escapeLiteralDollar": escapeLiteralDollar, - "shouldConfigureLuaRestyWAF": shouldConfigureLuaRestyWAF, - "buildLuaSharedDictionaries": buildLuaSharedDictionaries, - "buildLocation": buildLocation, - "buildAuthLocation": buildAuthLocation, - "shouldApplyGlobalAuth": shouldApplyGlobalAuth, - "buildAuthResponseHeaders": buildAuthResponseHeaders, - "buildProxyPass": buildProxyPass, - "filterRateLimits": filterRateLimits, - "buildRateLimitZones": buildRateLimitZones, - "buildRateLimit": buildRateLimit, - "configForLua": configForLua, - "locationConfigForLua": locationConfigForLua, - "buildResolvers": buildResolvers, - "buildUpstreamName": buildUpstreamName, - "isLocationInLocationList": isLocationInLocationList, - "isLocationAllowed": isLocationAllowed, - "buildLogFormatUpstream": buildLogFormatUpstream, - "buildDenyVariable": buildDenyVariable, - "getenv": os.Getenv, - "contains": strings.Contains, - "hasPrefix": strings.HasPrefix, - "hasSuffix": strings.HasSuffix, - "trimSpace": strings.TrimSpace, - "toUpper": strings.ToUpper, - "toLower": strings.ToLower, - "formatIP": formatIP, - "quote": quote, - "buildNextUpstream": buildNextUpstream, - "getIngressInformation": getIngressInformation, + "escapeLiteralDollar": escapeLiteralDollar, + "shouldConfigureLuaRestyWAF": shouldConfigureLuaRestyWAF, + "buildLuaSharedDictionaries": buildLuaSharedDictionaries, + "luaConfigurationRequestBodySize": luaConfigurationRequestBodySize, + "buildLocation": buildLocation, + "buildAuthLocation": buildAuthLocation, + "shouldApplyGlobalAuth": shouldApplyGlobalAuth, + "buildAuthResponseHeaders": buildAuthResponseHeaders, + "buildProxyPass": buildProxyPass, + "filterRateLimits": filterRateLimits, + "buildRateLimitZones": buildRateLimitZones, + "buildRateLimit": buildRateLimit, + "configForLua": configForLua, + "locationConfigForLua": locationConfigForLua, + "buildResolvers": buildResolvers, + "buildUpstreamName": buildUpstreamName, + "isLocationInLocationList": isLocationInLocationList, + "isLocationAllowed": isLocationAllowed, + "buildLogFormatUpstream": buildLogFormatUpstream, + "buildDenyVariable": buildDenyVariable, + "getenv": os.Getenv, + "contains": strings.Contains, + "hasPrefix": strings.HasPrefix, + "hasSuffix": strings.HasSuffix, + "trimSpace": strings.TrimSpace, + "toUpper": strings.ToUpper, + "toLower": strings.ToLower, + "formatIP": formatIP, + "quote": quote, + "buildNextUpstream": buildNextUpstream, + "getIngressInformation": getIngressInformation, "serverConfig": func(all config.TemplateConfig, server *ingress.Server) interface{} { return struct{ First, Second interface{} }{all, server} }, @@ -272,6 +273,22 @@ func buildLuaSharedDictionaries(c interface{}, s interface{}, disableLuaRestyWAF return strings.Join(out, ";\n") + ";\n" } +func luaConfigurationRequestBodySize(c interface{}) string { + cfg, ok := c.(config.Configuration) + if !ok { + klog.Errorf("expected a 'config.Configuration' type but %T was returned", c) + return "100" // just a default number + } + + size := cfg.LuaSharedDicts["configuration_data"] + if size < cfg.LuaSharedDicts["certificate_data"] { + size = cfg.LuaSharedDicts["certificate_data"] + } + size = size + 1 + + return fmt.Sprintf("%d", size) +} + // configForLua returns some general configuration as Lua table represented as string func configForLua(input interface{}) string { all, ok := input.(config.TemplateConfig) diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index aa83bfd73..08e07d681 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -225,6 +225,19 @@ func TestBuildLuaSharedDictionaries(t *testing.T) { } } +func TestLuaConfigurationRequestBodySize(t *testing.T) { + cfg := config.Configuration{ + LuaSharedDicts: map[string]int{ + "configuration_data": 10, "certificate_data": 20, + }, + } + + size := luaConfigurationRequestBodySize(cfg) + if "21" != size { + t.Errorf("expected the size to be 20 but got: %v", size) + } +} + func TestFormatIP(t *testing.T) { cases := map[string]struct { Input, Output string diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index adc4e550c..172fdd9c6 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -580,9 +580,8 @@ http { } location /configuration { - # this should be equals to configuration_data dict - client_max_body_size 10m; - client_body_buffer_size 10m; + client_max_body_size {{ luaConfigurationRequestBodySize $cfg }}m; + client_body_buffer_size {{ luaConfigurationRequestBodySize $cfg }}m; proxy_buffering off; content_by_lua_block {