Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 1 addition & 46 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,44 +227,17 @@ tests:
- class: org.elasticsearch.action.search.SearchProgressActionListenerIT
method: testSearchProgressWithQuery
issue: https://github.com/elastic/elasticsearch/issues/120994
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testSuggestProfilesWithName
issue: https://github.com/elastic/elasticsearch/issues/121022
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testProfileAPIsWhenIndexNotCreated
issue: https://github.com/elastic/elasticsearch/issues/121096
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testGetProfiles
issue: https://github.com/elastic/elasticsearch/issues/121101
- class: org.elasticsearch.xpack.security.authc.service.ServiceAccountSingleNodeTests
method: testAuthenticateWithServiceFileToken
issue: https://github.com/elastic/elasticsearch/issues/120988
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testUpdateProfileData
issue: https://github.com/elastic/elasticsearch/issues/121108
- class: org.elasticsearch.backwards.MixedClusterClientYamlTestSuiteIT
method: test {p0=nodes.stats/11_indices_metrics/indices mappings exact count test for indices level}
issue: https://github.com/elastic/elasticsearch/issues/120950
- class: org.elasticsearch.xpack.shutdown.AllocationFailuresResetOnShutdownIT
method: testResetAllocationFailuresOnNodeShutdown
issue: https://github.com/elastic/elasticsearch/issues/121129
- class: org.elasticsearch.xpack.security.authc.jwt.JwtRealmSingleNodeTests
method: testActivateProfileForJWT
issue: https://github.com/elastic/elasticsearch/issues/120983
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testProfileIndexAutoCreation
issue: https://github.com/elastic/elasticsearch/issues/120987
- class: org.elasticsearch.xpack.security.FileSettingsRoleMappingsRestartIT
method: testFileSettingsReprocessedOnRestartWithoutVersionChange
issue: https://github.com/elastic/elasticsearch/issues/120964
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testGetUsersWithProfileUidWhenProfileIndexDoesNotExists
issue: https://github.com/elastic/elasticsearch/issues/121179
- class: org.elasticsearch.xpack.ml.integration.PyTorchModelIT
issue: https://github.com/elastic/elasticsearch/issues/121165
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testSetEnabled
issue: https://github.com/elastic/elasticsearch/issues/121183
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
method: test {p0=transform/*}
issue: https://github.com/elastic/elasticsearch/issues/120816
Expand Down Expand Up @@ -293,30 +266,12 @@ tests:
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
method: test {yaml=reference/index-modules/slowlog/line_102}
issue: https://github.com/elastic/elasticsearch/issues/121288
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testSuggestProfilesWithHint
issue: https://github.com/elastic/elasticsearch/issues/121116
- class: org.elasticsearch.env.NodeEnvironmentTests
method: testGetBestDowngradeVersion
issue: https://github.com/elastic/elasticsearch/issues/121316
- class: org.elasticsearch.index.engine.ShuffleForcedMergePolicyTests
method: testDiagnostics
issue: https://github.com/elastic/elasticsearch/issues/121336
- class: org.elasticsearch.xpack.security.authc.jwt.JwtRealmSingleNodeTests
method: testGrantApiKeyForJWT
issue: https://github.com/elastic/elasticsearch/issues/121039
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testGetUsersWithProfileUid
issue: https://github.com/elastic/elasticsearch/issues/121483
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testActivateProfile
issue: https://github.com/elastic/elasticsearch/issues/121151
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testHasPrivileges
issue: https://github.com/elastic/elasticsearch/issues/121346
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testSuggestProfileWithData
issue: https://github.com/elastic/elasticsearch/issues/121258
- class: org.elasticsearch.search.CrossClusterSearchUnavailableClusterIT
method: testSearchSkipUnavailable
issue: https://github.com/elastic/elasticsearch/issues/121497
Expand Down Expand Up @@ -367,4 +322,4 @@ tests:
# issue: "https://github.com/elastic/elasticsearch/..."
# - class: "org.elasticsearch.xpack.esql.**"
# method: "test {union_types.MultiIndexIpStringStatsInline *}"
# issue: "https://github.com/elastic/elasticsearch/..."
# issue: "https://github.com/elastic/elasticsearch/..."
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
package org.elasticsearch.test;

import org.apache.http.HttpHost;
import org.elasticsearch.ResourceAlreadyExistsException;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse;
import org.elasticsearch.action.admin.cluster.node.info.PluginsAndModules;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
Expand All @@ -27,6 +34,7 @@
import org.elasticsearch.license.LicenseSettings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xpack.core.security.authc.support.Hasher;
import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
import org.elasticsearch.xpack.core.security.test.TestRestrictedIndices;
import org.elasticsearch.xpack.security.LocalStateSecurity;
import org.elasticsearch.xpack.security.support.SecurityMigrations;
Expand All @@ -45,9 +53,12 @@
import java.util.stream.Collectors;

import static org.elasticsearch.test.SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue;
import static org.elasticsearch.xpack.security.support.SecurityIndexManager.getMigrationVersionFromIndexMetadata;
import static org.elasticsearch.xpack.security.support.SecuritySystemIndices.SECURITY_MAIN_ALIAS;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;

/**
* A test that starts a single node with security enabled. This test case allows for customization
Expand Down Expand Up @@ -82,6 +93,13 @@ public static void destroyDefaultSettings() {
tearDownRestClient();
}

@Override
public void setUp() throws Exception {
super.setUp();
deleteSecurityIndexIfExists();
createSecurityIndexWithWaitForActiveShards();
}

@Override
public void tearDown() throws Exception {
awaitSecurityMigration();
Expand All @@ -100,7 +118,7 @@ private boolean isMigrationComplete(ClusterState state) {
return getMigrationVersionFromIndexMetadata(indexMetadata) == SecurityMigrations.MIGRATIONS_BY_VERSION.lastKey();
}

private void awaitSecurityMigration() {
protected void awaitSecurityMigration() {
final var latch = new CountDownLatch(1);
ClusterService clusterService = getInstanceFromNode(ClusterService.class);
clusterService.addListener((event) -> {
Expand Down Expand Up @@ -362,4 +380,40 @@ private static RestClient createRestClient(
}
return builder.build();
}

protected void deleteSecurityIndexIfExists() {
// delete the security index, if it exist
GetIndexRequest getIndexRequest = new GetIndexRequest(TEST_REQUEST_TIMEOUT);
getIndexRequest.indices(SECURITY_MAIN_ALIAS);
getIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
GetIndexResponse getIndexResponse = client().admin().indices().getIndex(getIndexRequest).actionGet();
if (getIndexResponse.getIndices().length > 0) {
assertThat(getIndexResponse.getIndices().length, is(1));
assertThat(getIndexResponse.getIndices()[0], is(TestRestrictedIndices.INTERNAL_SECURITY_MAIN_INDEX_7));

// Security migration needs to finish before deleting the index
awaitSecurityMigration();
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(getIndexResponse.getIndices());
assertAcked(client().admin().indices().delete(deleteIndexRequest).actionGet());
}
}

protected void createSecurityIndexWithWaitForActiveShards() {
final Client client = client().filterWithHeader(
Collections.singletonMap(
"Authorization",
UsernamePasswordToken.basicAuthHeaderValue(
SecuritySettingsSource.ES_TEST_ROOT_USER,
SecuritySettingsSourceField.TEST_PASSWORD_SECURE_STRING
)
)
);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(SECURITY_MAIN_ALIAS).waitForActiveShards(ActiveShardCount.ALL)
.masterNodeTimeout(TEST_REQUEST_TIMEOUT);
try {
client.admin().indices().create(createIndexRequest).actionGet();
} catch (ResourceAlreadyExistsException e) {
logger.info("Security index already exists, ignoring.", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@
package org.elasticsearch.xpack.security.authc.esnative;

import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.ResponseException;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.MockSecureSettings;
import org.elasticsearch.common.settings.SecureString;
Expand All @@ -29,14 +22,9 @@
import org.elasticsearch.xpack.core.security.action.user.PutUserRequest;
import org.elasticsearch.xpack.core.security.authc.support.Hasher;
import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
import org.elasticsearch.xpack.core.security.test.TestRestrictedIndices;
import org.junit.BeforeClass;

import java.util.concurrent.CountDownLatch;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.xpack.core.security.action.UpdateIndexMigrationVersionAction.MIGRATION_VERSION_CUSTOM_KEY;
import static org.elasticsearch.xpack.security.support.SecuritySystemIndices.SECURITY_MAIN_ALIAS;
import static org.hamcrest.Matchers.is;

public class ReservedRealmElasticAutoconfigIntegTests extends SecuritySingleNodeTestCase {
Expand Down Expand Up @@ -70,46 +58,10 @@ protected SecureString getBootstrapPassword() {
return null; // no bootstrap password for this test
}

private boolean isMigrationComplete(ClusterState state) {
IndexMetadata indexMetadata = state.metadata().getIndices().get(TestRestrictedIndices.INTERNAL_SECURITY_MAIN_INDEX_7);
return indexMetadata != null && indexMetadata.getCustomData(MIGRATION_VERSION_CUSTOM_KEY) != null;
}

private void awaitSecurityMigrationRanOnce() {
final var latch = new CountDownLatch(1);
ClusterService clusterService = getInstanceFromNode(ClusterService.class);
clusterService.addListener((event) -> {
if (isMigrationComplete(event.state())) {
latch.countDown();
}
});
if (isMigrationComplete(clusterService.state())) {
latch.countDown();
}
safeAwait(latch);
}

private void deleteSecurityIndex() {
// delete the security index, if it exist
GetIndexRequest getIndexRequest = new GetIndexRequest(TEST_REQUEST_TIMEOUT);
getIndexRequest.indices(SECURITY_MAIN_ALIAS);
getIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen());
GetIndexResponse getIndexResponse = client().admin().indices().getIndex(getIndexRequest).actionGet();
if (getIndexResponse.getIndices().length > 0) {
assertThat(getIndexResponse.getIndices().length, is(1));
assertThat(getIndexResponse.getIndices()[0], is(TestRestrictedIndices.INTERNAL_SECURITY_MAIN_INDEX_7));

// Security migration needs to finish before deleting the index
awaitSecurityMigrationRanOnce();
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(getIndexResponse.getIndices());
assertAcked(client().admin().indices().delete(deleteIndexRequest).actionGet());
}
}

public void testAutoconfigFailedPasswordPromotion() throws Exception {
try {
// .security index is created automatically on node startup so delete the security index first
deleteSecurityIndex();
deleteSecurityIndexIfExists();
// prevents the .security index from being created automatically (after elastic user authentication)
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(
TEST_REQUEST_TIMEOUT,
Expand Down Expand Up @@ -176,7 +128,7 @@ public void testAutoconfigSucceedsAfterPromotionFailure() throws Exception {
putUserRequest.roles(Strings.EMPTY_ARRAY);
client().execute(PutUserAction.INSTANCE, putUserRequest).get();
// Security migration needs to finish before making the cluster read only
awaitSecurityMigrationRanOnce();
awaitSecurityMigration();

// but then make the cluster read-only
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,28 @@

public class ProfileIntegTests extends AbstractProfileIntegTestCase {

protected static final String ANONYMOUS_ROLE = "anonymous_role";

@Override
protected String configRoles() {
return super.configRoles()
+ "\n"
+ ANONYMOUS_ROLE
+ ":\n"
+ " cluster:\n"
+ " - 'manage_own_api_key'\n"
+ " - 'manage_token'\n"
+ " - 'manage_service_account'\n"
+ " - 'monitor'\n";
}

@Override
protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {
final Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal, otherSettings));
// This setting tests that the setting is registered
builder.put("xpack.security.authc.domains.my_domain.realms", "file");
// enable anonymous
builder.putList(AnonymousUser.ROLES_SETTING.getKey(), RAC_ROLE);
builder.putList(AnonymousUser.ROLES_SETTING.getKey(), ANONYMOUS_ROLE);
return builder.build();
}

Expand Down