Skip to content

Commit 2a16f30

Browse files
committed
remove allowExplicitIndex
Signed-off-by: Karen Xu <karenxyr@gmail.com>
1 parent 6d897b8 commit 2a16f30

File tree

8 files changed

+67
-299
lines changed

8 files changed

+67
-299
lines changed

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/GrpcPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public Map<String, Supplier<AuxTransport>> getAuxTransports(
210210

211211
return Collections.singletonMap(GRPC_TRANSPORT_SETTING_KEY, () -> {
212212
List<BindableService> grpcServices = new ArrayList<>(
213-
List.of(new DocumentServiceImpl(client, settings), new SearchServiceImpl(client, queryUtils))
213+
List.of(new DocumentServiceImpl(client), new SearchServiceImpl(client, queryUtils))
214214
);
215215
for (GrpcServiceFactory serviceFac : servicesFactory) {
216216
List<BindableService> pluginServices = serviceFac.initClient(client)
@@ -261,7 +261,7 @@ public Map<String, Supplier<AuxTransport>> getSecureAuxTransports(
261261
}
262262
return Collections.singletonMap(GRPC_SECURE_TRANSPORT_SETTING_KEY, () -> {
263263
List<BindableService> grpcServices = new ArrayList<>(
264-
List.of(new DocumentServiceImpl(client, settings), new SearchServiceImpl(client, queryUtils))
264+
List.of(new DocumentServiceImpl(client), new SearchServiceImpl(client, queryUtils))
265265
);
266266
for (GrpcServiceFactory serviceFac : servicesFactory) {
267267
List<BindableService> pluginServices = serviceFac.initClient(client)

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/document/bulk/BulkRequestParserProtoUtils.java

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ static MediaType detectMediaType(byte[] document) {
107107
* @param defaultFetchSourceContext
108108
* @param defaultPipeline
109109
* @param defaultRequireAlias
110-
* @param allowExplicitIndex whether explicit index specification is allowed (security setting)
111110
* @return
112111
*/
113112
public static DocWriteRequest<?>[] getDocWriteRequests(
@@ -116,8 +115,7 @@ public static DocWriteRequest<?>[] getDocWriteRequests(
116115
String defaultRouting,
117116
FetchSourceContext defaultFetchSourceContext,
118117
String defaultPipeline,
119-
Boolean defaultRequireAlias,
120-
boolean allowExplicitIndex
118+
Boolean defaultRequireAlias
121119
) {
122120
List<BulkRequestBody> bulkRequestBodyList = request.getBulkRequestBodyList();
123121
DocWriteRequest<?>[] docWriteRequests = new DocWriteRequest<?>[bulkRequestBodyList.size()];
@@ -155,9 +153,7 @@ public static DocWriteRequest<?>[] getDocWriteRequests(
155153
pipeline,
156154
ifSeqNo,
157155
ifPrimaryTerm,
158-
requireAlias,
159-
defaultIndex,
160-
allowExplicitIndex
156+
requireAlias
161157
);
162158
break;
163159
case INDEX:
@@ -173,13 +169,11 @@ public static DocWriteRequest<?>[] getDocWriteRequests(
173169
pipeline,
174170
ifSeqNo,
175171
ifPrimaryTerm,
176-
requireAlias,
177-
defaultIndex,
178-
allowExplicitIndex
172+
requireAlias
179173
);
180174
break;
181175
case UPDATE:
182-
// Extract the doc field from UpdateAction (matches REST API structure)
176+
// Extract the doc field from UpdateAction
183177
// Use ByteString directly to avoid unnecessary byte array allocation
184178
ByteString updateDocBytes = ByteString.EMPTY;
185179
if (bulkRequestBodyEntry.hasUpdateAction() && bulkRequestBodyEntry.getUpdateAction().hasDoc()) {
@@ -201,9 +195,7 @@ public static DocWriteRequest<?>[] getDocWriteRequests(
201195
pipeline,
202196
ifSeqNo,
203197
ifPrimaryTerm,
204-
requireAlias,
205-
defaultIndex,
206-
allowExplicitIndex
198+
requireAlias
207199
);
208200
break;
209201
case DELETE:
@@ -215,9 +207,7 @@ public static DocWriteRequest<?>[] getDocWriteRequests(
215207
version,
216208
versionType,
217209
ifSeqNo,
218-
ifPrimaryTerm,
219-
defaultIndex,
220-
allowExplicitIndex
210+
ifPrimaryTerm
221211
);
222212
break;
223213
case OPERATIONCONTAINER_NOT_SET:
@@ -246,8 +236,6 @@ public static DocWriteRequest<?>[] getDocWriteRequests(
246236
* @param ifSeqNo The default sequence number for optimistic concurrency control
247237
* @param ifPrimaryTerm The default primary term for optimistic concurrency control
248238
* @param requireAlias Whether the index must be an alias
249-
* @param defaultIndex The default index from the request URL (for security check)
250-
* @param allowExplicitIndex Whether explicit index specification is allowed
251239
* @return The constructed IndexRequest
252240
*/
253241
public static IndexRequest buildCreateRequest(
@@ -261,15 +249,9 @@ public static IndexRequest buildCreateRequest(
261249
String pipeline,
262250
long ifSeqNo,
263251
long ifPrimaryTerm,
264-
boolean requireAlias,
265-
String defaultIndex,
266-
boolean allowExplicitIndex
252+
boolean requireAlias
267253
) {
268-
// Check explicit index (matches REST BulkRequestParser line 218-221)
269254
if (createOperation.hasXIndex()) {
270-
if (!allowExplicitIndex && defaultIndex != null) {
271-
throw new IllegalArgumentException("explicit index in bulk is not allowed");
272-
}
273255
index = createOperation.getXIndex();
274256
}
275257

@@ -307,8 +289,6 @@ public static IndexRequest buildCreateRequest(
307289
* @param ifSeqNo The default sequence number for optimistic concurrency control
308290
* @param ifPrimaryTerm The default primary term for optimistic concurrency control
309291
* @param requireAlias Whether the index must be an alias
310-
* @param defaultIndex The default index from the request URL (for security check)
311-
* @param allowExplicitIndex Whether explicit index specification is allowed
312292
* @return The constructed IndexRequest
313293
*/
314294
public static IndexRequest buildIndexRequest(
@@ -323,17 +303,11 @@ public static IndexRequest buildIndexRequest(
323303
String pipeline,
324304
long ifSeqNo,
325305
long ifPrimaryTerm,
326-
boolean requireAlias,
327-
String defaultIndex,
328-
boolean allowExplicitIndex
306+
boolean requireAlias
329307
) {
330308
opType = indexOperation.hasOpType() ? indexOperation.getOpType() : opType;
331309

332-
// Check explicit index (matches REST BulkRequestParser line 218-221)
333310
if (indexOperation.hasXIndex()) {
334-
if (!allowExplicitIndex && defaultIndex != null) {
335-
throw new IllegalArgumentException("explicit index in bulk is not allowed");
336-
}
337311
index = indexOperation.getXIndex();
338312
}
339313

@@ -390,8 +364,6 @@ public static IndexRequest buildIndexRequest(
390364
* @param ifSeqNo The default sequence number for optimistic concurrency control
391365
* @param ifPrimaryTerm The default primary term for optimistic concurrency control
392366
* @param requireAlias Whether the index must be an alias
393-
* @param defaultIndex The default index from the request URL (for security check)
394-
* @param allowExplicitIndex Whether explicit index specification is allowed
395367
* @return The constructed UpdateRequest
396368
*/
397369
public static UpdateRequest buildUpdateRequest(
@@ -406,15 +378,9 @@ public static UpdateRequest buildUpdateRequest(
406378
String pipeline,
407379
long ifSeqNo,
408380
long ifPrimaryTerm,
409-
boolean requireAlias,
410-
String defaultIndex,
411-
boolean allowExplicitIndex
381+
boolean requireAlias
412382
) {
413-
// Check explicit index (matches REST BulkRequestParser line 218-221)
414383
if (updateOperation.hasXIndex()) {
415-
if (!allowExplicitIndex && defaultIndex != null) {
416-
throw new IllegalArgumentException("explicit index in bulk is not allowed");
417-
}
418384
index = updateOperation.getXIndex();
419385
}
420386

@@ -550,8 +516,6 @@ static UpdateRequest fromProto(
550516
* @param versionType The default version type
551517
* @param ifSeqNo The default sequence number for optimistic concurrency control
552518
* @param ifPrimaryTerm The default primary term for optimistic concurrency control
553-
* @param defaultIndex The default index from the request URL (for security check)
554-
* @param allowExplicitIndex Whether explicit index specification is allowed
555519
* @return The constructed DeleteRequest
556520
*/
557521
public static DeleteRequest buildDeleteRequest(
@@ -562,15 +526,9 @@ public static DeleteRequest buildDeleteRequest(
562526
long version,
563527
VersionType versionType,
564528
long ifSeqNo,
565-
long ifPrimaryTerm,
566-
String defaultIndex,
567-
boolean allowExplicitIndex
529+
long ifPrimaryTerm
568530
) {
569-
// Check explicit index (matches REST BulkRequestParser line 218-221)
570531
if (deleteOperation.hasXIndex()) {
571-
if (!allowExplicitIndex && defaultIndex != null) {
572-
throw new IllegalArgumentException("explicit index in bulk is not allowed");
573-
}
574532
index = deleteOperation.getXIndex();
575533
}
576534

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/document/bulk/BulkRequestProtoUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
package org.opensearch.transport.grpc.proto.request.document.bulk;
1010

1111
import org.opensearch.action.bulk.BulkShardRequest;
12-
import org.opensearch.common.settings.Settings;
1312
import org.opensearch.protobufs.BulkRequest;
1413
import org.opensearch.rest.RestRequest;
1514
import org.opensearch.rest.action.document.RestBulkAction;
@@ -37,11 +36,16 @@ private BulkRequestProtoUtils() {
3736
* Similar to {@link RestBulkAction#prepareRequest(RestRequest, NodeClient)}
3837
* Please ensure to keep both implementations consistent.
3938
*
39+
* Note: Unlike REST API, gRPC does not enforce the allowExplicitIndex security setting.
40+
* In REST, this setting provides network-level security by allowing proxies to filter
41+
* requests based on URL paths. In gRPC, both default_index and x_index are in the
42+
* request body, making this check ineffective for network-level security.
43+
* For gRPC security, use mTLS, gRPC interceptors, or service mesh policies instead.
44+
*
4045
* @param request the request to execute
41-
* @param settings node settings for security and configuration
4246
* @return a future of the bulk action that was executed
4347
*/
44-
public static org.opensearch.action.bulk.BulkRequest prepareRequest(BulkRequest request, Settings settings) {
48+
public static org.opensearch.action.bulk.BulkRequest prepareRequest(BulkRequest request) {
4549
org.opensearch.action.bulk.BulkRequest bulkRequest = Requests.bulkRequest();
4650

4751
String defaultIndex = request.hasIndex() ? request.getIndex() : null;
@@ -62,9 +66,6 @@ public static org.opensearch.action.bulk.BulkRequest prepareRequest(BulkRequest
6266

6367
bulkRequest.setRefreshPolicy(RefreshProtoUtils.getRefreshPolicy(request.getRefresh()));
6468

65-
// Read the allowExplicitIndex setting (matches REST BulkAction line 74)
66-
boolean allowExplicitIndex = RestBulkAction.MULTI_ALLOW_EXPLICIT_INDEX.get(settings);
67-
6869
// Note: batch_size is deprecated in OS 3.x. Add batch_size parameter when backporting to OS 2.x
6970
/*
7071
if (request.hasBatchSize()){
@@ -80,8 +81,7 @@ public static org.opensearch.action.bulk.BulkRequest prepareRequest(BulkRequest
8081
defaultRouting,
8182
defaultFetchSourceContext,
8283
defaultPipeline,
83-
defaultRequireAlias,
84-
allowExplicitIndex
84+
defaultRequireAlias
8585
)
8686
);
8787

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/services/DocumentServiceImpl.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.apache.logging.log4j.LogManager;
1212
import org.apache.logging.log4j.Logger;
13-
import org.opensearch.common.settings.Settings;
1413
import org.opensearch.protobufs.services.DocumentServiceGrpc;
1514
import org.opensearch.transport.client.Client;
1615
import org.opensearch.transport.grpc.listeners.BulkRequestActionListener;
@@ -26,17 +25,14 @@
2625
public class DocumentServiceImpl extends DocumentServiceGrpc.DocumentServiceImplBase {
2726
private static final Logger logger = LogManager.getLogger(DocumentServiceImpl.class);
2827
private final Client client;
29-
private final Settings settings;
3028

3129
/**
3230
* Creates a new DocumentServiceImpl.
3331
*
3432
* @param client Client for executing actions on the local node
35-
* @param settings Node settings for security and configuration
3633
*/
37-
public DocumentServiceImpl(Client client, Settings settings) {
34+
public DocumentServiceImpl(Client client) {
3835
this.client = client;
39-
this.settings = settings;
4036
}
4137

4238
/**
@@ -48,7 +44,7 @@ public DocumentServiceImpl(Client client, Settings settings) {
4844
@Override
4945
public void bulk(org.opensearch.protobufs.BulkRequest request, StreamObserver<org.opensearch.protobufs.BulkResponse> responseObserver) {
5046
try {
51-
org.opensearch.action.bulk.BulkRequest bulkRequest = BulkRequestProtoUtils.prepareRequest(request, settings);
47+
org.opensearch.action.bulk.BulkRequest bulkRequest = BulkRequestProtoUtils.prepareRequest(request);
5248
BulkRequestActionListener listener = new BulkRequestActionListener(responseObserver);
5349
client.bulk(bulkRequest, listener);
5450
} catch (RuntimeException e) {

0 commit comments

Comments
 (0)