Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Response Ops][Actions] Keep track of action execution source and show in connector exec log #152030

Merged
merged 24 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
53ed1fa
Requiring source in action executor execute function. Persisting sour…
ymao1 Feb 23, 2023
0da4e47
Merge
ymao1 Feb 23, 2023
7e7c492
Fixing unit tests
ymao1 Feb 23, 2023
10f09a0
Fixing types and tests
ymao1 Feb 23, 2023
56b0869
Merge branch 'main' of github.com:elastic/kibana into actions/executi…
ymao1 Feb 23, 2023
9c43d47
Making sourceType optional
ymao1 Feb 23, 2023
963ddd2
Merge branch 'main' of github.com:elastic/kibana into actions/executi…
ymao1 Feb 24, 2023
1114477
Showing source on exec log
ymao1 Feb 24, 2023
bfe1318
Fixing tests
ymao1 Feb 24, 2023
1da3486
Merge branch 'main' of github.com:elastic/kibana into actions/executi…
ymao1 Feb 27, 2023
885c1de
Adding functional tests
ymao1 Feb 27, 2023
8e270b4
dont need to index new field
ymao1 Feb 27, 2023
6a523cc
cleanup
ymao1 Feb 27, 2023
79febfc
cleanup
ymao1 Feb 27, 2023
705d5f8
Merge branch 'actions/execution-source' of github.com:ymao1/kibana in…
ymao1 Feb 27, 2023
4a548f6
Merge branch 'main' of github.com:elastic/kibana into actions/executi…
ymao1 Mar 1, 2023
91209de
Differentiating between saved object sources and lowercasing the string
ymao1 Mar 1, 2023
8400bcc
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Mar 1, 2023
ce7e26c
Merge branch 'main' into actions/execution-source
kibanamachine Mar 6, 2023
7ddb632
Merging in main
ymao1 Mar 8, 2023
af17277
Adding dynamic false to action task param mappings
ymao1 Mar 8, 2023
3337e33
Merge branch 'actions/execution-source' of github.com:ymao1/kibana in…
ymao1 Mar 8, 2023
6b3609b
Fixing test
ymao1 Mar 8, 2023
0318ba9
Merge branch 'main' of github.com:elastic/kibana into actions/executi…
ymao1 Mar 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
expect(hashMap).toMatchInlineSnapshot(`
Object {
"action": "6cfc277ed3211639e37546ac625f4a68f2494215",
"action_task_params": "db2afea7d78e00e725486b791554d0d4e81956ef",
"action_task_params": "c2cb5c9060322e3e51c9e65debd8df48c0e54b8f",
"alert": "2568bf6d8ba0876441c61c9e58e08016c1dc1617",
"api_key_pending_invalidation": "16e7bcf8e78764102d7f525542d5b616809a21ee",
"apm-indices": "d19dd7fb51f2d2cbc1f8769481721e0953f9a6d2",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/actions/common/execution_log_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IExecutionLog {
connector_name: string;
connector_id: string;
timed_out: boolean;
source: string;
}

export interface IExecutionLogResult {
Expand Down
28 changes: 27 additions & 1 deletion x-pack/plugins/actions/server/actions_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { ByteSizeValue } from '@kbn/config-schema';
import { ActionTypeRegistry, ActionTypeRegistryOpts } from './action_type_registry';
import { ActionsClient } from './actions_client';
import { ExecutorType, ActionType } from './types';
import { ActionExecutor, TaskRunnerFactory, ILicenseState } from './lib';
import {
ActionExecutor,
TaskRunnerFactory,
ILicenseState,
asHttpRequestExecutionSource,
} from './lib';
import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks';
import { actionsConfigMock } from './actions_config.mock';
import { getActionsConfigurationUtilities } from './actions_config';
Expand Down Expand Up @@ -2171,6 +2176,7 @@ describe('execute()', () => {
params: {
name: 'my name',
},
source: asHttpRequestExecutionSource(request),
});
expect(authorization.ensureAuthorized).toHaveBeenCalledWith('execute');
});
Expand All @@ -2189,6 +2195,7 @@ describe('execute()', () => {
params: {
name: 'my name',
},
source: asHttpRequestExecutionSource(request),
})
).rejects.toMatchInlineSnapshot(`[Error: Unauthorized to execute all actions]`);

Expand All @@ -2205,6 +2212,7 @@ describe('execute()', () => {
params: {
name: 'my name',
},
source: asHttpRequestExecutionSource(request),
});

expect(trackLegacyRBACExemption as jest.Mock).toBeCalledWith('execute', mockUsageCounter);
Expand All @@ -2221,6 +2229,7 @@ describe('execute()', () => {
params: {
name: 'my name',
},
source: asHttpRequestExecutionSource(request),
})
).resolves.toMatchObject({ status: 'ok', actionId });

Expand All @@ -2231,6 +2240,7 @@ describe('execute()', () => {
name: 'my name',
},
actionExecutionId,
sourceType: 'HTTP_REQUEST',
});

await expect(
Expand All @@ -2239,6 +2249,7 @@ describe('execute()', () => {
params: {
name: 'my name',
},
source: asHttpRequestExecutionSource(request),
relatedSavedObjects: [
{
id: 'some-id',
Expand All @@ -2263,6 +2274,7 @@ describe('execute()', () => {
},
],
actionExecutionId,
sourceType: 'HTTP_REQUEST',
});

await expect(
Expand All @@ -2271,6 +2283,7 @@ describe('execute()', () => {
params: {
name: 'my name',
},
source: asHttpRequestExecutionSource(request),
relatedSavedObjects: [
{
id: 'some-id',
Expand All @@ -2288,6 +2301,7 @@ describe('execute()', () => {
params: {
name: 'my name',
},
sourceType: 'HTTP_REQUEST',
relatedSavedObjects: [
{
id: 'some-id',
Expand All @@ -2313,6 +2327,7 @@ describe('enqueueExecution()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
});
expect(authorization.ensureAuthorized).toHaveBeenCalledWith('execute');
});
Expand All @@ -2332,6 +2347,7 @@ describe('enqueueExecution()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
})
).rejects.toMatchInlineSnapshot(`[Error: Unauthorized to execute all actions]`);

Expand All @@ -2349,6 +2365,7 @@ describe('enqueueExecution()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
});

expect(trackLegacyRBACExemption as jest.Mock).toBeCalledWith(
Expand All @@ -2365,6 +2382,7 @@ describe('enqueueExecution()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: Buffer.from('123:abc').toString('base64'),
source: asHttpRequestExecutionSource(request),
};
await expect(actionsClient.enqueueExecution(opts)).resolves.toMatchInlineSnapshot(`undefined`);

Expand All @@ -2385,13 +2403,15 @@ describe('bulkEnqueueExecution()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
{
id: uuidv4(),
params: {},
spaceId: 'default',
executionId: '456def',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
]);
expect(authorization.ensureAuthorized).toHaveBeenCalledWith('execute');
Expand All @@ -2413,13 +2433,15 @@ describe('bulkEnqueueExecution()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
{
id: uuidv4(),
params: {},
spaceId: 'default',
executionId: '456def',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
])
).rejects.toMatchInlineSnapshot(`[Error: Unauthorized to execute all actions]`);
Expand All @@ -2439,13 +2461,15 @@ describe('bulkEnqueueExecution()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
{
id: uuidv4(),
params: {},
spaceId: 'default',
executionId: '456def',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
]);

Expand All @@ -2468,13 +2492,15 @@ describe('bulkEnqueueExecution()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
{
id: uuidv4(),
params: {},
spaceId: 'default',
executionId: '456def',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
];
await expect(actionsClient.bulkEnqueueExecution(opts)).resolves.toMatchInlineSnapshot(
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/actions/server/actions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,9 @@ export class ActionsClient {
params,
source,
relatedSavedObjects,
}: Omit<ExecuteOptions, 'request' | 'actionExecutionId'>): Promise<
ActionTypeExecutorResult<unknown>
> {
}: Omit<ExecuteOptions, 'request' | 'actionExecutionId' | 'sourceType'> & {
source: ActionExecutionSource<unknown>;
}): Promise<ActionTypeExecutorResult<unknown>> {
if (
(await getAuthorizationModeBySource(this.unsecuredSavedObjectsClient, source)) ===
AuthorizationMode.RBAC
Expand All @@ -682,7 +682,7 @@ export class ActionsClient {
return this.actionExecutor.execute({
actionId,
params,
source,
sourceType: source.type,
request: this.request,
relatedSavedObjects,
actionExecutionId: uuidv4(),
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/actions/server/constants/event_log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ export const EVENT_LOG_PROVIDER = 'actions';
export const EVENT_LOG_ACTIONS = {
execute: 'execute',
executeStart: 'execute-start',
executeViaHttp: 'execute-via-http',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically different event log actions means a different document is written out (we write out separate docs for execute and execute-start. In this case, it doesn't seem to make sense to write out a different doc for execute-via-http and it made more sense to store the source in the execute doc. This value was unused anyway, so I removed it.

executeTimeout: 'execute-timeout',
};
18 changes: 18 additions & 0 deletions x-pack/plugins/actions/server/create_execute_function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('execute()', () => {
actionId: '123',
params: { baz: false },
executionId: '123abc',
source: 'HTTP_REQUEST',
apiKey: Buffer.from('123:abc').toString('base64'),
},
{
Expand Down Expand Up @@ -151,6 +152,7 @@ describe('execute()', () => {
params: { baz: false },
executionId: '123abc',
consumer: 'test-consumer',
source: 'HTTP_REQUEST',
apiKey: Buffer.from('123:abc').toString('base64'),
},
{
Expand Down Expand Up @@ -213,6 +215,7 @@ describe('execute()', () => {
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
source: 'HTTP_REQUEST',
relatedSavedObjects: [
{
id: 'related_some-type_0',
Expand Down Expand Up @@ -303,6 +306,7 @@ describe('execute()', () => {
actionId: '123',
params: { baz: false },
executionId: '123abc',
source: 'SAVED_OBJECT',
apiKey: Buffer.from('123:abc').toString('base64'),
},
{
Expand Down Expand Up @@ -390,6 +394,7 @@ describe('execute()', () => {
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
source: 'SAVED_OBJECT',
relatedSavedObjects: [
{
id: 'related_some-type_0',
Expand Down Expand Up @@ -430,6 +435,7 @@ describe('execute()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unable to execute action because the Encrypted Saved Objects plugin is missing encryption key. Please set xpack.encryptedSavedObjects.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command."`
Expand Down Expand Up @@ -460,6 +466,7 @@ describe('execute()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
})
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Unable to execute action because no secrets are defined for the \\"mock-action\\" connector."`
Expand Down Expand Up @@ -493,6 +500,7 @@ describe('execute()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
})
).rejects.toThrowErrorMatchingInlineSnapshot(`"Fail"`);
});
Expand Down Expand Up @@ -537,6 +545,7 @@ describe('execute()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
});

