Warn users if security is implicitly disabled (#70114)

* Warn users if security is implicitly disabled

Elasticsearch has security features implicitly disabled by default for
Basic and Trial licenses, unless explicitly set in the configuration
file.
This may be good for onboarding, but it also lead to unintended insecure
 clusters.
 This change introduces clear warnings when security features are
 implicitly disabled.
 - a warning header in each REST response if security is implicitly
 disabled;
 - a log message during cluster boot.
This commit is contained in:
Lyudmila Fokina 2021-04-13 18:33:41 +02:00 committed by GitHub
parent 46efa6ad04
commit 3b0b7941ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
102 changed files with 404 additions and 107 deletions

View file

@ -10,7 +10,6 @@ package org.elasticsearch.docker.test;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.common.CharArrays;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -24,11 +23,8 @@ import org.junit.BeforeClass;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.CharBuffer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays;
import java.util.Base64;
public class DockerYmlTestSuiteIT extends ESClientYamlSuiteTestCase { public class DockerYmlTestSuiteIT extends ESClientYamlSuiteTestCase {
@ -130,22 +126,4 @@ public class DockerYmlTestSuiteIT extends ESClientYamlSuiteTestCase {
} }
return "https"; return "https";
} }
private static String basicAuthHeaderValue(String username, SecureString passwd) {
CharBuffer chars = CharBuffer.allocate(username.length() + passwd.length() + 1);
byte[] charBytes = null;
try {
chars.put(username).put(':').put(passwd.getChars());
charBytes = CharArrays.toUtf8Bytes(chars.array());
//TODO we still have passwords in Strings in headers. Maybe we can look into using a CharSequence?
String basicToken = Base64.getEncoder().encodeToString(charBytes);
return "Basic " + basicToken;
} finally {
Arrays.fill(chars.array(), (char) 0);
if (charBytes != null) {
Arrays.fill(charBytes, (byte) 0);
}
}
}
} }

View file

@ -68,6 +68,7 @@ testClusters.matching { it.name == "integTest"}.configureEach {
// enable regexes in painless so our tests don't complain about example snippets that use them // enable regexes in painless so our tests don't complain about example snippets that use them
setting 'script.painless.regex.enabled', 'true' setting 'script.painless.regex.enabled', 'true'
setting 'xpack.security.enabled', 'false'
setting 'path.repo', "${buildDir}/cluster/shared/repo" setting 'path.repo', "${buildDir}/cluster/shared/repo"
Closure configFile = { Closure configFile = {
extraConfigFile it, file("src/test/cluster/config/$it") extraConfigFile it, file("src/test/cluster/config/$it")

View file

@ -48,15 +48,7 @@ GET /_xpack/usage
{ {
"security" : { "security" : {
"available" : true, "available" : true,
"enabled" : false, "enabled" : false
"ssl" : {
"http" : {
"enabled" : false
},
"transport" : {
"enabled" : false
}
}
}, },
"monitoring" : { "monitoring" : {
"available" : true, "available" : true,

View file

@ -12,6 +12,8 @@ apply plugin: 'elasticsearch.rest-test'
testClusters.all { testClusters.all {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'resource.reload.interval.high', '100ms' setting 'resource.reload.interval.high', '100ms'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
} }
tasks.named("integTest").configure { tasks.named("integTest").configure {

View file

@ -11,6 +11,9 @@ import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.common.xcontent.ObjectPath;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
@ -53,4 +56,12 @@ public class UpdateDatabasesIT extends ESRestTestCase {
return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false); return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -23,6 +23,7 @@ dependencies {
testClusters.all { testClusters.all {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'false'
} }
tasks.named("test").configure { enabled = false } tasks.named("test").configure { enabled = false }

View file

@ -35,12 +35,14 @@ for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) {
numberOfNodes = 2 numberOfNodes = 2
versions = [bwcVersionStr, project.version] versions = [bwcVersionStr, project.version]
setting 'cluster.remote.node.attr', 'gateway' setting 'cluster.remote.node.attr', 'gateway'
setting 'xpack.security.enabled', 'false'
} }
"${baseName}-remote" { "${baseName}-remote" {
numberOfNodes = 3 numberOfNodes = 3
versions = [bwcVersionStr, project.version] versions = [bwcVersionStr, project.version]
firstNode.setting 'node.attr.gateway', 'true' firstNode.setting 'node.attr.gateway', 'true'
lastNode.setting 'node.attr.gateway', 'true' lastNode.setting 'node.attr.gateway', 'true'
setting 'xpack.security.enabled', 'false'
} }
} }

View file

@ -10,6 +10,11 @@ apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test' apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.test-with-dependencies' apply plugin: 'elasticsearch.test-with-dependencies'
testClusters.matching { it.name == "integTest" }.configureEach {
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
}
dependencies { dependencies {
testImplementation project(":client:rest-high-level") testImplementation project(":client:rest-high-level")
} }

View file

@ -38,7 +38,9 @@ import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.search.aggregations.InternalAggregations; import org.elasticsearch.search.aggregations.InternalAggregations;
@ -327,4 +329,12 @@ public class CrossClusterSearchUnavailableClusterIT extends ESRestTestCase {
super(restClient, (client) -> {}, Collections.emptyList()); super(restClient, (client) -> {}, Collections.emptyList());
} }
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -21,6 +21,8 @@ tasks.named("javaRestTest").configure {
testClusters.matching { it.name == "javaRestTest" }.configureEach { testClusters.matching { it.name == "javaRestTest" }.configureEach {
systemProperty "die.with.dignity.test", "whatever" systemProperty "die.with.dignity.test", "whatever"
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
} }
tasks.named("test").configure { tasks.named("test").configure {

View file

@ -10,7 +10,9 @@ package org.elasticsearch.qa.die_with_dignity;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -99,13 +101,14 @@ public class DieWithDignityIT extends ESRestTestCase {
@Override @Override
protected final Settings restClientSettings() { protected final Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder() return Settings.builder()
.put(super.restClientSettings()) .put(super.restClientSettings())
.put(ThreadContext.PREFIX + ".Authorization", token)
// increase the timeout here to 90 seconds to handle long waits for a green // increase the timeout here to 90 seconds to handle long waits for a green
// cluster health. the waits for green need to be longer than a minute to // cluster health. the waits for green need to be longer than a minute to
// account for delayed shards // account for delayed shards
.put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "1s") .put(ESRestTestCase.CLIENT_SOCKET_TIMEOUT, "1s")
.build(); .build();
} }
} }

View file

@ -26,6 +26,7 @@ for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) {
// some tests rely on the translog not being flushed // some tests rely on the translog not being flushed
setting 'indices.memory.shard_inactive_time', '60m' setting 'indices.memory.shard_inactive_time', '60m'
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'xpack.security.enabled', 'false'
} }
} }
@ -59,4 +60,4 @@ for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) {
tasks.register(bwcTaskName(bwcVersion)) { tasks.register(bwcTaskName(bwcVersion)) {
dependsOn tasks.named("${baseName}#upgradedClusterTest") dependsOn tasks.named("${baseName}#upgradedClusterTest")
} }
} }

