-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Backport 2.x] Add ThreadContextPermission for markAsSystemContext and allow core to perform the method #15035
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.secure_sm; | ||
|
||
import java.security.BasicPermission; | ||
|
||
/** | ||
* Permission to utilize methods in the ThreadContext class that are normally not accessible | ||
* | ||
* @see ThreadGroup | ||
* @see SecureSM | ||
*/ | ||
public final class ThreadContextPermission extends BasicPermission { | ||
|
||
/** | ||
* Creates a new ThreadContextPermission object. | ||
* | ||
* @param name target name | ||
*/ | ||
public ThreadContextPermission(String name) { | ||
super(name); | ||
} | ||
|
||
/** | ||
* Creates a new ThreadContextPermission object. | ||
* This constructor exists for use by the {@code Policy} object to instantiate new Permission objects. | ||
* | ||
* @param name target name | ||
* @param actions ignored | ||
*/ | ||
public ThreadContextPermission(String name, String actions) { | ||
super(name, actions); | ||
} | ||
Check warning on line 39 in libs/secure-sm/src/main/java/org/opensearch/secure_sm/ThreadContextPermission.java Codecov / codecov/patchlibs/secure-sm/src/main/java/org/opensearch/secure_sm/ThreadContextPermission.java#L38-L39
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.util.concurrent; | ||
|
||
import org.opensearch.SpecialPermission; | ||
import org.opensearch.common.annotation.InternalApi; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
/** | ||
* This class wraps the {@link ThreadContext} operations requiring access in | ||
* {@link AccessController#doPrivileged(PrivilegedAction)} blocks. | ||
* | ||
* @opensearch.internal | ||
*/ | ||
@SuppressWarnings("removal") | ||
@InternalApi | ||
public final class ThreadContextAccess { | ||
|
||
private ThreadContextAccess() {} | ||
|
||
public static <T> T doPrivileged(PrivilegedAction<T> operation) { | ||
SpecialPermission.check(); | ||
return AccessController.doPrivileged(operation); | ||
Check warning on line 31 in server/src/main/java/org/opensearch/common/util/concurrent/ThreadContextAccess.java Codecov / codecov/patchserver/src/main/java/org/opensearch/common/util/concurrent/ThreadContextAccess.java#L30-L31
|
||
} | ||
|
||
public static void doPrivilegedVoid(Runnable action) { | ||
SpecialPermission.check(); | ||
AccessController.doPrivileged((PrivilegedAction<Void>) () -> { | ||
action.run(); | ||
return null; | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed (#15016 (comment)), we need to make this change backward compatible