-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Empty GetAliases authorization fix #34444
Changes from all commits
e6c615e
c376bfc
6a8c682
f320483
2c28901
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,9 +46,9 @@ | |
|
||
class IndicesAndAliasesResolver { | ||
|
||
//`*,-*` what we replace indices with if we need Elasticsearch to return empty responses without throwing exception | ||
private static final String[] NO_INDICES_ARRAY = new String[] { "*", "-*" }; | ||
static final List<String> NO_INDICES_LIST = Arrays.asList(NO_INDICES_ARRAY); | ||
//`*,-*` what we replace indices and aliases with if we need Elasticsearch to return empty responses without throwing exception | ||
static final String[] NO_INDICES_OR_ALIASES_ARRAY = new String[] { "*", "-*" }; | ||
static final List<String> NO_INDICES_OR_ALIASES_LIST = Arrays.asList(NO_INDICES_OR_ALIASES_ARRAY); | ||
|
||
private final IndexNameExpressionResolver nameExpressionResolver; | ||
private final RemoteClusterResolver remoteClusterResolver; | ||
|
@@ -165,7 +165,7 @@ ResolvedIndices resolveIndicesAndAliases(IndicesRequest indicesRequest, MetaData | |
//this is how we tell es core to return an empty response, we can let the request through being sure | ||
//that the '-*' wildcard expression will be resolved to no indices. We can't let empty indices through | ||
//as that would be resolved to _all by es core. | ||
replaceable.indices(NO_INDICES_ARRAY); | ||
replaceable.indices(NO_INDICES_OR_ALIASES_ARRAY); | ||
indicesReplacedWithNoIndices = true; | ||
resolvedIndicesBuilder.addLocal(NO_INDEX_PLACEHOLDER); | ||
} else { | ||
|
@@ -176,8 +176,6 @@ ResolvedIndices resolveIndicesAndAliases(IndicesRequest indicesRequest, MetaData | |
} | ||
} else { | ||
if (containsWildcards(indicesRequest)) { | ||
//an alias can still contain '*' in its name as of 5.0. Such aliases cannot be referred to when using | ||
//the security plugin, otherwise the following exception gets thrown | ||
throw new IllegalStateException("There are no external requests known to support wildcards that don't support replacing " + | ||
"their indices"); | ||
} | ||
|
@@ -198,8 +196,6 @@ ResolvedIndices resolveIndicesAndAliases(IndicesRequest indicesRequest, MetaData | |
if (aliasesRequest.expandAliasesWildcards()) { | ||
List<String> aliases = replaceWildcardsWithAuthorizedAliases(aliasesRequest.aliases(), | ||
loadAuthorizedAliases(authorizedIndices.get(), metaData)); | ||
//it may be that we replace aliases with an empty array, in case there are no authorized aliases for the action. | ||
//MetaData#findAliases will return nothing when some alias was originally requested, which was replaced with empty. | ||
aliasesRequest.replaceAliases(aliases.toArray(new String[aliases.size()])); | ||
} | ||
if (indicesReplacedWithNoIndices) { | ||
|
@@ -213,6 +209,13 @@ ResolvedIndices resolveIndicesAndAliases(IndicesRequest indicesRequest, MetaData | |
} else { | ||
resolvedIndicesBuilder.addLocal(aliasesRequest.aliases()); | ||
} | ||
// if no aliases are authorized, then fill in an expression that | ||
// MetaData#findAliases evaluates to the empty alias list. You cannot put | ||
// "nothing" (the empty list) explicitly because this is resolved by es core to | ||
// _all | ||
if (aliasesRequest.aliases().length == 0) { | ||
aliasesRequest.replaceAliases(NO_INDICES_OR_ALIASES_ARRAY); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the essence. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jasontedor @tvernum I believe this is the root issue!
For the remove index alias action type the |
||
} | ||
return resolvedIndicesBuilder.build(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -778,11 +778,11 @@ public void testResolveAllAliasesWildcardsIndicesAliasesRequestDeleteActions() { | |
public void testResolveAliasesWildcardsIndicesAliasesRequestDeleteActionsNoAuthorizedIndices() { | ||
IndicesAliasesRequest request = new IndicesAliasesRequest(); | ||
request.addAliasAction(AliasActions.remove().index("foo*").alias("foo*")); | ||
//no authorized aliases match bar*, hence aliases are replaced with empty string for that action | ||
//no authorized aliases match bar*, hence aliases are replaced with no-aliases-expression for that action | ||
request.addAliasAction(AliasActions.remove().index("*bar").alias("bar*")); | ||
resolveIndices(request, buildAuthorizedIndices(user, IndicesAliasesAction.NAME)); | ||
assertThat(request.getAliasActions().get(0).aliases(), arrayContainingInAnyOrder("foofoobar", "foobarfoo")); | ||
assertThat(request.getAliasActions().get(1).aliases().length, equalTo(0)); | ||
assertThat(request.getAliasActions().get(1).aliases(), arrayContaining(IndicesAndAliasesResolver.NO_INDICES_OR_ALIASES_ARRAY)); | ||
} | ||
|
||
public void testResolveWildcardsIndicesAliasesRequestAddAndDeleteActions() { | ||
|
@@ -1084,11 +1084,11 @@ public void testResolveAliasesWildcardsGetAliasesRequest() { | |
|
||
public void testResolveAliasesWildcardsGetAliasesRequestNoAuthorizedIndices() { | ||
GetAliasesRequest request = new GetAliasesRequest(); | ||
//no authorized aliases match bar*, hence aliases are replaced with empty array | ||
//no authorized aliases match bar*, hence aliases are replaced with the no-aliases-expression | ||
request.aliases("bar*"); | ||
request.indices("*bar"); | ||
resolveIndices(request, buildAuthorizedIndices(user, GetAliasesAction.NAME)); | ||
assertThat(request.aliases().length, equalTo(0)); | ||
assertThat(request.aliases(), arrayContaining(IndicesAndAliasesResolver.NO_INDICES_OR_ALIASES_ARRAY)); | ||
} | ||
|
||
public void testResolveAliasesExclusionWildcardsGetAliasesRequest() { | ||
|
@@ -1112,10 +1112,11 @@ public void testResolveAliasesAllGetAliasesRequestNoAuthorizedIndices() { | |
request.aliases("_all"); | ||
} | ||
request.indices("non_existing"); | ||
//current user is not authorized for any index, foo* resolves to no indices, aliases are replaced with empty array | ||
//current user is not authorized for any index, aliases are replaced with the no-aliases-expression | ||
ResolvedIndices resolvedIndices = resolveIndices(request, buildAuthorizedIndices(userNoIndices, GetAliasesAction.NAME)); | ||
assertThat(resolvedIndices.getLocal(), contains("non_existing")); | ||
assertThat(request.aliases().length, equalTo(0)); | ||
assertThat(Arrays.asList(request.indices()), contains("non_existing")); | ||
assertThat(request.aliases(), arrayContaining(IndicesAndAliasesResolver.NO_INDICES_OR_ALIASES_ARRAY)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing these previous 3 tests : |
||
} | ||
|
||
/** | ||
|
@@ -1372,7 +1373,7 @@ private static void assertNoIndices(IndicesRequest.Replaceable request, Resolved | |
final List<String> localIndices = resolvedIndices.getLocal(); | ||
assertEquals(1, localIndices.size()); | ||
assertEquals(IndicesAndAliasesResolverField.NO_INDEX_PLACEHOLDER, localIndices.iterator().next()); | ||
assertEquals(IndicesAndAliasesResolver.NO_INDICES_LIST, Arrays.asList(request.indices())); | ||
assertEquals(IndicesAndAliasesResolver.NO_INDICES_OR_ALIASES_LIST, Arrays.asList(request.indices())); | ||
assertEquals(0, resolvedIndices.getRemote().size()); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is testing that aliases with names with leading '-' cannot indeed be created so that
-*
can be safely used as an exclude wildcard (as it presently is).