Skip to content

Commit 6d9c733

Browse files
committed
Revert "[Backport 2.x] Use SystemIndexRegistry from core to determine if request contains system indices (opensearch-project#4550)"
This reverts commit ed67676.
1 parent 5edd5f5 commit 6d9c733

File tree

5 files changed

+13
-126
lines changed

5 files changed

+13
-126
lines changed

src/integrationTest/java/org/opensearch/security/SystemIndexTests.java

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/integrationTest/java/org/opensearch/security/http/ExampleSystemIndexPlugin.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public class PrivilegesEvaluator {
136136
private ConfigModel configModel;
137137
private final IndexResolverReplacer irr;
138138
private final SnapshotRestoreEvaluator snapshotRestoreEvaluator;
139-
private final SystemIndexAccessEvaluator systemIndexAccessEvaluator;
139+
private final SecurityIndexAccessEvaluator securityIndexAccessEvaluator;
140140
private final ProtectedIndexAccessEvaluator protectedIndexAccessEvaluator;
141141
private final TermsAggregationEvaluator termsAggregationEvaluator;
142142
private final PitPrivilegesEvaluator pitPrivilegesEvaluator;
@@ -172,7 +172,7 @@ public PrivilegesEvaluator(
172172
this.clusterInfoHolder = clusterInfoHolder;
173173
this.irr = irr;
174174
snapshotRestoreEvaluator = new SnapshotRestoreEvaluator(settings, auditLog);
175-
systemIndexAccessEvaluator = new SystemIndexAccessEvaluator(settings, auditLog, irr);
175+
securityIndexAccessEvaluator = new SecurityIndexAccessEvaluator(settings, auditLog, irr);
176176
protectedIndexAccessEvaluator = new ProtectedIndexAccessEvaluator(settings, auditLog);
177177
termsAggregationEvaluator = new TermsAggregationEvaluator();
178178
pitPrivilegesEvaluator = new PitPrivilegesEvaluator();
@@ -328,7 +328,7 @@ public PrivilegesEvaluatorResponse evaluate(PrivilegesEvaluationContext context)
328328
}
329329

330330
// Security index access
331-
if (systemIndexAccessEvaluator.evaluate(
331+
if (securityIndexAccessEvaluator.evaluate(
332332
request,
333333
task,
334334
action0,

src/main/java/org/opensearch/security/privileges/SystemIndexAccessEvaluator.java renamed to src/main/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluator.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
4242
import org.opensearch.cluster.service.ClusterService;
4343
import org.opensearch.common.settings.Settings;
44-
import org.opensearch.indices.SystemIndexRegistry;
4544
import org.opensearch.security.auditlog.AuditLog;
4645
import org.opensearch.security.resolver.IndexResolverReplacer;
4746
import org.opensearch.security.resolver.IndexResolverReplacer.Resolved;
@@ -57,7 +56,7 @@
5756
* - The term `protected system indices` used here translates to system indices
5857
* which have an added layer of security and cannot be accessed by anyone except Super Admin
5958
*/
60-
public class SystemIndexAccessEvaluator {
59+
public class SecurityIndexAccessEvaluator {
6160

6261
Logger log = LogManager.getLogger(this.getClass());
6362

@@ -73,7 +72,7 @@ public class SystemIndexAccessEvaluator {
7372
private final boolean isSystemIndexEnabled;
7473
private final boolean isSystemIndexPermissionEnabled;
7574

76-
public SystemIndexAccessEvaluator(final Settings settings, AuditLog auditLog, IndexResolverReplacer irr) {
75+
public SecurityIndexAccessEvaluator(final Settings settings, AuditLog auditLog, IndexResolverReplacer irr) {
7776
this.securityIndex = settings.get(
7877
ConfigConstants.SECURITY_CONFIG_INDEX_NAME,
7978
ConfigConstants.OPENDISTRO_SECURITY_DEFAULT_CONFIG_INDEX
@@ -84,7 +83,6 @@ public SystemIndexAccessEvaluator(final Settings settings, AuditLog auditLog, In
8483
this.systemIndexMatcher = WildcardMatcher.from(
8584
settings.getAsList(ConfigConstants.SECURITY_SYSTEM_INDICES_KEY, ConfigConstants.SECURITY_SYSTEM_INDICES_DEFAULT)
8685
);
87-
8886
this.superAdminAccessOnlyIndexMatcher = WildcardMatcher.from(this.securityIndex);
8987
this.isSystemIndexEnabled = settings.getAsBoolean(
9088
ConfigConstants.SECURITY_SYSTEM_INDICES_ENABLED_KEY,
@@ -170,16 +168,15 @@ private boolean requestContainsAnySystemIndices(final Resolved requestedResolved
170168
* It will always return security index if it is present in the request, as security index is protected regardless
171169
* of feature being enabled or disabled
172170
* @param requestedResolved request which contains indices to be matched against system indices
173-
* @return the set of protected system indices present in the request
171+
* @return the list of protected system indices present in the request
174172
*/
175-
private Set<String> getAllSystemIndices(final Resolved requestedResolved) {
176-
final Set<String> systemIndices = requestedResolved.getAllIndices()
173+
private List<String> getAllSystemIndices(final Resolved requestedResolved) {
174+
final List<String> systemIndices = requestedResolved.getAllIndices()
177175
.stream()
178176
.filter(securityIndex::equals)
179-
.collect(Collectors.toSet());
177+
.collect(Collectors.toList());
180178
if (isSystemIndexEnabled) {
181179
systemIndices.addAll(systemIndexMatcher.getMatchAny(requestedResolved.getAllIndices(), Collectors.toList()));
182-
systemIndices.addAll(SystemIndexRegistry.matchesSystemIndexPattern(requestedResolved.getAllIndices().toArray(String[]::new)));
183180
}
184181
return systemIndices;
185182
}
@@ -213,7 +210,7 @@ private List<String> getAllProtectedSystemIndices(final Resolved requestedResolv
213210
private boolean requestContainsAnyRegularIndices(final Resolved requestedResolved) {
214211
Set<String> allIndices = requestedResolved.getAllIndices();
215212

216-
Set<String> allSystemIndices = getAllSystemIndices(requestedResolved);
213+
List<String> allSystemIndices = getAllSystemIndices(requestedResolved);
217214
List<String> allProtectedSystemIndices = getAllProtectedSystemIndices(requestedResolved);
218215

219216
return allIndices.stream().anyMatch(index -> !allSystemIndices.contains(index) && !allProtectedSystemIndices.contains(index));

src/test/java/org/opensearch/security/privileges/SystemIndexAccessEvaluatorTest.java renamed to src/test/java/org/opensearch/security/privileges/SecurityIndexAccessEvaluatorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
import static org.mockito.Mockito.when;
5757

5858
@RunWith(MockitoJUnitRunner.class)
59-
public class SystemIndexAccessEvaluatorTest {
59+
public class SecurityIndexAccessEvaluatorTest {
6060

6161
@Mock
6262
private AuditLog auditLog;
@@ -73,7 +73,7 @@ public class SystemIndexAccessEvaluatorTest {
7373
@Mock
7474
ClusterService cs;
7575

76-
private SystemIndexAccessEvaluator evaluator;
76+
private SecurityIndexAccessEvaluator evaluator;
7777
private static final String UNPROTECTED_ACTION = "indices:data/read";
7878
private static final String PROTECTED_ACTION = "indices:data/write";
7979

@@ -137,7 +137,7 @@ public void setup(
137137

138138
// when trying to resolve Index Names
139139

140-
evaluator = new SystemIndexAccessEvaluator(
140+
evaluator = new SecurityIndexAccessEvaluator(
141141
Settings.builder()
142142
.put(ConfigConstants.SECURITY_SYSTEM_INDICES_KEY, TEST_SYSTEM_INDEX)
143143
.put(ConfigConstants.SECURITY_SYSTEM_INDICES_ENABLED_KEY, isSystemIndexEnabled)

0 commit comments

Comments
 (0)