Skip to content

Commit 5f842fb

Browse files
authored
[Alerting] Control Alerts Management via feature controls & privileges (#72029) (#73457)
This PR removes the alerting and actions ui privileges (alerting:show, actions:show, etc...) and instead relies on the standard Kibana feature control model to decide whether management displays the Alerts Management section under management.
1 parent b7a561a commit 5f842fb

File tree

16 files changed

+157
-139
lines changed

16 files changed

+157
-139
lines changed

examples/alerting_example/server/plugin.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export class AlertingExamplePlugin implements Plugin<void, void, AlertingExample
4444
defaultMessage: 'Alerts Example',
4545
}),
4646
app: [],
47+
management: {
48+
insightsAndAlerting: ['triggersActions'],
49+
},
4750
alerting: [alwaysFiringAlert.id, peopleInSpaceAlert.id, INDEX_THRESHOLD_ID],
4851
privileges: {
4952
all: {
@@ -54,7 +57,10 @@ export class AlertingExamplePlugin implements Plugin<void, void, AlertingExample
5457
all: [],
5558
read: [],
5659
},
57-
ui: ['alerting:show'],
60+
management: {
61+
insightsAndAlerting: ['triggersActions'],
62+
},
63+
ui: [],
5864
},
5965
read: {
6066
alerting: {
@@ -64,7 +70,10 @@ export class AlertingExamplePlugin implements Plugin<void, void, AlertingExample
6470
all: [],
6571
read: [],
6672
},
67-
ui: ['alerting:show'],
73+
management: {
74+
insightsAndAlerting: ['triggersActions'],
75+
},
76+
ui: [],
6877
},
6978
},
7079
});

