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

Add the new 'maintenance' privilege containing 4 actions (#29998) #50643

Merged
merged 10 commits into from
Jan 30, 2020
Merged

Add the new 'maintenance' privilege containing 4 actions (#29998) #50643

merged 10 commits into from
Jan 30, 2020

Conversation

amirhmd
Copy link

@amirhmd amirhmd commented Jan 6, 2020

  • Have you signed the contributor license agreement?
  • Have you followed the contributor guidelines?
  • If submitting code, have you built your formula locally prior to submission with gradle check?
  • If submitting code, is your pull request against master? Unless there is a good reason otherwise, we prefer pull requests against master and will backport as needed.
  • If submitting code, have you checked that your submission is for an OS and architecture that we support?
  • If you are submitting this code for a class then read our policy for that.

@cbuescher cbuescher added the :Security/Authorization Roles, Privileges, DLS/FLS, RBAC/ABAC label Jan 6, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (:Security/Authorization)

@tvernum
Copy link
Contributor

tvernum commented Jan 6, 2020

@amirhmd One of your "fix merge conflict" commits has introduced uninentional changes.

Can you please have a look at the diff, and have a go at cleaning it up. Let us know if you need help - we may need to perform a little bit of git surgery.

@amirhmd
Copy link
Author

amirhmd commented Jan 7, 2020

hi @tvernum
could you please confirm if it sounds good now?

@tvernum
Copy link
Contributor

tvernum commented Jan 7, 2020

Thanks @amirhmd the diff looks good.
However, it still shows a merge conflit in GitHub, so I think there's still some work to do before we get to merging this.

@tvernum
Copy link
Contributor

tvernum commented Jan 7, 2020

@elasticmachine ok to test.

@amirhmd
Copy link
Author

amirhmd commented Jan 7, 2020

hi @albertzaharovits one test is failing as I was explained in the comment.
IndexPrivilegeTests/testUser15/
The other one which is failing XPackRestIT.test {p0=privileges/11_builtin/Test get builtin privileges} is because there is 33 Cluster Priviledge, I didnt increase this one in 11_builtin but at the time of commit it shows a conflict and I forced to change it.
could you please advise on this?

@albertzaharovits
Copy link
Contributor

I left a comment to hint at why the test is failing, I'll take a closer look in the morning.

@@ -201,15 +201,18 @@ Privilege to delete an index.
Privilege to index and update documents. Also grants access to the update
mapping action.

`maintenance`::
Privilege to refresh, flush, synced_flush, force merge
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Privilege to refresh, flush, synced_flush, force merge
Permits refresh, flush, synced flush and force merge operations. No privilege to read or write index data or otherwise manage the index.

Comment on lines 397 to 403
assertAccessIsAllowed("u15",
"GET", "/" + randomIndex() + "/_msearch", "{}\n{ \"query\" : { \"match_all\" : {} } }\n");
assertAccessIsAllowed("u15", "POST", "/" + randomIndex() + "/_mget", "{ \"ids\" : [ \"1\", \"2\" ] } ");
assertAccessIsDenied("u15", "PUT",
"/" + randomIndex() + "/_bulk", "{ \"index\" : { \"_id\" : \"123\" } }\n{ \"foo\" : \"bar\" }\n");
assertAccessIsAllowed("u15",
"GET", "/" + randomIndex() + "/_mtermvectors", "{ \"docs\" : [ { \"_id\": \"1\" }, { \"_id\": \"2\" } ] }");
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this fluff. This is testing the authorization of composite requests but refresh and flush are not part of those composite type of requests.
In addition to assertUserIsAllowed("u15", "maintenance", "a"); I would also check that crud is not allowed, and we should also test that other users in this class don't have the maintenance priv (right now it only checks the positive case).

assertAccessIsDenied(user, "PUT", "/" + index);
assertAccessIsDenied(user, "POST", "/" + index + "/_refresh");
assertAccessIsDenied(user, "POST", "/" + index + "/_flush");
assertAccessIsAllowed(user, "POST", "/" + index + "/_flush/synced");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be assertAccessIsDenied, right?

Copy link
Contributor

@albertzaharovits albertzaharovits left a comment

Choose a reason for hiding this comment

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

I left a few comments. I think this is close and after you address the comments it should be OK.

@albertzaharovits
Copy link
Contributor

albertzaharovits commented Jan 9, 2020

Thank you for your contribution @amirhmd and apologies for the delay.
I'll have another pass after we settle the comments.

@amirhmd
Copy link
Author

amirhmd commented Jan 9, 2020

Hi @albertzaharovits , thanks for checking my code. As soon as I get home I will apply the comment.

Copy link
Contributor

@albertzaharovits albertzaharovits left a comment

Choose a reason for hiding this comment

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

I've left two minor comments, please address, otherwise LGTM.
We'll wait for Tim's review and then merge. Thank you for your effort Amir!

assertUserIsAllowed("u15", "maintenance", "a");
assertUserIsDenied("u15", "crud", "a");

assertUserIsDenied("u11", "maintenance", "a");
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this to the testUser11 function and do it for the b and c indices, i.e.
assertUserIsDenied("u11", "maintenance", "b");, assertUserIsDenied("u11", "maintenance", "c"); .

@@ -204,15 +204,19 @@ Privilege to delete an index.
Privilege to index and update documents. Also grants access to the update
mapping action.

`maintenance`::
Permits refresh, flush, synced flush, force merge operations. No privilege
Copy link
Contributor

Choose a reason for hiding this comment

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

You missed an and. We try to be sharp wrt the docs.

Suggested change
Permits refresh, flush, synced flush, force merge operations. No privilege
Permits refresh, flush, synced flush and force merge index administration operations.

@amirhmd
Copy link
Author

amirhmd commented Jan 10, 2020

Thanks @albertzaharovits for the comment. I will commit in 3 hours.

@amirhmd
Copy link
Author

amirhmd commented Jan 10, 2020

hi @albertzaharovits elasticsearch-ci/2 is failing because as part of #50454 and #50781 Wait For Snapshot is added. I think thats why this test (testWaitForSnapshotSlmExecutedBefore) is failing. could you please advise?

@polyfractal polyfractal added v7.7.0 and removed v7.6.0 labels Jan 15, 2020
@amirhmd
Copy link
Author

amirhmd commented Jan 15, 2020

Hi @albertzaharovits may I know if I should do anything in this regard #50643 (comment)?

@albertzaharovits
Copy link
Contributor

@amirhmd you don't have to worry about those tests. There's no action to take on your part.
@elasticmachine update branch
ping @tvernum

@albertzaharovits
Copy link
Contributor

@elasticmachine update branch

@albertzaharovits
Copy link
Contributor

@elasticmachine update branch

@@ -102,7 +105,8 @@
entry("read_cross_cluster", READ_CROSS_CLUSTER),
entry("manage_follow_index", MANAGE_FOLLOW_INDEX),
entry("manage_leader_index", MANAGE_LEADER_INDEX),
entry("manage_ilm", MANAGE_ILM));
entry("manage_ilm", MANAGE_ILM),
entry("maintenance",MAINTENANCE));
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor:

