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 ThreadContextPermission for markAsSystemContext and allow core to perform the method #15016

Merged
merged 10 commits into from
Jul 31, 2024

Conversation

cwperks
Copy link
Member

@cwperks cwperks commented Jul 30, 2024

Description

This PR replaces a previous PR and takes a different approach to protect methods in the ThreadContext class. Instead of changing the access modifier, this PR shows how permissions can be declared to protect methods within the ThreadContext class that should not be accessible outside of the core without explicit permission.

With this change, plugins would be able to utilize the method but permission needs to be granted through an entry in the plugin-security.policy file. The permissions would be:

permission java.lang.RuntimePermission "markAsSystemContext";

Related Issues

Resolves #14931

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

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.

…rm the method

Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
@github-actions github-actions bot added enhancement Enhancement or improvement to existing feature or request Identity PR/Issues associated with Authentication or Authorization Plugins security Anything security related labels Jul 30, 2024
@cwperks
Copy link
Member Author

cwperks commented Jul 30, 2024

for 2.x we could consider replacing the permission check with deprecation warning.

@reta How can the deprecation warning differentiate who the caller is though? The usage of the method is not deprecated in this repo so I would not want the message to display every time the method is called, only if its called from a class outside of the core.

Signed-off-by: Craig Perkins <cwperx@amazon.com>
@reta
Copy link
Collaborator

reta commented Jul 30, 2024

@reta How can the deprecation warning differentiate who the caller is though?

@cwperks Something along these lines:

 SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            try {
                sm.checkPermission(ACCESS_SYSTEM_THREAD_CONTEXT_PERMISSION);
            } catch (SecurityException ex) {
                deprecationLogger.warn( .,... )
            }
        }

@cwperks
Copy link
Member Author

cwperks commented Jul 30, 2024

That's smart. Thanks @reta!

@cwperks
Copy link
Member Author

cwperks commented Jul 30, 2024

Should I open up a manual backport with the change from here or wait for backport bot to create a backport and push a commit to the branch?

Copy link
Contributor

✅ Gradle check result for 1ff09c2: SUCCESS

@reta
Copy link
Collaborator

reta commented Jul 30, 2024

Should I open up a manual backport with the change from here or wait for backport bot to create a backport and push a commit to the branch?

I will add backport label (so the changelog check passes), but we could take it from there

@reta reta added v2.17.0 backport 2.x Backport to 2.x branch labels Jul 30, 2024
@reta reta merged commit 597747d into opensearch-project:main Jul 31, 2024
37 of 43 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jul 31, 2024
… perform the method (#15016)

* Add RuntimePermission for markAsSystemContext and allow core to perform the method

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* private

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Surround with doPrivileged

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create ThreadContextAccess

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create notion of ThreadContextPermission

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add javadoc

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to test-framework.policy file

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Mark as internal

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
(cherry picked from commit 597747d)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
cwperks added a commit to cwperks/OpenSearch that referenced this pull request Jul 31, 2024
… perform the method (opensearch-project#15016)

* Add RuntimePermission for markAsSystemContext and allow core to perform the method

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* private

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Surround with doPrivileged

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create ThreadContextAccess

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create notion of ThreadContextPermission

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add javadoc

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to test-framework.policy file

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Mark as internal

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
reta pushed a commit that referenced this pull request Jul 31, 2024
…d allow core to perform the method (#15038)

* Add ThreadContextPermission for markAsSystemContext and allow core to perform the method (#15016)

* Add RuntimePermission for markAsSystemContext and allow core to perform the method

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* private

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Surround with doPrivileged

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create ThreadContextAccess

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create notion of ThreadContextPermission

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add javadoc

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to test-framework.policy file

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Mark as internal

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add deprecationLogger

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
harshavamsi pushed a commit to harshavamsi/OpenSearch that referenced this pull request Aug 20, 2024
… perform the method (opensearch-project#15016)

* Add RuntimePermission for markAsSystemContext and allow core to perform the method

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* private

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Surround with doPrivileged

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create ThreadContextAccess

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create notion of ThreadContextPermission

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add javadoc

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to test-framework.policy file

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Mark as internal

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
wdongyu pushed a commit to wdongyu/OpenSearch that referenced this pull request Aug 22, 2024
… perform the method (opensearch-project#15016)

* Add RuntimePermission for markAsSystemContext and allow core to perform the method

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* private

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Surround with doPrivileged

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create ThreadContextAccess

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Create notion of ThreadContextPermission

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to CHANGELOG

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add javadoc

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Add to test-framework.policy file

Signed-off-by: Craig Perkins <cwperx@amazon.com>

* Mark as internal

Signed-off-by: Craig Perkins <cwperx@amazon.com>

---------

Signed-off-by: Craig Perkins <cwperx@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch enhancement Enhancement or improvement to existing feature or request Identity PR/Issues associated with Authentication or Authorization Plugins security Anything security related v2.17.0 v3.0.0 Issues and PRs related to version 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Create Higher-Level APIs for Plugins to switch contexts
2 participants