-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x][ResponseOps] Upgrade assistant - cleanup alerting RBAC exceptio…
…n code (#203030) Resolves elastic/response-ops-team#250 ## Summary Adds a deprecation to the upgrade assistant to warn users that the legacy RBAC exemption code will be removed in 9.0 and provide mitigation steps. ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify 1. Start Kibana 2. Save this rule that has `versionApiKeyLastmodified: pre-7.10.0` to an .ndjson file and import. ``` {"attributes":{"actions":[{"actionRef":"system_action:system-connector-.system-log-example","actionTypeId":".system-log-example","params":{"message":"Alerts have been triggered."},"uuid":"f714d779-acc4-471d-8838-2b14df5ced01"}],"alertDelay":{"active":1},"alertTypeId":"example.always-firing","apiKey":null,"apiKeyCreatedByUser":null,"apiKeyOwner":null,"consumer":"alerts","createdAt":"2024-12-06T19:00:29.433Z","createdBy":"elastic","enabled":false,"executionStatus":{"error":null,"lastExecutionDate":"2024-12-06T19:55:20.506Z","status":"pending","warning":null},"lastRun":{"alertsCount":{"active":5,"ignored":0,"new":5,"recovered":5},"outcome":"succeeded","outcomeMsg":null,"outcomeOrder":0,"warning":null},"legacyId":null,"meta":{"versionApiKeyLastmodified":"pre-7.10.0"},"monitoring":{"run":{"calculated_metrics":{"p50":640,"p95":1092,"p99":1121,"success_ratio":1},"history":[],"last_run":{"metrics":{"duration":951,"gap_duration_s":null,"total_alerts_created":null,"total_alerts_detected":null,"total_indexing_duration_ms":null,"total_search_duration_ms":null},"timestamp":"2024-12-06T19:54:58.676Z"}}},"muteAll":false,"mutedInstanceIds":[],"name":"legacy-rule","nextRun":"2024-12-06T19:55:58.467Z","notifyWhen":null,"params":{},"revision":1,"running":false,"schedule":{"interval":"1m"},"scheduledTaskId":null,"snoozeSchedule":[],"tags":[],"throttle":null,"updatedAt":"2024-12-06T19:38:30.530Z","updatedBy":"elastic"},"coreMigrationVersion":"8.8.0","created_at":"2024-12-06T19:38:30.531Z","id":"2449a0be-cb40-40da-89f6-2f16972c8d1b","managed":false,"references":[],"type":"alert","typeMigrationVersion":"10.3.0","updated_at":"2024-12-06T19:38:30.531Z","version":"WzMxNSwxXQ=="} {"excludedObjects":[],"excludedObjectsCount":0,"exportedCount":1,"missingRefCount":0,"missingReferences":[]} ``` 4. Check the [deprecation page](http://localhost:5601/app/management/stack/upgrade_assistant/kibana_deprecations) to verify that the legacy RBAC exemption deprecation is registered. 5. Edit the rule and save 6. Repeat step 3 and verify that the deprecation warning has been resolved. --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Lisa Cawley <[email protected]>
- Loading branch information
1 parent
c4658e7
commit 7b7dd4e
Showing
8 changed files
with
233 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { CoreSetup } from '@kbn/core/server'; | ||
import { getLegacyRbacDeprecationsInfo } from './legacy_rbac'; | ||
|
||
export const registerDeprecations = ({ core }: { core: CoreSetup }) => { | ||
core.deprecations.registerDeprecations({ | ||
getDeprecations: async (context) => { | ||
return [...(await getLegacyRbacDeprecationsInfo(context, core.docLinks))]; | ||
}, | ||
}); | ||
}; |
79 changes: 79 additions & 0 deletions
79
x-pack/plugins/alerting/server/deprecations/legacy_rbac.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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { GetDeprecationsContext } from '@kbn/core/server'; | ||
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; | ||
import { SearchHit } from '@kbn/es-types'; | ||
import { docLinksServiceMock } from '@kbn/core-doc-links-server-mocks'; | ||
import { getLegacyRbacDeprecationsInfo } from './legacy_rbac'; | ||
|
||
let context: GetDeprecationsContext; | ||
const esClient = elasticsearchClientMock.createScopedClusterClient(); | ||
const docsLinks = docLinksServiceMock.createSetupContract(); | ||
|
||
describe('getLegacyRbacDeprecationsInfo', () => { | ||
beforeEach(async () => { | ||
context = { esClient } as unknown as GetDeprecationsContext; | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
test('does not return deprecations when there is no legacyRBACExemption usage', async () => { | ||
esClient.asCurrentUser.search.mockResponse({ | ||
took: 1, | ||
timed_out: false, | ||
_shards: { | ||
total: 1, | ||
successful: 1, | ||
skipped: 0, | ||
failed: 0, | ||
}, | ||
hits: { | ||
hits: [], | ||
}, | ||
}); | ||
expect(await getLegacyRbacDeprecationsInfo(context, docsLinks)).toMatchInlineSnapshot( | ||
`Array []` | ||
); | ||
}); | ||
|
||
test('does return deprecations when there is legacyRBACExemption usage', async () => { | ||
esClient.asCurrentUser.search.mockResponse({ | ||
took: 1, | ||
timed_out: false, | ||
_shards: { | ||
total: 1, | ||
successful: 1, | ||
skipped: 0, | ||
failed: 0, | ||
}, | ||
hits: { | ||
hits: [{} as SearchHit<unknown>], | ||
}, | ||
}); | ||
|
||
expect(await getLegacyRbacDeprecationsInfo(context, docsLinks)).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"correctiveActions": Object { | ||
"manualSteps": Array [ | ||
"To identify the affected rules run the query in Dev Tools that is linked under Learn more.", | ||
"To use normal RBAC authorization, update the API key by editing the rule.", | ||
], | ||
}, | ||
"deprecationType": "feature", | ||
"documentationUrl": "https://www.elastic.co/guide/en/kibana/test-branch/breaking-changes-summary.html#breaking-legacy-rbac", | ||
"level": "warning", | ||
"message": "The legacy role-based action control exemption for alerting rules has been removed in future versions. This cluster has alerting rules triggering actions that rely on the legacy exemption. The rules will fail to trigger actions for alerts.", | ||
"title": "Legacy RBAC exemption", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
79 changes: 79 additions & 0 deletions
79
x-pack/plugins/alerting/server/deprecations/legacy_rbac.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,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { DeprecationsDetails } from '@kbn/core-deprecations-common'; | ||
import { GetDeprecationsContext } from '@kbn/core-deprecations-server'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { DocLinksServiceSetup } from '@kbn/core/server'; | ||
|
||
export const getLegacyRbacDeprecationsInfo = async ( | ||
{ esClient }: GetDeprecationsContext, | ||
docLinks: DocLinksServiceSetup | ||
): Promise<DeprecationsDetails[]> => { | ||
const { hits: legacyRBACExemptions } = await esClient.asCurrentUser.search({ | ||
index: '.kibana*', | ||
body: { | ||
runtime_mappings: { | ||
apiKeyVersion: { | ||
type: 'keyword', | ||
script: { | ||
source: | ||
"def alert = params._source['alert']; if (alert != null) { def meta = alert.meta; if (meta != null) { emit(meta.versionApiKeyLastmodified); } else { emit('');}}", | ||
}, | ||
}, | ||
}, | ||
size: 10000, | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
term: { | ||
type: 'alert', | ||
}, | ||
}, | ||
{ | ||
term: { | ||
apiKeyVersion: 'pre-7.10.0', | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
_source: ['alert.name', 'namespaces'], | ||
}, | ||
}); | ||
|
||
if (legacyRBACExemptions.hits.length) { | ||
return [ | ||
{ | ||
title: i18n.translate('xpack.alerting.deprecations.legacyRbacExemption.title', { | ||
defaultMessage: 'Legacy RBAC exemption', | ||
}), | ||
level: 'warning', | ||
deprecationType: 'feature', | ||
message: i18n.translate('xpack.alerting.deprecations.legacyRbacExemption.message', { | ||
defaultMessage: | ||
'The legacy role-based action control exemption for alerting rules has been removed in future versions. This cluster has alerting rules triggering actions that rely on the legacy exemption. The rules will fail to trigger actions for alerts.', | ||
}), | ||
correctiveActions: { | ||
manualSteps: [ | ||
i18n.translate('xpack.alerting.deprecations.legacyRbacExemption.manualStepOne', { | ||
defaultMessage: | ||
'To identify the affected rules run the query in Dev Tools that is linked under Learn more.', | ||
}), | ||
i18n.translate('xpack.alerting.deprecations.legacyRbacExemption.manualStepTwo', { | ||
defaultMessage: | ||
'To use normal RBAC authorization, update the API key by editing the rule.', | ||
}), | ||
], | ||
}, | ||
documentationUrl: docLinks.links.alerting.legacyRbacExemption, | ||
}, | ||
]; | ||
} | ||
return []; | ||
}; |
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