x-pack/plugins/actions/server/feature.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ export const ACTIONS_FEATURE = {
1515
icon: 'bell',
1616
navLinkId: 'actions',
1717
app: [],
18+
management: {
19+
insightsAndAlerting: ['triggersActions'],
20+
},
1821
privileges: {
1922
all: {
2023
app: [],
2124
api: [],
2225
catalogue: [],
26+
management: {
27+
insightsAndAlerting: ['triggersActions'],
28+
},
2329
savedObject: {
2430
all: [ACTION_SAVED_OBJECT_TYPE, ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE],
2531
read: [],
@@ -30,6 +36,9 @@ export const ACTIONS_FEATURE = {
3036
app: [],
3137
api: [],
3238
catalogue: [],
39+
management: {
40+
insightsAndAlerting: ['triggersActions'],
41+
},
3342
savedObject: {
3443
// action execution requires 'read' over `actions`, but 'all' over `action_task_params`
3544
all: [ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE],

x-pack/plugins/alerting_builtins/server/feature.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ export const BUILT_IN_ALERTS_FEATURE = {
1515
}),
1616
icon: 'bell',
1717
app: [],
18+
management: {
19+
insightsAndAlerting: ['triggersActions'],
20+
},
1821
alerting: [IndexThreshold],
1922
privileges: {
2023
all: {
2124
app: [],
2225
catalogue: [],
26+
management: {
27+
insightsAndAlerting: ['triggersActions'],
28+
},
2329
alerting: {
2430
all: [IndexThreshold],
2531
read: [],
@@ -29,11 +35,14 @@ export const BUILT_IN_ALERTS_FEATURE = {
2935
read: [],
3036
},
3137
api: [],
32-
ui: ['alerting:show'],
38+
ui: [],
3339
},
3440
read: {
3541
app: [],
3642
catalogue: [],
43+
management: {
44+
insightsAndAlerting: ['triggersActions'],
45+
},
3746
alerting: {
3847
all: [],
3948
read: [IndexThreshold],
@@ -43,7 +52,7 @@ export const BUILT_IN_ALERTS_FEATURE = {
4352
read: [],
4453
},
4554
api: [],
46-
ui: ['alerting:show'],
55+
ui: [],
4756
},
4857
},
4958
};

x-pack/plugins/alerts/server/plugin.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ export class AlertingPlugin {
129129
this.spaces = plugins.spaces?.spacesService;
130130
this.security = plugins.security;
131131

132+
core.capabilities.registerProvider(() => {
133+
return {
134+
management: {
135+
insightsAndAlerting: {
136+
triggersActions: true,
137+
},
138+
},
139+
};
140+
});
141+
132142
this.isESOUsingEphemeralEncryptionKey =
133143
plugins.encryptedSavedObjects.usingEphemeralEncryptionKey;
134144

x-pack/plugins/apm/server/feature.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export const APM_FEATURE = {
1717
navLinkId: 'apm',
1818
app: ['apm', 'kibana'],
1919
catalogue: ['apm'],
20+
management: {
21+
insightsAndAlerting: ['triggersActions'],
22+
},
2023
alerting: Object.values(AlertType),
2124
// see x-pack/plugins/features/common/feature_kibana_privileges.ts
2225
privileges: {
@@ -31,6 +34,9 @@ export const APM_FEATURE = {
3134
alerting: {
3235
all: Object.values(AlertType),
3336
},
37+
management: {
38+
insightsAndAlerting: ['triggersActions'],
39+
},
3440
ui: ['show', 'save', 'alerting:show', 'alerting:save'],
3541
},
3642
read: {
@@ -44,6 +50,9 @@ export const APM_FEATURE = {
4450
alerting: {
4551
all: Object.values(AlertType),
4652
},
53+
management: {
54+
insightsAndAlerting: ['triggersActions'],
55+
},
4756
ui: ['show', 'alerting:show', 'alerting:save'],
4857
},
4958
},

x-pack/plugins/infra/server/features.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export const METRICS_FEATURE = {
1919
navLinkId: 'metrics',
2020
app: ['infra', 'metrics', 'kibana'],
2121
catalogue: ['infraops'],
22+
management: {
23+
insightsAndAlerting: ['triggersActions'],
24+
},
2225
alerting: [METRIC_THRESHOLD_ALERT_TYPE_ID, METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID],
2326
privileges: {
2427
all: {
@@ -32,7 +35,10 @@ export const METRICS_FEATURE = {
3235
alerting: {
3336
all: [METRIC_THRESHOLD_ALERT_TYPE_ID, METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID],
3437
},
35-
ui: ['show', 'configureSource', 'save', 'alerting:show'],
38+
management: {
39+
insightsAndAlerting: ['triggersActions'],
40+
},
41+
ui: ['show', 'configureSource', 'save'],
3642
},
3743
read: {
3844
app: ['infra', 'metrics', 'kibana'],
@@ -45,7 +51,10 @@ export const METRICS_FEATURE = {
4551
alerting: {
4652
all: [METRIC_THRESHOLD_ALERT_TYPE_ID, METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID],
4753
},
48-
ui: ['show', 'alerting:show'],
54+
management: {
55+
insightsAndAlerting: ['triggersActions'],
56+
},
57+
ui: ['show'],
4958
},
5059
},
5160
};

x-pack/plugins/security_solution/server/plugin.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
174174
navLinkId: APP_ID,
175175
app: [...securitySubPlugins, 'kibana'],
176176
catalogue: ['securitySolution'],
177+
management: {
178+
insightsAndAlerting: ['triggersActions'],
179+
},
177180
alerting: [SIGNALS_ID, NOTIFICATIONS_ID],
178181
privileges: {
179182
all: {
@@ -194,7 +197,10 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
194197
alerting: {
195198
all: [SIGNALS_ID, NOTIFICATIONS_ID],
196199
},
197-
ui: ['show', 'crud', 'alerting:show'],
200+
management: {
201+
insightsAndAlerting: ['triggersActions'],
202+
},
203+
ui: ['show', 'crud'],
198204
},
199205
read: {
200206
app: [...securitySubPlugins, 'kibana'],
@@ -214,7 +220,10 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
214220
alerting: {
215221
all: [SIGNALS_ID, NOTIFICATIONS_ID],
216222
},
217-
ui: ['show', 'alerting:show'],
223+
management: {
224+
insightsAndAlerting: ['triggersActions'],
225+
},
226+
ui: ['show'],
218227
},
219228
},
220229
});

x-pack/plugins/triggers_actions_ui/public/application/app.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import {
1717
ScopedHistory,
1818
} from 'kibana/public';
1919
import { Section, routeToAlertDetails } from './constants';
20-
import { AppContextProvider, useAppDependencies } from './app_context';
21-
import { hasShowAlertsCapability } from './lib/capabilities';
20+
import { AppContextProvider } from './app_context';
2221
import { ActionTypeModel, AlertTypeModel } from '../types';
2322
import { TypeRegistry } from './type_registry';
2423
import { ChartsPluginStart } from '../../../../../src/plugins/charts/public';
@@ -63,22 +62,17 @@ export const App = (appDeps: AppDeps) => {
6362
};
6463

6564
export const AppWithoutRouter = ({ sectionsRegex }: { sectionsRegex: string }) => {
66-
const { capabilities } = useAppDependencies();
67-
const canShowAlerts = hasShowAlertsCapability(capabilities);
68-
const DEFAULT_SECTION: Section = canShowAlerts ? 'alerts' : 'connectors';
6965
return (
7066
<Switch>
7167
<Route
7268
path={`/:section(${sectionsRegex})`}
7369
component={suspendedComponentWithProps(TriggersActionsUIHome, 'xl')}
7470
/>
75-
{canShowAlerts && (
76-
<Route
77-
path={routeToAlertDetails}
78-
component={suspendedComponentWithProps(AlertDetailsRoute, 'xl')}
79-
/>
80-
)}
81-
<Redirect from={'/'} to={`${DEFAULT_SECTION}`} />
71+
<Route
72+
path={routeToAlertDetails}
73+
component={suspendedComponentWithProps(AlertDetailsRoute, 'xl')}
74+
/>
75+
<Redirect from={'/'} to="alerts" />
8276
</Switch>
8377
);
8478
};

x-pack/plugins/triggers_actions_ui/public/application/home.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { Section, routeToConnectors, routeToAlerts } from './constants';
2525
import { getCurrentBreadcrumb } from './lib/breadcrumb';
2626
import { getCurrentDocTitle } from './lib/doc_title';
2727
import { useAppDependencies } from './app_context';
28-
import { hasShowActionsCapability, hasShowAlertsCapability } from './lib/capabilities';
28+
import { hasShowActionsCapability } from './lib/capabilities';
2929

3030
import { ActionsConnectorsList } from './sections/actions_connectors_list/components/actions_connectors_list';
3131
import { AlertsList } from './sections/alerts_list/components/alerts_list';
@@ -45,23 +45,17 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<
4545
const { chrome, capabilities, setBreadcrumbs, docLinks, http } = useAppDependencies();
4646

4747
const canShowActions = hasShowActionsCapability(capabilities);
48-
const canShowAlerts = hasShowAlertsCapability(capabilities);
4948
const tabs: Array<{
5049
id: Section;
5150
name: React.ReactNode;
5251
}> = [];
5352

54-
if (canShowAlerts) {
55-
tabs.push({
56-
id: 'alerts',
57-
name: (
58-
<FormattedMessage
59-
id="xpack.triggersActionsUI.home.alertsTabTitle"
60-
defaultMessage="Alerts"
61-
/>
62-
),
63-
});
64-
}
53+
tabs.push({
54+
id: 'alerts',
55+
name: (
56+
<FormattedMessage id="xpack.triggersActionsUI.home.alertsTabTitle" defaultMessage="Alerts" />
57+
),
58+
});
6559

6660
if (canShowActions) {
6761
tabs.push({
@@ -151,17 +145,15 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<
151145
)}
152146
/>
153147
)}
154-
{canShowAlerts && (
155-
<Route
156-
exact
157-
path={routeToAlerts}
158-
component={() => (
159-
<HealthCheck docLinks={docLinks} http={http}>
160-
<AlertsList />
161-
</HealthCheck>
162-
)}
163-
/>
164-
)}
148+
<Route
149+
exact
150+
path={routeToAlerts}
151+
component={() => (
152+
<HealthCheck docLinks={docLinks} http={http}>
153+
<AlertsList />
154+
</HealthCheck>
155+
)}
156+
/>
165157
</Switch>
166158
</EuiPageContent>
167159
</EuiPageBody>

x-pack/plugins/triggers_actions_ui/public/application/lib/capabilities.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { BUILT_IN_ALERTS_FEATURE_ID } from '../../../../alerting_builtins/common';
87
import { Alert, AlertType } from '../../types';
98

109
/**
@@ -15,18 +14,6 @@ import { Alert, AlertType } from '../../types';
1514

1615
type Capabilities = Record<string, any>;
1716

18-
const apps = ['apm', 'siem', 'uptime', 'infrastructure', 'actions', BUILT_IN_ALERTS_FEATURE_ID];
19-
20-
function hasCapability(capabilities: Capabilities, capability: string) {
21-
return apps.some((app) => capabilities[app]?.[capability]);
22-
}
23-
24-
function createCapabilityCheck(capability: string) {
25-
return (capabilities: Capabilities) => hasCapability(capabilities, capability);
26-
}
27-
28-
export const hasShowAlertsCapability = createCapabilityCheck('alerting:show');
29-
3017
export const hasShowActionsCapability = (capabilities: Capabilities) => capabilities?.actions?.show;
3118
export const hasSaveActionsCapability = (capabilities: Capabilities) => capabilities?.actions?.save;
3219
export const hasExecuteActionsCapability = (capabilities: Capabilities) =>

0 commit comments

Comments
 (0)