-
Couldn't load subscription status.
- Fork 25.6k
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
Conversation
5d95452 to
60de9dc
Compare
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
6b023dc to
cba405d
Compare
caef5bc to
6d17a3a
Compare
6d17a3a to
8530cc1
Compare
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.
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.
...entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/PathActions.java
Show resolved
Hide resolved
...ment/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementCheckerUtils.java
Show resolved
Hide resolved
...nt/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @Override | ||
| public void check$java_net_URL$openConnection(Class<?> callerClass, java.net.URL that) { | ||
| checkEntitlementForUrl(callerClass, that); | ||
| policyChecker.checkEntitlementForUrl(callerClass, that); |
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.
I don't understand why these were moved - they were private to EntitlementChecker, why widen their visibility?
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.
(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)
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.
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.
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.
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( |
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.
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.
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.
Agreed, this is an unusual thing to do. I can change it to use PolicyCheckerImpl, especially since it's a trace log.
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.
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.
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.
Your call :) I'm OK with keeping it unchanged if you are worried about something like alerts
💔 Backport failed
You can use sqren/backport to manually backport by running |
* Split PolicyChecker from PolicyManager * Restore EntitlementCheckerUtils * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
* Split PolicyChecker from PolicyManager * Restore EntitlementCheckerUtils * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
* Split PolicyChecker from PolicyManager * Restore EntitlementCheckerUtils * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
* Split PolicyChecker from PolicyManager * Restore EntitlementCheckerUtils * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
* Split PolicyChecker from PolicyManager * Restore EntitlementCheckerUtils * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
* Split PolicyChecker from PolicyManager * Restore EntitlementCheckerUtils * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
* 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]>
* Split PolicyChecker from PolicyManager * Restore EntitlementCheckerUtils * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
* Split PolicyChecker from PolicyManager * Restore EntitlementCheckerUtils * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]> (cherry picked from commit ba50798) # Conflicts: # libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
PolicyManagerhas a number of responsibilities, including at least:checkmethods that determine whether some required entitlement is presentThis PR splits those into two objects, with the immediate consequence being that we can now swap in a
PolicyManagerForTestingthat modifies the behaviour.With this change, the design looks as follows:
EntitlementCheckerinterface has one method per sensitive JDK method. Its implementation (calledElasticsearchEntitlementChecker) determines which kind of check we should do for each method. Its methods are all one-liners that callPolicyChecker.PolicyCheckerinterface 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 thePolicyManagerto determine what entitlements are granted to that class, and then checking whether the required entitlements are present.PolicyManagerclass determines, for a given caller class, what entitlements that class has been granted, and whether it is trivially allowed.It's
PolicyManagerthat implementsgetEntitlementsandisTriviallyAllowed. The idea is that we'd create aPolicyManagerForTestingthat would override these to provide the required semantics when running in junit.