forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alerting] Exempt Alerts pre 7.10 from RBAC on their Action execution…
… until updated (elastic#75563) Marks all Alerts with a `versionApiKeyLastmodified ` field that tracks what version the alert's Api Key was last updated in. We then use this field to exempt legacy alerts (created pre `7.10.0`) in order to use a _dialed down_ version of RBAC which should allow old alerts to continue to function after the upgrade, until they are updates (at which point they will no longer be **Legacy**). More details here: elastic#74858 (comment)
- Loading branch information
Showing
41 changed files
with
4,411 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
x-pack/plugins/actions/server/authorization/should_legacy_rbac_apply_by_source.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
* 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 { shouldLegacyRbacApplyBySource } from './should_legacy_rbac_apply_by_source'; | ||
import { savedObjectsClientMock } from '../../../../../src/core/server/mocks'; | ||
import uuid from 'uuid'; | ||
import { asSavedObjectExecutionSource } from '../lib'; | ||
|
||
const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); | ||
|
||
describe(`#shouldLegacyRbacApplyBySource`, () => { | ||
test('should return false if no source is provided', async () => { | ||
expect(await shouldLegacyRbacApplyBySource(unsecuredSavedObjectsClient)).toEqual(false); | ||
}); | ||
|
||
test('should return false if source is not an alert', async () => { | ||
expect( | ||
await shouldLegacyRbacApplyBySource( | ||
unsecuredSavedObjectsClient, | ||
asSavedObjectExecutionSource({ | ||
type: 'action', | ||
id: uuid.v4(), | ||
}) | ||
) | ||
).toEqual(false); | ||
}); | ||
|
||
test('should return false if source alert is not marked as legacy', async () => { | ||
const id = uuid.v4(); | ||
unsecuredSavedObjectsClient.get.mockResolvedValue(mockAlert({ id })); | ||
expect( | ||
await shouldLegacyRbacApplyBySource( | ||
unsecuredSavedObjectsClient, | ||
asSavedObjectExecutionSource({ | ||
type: 'alert', | ||
id, | ||
}) | ||
) | ||
).toEqual(false); | ||
}); | ||
|
||
test('should return true if source alert is marked as legacy', async () => { | ||
const id = uuid.v4(); | ||
unsecuredSavedObjectsClient.get.mockResolvedValue( | ||
mockAlert({ id, attributes: { meta: { versionApiKeyLastmodified: 'pre-7.10.0' } } }) | ||
); | ||
expect( | ||
await shouldLegacyRbacApplyBySource( | ||
unsecuredSavedObjectsClient, | ||
asSavedObjectExecutionSource({ | ||
type: 'alert', | ||
id, | ||
}) | ||
) | ||
).toEqual(true); | ||
}); | ||
|
||
test('should return false if source alert is marked as modern', async () => { | ||
const id = uuid.v4(); | ||
unsecuredSavedObjectsClient.get.mockResolvedValue( | ||
mockAlert({ id, attributes: { meta: { versionApiKeyLastmodified: '7.10.0' } } }) | ||
); | ||
expect( | ||
await shouldLegacyRbacApplyBySource( | ||
unsecuredSavedObjectsClient, | ||
asSavedObjectExecutionSource({ | ||
type: 'alert', | ||
id, | ||
}) | ||
) | ||
).toEqual(false); | ||
}); | ||
|
||
test('should return false if source alert is marked with a last modified version', async () => { | ||
const id = uuid.v4(); | ||
unsecuredSavedObjectsClient.get.mockResolvedValue(mockAlert({ id, attributes: { meta: {} } })); | ||
expect( | ||
await shouldLegacyRbacApplyBySource( | ||
unsecuredSavedObjectsClient, | ||
asSavedObjectExecutionSource({ | ||
type: 'alert', | ||
id, | ||
}) | ||
) | ||
).toEqual(false); | ||
}); | ||
}); | ||
|
||
const mockAlert = (overrides: Record<string, unknown> = {}) => ({ | ||
id: '1', | ||
type: 'alert', | ||
attributes: { | ||
consumer: 'myApp', | ||
schedule: { interval: '10s' }, | ||
alertTypeId: 'myType', | ||
enabled: false, | ||
actions: [ | ||
{ | ||
group: 'default', | ||
id: '1', | ||
actionTypeId: '1', | ||
actionRef: '1', | ||
params: { | ||
foo: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
version: '123', | ||
references: [], | ||
...overrides, | ||
}); |
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/actions/server/authorization/should_legacy_rbac_apply_by_source.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* 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 { ActionExecutionSource, isSavedObjectExecutionSource } from '../lib'; | ||
import { ALERT_SAVED_OBJECT_TYPE } from '../saved_objects'; | ||
|
||
const LEGACY_VERSION = 'pre-7.10.0'; | ||
|
||
export async function shouldLegacyRbacApplyBySource( | ||
unsecuredSavedObjectsClient: SavedObjectsClientContract, | ||
executionSource?: ActionExecutionSource<unknown> | ||
): Promise<boolean> { | ||
return isSavedObjectExecutionSource(executionSource) && | ||
executionSource?.source?.type === ALERT_SAVED_OBJECT_TYPE | ||
? ( | ||
await unsecuredSavedObjectsClient.get<{ | ||
meta?: { | ||
versionApiKeyLastmodified?: string; | ||
}; | ||
}>(ALERT_SAVED_OBJECT_TYPE, executionSource.source.id) | ||
).attributes.meta?.versionApiKeyLastmodified === LEGACY_VERSION | ||
: false; | ||
} |
Oops, something went wrong.