Skip to content

Commit

Permalink
Do not allow setting kibana privileges if it is not a system action type
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jul 13, 2023
1 parent a8ea16b commit dddcc8e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 24 deletions.
47 changes: 23 additions & 24 deletions x-pack/plugins/actions/server/action_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,29 @@ describe('actionTypeRegistry', () => {
})
).not.toThrow();
});

test('throws if the kibana privileges are defined but the action type is not a system action type', () => {
const actionTypeRegistry = new ActionTypeRegistry(actionTypeRegistryParams);

expect(() =>
actionTypeRegistry.register({
id: 'my-action-type',
name: 'My action type',
minimumLicenseRequired: 'basic',
supportedFeatureIds: ['alerting'],
getKibanaPrivileges: jest.fn(),
isSystemActionType: false,
validate: {
config: { schema: schema.object({}) },
secrets: { schema: schema.object({}) },
params: { schema: schema.object({}) },
},
executor,
})
).toThrowErrorMatchingInlineSnapshot(
`"Kibana privilege authorization is only supported for system action types"`
);
});
});

describe('get()', () => {
Expand Down Expand Up @@ -756,30 +779,6 @@ describe('actionTypeRegistry', () => {
expect(result).toEqual([]);
});

it('should return an empty array if the action type is not a system action but defines kibana privileges', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);
const getKibanaPrivileges = jest.fn().mockReturnValue(['test/create']);

registry.register({
id: 'foo',
name: 'Foo',
minimumLicenseRequired: 'basic',
supportedFeatureIds: ['alerting'],
getKibanaPrivileges,
validate: {
config: { schema: schema.object({}) },
secrets: { schema: schema.object({}) },
params: { schema: schema.object({}) },
},
executor,
});

const result = registry.getSystemActionKibanaPrivileges('foo');

expect(result).toEqual([]);
expect(getKibanaPrivileges).not.toHaveBeenCalled();
});

it('should pass the metadata correctly', () => {
const registry = new ActionTypeRegistry(actionTypeRegistryParams);
const getKibanaPrivileges = jest.fn().mockReturnValue(['test/create']);
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/actions/server/action_type_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ export class ActionTypeRegistry {
);
}

if (!actionType.isSystemActionType && actionType.getKibanaPrivileges) {
throw new Error(
i18n.translate('xpack.actions.actionTypeRegistry.register.invalidKibanaPrivileges', {
defaultMessage:
'Kibana privilege authorization is only supported for system action types',
values: {
connectorTypeId: actionType.id,
ids: actionType.supportedFeatureIds.join(','),
},
})
);
}

const maxAttempts = this.actionsConfigUtils.getMaxAttempts({
actionTypeId: actionType.id,
actionTypeMaxAttempts: actionType.maxAttempts,
Expand Down

0 comments on commit dddcc8e

Please sign in to comment.