View file

@ -11,6 +11,10 @@ apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test' apply plugin: 'elasticsearch.rest-test'
apply plugin: 'elasticsearch.standalone-test' apply plugin: 'elasticsearch.standalone-test'
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
testClusters.matching { it.name == "integTest" }.configureEach { testClusters.matching { it.name == "integTest" }.configureEach {
/** /**
* Provide a custom log4j configuration where layout is an old style pattern and confirm that Elasticsearch * Provide a custom log4j configuration where layout is an old style pattern and confirm that Elasticsearch

View file

@ -38,6 +38,7 @@ for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) {
numberOfNodes = 4 numberOfNodes = 4
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'xpack.security.enabled', 'false'
} }
} }

View file

@ -25,6 +25,7 @@ testClusters {
'remote-cluster' { 'remote-cluster' {
numberOfNodes = 2 numberOfNodes = 2
setting 'node.roles', '[data,ingest,master]' setting 'node.roles', '[data,ingest,master]'
setting 'xpack.security.enabled', 'false'
} }
} }
@ -38,6 +39,7 @@ testClusters.matching { it.name == "mixedClusterTest"}.configureEach {
setting 'cluster.remote.my_remote_cluster.seeds', setting 'cluster.remote.my_remote_cluster.seeds',
{ "\"${testClusters.'remote-cluster'.getAllTransportPortURI().get(0)}\"" } { "\"${testClusters.'remote-cluster'.getAllTransportPortURI().get(0)}\"" }
setting 'cluster.remote.connections_per_cluster', '1' setting 'cluster.remote.connections_per_cluster', '1'
setting 'xpack.security.enabled', 'false'
} }
tasks.register("integTest") { tasks.register("integTest") {

View file

@ -13,7 +13,6 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.CharArrays;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -26,11 +25,8 @@ import org.junit.BeforeClass;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.CharBuffer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections; import java.util.Collections;
public abstract class AbstractMultiClusterRemoteTestCase extends ESRestTestCase { public abstract class AbstractMultiClusterRemoteTestCase extends ESRestTestCase {
@ -150,24 +146,6 @@ public abstract class AbstractMultiClusterRemoteTestCase extends ESRestTestCase
return "https"; return "https";
} }
private static String basicAuthHeaderValue(String username, SecureString passwd) {
CharBuffer chars = CharBuffer.allocate(username.length() + passwd.length() + 1);
byte[] charBytes = null;
try {
chars.put(username).put(':').put(passwd.getChars());
charBytes = CharArrays.toUtf8Bytes(chars.array());
//TODO we still have passwords in Strings in headers. Maybe we can look into using a CharSequence?
String basicToken = Base64.getEncoder().encodeToString(charBytes);
return "Basic " + basicToken;
} finally {
Arrays.fill(chars.array(), (char) 0);
if (charBytes != null) {
Arrays.fill(charBytes, (byte) 0);
}
}
}
private String getProperty(String key) { private String getProperty(String key) {
String value = System.getProperty(key); String value = System.getProperty(key);
if (value == null) { if (value == null) {

View file

@ -30,6 +30,7 @@ for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) {
version = v version = v
numberOfNodes = 2 numberOfNodes = 2
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'xpack.security.enabled', 'false'
} }
} }
@ -76,4 +77,4 @@ for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) {
tasks.register(bwcTaskName(bwcVersion)) { tasks.register(bwcTaskName(bwcVersion)) {
dependsOn tasks.named("${baseName}#Step4NewClusterTest") dependsOn tasks.named("${baseName}#Step4NewClusterTest")
} }
} }

View file

@ -38,6 +38,7 @@ for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) {
setting 'repositories.url.allowed_urls', 'http://snapshot.test*' setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'xpack.security.enabled', 'false'
} }
} }

View file

@ -17,6 +17,10 @@ dependencies {
testImplementation project(':plugins:transport-nio') // for http testImplementation project(':plugins:transport-nio') // for http
} }
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
tasks.named("integTest").configure { tasks.named("integTest").configure {
/* /*
* We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each * We have to disable setting the number of available processors as tests in the same JVM randomize processors and will step on each

View file

@ -15,6 +15,10 @@ dependencies {
testImplementation project(':modules:ingest-common') testImplementation project(':modules:ingest-common')
} }
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
testClusters.matching { it.name == "integTest" }.configureEach { testClusters.matching { it.name == "integTest" }.configureEach {
setting 'node.roles', '[data,master,remote_cluster_client]' setting 'node.roles', '[data,master,remote_cluster_client]'
} }

View file

@ -19,6 +19,10 @@ dependencies {
testImplementation project(':modules:reindex') testImplementation project(':modules:reindex')
} }
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
tasks.named("testingConventions").configure { tasks.named("testingConventions").configure {
naming { naming {
IT { IT {

View file

@ -23,6 +23,10 @@ testClusters.matching { it.name == "integTest" }.configureEach {
setting 'path.repo', repo.absolutePath setting 'path.repo', repo.absolutePath
} }
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
tasks.named("integTest").configure { tasks.named("integTest").configure {
doFirst { doFirst {
project.delete(repo) project.delete(repo)

View file

@ -27,6 +27,7 @@ testClusters.matching { it.name == "integTest" }.configureEach {
pluginPaths.each { pluginPath -> pluginPaths.each { pluginPath ->
plugin pluginPath plugin pluginPath
} }
setting 'xpack.security.enabled', 'false'
} }
ext.expansions = [ ext.expansions = [

View file

@ -1,5 +1,3 @@
import org.elasticsearch.gradle.OS
/* /*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License * or more contributor license agreements. Licensed under the Elastic License
@ -12,6 +10,10 @@ apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test' apply plugin: 'elasticsearch.rest-test'
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
testClusters.matching { it.name == "integTest" }.configureEach { testClusters.matching { it.name == "integTest" }.configureEach {
nameCustomization = { null } nameCustomization = { null }
} }

View file

@ -21,6 +21,8 @@ for (Version bwcVersion : BuildParams.bwcVersions.indexCompatible) {
testClusters { testClusters {
"${baseName}" { "${baseName}" {
version = bwcVersion.toString() version = bwcVersion.toString()
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
} }
} }

View file

@ -11,6 +11,9 @@ package org.elasticsearch.qa.verify_version_constants;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath; import org.elasticsearch.test.rest.yaml.ObjectPath;
@ -42,4 +45,12 @@ public class VerifyVersionConstantsIT extends ESRestTestCase {
*/ */
return true; return true;
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -33,10 +33,12 @@ import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder; import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.WarningsHandler; import org.elasticsearch.client.WarningsHandler;
import org.elasticsearch.common.CharArrays;
import org.elasticsearch.common.CheckedRunnable; import org.elasticsearch.common.CheckedRunnable;
import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.ssl.PemUtils; import org.elasticsearch.common.ssl.PemUtils;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
@ -67,6 +69,7 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
@ -80,6 +83,7 @@ import java.security.cert.Certificate;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -299,6 +303,28 @@ public abstract class ESRestTestCase extends ESTestCase {
return expectVersionSpecificWarnings(consumer -> consumer.current(warnings)); return expectVersionSpecificWarnings(consumer -> consumer.current(warnings));
} }
/**
* Construct a Basic auth header
* @param username user name
* @param passwd user password
*/
public static String basicAuthHeaderValue(String username, SecureString passwd) {
CharBuffer chars = CharBuffer.allocate(username.length() + passwd.length() + 1);
byte[] charBytes = null;
try {
chars.put(username).put(':').put(passwd.getChars());
charBytes = CharArrays.toUtf8Bytes(chars.array());
String basicToken = Base64.getEncoder().encodeToString(charBytes);
return "Basic " + basicToken;
} finally {
Arrays.fill(chars.array(), (char) 0);
if (charBytes != null) {
Arrays.fill(charBytes, (byte) 0);
}
}
}
/** /**
* Construct an HttpHost from the given host and port * Construct an HttpHost from the given host and port
*/ */

View file

@ -15,13 +15,18 @@ testClusters {
"leader-cluster" { "leader-cluster" {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
} }
"follow-cluster" { "follow-cluster" {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.monitoring.collection.enabled', 'true' setting 'xpack.monitoring.collection.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'cluster.remote.leader_cluster.seeds', { "\"${testClusters."leader-cluster".getAllTransportPortURI().join(",")}\"" } setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
setting 'cluster.remote.leader_cluster.seeds', { "\"${testClusters."leader-cluster".getAllTransportPortURI().join(",")}\""
}
} }
} }

