Skip to content

Commit

Permalink
Fix transport serialization of AsyncSearchUser (#54761)
Browse files Browse the repository at this point in the history
This change ensures that the AsyncSearchUser is correctly (de)serialized when
an action executed by this user is sent to a remote node internally (via transport client).
  • Loading branch information
jimczi committed Apr 7, 2020
1 parent 89b70c1 commit 5b17d31
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions x-pack/plugin/async-search/qa/security/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {

testClusters.integTest {
testDistribution = 'DEFAULT'
numberOfNodes = 2
setting 'xpack.license.self_generated.type', 'trial'
setting 'xpack.security.enabled', 'true'
extraConfigFile 'roles.yml', file('roles.yml')
Expand Down
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)) {
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 @@ -58,6 +58,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 @@ -416,7 +417,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

0 comments on commit 5b17d31

Please sign in to comment.