Skip to content

Commit ea55cbf

Browse files
Merge remote-tracking branch 'upstream/main' into searchonly-2
2 parents 0cb7a3e + ca03fdd commit ea55cbf

File tree

56 files changed

+231
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+231
-302
lines changed

libs/agent-sm/agent/src/main/java/org/opensearch/javaagent/FileInterceptor.java

+30-8
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,27 @@ public static void intercept(@Advice.AllArguments Object[] args, @Advice.Origin
6161
final Collection<ProtectionDomain> callers = walker.walk(StackCallerProtectionDomainChainExtractor.INSTANCE);
6262

6363
final String name = method.getName();
64-
boolean isMutating = name.equals("copy") || name.equals("move") || name.equals("write") || name.startsWith("create");
64+
boolean isMutating = name.equals("move") || name.equals("write") || name.startsWith("create");
6565
final boolean isDelete = isMutating == false ? name.startsWith("delete") : false;
6666

67-
if (isMutating == false && isDelete == false && name.equals("newByteChannel") == true) {
68-
if (args.length > 1 && args[1] instanceof OpenOption[] opts) {
69-
for (final OpenOption opt : opts) {
70-
if (opt != StandardOpenOption.READ) {
71-
isMutating = true;
72-
break;
67+
String targetFilePath = null;
68+
if (isMutating == false && isDelete == false) {
69+
if (name.equals("newByteChannel") == true) {
70+
if (args.length > 1 && args[1] instanceof OpenOption[] opts) {
71+
for (final OpenOption opt : opts) {
72+
if (opt != StandardOpenOption.READ) {
73+
isMutating = true;
74+
break;
75+
}
7376
}
74-
}
7577

78+
}
79+
} else if (name.equals("copy") == true) {
80+
if (args.length > 1 && args[1] instanceof String pathStr) {
81+
targetFilePath = Paths.get(pathStr).toAbsolutePath().toString();
82+
} else if (args.length > 1 && args[1] instanceof Path path) {
83+
targetFilePath = path.toAbsolutePath().toString();
84+
}
7685
}
7786
}
7887

@@ -85,6 +94,19 @@ public static void intercept(@Advice.AllArguments Object[] args, @Advice.Origin
8594
}
8695
}
8796

97+
// Handle Files.copy() separately to check read/write permissions properly
98+
if (method.getName().equals("copy")) {
99+
if (!policy.implies(domain, new FilePermission(filePath, "read"))) {
100+
throw new SecurityException("Denied OPEN access to file: " + filePath + ", domain: " + domain);
101+
}
102+
103+
if (targetFilePath != null) {
104+
if (!policy.implies(domain, new FilePermission(targetFilePath, "write"))) {
105+
throw new SecurityException("Denied OPEN access to file: " + targetFilePath + ", domain: " + domain);
106+
}
107+
}
108+
}
109+
88110
// File mutating operations
89111
if (isMutating && !policy.implies(domain, new FilePermission(filePath, "write"))) {
90112
throw new SecurityException("Denied WRITE access to file: " + filePath + ", domain: " + domain);

libs/agent-sm/agent/src/test/java/org/opensearch/javaagent/FileInterceptorIntegTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import static org.junit.Assert.assertEquals;
3131
import static org.junit.Assert.assertFalse;
32+
import static org.junit.Assert.assertThrows;
3233
import static org.junit.Assert.assertTrue;
3334

3435
@SuppressWarnings("removal")
@@ -144,6 +145,10 @@ public void testCopy() throws Exception {
144145

145146
// Test copy operation
146147
Files.copy(sourcePath, targetPath);
148+
assertThrows(
149+
SecurityException.class,
150+
() -> Files.copy(sourcePath, tmpDir.getRoot().resolve("test-target-" + randomAlphaOfLength(8) + ".txt"))
151+
);
147152

148153
// Verify copy
149154
assertTrue("Target file should exist", Files.exists(targetPath));

modules/geo/src/yamlRestTest/resources/rest-api-spec/test/geo_shape/290_geotile_grid.yml

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
setup:
2-
- skip:
3-
version: " - 6.99.99"
4-
reason: "added in 7.0.0"
52
- do:
63
indices.create:
74
index: test_1

qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/20_date_range.yml

-80
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,3 @@
1-
---
2-
"Create index with joda style index that is incompatible with java.time. (6.0)":
3-
- skip:
4-
features: "allowed_warnings"
5-
version: "6.8.1 -"
6-
reason: change of warning message
7-
- do:
8-
allowed_warnings:
9-
- "Use of 'Y' (year-of-era) will change to 'y' in the next major version of OpenSearch. Prefix your date format with '8' to use the new specifier."
10-
indices.create:
11-
index: joda_for_range
12-
body:
13-
settings:
14-
index:
15-
number_of_replicas: 2
16-
mappings:
17-
"properties":
18-
"time_frame":
19-
"type": "date_range"
20-
"format": "YYYY-MM-dd'T'HH:mmZZ"
21-
22-
- do:
23-
bulk:
24-
refresh: true
25-
body:
26-
- '{"index": {"_index": "joda_for_range"}}'
27-
- '{"time_frame": {"gte": "2019-01-01T00:00+01:00", "lte" : "2019-03-01T00:00+01:00"}}'
28-
29-
- do:
30-
search:
31-
rest_total_hits_as_int: true
32-
index: joda_for_range
33-
body:
34-
query:
35-
range:
36-
time_frame:
37-
gte: "2019-02-01T00:00+01:00"
38-
lte: "2019-02-01T00:00+01:00"
39-
- match: { hits.total: 1 }
40-
41-
---
42-
"Create index with joda style index that is incompatible with java.time (>6.1)":
43-
- skip:
44-
features: "allowed_warnings"
45-
version: " - 6.8.0, 7.0.0 -"
46-
reason: change of warning message, we skip 7 becase this format will be considered java
47-
- do:
48-
allowed_warnings:
49-
- "'Y' year-of-era should be replaced with 'y'. Use 'Y' for week-based-year.; 'Z' time zone offset/id fails when parsing 'Z' for Zulu timezone. Consider using 'X'. Prefix your date format with '8' to use the new specifier."
50-
indices.create:
51-
index: joda_for_range
52-
body:
53-
settings:
54-
index:
55-
number_of_replicas: 2
56-
mappings:
57-
"properties":
58-
"time_frame":
59-
"type": "date_range"
60-
"format": "YYYY-MM-dd'T'HH:mmZZ"
61-
62-
- do:
63-
bulk:
64-
refresh: true
65-
body:
66-
- '{"index": {"_index": "joda_for_range"}}'
67-
- '{"time_frame": {"gte": "2019-01-01T00:00+01:00", "lte" : "2019-03-01T00:00+01:00"}}'
68-
69-
- do:
70-
search:
71-
rest_total_hits_as_int: true
72-
index: joda_for_range
73-
body:
74-
query:
75-
range:
76-
time_frame:
77-
gte: "2019-02-01T00:00+01:00"
78-
lte: "2019-02-01T00:00+01:00"
79-
- match: { hits.total: 1 }
80-
811
---
822
"Create index with java style index in 6":
833
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/cat.thread_pool/10_basic.yml

-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
5555
---
5656
"Test cat thread_pool output":
57-
- skip:
58-
version: " - 6.99.99"
59-
reason: this API was changed in a backwards-incompatible fashion in 7.0.0 so we need to skip in a mixed cluster
6057

6158
- do:
6259
cat.thread_pool: {}

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.state/10_basic.yml

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
---
99
"get cluster state returns cluster_uuid at the top level":
10-
- skip:
11-
version: " - 6.3.99"
12-
reason: "cluster state including cluster_uuid at the top level is new in v6.4.0 and higher"
13-
1410
- do:
1511
cluster.state:
1612
human: true

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.state/20_filtering.yml

-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ setup:
156156
---
157157
"Filtering the cluster state returns cluster_uuid at the top level regardless of metric filters":
158158
- skip:
159-
version: " - 6.3.99"
160-
reason: "cluster state including cluster_uuid at the top level is new in v6.4.0 and higher"
161159
features: allowed_warnings
162160

163161
# Get the current cluster_uuid

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.voting_config_exclusions/10_basic.yml

-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ teardown:
44

55
---
66
"Get cluster state without voting config exclusions":
7-
- skip:
8-
version: " - 6.99.99"
9-
reason: Voting config exclusions were introduced in 7.0.0
10-
117
- do:
128
cluster.state: {}
139

rest-api-spec/src/main/resources/rest-api-spec/test/create/10_with_id.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
"Create with ID":
3-
- skip:
4-
version: " - 6.99.99"
5-
reason: types are required in requests before 7.0.0
3+
64
- do:
75
create:
86
index: test_1

rest-api-spec/src/main/resources/rest-api-spec/test/create/15_without_id.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
"Create without ID":
3-
- skip:
4-
version: " - 6.99.99"
5-
reason: types are required in requests before 7.0.0
3+
64
- do:
75
catch: param
86
create:

rest-api-spec/src/main/resources/rest-api-spec/test/create/35_external_version.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
"External version":
3-
- skip:
4-
version: " - 6.99.99"
5-
reason: types are required in requests before 7.0.0
3+
64
- do:
75
catch: bad_request
86
create:

rest-api-spec/src/main/resources/rest-api-spec/test/create/40_routing.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
"Routing":
3-
- skip:
4-
version: " - 6.99.99"
5-
reason: types are required in requests before 7.0.0
3+
64
- do:
75
indices.create:
86
index: test_1

rest-api-spec/src/main/resources/rest-api-spec/test/create/60_refresh.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
"Refresh":
3-
- skip:
4-
version: " - 6.99.99"
5-
reason: types are required in requests before 7.0.0
3+
64
- do:
75
indices.create:
86
index: test_1
@@ -44,9 +42,7 @@
4442

4543
---
4644
"When refresh url parameter is an empty string that means \"refresh immediately\"":
47-
- skip:
48-
version: " - 6.99.99"
49-
reason: types are required in requests before 7.0.0
45+
5046
- do:
5147
create:
5248
index: test_1
@@ -66,9 +62,7 @@
6662

6763
---
6864
"refresh=wait_for waits until changes are visible in search":
69-
- skip:
70-
version: " - 6.99.99"
71-
reason: types are required in requests before 7.0.0
65+
7266
- do:
7367
index:
7468
index: create_60_refresh_1

rest-api-spec/src/main/resources/rest-api-spec/test/delete/10_basic.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
"Basic":
33

4-
- skip:
5-
version: " - 6.99.99"
6-
reason: types are required in requests before 7.0.0
7-
84
- do:
95
index:
106
index: test_1

rest-api-spec/src/main/resources/rest-api-spec/test/delete/11_shard_header.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
"Delete check shard header":
33

4-
- skip:
5-
version: " - 6.99.99"
6-
reason: types are required in requests before 7.0.0
7-
84
- do:
95
indices.create:
106
index: foobar

rest-api-spec/src/main/resources/rest-api-spec/test/delete/12_result.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
"Delete result field":
33

4-
- skip:
5-
version: " - 6.99.99"
6-
reason: types are required in requests before 7.0.0
7-
84
- do:
95
index:
106
index: test_1

rest-api-spec/src/main/resources/rest-api-spec/test/delete/20_cas.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
"Internal version":
33

4-
- skip:
5-
version: " - 6.99.99"
6-
reason: types are required in requests before 7.0.0
7-
84
- do:
95
index:
106
index: test_1

rest-api-spec/src/main/resources/rest-api-spec/test/delete/25_external_version.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
"External version":
33

4-
- skip:
5-
version: " - 6.99.99"
6-
reason: types are required in requests before 7.0.0
7-
84
- do:
95
index:
106
index: test_1

rest-api-spec/src/main/resources/rest-api-spec/test/delete/26_external_gte_version.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
"External GTE version":
33

4-
- skip:
5-
version: " - 6.99.99"
6-
reason: types are required in requests before 7.0.0
7-
84
- do:
95
index:
106
index: test_1

rest-api-spec/src/main/resources/rest-api-spec/test/delete/30_routing.yml

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
"Routing":
33

4-
- skip:
5-
version: " - 6.99.99"
6-
reason: types are required in requests before 7.0.0
7-
84
- do:
95
indices.create:
106
index: test_1

rest-api-spec/src/main/resources/rest-api-spec/test/delete/50_refresh.yml

-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
"Refresh":
33

4-
- skip:
5-
version: " - 6.99.99"
6-
reason: types are required in requests before 7.0.0
7-
84
- do:
95
indices.create:
106
index: test_1
@@ -81,10 +77,6 @@
8177
---
8278
"When refresh url parameter is an empty string that means \"refresh immediately\"":
8379

84-
- skip:
85-
version: " - 6.99.99"
86-
reason: types are required in requests before 7.0.0
87-
8880
- do:
8981
index:
9082
index: test_1
@@ -118,10 +110,6 @@
118110
---
119111
"refresh=wait_for waits until changes are visible in search":
120112

121-
- skip:
122-
version: " - 6.99.99"
123-
reason: types are required in requests before 7.0.0
124-
125113
- do:
126114
index:
127115
index: delete_50_refresh_1

0 commit comments

Comments
 (0)