View file

@ -13,6 +13,9 @@ import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.logging.JsonLogLine; import org.elasticsearch.common.logging.JsonLogLine;
import org.elasticsearch.common.logging.JsonLogsStream; import org.elasticsearch.common.logging.JsonLogsStream;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.hamcrest.FeatureMatcher; import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
@ -125,4 +128,12 @@ public class FollowIndexIT extends ESCCRRestTestCase {
} }
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -13,11 +13,15 @@ testClusters {
'leader-cluster' { 'leader-cluster' {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
setting 'path.repo', "${buildDir}/cluster/shared/repo/leader-cluster" setting 'path.repo', "${buildDir}/cluster/shared/repo/leader-cluster"
} }
'middle-cluster' { 'middle-cluster' {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
setting 'cluster.remote.leader_cluster.seeds', setting 'cluster.remote.leader_cluster.seeds',
{ "\"${testClusters.named('leader-cluster').get().getAllTransportPortURI().join(",")}\"" } { "\"${testClusters.named('leader-cluster').get().getAllTransportPortURI().join(",")}\"" }
} }
@ -55,6 +59,8 @@ testClusters.matching { it.name == "follow-cluster" }.configureEach {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.monitoring.collection.enabled', 'true' setting 'xpack.monitoring.collection.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
setting 'cluster.remote.leader_cluster.seeds', setting 'cluster.remote.leader_cluster.seeds',
{ "\"${testClusters.named('leader-cluster').get().getAllTransportPortURI().join(",")}\"" } { "\"${testClusters.named('leader-cluster').get().getAllTransportPortURI().join(",")}\"" }
setting 'cluster.remote.middle_cluster.seeds', setting 'cluster.remote.middle_cluster.seeds',

View file

@ -16,7 +16,9 @@ import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.CheckedRunnable; import org.elasticsearch.common.CheckedRunnable;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.common.xcontent.ObjectPath;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
@ -771,7 +773,7 @@ public class AutoFollowIT extends ESCCRRestTestCase {
Request deleteTemplateRequest = new Request("DELETE", "/_data_stream/" + name); Request deleteTemplateRequest = new Request("DELETE", "/_data_stream/" + name);
assertOK(client.performRequest(deleteTemplateRequest)); assertOK(client.performRequest(deleteTemplateRequest));
} }
private Response getAutoFollowStats() throws IOException { private Response getAutoFollowStats() throws IOException {
final Request statsRequest = new Request("GET", "/_ccr/stats"); final Request statsRequest = new Request("GET", "/_ccr/stats");
statsRequest.addParameter("pretty", Boolean.TRUE.toString()); statsRequest.addParameter("pretty", Boolean.TRUE.toString());
@ -792,4 +794,12 @@ public class AutoFollowIT extends ESCCRRestTestCase {
throw ae; throw ae;
} }
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -8,7 +8,9 @@
package org.elasticsearch.xpack.ccr; package org.elasticsearch.xpack.ccr;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
public class ChainIT extends ESCCRRestTestCase { public class ChainIT extends ESCCRRestTestCase {
@ -67,4 +69,12 @@ public class ChainIT extends ESCCRRestTestCase {
} }
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -12,7 +12,9 @@ import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.cluster.metadata.DataStream; import org.elasticsearch.cluster.metadata.DataStream;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.repositories.fs.FsRepository; import org.elasticsearch.repositories.fs.FsRepository;
import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.RestStatus;
@ -232,4 +234,12 @@ public class FollowIndexIT extends ESCCRRestTestCase {
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(400)); assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(400));
} }
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -8,6 +8,9 @@ package org.elasticsearch.xpack.ccr;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.common.xcontent.ObjectPath;
import java.io.IOException; import java.io.IOException;
@ -91,4 +94,12 @@ public class XPackUsageIT extends ESCCRRestTestCase {
assertThat(followStatus, equalTo("active")); assertThat(followStatus, equalTo("active"));
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -12,11 +12,15 @@ dependencies {
testClusters { testClusters {
'leader-cluster' { 'leader-cluster' {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
} }
'follow-cluster' { 'follow-cluster' {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
setting 'cluster.remote.leader_cluster.seeds', setting 'cluster.remote.leader_cluster.seeds',
{ "\"${testClusters.'leader-cluster'.getAllTransportPortURI().join(",")}\"" } { "\"${testClusters.'leader-cluster'.getAllTransportPortURI().join(",")}\"" }
} }

View file

@ -9,6 +9,9 @@ package org.elasticsearch.xpack.ccr;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import java.util.Locale; import java.util.Locale;
@ -44,4 +47,11 @@ public class CcrMultiClusterLicenseIT extends ESCCRRestTestCase {
assertThat(e, hasToString(containsString(expected))); assertThat(e, hasToString(containsString(expected)));
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -12,12 +12,16 @@ testClusters {
'leader-cluster' { 'leader-cluster' {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
} }
'follow-cluster' { 'follow-cluster' {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.monitoring.collection.enabled', 'true' setting 'xpack.monitoring.collection.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
setting 'cluster.remote.leader_cluster.seeds', setting 'cluster.remote.leader_cluster.seeds',
{ "\"${testClusters.'leader-cluster'.getAllTransportPortURI().get(0)}\"" } { "\"${testClusters.'leader-cluster'.getAllTransportPortURI().get(0)}\"" }
nameCustomization = { 'follow' } nameCustomization = { 'follow' }

View file

@ -10,7 +10,9 @@ package org.elasticsearch.xpack.ccr;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import java.io.IOException; import java.io.IOException;
@ -95,4 +97,12 @@ public class RestartIT extends ESCCRRestTestCase {
}); });
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -26,7 +26,6 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;

View file

@ -15,8 +15,6 @@ import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
public class XPackCoreClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { public class XPackCoreClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
private static final String BASIC_AUTH_VALUE = private static final String BASIC_AUTH_VALUE =

View file

@ -20,6 +20,7 @@ testClusters.all {
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
// disable ILM history, since it disturbs tests using _all // disable ILM history, since it disturbs tests using _all
setting 'indices.lifecycle.history_index_enabled', 'false' setting 'indices.lifecycle.history_index_enabled', 'false'
setting 'xpack.security.enabled', 'false'
} }
if (BuildParams.inFipsJvm){ if (BuildParams.inFipsJvm){
// These fail in CI but only when run as part of checkPart2 and not individually. // These fail in CI but only when run as part of checkPart2 and not individually.

View file

@ -4,3 +4,9 @@ tasks.named("test").configure { enabled = false }
dependencies { dependencies {
api project(':test:framework') api project(':test:framework')
} }
testClusters.all {
testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'basic'
setting 'xpack.security.enabled', 'false'
}

View file

@ -6,7 +6,6 @@
*/ */
package org.elasticsearch.xpack.enrich; package org.elasticsearch.xpack.enrich;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.nullValue;

View file

@ -24,4 +24,5 @@ testClusters.all {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'basic' setting 'xpack.license.self_generated.type', 'basic'
setting 'xpack.monitoring.collection.enabled', 'true' setting 'xpack.monitoring.collection.enabled', 'true'
setting 'xpack.security.enabled', 'false'
} }

View file

@ -9,6 +9,9 @@ package org.elasticsearch.test.eql.stats;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.eql.DataLoader; import org.elasticsearch.test.eql.DataLoader;
@ -373,4 +376,12 @@ public abstract class EqlUsageRestTestCase extends ESRestTestCase {
} }
return highLevelClient; return highLevelClient;
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -40,6 +40,8 @@ testClusters {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'basic' setting 'xpack.license.self_generated.type', 'basic'
jvmArgs '-Xms4g', '-Xmx4g' jvmArgs '-Xms4g', '-Xmx4g'
setting 'xpack.security.enabled', 'true'
user username: 'admin', password: 'admin-password', role: 'superuser'
} }
runTask { runTask {
jvmArgs '-Xms8g', '-Xmx8g' jvmArgs '-Xms8g', '-Xmx8g'

View file

@ -20,7 +20,9 @@ import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.eql.EqlSearchRequest; import org.elasticsearch.client.eql.EqlSearchRequest;
import org.elasticsearch.client.eql.EqlSearchResponse; import org.elasticsearch.client.eql.EqlSearchResponse;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.junit.annotations.TestLogging; import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.After; import org.junit.After;
@ -84,6 +86,12 @@ public class EsEQLCorrectnessIT extends ESRestTestCase {
return true; return true;
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
}
@Override @Override
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException { protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts); RestClientBuilder builder = RestClient.builder(hosts);

View file

@ -32,7 +32,7 @@ for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible.findAll { it.on
setting 'xpack.security.enabled', 'false' setting 'xpack.security.enabled', 'false'
setting 'xpack.watcher.enabled', 'false' setting 'xpack.watcher.enabled', 'false'
setting 'xpack.ml.enabled', 'false' setting 'xpack.ml.enabled', 'false'
setting 'xpack.eql.enabled', 'true' setting 'xpack.eql.enabled', 'true'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
// for debugging purposes // for debugging purposes
// setting 'logger.org.elasticsearch.xpack.eql.plugin.TransportEqlSearchAction', 'TRACE' // setting 'logger.org.elasticsearch.xpack.eql.plugin.TransportEqlSearchAction', 'TRACE'

View file

@ -23,4 +23,5 @@ testClusters.all {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'basic' setting 'xpack.license.self_generated.type', 'basic'
setting 'xpack.monitoring.collection.enabled', 'true' setting 'xpack.monitoring.collection.enabled', 'true'
setting 'xpack.security.enabled', 'false'
} }

View file

@ -7,7 +7,18 @@
package org.elasticsearch.xpack.eql; package org.elasticsearch.xpack.eql;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.eql.EqlRestTestCase; import org.elasticsearch.test.eql.EqlRestTestCase;
public class EqlRestIT extends EqlRestTestCase { public class EqlRestIT extends EqlRestTestCase {
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.build();
}
} }

View file

@ -24,4 +24,6 @@ dependencies {
testClusters.all { testClusters.all {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'true'
user username: 'x_pack_rest_user', password: 'x-pack-test-password', role: 'superuser'
} }

View file

@ -62,7 +62,6 @@ import java.util.concurrent.TimeUnit;
import static java.util.Collections.singletonMap; import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;

View file

@ -19,4 +19,6 @@ dependencies {
testClusters.all { testClusters.all {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'true'
user username: 'x_pack_rest_user', password: 'x-pack-test-password', role: 'superuser'
} }

View file

@ -14,4 +14,8 @@ dependencies {
testImplementation(testArtifact(project(xpackModule('core')))) testImplementation(testArtifact(project(xpackModule('core'))))
} }
addQaCheckDependencies() testClusters.all {
setting 'xpack.security.enabled', 'false'
}
addQaCheckDependencies()

View file

@ -48,6 +48,10 @@ if (useFixture) {
testFixtures.useFixture(fixture.path, 'azure-fixture-repositories-metering') testFixtures.useFixture(fixture.path, 'azure-fixture-repositories-metering')
} }
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
tasks.named("integTest") { tasks.named("integTest") {
dependsOn ":plugins:repository-azure:bundlePlugin" dependsOn ":plugins:repository-azure:bundlePlugin"
systemProperty 'test.azure.container', azureContainer systemProperty 'test.azure.container', azureContainer

View file

@ -50,6 +50,10 @@ if (!gcsServiceAccount && !gcsBucket && !gcsBasePath) {
serviceAccountFile = new File(gcsServiceAccount) serviceAccountFile = new File(gcsServiceAccount)
} }
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
/** A service account file that points to the Google Cloud Storage service emulated by the fixture **/ /** A service account file that points to the Google Cloud Storage service emulated by the fixture **/
tasks.register("createServiceAccountFile") { tasks.register("createServiceAccountFile") {
doLast { doLast {

View file

@ -67,6 +67,7 @@ testClusters.matching { it.name == "integTest" }.configureEach {
} else { } else {
println "Using an external service to test " + project.name println "Using an external service to test " + project.name
} }
setting 'xpack.security.enabled', 'false'
} }
tasks.register("s3ThirdPartyTest").configure { tasks.register("s3ThirdPartyTest").configure {

View file

@ -23,6 +23,7 @@ testClusters.all {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'basic' setting 'xpack.license.self_generated.type', 'basic'
systemProperty 'es.rollup_v2_feature_flag_enabled', 'true' systemProperty 'es.rollup_v2_feature_flag_enabled', 'true'
setting 'xpack.security.enabled', 'false'
} }
tasks.named("test").configure{enabled = false } tasks.named("test").configure{enabled = false }

View file

@ -59,6 +59,7 @@ testClusters.matching { it.name == "integTest" }.configureEach {
} }
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'false'
if (useFixture) { if (useFixture) {
def fixtureAddress = { fixtureName -> def fixtureAddress = { fixtureName ->

View file

@ -111,6 +111,8 @@ testClusters.matching { it.name == "integTest" }.configureEach {
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB' setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB' setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
setting 'xpack.security.enabled', 'false'
} }

View file

@ -134,6 +134,8 @@ testClusters.configureEach {
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB' setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB' setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
setting 'xpack.security.enabled', 'false'
} }
testClusters.matching { it.name == "integTestSecure" }.configureEach { testClusters.matching { it.name == "integTestSecure" }.configureEach {

View file

@ -43,5 +43,7 @@ testClusters.matching { it.name == "integTest" }.configureEach {
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB' setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB' setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
setting 'xpack.security.enabled', 'false'
} }

View file

@ -25,4 +25,6 @@ testClusters.all {
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB' setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB' setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
setting 'xpack.security.enabled', 'false'
} }

View file

@ -70,6 +70,8 @@ testClusters.matching { it.name == "integTest" }.configureEach {
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB' setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB' setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
setting 'xpack.security.enabled', 'false'
} }
tasks.register("s3ThirdPartyTest") { tasks.register("s3ThirdPartyTest") {

View file

@ -43,4 +43,6 @@ testClusters.matching { it.name == "integTest" }.configureEach {
setting 'xpack.searchable.snapshot.shared_cache.size', '16MB' setting 'xpack.searchable.snapshot.shared_cache.size', '16MB'
setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB' setting 'xpack.searchable.snapshot.shared_cache.region_size', '256KB'
setting 'xpack.security.enabled', 'false'
} }

View file

@ -4,6 +4,9 @@ import org.elasticsearch.gradle.info.BuildParams
apply plugin: 'elasticsearch.java-rest-test' apply plugin: 'elasticsearch.java-rest-test'
//randomise between implicitly and explicitly disabled security
boolean implicitlyDisabledSecurity = (new Random(Long.parseUnsignedLong(BuildParams.testSeed.tokenize(':').get(0), 16))).nextBoolean()
dependencies { dependencies {
javaRestTestImplementation(testArtifact(project(xpackModule('security')))) javaRestTestImplementation(testArtifact(project(xpackModule('security'))))
javaRestTestImplementation(testArtifact(project(xpackModule('core')))) javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
@ -11,7 +14,9 @@ dependencies {
tasks.named("javaRestTest").configure { tasks.named("javaRestTest").configure {
description = "Run tests against a cluster that doesn't have security" description = "Run tests against a cluster that doesn't have security"
systemProperty 'tests.has_security', 'false' if (!implicitlyDisabledSecurity) {
systemProperty 'tests.has_security', 'false'
}
} }
if (BuildParams.inFipsJvm){ if (BuildParams.inFipsJvm){
@ -25,11 +30,14 @@ testClusters {
numberOfNodes = 2 numberOfNodes = 2
setting 'xpack.ml.enabled', 'false' setting 'xpack.ml.enabled', 'false'
setting 'xpack.license.self_generated.type', 'basic' setting 'xpack.license.self_generated.type', 'basic'
setting 'xpack.security.enabled', 'false' if (!implicitlyDisabledSecurity) {
setting 'xpack.security.enabled', 'false'
}
} }
} }
tasks.register("javaRestTestWithSecurity", StandaloneRestIntegTestTask) { tasks.register("javaRestTestWithSecurityEnabled", StandaloneRestIntegTestTask) {
mustRunAfter("javaRestTest")
description = "Run tests against a cluster that has security enabled" description = "Run tests against a cluster that has security enabled"
dependsOn "javaRestTest" dependsOn "javaRestTest"
useCluster testClusters.javaRestTest useCluster testClusters.javaRestTest
@ -64,5 +72,5 @@ tasks.register("javaRestTestWithSecurity", StandaloneRestIntegTestTask) {
nonInputProperties.systemProperty 'tests.rest.cluster', "${-> testClusters.javaRestTest.getAllHttpSocketURI().join(",")}" nonInputProperties.systemProperty 'tests.rest.cluster', "${-> testClusters.javaRestTest.getAllHttpSocketURI().join(",")}"
} }
} }
tasks.named("check").configure { dependsOn("javaRestTestWithSecurity") } tasks.named("check").configure { dependsOn("javaRestTestWithSecurityEnabled") }

View file

@ -6,10 +6,14 @@
*/ */
package org.elasticsearch.xpack.security; package org.elasticsearch.xpack.security;
import org.apache.http.HttpHost;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.elasticsearch.Version;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.ResponseException;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Booleans;
import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
@ -17,14 +21,15 @@ import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath; import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.elasticsearch.xpack.security.authc.InternalRealms; import org.elasticsearch.xpack.security.authc.InternalRealms;
import org.hamcrest.Matchers;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
@ -33,11 +38,13 @@ import static org.hamcrest.Matchers.notNullValue;
public class EnableSecurityOnBasicLicenseIT extends ESRestTestCase { public class EnableSecurityOnBasicLicenseIT extends ESRestTestCase {
private static boolean securityEnabled; private static boolean securityEnabled;
private static boolean securityExplicitlySet;
@BeforeClass @BeforeClass
public static void checkTestMode() { public static void checkTestMode() {
final String hasSecurity = System.getProperty("tests.has_security"); final String hasSecurity = System.getProperty("tests.has_security");
securityEnabled = Booleans.parseBoolean(hasSecurity); securityExplicitlySet = hasSecurity != null;
securityEnabled = hasSecurity == null ? false : Booleans.parseBoolean(hasSecurity);
} }
@Override @Override
@ -58,10 +65,24 @@ public class EnableSecurityOnBasicLicenseIT extends ESRestTestCase {
@Override @Override
protected boolean preserveClusterUponCompletion() { protected boolean preserveClusterUponCompletion() {
// If this is the first run (security not yet enabled), then don't clean up afterwards because we want to test restart with data // If this is one of the first two runs (security not yet enabled), then don't clean up afterwards because we want to test restart
// with data
return securityEnabled == false; return securityEnabled == false;
} }
@Override
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException {
RestClientBuilder builder = RestClient.builder(hosts);
configureClient(builder, settings);
if (System.getProperty("tests.has_security") != null) {
builder.setStrictDeprecationMode(true);
} else {
builder.setStrictDeprecationMode(false);
}
return builder.build();
}
public void testSecuritySetup() throws Exception { public void testSecuritySetup() throws Exception {
logger.info("Security status: {}", securityEnabled); logger.info("Security status: {}", securityEnabled);
logger.info("Cluster:\n{}", getClusterInfo()); logger.info("Cluster:\n{}", getClusterInfo());
@ -74,7 +95,8 @@ public class EnableSecurityOnBasicLicenseIT extends ESRestTestCase {
} }
checkAllowedWrite("index_allowed"); checkAllowedWrite("index_allowed");
// Security runs second, and should see the doc from the first (non-security) run // Security runs third, and should see the docs from the first two (non-security) runs
// Security explicitly disabled runs second and should see the doc from the first (implicitly disabled) run
final int expectedIndexCount = securityEnabled ? 2 : 1; final int expectedIndexCount = securityEnabled ? 2 : 1;
checkIndexCount("index_allowed", expectedIndexCount); checkIndexCount("index_allowed", expectedIndexCount);
@ -84,6 +106,22 @@ public class EnableSecurityOnBasicLicenseIT extends ESRestTestCase {
} else { } else {
checkAllowedWrite(otherIndex); checkAllowedWrite(otherIndex);
} }
checkSecurityDisabledWarning();
}
public void checkSecurityDisabledWarning() throws Exception {
final Request request = new Request("GET", "/_cat/indices");
Response response = client().performRequest(request);
List<String> warningHeaders = response.getWarnings();
if (securityExplicitlySet) {
assertThat (warningHeaders, Matchers.empty());
} else {
assertThat (warningHeaders, Matchers.hasSize(1));
assertThat (warningHeaders.get(0),
containsString("Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be " +
"accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/" + Version.CURRENT.major + "." +
Version.CURRENT.minor + "/security-minimal-setup.html to enable security."));
}
} }
private String getClusterInfo() throws IOException { private String getClusterInfo() throws IOException {

View file

@ -21,4 +21,5 @@ testClusters.all {
// We run with a trial license, but do not enable security. // We run with a trial license, but do not enable security.
// This means the security plugin is loaded and all feature are permitted, but they are not enabled // This means the security plugin is loaded and all feature are permitted, but they are not enabled
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'false'
} }

View file

@ -18,7 +18,6 @@ import org.elasticsearch.test.rest.ESRestTestCase;
import java.io.IOException; import java.io.IOException;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.matchesRegex; import static org.hamcrest.Matchers.matchesRegex;
public class CatIndicesWithSecurityIT extends ESRestTestCase { public class CatIndicesWithSecurityIT extends ESRestTestCase {

View file

@ -24,6 +24,7 @@ testClusters.javaRestTest {
setting 'xpack.ml.enabled', 'false' setting 'xpack.ml.enabled', 'false'
setting 'xpack.license.self_generated.type', 'basic' setting 'xpack.license.self_generated.type', 'basic'
setting 'xpack.security.enabled', 'true'
setting 'xpack.security.http.ssl.enabled', 'true' setting 'xpack.security.http.ssl.enabled', 'true'
setting 'xpack.security.http.ssl.certificate', 'http.crt' setting 'xpack.security.http.ssl.certificate', 'http.crt'
setting 'xpack.security.http.ssl.key', 'http.key' setting 'xpack.security.http.ssl.key', 'http.key'
@ -34,4 +35,5 @@ testClusters.javaRestTest {
setting 'xpack.security.transport.ssl.key', 'transport.key' setting 'xpack.security.transport.ssl.key', 'transport.key'
setting 'xpack.security.transport.ssl.key_passphrase', 'transport-password' setting 'xpack.security.transport.ssl.key_passphrase', 'transport-password'
setting 'xpack.security.transport.ssl.certificate_authorities', 'ca.crt' setting 'xpack.security.transport.ssl.certificate_authorities', 'ca.crt'
user username: 'admin', password: 'admin-password', role: 'superuser'
} }

View file

@ -10,7 +10,9 @@ import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.ResponseException;
import org.elasticsearch.common.io.PathUtils; import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath; import org.elasticsearch.test.rest.yaml.ObjectPath;
import org.junit.AfterClass; import org.junit.AfterClass;
@ -55,7 +57,9 @@ public class TlsWithBasicLicenseIT extends ESRestTestCase {
@Override @Override
protected Settings restClientSettings() { protected Settings restClientSettings() {
String token = basicAuthHeaderValue("admin", new SecureString("admin-password".toCharArray()));
return Settings.builder() return Settings.builder()
.put(ThreadContext.PREFIX + ".Authorization", token)
.put(TRUSTSTORE_PATH, httpTrustStore) .put(TRUSTSTORE_PATH, httpTrustStore)
.put(TRUSTSTORE_PASSWORD, "password") .put(TRUSTSTORE_PASSWORD, "password")
.build(); .build();

View file

@ -11,8 +11,10 @@ import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier; import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.logging.HeaderWarning;
import org.elasticsearch.common.util.Maps; import org.elasticsearch.common.util.Maps;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.common.xcontent.MediaType; import org.elasticsearch.common.xcontent.MediaType;
@ -88,6 +90,11 @@ public class SecurityRestFilter implements RestHandler {
e -> handleException("Secondary authentication", request, channel, e))); e -> handleException("Secondary authentication", request, channel, e)));
}, e -> handleException("Authentication", request, channel, e))); }, e -> handleException("Authentication", request, channel, e)));
} else { } else {
if (request.method() != Method.OPTIONS) {
HeaderWarning.addWarning("Elasticsearch built-in security features are not enabled. Without authentication, your cluster " +
"could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/" + Version.CURRENT.major +
"." + Version.CURRENT.minor + "/security-minimal-setup.html to enable security.");
}
restHandler.handleRequest(request, channel, client); restHandler.handleRequest(request, channel, client);
} }
} }

View file

@ -9,6 +9,7 @@ package org.elasticsearch.xpack.security.support;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.license.LicenseStateListener; import org.elasticsearch.license.LicenseStateListener;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
@ -40,6 +41,11 @@ public class SecurityStatusChangeListener implements LicenseStateListener {
// old state might be null (undefined) so do Object comparison // old state might be null (undefined) so do Object comparison
if (Objects.equals(newState, securityEnabled) == false) { if (Objects.equals(newState, securityEnabled) == false) {
logger.info("Active license is now [{}]; Security is {}", licenseState.getOperationMode(), newState ? "enabled" : "disabled"); logger.info("Active license is now [{}]; Security is {}", licenseState.getOperationMode(), newState ? "enabled" : "disabled");
if (newState == false) {
logger.warn("Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be " +
"accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/" + Version.CURRENT.major + "." +
Version.CURRENT.minor + "/security-minimal-setup.html to enable security.");
}
this.securityEnabled = newState; this.securityEnabled = newState;
} }
} }

View file

@ -9,6 +9,7 @@ package org.elasticsearch.xpack.security.rest;
import com.nimbusds.jose.util.StandardCharset; import com.nimbusds.jose.util.StandardCharset;
import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.SetOnce;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesArray;
@ -143,6 +144,9 @@ public class SecurityRestFilterTests extends ESTestCase {
RestRequest request = mock(RestRequest.class); RestRequest request = mock(RestRequest.class);
when(licenseState.isSecurityEnabled()).thenReturn(false); when(licenseState.isSecurityEnabled()).thenReturn(false);
filter.handleRequest(request, channel, null); filter.handleRequest(request, channel, null);
assertWarnings("Elasticsearch built-in security features are not enabled. Without authentication, your cluster " +
"could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/" + Version.CURRENT.major + "." +
Version.CURRENT.minor + "/security-minimal-setup.html to enable security.");
verify(restHandler).handleRequest(request, channel, null); verify(restHandler).handleRequest(request, channel, null);
verifyZeroInteractions(channel, authcService); verifyZeroInteractions(channel, authcService);
} }

View file

@ -10,6 +10,7 @@ package org.elasticsearch.xpack.security.support;
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.elasticsearch.Version;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.license.License; import org.elasticsearch.license.License;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
@ -63,7 +64,14 @@ public class SecurityStatusChangeListenerTests extends ESTestCase {
Level.INFO, Level.INFO,
"Active license is now [PLATINUM]; Security is enabled" "Active license is now [PLATINUM]; Security is enabled"
)); ));
logAppender.addExpectation(new MockLogAppender.SeenEventExpectation(
"built-in security features are not enabled",
listener.getClass().getName(),
Level.WARN,
"Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible " +
"to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/" + Version.CURRENT.major + "." +
Version.CURRENT.minor + "/security-minimal-setup.html to enable security."
));
when(licenseState.isSecurityEnabled()).thenReturn(false); when(licenseState.isSecurityEnabled()).thenReturn(false);
when(licenseState.getOperationMode()).thenReturn(License.OperationMode.BASIC); when(licenseState.getOperationMode()).thenReturn(License.OperationMode.BASIC);
logAppender.addExpectation(new MockLogAppender.SeenEventExpectation( logAppender.addExpectation(new MockLogAppender.SeenEventExpectation(
@ -87,6 +95,14 @@ public class SecurityStatusChangeListenerTests extends ESTestCase {
Level.INFO, Level.INFO,
"Active license is now [TRIAL]; Security is disabled" "Active license is now [TRIAL]; Security is disabled"
)); ));
logAppender.addExpectation(new MockLogAppender.SeenEventExpectation(
"built-in security features are not enabled",
listener.getClass().getName(),
Level.WARN,
"Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible " +
"to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/" + Version.CURRENT.major + "." +
Version.CURRENT.minor + "/security-minimal-setup.html to enable security."
));
listener.licenseStateChanged(); listener.licenseStateChanged();
when(licenseState.getOperationMode()).thenReturn(License.OperationMode.BASIC); when(licenseState.getOperationMode()).thenReturn(License.OperationMode.BASIC);

View file

@ -17,4 +17,6 @@ testClusters.all {
numberOfNodes = 4 numberOfNodes = 4
systemProperty 'es.shutdown_feature_flag_enabled', 'true' systemProperty 'es.shutdown_feature_flag_enabled', 'true'
setting 'xpack.security.enabled', 'true'
user username: clusterCredentials.username, password: clusterCredentials.password, role: 'superuser'
} }

