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

[Actions] System actions enhancements #161340

Merged
merged 65 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
1352e52
Add isSystemAction to ActionResult type and default it to false
cnasikas Jun 28, 2023
09b82f6
Disallow registering system actions
cnasikas Jun 28, 2023
dc1a2c8
Add test
cnasikas Jun 28, 2023
bb7e9a5
Fix alerting types
cnasikas Jun 28, 2023
774b389
Fix integration tests
cnasikas Jun 28, 2023
83ee747
Fix triggers_actions_ui types
cnasikas Jun 28, 2023
d2b8e67
Fix cases types
cnasikas Jun 28, 2023
31f1f39
Fix cases tests
cnasikas Jun 28, 2023
85ca6a4
Fix integration tests
cnasikas Jun 28, 2023
b070bd9
Fix cases tests
cnasikas Jun 28, 2023
a8e7143
Merge branch 'main' into system_actions_registration
kibanamachine Jun 29, 2023
b50a3e0
Fix types from other plugins
cnasikas Jun 29, 2023
ee5df7b
Merge branch 'system_actions_registration' of github.com:cnasikas/kib…
cnasikas Jun 29, 2023
1caf874
Rename preconfiguredConnectors to inMemoryConnectors
cnasikas Jun 29, 2023
2aabeed
Create system actions
cnasikas Jun 29, 2023
3cf469a
Prevent create/update/delete of system actions
cnasikas Jun 30, 2023
8c1246c
Fix types
cnasikas Jun 30, 2023
0d7aea1
Merge branch 'main' into load_system_actions_in_memory
cnasikas Jun 30, 2023
52ef0e5
Fix types
cnasikas Jun 30, 2023
d763161
Remove cases from basic
cnasikas Jul 1, 2023
5c3245e
Convert preconfigured to in-memory
cnasikas Jul 1, 2023
31bc750
Merge branch 'main' into load_system_actions_in_memory
cnasikas Jul 1, 2023
d35a7f9
Get in-memory connectors after they have been created in the route co…
cnasikas Jul 1, 2023
34ee2ab
Register test system action in integration tests
cnasikas Jul 1, 2023
86b279c
Add integration tests
cnasikas Jul 1, 2023
57b4d3a
Fix i18n
cnasikas Jul 2, 2023
a162163
Fix types
cnasikas Jul 2, 2023
2ea3c9c
Fix integration test
cnasikas Jul 2, 2023
7362b97
Fixes
cnasikas Jul 2, 2023
cbaeb1f
Merge branch 'main' into load_system_actions_in_memory
cnasikas Jul 3, 2023
a1b5d51
Filtered out system connectors in telemetry
cnasikas Jul 3, 2023
45c4690
Add the ability to pass additional privileges to the actions authoriz…
cnasikas Jul 3, 2023
2db46a0
Perform system actions RBAC
cnasikas Jul 3, 2023
9ebb327
Fix types and tests
cnasikas Jul 3, 2023
45f0265
Add unit tests
cnasikas Jul 4, 2023
e62faae
Add integration tests
cnasikas Jul 4, 2023
15da2b9
Add integration tests
cnasikas Jul 4, 2023
d7b05a9
Forbid registration of system action types in preconfigured connectors
cnasikas Jul 5, 2023
4b42071
Add system connector references
cnasikas Jul 5, 2023
813804c
Merge branch 'main' into forbid_system_action_from_config
cnasikas Jul 6, 2023
a8f3d0b
Add telemetry for system connectors
cnasikas Jul 6, 2023
17d3c6e
Merge branch 'main' into system_actions_rbac
cnasikas Jul 6, 2023
637a6b3
Merge branch 'main' into system_actions_rbac
cnasikas Jul 7, 2023
3a7e947
Merge branch 'main' into system_actions_refs
cnasikas Jul 7, 2023
eca005d
Fix tests
cnasikas Jul 8, 2023
0020ee9
Enhancements
cnasikas Jul 9, 2023
356432c
Pass params to system actions when getting kibana privileges
cnasikas Jul 9, 2023
4259f54
Fix integration tests
cnasikas Jul 9, 2023
c44f49d
Add integration tests for enqueue
cnasikas Jul 11, 2023
4035d11
Add integration tests for bulk_enqueue
cnasikas Jul 11, 2023
be7ec67
Add integration tests for spaces_only
cnasikas Jul 11, 2023
2c565b1
Fix integration tests
cnasikas Jul 11, 2023
a9e3bd5
Merge branch 'main' into system_actions_rbac
cnasikas Jul 11, 2023
72e9d72
Small improvements
cnasikas Jul 11, 2023
abe3edf
Merge branch 'system_actions_rbac' into system_actions_refs
cnasikas Jul 11, 2023
de1f454
Improvements
cnasikas Jul 12, 2023
a54dd07
Merge branch 'main' into system_actions_refs
cnasikas Jul 22, 2023
25a93f0
Fixes
cnasikas Jul 22, 2023
f479dff
Allow to disable system actions
cnasikas Jul 22, 2023
637a98f
Allow rules client to get system actions
cnasikas Jul 22, 2023
a04b5ae
Merge branch 'main' into system_actions_refs
kibanamachine Jul 24, 2023
9b0cc28
Merge branch 'main' into system_actions_refs
cnasikas Jul 28, 2023
4fa0b02
PR feedback
cnasikas Jul 28, 2023
96115ef
Merge branch 'system_actions_refs' of github.com:cnasikas/kibana into…
cnasikas Jul 28, 2023
9b94ea4
Merge branch 'main' into system_actions_refs
kibanamachine Jul 28, 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
35 changes: 19 additions & 16 deletions x-pack/plugins/actions/server/action_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ describe('actionTypeRegistry', () => {
isSystemAction: false,
},
{
actionTypeId: '.cases',
actionTypeId: 'test.system-action',
config: {},
id: 'system-connector-.cases',
name: 'System action: .cases',
id: 'system-connector-test.system-action',
name: 'System action: test.system-action',
secrets: {},
isPreconfigured: false,
isDeprecated: false,
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('actionTypeRegistry', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);

actionTypeRegistry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -410,7 +410,7 @@ describe('actionTypeRegistry', () => {

expect(actionTypes).toEqual([
{
id: '.cases',
id: 'test.system-action',
name: 'Cases',
enabled: true,
enabledInConfig: true,
Expand Down Expand Up @@ -497,13 +497,16 @@ describe('actionTypeRegistry', () => {
expect(actionTypeRegistry.isActionExecutable('my-slack1', 'foo')).toEqual(true);
});

test('should return true when isActionTypeEnabled is false and isLicenseValidForActionType is true and it has system connectors', async () => {
test('should return false when isActionTypeEnabled is false and isLicenseValidForActionType is true and it has system connectors', async () => {
mockedActionsConfig.isActionTypeEnabled.mockReturnValue(false);
mockedLicenseState.isLicenseValidForActionType.mockReturnValue({ isValid: true });

expect(
actionTypeRegistry.isActionExecutable('system-connector-.cases', 'system-action-type')
).toEqual(true);
actionTypeRegistry.isActionExecutable(
'system-connector-test.system-action',
'system-action-type'
)
).toEqual(false);
});

test('should call isLicenseValidForActionType of the license state with notifyUsage false by default', async () => {
Expand Down Expand Up @@ -662,7 +665,7 @@ describe('actionTypeRegistry', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);

registry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -675,7 +678,7 @@ describe('actionTypeRegistry', () => {
executor,
});

const result = registry.isSystemActionType('.cases');
const result = registry.isSystemActionType('test.system-action');
expect(result).toBe(true);
});

Expand Down Expand Up @@ -720,7 +723,7 @@ describe('actionTypeRegistry', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);

registry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -734,15 +737,15 @@ describe('actionTypeRegistry', () => {
executor,
});

const result = registry.getSystemActionKibanaPrivileges('.cases');
const result = registry.getSystemActionKibanaPrivileges('test.system-action');
expect(result).toEqual(['test/create']);
});

it('should return an empty array if the system action does not define any kibana privileges', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);

registry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -755,7 +758,7 @@ describe('actionTypeRegistry', () => {
executor,
});

const result = registry.getSystemActionKibanaPrivileges('.cases');
const result = registry.getSystemActionKibanaPrivileges('test.system-action');
expect(result).toEqual([]);
});

Expand Down Expand Up @@ -784,7 +787,7 @@ describe('actionTypeRegistry', () => {
const getKibanaPrivileges = jest.fn().mockReturnValue(['test/create']);

registry.register({
id: '.cases',
id: 'test.system-action',
name: 'Cases',
minimumLicenseRequired: 'platinum',
supportedFeatureIds: ['alerting'],
Expand All @@ -798,7 +801,7 @@ describe('actionTypeRegistry', () => {
executor,
});

registry.getSystemActionKibanaPrivileges('.cases', { foo: 'bar' });
registry.getSystemActionKibanaPrivileges('test.system-action', { foo: 'bar' });
expect(getKibanaPrivileges).toHaveBeenCalledWith({ params: { foo: 'bar' } });
});
});
Expand Down
13 changes: 7 additions & 6 deletions x-pack/plugins/actions/server/action_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,21 @@ export class ActionTypeRegistry {
}

/**
* Returns true if action type is enabled or it is an in memory action type.
* Returns true if action type is enabled or preconfigured.
* An action type can be disabled but used with a preconfigured action.
* This does not apply to system actions as those can be disabled.
*/
public isActionExecutable(
actionId: string,
actionTypeId: string,
options: { notifyUsage: boolean } = { notifyUsage: false }
) {
const actionTypeEnabled = this.isActionTypeEnabled(actionTypeId, options);
return (
actionTypeEnabled ||
(!actionTypeEnabled &&
this.inMemoryConnectors.find((inMemoryConnector) => inMemoryConnector.id === actionId) !==
undefined)
const inMemoryConnector = this.inMemoryConnectors.find(
(connector) => connector.id === actionId
);

return actionTypeEnabled || (!actionTypeEnabled && inMemoryConnector?.isPreconfigured === true);
}

/**
Expand Down
15 changes: 9 additions & 6 deletions x-pack/plugins/actions/server/actions_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ describe('getBulk()', () => {
connectorTokenClient: connectorTokenClientMock.create(),
getEventLogClient,
});
return actionsClient.getBulk(['1', 'testPreconfigured']);
return actionsClient.getBulk({ ids: ['1', 'testPreconfigured'] });
}

test('ensures user is authorised to get the type of action', async () => {
Expand Down Expand Up @@ -1709,7 +1709,7 @@ describe('getBulk()', () => {
}
);

await actionsClient.getBulk(['1']);
await actionsClient.getBulk({ ids: ['1'] });

expect(auditLogger.log).toHaveBeenCalledWith(
expect.objectContaining({
Expand All @@ -1725,7 +1725,7 @@ describe('getBulk()', () => {
test('logs audit event when not authorised to bulk get connectors', async () => {
authorization.ensureAuthorized.mockRejectedValue(new Error('Unauthorized'));

await expect(actionsClient.getBulk(['1'])).rejects.toThrow();
await expect(actionsClient.getBulk({ ids: ['1'] })).rejects.toThrow();

expect(auditLogger.log).toHaveBeenCalledWith(
expect.objectContaining({
Expand Down Expand Up @@ -1810,7 +1810,7 @@ describe('getBulk()', () => {
getEventLogClient,
});

const result = await actionsClient.getBulk(['1', 'testPreconfigured']);
const result = await actionsClient.getBulk({ ids: ['1', 'testPreconfigured'] });

expect(result).toEqual([
{
Expand Down Expand Up @@ -1907,7 +1907,7 @@ describe('getBulk()', () => {
});

await expect(
actionsClient.getBulk(['1', 'testPreconfigured', 'system-connector-.cases'])
actionsClient.getBulk({ ids: ['1', 'testPreconfigured', 'system-connector-.cases'] })
).rejects.toThrowErrorMatchingInlineSnapshot(`"Connector system-connector-.cases not found"`);
});

Expand Down Expand Up @@ -1982,7 +1982,10 @@ describe('getBulk()', () => {
});

expect(
await actionsClient.getBulk(['1', 'testPreconfigured', 'system-connector-.cases'], false)
await actionsClient.getBulk({
ids: ['1', 'testPreconfigured', 'system-connector-.cases'],
throwIfSystemAction: false,
})
).toEqual([
{
actionTypeId: '.slack',
Expand Down
11 changes: 7 additions & 4 deletions x-pack/plugins/actions/server/actions_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,13 @@ export class ActionsClient {
/**
* Get bulk actions with in-memory list
*/
public async getBulk(
ids: string[],
throwIfSystemAction: boolean = true
): Promise<ActionResult[]> {
public async getBulk({
ids,
throwIfSystemAction = true,
}: {
ids: string[];
throwIfSystemAction?: boolean;
}): Promise<ActionResult[]> {
try {
await this.authorization.ensureAuthorized({ operation: 'get' });
} catch (error) {
Expand Down
Loading
Loading