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

InjectSecurity - inject User object in UserInfo in threadContext #396

Merged
merged 3 commits into from
Apr 13, 2023

Conversation

petardz
Copy link
Contributor

@petardz petardz commented Apr 11, 2023

Description

Added user_info injection of User object in InjectSecurity

Pre-requisite for opensearch-project/alerting#852

Issues Resolved

[List any issues this PR will resolve]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • 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 petardz requested a review from a team April 11, 2023 22:24
@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@deed4bd). Click here to learn what that means.
The diff coverage is 50.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##             main     #396   +/-   ##
=======================================
  Coverage        ?   73.20%           
  Complexity      ?      700           
=======================================
  Files           ?      110           
  Lines           ?     4631           
  Branches        ?      610           
=======================================
  Hits            ?     3390           
  Misses          ?      985           
  Partials        ?      256           
Impacted Files Coverage Δ
...in/java/org/opensearch/commons/InjectSecurity.java 71.92% <50.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Petar <petar.dzepina@gmail.com>
@petardz petardz force-pushed the injectsecurity-userinfo branch from 90f1c8f to 0053ee6 Compare April 13, 2023 18:26
lezzago
lezzago previously approved these changes Apr 13, 2023
if (user == null) {
return;
}
if (threadContext.getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT) != null) {
Copy link
Member

Choose a reason for hiding this comment

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

can we log in the error message the value present in threadContext.getTransient(ConfigConstants.OPENSEARCH_SECURITY_USER_INFO_THREAD_CONTEXT)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the error message may not be that useful.
Can you add in the comment of this method that this should only be used within plugin after stash the context and injecting user permission? I think this is the only use case of this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eirsep @bowenlan-amzn

Added comments, better logging and unit test

Comment on lines +136 to +139
StringJoiner joiner = new StringJoiner("|");
joiner.add(user.getName());
joiner.add(java.lang.String.join(",", user.getBackendRoles()));
joiner.add(java.lang.String.join(",", user.getRoles()));
Copy link
Member

Choose a reason for hiding this comment

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

Is there already a method to reuse for combining these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't find one. ISM has one in SecurityUtils (generateUserString)

Copy link
Member

Choose a reason for hiding this comment

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

This is the source of where this ThreadContext header is populated from the security plugin: https://github.com/opensearch-project/security/blob/main/src/main/java/org/opensearch/security/privileges/PrivilegesEvaluator.java#L197-L209

This is done in the PrivilegesEvaluator which is called from the SecurityFilter which is the first action filter that is applied before a transport request is executed on a node.

mappedRoles in this method is the set of roles that are resolved to as part of the roles resolution process which is calculating via a roles mapping like:

# mapping for role1
role1
{
  "backend_roles" : [ "starfleet", "captains", "defectors" ],
  "hosts" : [ "*.starfleetintranet.com" ],
  "users" : [ "kirk", "spock" ],
  "and_backend_roles": ["enterprise", "voyager"] // User must have all backend roles in this list to be mapped to role1
}

Copy link
Member

Choose a reason for hiding this comment

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

@cwperks thanks for checking on this. If there's any possible regression in the future, please help track it in some issue.

Copy link
Member

Choose a reason for hiding this comment

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

@bowenlan-amzn No regression that I can see. I saw this PR and wanted to get familiar with what it was introducing. I thought I'd leave a fly-by comment for future reference in case anyone wants to know where this threadcontext header originally comes from.

Signed-off-by: Petar <petar.dzepina@gmail.com>
@petardz petardz force-pushed the injectsecurity-userinfo branch from 67e9728 to 98eb7f1 Compare April 13, 2023 19:50
bowenlan-amzn
bowenlan-amzn previously approved these changes Apr 13, 2023
Copy link
Member

@bowenlan-amzn bowenlan-amzn left a comment

Choose a reason for hiding this comment

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

Thanks!

lezzago
lezzago previously approved these changes Apr 13, 2023
@lezzago lezzago self-requested a review April 13, 2023 20:29
@petardz petardz dismissed stale reviews from lezzago and bowenlan-amzn via 41890cf April 13, 2023 20:49
Signed-off-by: Petar <petar.dzepina@gmail.com>
@petardz petardz force-pushed the injectsecurity-userinfo branch from 41890cf to a85eba0 Compare April 13, 2023 20:52
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2023
* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2023
* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2023
* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2023
* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2023
* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2023
* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2023
* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 13, 2023
* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)
lezzago pushed a commit that referenced this pull request Apr 14, 2023
… (#399)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
stevanbz pushed a commit to stevanbz/common-utils that referenced this pull request Apr 17, 2023
…nsearch-project#396) (opensearch-project#399)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
lezzago pushed a commit that referenced this pull request Apr 17, 2023
… (#399) (#406)

* Added user_info injection of User object in InjectSecurity


(cherry picked from commit f7639aa)

Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
@petardz petardz deleted the injectsecurity-userinfo branch April 27, 2023 08:16
AWSHurneyt pushed a commit that referenced this pull request May 31, 2023
… (#403)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
AWSHurneyt pushed a commit that referenced this pull request May 31, 2023
… (#401)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
bowenlan-amzn pushed a commit that referenced this pull request Jul 13, 2023
… (#404)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
bowenlan-amzn pushed a commit that referenced this pull request Jul 13, 2023
… (#402)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
engechas pushed a commit that referenced this pull request Apr 11, 2024
… (#400)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
engechas pushed a commit that referenced this pull request Apr 11, 2024
… (#398)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
engechas pushed a commit that referenced this pull request Apr 11, 2024
… (#397)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
AWSHurneyt pushed a commit to AWSHurneyt/common-utils that referenced this pull request Apr 12, 2024
…nsearch-project#396) (opensearch-project#399)

* Added user_info injection of User object in InjectSecurity

Signed-off-by: Petar <petar.dzepina@gmail.com>
(cherry picked from commit f7639aa)

Co-authored-by: Petar Dzepina <petar.dzepina@gmail.com>
Signed-off-by: AWSHurneyt <hurneyt@amazon.com>
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.

6 participants