|
15 | 15 | import org.elasticsearch.common.Nullable;
|
16 | 16 | import org.elasticsearch.common.Strings;
|
17 | 17 | import org.elasticsearch.common.bytes.BytesReference;
|
| 18 | +import org.elasticsearch.common.regex.Regex; |
18 | 19 | import org.elasticsearch.xpack.core.security.authz.accesscontrol.IndicesAccessControl;
|
19 | 20 | import org.elasticsearch.xpack.core.security.authz.privilege.IndexPrivilege;
|
20 | 21 | import org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames;
|
@@ -139,7 +140,7 @@ public ResourcePrivilegesMap checkResourcePrivileges(Set<String> checkForIndexPa
|
139 | 140 | final Map<IndicesPermission.Group, Automaton> predicateCache = new HashMap<>();
|
140 | 141 | for (String forIndexPattern : checkForIndexPatterns) {
|
141 | 142 | Automaton checkIndexAutomaton = Automatons.patterns(forIndexPattern);
|
142 |
| - if (false == allowRestrictedIndices && false == RestrictedIndicesNames.RESTRICTED_NAMES.contains(forIndexPattern)) { |
| 143 | + if (false == allowRestrictedIndices && false == isConcreteRestrictedIndex(forIndexPattern)) { |
143 | 144 | checkIndexAutomaton = Automatons.minusAndMinimize(checkIndexAutomaton, RestrictedIndicesNames.NAMES_AUTOMATON);
|
144 | 145 | }
|
145 | 146 | if (false == Operations.isEmpty(checkIndexAutomaton)) {
|
@@ -268,6 +269,13 @@ public Map<String, IndicesAccessControl.IndexAccessControl> authorize(String act
|
268 | 269 | return unmodifiableMap(indexPermissions);
|
269 | 270 | }
|
270 | 271 |
|
| 272 | + private boolean isConcreteRestrictedIndex(String indexPattern) { |
| 273 | + if (Regex.isSimpleMatchPattern(indexPattern) || Automatons.isLuceneRegex(indexPattern)) { |
| 274 | + return false; |
| 275 | + } |
| 276 | + return RestrictedIndicesNames.isRestricted(indexPattern); |
| 277 | + } |
| 278 | + |
271 | 279 | public static class Group {
|
272 | 280 | private final IndexPrivilege privilege;
|
273 | 281 | private final Predicate<String> actionMatcher;
|
@@ -316,7 +324,7 @@ private boolean check(String action) {
|
316 | 324 | private boolean check(String action, String index) {
|
317 | 325 | assert index != null;
|
318 | 326 | return check(action) && indexNameMatcher.test(index)
|
319 |
| - && (allowRestrictedIndices || (false == RestrictedIndicesNames.RESTRICTED_NAMES.contains(index))); |
| 327 | + && (allowRestrictedIndices || (false == RestrictedIndicesNames.isRestricted(index))); |
320 | 328 | }
|
321 | 329 |
|
322 | 330 | boolean hasQuery() {
|
@@ -351,13 +359,13 @@ private static Predicate<String> buildIndexMatcherPredicateForAction(String acti
|
351 | 359 | final Predicate<String> predicate;
|
352 | 360 | if (restrictedIndices.isEmpty()) {
|
353 | 361 | predicate = indexMatcher(ordinaryIndices)
|
354 |
| - .and(index -> false == RestrictedIndicesNames.RESTRICTED_NAMES.contains(index)); |
| 362 | + .and(index -> false == RestrictedIndicesNames.isRestricted(index)); |
355 | 363 | } else if (ordinaryIndices.isEmpty()) {
|
356 | 364 | predicate = indexMatcher(restrictedIndices);
|
357 | 365 | } else {
|
358 | 366 | predicate = indexMatcher(restrictedIndices)
|
359 | 367 | .or(indexMatcher(ordinaryIndices)
|
360 |
| - .and(index -> false == RestrictedIndicesNames.RESTRICTED_NAMES.contains(index))); |
| 368 | + .and(index -> false == RestrictedIndicesNames.isRestricted(index))); |
361 | 369 | }
|
362 | 370 | return predicate;
|
363 | 371 | }
|
|
0 commit comments