Suggested change
entry("maintenance",MAINTENANCE));
entry("maintenance", MAINTENANCE));

@@ -419,6 +432,22 @@ private void assertUserExecutes(String user, String action, String index, boolea
}
break;

case "maintenance" :
if (userIsAllowed) {
assertUserIsDenied(user, "crud", index);
Copy link
Contributor

@tvernum tvernum Jan 28, 2020

Choose a reason for hiding this comment

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

I think this this is what we want.
A user being allowed maintenance should not imply anything about whether they are/aren't allowed crud.

Copy link
Author

Choose a reason for hiding this comment

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

@tvernum the first and second statement made me a bit confuse. but it looks like the explanation has precedence. so I will remove them.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, somehow I dropped a word. It should have said:

I don't think this is what we want.

Your fix is correct.

assertAccessIsAllowed(user, "POST", "/" + index + "/_flush/synced");
assertAccessIsAllowed(user, "POST", "/" + index + "/_forcemerge");
} else {
assertUserIsDenied(user, "crud", index);
Copy link
Contributor

Choose a reason for hiding this comment

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

Per above.

@amirhmd amirhmd requested a review from tvernum January 28, 2020 09:59
@albertzaharovits albertzaharovits merged commit 5712246 into elastic:master Jan 30, 2020
@albertzaharovits
Copy link
Contributor

Thank you for your contribution, @amirhmd !

albertzaharovits added a commit that referenced this pull request Jan 30, 2020
This commit creates a new index privilege named `maintenance`.
The privilege grants the following actions: `refresh`, `flush` (also synced-`flush`),
and `force-merge`. Previously the actions were only under the `manage` privilege
which in some situations was too permissive.

Co-authored-by: Amir H Movahed <arhd83@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants