From a18b219f7934decc6607531ebe8dcfcd006fa19b Mon Sep 17 00:00:00 2001 From: Tim Vernum Date: Tue, 27 Nov 2018 15:08:53 +1100 Subject: [PATCH] Allow noop PutUser updates (#35843) When assertions are enabled, a Put User action that have no effect (a noop update) would trigger an assertion failure and shutdown the node. This change accepts "noop" as an update result, and adds more diagnostics to the assertion failure message. --- .../core/security/action/user/PutUserRequest.java | 15 +++++++++++++++ .../security/authc/esnative/NativeUsersStore.java | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserRequest.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserRequest.java index f39c5682516..d09b168e966 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserRequest.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/user/PutUserRequest.java @@ -17,6 +17,7 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import java.io.IOException; +import java.util.Arrays; import java.util.Map; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -180,4 +181,18 @@ public class PutUserRequest extends ActionRequest implements UserRequest, WriteR } out.writeBytesReference(charBytesRef); } + + @Override + public String toString() { + return "PutUserRequest{" + + "username='" + username + '\'' + + ", roles=" + Arrays.toString(roles) + + ", fullName='" + fullName + '\'' + + ", email='" + email + '\'' + + ", metadata=" + metadata + + ", passwordHash=" + (passwordHash == null ? "" : "") + + ", enabled=" + enabled + + ", refreshPolicy=" + refreshPolicy + + '}'; + } } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStore.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStore.java index 1fbb8d1eaa5..f941f560c11 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStore.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/esnative/NativeUsersStore.java @@ -341,7 +341,9 @@ public class NativeUsersStore { new ActionListener() { @Override public void onResponse(UpdateResponse updateResponse) { - assert updateResponse.getResult() == DocWriteResponse.Result.UPDATED; + assert updateResponse.getResult() == DocWriteResponse.Result.UPDATED + || updateResponse.getResult() == DocWriteResponse.Result.NOOP + : "Expected 'UPDATED' or 'NOOP' result [" + updateResponse + "] for request [" + putUserRequest + "]"; clearRealmCache(putUserRequest.username(), listener, false); }