Skip to content

Fix error message when changing the password for a user in the file realm #127621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ankit--sethi
Copy link
Contributor

@ankit--sethi ankit--sethi commented May 1, 2025

This PR addresses #113535 - a confusing error message when the user attempts to update the password for the elastic superuser in a cloud deployment.

At the heart of the issue is the difference in how the elastic superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: file and native. On a self-hosted deployment, the elastic superuser is represented as a document in the .security index (placing it in the native realm), whereas in a cloud deployment elastic is defined in the ES_PATH_CONF/users and ES_PATH_CONF/user_roles files installed on each node in the cluster (placing it in the file realm).

The TransportChangePasswordAction impl is designed to update the password for users in the native realm specifically, and on cloud an attempt to change the password for elastic using the Change Password API fails with the error that the user does not exist. This is misleading since the user exists but is simply coming from the file realm.

The solution here first checks if any of the reserved realm users are being updated in a cluster where the reserved realm has been turned off. This reflects the typical cloud use case that causes #113535.

In addition, if the API detects that the user principal is not a native/reserved user, it attempts to search for the user in all other active realms. Performing this check helps give smarter feedback to the user, i.e., that the user is present in some other realm, instead of a generic "user not found" error that may be confusing to someone who knows the user exists but is not informed about the different realms.

… user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.
@ankit--sethi ankit--sethi added >bug :Security/Security Security issues without another label auto-backport Automatically create backport pull requests when merged v8.19.0 v8.17.7 v8.18.2 v9.0.2 labels May 1, 2025
@elasticsearchmachine elasticsearchmachine added v9.1.0 Team:Security Meta label for security team labels May 1, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @ankit--sethi, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Collaborator

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

@ankit--sethi ankit--sethi requested a review from a team as a code owner May 7, 2025 21:03
@elasticsearchmachine
Copy link
Collaborator

Hi @ankit--sethi, I've updated the changelog YAML for you.

