This PR adds _Role Based Access-Control_ to the Alerting framework & Actions feature using Kibana Feature Controls, addressing most of the Meta issue: https://github.com/elastic/kibana/issues/43994 This also closes https://github.com/elastic/kibana/issues/62438 This PR includes the following: 1. Adds `alerting` specific Security Actions (not to be confused with Alerting Actions) to the `security` plugin which allows us to assign alerting specific privileges to users of other plugins using the `features` plugin. 2. Removes the security wrapper from the savedObjectsClient in AlertsClient and instead plugs in the new AlertsAuthorization which performs the privilege checks on each api call made to the AlertsClient. 3. Adds privileges in each plugin that is already using the Alerting Framework which mirror (as closely as possible) the existing api-level tag-based privileges and plugs them into the AlertsClient. 4. Adds feature granted privileges arounds Actions (by relying on Saved Object privileges under the hood) and plugs them into the ActionsClient 5. Removes the legacy api-level tag-based privilege system from both the Alerts and Action HTTP APIs
82 lines
2.5 KiB
TypeScript
82 lines
2.5 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
*/
|
|
|
|
import { SavedObjectsClientContract } from '../../../../src/core/server';
|
|
import { TaskManagerStartContract } from '../../task_manager/server';
|
|
import { RawAction, ActionTypeRegistryContract, PreConfiguredAction } from './types';
|
|
import { ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE } from './saved_objects';
|
|
|
|
interface CreateExecuteFunctionOptions {
|
|
taskManager: TaskManagerStartContract;
|
|
isESOUsingEphemeralEncryptionKey: boolean;
|
|
actionTypeRegistry: ActionTypeRegistryContract;
|
|
preconfiguredActions: PreConfiguredAction[];
|
|
}
|
|
|
|
export interface ExecuteOptions {
|
|
id: string;
|
|
params: Record<string, unknown>;
|
|
spaceId: string;
|
|
apiKey: string | null;
|
|
}
|
|
|
|
export type ExecutionEnqueuer = (
|
|
savedObjectsClient: SavedObjectsClientContract,
|
|
options: ExecuteOptions
|
|
) => Promise<void>;
|
|
|
|
export function createExecutionEnqueuerFunction({
|
|
taskManager,
|
|
actionTypeRegistry,
|
|
isESOUsingEphemeralEncryptionKey,
|
|
preconfiguredActions,
|
|
}: CreateExecuteFunctionOptions) {
|
|
return async function execute(
|
|
savedObjectsClient: SavedObjectsClientContract,
|
|
{ id, params, spaceId, apiKey }: ExecuteOptions
|
|
) {
|
|
if (isESOUsingEphemeralEncryptionKey === true) {
|
|
throw new Error(
|
|
`Unable to execute action due to the Encrypted Saved Objects plugin using an ephemeral encryption key. Please set xpack.encryptedSavedObjects.encryptionKey in kibana.yml`
|
|
);
|
|
}
|
|
|
|
const actionTypeId = await getActionTypeId(id);
|
|
|
|
if (!actionTypeRegistry.isActionExecutable(id, actionTypeId)) {
|
|
actionTypeRegistry.ensureActionTypeEnabled(actionTypeId);
|
|
}
|
|
|
|
const actionTaskParamsRecord = await savedObjectsClient.create(
|
|
ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE,
|
|
{
|
|
actionId: id,
|
|
params,
|
|
apiKey,
|
|
}
|
|
);
|
|
|
|
await taskManager.schedule({
|
|
taskType: `actions:${actionTypeId}`,
|
|
params: {
|
|
spaceId,
|
|
actionTaskParamsId: actionTaskParamsRecord.id,
|
|
},
|
|
state: {},
|
|
scope: ['actions'],
|
|
});
|
|
|
|
async function getActionTypeId(actionId: string): Promise<string> {
|
|
const pcAction = preconfiguredActions.find((action) => action.id === actionId);
|
|
if (pcAction) {
|
|
return pcAction.actionTypeId;
|
|
}
|
|
|
|
const actionSO = await savedObjectsClient.get<RawAction>('action', actionId);
|
|
return actionSO.attributes.actionTypeId;
|
|
}
|
|
};
|
|
}
|