expect(mockedActionTypeRegistry.ensureActionTypeEnabled).not.toHaveBeenCalled();
Expand Down Expand Up @@ -613,6 +622,7 @@ describe('bulkExecute()', () => {
actionId: '123',
params: { baz: false },
executionId: '123abc',
source: 'HTTP_REQUEST',
apiKey: Buffer.from('123:abc').toString('base64'),
},
references: [
Expand Down Expand Up @@ -703,6 +713,7 @@ describe('bulkExecute()', () => {
params: { baz: false },
executionId: '123abc',
consumer: 'test-consumer',
source: 'HTTP_REQUEST',
apiKey: Buffer.from('123:abc').toString('base64'),
},
references: [
Expand Down Expand Up @@ -778,6 +789,7 @@ describe('bulkExecute()', () => {
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
source: 'HTTP_REQUEST',
relatedSavedObjects: [
{
id: 'related_some-type_0',
Expand Down Expand Up @@ -885,6 +897,7 @@ describe('bulkExecute()', () => {
actionId: '123',
params: { baz: false },
executionId: '123abc',
source: 'SAVED_OBJECT',
apiKey: Buffer.from('123:abc').toString('base64'),
},
references: [
Expand Down Expand Up @@ -989,6 +1002,7 @@ describe('bulkExecute()', () => {
params: { baz: false },
apiKey: Buffer.from('123:abc').toString('base64'),
executionId: '123abc',
source: 'SAVED_OBJECT',
relatedSavedObjects: [
{
id: 'related_some-type_0',
Expand Down Expand Up @@ -1031,6 +1045,7 @@ describe('bulkExecute()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
])
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down Expand Up @@ -1067,6 +1082,7 @@ describe('bulkExecute()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
])
).rejects.toThrowErrorMatchingInlineSnapshot(
Expand Down Expand Up @@ -1106,6 +1122,7 @@ describe('bulkExecute()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
])
).rejects.toThrowErrorMatchingInlineSnapshot(`"Fail"`);
Expand Down Expand Up @@ -1162,6 +1179,7 @@ describe('bulkExecute()', () => {
spaceId: 'default',
executionId: '123abc',
apiKey: null,
source: asHttpRequestExecutionSource(request),
},
]);

Expand Down
Loading