Optional<Realm> realm = realms.stream().filter(t -> FileRealmSettings.TYPE.equalsIgnoreCase(t.type())).findAny();
if (user == null && realm.isPresent()) {
// we should check if this request is mistakenly trying to reset a file realm user
FileRealm fileRealm = (FileRealm) realm.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why only file realms? Couldn't we just do this for all realms?

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 point, maybe we can? I'm gonna take a closer look to see if there are any gotchas to doing that.

ankit--sethi and others added 8 commits June 12, 2025 14:20
…ecurity/action/user/TransportChangePasswordAction.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
…security/authc/esnative/ClientReservedRealm.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
…' into feature/misleading-error-message

# Conflicts:
#	x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java
Copy link
Contributor

@slobodanadamovic slobodanadamovic left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Nice job on this one!

I have one last suggestion to update the PR title and description to reflect better the changes made in this PR.

@ankit--sethi ankit--sethi merged commit 4656a53 into elastic:main Jun 13, 2025
23 checks passed
ankit--sethi added a commit to ankit--sethi/elasticsearch that referenced this pull request Jun 13, 2025
…ealm (elastic#127621)

* This PR addresses elastic#113535 - a confusing error message when the user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.

* Update docs/changelog/127621.yaml

* re-do the ticket in Continuation-passing style. Previous unanswered questions around CI/CD are resolved.

* link issue

* accidental commit, reverting

* Update docs/changelog/127621.yaml

* try to check for membership in all non-native realms

* [CI] Auto commit changes from spotless

* improve checks to fix failing tests

* improve

* improve

* improve logic with GroupedActionListener

* return early

* extra spaces

* revert

* Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/user/TransportChangePasswordAction.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>

* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>

* PR feedback

* fix imports

* fix test

* add test

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
ankit--sethi added a commit to ankit--sethi/elasticsearch that referenced this pull request Jun 13, 2025
…ealm (elastic#127621)

* This PR addresses elastic#113535 - a confusing error message when the user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.

* Update docs/changelog/127621.yaml

* re-do the ticket in Continuation-passing style. Previous unanswered questions around CI/CD are resolved.

* link issue

* accidental commit, reverting

* Update docs/changelog/127621.yaml

* try to check for membership in all non-native realms

* [CI] Auto commit changes from spotless

* improve checks to fix failing tests

* improve

* improve

* improve logic with GroupedActionListener

* return early

* extra spaces

* revert

* Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/user/TransportChangePasswordAction.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>

* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>

* PR feedback

* fix imports

* fix test

* add test

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
ankit--sethi added a commit to ankit--sethi/elasticsearch that referenced this pull request Jun 13, 2025
…ealm (elastic#127621)

* This PR addresses elastic#113535 - a confusing error message when the user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.

* Update docs/changelog/127621.yaml

* re-do the ticket in Continuation-passing style. Previous unanswered questions around CI/CD are resolved.

* link issue

* accidental commit, reverting

* Update docs/changelog/127621.yaml

* try to check for membership in all non-native realms

* [CI] Auto commit changes from spotless

* improve checks to fix failing tests

* improve

* improve

* improve logic with GroupedActionListener

* return early

* extra spaces

* revert

* Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/user/TransportChangePasswordAction.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>

* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>

* PR feedback

* fix imports

* fix test

* add test

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
ankit--sethi added a commit to ankit--sethi/elasticsearch that referenced this pull request Jun 13, 2025
…ealm (elastic#127621)

* This PR addresses elastic#113535 - a confusing error message when the user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.

* Update docs/changelog/127621.yaml

* re-do the ticket in Continuation-passing style. Previous unanswered questions around CI/CD are resolved.

* link issue

* accidental commit, reverting

* Update docs/changelog/127621.yaml

* try to check for membership in all non-native realms

* [CI] Auto commit changes from spotless

* improve checks to fix failing tests

* improve

* improve

* improve logic with GroupedActionListener

* return early

* extra spaces

* revert

* Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/user/TransportChangePasswordAction.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>

* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java

Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>

* PR feedback

* fix imports

* fix test

* add test

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.19
9.0
8.17
8.18

elasticsearchmachine pushed a commit that referenced this pull request Jun 13, 2025
…ealm (#127621) (#129433)

* This PR addresses #113535 - a confusing error message when the user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.

* Update docs/changelog/127621.yaml

* re-do the ticket in Continuation-passing style. Previous unanswered questions around CI/CD are resolved.

* link issue

* accidental commit, reverting

* Update docs/changelog/127621.yaml

* try to check for membership in all non-native realms

* [CI] Auto commit changes from spotless

* improve checks to fix failing tests

* improve

* improve

* improve logic with GroupedActionListener

* return early

* extra spaces

* revert

* Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/user/TransportChangePasswordAction.java



* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java



* PR feedback

* fix imports

* fix test

* add test

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
elasticsearchmachine pushed a commit that referenced this pull request Jun 13, 2025
…ealm (#127621) (#129435)

* This PR addresses #113535 - a confusing error message when the user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.

* Update docs/changelog/127621.yaml

* re-do the ticket in Continuation-passing style. Previous unanswered questions around CI/CD are resolved.

* link issue

* accidental commit, reverting

* Update docs/changelog/127621.yaml

* try to check for membership in all non-native realms

* [CI] Auto commit changes from spotless

* improve checks to fix failing tests

* improve

* improve

* improve logic with GroupedActionListener

* return early

* extra spaces

* revert

* Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/user/TransportChangePasswordAction.java



* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java



* PR feedback

* fix imports

* fix test

* add test

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
elasticsearchmachine pushed a commit that referenced this pull request Jun 13, 2025
…ealm (#127621) (#129434)

* This PR addresses #113535 - a confusing error message when the user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.

* Update docs/changelog/127621.yaml

* re-do the ticket in Continuation-passing style. Previous unanswered questions around CI/CD are resolved.

* link issue

* accidental commit, reverting

* Update docs/changelog/127621.yaml

* try to check for membership in all non-native realms

* [CI] Auto commit changes from spotless

* improve checks to fix failing tests

* improve

* improve

* improve logic with GroupedActionListener

* return early

* extra spaces

* revert

* Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/user/TransportChangePasswordAction.java



* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java



* PR feedback

* fix imports

* fix test

* add test

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
elasticsearchmachine pushed a commit that referenced this pull request Jun 13, 2025
…ealm (#127621) (#129432)

* This PR addresses #113535 - a confusing error message when the user attempts to update the password for the `elastic` superuser in a cloud deployment.

At the heart of the issue is the difference in how the `elastic` superuser is implemented on self-hosted deployments vs. managed cloud deployments. Elasticsearch has two distinct security realms: `file` and `native`. On a self-hosted deployment, the `elastic` superuser is represented as a document in the `.security` index, whereas in a cloud deployment `elastic` is defined in the `ES_PATH_CONF/users` and `ES_PATH_CONF/user_roles` files placed on each node in the cluster.

The TransportChangePasswordAction impl is designed to update the password for users in the `native` realm specifically, and a failure on cloud to change the password for `elastic` using the Change Password API fails with the error that the user does not exist.

The solution here leverages `fileUserPasswdStore.userExists` to do a low cost check on whether the request username belongs to the `file` realm and will exit early with an informative error message if that is the case.

* Update docs/changelog/127621.yaml

* re-do the ticket in Continuation-passing style. Previous unanswered questions around CI/CD are resolved.

* link issue

* accidental commit, reverting

* Update docs/changelog/127621.yaml

* try to check for membership in all non-native realms

* [CI] Auto commit changes from spotless

* improve checks to fix failing tests

* improve

* improve

* improve logic with GroupedActionListener

* return early

* extra spaces

* revert

* Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/action/user/TransportChangePasswordAction.java



* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/esnative/ClientReservedRealm.java



* PR feedback

* fix imports

* fix test

* add test

---------

Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
Co-authored-by: Slobodan Adamović <slobodanadamovic@users.noreply.github.com>
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 v8.17.8 v8.18.3 v8.19.0 v9.0.3 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants