Skip to content

Commit 16993b4

Browse files
authored
Allow any plugin system request when plugins.security.system_indices.enabled is set to false (#5579)
Signed-off-by: Craig Perkins <[email protected]> Signed-off-by: Craig Perkins <[email protected]>
1 parent 719c456 commit 16993b4

File tree

4 files changed

+47
-34
lines changed

4 files changed

+47
-34
lines changed

.github/workflows/plugin_install.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,24 @@ jobs:
4242

4343
- name: Run Opensearch with A Single Plugin
4444
uses: derek-ho/start-opensearch@v7
45+
if: ${{ runner.os != 'Windows' }}
4546
with:
4647
opensearch-version: ${{ env.OPENSEARCH_VERSION }}
4748
plugins: "file:$(pwd)/${{ env.PLUGIN_NAME }}.zip"
4849
security-enabled: true
4950
admin-password: ${{ steps.generate-password.outputs.password }}
5051
jdk-version: 21
5152

53+
- name: Run Opensearch with A Single Plugin
54+
uses: derek-ho/start-opensearch@v7
55+
if: ${{ runner.os == 'Windows' }}
56+
with:
57+
opensearch-version: ${{ env.OPENSEARCH_VERSION }}
58+
plugins: "file:///$((Get-Location).Path -replace '\\\\','/')/${{ env.PLUGIN_NAME }}.zip"
59+
security-enabled: true
60+
admin-password: ${{ steps.generate-password.outputs.password }}
61+
jdk-version: 21
62+
5263
- name: Run sanity tests
5364
uses: gradle/gradle-build-action@v3
5465
with:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1515
* [Resource Sharing] Fixes accessible resource ids search by marking created_by.user field as keyword search instead of text ([#5574](https://github.com/opensearch-project/security/pull/5574))
1616
* [Resource Sharing] Reverts @Inject pattern usage for ResourceSharingExtension to client accessor pattern. ([#5576](https://github.com/opensearch-project/security/pull/5576))
1717
* Inject user custom attributes when injecting user and role information to the thread context ([#5560](https://github.com/opensearch-project/security/pull/5560))
18+
* Allow any plugin system request when `plugins.security.system_indices.enabled` is set to `false` ([#5579](https://github.com/opensearch-project/security/pull/5579))
1819

1920
### Refactoring
2021

src/integrationTest/java/org/opensearch/security/systemindex/SystemIndexDisabledTests.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.Map;
1414

1515
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
16-
import org.junit.Before;
1716
import org.junit.ClassRule;
1817
import org.junit.Test;
1918
import org.junit.runner.RunWith;
@@ -57,13 +56,6 @@ public class SystemIndexDisabledTests {
5756
)
5857
.build();
5958

60-
@Before
61-
public void setup() {
62-
try (TestRestClient client = cluster.getRestClient(cluster.getAdminCertificate())) {
63-
client.delete(".system-index1");
64-
}
65-
}
66-
6759
@Test
6860
public void testPluginShouldBeAbleToIndexIntoAnySystemIndexWhenProtectionIsDisabled() {
6961
try (TestRestClient client = cluster.getRestClient(cluster.getAdminCertificate())) {
@@ -79,10 +71,12 @@ public void testPluginShouldBeAbleToIndexIntoAnySystemIndexWhenProtectionIsDisab
7971
response.getBody(),
8072
not(
8173
containsString(
82-
"no permissions for [] and User [name=plugin:org.opensearch.security.systemindex.sampleplugin.SystemIndexPlugin1"
74+
"no permissions for [indices:data/write/bulk[s], indices:data/write/index] and User [name=plugin:org.opensearch.security.systemindex.sampleplugin.SystemIndexPlugin1"
8375
)
8476
)
8577
);
78+
79+
assertThat(response.getBody(), not(containsString("\"errors\":true")));
8680
}
8781
}
8882
}

src/main/java/org/opensearch/security/privileges/SystemIndexAccessEvaluator.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -305,34 +305,41 @@ private void evaluateSystemIndicesAccess(
305305
}
306306

307307
// the following section should only be run for index actions
308-
if (this.isSystemIndexEnabled && user.isPluginUser() && !isClusterPerm(action)) {
309-
Set<String> matchingPluginIndices = SystemIndexRegistry.matchesPluginSystemIndexPattern(
310-
user.getName().replace("plugin:", ""),
311-
requestedResolved.getAllIndices()
312-
);
313-
if (requestedResolved.getAllIndices().equals(matchingPluginIndices)) {
314-
// plugin is authorized to perform any actions on its own registered system indices
315-
presponse.allowed = true;
316-
presponse.markComplete();
317-
return;
318-
} else {
319-
Set<String> matchingSystemIndices = SystemIndexRegistry.matchesSystemIndexPattern(requestedResolved.getAllIndices());
320-
matchingSystemIndices.removeAll(matchingPluginIndices);
321-
// See if request matches other system indices not belong to the plugin
322-
if (!matchingSystemIndices.isEmpty()) {
323-
if (log.isInfoEnabled()) {
324-
log.info(
325-
"Plugin {} can only perform {} on it's own registered System Indices. System indices from request that match plugin's registered system indices: {}",
326-
user.getName(),
327-
action,
328-
matchingPluginIndices
329-
);
330-
}
331-
presponse.allowed = false;
332-
presponse.getMissingPrivileges();
308+
if (user.isPluginUser() && !isClusterPerm(action)) {
309+
if (this.isSystemIndexEnabled) {
310+
Set<String> matchingPluginIndices = SystemIndexRegistry.matchesPluginSystemIndexPattern(
311+
user.getName().replace("plugin:", ""),
312+
requestedResolved.getAllIndices()
313+
);
314+
if (requestedResolved.getAllIndices().equals(matchingPluginIndices)) {
315+
// plugin is authorized to perform any actions on its own registered system indices
316+
presponse.allowed = true;
333317
presponse.markComplete();
334318
return;
319+
} else {
320+
Set<String> matchingSystemIndices = SystemIndexRegistry.matchesSystemIndexPattern(requestedResolved.getAllIndices());
321+
matchingSystemIndices.removeAll(matchingPluginIndices);
322+
// See if request matches other system indices not belong to the plugin
323+
if (!matchingSystemIndices.isEmpty()) {
324+
if (log.isInfoEnabled()) {
325+
log.info(
326+
"Plugin {} can only perform {} on it's own registered System Indices. System indices from request that match plugin's registered system indices: {}",
327+
user.getName(),
328+
action,
329+
matchingPluginIndices
330+
);
331+
}
332+
presponse.allowed = false;
333+
presponse.getMissingPrivileges();
334+
presponse.markComplete();
335+
return;
336+
}
335337
}
338+
} else {
339+
// no system index protection and request originating from plugin, allow
340+
presponse.allowed = true;
341+
presponse.markComplete();
342+
return;
336343
}
337344
}
338345

0 commit comments

Comments
 (0)