Skip to content

Commit 00c22c7

Browse files
committed
Merge branch 'main' into access-controller
2 parents 44eb148 + 3a4f749 commit 00c22c7

File tree

35 files changed

+763
-159
lines changed

35 files changed

+763
-159
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2828
- Use QueryCoordinatorContext for the rewrite in validate API. ([#18272](https://github.com/opensearch-project/OpenSearch/pull/18272))
2929
- Upgrade crypto kms plugin dependencies for AWS SDK v2.x. ([#18268](https://github.com/opensearch-project/OpenSearch/pull/18268))
3030
- Add support for `matched_fields` with the unified highlighter ([#18164](https://github.com/opensearch-project/OpenSearch/issues/18164))
31+
- [repository-s3] Add support for SSE-KMS and S3 bucket owner verification ([#18312](https://github.com/opensearch-project/OpenSearch/pull/18312))
3132
- Create equivalents of JSM's AccessController in the java agent ([#18346](https://github.com/opensearch-project/OpenSearch/issues/18346))
3233

3334
### Changed
@@ -54,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5455
### Deprecated
5556

5657
### Removed
58+
- [repository-s3] Removed existing ineffective `server_side_encryption` setting ([#18312](https://github.com/opensearch-project/OpenSearch/pull/18312))
5759

5860
### Fixed
5961
- Fix simultaneously creating a snapshot and updating the repository can potentially trigger an infinite loop ([#17532](https://github.com/opensearch-project/OpenSearch/pull/17532))
@@ -64,6 +66,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6466
- Null check field names in QueryStringQueryBuilder ([#18194](https://github.com/opensearch-project/OpenSearch/pull/18194))
6567
- Avoid NPE if on SnapshotInfo if 'shallow' boolean not present ([#18187](https://github.com/opensearch-project/OpenSearch/issues/18187))
6668
- Fix 'system call filter not installed' caused when network.host: 0.0.0.0 ([#18309](https://github.com/opensearch-project/OpenSearch/pull/18309))
69+
- Fix MatrixStatsAggregator reuse when mode parameter changes ([#18242](https://github.com/opensearch-project/OpenSearch/issues/18242))
6770

6871
### Security
6972

MAINTAINERS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
2626
| Owais Kazi | [owaiskazi19](https://github.com/owaiskazi19) | Amazon |
2727
| Pan Guixin | [bugmakerrrrrr](https://github.com/bugmakerrrrrr) | ByteDance |
2828
| Peter Nied | [peternied](https://github.com/peternied) | Amazon |
29+
| Rishabh Maurya | [rishabhmaurya](https://github.com/rishabhmaurya) | Amazon |
2930
| Rishikesh Pasham | [Rishikesh1159](https://github.com/Rishikesh1159) | Amazon |
3031
| Sachin Kale | [sachinpkale](https://github.com/sachinpkale) | Amazon |
3132
| Sarat Vemulapalli | [saratvemulapalli](https://github.com/saratvemulapalli) | Amazon |

distribution/tools/plugin-cli/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ base {
3737
dependencies {
3838
compileOnly project(":server")
3939
compileOnly project(":libs:opensearch-cli")
40+
api project(":libs:agent-sm:agent-policy")
4041
api "org.bouncycastle:bc-fips:${versions.bouncycastle_jce}"
4142
api "org.bouncycastle:bcpg-fips:${versions.bouncycastle_pg}"
4243
testImplementation project(":test:framework")

distribution/tools/plugin-cli/src/main/java/org/opensearch/tools/cli/plugin/PluginSecurity.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@
3737
import org.opensearch.cli.Terminal.Verbosity;
3838
import org.opensearch.cli.UserException;
3939
import org.opensearch.common.util.io.IOUtils;
40+
import org.opensearch.secure_sm.policy.PolicyFile;
4041

4142
import java.io.IOException;
4243
import java.nio.file.Files;
4344
import java.nio.file.Path;
44-
import java.security.NoSuchAlgorithmException;
4545
import java.security.Permission;
4646
import java.security.PermissionCollection;
4747
import java.security.Permissions;
4848
import java.security.Policy;
49-
import java.security.URIParameter;
5049
import java.security.UnresolvedPermission;
5150
import java.util.ArrayList;
5251
import java.util.Collections;
@@ -143,22 +142,12 @@ static Set<String> parsePermissions(Path file, Path tmpDir) throws IOException {
143142
// 2. read permission to the code itself (e.g. jar file of the code)
144143

145144
Path emptyPolicyFile = Files.createTempFile(tmpDir, "empty", "tmp");
146-
final Policy emptyPolicy;
147-
try {
148-
emptyPolicy = Policy.getInstance("JavaPolicy", new URIParameter(emptyPolicyFile.toUri()));
149-
} catch (NoSuchAlgorithmException e) {
150-
throw new RuntimeException(e);
151-
}
145+
final Policy emptyPolicy = new PolicyFile(emptyPolicyFile.toUri().toURL());
152146
IOUtils.rm(emptyPolicyFile);
153147

154148
// parse the plugin's policy file into a set of permissions
155-
final Policy policy;
156-
try {
157-
policy = Policy.getInstance("JavaPolicy", new URIParameter(file.toUri()));
158-
} catch (NoSuchAlgorithmException e) {
159-
throw new RuntimeException(e);
160-
}
161-
PermissionCollection permissions = policy.getPermissions(PluginSecurity.class.getProtectionDomain());
149+
final Policy policy = new PolicyFile(file.toUri().toURL());
150+
final PermissionCollection permissions = policy.getPermissions(PluginSecurity.class.getProtectionDomain());
162151
// this method is supported with the specific implementation we use, but just check for safety.
163152
if (permissions == Policy.UNSUPPORTED_EMPTY_COLLECTION) {
164153
throw new UnsupportedOperationException("JavaPolicy implementation does not support retrieving permissions");

gradle/code-coverage.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repositories {
1919

2020
allprojects {
2121
plugins.withId('jacoco') {
22-
jacoco.toolVersion = '0.8.12'
22+
jacoco.toolVersion = '0.8.13'
2323
}
2424
}
2525

libs/agent-sm/agent-policy/src/main/java/org/opensearch/secure_sm/policy/PolicyFile.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,32 @@ private void addGrantEntry(GrantEntry grantEntry, List<PolicyEntry> entries) thr
125125
entries.add(new PolicyEntry(codesource, permissions));
126126
}
127127

128+
/**
129+
* Expands known system properties like ${java.home} and ${user.home} to their absolute
130+
* path equivalents.
131+
*/
132+
private static String expandKnownSystemProperty(final String property, final String value) {
133+
final int index = value.indexOf("${" + property + "}/");
134+
final String path = System.getProperty(property);
135+
if (path.endsWith(File.pathSeparator)) {
136+
return path + value.substring(index + property.length() + 4 /* replace the path separator */);
137+
} else {
138+
return path + value.substring(index + property.length() + 3 /* keep the path separator */);
139+
}
140+
}
141+
128142
private static PermissionEntry expandPermissionName(PermissionEntry pe) {
129-
if (pe.name() == null || !pe.name().contains("${{")) {
143+
if (pe.name() == null) {
144+
return pe;
145+
}
146+
147+
if (pe.name().startsWith("${java.home}")) {
148+
return new PermissionEntry(pe.permission(), expandKnownSystemProperty("java.home", pe.name()), pe.action());
149+
} else if (pe.name().startsWith("${user.home}")) {
150+
return new PermissionEntry(pe.permission(), expandKnownSystemProperty("user.home", pe.name()), pe.action());
151+
}
152+
153+
if (!pe.name().contains("${{")) {
130154
return pe;
131155
}
132156

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.file.Files;
2323
import java.nio.file.Path;
2424
import java.nio.file.StandardOpenOption;
25+
import java.security.Permission;
2526
import java.security.PermissionCollection;
2627
import java.security.Permissions;
2728
import java.security.Policy;
@@ -56,6 +57,17 @@ public PermissionCollection getPermissions(ProtectionDomain domain) {
5657
permissions.add(new FilePermission(System.getProperty("user.dir") + "/-", "read,write,delete"));
5758
return permissions;
5859
}
60+
61+
@Override
62+
public boolean implies(ProtectionDomain domain, Permission permission) {
63+
final PermissionCollection pc = getPermissions(domain);
64+
65+
if (pc == null) {
66+
return false;
67+
}
68+
69+
return pc.implies(permission);
70+
}
5971
};
6072
AgentPolicy.setPolicy(policy);
6173
Files.createDirectories(getTestDir());

modules/aggs-matrix-stats/src/main/java/org/opensearch/search/aggregations/matrix/stats/MatrixStatsAggregationBuilder.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
package org.opensearch.search.aggregations.matrix.stats;
3333

34+
import org.opensearch.Version;
3435
import org.opensearch.core.common.io.stream.StreamInput;
3536
import org.opensearch.core.common.io.stream.StreamOutput;
3637
import org.opensearch.core.xcontent.ToXContent;
@@ -45,6 +46,7 @@
4546

4647
import java.io.IOException;
4748
import java.util.Map;
49+
import java.util.Objects;
4850

4951
public class MatrixStatsAggregationBuilder extends ArrayValuesSourceAggregationBuilder.LeafOnly<MatrixStatsAggregationBuilder> {
5052
public static final String NAME = "matrix_stats";
@@ -74,11 +76,18 @@ protected AggregationBuilder shallowCopy(AggregatorFactories.Builder factoriesBu
7476
*/
7577
public MatrixStatsAggregationBuilder(StreamInput in) throws IOException {
7678
super(in);
79+
if (in.getVersion().onOrAfter(Version.V_3_1_0)) {
80+
this.multiValueMode = in.readEnum(MultiValueMode.class);
81+
} else {
82+
this.multiValueMode = MultiValueMode.AVG;
83+
}
7784
}
7885

7986
@Override
80-
protected void innerWriteTo(StreamOutput out) {
81-
// Do nothing, no extra state to write to stream
87+
protected void innerWriteTo(StreamOutput out) throws IOException {
88+
if (out.getVersion().onOrAfter(Version.V_3_1_0)) {
89+
out.writeEnum(multiValueMode);
90+
}
8291
}
8392

8493
public MatrixStatsAggregationBuilder multiValueMode(MultiValueMode multiValueMode) {
@@ -110,4 +119,18 @@ public XContentBuilder doXContentBody(XContentBuilder builder, ToXContent.Params
110119
public String getType() {
111120
return NAME;
112121
}
122+
123+
@Override
124+
public boolean equals(Object obj) {
125+
if (this == obj) return true;
126+
if (obj == null || getClass() != obj.getClass()) return false;
127+
if (super.equals(obj) == false) return false;
128+
MatrixStatsAggregationBuilder other = (MatrixStatsAggregationBuilder) obj;
129+
return multiValueMode == other.multiValueMode;
130+
}
131+
132+
@Override
133+
public int hashCode() {
134+
return Objects.hash(super.hashCode(), multiValueMode);
135+
}
113136
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.search.aggregations.matrix;
10+
11+
import org.opensearch.cluster.metadata.IndexMetadata;
12+
import org.opensearch.common.settings.Settings;
13+
import org.opensearch.index.IndexSettings;
14+
import org.opensearch.index.cache.request.RequestCacheStats;
15+
import org.opensearch.indices.IndicesRequestCache;
16+
import org.opensearch.search.MultiValueMode;
17+
import org.opensearch.search.aggregations.matrix.stats.MatrixStatsAggregationBuilder;
18+
import org.opensearch.test.OpenSearchIntegTestCase;
19+
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;
20+
import org.opensearch.transport.client.Client;
21+
22+
import java.util.List;
23+
24+
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
25+
26+
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, supportsDedicatedMasters = false)
27+
public class MatrixStatsIT extends ParameterizedStaticSettingsOpenSearchIntegTestCase {
28+
public MatrixStatsIT(Settings nodeSettings) {
29+
super(nodeSettings);
30+
}
31+
32+
public void testMatrixStatsMultiValueModeEffect() throws Exception {
33+
String index = "test_matrix_stats_multimode";
34+
Client client = client();
35+
36+
assertAcked(
37+
client.admin()
38+
.indices()
39+
.prepareCreate(index)
40+
.setSettings(
41+
Settings.builder()
42+
.put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), -1)
43+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
44+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
45+
.put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true)
46+
)
47+
.get()
48+
);
49+
50+
client.prepareIndex(index).setId("1").setSource("num", List.of(10, 30), "num2", List.of(40, 60)).setWaitForActiveShards(1).get();
51+
client.admin().indices().prepareRefresh(index).get();
52+
53+
MatrixStatsAggregationBuilder avgAgg = new MatrixStatsAggregationBuilder("agg_avg").fields(List.of("num", "num2"))
54+
.multiValueMode(MultiValueMode.AVG);
55+
56+
client.prepareSearch(index).setSize(0).setRequestCache(true).addAggregation(avgAgg).get();
57+
58+
RequestCacheStats stats1 = getRequestCacheStats(client, index);
59+
long hit1 = stats1.getHitCount();
60+
long miss1 = stats1.getMissCount();
61+
62+
client.prepareSearch(index).setSize(0).setRequestCache(true).addAggregation(avgAgg).get();
63+
64+
RequestCacheStats stats2 = getRequestCacheStats(client, index);
65+
long hit2 = stats2.getHitCount();
66+
long miss2 = stats2.getMissCount();
67+
68+
MatrixStatsAggregationBuilder minAgg = new MatrixStatsAggregationBuilder("agg_min").fields(List.of("num", "num2"))
69+
.multiValueMode(MultiValueMode.MIN);
70+
71+
client.prepareSearch(index).setSize(0).setRequestCache(true).addAggregation(minAgg).get();
72+
73+
RequestCacheStats stats3 = getRequestCacheStats(client, index);
74+
long hit3 = stats3.getHitCount();
75+
long miss3 = stats3.getMissCount();
76+
77+
client.prepareSearch(index).setSize(0).setRequestCache(true).addAggregation(minAgg).get();
78+
79+
RequestCacheStats stats4 = getRequestCacheStats(client, index);
80+
long hit4 = stats4.getHitCount();
81+
long miss4 = stats4.getMissCount();
82+
83+
assertEquals("Expected 1 cache miss for first AVG request", 1, miss1);
84+
assertEquals("Expected 1 cache hit for second AVG request", hit1 + 1, hit2);
85+
assertEquals("Expected 1 cache miss for first MIN request", miss1 + 1, miss3);
86+
assertEquals("Expected 1 cache hit for second MIN request", hit2 + 1, hit4);
87+
assertEquals("Expected no additional cache misses for second MIN request", miss3, miss4);
88+
}
89+
90+
private static RequestCacheStats getRequestCacheStats(Client client, String index) {
91+
return client.admin().indices().prepareStats(index).setRequestCache(true).get().getTotal().getRequestCache();
92+
}
93+
}

0 commit comments

Comments
 (0)