Skip to content

Commit 2f49f05

Browse files
committed
Fix
1 parent be293d6 commit 2f49f05

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/PutRoleRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ public void addIndex(
114114
String[] grantedFields,
115115
String[] deniedFields,
116116
@Nullable BytesReference query,
117-
boolean allowRestrictedIndices
117+
boolean allowRestrictedIndices,
118+
List<String> selectors
118119
) {
119120
this.indicesPrivileges.add(
120121
RoleDescriptor.IndicesPrivileges.builder()
@@ -123,6 +124,7 @@ public void addIndex(
123124
.grantedFields(grantedFields)
124125
.deniedFields(deniedFields)
125126
.query(query)
127+
.selectors(selectors)
126128
.allowRestrictedIndices(allowRestrictedIndices)
127129
.build()
128130
);

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/role/PutRoleRequestBuilder.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
package org.elasticsearch.xpack.core.security.action.role;
88

99
import org.elasticsearch.action.ActionRequestBuilder;
10+
import org.elasticsearch.action.support.IndexComponentSelector;
1011
import org.elasticsearch.client.internal.ElasticsearchClient;
1112
import org.elasticsearch.common.bytes.BytesReference;
1213
import org.elasticsearch.core.Nullable;
1314
import org.elasticsearch.xcontent.XContentType;
1415
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor;
1516

1617
import java.io.IOException;
18+
import java.util.List;
1719
import java.util.Map;
1820

1921
/**
@@ -75,7 +77,28 @@ public PutRoleRequestBuilder addIndices(
7577
@Nullable BytesReference query,
7678
boolean allowRestrictedIndices
7779
) {
78-
request.addIndex(indices, privileges, grantedFields, deniedFields, query, allowRestrictedIndices);
80+
request.addIndex(
81+
indices,
82+
privileges,
83+
grantedFields,
84+
deniedFields,
85+
query,
86+
allowRestrictedIndices,
87+
List.of(IndexComponentSelector.DATA.getKey())
88+
);
89+
return this;
90+
}
91+
92+
public PutRoleRequestBuilder addIndices(
93+
String[] indices,
94+
String[] privileges,
95+
String[] grantedFields,
96+
String[] deniedFields,
97+
@Nullable BytesReference query,
98+
boolean allowRestrictedIndices,
99+
List<String> selectors
100+
) {
101+
request.addIndex(indices, privileges, grantedFields, deniedFields, query, allowRestrictedIndices, selectors);
79102
return this;
80103
}
81104

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/RoleDescriptor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,10 @@ public IndicesPrivileges build() {
16461646
if (indicesPrivileges.privileges == null || indicesPrivileges.privileges.length == 0) {
16471647
throw new IllegalArgumentException("indices privileges must define at least one privilege");
16481648
}
1649+
// TODO
1650+
if (indicesPrivileges.selectors == null || indicesPrivileges.selectors.isEmpty()) {
1651+
indicesPrivileges.selectors = DEFAULT_SELECTORS;
1652+
}
16491653
return indicesPrivileges;
16501654
}
16511655
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/action/role/PutRoleRequestTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package org.elasticsearch.xpack.core.security.action.role;
88

99
import org.elasticsearch.action.ActionRequestValidationException;
10+
import org.elasticsearch.action.support.IndexComponentSelector;
1011
import org.elasticsearch.action.support.WriteRequest;
1112
import org.elasticsearch.test.ESTestCase;
1213
import org.elasticsearch.xpack.core.security.authz.RoleDescriptor.ApplicationResourcePrivileges;
@@ -76,7 +77,8 @@ public void testValidationErrorWithUnknownIndexPrivilegeName() {
7677
null,
7778
null,
7879
null,
79-
randomBoolean()
80+
randomBoolean(),
81+
List.of(IndexComponentSelector.DATA.getKey())
8082
);
8183

8284
// Fail
@@ -180,7 +182,8 @@ public void testValidationSuccessWithCorrectIndexPrivilegeName() {
180182
null,
181183
null,
182184
null,
183-
randomBoolean()
185+
randomBoolean(),
186+
List.of(IndexComponentSelector.DATA.getKey())
184187
);
185188
assertSuccessfulValidation(request);
186189
}

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/privilege/ManageRolesPrivilegesTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.elasticsearch.xpack.core.security.authz.privilege;
99

1010
import org.elasticsearch.action.ActionRequest;
11+
import org.elasticsearch.action.support.IndexComponentSelector;
1112
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1213
import org.elasticsearch.test.AbstractNamedWriteableTestCase;
1314
import org.elasticsearch.xcontent.ToXContent;
@@ -276,7 +277,7 @@ private static void assertAllowedIndexPatterns(
276277
{
277278
final PutRoleRequest putRoleRequest = new PutRoleRequest();
278279
putRoleRequest.name(randomAlphaOfLength(3));
279-
putRoleRequest.addIndex(indexPatterns, privileges, null, null, null, false);
280+
putRoleRequest.addIndex(indexPatterns, privileges, null, null, null, false, List.of(IndexComponentSelector.DATA.getKey()));
280281
assertThat(permissionCheck(permission, "cluster:admin/xpack/security/role/put", putRoleRequest), is(expected));
281282
}
282283
{

0 commit comments

Comments
 (0)