Skip to content

Commit b5c50ba

Browse files
committed
Merge branch 'main' into entitlements/checker_then_instrumentation
2 parents 8b8eece + 9e40dc4 commit b5c50ba

File tree

21 files changed

+1002
-110
lines changed

21 files changed

+1002
-110
lines changed

libs/entitlement/src/main/java/module-info.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
requires static org.elasticsearch.entitlement.bridge; // At runtime, this will be in java.base
2121

2222
exports org.elasticsearch.entitlement.runtime.api;
23-
exports org.elasticsearch.entitlement.runtime.policy;
24-
exports org.elasticsearch.entitlement.runtime.policy.entitlements to org.elasticsearch.server;
2523
exports org.elasticsearch.entitlement.instrumentation;
2624
exports org.elasticsearch.entitlement.bootstrap to org.elasticsearch.server;
2725
exports org.elasticsearch.entitlement.initialization to java.base;
2826

27+
// TODO: Most of the things in the policy package should be internal implementation details that are not exported.
28+
exports org.elasticsearch.entitlement.runtime.policy;
29+
exports org.elasticsearch.entitlement.runtime.policy.entitlements to org.elasticsearch.server;
30+
2931
uses org.elasticsearch.entitlement.instrumentation.InstrumentationService;
3032
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/bootstrap/EntitlementBootstrap.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
import com.sun.tools.attach.AttachNotSupportedException;
1515
import com.sun.tools.attach.VirtualMachine;
1616

17-
import org.elasticsearch.core.Nullable;
1817
import org.elasticsearch.core.PathUtils;
1918
import org.elasticsearch.core.SuppressForbidden;
2019
import org.elasticsearch.entitlement.initialization.EntitlementInitialization;
21-
import org.elasticsearch.entitlement.runtime.policy.PathLookup;
2220
import org.elasticsearch.entitlement.runtime.policy.PathLookupImpl;
2321
import org.elasticsearch.entitlement.runtime.policy.Policy;
2422
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
@@ -33,35 +31,11 @@
3331
import java.util.function.Function;
3432
import java.util.stream.Stream;
3533

