-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Encapsulate entitlements #128637
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
Encapsulate entitlements #128637
Changes from all commits
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 |
|---|---|---|
|
|
@@ -10,9 +10,9 @@ | |
| package org.elasticsearch.entitlement.initialization; | ||
|
|
||
| import org.elasticsearch.core.Booleans; | ||
| import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.entitlement.bridge.EntitlementChecker; | ||
| import org.elasticsearch.entitlement.runtime.api.ElasticsearchEntitlementChecker; | ||
| import org.elasticsearch.entitlement.runtime.policy.ElasticsearchEntitlementChecker; | ||
| import org.elasticsearch.entitlement.runtime.policy.PathLookup; | ||
| import org.elasticsearch.entitlement.runtime.policy.Policy; | ||
| import org.elasticsearch.entitlement.runtime.policy.PolicyChecker; | ||
|
|
@@ -22,8 +22,12 @@ | |
| import java.lang.instrument.Instrumentation; | ||
| import java.lang.reflect.Constructor; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.nio.file.Path; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.function.Function; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| /** | ||
| * Called by the agent during {@code agentmain} to configure the entitlement system, | ||
|
|
@@ -36,6 +40,7 @@ public class EntitlementInitialization { | |
|
|
||
| private static final Module ENTITLEMENTS_MODULE = PolicyManager.class.getModule(); | ||
|
|
||
| public static InitializeArgs initializeArgs; | ||
|
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.
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. I figured they are the arguments for the |
||
| private static ElasticsearchEntitlementChecker checker; | ||
|
|
||
| // Note: referenced by bridge reflectively | ||
|
|
@@ -66,29 +71,55 @@ public static void initialize(Instrumentation inst) throws Exception { | |
| checker = initChecker(inst, createPolicyManager()); | ||
| } | ||
|
|
||
| /** | ||
| * Arguments to {@link #initialize}. Since that's called in a static context from the agent, | ||
| * we have no way to pass arguments directly, so we stuff them in here. | ||
| * | ||
| * @param serverPolicyPatch | ||
| * @param pluginPolicies | ||
| * @param scopeResolver | ||
| * @param pathLookup | ||
| * @param sourcePaths | ||
| * @param suppressFailureLogPackages | ||
| */ | ||
| public record InitializeArgs( | ||
| @Nullable Policy serverPolicyPatch, | ||
| Map<String, Policy> pluginPolicies, | ||
| Function<Class<?>, PolicyManager.PolicyScope> scopeResolver, | ||
| PathLookup pathLookup, | ||
| Map<String, Path> sourcePaths, | ||
| Set<Package> suppressFailureLogPackages | ||
| ) { | ||
| public InitializeArgs { | ||
| requireNonNull(pluginPolicies); | ||
| requireNonNull(scopeResolver); | ||
| requireNonNull(pathLookup); | ||
| requireNonNull(sourcePaths); | ||
| requireNonNull(suppressFailureLogPackages); | ||
| } | ||
| } | ||
|
|
||
| private static PolicyCheckerImpl createPolicyChecker(PolicyManager policyManager) { | ||
| EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs(); | ||
| return new PolicyCheckerImpl( | ||
| bootstrapArgs.suppressFailureLogPackages(), | ||
| initializeArgs.suppressFailureLogPackages(), | ||
| ENTITLEMENTS_MODULE, | ||
| policyManager, | ||
| bootstrapArgs.pathLookup() | ||
| initializeArgs.pathLookup() | ||
| ); | ||
| } | ||
|
|
||
| private static PolicyManager createPolicyManager() { | ||
| EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs(); | ||
| Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies(); | ||
| PathLookup pathLookup = bootstrapArgs.pathLookup(); | ||
| Map<String, Policy> pluginPolicies = initializeArgs.pluginPolicies(); | ||
| PathLookup pathLookup = initializeArgs.pathLookup(); | ||
|
|
||
| FilesEntitlementsValidation.validate(pluginPolicies, pathLookup); | ||
|
|
||
| return new PolicyManager( | ||
| HardcodedEntitlements.serverPolicy(pathLookup.pidFile(), bootstrapArgs.serverPolicyPatch()), | ||
| HardcodedEntitlements.serverPolicy(pathLookup.pidFile(), initializeArgs.serverPolicyPatch()), | ||
| HardcodedEntitlements.agentEntitlements(), | ||
| pluginPolicies, | ||
| EntitlementBootstrap.bootstrapArgs().scopeResolver(), | ||
| EntitlementBootstrap.bootstrapArgs().sourcePaths(), | ||
| initializeArgs.scopeResolver(), | ||
| initializeArgs.sourcePaths(), | ||
| pathLookup | ||
| ); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * 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". | ||
| */ | ||
|
|
||
| /** | ||
| * The public API for the Entitlements system. | ||
| * All other packages are implementation details that should use selective exports. | ||
| */ | ||
| package org.elasticsearch.entitlement.runtime.api; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,8 @@ | |
| import org.elasticsearch.bootstrap.TestScopeResolver; | ||
| import org.elasticsearch.core.Strings; | ||
| import org.elasticsearch.core.SuppressForbidden; | ||
| import org.elasticsearch.entitlement.bootstrap.TestEntitlementBootstrap; | ||
| import org.elasticsearch.entitlement.bridge.EntitlementChecker; | ||
| import org.elasticsearch.entitlement.runtime.api.ElasticsearchEntitlementChecker; | ||
| import org.elasticsearch.entitlement.runtime.policy.ElasticsearchEntitlementChecker; | ||
| import org.elasticsearch.entitlement.runtime.policy.PathLookup; | ||
| import org.elasticsearch.entitlement.runtime.policy.Policy; | ||
| import org.elasticsearch.entitlement.runtime.policy.PolicyManager; | ||
|
|
@@ -38,17 +37,19 @@ | |
| public class TestEntitlementInitialization { | ||
|
|
||
| private static ElasticsearchEntitlementChecker checker; | ||
| public static InitializeArgs initializeArgs; | ||
|
|
||
| // Note: referenced by bridge reflectively | ||
| public static EntitlementChecker checker() { | ||
| return checker; | ||
| } | ||
|
|
||
| public static void initialize(Instrumentation inst) throws Exception { | ||
| TestEntitlementBootstrap.BootstrapArgs bootstrapArgs = TestEntitlementBootstrap.bootstrapArgs(); | ||
| checker = EntitlementInitialization.initChecker(inst, createPolicyManager(bootstrapArgs.pathLookup())); | ||
| checker = EntitlementInitialization.initChecker(inst, createPolicyManager(initializeArgs.pathLookup())); | ||
| } | ||
|
|
||
| public record InitializeArgs(PathLookup pathLookup) {} | ||
|
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.
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. Ditto. The problem this solves is that we can't pass arguments directly to the |
||
|
|
||
| private record TestPluginData(String pluginName, boolean isModular, boolean isExternalPlugin) {} | ||
|
|
||
| private static Map<String, Policy> parsePluginsPolicies(List<TestPluginData> pluginsData) { | ||
|
|
@@ -115,4 +116,5 @@ private static PolicyManager createPolicyManager(PathLookup pathLookup) throws I | |
| ); | ||
| throw new IllegalStateException("Not yet implemented!"); | ||
| } | ||
|
|
||
| } | ||
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: Should this drop to the lines with the other runtime exports?
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.
This is the one we proudly export. The others are not supposed to be public, but they currently are of necessity, so I pulled them down into their own section with a
TODO.