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

AddPolicyAction - Recursion removal #779

Merged
merged 11 commits into from
May 18, 2023

Conversation

petardz
Copy link
Contributor

@petardz petardz commented May 15, 2023

Issue #, if available: #774

Description of changes:

Removed recursion when checking permissions on indices.

Fixed index pattern permission check: injected "injected_user" property into threadContext

CheckList:

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

petardz added 3 commits May 14, 2023 13:49
Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
petardz added 3 commits May 15, 2023 18:16
Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
injector.injectRoles(DEFAULT_INJECT_ROLES)
} else {
injector.injectRoles(user.roles)
injector.injectUser(user.name)
Copy link
Contributor Author

@petardz petardz May 17, 2023

Choose a reason for hiding this comment

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

I had inject user in context for index permissions(patterns) to be verified by Security plugin. This information being tied to a role, I would expect by just injecting roles, that it would be enough.

Without injecting user, index permission check seem to be skipped.

We're checking index permission by restoring roles in threadContext and then calling our dummy Transport Action which ActionRequest extends BroadcastRequest which implements IndicesRequest.Replaceable.

@bowenlan-amzn

Copy link
Member

@cwperks cwperks May 17, 2023

Choose a reason for hiding this comment

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

It should not be necessary to call on inject user directly. The security plugin also does not support injecting user directly into the thread context by default, this is a feature that is turned off and the setting to enable the feature makes it clear that it is an unsupported feature: https://github.com/opensearch-project/security/blob/main/src/main/java/org/opensearch/security/auth/UserInjector.java#L62

I'm puzzled to why its not working with only using injectRoles - I will continue looking at this further, but here's the analysis I have done so far:

By calling on injectUser and passing the username it is populating a threadcontext header as injected_user: <username>

If the plugins.security.unsupported.inject_user.enabled is turned on inside opensearch.yml then it would hit this block in the SecurityFilter, but only if the opendistro_security_user transient header is null (which it shouldn't be after a roles injection) and the feature is enabled.

@petardz What list of roles are you testing with?

Copy link
Contributor Author

@petardz petardz May 17, 2023

Choose a reason for hiding this comment

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

We use 1 role in security tests. This is where we create role and assign role to user: link and implementations of those util functions: link

Copy link
Member

Choose a reason for hiding this comment

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

Could it have been hitting this block in InjectSecurity where it does nothing if the list of roles is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As of today I cannot reproduce this issue anymore... Two days ago I was flipping between "with injectUser" and "without injectUser" and was able to reproduce it every time.. My testing setup was official 2.7 docker image with installed security plugin where I installed ISM through script.

Thanks for looking into this and sorry for false alarm. I'll revert my change regarding threadContext

Copy link
Member

Choose a reason for hiding this comment

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

@petardz Were you testing locally or via a Github action? If there's a github action log available, could you provide a link? I'm glad its working now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cwperks It was locally tested with my own scripts.

Signed-off-by: Petar Dzepina <[email protected]>
@codecov
Copy link

codecov bot commented May 17, 2023

Codecov Report

Merging #779 (f93e7eb) into main (2c84ffb) will decrease coverage by 0.15%.
The diff coverage is 13.33%.

@@             Coverage Diff              @@
##               main     #779      +/-   ##
============================================
- Coverage     75.46%   75.31%   -0.15%     
- Complexity     2591     2595       +4     
============================================
  Files           335      335              
  Lines         15174    15176       +2     
  Branches       2189     2188       -1     
============================================
- Hits          11451    11430      -21     
- Misses         2448     2472      +24     
+ Partials       1275     1274       -1     
Impacted Files Coverage Δ
...exmanagement/opensearchapi/OpenSearchExtensions.kt 76.06% <ø> (ø)
...sport/action/addpolicy/TransportAddPolicyAction.kt 64.63% <13.33%> (+2.42%) ⬆️

... and 11 files with indirect coverage changes

petardz added 2 commits May 17, 2023 20:37
Signed-off-by: Petar Dzepina <[email protected]>
@bowenlan-amzn bowenlan-amzn merged commit 45b1476 into opensearch-project:main May 18, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-779-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 45b14765c2139095da9ce12c835a8bac35fa5fbb
# Push it to GitHub
git push --set-upstream origin backport/backport-779-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-779-to-2.x.

@bowenlan-amzn
Copy link
Member

@petardz pls do a manual backport... not sure what's conflict that keeps failing the auto backport

petardz added a commit to petardz/index-management that referenced this pull request May 18, 2023
* recursion removal from AddPolicy Action

Signed-off-by: Petar Dzepina <[email protected]>

* added test

Signed-off-by: Petar Dzepina <[email protected]>

* debug logging

Signed-off-by: Petar Dzepina <[email protected]>

* removed single node testcase

Signed-off-by: Petar Dzepina <[email protected]>

* added security test; fixed index permission check

Signed-off-by: Petar Dzepina <[email protected]>

* test fix

Signed-off-by: Petar Dzepina <[email protected]>

* addressing comments

Signed-off-by: Petar Dzepina <[email protected]>

* test cleanup

Signed-off-by: Petar Dzepina <[email protected]>

* reverted security inject changes

Signed-off-by: Petar Dzepina <[email protected]>

* fixed weak password error when creating test user

Signed-off-by: Petar Dzepina <[email protected]>

* test tweak

Signed-off-by: Petar Dzepina <[email protected]>

---------

Signed-off-by: Petar Dzepina <[email protected]>
(cherry picked from commit 45b1476)
bowenlan-amzn pushed a commit that referenced this pull request May 22, 2023
* recursion removal from AddPolicy Action

Signed-off-by: Petar Dzepina <[email protected]>

* added test

Signed-off-by: Petar Dzepina <[email protected]>

* debug logging

Signed-off-by: Petar Dzepina <[email protected]>

* removed single node testcase

Signed-off-by: Petar Dzepina <[email protected]>

* added security test; fixed index permission check

Signed-off-by: Petar Dzepina <[email protected]>

* test fix

Signed-off-by: Petar Dzepina <[email protected]>

* addressing comments

Signed-off-by: Petar Dzepina <[email protected]>

* test cleanup

Signed-off-by: Petar Dzepina <[email protected]>

* reverted security inject changes

Signed-off-by: Petar Dzepina <[email protected]>

* fixed weak password error when creating test user

Signed-off-by: Petar Dzepina <[email protected]>

* test tweak

Signed-off-by: Petar Dzepina <[email protected]>

---------

Signed-off-by: Petar Dzepina <[email protected]>
(cherry picked from commit 45b1476)
ronnaksaxena pushed a commit to ronnaksaxena/index-management that referenced this pull request Jul 19, 2023
…rch-project#785)

* recursion removal from AddPolicy Action

Signed-off-by: Petar Dzepina <[email protected]>

* added test

Signed-off-by: Petar Dzepina <[email protected]>

* debug logging

Signed-off-by: Petar Dzepina <[email protected]>

* removed single node testcase

Signed-off-by: Petar Dzepina <[email protected]>

* added security test; fixed index permission check

Signed-off-by: Petar Dzepina <[email protected]>

* test fix

Signed-off-by: Petar Dzepina <[email protected]>

* addressing comments

Signed-off-by: Petar Dzepina <[email protected]>

* test cleanup

Signed-off-by: Petar Dzepina <[email protected]>

* reverted security inject changes

Signed-off-by: Petar Dzepina <[email protected]>

* fixed weak password error when creating test user

Signed-off-by: Petar Dzepina <[email protected]>

* test tweak

Signed-off-by: Petar Dzepina <[email protected]>

---------

Signed-off-by: Petar Dzepina <[email protected]>
(cherry picked from commit 45b1476)
Signed-off-by: Ronnak Saxena <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants