Skip to content
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

Fix transport serialization of AsyncSearchUser #54761

Merged
merged 4 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public static User readFrom(StreamInput input) throws IOException {
return XPackUser.INSTANCE;
} else if (XPackSecurityUser.is(username)) {
return XPackSecurityUser.INSTANCE;
} else if (AsyncSearchUser.is(username)) {
return AsyncSearchUser.INSTANCE;
}
throw new IllegalStateException("user [" + username + "] is not an internal user");
}
Expand All @@ -36,6 +38,9 @@ public static void writeTo(User user, StreamOutput output) throws IOException {
} else if (XPackSecurityUser.is(user)) {
output.writeBoolean(true);
output.writeString(XPackSecurityUser.NAME);
} else if (AsyncSearchUser.is(user)) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this a concern for bwc? I think, in a mixed cluster environment, writing and reading this information from different versions would fail. But current failures don't seem to be releavant. I don't know the details about async search work. Is it 8.0 only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a 7.7 feature so nodes in this version will be able to run _async_search and to create the new .async-search index. For the few cases where an older node could be picked, the IllegalStateException thrown by readFrom should be enough to handle failures gracefully ?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is indeed a problem, but I don't see an easy way around it.

With the proposed changes, async search won't work until the master node is also upgraded, even if the coordinating node is. Does this sound reasonable to you @jimczi ? Are there other issues that would prevent the async search feature to work in a mixed cluster (assuming no, but maybe there is :) )?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine IMO. We expect users to upgrade clusters entirely before using new features . Also, Kibana will use _async_search internally so the ES cluster must be fully upgraded before upgrading Kibana.

output.writeBoolean(true);
output.writeString(AsyncSearchUser.NAME);
} else {
User.writeTo(user, output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.elasticsearch.xpack.core.security.authz.privilege.ClusterPrivilegeResolver;
import org.elasticsearch.xpack.core.security.authz.privilege.IndexPrivilege;
import org.elasticsearch.xpack.core.security.user.AnonymousUser;
import org.elasticsearch.xpack.core.security.user.AsyncSearchUser;
import org.elasticsearch.xpack.core.security.user.SystemUser;
import org.elasticsearch.xpack.core.security.user.User;
import org.elasticsearch.xpack.core.security.user.XPackSecurityUser;
Expand Down Expand Up @@ -417,7 +418,7 @@ private TransportRequest maybeUnwrapRequest(Authentication authentication, Trans
}

private boolean isInternalUser(User user) {
return SystemUser.is(user) || XPackUser.is(user) || XPackSecurityUser.is(user);
return SystemUser.is(user) || XPackUser.is(user) || XPackSecurityUser.is(user) || AsyncSearchUser.is(user);
}

private void authorizeRunAs(final RequestInfo requestInfo, final AuthorizationInfo authzInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.security.user.AsyncSearchUser;
import org.elasticsearch.xpack.core.security.user.ElasticUser;
import org.elasticsearch.xpack.core.security.user.InternalUserSerializationHelper;
import org.elasticsearch.xpack.core.security.user.KibanaUser;
Expand Down Expand Up @@ -87,6 +88,16 @@ public void testXPackUserReadAndWrite() throws Exception {
assertThat(readFrom.authenticatedUser(), is(XPackUser.INSTANCE));
}

public void testAsyncSearchUserReadAndWrite() throws Exception {
BytesStreamOutput output = new BytesStreamOutput();

InternalUserSerializationHelper.writeTo(AsyncSearchUser.INSTANCE, output);
User readFrom = InternalUserSerializationHelper.readFrom(output.bytes().streamInput());

assertThat(readFrom, is(sameInstance(AsyncSearchUser.INSTANCE)));
assertThat(readFrom.authenticatedUser(), is(AsyncSearchUser.INSTANCE));
}

public void testFakeInternalUserSerialization() throws Exception {
BytesStreamOutput output = new BytesStreamOutput();
output.writeBoolean(true);
Expand Down