-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Entitlements: manage_threads #122261
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
Entitlements: manage_threads #122261
Changes from 7 commits
13e0d54
a30fc17
14f70df
d0e428d
7835c36
d075cc3
99ab3d9
7a4ba3c
0953768
bcd0183
47fc38d
56aa68d
0c1d79f
f46110b
a2de8d2
ce9cce7
92bbfe4
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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.core.CheckedRunnable; | ||
| import org.elasticsearch.core.SuppressForbidden; | ||
| import org.elasticsearch.entitlement.qa.entitled.EntitledActions; | ||
| import org.elasticsearch.logging.LogManager; | ||
| import org.elasticsearch.logging.Logger; | ||
| import org.elasticsearch.rest.BaseRestHandler; | ||
|
|
@@ -47,13 +48,16 @@ | |
| import java.util.Map; | ||
| import java.util.Map.Entry; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ForkJoinPool; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import javax.net.ssl.HttpsURLConnection; | ||
| import javax.net.ssl.SSLContext; | ||
|
|
||
| import static java.lang.Thread.currentThread; | ||
| import static java.util.Map.entry; | ||
| import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS; | ||
| import static org.elasticsearch.entitlement.qa.test.RestEntitlementsCheckAction.CheckAction.alwaysDenied; | ||
|
|
@@ -180,7 +184,25 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) { | |
| entry("runtime_load", forPlugins(LoadNativeLibrariesCheckActions::runtimeLoad)), | ||
| entry("runtime_load_library", forPlugins(LoadNativeLibrariesCheckActions::runtimeLoadLibrary)), | ||
| entry("system_load", forPlugins(LoadNativeLibrariesCheckActions::systemLoad)), | ||
| entry("system_load_library", forPlugins(LoadNativeLibrariesCheckActions::systemLoadLibrary)) | ||
| entry("system_load_library", forPlugins(LoadNativeLibrariesCheckActions::systemLoadLibrary)), | ||
|
|
||
| entry("java_lang_Thread$start", forPlugins(RestEntitlementsCheckAction::java_lang_Thread$start)), | ||
prdoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| entry("java_lang_Thread$setDaemon", deniedToPlugins(RestEntitlementsCheckAction::java_lang_Thread$setDaemon)), | ||
| entry("java_lang_ThreadGroup$setDaemon", deniedToPlugins(RestEntitlementsCheckAction::java_lang_ThreadGroup$setDaemon)), | ||
| entry( | ||
| "java_util_concurrent_ForkJoinPool$setParallelism", | ||
| deniedToPlugins(RestEntitlementsCheckAction::java_util_concurrent_ForkJoinPool$setParallelism) | ||
| ), | ||
| entry("java_lang_Thread$setName", deniedToPlugins(RestEntitlementsCheckAction::java_lang_Thread$setName)), | ||
| entry("java_lang_Thread$setPriority", deniedToPlugins(RestEntitlementsCheckAction::java_lang_Thread$setPriority)), | ||
| entry( | ||
| "java_lang_Thread$setUncaughtExceptionHandler", | ||
| deniedToPlugins(RestEntitlementsCheckAction::java_lang_Thread$setUncaughtExceptionHandler) | ||
| ), | ||
| entry( | ||
| "java_lang_ThreadGroup$setMaxPriority", | ||
| deniedToPlugins(RestEntitlementsCheckAction::java_lang_ThreadGroup$setMaxPriority) | ||
| ) | ||
| ), | ||
| getTestEntries(FileCheckActions.class), | ||
| getTestEntries(SpiActions.class), | ||
|
|
@@ -423,7 +445,45 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli | |
| return channel -> { | ||
| logger.info("Calling check action [{}]", actionName); | ||
| checkAction.action().run(); | ||
| logger.debug("Check action [{}] returned", actionName); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intentional or leftover from debugging? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At one point, I wanted to know whether the action actually returned, as opposed to throwing. By and large, when I add log statements during debugging, I don't remove them before merging because if they're helpful once, they're likely to be helpful again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| channel.sendResponse(new RestResponse(RestStatus.OK, Strings.format("Succesfully executed action [%s]", actionName))); | ||
| }; | ||
| } | ||
|
|
||
| static void java_lang_Thread$start() throws InterruptedException { | ||
| AtomicBoolean threadRan = new AtomicBoolean(false); | ||
| Thread thread = EntitledActions.newThread(() -> threadRan.set(true), "test"); | ||
| thread.start(); | ||
| thread.join(); | ||
| assert threadRan.get(); | ||
| } | ||
|
|
||
| static void java_lang_Thread$setDaemon() { | ||
| currentThread().setDaemon(currentThread().isDaemon()); | ||
| } | ||
|
|
||
| static void java_lang_ThreadGroup$setDaemon() { | ||
| currentThread().getThreadGroup().setDaemon(currentThread().getThreadGroup().isDaemon()); | ||
| } | ||
|
|
||
| static void java_util_concurrent_ForkJoinPool$setParallelism() { | ||
| ForkJoinPool.commonPool().setParallelism(ForkJoinPool.commonPool().getParallelism()); | ||
| } | ||
|
|
||
| static void java_lang_Thread$setName() { | ||
| currentThread().setName(currentThread().getName()); | ||
| } | ||
|
|
||
| static void java_lang_Thread$setPriority() { | ||
| currentThread().setPriority(currentThread().getPriority()); | ||
| } | ||
|
|
||
| static void java_lang_Thread$setUncaughtExceptionHandler() { | ||
| currentThread().setUncaughtExceptionHandler(currentThread().getUncaughtExceptionHandler()); | ||
| } | ||
|
|
||
| static void java_lang_ThreadGroup$setMaxPriority() { | ||
| currentThread().getThreadGroup().setMaxPriority(currentThread().getThreadGroup().getMaxPriority()); | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.