Skip to content

Commit b27d66f

Browse files
committed
Merge pull request #4456 from eddumelendez/gh-4325
* pr/4456: Polish contribution Add timeout configuration for CRaSH
2 parents 0c8d302 + ba2aea4 commit b27d66f

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/ShellProperties.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
*
3737
* @author Christian Dupuis
3838
* @author Phillip Webb
39+
* @author Eddú Meléndez
3940
*/
4041
@ConfigurationProperties(prefix = "shell", ignoreUnknownFields = true)
4142
public class ShellProperties {
@@ -242,10 +243,22 @@ public static class Ssh extends CrshShellProperties {
242243
*/
243244
private Integer port = 2000;
244245

246+
/**
247+
* Number of milliseconds after user will be prompted to login again.
248+
*/
249+
private Integer authTimeout = 600000;
250+
251+
/**
252+
* Number of milliseconds after which unused connections are closed.
253+
*/
254+
private Integer idleTimeout = 600000;
255+
245256
@Override
246257
protected void applyToCrshShellConfig(Properties config) {
247258
if (this.enabled) {
248259
config.put("crash.ssh.port", String.valueOf(this.port));
260+
config.put("crash.ssh.auth_timeout", String.valueOf(this.authTimeout));
261+
config.put("crash.ssh.idle_timeout", String.valueOf(this.idleTimeout));
249262
if (this.keyPath != null) {
250263
config.put("crash.ssh.keypath", this.keyPath);
251264
}
@@ -278,6 +291,21 @@ public Integer getPort() {
278291
return this.port;
279292
}
280293

294+
public Integer getIdleTimeout() {
295+
return this.idleTimeout;
296+
}
297+
298+
public void setIdleTimeout(Integer idleTimeout) {
299+
this.idleTimeout = idleTimeout;
300+
}
301+
302+
public Integer getAuthTimeout() {
303+
return this.authTimeout;
304+
}
305+
306+
public void setAuthTimeout(Integer authTimeout) {
307+
this.authTimeout = authTimeout;
308+
}
281309
}
282310

283311
/**

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/autoconfigure/CrshAutoConfigurationTests.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
*
6363
* @author Christian Dupuis
6464
* @author Andreas Ahlenstorf
65+
* @author Eddú Meléndez
6566
*/
6667
@SuppressWarnings({ "rawtypes", "unchecked" })
6768
public class CrshAutoConfigurationTests {
@@ -80,10 +81,7 @@ public void testDisabledPlugins() throws Exception {
8081
MockEnvironment env = new MockEnvironment();
8182
env.setProperty("shell.disabled_plugins",
8283
"GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin");
83-
this.context = new AnnotationConfigWebApplicationContext();
84-
this.context.setEnvironment(env);
85-
this.context.register(CrshAutoConfiguration.class);
86-
this.context.refresh();
84+
load(env);
8785

8886
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
8987
assertNotNull(lifeCycle);
@@ -112,32 +110,49 @@ public void testSshConfiguration() {
112110
MockEnvironment env = new MockEnvironment();
113111
env.setProperty("shell.ssh.enabled", "true");
114112
env.setProperty("shell.ssh.port", "3333");
115-
this.context = new AnnotationConfigWebApplicationContext();
116-
this.context.setEnvironment(env);
117-
this.context.register(CrshAutoConfiguration.class);
118-
this.context.refresh();
113+
load(env);
119114

120115
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
121116

122117
assertEquals("3333", lifeCycle.getConfig().getProperty("crash.ssh.port"));
118+
assertEquals("600000", lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"));
119+
assertEquals("600000", lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout"));
123120
}
124121

125122
@Test
126123
public void testSshConfigurationWithKeyPath() {
127124
MockEnvironment env = new MockEnvironment();
128125
env.setProperty("shell.ssh.enabled", "true");
129126
env.setProperty("shell.ssh.key_path", "~/.ssh/id.pem");
130-
this.context = new AnnotationConfigWebApplicationContext();
131-
this.context.setEnvironment(env);
132-
this.context.register(CrshAutoConfiguration.class);
133-
this.context.refresh();
127+
load(env);
134128

135129
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
136130

137131
assertEquals("~/.ssh/id.pem",
138132
lifeCycle.getConfig().getProperty("crash.ssh.keypath"));
139133
}
140134

135+
@Test
136+
public void testSshConfigurationCustomTimeouts() {
137+
MockEnvironment env = new MockEnvironment();
138+
env.setProperty("shell.ssh.enabled", "true");
139+
env.setProperty("shell.ssh.auth-timeout", "300000");
140+
env.setProperty("shell.ssh.idle-timeout", "400000");
141+
load(env);
142+
143+
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
144+
145+
assertEquals("300000", lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"));
146+
assertEquals("400000", lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout"));
147+
}
148+
149+
private void load(MockEnvironment env) {
150+
this.context = new AnnotationConfigWebApplicationContext();
151+
this.context.setEnvironment(env);
152+
this.context.register(CrshAutoConfiguration.class);
153+
this.context.refresh();
154+
}
155+
141156
@Test
142157
public void testCommandResolution() {
143158
this.context = new AnnotationConfigWebApplicationContext();

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,9 @@ content into your application; rather pick only the properties that you need.
846846
shell.config-path-patterns=classpath*:/crash/* # Patterns to use to look for configurations.
847847
shell.disabled-commands=jpa*,jdbc*,jndi* # Comma-separated list of commands to disable.
848848
shell.disabled-plugins= # Comma-separated list of plugins to disable. Certain plugins are disabled by default based on the environment.
849+
shell.ssh.auth-timeout = # Number of milliseconds after user will be prompted to login again.
849850
shell.ssh.enabled=true # Enable CRaSH SSH support.
851+
shell.ssh.idle-timeout = # Number of milliseconds after which unused connections are closed.
850852
shell.ssh.key-path= # Path to the SSH server key.
851853
shell.ssh.port=2000 # SSH port.
852854
shell.telnet.enabled=false # Enable CRaSH telnet support. Enabled by default if the TelnetPlugin is available.

0 commit comments

Comments
 (0)