Skip to content

Commit f817bc5

Browse files
[Security] Multi Index Expression alias wildcard exclusion (#34144)
The Security plugin authorizes actions on indices. Authorization happens on a per index/alias basis. Therefore a request with a Multi Index Expression (containing wildcards) has to be first evaluated in the authorization layer, before the request is handled. For authorization purposes, wildcards in expressions will only be expanded to indices/aliases that are visible by the authenticated user. However, this "constrained" evaluation has to be compatible with the expression evaluation that a cluster without the Security plugin would do. Therefore any change in the evaluation logic in any of these sites has to be mirrored in the other site. This commit mirrors the changes in core from #33518 that allowed for Multi Index Expression in the Get Alias API, loosely speaking.
1 parent 577261e commit f817bc5

File tree

2 files changed

+84
-61
lines changed

2 files changed

+84
-61
lines changed

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -275,26 +275,39 @@ private List<String> loadAuthorizedAliases(List<String> authorizedIndices, MetaD
275275
}
276276

277277
private List<String> replaceWildcardsWithAuthorizedAliases(String[] aliases, List<String> authorizedAliases) {
278-
List<String> finalAliases = new ArrayList<>();
278+
final List<String> finalAliases = new ArrayList<>();
279279

280-
//IndicesAliasesRequest doesn't support empty aliases (validation fails) but GetAliasesRequest does (in which case empty means _all)
280+
// IndicesAliasesRequest doesn't support empty aliases (validation fails) but
281+
// GetAliasesRequest does (in which case empty means _all)
281282
if (aliases.length == 0) {
282283
finalAliases.addAll(authorizedAliases);
283284
}
284285

285-
for (String aliasPattern : aliases) {
286-
if (aliasPattern.equals(MetaData.ALL)) {
287-
finalAliases.addAll(authorizedAliases);
288-
} else if (Regex.isSimpleMatchPattern(aliasPattern)) {
289-
for (String authorizedAlias : authorizedAliases) {
290-
if (Regex.simpleMatch(aliasPattern, authorizedAlias)) {
291-
finalAliases.add(authorizedAlias);
286+
for (String aliasExpression : aliases) {
287+
boolean include = true;
288+
if (aliasExpression.charAt(0) == '-') {
289+
include = false;
290+
aliasExpression = aliasExpression.substring(1);
291+
}
292+
if (MetaData.ALL.equals(aliasExpression) || Regex.isSimpleMatchPattern(aliasExpression)) {
293+
final Set<String> resolvedAliases = new HashSet<>();
294+
for (final String authorizedAlias : authorizedAliases) {
295+
if (MetaData.ALL.equals(aliasExpression) || Regex.simpleMatch(aliasExpression, authorizedAlias)) {
296+
resolvedAliases.add(authorizedAlias);
292297
}
293298
}
299+
if (include) {
300+
finalAliases.addAll(resolvedAliases);
301+
} else {
302+
finalAliases.removeAll(resolvedAliases);
303+
}
304+
} else if (include) {
305+
finalAliases.add(aliasExpression);
294306
} else {
295-
finalAliases.add(aliasPattern);
307+
finalAliases.remove(aliasExpression);
296308
}
297309
}
310+
298311
return finalAliases;
299312
}
300313

0 commit comments

Comments
 (0)