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

Check block request only if system index #4430

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -152,6 +152,11 @@ protected final boolean isBlockedProtectedIndexRequest() {
}

protected final boolean isBlockedSystemIndexRequest() {
boolean isSystemIndex = systemIndexMatcher.test(index.getName());
if (!isSystemIndex) {
return false;
}
10000-ki marked this conversation as resolved.
Show resolved Hide resolved

if (systemIndexPermissionEnabled) {
final User user = threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_USER);
if (user == null) {
Expand All @@ -163,7 +168,7 @@ protected final boolean isBlockedSystemIndexRequest() {
final SecurityRoles securityRoles = evaluator.getSecurityRoles(mappedRoles);
return !securityRoles.isPermittedOnSystemIndex(index.getName());
}
return systemIndexMatcher.test(index.getName());
return true;
}

protected final boolean isAdminDnOrPluginRequest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public abstract class AbstractSystemIndicesTests extends SingleClusterTest {
SYSTEM_INDEX_WITH_NO_ASSOCIATED_ROLE_PERMISSIONS,
ACCESSIBLE_ONLY_BY_SUPER_ADMIN
);
static final List<String> NO_SYSTEM_INDICES = List.of(".no_system_index_1", ".no_system_index_2");

static final List<String> INDICES_FOR_CREATE_REQUEST = List.of(".system_index_2");
static final String matchAllQuery = "{\n\"query\": {\"match_all\": {}}}";
Expand Down Expand Up @@ -117,6 +118,14 @@ void createTestIndicesAndDocs() {
.source("{ \"foo\": \"bar\" }", XContentType.JSON)
).actionGet();
}

for (String index : NO_SYSTEM_INDICES) {
tc.index(
new IndexRequest(index).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.id("document1")
.source("{ \"foo\": \"bar\" }", XContentType.JSON)
).actionGet();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,28 @@ public void testSearchAsNormalUserWithoutSystemIndexAccess() {
validateForbiddenResponse(response, "indices:data/read/search", normalUserWithoutSystemIndex);
}

@Test
public void testNormalIndexShouldAlwaysBeSearchable() throws Exception {
RestHelper restHelper = sslRestHelper();

// search system indices
for (String index : NO_SYSTEM_INDICES) {
RestHelper.HttpResponse responseWithoutSystemIndexPermission = restHelper.executeGetRequest(
index + "/_search",
"",
normalUserWithoutSystemIndexHeader
);
validateSearchResponse(responseWithoutSystemIndexPermission, 1);

RestHelper.HttpResponse responseWithSystemIndexPermission = restHelper.executeGetRequest(
index + "/_search",
"",
normalUserHeader
);
validateSearchResponse(responseWithSystemIndexPermission, 1);
}
}

/**
* DELETE document + index
*/
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/system_indices/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ normal_role:
index_permissions:
- index_patterns:
- '.system*'
- '.no_system*'
allowed_actions:
- '*'
- 'system:admin/system_index'
Expand All @@ -31,5 +32,6 @@ normal_role_without_system_index:
index_permissions:
- index_patterns:
- '.system*'
- '.no_system*'
allowed_actions:
- '*'
Loading