Skip to content

Split PolicyChecker from PolicyManager #128004

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

Merged
merged 4 commits into from
May 28, 2025
Merged

Conversation

prdoyle
Copy link
Contributor

@prdoyle prdoyle commented May 9, 2025

PolicyManager has a number of responsibilities, including at least:

  • Determining the entitlements granted to a given requesting class
  • Two dozen check methods that determine whether some required entitlement is present

This PR splits those into two objects, with the immediate consequence being that we can now swap in a PolicyManagerForTesting that modifies the behaviour.

With this change, the design looks as follows:

  • The EntitlementChecker interface has one method per sensitive JDK method. Its implementation (called ElasticsearchEntitlementChecker) determines which kind of check we should do for each method. Its methods are all one-liners that call PolicyChecker.
  • The PolicyChecker interface has one method per distinct kind of check (about 27 methods in total). Its implementation (PolicyCheckerImpl) has the job of determining the caller class, querying the PolicyManager to determine what entitlements are granted to that class, and then checking whether the required entitlements are present.
  • The PolicyManager class determines, for a given caller class, what entitlements that class has been granted, and whether it is trivially allowed.

It's PolicyManager that implements getEntitlements and isTriviallyAllowed. The idea is that we'd create a PolicyManagerForTesting that would override these to provide the required semantics when running in junit.

@prdoyle prdoyle added >refactoring auto-backport Automatically create backport pull requests when merged v8.19.0 :Core/Infra/Entitlements Entitlements infrastructure v8.18.2 v9.0.2 labels May 9, 2025
@prdoyle prdoyle force-pushed the externalized-cache branch from 5d95452 to 60de9dc Compare May 12, 2025 13:38
@prdoyle prdoyle marked this pull request as ready for review May 12, 2025 13:42
@prdoyle prdoyle requested a review from a team as a code owner May 12, 2025 13:42
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label May 12, 2025
@prdoyle prdoyle force-pushed the externalized-cache branch 2 times, most recently from 6b023dc to cba405d Compare May 12, 2025 14:15
@prdoyle prdoyle force-pushed the externalized-cache branch from caef5bc to 6d17a3a Compare May 12, 2025 15:22
@prdoyle prdoyle force-pushed the externalized-cache branch from 6d17a3a to 8530cc1 Compare May 12, 2025 17:02
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.

I'm neutral wrt to this design; it is different from what I thought we discussed (keep one PolicyManager, inject different behaviours for entitlements resolution in test vs prod) but it might be OK.
But if we go in this direction, there are a couple of things that did not need to change (see comments) and I think they need to be reverted.

}

@Override
public void check$java_net_URL$openConnection(Class<?> callerClass, java.net.URL that) {
checkEntitlementForUrl(callerClass, that);
policyChecker.checkEntitlementForUrl(callerClass, that);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why these were moved - they were private to EntitlementChecker, why widen their visibility?

Copy link
Contributor

Choose a reason for hiding this comment

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

(I prefer the way they are, and leave them out of the interface so it just have the "basic blocks", but I'm OK with moving them and exposing them if you feel strongly about it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before, some of the check utility methods were in ElasticsearchEntitlementChecker and some were in PolicyManager, with no clear reason to pick one or the other. Now, all the check utilities are in PolicyChecker, leaving EntitlementChecker with nothing but the one-liner methods describing which entitlement is required for each sensitive JDK method.

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.

One question to consider, but I'm fine either way. LGTM

private static boolean isPathOnDefaultFilesystem(Path path) {
var pathFileSystemClass = path.getFileSystem().getClass();
if (path.getFileSystem().getClass() != DEFAULT_FILESYSTEM_CLASS) {
PolicyManager.generalLogger.trace(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I find it strange this uses PolicyManager logger; I guess it is for having more consistent logs, but it can be confusing I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, this is an unusual thing to do. I can change it to use PolicyCheckerImpl, especially since it's a trace log.

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 think I was concerned that we already have some alerting on PolicyManager logs and didn't want to worry about those. But we definitely don't have alerts on this one, so that reasoning isn't really sound.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your call :) I'm OK with keeping it unchanged if you are worried about something like alerts

@prdoyle prdoyle merged commit ba50798 into elastic:main May 28, 2025
18 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.19 Commit could not be cherrypicked due to conflicts
9.0
8.18 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 128004

prdoyle added a commit to prdoyle/elasticsearch that referenced this pull request May 28, 2025
* Split PolicyChecker from PolicyManager

* Restore EntitlementCheckerUtils

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
elasticsearchmachine added a commit that referenced this pull request May 28, 2025
* Split PolicyChecker from PolicyManager

* Restore EntitlementCheckerUtils

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
@prdoyle prdoyle removed the v8.18.3 label May 29, 2025
prdoyle added a commit to prdoyle/elasticsearch that referenced this pull request May 29, 2025
* Split PolicyChecker from PolicyManager

* Restore EntitlementCheckerUtils

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
prdoyle added a commit to prdoyle/elasticsearch that referenced this pull request May 29, 2025
* Split PolicyChecker from PolicyManager

* Restore EntitlementCheckerUtils

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
prdoyle added a commit to prdoyle/elasticsearch that referenced this pull request May 29, 2025
* Split PolicyChecker from PolicyManager

* Restore EntitlementCheckerUtils

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
prdoyle added a commit to prdoyle/elasticsearch that referenced this pull request May 30, 2025
* Split PolicyChecker from PolicyManager

* Restore EntitlementCheckerUtils

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>
elasticsearchmachine added a commit that referenced this pull request May 30, 2025
* Split PolicyChecker from PolicyManager (#128004)

* Split PolicyChecker from PolicyManager

* Restore EntitlementCheckerUtils

* [CI] Auto commit changes from spotless

---------

Co-authored-by: elasticsearchmachine <[email protected]>

* PolicyChecker change in JavaXX entitlement checkers

---------

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 backport pending :Core/Infra/Entitlements Entitlements infrastructure >refactoring Team:Core/Infra Meta label for core/infra team v8.19.0 v9.0.3 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants