Skip to content

Commit

Permalink
Add timeout configuration for CRaSH
Browse files Browse the repository at this point in the history
  • Loading branch information
eddumelendez authored and snicoll committed Nov 13, 2015
1 parent 0c8d302 commit 41300c3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*
* @author Christian Dupuis
* @author Phillip Webb
* @author Eddú Meléndez
*/
@ConfigurationProperties(prefix = "shell", ignoreUnknownFields = true)
public class ShellProperties {
Expand Down Expand Up @@ -242,10 +243,22 @@ public static class Ssh extends CrshShellProperties {
*/
private Integer port = 2000;

/**
* Number of milliseconds after which unused connections are closed.
*/
private Integer idleTimeout = 600000;

/**
* Number of milliseconds after user will be prompted to login again.
*/
private Integer authTimeout = 600000;

@Override
protected void applyToCrshShellConfig(Properties config) {
if (this.enabled) {
config.put("crash.ssh.port", String.valueOf(this.port));
config.put("crash.ssh.auth_timeout", String.valueOf(this.authTimeout));
config.put("crash.ssh.idle_timeout", String.valueOf(this.idleTimeout));
if (this.keyPath != null) {
config.put("crash.ssh.keypath", this.keyPath);
}
Expand Down Expand Up @@ -278,6 +291,21 @@ public Integer getPort() {
return this.port;
}

public Integer getIdleTimeout() {
return this.idleTimeout;
}

public void setIdleTimeout(Integer idleTimeout) {
this.idleTimeout = idleTimeout;
}

public Integer getAuthTimeout() {
return this.authTimeout;
}

public void setAuthTimeout(Integer authTimeout) {
this.authTimeout = authTimeout;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
*
* @author Christian Dupuis
* @author Andreas Ahlenstorf
* @author Eddú Meléndez
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class CrshAutoConfigurationTests {
Expand All @@ -80,10 +81,7 @@ public void testDisabledPlugins() throws Exception {
MockEnvironment env = new MockEnvironment();
env.setProperty("shell.disabled_plugins",
"GroovyREPL, termIOHandler, org.crsh.auth.AuthenticationPlugin");
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
load(env);

PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertNotNull(lifeCycle);
Expand Down Expand Up @@ -112,32 +110,49 @@ public void testSshConfiguration() {
MockEnvironment env = new MockEnvironment();
env.setProperty("shell.ssh.enabled", "true");
env.setProperty("shell.ssh.port", "3333");
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
load(env);

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

assertEquals("3333", lifeCycle.getConfig().getProperty("crash.ssh.port"));
assertEquals("600000", lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"));
assertEquals("600000", lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout"));
}

@Test
public void testSshConfigurationWithKeyPath() {
MockEnvironment env = new MockEnvironment();
env.setProperty("shell.ssh.enabled", "true");
env.setProperty("shell.ssh.key_path", "~/.ssh/id.pem");
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
load(env);

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

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

@Test
public void testSshConfigurationCustomTimeouts() {
MockEnvironment env = new MockEnvironment();
env.setProperty("shell.ssh.enabled", "true");
env.setProperty("shell.ssh.auth-timeout", "300000");
env.setProperty("shell.ssh.idle-timeout", "300000");
load(env);

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

assertEquals("300000", lifeCycle.getConfig().getProperty("crash.ssh.auth_timeout"));
assertEquals("300000", lifeCycle.getConfig().getProperty("crash.ssh.idle_timeout"));
}

private void load(MockEnvironment env) {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setEnvironment(env);
this.context.register(CrshAutoConfiguration.class);
this.context.refresh();
}

@Test
public void testCommandResolution() {
this.context = new AnnotationConfigWebApplicationContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,9 @@ content into your application; rather pick only the properties that you need.
shell.config-path-patterns=classpath*:/crash/* # Patterns to use to look for configurations.
shell.disabled-commands=jpa*,jdbc*,jndi* # Comma-separated list of commands to disable.
shell.disabled-plugins= # Comma-separated list of plugins to disable. Certain plugins are disabled by default based on the environment.
shell.ssh.auth-timeout = # Number of milliseconds after user will be prompted to login again.
shell.ssh.enabled=true # Enable CRaSH SSH support.
shell.ssh.idle-timeout = # Number of milliseconds after which unused connections are closed.
shell.ssh.key-path= # Path to the SSH server key.
shell.ssh.port=2000 # SSH port.
shell.telnet.enabled=false # Enable CRaSH telnet support. Enabled by default if the TelnetPlugin is available.
Expand Down

0 comments on commit 41300c3

Please sign in to comment.