From e1f665fc194bf44df75718bf4e5870b6d60abcc5 Mon Sep 17 00:00:00 2001 From: Rene Pfeuffer Date: Wed, 12 Mar 2025 14:43:41 +0100 Subject: [PATCH] Add possibility to configure form boundaries in Jetty The configuration options 'maxFormKeys' and 'maxFormContentSize' from Jetty can now be set using the SCM config.yml file or environment variables. This is required, when instances with lots of repositories are to be migrated from 1.x to 3.x. --- docs/en/migrate-scm-manager-from-v1/index.md | 29 ++++++++----------- gradle/changelog/form_config.yaml | 2 ++ .../sonia/scm/server/ServerConfigYaml.java | 20 +++++++++++++ .../sonia/scm/server/ServerConfiguration.java | 7 +++-- 4 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 gradle/changelog/form_config.yaml diff --git a/docs/en/migrate-scm-manager-from-v1/index.md b/docs/en/migrate-scm-manager-from-v1/index.md index d9aea6418a..2fa2dcb55d 100644 --- a/docs/en/migrate-scm-manager-from-v1/index.md +++ b/docs/en/migrate-scm-manager-from-v1/index.md @@ -53,25 +53,20 @@ If however you have to install plugins manually (for example because you cannot # Huge number of repositories -If you have more than 100 Repositories to migrate, you may have to adapt some configuration and increase the limit of jetty form keys. You can do this by setting the `maxFormKeys` and `maxFormContentSize` of the webapp in `conf/server-config.xml`. You have to add the keys to the `WebAppContext` with the id `"scm-webapp"` e.g.: +If you have more than 100 Repositories to migrate, you may have to adapt some configuration and increase the limit of jetty form keys. You can do this by setting the `maxFormKeys` and `maxFormContentSize` in your `conf/config.yml` file. You have to add the keys at top level of the yaml file: ``` - - /scm - - /var/webapp/scm-webapp.war - - - org.eclipse.jetty.servlet.Default.dirAllowed - false - - - /work/scm - - - 1000000 - 5000 - +# base server config +## Address to listen 0.0.0.0 means on every interface +addressBinding: 0.0.0.0 +port: 8080 +contextPath: /scm + +## Additions for the huge number of repositories: +maxFormContentSize: 1000000 +maxFormKeys: 5000 + +... ``` The value for `maxFormKeys` should be the count of your repositories * 3 + 10. The `maxFormContentSize` depends on the length of your repository namespace and name, but you should be safe with repository count * 100. diff --git a/gradle/changelog/form_config.yaml b/gradle/changelog/form_config.yaml new file mode 100644 index 0000000000..ae655b4c1a --- /dev/null +++ b/gradle/changelog/form_config.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Possibility to configure 'maxFormKeys' and 'maxFormContentSize' in Jetty diff --git a/scm-server/src/main/java/sonia/scm/server/ServerConfigYaml.java b/scm-server/src/main/java/sonia/scm/server/ServerConfigYaml.java index 5d46ecf516..e1beadc1cf 100644 --- a/scm-server/src/main/java/sonia/scm/server/ServerConfigYaml.java +++ b/scm-server/src/main/java/sonia/scm/server/ServerConfigYaml.java @@ -16,6 +16,8 @@ package sonia.scm.server; +import org.eclipse.jetty.server.handler.ContextHandler; + public class ServerConfigYaml { private static final String SCM_SERVER_PREFIX = "SCM_"; @@ -30,6 +32,8 @@ public class ServerConfigYaml { // Resolves the client ip instead of the reverse proxy ip if the X-Forwarded-For header is present private boolean forwardHeadersEnabled = false; private int idleTimeout = 0; + private int maxFormContentSize = ContextHandler.DEFAULT_MAX_FORM_CONTENT_SIZE; + private int maxFormKeys = ContextHandler.DEFAULT_MAX_FORM_KEYS; // ### SSL-related config // Only configure SSL if the key store path is set @@ -150,6 +154,22 @@ public class ServerConfigYaml { this.idleTimeout = idleTimeout; } + public int getMaxFormContentSize() { + return getEnvWithDefault("MAX_FORM_CONTENT_SIZE", maxFormContentSize); + } + + public void setMaxFormContentSize(int maxFormContentSize) { + this.maxFormContentSize = maxFormContentSize; + } + + public int getMaxFormKeys() { + return getEnvWithDefault("MAX_FORM_KEYS", maxFormKeys); + } + + public void setMaxFormKeys(int maxFormKeys) { + this.maxFormKeys = maxFormKeys; + } + static int getEnvWithDefault(String envKey, int configValue) { String value = getEnv(envKey); return value != null ? Integer.parseInt(value) : configValue; diff --git a/scm-server/src/main/java/sonia/scm/server/ServerConfiguration.java b/scm-server/src/main/java/sonia/scm/server/ServerConfiguration.java index 47b6582730..16617ffa23 100644 --- a/scm-server/src/main/java/sonia/scm/server/ServerConfiguration.java +++ b/scm-server/src/main/java/sonia/scm/server/ServerConfiguration.java @@ -152,6 +152,10 @@ public final class ServerConfiguration { ); System.out.printf("Set webapp temp directory to %s%n", webappTempDir); webApp.setTempDirectory(webappTempDir); + webApp.setMaxFormContentSize(configYaml.getMaxFormContentSize()); + System.out.println("Set webapp max form content size to " + configYaml.getMaxFormContentSize()); + webApp.setMaxFormKeys(configYaml.getMaxFormKeys()); + System.out.println("Set webapp max form keys to " + configYaml.getMaxFormKeys()); return webApp; } @@ -205,8 +209,7 @@ public final class ServerConfiguration { } for (Connector connector : server.getConnectors()) { - if (connector instanceof ServerConnector) { - ServerConnector serverConnector = (ServerConnector) connector; + if (connector instanceof ServerConnector serverConnector) { String scheme = "http"; String protocol = serverConnector.getDefaultProtocol(); if ("SSL".equalsIgnoreCase(protocol) || "TLS".equalsIgnoreCase(protocol)) {