Skip to content

Commit 9a5a3c7

Browse files
authored
Merge branch '9.0' into backport/9.0/pr-121887
2 parents 964ae12 + 31cad16 commit 9a5a3c7

File tree

7 files changed

+45
-6
lines changed

7 files changed

+45
-6
lines changed

docs/changelog/132018.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 132018
2+
summary: Fix decoding of non-ascii field names in ignored source
3+
area: Mapping
4+
type: bug
5+
issues: []

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ private static List<Scope> createServerEntitlements(Path pidFile) {
9292
new CreateClassLoaderEntitlement(),
9393
new FilesEntitlement(
9494
List.of(
95-
// TODO: what in es.base is accessing shared repo?
95+
// necessary due to lack of delegation ES-12382
9696
FilesEntitlement.FileData.ofBaseDirPath(SHARED_REPO, READ_WRITE),
97+
FilesEntitlement.FileData.ofBaseDirPath(SHARED_DATA, READ_WRITE),
9798
FilesEntitlement.FileData.ofBaseDirPath(DATA, READ_WRITE)
9899
)
99100
)
@@ -122,6 +123,7 @@ private static List<Scope> createServerEntitlements(Path pidFile) {
122123
new FilesEntitlement(
123124
List.of(
124125
FilesEntitlement.FileData.ofBaseDirPath(CONFIG, READ),
126+
FilesEntitlement.FileData.ofBaseDirPath(SHARED_DATA, READ_WRITE),
125127
FilesEntitlement.FileData.ofBaseDirPath(DATA, READ_WRITE)
126128
)
127129
)
@@ -130,7 +132,12 @@ private static List<Scope> createServerEntitlements(Path pidFile) {
130132
new Scope(
131133
"org.apache.lucene.misc",
132134
List.of(
133-
new FilesEntitlement(List.of(FilesEntitlement.FileData.ofBaseDirPath(DATA, READ_WRITE))),
135+
new FilesEntitlement(
136+
List.of(
137+
FilesEntitlement.FileData.ofBaseDirPath(SHARED_DATA, READ_WRITE),
138+
FilesEntitlement.FileData.ofBaseDirPath(DATA, READ_WRITE)
139+
)
140+
),
134141
new ReadStoreAttributesEntitlement()
135142
)
136143
),
@@ -145,7 +152,12 @@ private static List<Scope> createServerEntitlements(Path pidFile) {
145152
"org.elasticsearch.nativeaccess",
146153
List.of(
147154
new LoadNativeLibrariesEntitlement(),
148-
new FilesEntitlement(List.of(FilesEntitlement.FileData.ofBaseDirPath(DATA, READ_WRITE)))
155+
new FilesEntitlement(
156+
List.of(
157+
FilesEntitlement.FileData.ofBaseDirPath(SHARED_DATA, READ_WRITE),
158+
FilesEntitlement.FileData.ofBaseDirPath(DATA, READ_WRITE)
159+
)
160+
)
149161
)
150162
)
151163
);

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/entitlements/FilesEntitlement.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ private static BaseDir parseBaseDir(String baseDir) {
182182
case "config" -> BaseDir.CONFIG;
183183
case "data" -> BaseDir.DATA;
184184
case "home" -> BaseDir.USER_HOME;
185+
case "shared_data" -> BaseDir.SHARED_DATA;
185186
// it would be nice to limit this to just ES modules, but we don't have a way to plumb that through to here
186-
// however, we still don't document in the error case below that shared_repo is valid
187+
// however, we still don't document in the error case below that shared_repo and shared_data is valid
187188
case "shared_repo" -> BaseDir.SHARED_REPO;
188189
default -> throw new PolicyValidationException(
189190
"invalid relative directory: " + baseDir + ", valid values: [config, data, home]"

plugins/store-smb/src/main/plugin-metadata/entitlement-policy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ ALL-UNNAMED:
33
- relative_path: "indices/"
44
relative_to: data
55
mode: read_write
6+
- relative_path: ""
7+
relative_to: shared_data
8+
mode: read_write

server/src/main/java/org/elasticsearch/index/mapper/IgnoredSourceFieldMapper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ static NameValue decode(Object field) {
181181
int encodedSize = ByteUtils.readIntLE(bytes, 0);
182182
int nameSize = encodedSize % PARENT_OFFSET_IN_NAME_OFFSET;
183183
int parentOffset = encodedSize / PARENT_OFFSET_IN_NAME_OFFSET;
184-
String name = new String(bytes, 4, nameSize, StandardCharsets.UTF_8);
185-
BytesRef value = new BytesRef(bytes, 4 + nameSize, bytes.length - nameSize - 4);
184+
185+
String decoded = new String(bytes, 4, bytes.length - 4, StandardCharsets.UTF_8);
186+
String name = decoded.substring(0, nameSize);
187+
int nameByteCount = name.getBytes(StandardCharsets.UTF_8).length;
188+
189+
BytesRef value = new BytesRef(bytes, 4 + nameByteCount, bytes.length - nameByteCount - 4);
186190
return new NameValue(name, parentOffset, value, null);
187191
}
188192

server/src/test/java/org/elasticsearch/index/mapper/IgnoredSourceFieldMapperTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
package org.elasticsearch.index.mapper;
1111

1212
import org.apache.lucene.index.DirectoryReader;
13+
import org.elasticsearch.common.Strings;
1314
import org.elasticsearch.common.settings.Settings;
1415
import org.elasticsearch.core.CheckedConsumer;
1516
import org.elasticsearch.core.Nullable;
1617
import org.elasticsearch.search.lookup.SourceFilter;
1718
import org.elasticsearch.test.FieldMaskingReader;
1819
import org.elasticsearch.xcontent.XContentBuilder;
20+
import org.elasticsearch.xcontent.json.JsonXContent;
1921
import org.hamcrest.Matchers;
2022

2123
import java.io.IOException;
@@ -122,6 +124,15 @@ public void testIgnoredString() throws IOException {
122124
);
123125
}
124126

127+
public void testIgnoredStringFullUnicode() throws IOException {
128+
String value = randomUnicodeOfCodepointLengthBetween(5, 20);
129+
String fieldName = randomUnicodeOfCodepointLength(5);
130+
131+
String expected = Strings.toString(JsonXContent.contentBuilder().startObject().field(fieldName, value).endObject());
132+
133+
assertEquals(expected, getSyntheticSourceWithFieldLimit(b -> b.field(fieldName, value)));
134+
}
135+
125136
public void testIgnoredInt() throws IOException {
126137
int value = randomInt();
127138
assertEquals("{\"my_value\":" + value + "}", getSyntheticSourceWithFieldLimit(b -> b.field("my_value", value)));

x-pack/plugin/searchable-snapshots/src/main/plugin-metadata/entitlement-policy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ org.elasticsearch.searchablesnapshots:
66
- relative_path: indices
77
relative_to: data
88
mode: read_write
9+
- relative_path: ""
10+
relative_to: shared_data
11+
mode: read_write

0 commit comments

Comments
 (0)