View file

@ -8,6 +8,9 @@
package org.elasticsearch.xpack.shutdown; package org.elasticsearch.xpack.shutdown;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
import java.io.IOException; import java.io.IOException;
@ -62,4 +65,13 @@ public class NodeShutdownIT extends ESRestTestCase {
List<Map<String, Object>> nodesArray = (List<Map<String, Object>>) statusResponse.get("nodes"); List<Map<String, Object>> nodesArray = (List<Map<String, Object>>) statusResponse.get("nodes");
assertThat(nodesArray, empty()); assertThat(nodesArray, empty());
} }
@Override
protected Settings restClientSettings() {
String token = basicAuthHeaderValue(
System.getProperty("tests.rest.cluster.username"),
new SecureString(System.getProperty("tests.rest.cluster.password").toCharArray())
);
return Settings.builder().put(ThreadContext.PREFIX + ".Authorization", token).build();
}
} }

View file

@ -48,6 +48,10 @@ if (useFixture) {
testFixtures.useFixture(fixture.path, 'azure-fixture-repository-test-kit') testFixtures.useFixture(fixture.path, 'azure-fixture-repository-test-kit')
} }
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
tasks.named("integTest").configure { tasks.named("integTest").configure {
systemProperty 'test.azure.container', azureContainer systemProperty 'test.azure.container', azureContainer
nonInputProperties.systemProperty 'test.azure.base_path', azureBasePath + "_repository_test_kit_tests_" + BuildParams.testSeed nonInputProperties.systemProperty 'test.azure.base_path', azureBasePath + "_repository_test_kit_tests_" + BuildParams.testSeed

View file

@ -107,6 +107,7 @@ testClusters.matching { it.name == "integTest" }.configureEach {
} else { } else {
println "Using an external service to test " + project.name println "Using an external service to test " + project.name
} }
setting 'xpack.security.enabled', 'false'
} }
tasks.register("gcsThirdPartyTest") { tasks.register("gcsThirdPartyTest") {

View file

@ -46,5 +46,7 @@ testClusters.matching { it.name == "integTest" }.configureEach {
keystore 's3.client.repository_test_kit.secret_key', 's3_test_secret_key' keystore 's3.client.repository_test_kit.secret_key', 's3_test_secret_key'
setting 's3.client.repository_test_kit.protocol', 'http' setting 's3.client.repository_test_kit.protocol', 'http'
setting 's3.client.repository_test_kit.endpoint', { "${-> fixtureAddress()}" }, IGNORE_VALUE setting 's3.client.repository_test_kit.endpoint', { "${-> fixtureAddress()}" }, IGNORE_VALUE
setting 'xpack.security.enabled', 'false'
} }

View file

@ -17,6 +17,7 @@ tasks.named("integTest").configure {
testClusters.matching { it.name == "integTest" }.configureEach { testClusters.matching { it.name == "integTest" }.configureEach {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'path.repo', repoDir.absolutePath setting 'path.repo', repoDir.absolutePath
setting 'xpack.security.enabled', 'false'
} }
restResources { restResources {

View file

@ -72,6 +72,7 @@ testClusters.matching { it.name == "integTest" }.configureEach {
} else { } else {
println "Using an external service to test " + project.name println "Using an external service to test " + project.name
} }
setting 'xpack.security.enabled', 'false'
} }
tasks.register("s3ThirdPartyTest") { tasks.register("s3ThirdPartyTest") {

View file

@ -30,4 +30,5 @@ restResources {
testClusters.all { testClusters.all {
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.security.enabled', 'false'
} }

View file

@ -19,8 +19,6 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Properties; import java.util.Properties;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
public class JdbcConnectionIT extends ConnectionTestCase { public class JdbcConnectionIT extends ConnectionTestCase {
static final boolean SSL_ENABLED = Booleans.parseBoolean(System.getProperty("tests.ssl.enabled"), false); static final boolean SSL_ENABLED = Booleans.parseBoolean(System.getProperty("tests.ssl.enabled"), false);

View file

@ -14,6 +14,10 @@ dependencies {
testImplementation project(xpackModule('sql')) testImplementation project(xpackModule('sql'))
} }
testClusters.all {
setting 'xpack.security.enabled', 'false'
}
tasks.named("integTest").configure{ enabled = false} tasks.named("integTest").configure{ enabled = false}
// A bug (https://github.com/elastic/elasticsearch/issues/68439) limits us to perform tests with versions from 7.10.3 onwards // A bug (https://github.com/elastic/elasticsearch/issues/68439) limits us to perform tests with versions from 7.10.3 onwards

View file

@ -18,8 +18,6 @@ import java.net.URISyntaxException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
/** /**
* Integration test for the rest sql action. The one that speaks json directly to a * Integration test for the rest sql action. The one that speaks json directly to a
* user rather than to the JDBC driver or CLI. * user rather than to the JDBC driver or CLI.

View file

@ -41,7 +41,6 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public abstract class TransformRestTestCase extends ESRestTestCase { public abstract class TransformRestTestCase extends ESRestTestCase {

View file

@ -24,7 +24,6 @@ import java.util.concurrent.atomic.AtomicReference;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM; import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;

View file

@ -25,7 +25,6 @@ import java.util.concurrent.atomic.AtomicReference;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM; import static org.elasticsearch.rest.action.search.RestSearchAction.TOTAL_HITS_AS_INT_PARAM;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasEntry; import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;

View file

@ -13,12 +13,9 @@ import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.elasticsearch.xpack.watcher.WatcherYamlSuiteTestCase; import org.elasticsearch.xpack.watcher.WatcherYamlSuiteTestCase;
import org.junit.Before; import org.junit.Before;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
public class SmokeTestWatcherWithSecurityClientYamlTestSuiteIT extends WatcherYamlSuiteTestCase { public class SmokeTestWatcherWithSecurityClientYamlTestSuiteIT extends WatcherYamlSuiteTestCase {
private static final String TEST_ADMIN_USERNAME = "test_admin"; private static final String TEST_ADMIN_USERNAME = "test_admin";

View file

@ -19,8 +19,6 @@ import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import java.util.Objects; import java.util.Objects;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
@TimeoutSuite(millis = 30 * TimeUnits.MINUTE) // as default timeout seems not enough on the jenkins VMs @TimeoutSuite(millis = 30 * TimeUnits.MINUTE) // as default timeout seems not enough on the jenkins VMs
public class CoreWithSecurityClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { public class CoreWithSecurityClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {

View file

@ -15,8 +15,6 @@ import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
public class MultiClusterSearchWithSecurityYamlTestSuiteIT extends ESClientYamlSuiteTestCase { public class MultiClusterSearchWithSecurityYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
private static final String USER = "test_user"; private static final String USER = "test_user";

View file

@ -18,8 +18,6 @@ import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate; import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase; import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
@TimeoutSuite(millis = 5 * TimeUnits.MINUTE) // to account for slow as hell VMs @TimeoutSuite(millis = 5 * TimeUnits.MINUTE) // to account for slow as hell VMs
public class MultiClusterYamlTestSuiteIT extends ESClientYamlSuiteTestCase { public class MultiClusterYamlTestSuiteIT extends ESClientYamlSuiteTestCase {

View file

@ -17,7 +17,6 @@ import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.yaml.ObjectPath; import org.elasticsearch.test.rest.yaml.ObjectPath;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class GlobalCheckpointSyncActionIT extends ESRestTestCase { public class GlobalCheckpointSyncActionIT extends ESRestTestCase {

View file

@ -33,7 +33,6 @@ import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.oneOf; import static org.hamcrest.Matchers.oneOf;

View file

@ -21,8 +21,6 @@ import java.io.FileNotFoundException;
import java.net.URL; import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
public class ReindexWithSecurityClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase { public class ReindexWithSecurityClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
private static final String USER = "test_admin"; private static final String USER = "test_admin";
private static final String PASS = "x-pack-test-password"; private static final String PASS = "x-pack-test-password";

View file

@ -33,7 +33,6 @@ import java.net.URL;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Collections; import java.util.Collections;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;

View file

@ -10,6 +10,7 @@ import org.elasticsearch.Version;
import org.elasticsearch.client.Request; import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response; import org.elasticsearch.client.Response;
import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.rest.ESRestTestCase; import org.elasticsearch.test.rest.ESRestTestCase;
@ -21,12 +22,10 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.elasticsearch.xpack.test.SecuritySettingsSourceField.basicAuthHeaderValue;
public abstract class AbstractUpgradeTestCase extends ESRestTestCase { public abstract class AbstractUpgradeTestCase extends ESRestTestCase {
private static final String BASIC_AUTH_VALUE = private static final String BASIC_AUTH_VALUE =
basicAuthHeaderValue("test_user", SecuritySettingsSourceField.TEST_PASSWORD); basicAuthHeaderValue("test_user", new SecureString(SecuritySettingsSourceField.TEST_PASSWORD));
protected static final Version UPGRADE_FROM_VERSION = protected static final Version UPGRADE_FROM_VERSION =
Version.fromString(System.getProperty("tests.upgrade_from_version")); Version.fromString(System.getProperty("tests.upgrade_from_version"));

View file

@ -29,6 +29,7 @@ subprojects {
testClusters.matching { it.name == "yamlRestTest" }.configureEach { testClusters.matching { it.name == "yamlRestTest" }.configureEach {
testDistribution = 'DEFAULT' testDistribution = 'DEFAULT'
setting 'xpack.license.self_generated.type', 'trial' setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'false'
} }
tasks.named("yamlRestTest").configure { tasks.named("yamlRestTest").configure {

View file

@ -29,8 +29,6 @@ import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
public class PermissionsIT extends ESRestTestCase { public class PermissionsIT extends ESRestTestCase {
private static HighLevelClient highLevelClient; private static HighLevelClient highLevelClient;

Some files were not shown because too many files have changed in this diff Show more