36-
import static java.util.Objects.requireNonNull;
37-
3834
public class EntitlementBootstrap {
3935

40-
public record BootstrapArgs(
41-
@Nullable Policy serverPolicyPatch,
42-
Map<String, Policy> pluginPolicies,
43-
Function<Class<?>, PolicyManager.PolicyScope> scopeResolver,
44-
PathLookup pathLookup,
45-
Map<String, Path> sourcePaths,
46-
Set<Package> suppressFailureLogPackages
47-
) {
48-
public BootstrapArgs {
49-
requireNonNull(pluginPolicies);
50-
requireNonNull(scopeResolver);
51-
requireNonNull(pathLookup);
52-
requireNonNull(sourcePaths);
53-
requireNonNull(suppressFailureLogPackages);
54-
}
55-
}
56-
57-
private static BootstrapArgs bootstrapArgs;
58-
59-
public static BootstrapArgs bootstrapArgs() {
60-
return bootstrapArgs;
61-
}
62-
6336
/**
64-
* Activates entitlement checking. Once this method returns, calls to methods protected by Entitlements from classes without a valid
37+
* Main entry point that activates entitlement checking. Once this method returns,
38+
* calls to methods protected by entitlements from classes without a valid
6539
* policy will throw {@link org.elasticsearch.entitlement.runtime.api.NotEntitledException}.
6640
*
6741
* @param serverPolicyPatch a policy with additional entitlements to patch the embedded server layer policy
@@ -98,10 +72,10 @@ public static void bootstrap(
9872
Set<Package> suppressFailureLogPackages
9973
) {
10074
logger.debug("Loading entitlement agent");
101-
if (EntitlementBootstrap.bootstrapArgs != null) {
102-
throw new IllegalStateException("plugin data is already set");
75+
if (EntitlementInitialization.initializeArgs != null) {
76+
throw new IllegalStateException("initialization data is already set");
10377
}
104-
EntitlementBootstrap.bootstrapArgs = new BootstrapArgs(
78+
EntitlementInitialization.initializeArgs = new EntitlementInitialization.InitializeArgs(
10579
serverPolicyPatch,
10680
pluginPolicies,
10781
scopeResolver,

libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/EntitlementInitialization.java

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
package org.elasticsearch.entitlement.initialization;
1111

1212
import org.elasticsearch.core.Booleans;
13-
import org.elasticsearch.entitlement.bootstrap.EntitlementBootstrap;
13+
import org.elasticsearch.core.Nullable;
1414
import org.elasticsearch.entitlement.bridge.EntitlementChecker;
15-
import org.elasticsearch.entitlement.runtime.api.ElasticsearchEntitlementChecker;
15+
import org.elasticsearch.entitlement.runtime.policy.ElasticsearchEntitlementChecker;
1616
import org.elasticsearch.entitlement.runtime.policy.PathLookup;
1717
import org.elasticsearch.entitlement.runtime.policy.Policy;
1818
import org.elasticsearch.entitlement.runtime.policy.PolicyChecker;
@@ -22,8 +22,12 @@
2222
import java.lang.instrument.Instrumentation;
2323
import java.lang.reflect.Constructor;
2424
import java.lang.reflect.InvocationTargetException;
25+
import java.nio.file.Path;
2526
import java.util.Map;
2627
import java.util.Set;
28+
import java.util.function.Function;
29+
30+
import static java.util.Objects.requireNonNull;
2731

2832
/**
2933
* Called by the agent during {@code agentmain} to configure the entitlement system,
@@ -36,6 +40,7 @@ public class EntitlementInitialization {
3640

3741
private static final Module ENTITLEMENTS_MODULE = PolicyManager.class.getModule();
3842

43+
public static InitializeArgs initializeArgs;
3944
private static ElasticsearchEntitlementChecker checker;
4045

4146
// Note: referenced by bridge reflectively
@@ -68,29 +73,55 @@ public static void initialize(Instrumentation inst) throws Exception {
6873
initInstrumentation(inst);
6974
}
7075

76+
/**
77+
* Arguments to {@link #initialize}. Since that's called in a static context from the agent,
78+
* we have no way to pass arguments directly, so we stuff them in here.
79+
*
80+
* @param serverPolicyPatch
81+
* @param pluginPolicies
82+
* @param scopeResolver
83+
* @param pathLookup
84+
* @param sourcePaths
85+
* @param suppressFailureLogPackages
86+
*/
87+
public record InitializeArgs(
88+
@Nullable Policy serverPolicyPatch,
89+
Map<String, Policy> pluginPolicies,
90+
Function<Class<?>, PolicyManager.PolicyScope> scopeResolver,
91+
PathLookup pathLookup,
92+
Map<String, Path> sourcePaths,
93+
Set<Package> suppressFailureLogPackages
94+
) {
95+
public InitializeArgs {
96+
requireNonNull(pluginPolicies);
97+
requireNonNull(scopeResolver);
98+
requireNonNull(pathLookup);
99+
requireNonNull(sourcePaths);
100+
requireNonNull(suppressFailureLogPackages);
101+
}
102+
}
103+
71104
private static PolicyCheckerImpl createPolicyChecker(PolicyManager policyManager) {
72-
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
73105
return new PolicyCheckerImpl(
74-
bootstrapArgs.suppressFailureLogPackages(),
106+
initializeArgs.suppressFailureLogPackages(),
75107
ENTITLEMENTS_MODULE,
76108
policyManager,
77-
bootstrapArgs.pathLookup()
109+
initializeArgs.pathLookup()
78110
);
79111
}
80112

81113
private static PolicyManager createPolicyManager() {
82-
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
83-
Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies();
84-
PathLookup pathLookup = bootstrapArgs.pathLookup();
114+
Map<String, Policy> pluginPolicies = initializeArgs.pluginPolicies();
115+
PathLookup pathLookup = initializeArgs.pathLookup();
85116

86117
FilesEntitlementsValidation.validate(pluginPolicies, pathLookup);
87118

88119
return new PolicyManager(
89-
HardcodedEntitlements.serverPolicy(pathLookup.pidFile(), bootstrapArgs.serverPolicyPatch()),
120+
HardcodedEntitlements.serverPolicy(pathLookup.pidFile(), initializeArgs.serverPolicyPatch()),
90121
HardcodedEntitlements.agentEntitlements(),
91122
pluginPolicies,
92-
EntitlementBootstrap.bootstrapArgs().scopeResolver(),
93-
EntitlementBootstrap.bootstrapArgs().sourcePaths(),
123+
initializeArgs.scopeResolver(),
124+
initializeArgs.sourcePaths(),
94125
pathLookup
95126
);
96127
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
* <h2>Checks</h2>
190190
* <p>
191191
* The injected prologue calls a {@code check$} method on {@link org.elasticsearch.entitlement.bridge.EntitlementChecker}; its
192-
* implementation (normally on {@link org.elasticsearch.entitlement.runtime.api.ElasticsearchEntitlementChecker}, unless it is a
192+
* implementation (normally on {@link org.elasticsearch.entitlement.runtime.policy.ElasticsearchEntitlementChecker}, unless it is a
193193
* version-specific method) calls the appropriate methods on {@link org.elasticsearch.entitlement.runtime.policy.PolicyManager},
194194
* forwarding the caller class and a specific set of arguments. These methods all start with check, roughly matching an entitlement type
195195
* (e.g. {@link org.elasticsearch.entitlement.runtime.policy.PolicyChecker#checkInboundNetworkAccess},
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
/**
11+
* The public API for the Entitlements system.
12+
* All other packages are implementation details that should use selective exports.
13+
*/
14+
package org.elasticsearch.entitlement.runtime.api;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
package org.elasticsearch.entitlement.runtime.api;
10+
package org.elasticsearch.entitlement.runtime.policy;
1111

1212
import jdk.nio.Channels;
1313

1414
import org.elasticsearch.core.SuppressForbidden;
1515
import org.elasticsearch.entitlement.bridge.EntitlementChecker;
16-
import org.elasticsearch.entitlement.runtime.policy.PolicyChecker;
1716

1817
import java.io.File;
1918
import java.io.FileDescriptor;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
99

10-
package org.elasticsearch.entitlement.runtime.api;
10+
package org.elasticsearch.entitlement.runtime.policy;
1111

1212
import org.elasticsearch.entitlement.bridge.Java23EntitlementChecker;
13-
import org.elasticsearch.entitlement.runtime.policy.PolicyChecker;
1413

1514
public class Java23ElasticsearchEntitlementChecker extends ElasticsearchEntitlementChecker implements Java23EntitlementChecker {
1615

rest-api-spec/src/yamlRestTest/java/org/elasticsearch/test/rest/ClientYamlTestSuiteIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
3838
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
3939
.feature(FeatureFlag.DOC_VALUES_SKIPPER)
4040
.feature(FeatureFlag.USE_LUCENE101_POSTINGS_FORMAT)
41+
.feature(FeatureFlag.IVF_FORMAT)
4142
.build();
4243

4344
public ClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) {

0 commit comments

Comments
 (0)