Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -550,6 +550,55 @@ describe('AlertingAuthorization', () => {
});
});

test('ensures the user has privileges to execute alerts when all features are disabled', async () => {
features.getKibanaFeatures.mockReturnValue([]);
const { authorization } = mockSecurity();
const checkPrivileges: jest.MockedFunction<
ReturnType<typeof authorization.checkPrivilegesDynamicallyWithRequest>
> = jest.fn();
authorization.checkPrivilegesDynamicallyWithRequest.mockReturnValue(checkPrivileges);
const alertAuthorization = new AlertingAuthorization({
request,
authorization,
ruleTypeRegistry,
features,
getSpace,
getSpaceId,
});

checkPrivileges.mockResolvedValueOnce({
username: 'some-user',
hasAllRequested: true,
privileges: { kibana: [] },
});

await alertAuthorization.ensureAuthorized({
ruleTypeId: 'myType',
consumer: 'alerts',
operation: WriteOperations.Update,
entity: AlertingAuthorizationEntity.Alert,
});

expect(ruleTypeRegistry.get).toHaveBeenCalledWith('myType');

expect(authorization.actions.alerting.get).toHaveBeenCalledTimes(2);
expect(authorization.actions.alerting.get).toHaveBeenCalledWith(
'myType',
'alerts',
'alert',
'update'
);
expect(authorization.actions.alerting.get).toHaveBeenCalledWith(
'myType',
'myApp',
'alert',
'update'
);
expect(checkPrivileges).toHaveBeenCalledWith({
kibana: [mockAuthorizationAction('myType', 'myApp', 'alert', 'update')],
});
});

test('throws if user lacks the required rule privileges for the consumer', async () => {
const { authorization } = mockSecurity();
const checkPrivileges: jest.MockedFunction<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,10 @@ export class AlertingAuthorization {
});

this.allPossibleConsumers = this.featuresIds.then((featuresIds) => {
return featuresIds.size
? asAuthorizedConsumers([ALERTS_FEATURE_ID, ...featuresIds], {
read: true,
all: true,
})
: {};
return asAuthorizedConsumers([ALERTS_FEATURE_ID, ...featuresIds], {
read: true,
all: true,
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,6 @@ export default function createAlertTests({ getService }: FtrProviderContext) {
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage('create', 'test.noop', 'alerts'),
statusCode: 403,
});
break;
case 'global_read at space1':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,9 @@ export default function createDeleteTests({ getService }: FtrProviderContext) {
.auth(user.username, user.password);

switch (scenario.id) {
case 'global_read at space1':
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage('delete', 'test.noop', 'alerts'),
statusCode: 403,
});
objectRemover.add(space.id, createdAlert.id, 'rule', 'alerting');
break;
case 'global_read at space1':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,6 @@ export default function createEnableAlertTests({ getService }: FtrProviderContex
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage('enable', 'test.noop', 'alerts'),
statusCode: 403,
});
break;
case 'global_read at space1':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,6 @@ const getTestUtils = (
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'get',
'test.restricted-noop',
'alerts'
),
statusCode: 403,
});
break;
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
expect(response.statusCode).to.eql(403);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,6 @@ export default function createMuteAlertTests({ getService }: FtrProviderContext)
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'muteAll',
'test.restricted-noop',
'alerts'
),
statusCode: 403,
});
break;
case 'global_read at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,6 @@ export default function createMuteAlertInstanceTests({ getService }: FtrProvider
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'muteAlert',
'test.restricted-noop',
'alerts'
),
statusCode: 403,
});
break;
case 'global_read at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,6 @@ export default function createSnoozeRuleTests({ getService }: FtrProviderContext
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'snooze',
'test.restricted-noop',
'alerts'
),
statusCode: 403,
});
break;
case 'global_read at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,6 @@ export default function createUnmuteAlertTests({ getService }: FtrProviderContex
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'unmuteAll',
'test.restricted-noop',
'alerts'
),
statusCode: 403,
});
break;
case 'global_read at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,6 @@ export default function createMuteAlertInstanceTests({ getService }: FtrProvider
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'unmuteAlert',
'test.restricted-noop',
'alerts'
),
statusCode: 403,
});
break;
case 'global_read at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,17 +378,6 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'update',
'test.restricted-noop',
'alerts'
),
statusCode: 403,
});
break;
case 'global_read at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,6 @@ export default function createUpdateApiKeyTests({ getService }: FtrProviderConte
switch (scenario.id) {
case 'no_kibana_privileges at space1':
case 'space_1_all at space2':
expect(response.statusCode).to.eql(403);
expect(response.body).to.eql({
error: 'Forbidden',
message: getConsumerUnauthorizedErrorMessage(
'updateApiKey',
'test.restricted-noop',
'alerts'
),
statusCode: 403,
});
break;
case 'global_read at space1':
case 'space_1_all at space1':
case 'space_1_all_alerts_none_actions at space1':
Expand Down