Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6572e47
Fix internal cluster tests
slobodanadamovic Jan 31, 2025
25eacc0
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Jan 31, 2025
ce30661
[CI] Auto commit changes from spotless
Jan 31, 2025
71d4960
Merge branch 'main' of github.com:elastic/elasticsearch into sa-fix-i…
slobodanadamovic Feb 1, 2025
e0703e7
unmute tests
slobodanadamovic Feb 3, 2025
82704bc
Merge branch 'sa-fix-internal-cluster-tests' of github.com:slobodanad…
slobodanadamovic Feb 3, 2025
d288305
Merge branch 'main' of github.com:elastic/elasticsearch into sa-fix-i…
slobodanadamovic Feb 4, 2025
8c629d0
fix merge conflict
slobodanadamovic Feb 4, 2025
042de75
revert draft changes
slobodanadamovic Feb 4, 2025
974703d
revert new line change
slobodanadamovic Feb 4, 2025
2fca9c8
fix security single note tests by cleaning up and creating security i…
slobodanadamovic Feb 4, 2025
112d9d8
increase timeout
slobodanadamovic Feb 4, 2025
3fd7f4c
Merge branch 'main' of github.com:elastic/elasticsearch into sa-fix-i…
slobodanadamovic Feb 7, 2025
43d62b4
revert TestCluster changes
slobodanadamovic Feb 7, 2025
df96e0d
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 7, 2025
b22b781
ensure no initializing shards before wiping the cluster during setup
slobodanadamovic Feb 12, 2025
5401a0d
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 12, 2025
08b6f1c
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 12, 2025
e83611f
revert adding ensureNoInitializingShardsBeforeWipingCluster
slobodanadamovic Feb 12, 2025
a0feb24
avoid assigning anonymous role with app privileges to the root user
slobodanadamovic Feb 12, 2025
92f7469
Merge branch 'sa-fix-internal-cluster-tests' of github.com:slobodanad…
slobodanadamovic Feb 12, 2025
0314186
Merge branch 'main' of github.com:elastic/elasticsearch into sa-fix-i…
slobodanadamovic Feb 14, 2025
d2587b1
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 14, 2025
dd587d1
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 14, 2025
f677c7b
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 15, 2025
7ba289f
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 15, 2025
09588d0
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 16, 2025
294aaf1
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic Feb 16, 2025
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
48 changes: 0 additions & 48 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,41 +213,14 @@ 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.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 @@ -286,29 +259,8 @@ tests:
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
method: test {yaml=reference/snapshot-restore/apis/get-snapshot-api/line_751}
issue: https://github.com/elastic/elasticsearch/issues/121345
- 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: testActivateProfile
issue: https://github.com/elastic/elasticsearch/issues/121151
- class: org.elasticsearch.test.rest.yaml.CcsCommonYamlTestSuiteIT
issue: https://github.com/elastic/elasticsearch/issues/121407
- class: org.elasticsearch.xpack.security.authc.jwt.JwtRealmSingleNodeTests
method: testClientSecretRotation
issue: https://github.com/elastic/elasticsearch/issues/120985
- 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: testSuggestProfilesWithHint
issue: https://github.com/elastic/elasticsearch/issues/121116
- class: org.elasticsearch.xpack.security.profile.ProfileIntegTests
method: testSuggestProfileWithData
issue: https://github.com/elastic/elasticsearch/issues/121258
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
method: test {yaml=reference/cat/health/cat-health-no-timestamp-example}
issue: https://github.com/elastic/elasticsearch/issues/121867
Expand Down
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) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed these as they are somewhat duplicates of existing methods in SecuritySingleNodeTestCase class.

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() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Renamed this one and moved it into SecuritySingleNodeTestCase.

// 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