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

Entitlements for JDK-wide global state changes #119592

Merged
merged 10 commits into from
Jan 8, 2025

Conversation

prdoyle
Copy link
Contributor

@prdoyle prdoyle commented Jan 6, 2025

These entitlements are always denied.

Implements ES-10357.

@prdoyle prdoyle added >non-issue :Core/Infra/Core Core issues without another label auto-backport Automatically create backport pull requests when merged v9.0.0 v8.18.0 test-entitlements Trigger CI checks using security manager replacement labels Jan 6, 2025
@prdoyle prdoyle self-assigned this Jan 6, 2025
@prdoyle prdoyle requested a review from a team as a code owner January 6, 2025 16:11
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Jan 6, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@prdoyle prdoyle force-pushed the moar-entitlements branch from 1f010d7 to 8219a91 Compare January 6, 2025 16:12
}

private record ParsedCheckerMethod(
Copy link
Contributor Author

@prdoyle prdoyle Jan 6, 2025

Choose a reason for hiding this comment

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

My intention was to use this to implement this TODO. However, InstrumentationServiceImpl is not available at that point in the code, so we'd need to move this parsing logic to a common location.

Deferring that for a subsequent PR seemed like a good idea, but if the team wants me to do it here in this PR, I can.

Regardless, this refactoring made the code more clear anyway, I think. Parsing the name and signature are distinct "phases" with different dependencies (name parsing doesn't require the argument types) so it makes sense to move the name parsing into its own method.

Copy link
Contributor

Choose a reason for hiding this comment

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

++ for leaving it for another PR.

I'm not sure if we'll need this refactoring in the end, but I'm OK with it.


void check$java_lang_Runtime$removeShutdownHook(Class<?> callerClass, Runtime runtime, Thread hook);

void check$jdk_tools_jlink_internal_Jlink$(Class<?> callerClass);
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 just realized I left some of these in place despite the fact that we have no tests for them because these classes are not accessible to our code.

I can delete these if we want, or leave them in place "just in case".

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm for keeping them "just in case" -- I thought maybe we can check if the jdk.jlink module is loaded at all, but we can't know which Java distribution we are running on, so...

Copy link
Contributor

@ldematte ldematte left a comment

Choose a reason for hiding this comment

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

LGTM, but please get another opinion on the Dummy vs Test prefix (and then change the related classes to use one consistently)

}

private record ParsedCheckerMethod(
Copy link
Contributor

Choose a reason for hiding this comment

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

++ for leaving it for another PR.

I'm not sure if we'll need this refactoring in the end, but I'm OK with it.


void check$java_lang_Runtime$removeShutdownHook(Class<?> callerClass, Runtime runtime, Thread hook);

void check$jdk_tools_jlink_internal_Jlink$(Class<?> callerClass);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm for keeping them "just in case" -- I thought maybe we can check if the jdk.jlink module is loaded at all, but we can't know which Java distribution we are running on, so...

* <p>
* A bit like Mockito but way more painful.
*/
class DummyImplementations {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the "Dummy" prefix, but I used "Test" in previous code (e.g. TestSSLSocketFactory), as it looked more consistent with the rest of the codebase.
Happy to go either way, but we should decide on one style and use that.

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 went with "Dummy" and renamed your classes.

@@ -32,7 +32,7 @@ public class EntitlementsDeniedIT extends ESRestTestCase {
.systemProperty("es.entitlements.enabled", "true")
.setting("xpack.security.enabled", "false")
// Logs in libs/entitlement/qa/build/test-results/javaRestTest/TEST-org.elasticsearch.entitlement.qa.EntitlementsDeniedIT.xml
.setting("logger.org.elasticsearch.entitlement", "TRACE")
// .setting("logger.org.elasticsearch.entitlement", "DEBUG")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intentional or a leftover from your own testing/debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving TRACE enabled was definitely unintentional; commenting this out is an improvement. 😅

Whether it should be there at all is another question. I find it really convenient and hard to remember, but if you don't like this, I can move it out to my own documentation instead.

@prdoyle prdoyle enabled auto-merge (squash) January 7, 2025 20:32
@prdoyle prdoyle merged commit 6484f94 into elastic:main Jan 8, 2025
21 checks passed
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

prdoyle added a commit to prdoyle/elasticsearch that referenced this pull request Jan 8, 2025
* Refactor: separate check method name vs signature parsing

* Cosmetic: change checker comment format

* Entitlements for JDK-wide global state

* [CI] Auto commit changes from spotless

* Comment explaining entitlement add-exports

* @SuppressForbidden

* Refactor: rename dummy subclases

---------

Co-authored-by: elasticsearchmachine <[email protected]>
@prdoyle prdoyle deleted the moar-entitlements branch January 8, 2025 05:04
elasticsearchmachine added a commit that referenced this pull request Jan 8, 2025
* Refactor: separate check method name vs signature parsing

* Cosmetic: change checker comment format

* Entitlements for JDK-wide global state

* [CI] Auto commit changes from spotless

* Comment explaining entitlement add-exports

* @SuppressForbidden

* Refactor: rename dummy subclases

---------

Co-authored-by: elasticsearchmachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged :Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team test-entitlements Trigger CI checks using security manager replacement v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants