Skip to content

More reliable trigger for security index migration#139028

Merged
tvernum merged 2 commits intoelastic:mainfrom
tvernum:fix/always-trigger-security-migration
Dec 4, 2025
Merged

More reliable trigger for security index migration#139028
tvernum merged 2 commits intoelastic:mainfrom
tvernum:fix/always-trigger-security-migration

Conversation

@tvernum
Copy link
Contributor

@tvernum tvernum commented Dec 4, 2025

We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to the state of the security index on the master node. But a rolling upgrade might not cause a detectable change in index state - for example, in a cluster with dedicated masters nodes, if those nodes were upgraded last, then all index relocation would happen before the masters knew about the new migration (so they couldn't trigger it) and once the masters were upgraded they would detect that nothing had changed so never send a "security index changed" event and never trigger the migration task.

Now, we say that if a security index exists, and it requires migration then it also triggers a change event

We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event
@tvernum tvernum requested review from a team and jfreden December 4, 2025 05:28
@tvernum tvernum added >bug :Security/Security Security issues without another label auto-backport Automatically create backport pull requests when merged test-full-bwc Trigger full BWC version matrix tests v9.3.0 branch:9.2 branch:9.1 branch:8.19 labels Dec 4, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Security Meta label for security team label Dec 4, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@elasticsearchmachine
Copy link
Collaborator

Hi @tvernum, I've created a changelog YAML for you.

Copy link
Contributor

@jfreden jfreden left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for fixing this!

return new ClusterChangedEvent("test-event", clusterState, EMPTY_CLUSTER_STATE);
}

public void testStateChangeListenerIsCalledIfMigrationIsRequired() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to add an assertion in this test that makes sure that the listener isn't called if the migration is running and the state is unchanged, since that protects the listener from being called on every cluster state change until the target migration version has been applied.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair, I can add that in a followup PR (or leave it to you if you want to get one in today).

I don't think we want to hold up the fix waiting for the test (since the code does check for an in-progress migration)

@tvernum tvernum enabled auto-merge (squash) December 4, 2025 09:12
@tvernum tvernum merged commit ac2e0b0 into elastic:main Dec 4, 2025
37 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.1
8.19 Commit could not be cherrypicked due to conflicts
9.2

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 139028

tvernum added a commit to tvernum/elasticsearch that referenced this pull request Dec 4, 2025
We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event
tvernum added a commit to tvernum/elasticsearch that referenced this pull request Dec 4, 2025
We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Dec 4, 2025
We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event
elasticsearchmachine pushed a commit that referenced this pull request Dec 4, 2025
We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event
elasticsearchmachine pushed a commit that referenced this pull request Dec 4, 2025
We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event

Co-authored-by: Tim Vernum <tim@adjective.org>
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Dec 4, 2025
We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event

(cherry picked from commit ac2e0b0)

# Conflicts:
#	x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java
#	x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java
@jfreden
Copy link
Contributor

jfreden commented Dec 4, 2025

💚 All backports created successfully

Status Branch Result
8.19

Questions ?

Please refer to the Backport tool documentation

elasticsearchmachine pushed a commit that referenced this pull request Dec 4, 2025
We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event
jfreden added a commit that referenced this pull request Dec 4, 2025
We always want to trigger an index migration if one is required.

However, we previously would only do that if we detected a change to
the state of the security index on the master node.
But a rolling upgrade might not cause a detectable change in index
state - for example, in a cluster with dedicated masters nodes, if
those nodes were upgraded last, then all index relocation would happen
before the masters knew about the new migration (so they couldn't
trigger it) and once the masters were upgraded they would detect that
nothing had changed so never send a "security index changed" event and
never trigger the migration task.

Now, we say that if a security index exists, and it requires migration
then it also triggers a change event

(cherry picked from commit ac2e0b0)

# Conflicts:
#	x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/SecurityIndexManager.java
#	x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/support/SecurityIndexManagerTests.java

Co-authored-by: Tim Vernum <tim@adjective.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >bug :Security/Security Security issues without another label Team:Security Meta label for security team test-full-bwc Trigger full BWC version matrix tests v8.19.9 v9.1.9 v9.2.3 v9.3.0

3 participants