Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
ESExporter: Add option to disable hostname verification
Browse files Browse the repository at this point in the history
This adds a setting to allow hostname verification to be disabled for https
connections. Without this option Marvel will not work when the hostname
in a certificate cannot be verified.

Closes elastic#384
  • Loading branch information
jaymode committed Feb 17, 2015
1 parent 6671dc2 commit 9acf9b4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public class ESExporter extends AbstractLifecycleComponent<ESExporter> implement

/** https support * */
final SSLSocketFactory sslSocketFactory;
volatile boolean hostnameVerification;

final ClusterService clusterService;
final ClusterName clusterName;
Expand Down Expand Up @@ -143,6 +144,7 @@ public ESExporter(Settings settings, ClusterService clusterService, ClusterName
dynamicSettings.addDynamicSetting(SETTINGS_HOSTS + ".*");
dynamicSettings.addDynamicSetting(SETTINGS_TIMEOUT);
dynamicSettings.addDynamicSetting(SETTINGS_READ_TIMEOUT);
dynamicSettings.addDynamicSetting(SETTINGS_SSL_HOSTNAME_VERIFICATION);
nodeSettingsService.addListener(this);

if (!settings.getByPrefix(SETTINGS_SSL_PREFIX).getAsMap().isEmpty()) {
Expand All @@ -151,6 +153,7 @@ public ESExporter(Settings settings, ClusterService clusterService, ClusterName
logger.trace("no ssl context configured");
sslSocketFactory = null;
}
hostnameVerification = settings.getAsBoolean(SETTINGS_SSL_HOSTNAME_VERIFICATION, true);

logger.debug("initialized with targets: {}, index prefix [{}], index time format [{}]",
Utils.santizeUrlPwds(Strings.arrayToCommaDelimitedString(hosts)), indexPrefix, indexTimeFormat);
Expand Down Expand Up @@ -420,6 +423,9 @@ private HttpURLConnection openConnection(String host, String method, String path
if (conn instanceof HttpsURLConnection && sslSocketFactory != null) {
HttpsURLConnection httpsConn = (HttpsURLConnection) conn;
httpsConn.setSSLSocketFactory(sslSocketFactory);
if (!hostnameVerification) {
httpsConn.setHostnameVerifier(TrustAllHostnameVerifier.INSTANCE);
}
}

conn.setRequestMethod(method);
Expand Down Expand Up @@ -563,6 +569,12 @@ public void onRefreshSettings(Settings settings) {
this.checkedAndUploadedIndexTemplate = false;
this.boundToLocalNode = false;
}

Boolean newHostnameVerification = settings.getAsBoolean(SETTINGS_SSL_HOSTNAME_VERIFICATION, null);
if (newHostnameVerification != null) {
logger.info("hostname verification set to [{}]", newHostnameVerification);
this.hostnameVerification = newHostnameVerification;
}
}

interface MultiXContentRenderer {
Expand Down Expand Up @@ -806,7 +818,7 @@ public void run() {
public static final String SETTINGS_SSL_TRUSTSTORE = SETTINGS_SSL_PREFIX + "truststore.path";
public static final String SETTINGS_SSL_TRUSTSTORE_PASSWORD = SETTINGS_SSL_PREFIX + "truststore.password";
public static final String SETTINGS_SSL_TRUSTSTORE_ALGORITHM = SETTINGS_SSL_PREFIX + "truststore.algorithm";

public static final String SETTINGS_SSL_HOSTNAME_VERIFICATION = SETTINGS_SSL_PREFIX + "hostname_verification";

/** SSL Initialization * */
public SSLSocketFactory createSSLSocketFactory(Settings settings) {
Expand Down Expand Up @@ -861,5 +873,20 @@ public SSLSocketFactory createSSLSocketFactory(Settings settings) {
}
return sslContext.getSocketFactory();
}

/**
* Trust all hostname verifier. This simply returns true to completely disable hostname verification
*/
static class TrustAllHostnameVerifier implements HostnameVerifier {
static final HostnameVerifier INSTANCE = new TrustAllHostnameVerifier();

private TrustAllHostnameVerifier() {
}

@Override
public boolean verify(String s, SSLSession sslSession) {
return true;
}
}
}

7 changes: 6 additions & 1 deletion docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ the password to use when accessing the trust store.

Trust store format (defaults to SunX509).

`marvel.agent.exporter.es.ssl.hostname_verification`::
+
added[1.3.1] - Set this to `false` to disable HTTPS hostname verification when exporting.
+
This setting is update-able via the Cluster Update Settings API.

[[marvel-indices]]
=== Marvel indices
Expand Down Expand Up @@ -175,4 +180,4 @@ Needed for basic authentication support. You may want tighten it to only allow t

Please see the {ref}/modules-http.html[Elasticsearch documentation] for more information.

NOTE: enabling CORS may result in unwarrented access to your cluster. Consider these settings carefully.
NOTE: enabling CORS may result in unwarrented access to your cluster. Consider these settings carefully.

0 comments on commit 9acf9b4

Please sign in to comment.