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.
This commit is contained in:
Rene Pfeuffer
2025-03-12 14:43:41 +01:00
parent a4e51ebfe6
commit e1f665fc19
4 changed files with 39 additions and 19 deletions

View File

@@ -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:
```
<New id="scm-webapp" class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/scm</Set>
<Set name="war">
<SystemProperty name="basedir" default="."/>/var/webapp/scm-webapp.war</Set>
<!-- disable directory listings -->
<Call name="setInitParameter">
<Arg>org.eclipse.jetty.servlet.Default.dirAllowed</Arg>
<Arg>false</Arg>
</Call>
<Set name="tempDirectory">
<SystemProperty name="basedir" default="."/>/work/scm
</Set>
<!-- Set max form keys -->
<Set name="maxFormContentSize">1000000</Set>
<Set name="maxFormKeys">5000</Set>
</New>
# 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.

View File

@@ -0,0 +1,2 @@
- type: fixed
description: Possibility to configure 'maxFormKeys' and 'maxFormContentSize' in Jetty

View File

@@ -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;

View File

@@ -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)) {