Skip to content

Commit 77587a2

Browse files
committed
Fully initialize policy checker before instrumenting
Entitlement instrumentation works by reflectively calling back into the entitlements lib to grab the checker. It must be fully in place before any classes are instrumented. This commit fixes a bug that was introduced by refactoring which caused the checker to not be set until after all classes were instrumented. In some situations this could lead the checker to being null when it is grab (and statically cached) by the entitlement bridge.
1 parent 7f7cb83 commit 77587a2

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public static EntitlementChecker checker() {
6363
* @param inst the JVM instrumentation class instance
6464
*/
6565
public static void initialize(Instrumentation inst) throws Exception {
66-
checker = initChecker(inst, createPolicyManager());
66+
checker = initChecker(createPolicyManager());
67+
initInstrumentation(inst);
6768
}
6869

6970
private static PolicyCheckerImpl createPolicyChecker(PolicyManager policyManager) {
@@ -115,7 +116,7 @@ private static void ensureClassesSensitiveToVerificationAreInitialized() {
115116
}
116117
}
117118

118-
static ElasticsearchEntitlementChecker initChecker(Instrumentation inst, PolicyManager policyManager) throws Exception {
119+
static ElasticsearchEntitlementChecker initChecker(PolicyManager policyManager) {
119120
final PolicyChecker policyChecker = createPolicyChecker(policyManager);
120121
final Class<?> clazz = EntitlementCheckerUtils.getVersionSpecificCheckerClass(
121122
ElasticsearchEntitlementChecker.class,
@@ -136,17 +137,21 @@ static ElasticsearchEntitlementChecker initChecker(Instrumentation inst, PolicyM
136137
throw new AssertionError(e);
137138
}
138139

140+
141+
return checker;
142+
}
143+
144+
static void initInstrumentation(Instrumentation instrumentation) throws Exception {
139145
var verifyBytecode = Booleans.parseBoolean(System.getProperty("es.entitlements.verify_bytecode", "false"));
140146
if (verifyBytecode) {
141147
ensureClassesSensitiveToVerificationAreInitialized();
142148
}
143149

144150
DynamicInstrumentation.initialize(
145-
inst,
151+
instrumentation,
146152
EntitlementCheckerUtils.getVersionSpecificCheckerClass(EntitlementChecker.class, Runtime.version().feature()),
147153
verifyBytecode
148154
);
149155

150-
return checker;
151156
}
152157
}

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,6 @@ tests:
501501
- class: org.elasticsearch.xpack.esql.expression.function.scalar.string.WildcardLikeTests
502502
method: testEvaluateInManyThreads {TestCase=100 random code points matches self case insensitive with text}
503503
issue: https://github.com/elastic/elasticsearch/issues/128677
504-
- class: org.elasticsearch.test.apmintegration.MetricsApmIT
505-
method: testApmIntegration
506-
issue: https://github.com/elastic/elasticsearch/issues/128678
507504

508505
# Examples:
509506
#

0 commit comments

Comments
 (0)