Skip to content

Commit a8d3bbe

Browse files
committed
Merge remote-tracking branch 'upstream/main' into entitlements/logs-dir-bootstrap
2 parents dfc2a67 + 9141335 commit a8d3bbe

File tree

29 files changed

+527
-127
lines changed

29 files changed

+527
-127
lines changed

.buildkite/hooks/pre-command

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export GRADLE_BUILD_CACHE_USERNAME
4444
GRADLE_BUILD_CACHE_PASSWORD=$(vault read -field=password secret/ci/elastic-elasticsearch/migrated/gradle-build-cache)
4545
export GRADLE_BUILD_CACHE_PASSWORD
4646

47+
DEVELOCITY_ACCESS_KEY="gradle-enterprise.elastic.co=$(vault read -field=accesskey secret/ci/elastic-elasticsearch/migrated/gradle-build-cache)"
48+
export DEVELOCITY_ACCESS_KEY
49+
4750
BUILDKITE_API_TOKEN=$(vault read -field=token secret/ci/elastic-elasticsearch/buildkite-api-token)
4851
export BUILDKITE_API_TOKEN
4952

.ci/init.gradle

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
1+
final String buildCacheUrl = System.getProperty('org.elasticsearch.build.cache.url')
2+
final boolean buildCachePush = Boolean.valueOf(System.getProperty('org.elasticsearch.build.cache.push', 'false'))
3+
14
gradle.settingsEvaluated { settings ->
25
settings.pluginManager.withPlugin("com.gradle.develocity") {
36
settings.develocity {
4-
server = 'https://gradle-enterprise.elastic.co'
7+
server = "https://gradle-enterprise.elastic.co"
58
}
6-
}
7-
}
8-
9-
final String buildCacheUrl = System.getProperty('org.elasticsearch.build.cache.url')
10-
final boolean buildCachePush = Boolean.valueOf(System.getProperty('org.elasticsearch.build.cache.push', 'false'))
11-
12-
if (buildCacheUrl) {
13-
gradle.settingsEvaluated { settings ->
14-
settings.buildCache {
15-
local {
16-
// Disable the local build cache in CI since we use ephemeral workers and it incurs an IO penalty
17-
enabled = false
18-
}
19-
remote(HttpBuildCache) {
20-
url = buildCacheUrl
21-
push = buildCachePush
22-
credentials {
23-
username = System.getenv("GRADLE_BUILD_CACHE_USERNAME")
24-
password = System.getenv("GRADLE_BUILD_CACHE_PASSWORD")
9+
if (buildCacheUrl) {
10+
settings.buildCache {
11+
local {
12+
// Disable the local build cache in CI since we use ephemeral workers and it incurs an IO penalty
13+
enabled = false
14+
}
15+
remote(settings.develocity.buildCache) {
16+
enabled = true
17+
push = buildCachePush
2518
}
2619
}
2720
}
2821
}
2922
}
23+
24+

build-conventions/settings.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
* your election, the "Elastic License 2.0", the "GNU Affero General Public
77
* License v3.0 only", or the "Server Side Public License, v 1".
88
*/
9+
10+
plugins {
11+
id "com.gradle.develocity" version "3.18.1"
12+
}
13+
914
rootProject.name = 'build-conventions'
1015

1116
dependencyResolutionManagement {

build-tools-internal/settings.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ pluginManagement {
88
includeBuild "../build-tools"
99
}
1010

11+
plugins {
12+
id "com.gradle.develocity" version "3.18.1"
13+
}
14+
1115
dependencyResolutionManagement {
1216
versionCatalogs {
1317
buildLibs {

build-tools/settings.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
pluginManagement {
1010
includeBuild "../build-conventions"
1111
}
12-
12+
plugins {
13+
id "com.gradle.develocity" version "3.18.1"
14+
}
1315
include 'reaper'
1416

1517
dependencyResolutionManagement {

docs/changelog/122575.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 122575
2+
summary: Return an empty suggestion when suggest phase times out
3+
area: Suggesters
4+
type: bug
5+
issues:
6+
- 122548

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/LoadNativeLibrariesCheckActions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
class LoadNativeLibrariesCheckActions {
1313
static void runtimeLoad() {
1414
try {
15-
Runtime.getRuntime().load("libSomeLibFile.so");
15+
Runtime.getRuntime().load(FileCheckActions.readDir().resolve("libSomeLibFile.so").toString());
1616
} catch (UnsatisfiedLinkError ignored) {
1717
// The library does not exist, so we expect to fail loading it
1818
}
1919
}
2020

2121
static void systemLoad() {
2222
try {
23-
System.load("libSomeLibFile.so");
23+
System.load(FileCheckActions.readDir().resolve("libSomeLibFile.so").toString());
2424
} catch (UnsatisfiedLinkError ignored) {
2525
// The library does not exist, so we expect to fail loading it
2626
}

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/NativeActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void memorySegmentReinterpretWithSizeAndCleanup() {
113113
@EntitlementTest(expectedAccess = PLUGINS)
114114
static void symbolLookupWithPath() {
115115
try {
116-
SymbolLookup.libraryLookup(Path.of("/foo/bar/libFoo.so"), Arena.ofAuto());
116+
SymbolLookup.libraryLookup(FileCheckActions.readDir().resolve("libFoo.so"), Arena.ofAuto());
117117
} catch (IllegalArgumentException e) {
118118
// IllegalArgumentException is thrown if path does not point to a valid library (and it does not)
119119
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.elasticsearch.entitlement.instrumentation.MethodKey;
1919
import org.elasticsearch.entitlement.instrumentation.Transformer;
2020
import org.elasticsearch.entitlement.runtime.api.ElasticsearchEntitlementChecker;
21+
import org.elasticsearch.entitlement.runtime.policy.PathLookup;
2122
import org.elasticsearch.entitlement.runtime.policy.Policy;
2223
import org.elasticsearch.entitlement.runtime.policy.PolicyManager;
2324
import org.elasticsearch.entitlement.runtime.policy.Scope;
@@ -48,7 +49,6 @@
4849
import java.nio.file.attribute.FileAttribute;
4950
import java.nio.file.spi.FileSystemProvider;
5051
import java.util.ArrayList;
51-
import java.util.Arrays;
5252
import java.util.HashMap;
5353
import java.util.List;
5454
import java.util.Map;
@@ -126,9 +126,9 @@ private static Class<?>[] findClassesToRetransform(Class<?>[] loadedClasses, Set
126126
}
127127

128128
private static PolicyManager createPolicyManager() {
129-
Map<String, Policy> pluginPolicies = EntitlementBootstrap.bootstrapArgs().pluginPolicies();
130-
Path[] dataDirs = EntitlementBootstrap.bootstrapArgs().dataDirs();
131-
Path tempDir = EntitlementBootstrap.bootstrapArgs().tempDir();
129+
EntitlementBootstrap.BootstrapArgs bootstrapArgs = EntitlementBootstrap.bootstrapArgs();
130+
Map<String, Policy> pluginPolicies = bootstrapArgs.pluginPolicies();
131+
var pathLookup = new PathLookup(bootstrapArgs.configDir(), bootstrapArgs.dataDirs(), bootstrapArgs.tempDir());
132132
Path logsDir = EntitlementBootstrap.bootstrapArgs().logsDir();
133133

134134
// TODO(ES-10031): Decide what goes in the elasticsearch default policy and extend it
@@ -149,8 +149,8 @@ private static PolicyManager createPolicyManager() {
149149
new ManageThreadsEntitlement(),
150150
new FilesEntitlement(
151151
List.of(
152-
new FilesEntitlement.FileData(tempDir.toString(), READ_WRITE),
153-
new FilesEntitlement.FileData(logsDir.toString(), READ_WRITE)
152+
FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().tempDir(), READ_WRITE),
153+
FilesEntitlement.FileData.ofPath(EntitlementBootstrap.bootstrapArgs().logsDir(), READ_WRITE)
154154
)
155155
)
156156
)
@@ -163,7 +163,7 @@ private static PolicyManager createPolicyManager() {
163163
"org.elasticsearch.nativeaccess",
164164
List.of(
165165
new LoadNativeLibrariesEntitlement(),
166-
new FilesEntitlement(Arrays.stream(dataDirs).map(d -> new FileData(d.toString(), READ_WRITE)).toList())
166+
new FilesEntitlement(List.of(FileData.ofRelativePath(Path.of(""), FilesEntitlement.BaseDir.DATA, READ_WRITE)))
167167
)
168168
)
169169
)
@@ -179,7 +179,7 @@ private static PolicyManager createPolicyManager() {
179179
resolver,
180180
AGENTS_PACKAGE_NAME,
181181
ENTITLEMENTS_MODULE,
182-
tempDir
182+
pathLookup
183183
);
184184
}
185185

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/api/ElasticsearchEntitlementChecker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
836836

837837
@Override
838838
public void check$java_lang_Runtime$load(Class<?> callerClass, Runtime that, String filename) {
839-
// TODO: check filesystem entitlement READ
839+
policyManager.checkFileRead(callerClass, Path.of(filename));
840840
policyManager.checkLoadingNativeLibraries(callerClass);
841841
}
842842

@@ -847,7 +847,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
847847

848848
@Override
849849
public void check$java_lang_System$$load(Class<?> callerClass, String filename) {
850-
// TODO: check filesystem entitlement READ
850+
policyManager.checkFileRead(callerClass, Path.of(filename));
851851
policyManager.checkLoadingNativeLibraries(callerClass);
852852
}
853853

@@ -931,7 +931,7 @@ public void checkSelectorProviderInheritedChannel(Class<?> callerClass, Selector
931931

932932
@Override
933933
public void check$java_lang_foreign_SymbolLookup$$libraryLookup(Class<?> callerClass, Path path, Arena arena) {
934-
// TODO: check filesystem entitlement READ
934+
policyManager.checkFileRead(callerClass, path);
935935
policyManager.checkLoadingNativeLibraries(callerClass);
936936
}
937937

0 commit comments

Comments
 (0)