Skip to content
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

Merged

Conversation

albertzaharovits
Copy link
Contributor

The bug that this is fixing was introduced in #31952 and was discussed here #31952 (comment) .

The bug is about aliases authorization. A user might see aliases which he is not authorized to see.
This happens when the user is not authorized to see any alias and the GetAlias request is empty which is a marking that all aliases are requested. No aliases should be returned in the response but, due to this bug, all aliases are woefully returned.

@javanna When this is merged I will investigate removing originalAliases from the GetAlias request.

@albertzaharovits albertzaharovits added >bug v7.0.0 :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC labels Oct 15, 2018
@albertzaharovits albertzaharovits self-assigned this Oct 15, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security

// _all
if (aliasesRequest.aliases().length == 0) {
aliasesRequest.replaceAliases(NO_INDICES_OR_ALIASES_ARRAY);
}
Copy link
Contributor Author

@albertzaharovits albertzaharovits Oct 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the essence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasontedor @tvernum I believe this is the root issue!
It should be:

if (indicesRequest instanceof GetAliasesRequest && aliasesRequest.aliases().length == 0) {
    aliasesRequest.replaceAliases(NO_INDICES_OR_ALIASES_ARRAY);
}

For the remove index alias action type the alias parameter is not used and replacing it triggers the bug.

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));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing these previous 3 tests : testResolveAliasesWildcardsIndicesAliasesRequestDeleteActionsNoAuthorizedIndices, testResolveAliasesWildcardsGetAliasesRequestNoAuthorizedIndices, testResolveAliasesExclusionWildcardsGetAliasesRequest
also test for the changes introduced herein, so no additional test is required.

final String[] invalidAliasNames = new String[] { "-alias1", "+alias2", "_alias3", "a#lias", "al:ias", ".", ".." };
setupRequestAlias(new Alias(randomFrom(invalidAliasNames)));
expectThrows(InvalidAliasNameException.class, this::executeTask);
}
Copy link
Contributor Author

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).

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as long as CI is happy, thanks a lot @albertzaharovits for taking care of this!

@@ -194,12 +192,11 @@ ResolvedIndices resolveIndicesAndAliases(IndicesRequest indicesRequest, MetaData
if (indicesRequest instanceof AliasesRequest) {
//special treatment for AliasesRequest since we need to replace wildcards among the specified aliases too.
//AliasesRequest extends IndicesRequest.Replaceable, hence its indices have already been properly replaced.
assert indicesRequest instanceof IndicesRequest.Replaceable;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this new assert needed? after all the following cast will fail if the request is not a Replaceable...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@javanna I am being extra careful for when AliasesRequest might not extend IndicesRequest.Replaceable . They are both interfaces (so the work is minimal) so it might happen, I guess (I haven't tested).
Are you ok with keeping the assertion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but doesn't AliasesRequest extend IndicesRequest.Replaceable ? I think I don't follow. Not a big deal though :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, I was being paranoid with this assert. I'll remove it.

@albertzaharovits
Copy link
Contributor Author

run gradle build tests

@albertzaharovits
Copy link
Contributor Author

test this please

@albertzaharovits
Copy link
Contributor Author

test this please SUCCESS

2 similar comments
@albertzaharovits
Copy link
Contributor Author

test this please SUCCESS

@albertzaharovits
Copy link
Contributor Author

test this please SUCCESS

@albertzaharovits
Copy link
Contributor Author

test this please SUCCESS

@albertzaharovits
Copy link
Contributor Author

albertzaharovits commented Oct 23, 2018

https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request/558/consoleFull
seems unrelated?
FWIW

./gradlew -p x-pack/plugin/ml/qa check

passes locally.

run gradle build tests

@albertzaharovits
Copy link
Contributor Author

albertzaharovits commented Oct 23, 2018

https://elasticsearch-ci.elastic.co/job/elastic+elasticsearch+pull-request/633/console

Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://plugins.gradle.org/m2/com/gradle/build-scan-plugin/1.16/build-scan-plugin-1.16.jar'

run gradle build tests

@albertzaharovits albertzaharovits merged commit 11881e7 into elastic:master Oct 23, 2018
@albertzaharovits albertzaharovits deleted the aliases_empty_authorization branch October 23, 2018 15:50
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Oct 23, 2018
* master: (24 commits)
  ingest: better support for conditionals with simulate?verbose (elastic#34155)
  [Rollup] Job deletion should be invoked on the allocated task (elastic#34574)
  [DOCS] .Security index is never auto created (elastic#34589)
  CCR: Requires soft-deletes on the follower (elastic#34725)
  re-enable bwc tests (elastic#34743)
  Empty GetAliases authorization fix (elastic#34444)
  INGEST: Document Processor Conditional (elastic#33388)
  [CCR] Add total fetch time leader stat (elastic#34577)
  SQL: Support pattern against compatible indices (elastic#34718)
  [CCR] Auto follow pattern APIs adjustments (elastic#34518)
  [Test] Remove dead code from ExceptionSerializationTests (elastic#34713)
  A small typo in migration-assistance doc (elastic#34704)
  ingest: processor stats (elastic#34724)
  SQL: Implement IN(value1, value2, ...) expression. (elastic#34581)
  Tests: Add checks to GeoDistanceQueryBuilderTests (elastic#34273)
  INGEST: Rename Pipeline Processor Param. (elastic#34733)
  Core: Move IndexNameExpressionResolver to java time (elastic#34507)
  [DOCS] Force Merge: clarify execution and storage requirements (elastic#33882)
  TESTING.asciidoc fix examples using forbidden annotation (elastic#34515)
  SQL: Implement `CONVERT`, an alternative to `CAST` (elastic#34660)
  ...
kcm pushed a commit that referenced this pull request Oct 30, 2018
This fixes a bug about aliases authorization.
That is, a user might see aliases which he is not authorized to see.
This manifests when the user is not authorized to see any aliases
and the `GetAlias` request is empty which normally is a marking
that all aliases are requested. In this case, no aliases should be
returned, but due to this bug, all aliases will have been returned.
@jimczi jimczi added v7.0.0-beta1 and removed v7.0.0 labels Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants