Skip to content

Commit d7445d0

Browse files
[ML] Changing all calls to ML endpoints to use internal user (#70487)
* [ML] Changing all calls to ML endpoints to use internal user * updating alerting * updating documentation * [ML] Changing all calls to ML endpoints to use internal user * updating alerting * updating documentation * fixing missed types * adding authorization headers to endpoint calls * correcting has privileges call * updating security tests * odd eslint error * adding auth header to module setup * fixing missing auth argument * fixing delete DFA job permission checks * removing debug test tag * removing additional ml privilege checks * adding authorization header to _evaluate * updating alerting cluster client name * code clean up * changing authorizationHeader name * updating alterting documentation * fixing secondary credentials * adding management links * updating SIEM telemetry * fixing merge conflicts * granting access to index patterns Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 703d685 commit d7445d0

File tree

99 files changed

+965
-972
lines changed

Some content is hidden

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

99 files changed

+965
-972
lines changed

x-pack/plugins/actions/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ This is the primary function for an action type. Whenever the action needs to ex
160160
| config | The decrypted configuration given to an action. This comes from the action saved object that is partially or fully encrypted within the data store. If you would like to validate the config before being passed to the executor, define `validate.config` within the action type. |
161161
| params | Parameters for the execution. These will be given at execution time by either an alert or manually provided when calling the plugin provided execute function. |
162162
| services.callCluster(path, opts) | Use this to do Elasticsearch queries on the cluster Kibana connects to. This function is the same as any other `callCluster` in Kibana but runs in the context of the user who is calling the action when security is enabled. |
163-
| services.getScopedCallCluster | This function scopes an instance of CallCluster by returning a `callCluster(path, opts)` function that runs in the context of the user who is calling the action when security is enabled. This must only be called with instances of CallCluster provided by core. |
163+
| services.getLegacyScopedClusterClient | This function returns an instance of the LegacyScopedClusterClient scoped to the user who is calling the action when security is enabled. |
164164
| services.savedObjectsClient | This is an instance of the saved objects client. This provides the ability to do CRUD on any saved objects within the same space the alert lives in.<br><br>The scope of the saved objects client is tied to the user in context calling the execute API or the API key provided to the execute plugin function (only when security isenabled). |
165165
| services.log(tags, [data], [timestamp]) | Use this to create server logs. (This is the same function as server.log) |
166166

x-pack/plugins/actions/server/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const createServicesMock = () => {
3838
}
3939
> = {
4040
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
41-
getScopedCallCluster: jest.fn(),
41+
getLegacyScopedClusterClient: jest.fn(),
4242
savedObjectsClient: savedObjectsClientMock.create(),
4343
};
4444
return mock;

x-pack/plugins/actions/server/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ export class ActionsPlugin implements Plugin<Promise<PluginSetupContract>, Plugi
307307
return (request) => ({
308308
callCluster: elasticsearch.legacy.client.asScoped(request).callAsCurrentUser,
309309
savedObjectsClient: getScopedClient(request),
310-
getScopedCallCluster(clusterClient: ILegacyClusterClient) {
311-
return clusterClient.asScoped(request).callAsCurrentUser;
310+
getLegacyScopedClusterClient(clusterClient: ILegacyClusterClient) {
311+
return clusterClient.asScoped(request);
312312
},
313313
});
314314
}

x-pack/plugins/actions/server/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ export type SpaceIdToNamespaceFunction = (spaceId?: string) => string | undefine
2525
export interface Services {
2626
callCluster: ILegacyScopedClusterClient['callAsCurrentUser'];
2727
savedObjectsClient: SavedObjectsClientContract;
28-
getScopedCallCluster(
29-
clusterClient: ILegacyClusterClient
30-
): ILegacyScopedClusterClient['callAsCurrentUser'];
28+
getLegacyScopedClusterClient(clusterClient: ILegacyClusterClient): ILegacyScopedClusterClient;
3129
}
3230

3331
declare module 'src/core/server' {

x-pack/plugins/alerts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ This is the primary function for an alert type. Whenever the alert needs to exec
103103
|---|---|
104104
|services.callCluster(path, opts)|Use this to do Elasticsearch queries on the cluster Kibana connects to. This function is the same as any other `callCluster` in Kibana but in the context of the user who created the alert when security is enabled.|
105105
|services.savedObjectsClient|This is an instance of the saved objects client. This provides the ability to do CRUD on any saved objects within the same space the alert lives in.<br><br>The scope of the saved objects client is tied to the user who created the alert (only when security isenabled).|
106-
|services.getScopedCallCluster|This function scopes an instance of CallCluster by returning a `callCluster(path, opts)` function that runs in the context of the user who created the alert when security is enabled. This must only be called with instances of CallCluster provided by core.|
106+
|services.getLegacyScopedClusterClient|This function returns an instance of the LegacyScopedClusterClient scoped to the user who created the alert when security is enabled.|
107107
|services.alertInstanceFactory(id)|This [alert instance factory](#alert-instance-factory) creates instances of alerts and must be used in order to execute actions. The id you give to the alert instance factory is a unique identifier to the alert instance.|
108108
|services.log(tags, [data], [timestamp])|Use this to create server logs. (This is the same function as server.log)|
109109
|startedAt|The date and time the alert type started execution.|

x-pack/plugins/alerts/server/mocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const createAlertServicesMock = () => {
5959
.fn<jest.Mocked<AlertInstance>, [string]>()
6060
.mockReturnValue(alertInstanceFactoryMock),
6161
callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser,
62-
getScopedCallCluster: jest.fn(),
62+
getLegacyScopedClusterClient: jest.fn(),
6363
savedObjectsClient: savedObjectsClientMock.create(),
6464
};
6565
};

x-pack/plugins/alerts/server/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ export class AlertingPlugin {
273273
return (request) => ({
274274
callCluster: elasticsearch.legacy.client.asScoped(request).callAsCurrentUser,
275275
savedObjectsClient: this.getScopedClientWithAlertSavedObjectType(savedObjects, request),
276-
getScopedCallCluster(clusterClient: ILegacyClusterClient) {
277-
return clusterClient.asScoped(request).callAsCurrentUser;
276+
getLegacyScopedClusterClient(clusterClient: ILegacyClusterClient) {
277+
return clusterClient.asScoped(request);
278278
},
279279
});
280280
}

x-pack/plugins/alerts/server/types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ declare module 'src/core/server' {
4040
export interface Services {
4141
callCluster: ILegacyScopedClusterClient['callAsCurrentUser'];
4242
savedObjectsClient: SavedObjectsClientContract;
43-
getScopedCallCluster(
44-
clusterClient: ILegacyClusterClient
45-
): ILegacyScopedClusterClient['callAsCurrentUser'];
43+
getLegacyScopedClusterClient(clusterClient: ILegacyClusterClient): ILegacyScopedClusterClient;
4644
}
4745

4846
export interface AlertServices extends Services {

x-pack/plugins/apm/server/lib/helpers/setup_request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function getMlSetup(context: APMRequestHandlerContext, request: KibanaRequest) {
112112
return;
113113
}
114114
const ml = context.plugins.ml;
115-
const mlClient = ml.mlClient.asScoped(request).callAsCurrentUser;
115+
const mlClient = ml.mlClient.asScoped(request);
116116
return {
117117
mlSystem: ml.mlSystemProvider(mlClient, request),
118118
anomalyDetectors: ml.anomalyDetectorsProvider(mlClient, request),

x-pack/plugins/infra/server/plugin.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,9 @@ export class InfraServerPlugin {
152152
core.http.registerRouteHandlerContext(
153153
'infra',
154154
(context, request): InfraRequestHandlerContext => {
155-
const mlSystem =
156-
context.ml &&
157-
plugins.ml?.mlSystemProvider(context.ml?.mlClient.callAsCurrentUser, request);
155+
const mlSystem = context.ml && plugins.ml?.mlSystemProvider(context.ml?.mlClient, request);
158156
const mlAnomalyDetectors =
159-
context.ml &&
160-
plugins.ml?.anomalyDetectorsProvider(context.ml?.mlClient.callAsCurrentUser, request);
157+
context.ml && plugins.ml?.anomalyDetectorsProvider(context.ml?.mlClient, request);
161158
const spaceId = plugins.spaces?.spacesService.getSpaceId(request) || 'default';
162159

163160
return {

0 commit comments

Comments
 (0)