Skip to content

Commit 5dcb0cc

Browse files
committed
Require security to be provided by X-Pack
In order to provide a stronger guarantee to our solutions, that if a cluster is running the default distribution and has security (authentication) enabled, then it will be provided by Elastic's security features, and users can rely on it behaving in the ways they expect, this change 1) mandate that security in default distribution is provided by X-Pack by always installing the Security Rest Filter and 2) adding warnings if credentials are provided to a cluster that does not have security enabled. Related: elastic#188
1 parent bedc61d commit 5dcb0cc

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

x-pack/plugin/security/qa/basic-enable-security/src/javaRestTest/java/org/elasticsearch/xpack/security/EnableSecurityOnBasicLicenseIT.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
*/
66
package org.elasticsearch.xpack.security;
77

8+
import org.apache.http.HttpHost;
89
import org.apache.http.util.EntityUtils;
910
import org.elasticsearch.client.Request;
1011
import org.elasticsearch.client.Response;
1112
import org.elasticsearch.client.ResponseException;
13+
import org.elasticsearch.client.RestClient;
14+
import org.elasticsearch.client.RestClientBuilder;
1215
import org.elasticsearch.common.Booleans;
1316
import org.elasticsearch.common.settings.SecureString;
1417
import org.elasticsearch.common.settings.Settings;
@@ -20,6 +23,7 @@
2023

2124
import java.io.IOException;
2225
import java.util.Arrays;
26+
import java.util.List;
2327
import java.util.Locale;
2428
import java.util.Map;
2529

@@ -55,6 +59,14 @@ protected Settings restClientSettings() {
5559
.build();
5660
}
5761

62+
@Override
63+
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
64+
RestClientBuilder builder = RestClient.builder(hosts);
65+
configureClient(builder, settings);
66+
builder.setStrictDeprecationMode(false);
67+
return builder.build();
68+
}
69+
5870
@Override
5971
protected boolean preserveClusterUponCompletion() {
6072
// If this is the first run (security not yet enabled), then don't clean up afterwards because we want to test restart with data
@@ -85,6 +97,21 @@ public void testSecuritySetup() throws Exception {
8597
}
8698
}
8799

100+
public void testSecurityDisabledWarning() throws Exception {
101+
final Request request = new Request("GET", "/_cat/indices");
102+
Response response = client().performRequest(request);
103+
List<String> warningHeaders = response.getWarnings();
104+
if (securityEnabled) {
105+
assertThat (warningHeaders.isEmpty(), equalTo(true));
106+
} else {
107+
assertThat (warningHeaders.size(), equalTo(1));
108+
assertThat (warningHeaders.get(0),
109+
containsString("Elasticsearch security features are not enabled, anyone can access your cluster without " +
110+
"authentication. Read https://www.elastic.co/guide/en/elasticsearch/reference/<autodetected version number>/" +
111+
"get-started-enable-security.html for more information."));
112+
}
113+
}
114+
88115
private String getClusterInfo() throws IOException {
89116
Map<String, Object> info = getAsMap("/");
90117
assertThat(info, notNullValue());

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,6 @@ public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings set
10341034

10351035
@Override
10361036
public UnaryOperator<RestHandler> getRestHandlerWrapper(ThreadContext threadContext) {
1037-
if (enabled == false) {
1038-
return null;
1039-
}
10401037
final boolean ssl = HTTP_SSL_ENABLED.get(settings);
10411038
final SSLConfiguration httpSSLConfig = getSslService().getHttpTransportSSLConfiguration();
10421039
boolean extractClientCertificate = ssl && getSslService().isSSLClientAuthEnabled(httpSSLConfig);

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,12 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c
9595
e -> handleException("Secondary authentication", request, channel, e)));
9696
}, e -> handleException("Authentication", request, channel, e)));
9797
} else {
98-
HeaderWarning.addWarning("Security is disabled. No authentication available for REST request.");
98+
if (request.getHeaders() != null && request.getHeaders().containsKey("Authorization")) {
99+
HeaderWarning.addWarning("Elasticsearch security features are not enabled, anyone can access your cluster without " +
100+
"authentication. Read https://www.elastic.co/guide/en/elasticsearch/reference/<autodetected version number>/" +
101+
"get-started-enable-security.html for more information.");
102+
}
103+
restHandler.handleRequest(request, channel, client);
99104
}
100105
}
101106

0 commit comments

Comments
 (0)