Restrict Connector APIs to manage/monitor_connector privileges (#119863)

* Reapply "Restrict Connector APIs to manage/monitor_connector privileges (#119389)" (#119833)

This reverts commit e0cefb8ff0.

* Update docs/changelog/119863.yaml

* Update docs/changelog/119863.yaml

* Update changelog

* Fix changelog

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Jedr Blaszyk 2025-01-10 11:30:44 +01:00 committed by GitHub
parent 9a11f139de
commit 79713f5e99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 224 additions and 221 deletions

View file

@ -4,13 +4,12 @@ admin:
- manage_behavioral_analytics
- manage
- monitor
- manage_connector
indices:
- names: [
# indices and search applications
"test-*",
"another-test-search-application",
".elastic-connectors-v1",
".elastic-connectors-sync-jobs-v1"
]
privileges: [ "manage", "write", "read" ]
@ -20,6 +19,7 @@ user:
- manage_api_key
- read_connector_secrets
- write_connector_secrets
- monitor_connector
indices:
- names: [
"test-index1",
@ -27,9 +27,7 @@ user:
"test-search-application-1",
"test-search-application-with-aggs",
"test-search-application-with-list",
"test-search-application-with-list-invalid",
".elastic-connectors-v1",
".elastic-connectors-sync-jobs-v1"
"test-search-application-with-list-invalid"
]
privileges: [ "read" ]

View file

@ -21,6 +21,7 @@ import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.OriginSettingClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.query.BoolQueryBuilder;
@ -74,13 +75,15 @@ import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.application.connector.ConnectorFiltering.fromXContentBytesConnectorFiltering;
import static org.elasticsearch.xpack.application.connector.ConnectorFiltering.sortFilteringRulesByOrder;
import static org.elasticsearch.xpack.application.connector.ConnectorTemplateRegistry.MANAGED_CONNECTOR_INDEX_PREFIX;
import static org.elasticsearch.xpack.core.ClientHelper.CONNECTORS_ORIGIN;
/**
* A service that manages persistent {@link Connector} configurations.
*/
public class ConnectorIndexService {
private final Client client;
// The client to interact with the system index (internal user).
private final Client clientWithOrigin;
public static final String CONNECTOR_INDEX_NAME = ConnectorTemplateRegistry.CONNECTOR_INDEX_NAME_PATTERN;
@ -88,7 +91,7 @@ public class ConnectorIndexService {
* @param client A client for executing actions on the connector index
*/
public ConnectorIndexService(Client client) {
this.client = client;
this.clientWithOrigin = new OriginSettingClient(client, CONNECTORS_ORIGIN);
}
/**
@ -134,7 +137,7 @@ public class ConnectorIndexService {
indexRequest = indexRequest.id(connectorId);
}
client.index(
clientWithOrigin.index(
indexRequest,
listener.delegateFailureAndWrap(
(ll, indexResponse) -> ll.onResponse(
@ -201,7 +204,7 @@ public class ConnectorIndexService {
try {
final GetRequest getRequest = new GetRequest(CONNECTOR_INDEX_NAME).id(connectorId).realtime(true);
client.get(getRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, getResponse) -> {
clientWithOrigin.get(getRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, getResponse) -> {
if (getResponse.isExists() == false) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
@ -248,13 +251,16 @@ public class ConnectorIndexService {
.id(connectorId)
.source(Map.of(Connector.IS_DELETED_FIELD.getPreferredName(), true))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, l, (ll, updateResponse) -> {
clientWithOrigin.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, l, (ll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
ll.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
if (shouldDeleteSyncJobs) {
new ConnectorSyncJobIndexService(client).deleteAllSyncJobsByConnectorId(connectorId, ll.map(r -> updateResponse));
new ConnectorSyncJobIndexService(clientWithOrigin).deleteAllSyncJobsByConnectorId(
connectorId,
ll.map(r -> updateResponse)
);
} else {
ll.onResponse(updateResponse);
}
@ -294,7 +300,7 @@ public class ConnectorIndexService {
.fetchSource(true)
.sort(Connector.INDEX_NAME_FIELD.getPreferredName(), SortOrder.ASC);
final SearchRequest req = new SearchRequest(CONNECTOR_INDEX_NAME).source(source);
client.search(req, new ActionListener<>() {
clientWithOrigin.search(req, new ActionListener<>() {
@Override
public void onResponse(SearchResponse searchResponse) {
try {
@ -476,7 +482,7 @@ public class ConnectorIndexService {
return;
}
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, l, (ll, updateResponse) -> {
clientWithOrigin.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, l, (ll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
ll.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
@ -513,13 +519,16 @@ public class ConnectorIndexService {
}
})
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -541,13 +550,16 @@ public class ConnectorIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source(request.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -568,13 +580,16 @@ public class ConnectorIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source(Map.of(Connector.FILTERING_FIELD.getPreferredName(), filtering))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -595,13 +610,16 @@ public class ConnectorIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source(Map.of(Connector.FEATURES_FIELD.getPreferredName(), features))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -657,13 +675,16 @@ public class ConnectorIndexService {
.source(Map.of(Connector.FILTERING_FIELD.getPreferredName(), List.of(connectorFilteringWithUpdatedDraft)))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (ll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
ll.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
ll.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (ll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
ll.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
ll.onResponse(updateResponse);
})
);
}));
} catch (Exception e) {
@ -705,7 +726,7 @@ public class ConnectorIndexService {
.source(Map.of(Connector.FILTERING_FIELD.getPreferredName(), List.of(activatedConnectorFiltering)))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, l, (ll, updateResponse) -> {
clientWithOrigin.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, l, (ll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
ll.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
@ -762,7 +783,7 @@ public class ConnectorIndexService {
.source(Map.of(Connector.FILTERING_FIELD.getPreferredName(), List.of(activatedConnectorFiltering)))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, l, (ll, updateResponse) -> {
clientWithOrigin.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, l, (ll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
ll.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
@ -790,13 +811,16 @@ public class ConnectorIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source(Map.of(Connector.LAST_SEEN_FIELD.getPreferredName(), Instant.now()))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -817,13 +841,16 @@ public class ConnectorIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source(request.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -887,13 +914,16 @@ public class ConnectorIndexService {
)
)
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (ll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
ll.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
ll.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (ll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
ll.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
ll.onResponse(updateResponse);
})
);
}));
} catch (Exception e) {
listener.onFailure(e);
@ -916,13 +946,16 @@ public class ConnectorIndexService {
.source(Map.of(Connector.PIPELINE_FIELD.getPreferredName(), request.getPipeline()))
.source(request.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -981,7 +1014,7 @@ public class ConnectorIndexService {
}
})
);
client.update(
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (lll, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
@ -1014,13 +1047,16 @@ public class ConnectorIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source(Map.of(Connector.SCHEDULING_FIELD.getPreferredName(), request.getScheduling()))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -1056,7 +1092,7 @@ public class ConnectorIndexService {
)
);
client.update(
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (updateListener, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
@ -1099,7 +1135,7 @@ public class ConnectorIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source(Map.of(Connector.STATUS_FIELD.getPreferredName(), request.getStatus()))
);
client.update(
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (updateListener, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
@ -1127,13 +1163,16 @@ public class ConnectorIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.source(request.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS))
);
client.update(updateRequest, new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
}));
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundActionListener<>(connectorId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == UpdateResponse.Result.NOT_FOUND) {
l.onFailure(new ResourceNotFoundException(connectorNotFoundErrorMsg(connectorId)));
return;
}
l.onResponse(updateResponse);
})
);
} catch (Exception e) {
listener.onFailure(e);
}
@ -1211,7 +1250,7 @@ public class ConnectorIndexService {
final SearchSourceBuilder searchSource = new SearchSourceBuilder().query(boolFilterQueryBuilder);
final SearchRequest searchRequest = new SearchRequest(CONNECTOR_INDEX_NAME).source(searchSource);
client.search(searchRequest, new ActionListener<>() {
clientWithOrigin.search(searchRequest, new ActionListener<>() {
@Override
public void onResponse(SearchResponse searchResponse) {
boolean indexNameIsInUse = searchResponse.getHits().getTotalHits().value() > 0L;

View file

@ -9,12 +9,9 @@ package org.elasticsearch.xpack.application.connector.action;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.cluster.metadata.MetadataCreateIndexService;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.indices.InvalidIndexNameException;
import org.elasticsearch.xpack.application.connector.ConnectorTemplateRegistry;
import java.io.IOException;
@ -22,10 +19,9 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.xpack.application.connector.ConnectorTemplateRegistry.MANAGED_CONNECTOR_INDEX_PREFIX;
/**
* Abstract base class for action requests targeting the connectors index. Implements {@link org.elasticsearch.action.IndicesRequest}
* to ensure index-level privilege support. This class defines the connectors index as the target for all derived action requests.
* Abstract base class for action requests targeting the connectors index.
*/
public abstract class ConnectorActionRequest extends ActionRequest implements IndicesRequest {
public abstract class ConnectorActionRequest extends ActionRequest {
public ConnectorActionRequest() {
super();
@ -78,14 +74,4 @@ public abstract class ConnectorActionRequest extends ActionRequest implements In
}
return validationException;
}
@Override
public String[] indices() {
return new String[] { ConnectorTemplateRegistry.CONNECTOR_INDEX_NAME_PATTERN };
}
@Override
public IndicesOptions indicesOptions() {
return IndicesOptions.lenientExpandHidden();
}
}

View file

@ -18,7 +18,6 @@ import org.elasticsearch.xcontent.ParseField;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xpack.application.connector.ConnectorTemplateRegistry;
import java.io.IOException;
import java.util.Objects;
@ -28,7 +27,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class DeleteConnectorAction {
public static final String NAME = "indices:data/write/xpack/connector/delete";
public static final String NAME = "cluster:admin/xpack/connector/delete";
public static final ActionType<AcknowledgedResponse> INSTANCE = new ActionType<>(NAME);
private DeleteConnectorAction() {/* no instances */}
@ -71,14 +70,6 @@ public class DeleteConnectorAction {
return deleteSyncJobs;
}
@Override
public String[] indices() {
// When deleting a connector, corresponding sync jobs can also be deleted
return new String[] {
ConnectorTemplateRegistry.CONNECTOR_SYNC_JOBS_INDEX_NAME_PATTERN,
ConnectorTemplateRegistry.CONNECTOR_INDEX_NAME_PATTERN };
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);

View file

@ -30,7 +30,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class GetConnectorAction {
public static final String NAME = "indices:data/read/xpack/connector/get";
public static final String NAME = "cluster:admin/xpack/connector/get";
public static final ActionType<GetConnectorAction.Response> INSTANCE = new ActionType<>(NAME);
private GetConnectorAction() {/* no instances */}

View file

@ -35,7 +35,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class ListConnectorAction {
public static final String NAME = "indices:data/read/xpack/connector/list";
public static final String NAME = "cluster:admin/xpack/connector/list";
public static final ActionType<ListConnectorAction.Response> INSTANCE = new ActionType<>(NAME);
private ListConnectorAction() {/* no instances */}

View file

@ -25,7 +25,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class PostConnectorAction {
public static final String NAME = "indices:data/write/xpack/connector/post";
public static final String NAME = "cluster:admin/xpack/connector/post";
public static final ActionType<ConnectorCreateActionResponse> INSTANCE = new ActionType<>(NAME);
private PostConnectorAction() {/* no instances */}

View file

@ -9,7 +9,6 @@ package org.elasticsearch.xpack.application.connector.action;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
@ -27,12 +26,12 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class PutConnectorAction {
public static final String NAME = "indices:data/write/xpack/connector/put";
public static final String NAME = "cluster:admin/xpack/connector/put";
public static final ActionType<ConnectorCreateActionResponse> INSTANCE = new ActionType<>(NAME);
private PutConnectorAction() {/* no instances */}
public static class Request extends ConnectorActionRequest implements IndicesRequest, ToXContentObject {
public static class Request extends ConnectorActionRequest implements ToXContentObject {
@Nullable
private final String connectorId;

View file

@ -22,7 +22,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
public class UpdateConnectorActiveFilteringAction {
public static final String NAME = "indices:data/write/xpack/connector/update_filtering/activate";
public static final String NAME = "cluster:admin/xpack/connector/update_filtering/activate";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorActiveFilteringAction() {/* no instances */}

View file

@ -27,7 +27,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class UpdateConnectorApiKeyIdAction {
public static final String NAME = "indices:data/write/xpack/connector/update_api_key_id";
public static final String NAME = "cluster:admin/xpack/connector/update_api_key_id";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorApiKeyIdAction() {/* no instances */}

View file

@ -32,7 +32,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class UpdateConnectorConfigurationAction {
public static final String NAME = "indices:data/write/xpack/connector/update_configuration";
public static final String NAME = "cluster:admin/xpack/connector/update_configuration";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorConfigurationAction() {/* no instances */}

View file

@ -27,7 +27,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class UpdateConnectorErrorAction {
public static final String NAME = "indices:data/write/xpack/connector/update_error";
public static final String NAME = "cluster:admin/xpack/connector/update_error";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorErrorAction() {/* no instances */}

View file

@ -27,7 +27,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class UpdateConnectorFeaturesAction {
public static final String NAME = "indices:data/write/xpack/connector/update_features";
public static final String NAME = "cluster:admin/xpack/connector/update_features";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorFeaturesAction() {/* no instances */}

View file

@ -32,7 +32,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class UpdateConnectorFilteringAction {
public static final String NAME = "indices:data/write/xpack/connector/update_filtering";
public static final String NAME = "cluster:admin/xpack/connector/update_filtering";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorFilteringAction() {/* no instances */}

View file

@ -27,7 +27,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class UpdateConnectorFilteringValidationAction {
public static final String NAME = "indices:data/write/xpack/connector/update_filtering/draft_validation";
public static final String NAME = "cluster:admin/xpack/connector/update_filtering/draft_validation";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorFilteringValidationAction() {/* no instances */}

View file

@ -27,7 +27,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class UpdateConnectorIndexNameAction {
public static final String NAME = "indices:data/write/xpack/connector/update_index_name";
public static final String NAME = "cluster:admin/xpack/connector/update_index_name";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorIndexNameAction() {/* no instances */}

View file

@ -23,7 +23,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
public class UpdateConnectorLastSeenAction {
public static final String NAME = "indices:data/write/xpack/connector/update_last_seen";
public static final String NAME = "cluster:admin/xpack/connector/update_last_seen";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorLastSeenAction() {/* no instances */}

View file

@ -32,7 +32,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class UpdateConnectorLastSyncStatsAction {
public static final String NAME = "indices:data/write/xpack/connector/update_last_sync_stats";
public static final String NAME = "cluster:admin/xpack/connector/update_last_sync_stats";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorLastSyncStatsAction() {/* no instances */}

View file

@ -27,7 +27,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class UpdateConnectorNameAction {
public static final String NAME = "indices:data/write/xpack/connector/update_name";
public static final String NAME = "cluster:admin/xpack/connector/update_name";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorNameAction() {/* no instances */}

View file

@ -26,7 +26,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class UpdateConnectorNativeAction {
public static final String NAME = "indices:data/write/xpack/connector/update_native";
public static final String NAME = "cluster:admin/xpack/connector/update_native";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorNativeAction() {/* no instances */}

View file

@ -27,7 +27,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class UpdateConnectorPipelineAction {
public static final String NAME = "indices:data/write/xpack/connector/update_pipeline";
public static final String NAME = "cluster:admin/xpack/connector/update_pipeline";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorPipelineAction() {/* no instances */}

View file

@ -32,7 +32,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class UpdateConnectorSchedulingAction {
public static final String NAME = "indices:data/write/xpack/connector/update_scheduling";
public static final String NAME = "cluster:admin/xpack/connector/update_scheduling";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorSchedulingAction() {/* no instances */}

View file

@ -26,7 +26,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class UpdateConnectorServiceTypeAction {
public static final String NAME = "indices:data/write/xpack/connector/update_service_type";
public static final String NAME = "cluster:admin/xpack/connector/update_service_type";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorServiceTypeAction() {/* no instances */}

View file

@ -28,7 +28,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class UpdateConnectorStatusAction {
public static final String NAME = "indices:data/write/xpack/connector/update_status";
public static final String NAME = "cluster:admin/xpack/connector/update_status";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
public UpdateConnectorStatusAction() {/* no instances */}

View file

@ -28,6 +28,7 @@ import org.elasticsearch.action.support.WriteRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.client.internal.OriginSettingClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.engine.DocumentMissingException;
@ -68,6 +69,7 @@ import java.util.stream.Stream;
import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.application.connector.ConnectorIndexService.CONNECTOR_INDEX_NAME;
import static org.elasticsearch.xpack.core.ClientHelper.CONNECTORS_ORIGIN;
/**
* A service that manages persistent {@link ConnectorSyncJob} configurations.
@ -76,7 +78,8 @@ public class ConnectorSyncJobIndexService {
private static final Long ZERO = 0L;
private final Client client;
// The client to interact with the system index (internal user).
private final Client clientWithOrigin;
public static final String CONNECTOR_SYNC_JOB_INDEX_NAME = ConnectorTemplateRegistry.CONNECTOR_SYNC_JOBS_INDEX_NAME_PATTERN;
@ -84,7 +87,7 @@ public class ConnectorSyncJobIndexService {
* @param client A client for executing actions on the connectors sync jobs index.
*/
public ConnectorSyncJobIndexService(Client client) {
this.client = client;
this.clientWithOrigin = new OriginSettingClient(client, CONNECTORS_ORIGIN);
}
/**
@ -149,7 +152,7 @@ public class ConnectorSyncJobIndexService {
indexRequest.source(syncJob.toXContent(jsonBuilder(), ToXContent.EMPTY_PARAMS));
client.index(
clientWithOrigin.index(
indexRequest,
l.delegateFailureAndWrap(
(ll, indexResponse) -> ll.onResponse(new PostConnectorSyncJobAction.Response(indexResponse.getId()))
@ -175,7 +178,7 @@ public class ConnectorSyncJobIndexService {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
try {
client.delete(
clientWithOrigin.delete(
deleteRequest,
new DelegatingIndexNotFoundOrDocumentMissingActionListener<>(connectorSyncJobId, listener, (l, deleteResponse) -> {
if (deleteResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) {
@ -205,7 +208,7 @@ public class ConnectorSyncJobIndexService {
).doc(Map.of(ConnectorSyncJob.LAST_SEEN_FIELD.getPreferredName(), newLastSeen));
try {
client.update(
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundOrDocumentMissingActionListener<>(connectorSyncJobId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) {
@ -230,7 +233,7 @@ public class ConnectorSyncJobIndexService {
final GetRequest getRequest = new GetRequest(CONNECTOR_SYNC_JOB_INDEX_NAME).id(connectorSyncJobId).realtime(true);
try {
client.get(
clientWithOrigin.get(
getRequest,
new DelegatingIndexNotFoundOrDocumentMissingActionListener<>(connectorSyncJobId, listener, (l, getResponse) -> {
if (getResponse.isExists() == false) {
@ -306,7 +309,7 @@ public class ConnectorSyncJobIndexService {
WriteRequest.RefreshPolicy.IMMEDIATE
).doc(syncJobFieldsToUpdate);
client.update(
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundOrDocumentMissingActionListener<>(
connectorSyncJobId,
@ -355,7 +358,7 @@ public class ConnectorSyncJobIndexService {
final SearchRequest searchRequest = new SearchRequest(CONNECTOR_SYNC_JOB_INDEX_NAME).source(searchSource);
client.search(searchRequest, new ActionListener<>() {
clientWithOrigin.search(searchRequest, new ActionListener<>() {
@Override
public void onResponse(SearchResponse searchResponse) {
try {
@ -474,7 +477,7 @@ public class ConnectorSyncJobIndexService {
).doc(fieldsToUpdate);
try {
client.update(
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundOrDocumentMissingActionListener<>(syncJobId, listener, (l, updateResponse) -> {
if (updateResponse.getResult() == DocWriteResponse.Result.NOT_FOUND) {
@ -501,7 +504,7 @@ public class ConnectorSyncJobIndexService {
final GetRequest request = new GetRequest(CONNECTOR_INDEX_NAME, connectorId);
client.get(request, new ActionListener<>() {
clientWithOrigin.get(request, new ActionListener<>() {
@Override
public void onResponse(GetResponse response) {
final boolean connectorDoesNotExist = response.isExists() == false;
@ -594,7 +597,7 @@ public class ConnectorSyncJobIndexService {
)
);
client.update(
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundOrDocumentMissingActionListener<>(
connectorSyncJobId,
@ -629,7 +632,7 @@ public class ConnectorSyncJobIndexService {
)
).setRefresh(true).setIndicesOptions(IndicesOptions.fromOptions(true, true, false, false));
client.execute(DeleteByQueryAction.INSTANCE, deleteByQueryRequest, listener.delegateFailureAndWrap((l, r) -> {
clientWithOrigin.execute(DeleteByQueryAction.INSTANCE, deleteByQueryRequest, listener.delegateFailureAndWrap((l, r) -> {
final List<BulkItemResponse.Failure> bulkDeleteFailures = r.getBulkFailures();
if (bulkDeleteFailures.isEmpty() == false) {
l.onFailure(
@ -681,7 +684,7 @@ public class ConnectorSyncJobIndexService {
WriteRequest.RefreshPolicy.IMMEDIATE
).doc(document);
client.update(
clientWithOrigin.update(
updateRequest,
new DelegatingIndexNotFoundOrDocumentMissingActionListener<>(
connectorSyncJobId,

View file

@ -28,7 +28,7 @@ import static org.elasticsearch.xpack.application.connector.syncjob.ConnectorSyn
public class CancelConnectorSyncJobAction {
public static final String NAME = "indices:data/write/xpack/connector/sync_job/cancel";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/cancel";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<ConnectorUpdateActionResponse>(NAME);
private CancelConnectorSyncJobAction() {/* no instances */}

View file

@ -28,7 +28,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class CheckInConnectorSyncJobAction {
public static final String NAME = "indices:data/write/xpack/connector/sync_job/check_in";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/check_in";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private CheckInConnectorSyncJobAction() {/* no instances */}

View file

@ -31,7 +31,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class ClaimConnectorSyncJobAction {
public static final ParseField CONNECTOR_SYNC_JOB_ID_FIELD = new ParseField("connector_sync_job_id");
public static final String NAME = "indices:data/write/xpack/connector/sync_job/claim";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/claim";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private ClaimConnectorSyncJobAction() {/* no instances */}

View file

@ -8,19 +8,14 @@
package org.elasticsearch.xpack.application.connector.syncjob.action;
import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.IndicesRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.xpack.application.connector.ConnectorTemplateRegistry;
import java.io.IOException;
/**
* Abstract base class for action requests targeting the connector sync job index.
* Implements {@link org.elasticsearch.action.IndicesRequest} to ensure index-level privilege support.
* This class defines the connectors sync job index as the target for all derived action requests.
*/
public abstract class ConnectorSyncJobActionRequest extends ActionRequest implements IndicesRequest {
public abstract class ConnectorSyncJobActionRequest extends ActionRequest {
public ConnectorSyncJobActionRequest() {
super();
@ -29,14 +24,4 @@ public abstract class ConnectorSyncJobActionRequest extends ActionRequest implem
public ConnectorSyncJobActionRequest(StreamInput in) throws IOException {
super(in);
}
@Override
public String[] indices() {
return new String[] { ConnectorTemplateRegistry.CONNECTOR_SYNC_JOBS_INDEX_NAME_PATTERN };
}
@Override
public IndicesOptions indicesOptions() {
return IndicesOptions.lenientExpandHidden();
}
}

View file

@ -28,7 +28,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class DeleteConnectorSyncJobAction {
public static final String NAME = "indices:data/write/xpack/connector/sync_job/delete";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/delete";
public static final ActionType<AcknowledgedResponse> INSTANCE = new ActionType<>(NAME);
private DeleteConnectorSyncJobAction() {/* no instances */}

View file

@ -29,7 +29,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class GetConnectorSyncJobAction {
public static final String NAME = "indices:data/read/xpack/connector/sync_job/get";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/get";
public static final ActionType<GetConnectorSyncJobAction.Response> INSTANCE = new ActionType<>(NAME);
private GetConnectorSyncJobAction() {/* no instances */}

View file

@ -33,7 +33,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class ListConnectorSyncJobsAction {
public static final String NAME = "indices:data/read/xpack/connector/sync_job/list";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/list";
public static final ActionType<ListConnectorSyncJobsAction.Response> INSTANCE = new ActionType<>(NAME);
private ListConnectorSyncJobsAction() {/* no instances */}

View file

@ -18,7 +18,6 @@ import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xpack.application.connector.Connector;
import org.elasticsearch.xpack.application.connector.ConnectorTemplateRegistry;
import org.elasticsearch.xpack.application.connector.syncjob.ConnectorSyncJob;
import org.elasticsearch.xpack.application.connector.syncjob.ConnectorSyncJobTriggerMethod;
import org.elasticsearch.xpack.application.connector.syncjob.ConnectorSyncJobType;
@ -32,7 +31,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstr
public class PostConnectorSyncJobAction {
public static final String NAME = "indices:data/write/xpack/connector/sync_job/post";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/post";
public static final ActionType<PostConnectorSyncJobAction.Response> INSTANCE = new ActionType<>(NAME);
private PostConnectorSyncJobAction() {/* no instances */}
@ -140,14 +139,6 @@ public class PostConnectorSyncJobAction {
public int hashCode() {
return Objects.hash(id, jobType, triggerMethod);
}
@Override
public String[] indices() {
// Creating a new sync job requires reading from connector index
return new String[] {
ConnectorTemplateRegistry.CONNECTOR_SYNC_JOBS_INDEX_NAME_PATTERN,
ConnectorTemplateRegistry.CONNECTOR_INDEX_NAME_PATTERN };
}
}
public static class Response extends ActionResponse implements ToXContentObject {

View file

@ -28,7 +28,7 @@ import static org.elasticsearch.xcontent.ConstructingObjectParser.constructorArg
public class UpdateConnectorSyncJobErrorAction {
public static final String NAME = "indices:data/write/xpack/connector/sync_job/update_error";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/update_error";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorSyncJobErrorAction() {/* no instances */}

View file

@ -35,7 +35,7 @@ import static org.elasticsearch.xpack.application.connector.syncjob.ConnectorSyn
public class UpdateConnectorSyncJobIngestionStatsAction {
public static final String NAME = "indices:data/write/xpack/connector/sync_job/update_stats";
public static final String NAME = "cluster:admin/xpack/connector/sync_job/update_stats";
public static final ActionType<ConnectorUpdateActionResponse> INSTANCE = new ActionType<>(NAME);
private UpdateConnectorSyncJobIngestionStatsAction() {/* no instances */}