- 
                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 16 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 | 
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the "Elastic License | ||
| * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
| 
     | 
||
| package org.elasticsearch.entitlement.qa.test; | ||
| 
     | 
||
| import org.elasticsearch.core.SuppressForbidden; | ||
| 
     | 
||
| import java.util.concurrent.ForkJoinPool; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
| 
     | 
||
| import static java.lang.Thread.currentThread; | ||
| import static org.elasticsearch.entitlement.qa.test.EntitlementTest.ExpectedAccess.PLUGINS; | ||
| 
     | 
||
| @SuppressForbidden(reason = "testing entitlements") | ||
| @SuppressWarnings("unused") // used via reflection | ||
| class ManageThreadsActions { | ||
| private ManageThreadsActions() {} | ||
| 
     | 
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void java_lang_Thread$start() throws InterruptedException { | ||
| AtomicBoolean threadRan = new AtomicBoolean(false); | ||
| Thread thread = new Thread(() -> threadRan.set(true), "test"); | ||
| thread.start(); | ||
| thread.join(); | ||
| assert threadRan.get(); | ||
| } | ||
| 
     | 
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void java_lang_Thread$setDaemon() { | ||
| new Thread().setDaemon(true); | ||
| } | ||
| 
     | 
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void java_lang_ThreadGroup$setDaemon() { | ||
| currentThread().getThreadGroup().setDaemon(currentThread().getThreadGroup().isDaemon()); | ||
| } | ||
| 
     | 
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void java_util_concurrent_ForkJoinPool$setParallelism() { | ||
| ForkJoinPool.commonPool().setParallelism(ForkJoinPool.commonPool().getParallelism()); | ||
| } | ||
| 
     | 
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void java_lang_Thread$setName() { | ||
| currentThread().setName(currentThread().getName()); | ||
| } | ||
| 
     | 
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void java_lang_Thread$setPriority() { | ||
| currentThread().setPriority(currentThread().getPriority()); | ||
| } | ||
| 
     | 
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void java_lang_Thread$setUncaughtExceptionHandler() { | ||
| currentThread().setUncaughtExceptionHandler(currentThread().getUncaughtExceptionHandler()); | ||
| } | ||
| 
     | 
||
| @EntitlementTest(expectedAccess = PLUGINS) | ||
| static void java_lang_ThreadGroup$setMaxPriority() { | ||
| currentThread().getThreadGroup().setMaxPriority(currentThread().getThreadGroup().getMaxPriority()); | ||
| } | ||
| 
     | 
||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -181,13 +181,17 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) { | |
| entry("runtime_load_library", forPlugins(LoadNativeLibrariesCheckActions::runtimeLoadLibrary)), | ||
| entry("system_load", forPlugins(LoadNativeLibrariesCheckActions::systemLoad)), | ||
| entry("system_load_library", forPlugins(LoadNativeLibrariesCheckActions::systemLoadLibrary)) | ||
| 
     | 
||
| // MAINTENANCE NOTE: Please don't add any more entries to this map. | ||
| // Put new tests into their own "Actions" class using the @EntitlementTest annotation. | ||
| ), | ||
| getTestEntries(FileCheckActions.class), | ||
| getTestEntries(SpiActions.class), | ||
| getTestEntries(SystemActions.class), | ||
| getTestEntries(FileStoreActions.class), | ||
| getTestEntries(ManageThreadsActions.class), | ||
| getTestEntries(NativeActions.class), | ||
| getTestEntries(NioFileSystemActions.class), | ||
| getTestEntries(FileStoreActions.class) | ||
| getTestEntries(SpiActions.class), | ||
| getTestEntries(SystemActions.class) | ||
| ) | ||
| .flatMap(Function.identity()) | ||
| .filter(entry -> entry.getValue().fromJavaVersion() == null || Runtime.version().feature() >= entry.getValue().fromJavaVersion()) | ||
| 
          
            
          
           | 
    @@ -424,7 +428,9 @@ 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))); | ||
| }; | ||
| } | ||
| 
     | 
||
| } | ||
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.
Thanks for ordering this; maybe mention it to everyone so we keep it ordered (and help in reducing merge conflicts)