Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for conflict of rest_listen_uri and web_listen_uri #2652

Merged
merged 1 commit into from Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions graylog2-server/src/main/java/org/graylog2/Configuration.java
Expand Up @@ -319,10 +319,24 @@ public int getLoadBalancerRequestThrottleJournalUsage() {
}

@ValidatorMethod
@SuppressWarnings("unused")
public void validatePasswordSecret() throws ValidationException {
final String passwordSecret = getPasswordSecret();
if (passwordSecret == null || passwordSecret.length() < 16) {
throw new ValidationException("The minimum length for \"password_secret\" is 16 characters.");
}
}

@ValidatorMethod
@SuppressWarnings("unused")
public void validateNetworkInterfaces() throws ValidationException {
final URI restListenUri = getRestListenUri();
final URI webListenUri = getWebListenUri();

if ((restListenUri.getPort() == webListenUri.getPort()) &&
!restListenUri.getHost().equals(webListenUri.getHost()) &&
("0.0.0.0".equals(restListenUri.getHost()) || "0.0.0.0".equals(webListenUri.getHost()))) {
throw new ValidationException("Wildcard IP addresses cannot be used if the Graylog REST API and web interface listen on the same port.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding the current settings of rest_listen_uri and web_listen_uri to the message? I think that makes it easier to debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was afraid the message would get too convoluted if those were added.

}
}
}
24 changes: 24 additions & 0 deletions graylog2-server/src/test/java/org/graylog2/ConfigurationTest.java
Expand Up @@ -196,4 +196,28 @@ public void testPasswordSecretIsValid() throws ValidationException, RepositoryEx

assertThat(configuration.getPasswordSecret()).isEqualTo("abcdefghijklmnopqrstuvwxyz");
}

@Test
public void testRestApiListeningOnWildcardOnSamePortAsWebInterface() throws ValidationException, RepositoryException {
validProperties.put("rest_listen_uri", "http://0.0.0.0:9000/api/");
validProperties.put("web_listen_uri", "http://127.0.0.1:9000/");

expectedException.expect(ValidationException.class);
expectedException.expectMessage("Wildcard IP addresses cannot be used if the Graylog REST API and web interface listen on the same port.");

Configuration configuration = new Configuration();
new JadConfig(new InMemoryRepository(validProperties), configuration).process();
}

@Test
public void testWebInterfaceListeningOnWildcardOnSamePortAsRestApi() throws ValidationException, RepositoryException {
validProperties.put("rest_listen_uri", "http://127.0.0.1:9000/api/");
validProperties.put("web_listen_uri", "http://0.0.0.0:9000/");

expectedException.expect(ValidationException.class);
expectedException.expectMessage("Wildcard IP addresses cannot be used if the Graylog REST API and web interface listen on the same port.");

Configuration configuration = new Configuration();
new JadConfig(new InMemoryRepository(validProperties), configuration).process();
}
}