Skip to content

Commit 53ec1a3

Browse files
committed
Concrete index access
1 parent 0be2246 commit 53ec1a3

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

server/src/main/java/org/elasticsearch/cluster/metadata/IndexAbstraction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ default boolean isDataStreamRelated() {
100100
return false;
101101
}
102102

103-
default boolean isConcreteFailureIndexOfDataStream() {
103+
default boolean isFailureIndexOfDataStream() {
104104
return false;
105105
}
106106

@@ -198,7 +198,7 @@ public boolean isSystem() {
198198
}
199199

200200
@Override
201-
public boolean isConcreteFailureIndexOfDataStream() {
201+
public boolean isFailureIndexOfDataStream() {
202202
return getParentDataStream() != null && getParentDataStream().isFailureStoreIndex(getName());
203203
}
204204

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,14 +467,14 @@ public boolean checkIndex(Group group) {
467467
final DataStream ds = indexAbstraction == null ? null : indexAbstraction.getParentDataStream();
468468
if (ds != null) {
469469
if (group.checkIndex(ds.getName())) {
470-
// TODO is this right?
471-
final IndexComponentSelector selectorToCheck = indexAbstraction.isConcreteFailureIndexOfDataStream()
470+
final IndexComponentSelector selectorToCheck = indexAbstraction.isFailureIndexOfDataStream()
472471
? IndexComponentSelector.FAILURES
473472
: selector;
474-
return group.checkSelector(selectorToCheck);
473+
if (group.checkSelector(selectorToCheck)) {
474+
return true;
475+
}
475476
}
476477
}
477-
// TODO assertions around selector here?
478478
return group.checkIndex(name) && group.checkSelector(selector);
479479
}
480480

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/user/InternalUsers.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ public class InternalUsers {
161161
IndicesStatsAction.NAME + "*",
162162
TransportUpdateSettingsAction.TYPE.name(),
163163
DownsampleAction.NAME,
164-
TransportAddIndexBlockAction.TYPE.name(),
165-
"read_failures"
164+
TransportAddIndexBlockAction.TYPE.name()
166165
)
167166
.allowRestrictedIndices(false)
168167
.build(),
@@ -181,8 +180,7 @@ public class InternalUsers {
181180
IndicesStatsAction.NAME + "*",
182181
TransportUpdateSettingsAction.TYPE.name(),
183182
DownsampleAction.NAME,
184-
TransportAddIndexBlockAction.TYPE.name(),
185-
"read_failures"
183+
TransportAddIndexBlockAction.TYPE.name()
186184
)
187185
.allowRestrictedIndices(true)
188186
.build() },
@@ -221,8 +219,7 @@ public class InternalUsers {
221219
TransportBulkAction.NAME,
222220
TransportIndexAction.NAME,
223221
TransportSearchScrollAction.TYPE.name(),
224-
ModifyDataStreamsAction.NAME,
225-
"read_failures"
222+
ModifyDataStreamsAction.NAME
226223
)
227224
.allowRestrictedIndices(false)
228225
.build() },
@@ -246,6 +243,7 @@ public class InternalUsers {
246243
new RoleDescriptor.IndicesPrivileges[] {
247244
RoleDescriptor.IndicesPrivileges.builder()
248245
.indices("*")
246+
// TODO it's a bug this works...
249247
.privileges(LazyRolloverAction.NAME, "read_failures")
250248
.allowRestrictedIndices(true)
251249
.build() },

x-pack/plugin/security/qa/security-trial/src/javaRestTest/java/org/elasticsearch/xpack/security/FailureStoreSecurityRestIT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
public class FailureStoreSecurityRestIT extends SecurityOnTrialLicenseRestTestCase {
3333

3434
private static final String DATA_ACCESS_USER = "data_access_user";
35+
private static final String STAR_READ_ONLY_USER = "star_read_only_user";
3536
private static final String FAILURE_STORE_ACCESS_USER = "failure_store_access_user";
3637
private static final String BOTH_ACCESS_USER = "both_access_user";
3738
private static final String WRITE_ACCESS_USER = "write_access_user";
@@ -40,11 +41,13 @@ public class FailureStoreSecurityRestIT extends SecurityOnTrialLicenseRestTestCa
4041
@SuppressWarnings("unchecked")
4142
public void testFailureStoreAccess() throws IOException {
4243
String dataAccessRole = "data_access";
44+
String starReadOnlyRole = "star_read_only_access";
4345
String failureStoreAccessRole = "failure_store_access";
4446
String bothAccessRole = "both_access";
4547
String writeAccessRole = "write_access";
4648

4749
createUser(DATA_ACCESS_USER, PASSWORD, List.of(dataAccessRole));
50+
createUser(STAR_READ_ONLY_USER, PASSWORD, List.of(starReadOnlyRole));
4851
createUser(FAILURE_STORE_ACCESS_USER, PASSWORD, List.of(failureStoreAccessRole));
4952
createUser(BOTH_ACCESS_USER, PASSWORD, randomBoolean() ? List.of(bothAccessRole) : List.of(dataAccessRole, failureStoreAccessRole));
5053
createUser(WRITE_ACCESS_USER, PASSWORD, List.of(writeAccessRole));
@@ -55,6 +58,12 @@ public void testFailureStoreAccess() throws IOException {
5558
"cluster": ["all"],
5659
"indices": [{"names": ["test*"], "privileges": ["read"]}]
5760
}"""), dataAccessRole);
61+
upsertRole(Strings.format("""
62+
{
63+
"description": "Role with data access",
64+
"cluster": ["all"],
65+
"indices": [{"names": ["*"], "privileges": ["read"]}]
66+
}"""), starReadOnlyRole);
5867
upsertRole(Strings.format("""
5968
{
6069
"description": "Role with failure store access",
@@ -96,6 +105,9 @@ public void testFailureStoreAccess() throws IOException {
96105
String dataIndexName = dataIndexNames.get(0);
97106
String failureIndexName = failureIndexNames.get(0);
98107

108+
// `*` with read access user _can_ read concrete failure index with only read
109+
assertContainsDocIds(performRequest(STAR_READ_ONLY_USER, new Request("GET", "/" + failureIndexName + "/_search")), failedDocId);
110+
99111
// user with access to failures index
100112
assertContainsDocIds(performRequest(FAILURE_STORE_ACCESS_USER, new Request("GET", "/test1::failures/_search")), failedDocId);
101113
assertContainsDocIds(performRequest(FAILURE_STORE_ACCESS_USER, new Request("GET", "/test*::failures/_search")), failedDocId);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ static AuthorizedIndices resolveAuthorizedIndicesFromRole(
920920
// We check the parent data stream first if there is one. For testing requested indices, this is most likely
921921
// more efficient than checking the index name first because we recommend grant privileges over data stream
922922
// instead of backing indices.
923-
if (indexAbstraction.isConcreteFailureIndexOfDataStream()
923+
if (indexAbstraction.isFailureIndexOfDataStream()
924924
&& predicate.test(indexAbstraction.getParentDataStream(), IndexComponentSelector.FAILURES.getKey())) {
925925
return true;
926926
}

0 commit comments

Comments
 (0)