Skip to content

Commit

Permalink
[Alerting] Control Alerts Management via feature controls & privileges (
Browse files Browse the repository at this point in the history
#72029)

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.
  • Loading branch information
gmmorris authored Jul 28, 2020
1 parent dca4a23 commit f410474
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 139 deletions.
13 changes: 11 additions & 2 deletions examples/alerting_example/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class AlertingExamplePlugin implements Plugin<void, void, AlertingExample
defaultMessage: 'Alerts Example',
}),
app: [],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: [alwaysFiringAlert.id, peopleInSpaceAlert.id, INDEX_THRESHOLD_ID],
privileges: {
all: {
Expand All @@ -54,7 +57,10 @@ export class AlertingExamplePlugin implements Plugin<void, void, AlertingExample
all: [],
read: [],
},
ui: ['alerting:show'],
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: [],
},
read: {
alerting: {
Expand All @@ -64,7 +70,10 @@ export class AlertingExamplePlugin implements Plugin<void, void, AlertingExample
all: [],
read: [],
},
ui: ['alerting:show'],
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: [],
},
},
});
Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/actions/server/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ export const ACTIONS_FEATURE = {
icon: 'bell',
navLinkId: 'actions',
app: [],
management: {
insightsAndAlerting: ['triggersActions'],
},
privileges: {
all: {
app: [],
api: [],
catalogue: [],
management: {
insightsAndAlerting: ['triggersActions'],
},
savedObject: {
all: [ACTION_SAVED_OBJECT_TYPE, ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE],
read: [],
Expand All @@ -30,6 +36,9 @@ export const ACTIONS_FEATURE = {
app: [],
api: [],
catalogue: [],
management: {
insightsAndAlerting: ['triggersActions'],
},
savedObject: {
// action execution requires 'read' over `actions`, but 'all' over `action_task_params`
all: [ACTION_TASK_PARAMS_SAVED_OBJECT_TYPE],
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/alerting_builtins/server/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ export const BUILT_IN_ALERTS_FEATURE = {
}),
icon: 'bell',
app: [],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: [IndexThreshold],
privileges: {
all: {
app: [],
catalogue: [],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: {
all: [IndexThreshold],
read: [],
Expand All @@ -29,11 +35,14 @@ export const BUILT_IN_ALERTS_FEATURE = {
read: [],
},
api: [],
ui: ['alerting:show'],
ui: [],
},
read: {
app: [],
catalogue: [],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: {
all: [],
read: [IndexThreshold],
Expand All @@ -43,7 +52,7 @@ export const BUILT_IN_ALERTS_FEATURE = {
read: [],
},
api: [],
ui: ['alerting:show'],
ui: [],
},
},
};
10 changes: 10 additions & 0 deletions x-pack/plugins/alerts/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ export class AlertingPlugin {
this.spaces = plugins.spaces?.spacesService;
this.security = plugins.security;

core.capabilities.registerProvider(() => {
return {
management: {
insightsAndAlerting: {
triggersActions: true,
},
},
};
});

this.isESOUsingEphemeralEncryptionKey =
plugins.encryptedSavedObjects.usingEphemeralEncryptionKey;

Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/apm/server/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export const APM_FEATURE = {
navLinkId: 'apm',
app: ['apm', 'kibana'],
catalogue: ['apm'],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: Object.values(AlertType),
// see x-pack/plugins/features/common/feature_kibana_privileges.ts
privileges: {
Expand All @@ -31,6 +34,9 @@ export const APM_FEATURE = {
alerting: {
all: Object.values(AlertType),
},
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show', 'save', 'alerting:show', 'alerting:save'],
},
read: {
Expand All @@ -44,6 +50,9 @@ export const APM_FEATURE = {
alerting: {
all: Object.values(AlertType),
},
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show', 'alerting:show', 'alerting:save'],
},
},
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/infra/server/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const METRICS_FEATURE = {
navLinkId: 'metrics',
app: ['infra', 'metrics', 'kibana'],
catalogue: ['infraops'],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: [METRIC_THRESHOLD_ALERT_TYPE_ID, METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID],
privileges: {
all: {
Expand All @@ -32,7 +35,10 @@ export const METRICS_FEATURE = {
alerting: {
all: [METRIC_THRESHOLD_ALERT_TYPE_ID, METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID],
},
ui: ['show', 'configureSource', 'save', 'alerting:show'],
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show', 'configureSource', 'save'],
},
read: {
app: ['infra', 'metrics', 'kibana'],
Expand All @@ -45,7 +51,10 @@ export const METRICS_FEATURE = {
alerting: {
all: [METRIC_THRESHOLD_ALERT_TYPE_ID, METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID],
},
ui: ['show', 'alerting:show'],
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show'],
},
},
};
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/security_solution/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
navLinkId: APP_ID,
app: [...securitySubPlugins, 'kibana'],
catalogue: ['securitySolution'],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: [SIGNALS_ID, NOTIFICATIONS_ID],
privileges: {
all: {
Expand All @@ -194,7 +197,10 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
alerting: {
all: [SIGNALS_ID, NOTIFICATIONS_ID],
},
ui: ['show', 'crud', 'alerting:show'],
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show', 'crud'],
},
read: {
app: [...securitySubPlugins, 'kibana'],
Expand All @@ -214,7 +220,10 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
alerting: {
all: [SIGNALS_ID, NOTIFICATIONS_ID],
},
ui: ['show', 'alerting:show'],
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show'],
},
},
});
Expand Down
18 changes: 6 additions & 12 deletions x-pack/plugins/triggers_actions_ui/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
ScopedHistory,
} from 'kibana/public';
import { Section, routeToAlertDetails } from './constants';
import { AppContextProvider, useAppDependencies } from './app_context';
import { hasShowAlertsCapability } from './lib/capabilities';
import { AppContextProvider } from './app_context';
import { ActionTypeModel, AlertTypeModel } from '../types';
import { TypeRegistry } from './type_registry';
import { ChartsPluginStart } from '../../../../../src/plugins/charts/public';
Expand Down Expand Up @@ -63,22 +62,17 @@ export const App = (appDeps: AppDeps) => {
};

export const AppWithoutRouter = ({ sectionsRegex }: { sectionsRegex: string }) => {
const { capabilities } = useAppDependencies();
const canShowAlerts = hasShowAlertsCapability(capabilities);
const DEFAULT_SECTION: Section = canShowAlerts ? 'alerts' : 'connectors';
return (
<Switch>
<Route
path={`/:section(${sectionsRegex})`}
component={suspendedComponentWithProps(TriggersActionsUIHome, 'xl')}
/>
{canShowAlerts && (
<Route
path={routeToAlertDetails}
component={suspendedComponentWithProps(AlertDetailsRoute, 'xl')}
/>
)}
<Redirect from={'/'} to={`${DEFAULT_SECTION}`} />
<Route
path={routeToAlertDetails}
component={suspendedComponentWithProps(AlertDetailsRoute, 'xl')}
/>
<Redirect from={'/'} to="alerts" />
</Switch>
);
};
40 changes: 16 additions & 24 deletions x-pack/plugins/triggers_actions_ui/public/application/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Section, routeToConnectors, routeToAlerts } from './constants';
import { getCurrentBreadcrumb } from './lib/breadcrumb';
import { getCurrentDocTitle } from './lib/doc_title';
import { useAppDependencies } from './app_context';
import { hasShowActionsCapability, hasShowAlertsCapability } from './lib/capabilities';
import { hasShowActionsCapability } from './lib/capabilities';

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

const canShowActions = hasShowActionsCapability(capabilities);
const canShowAlerts = hasShowAlertsCapability(capabilities);
const tabs: Array<{
id: Section;
name: React.ReactNode;
}> = [];

if (canShowAlerts) {
tabs.push({
id: 'alerts',
name: (
<FormattedMessage
id="xpack.triggersActionsUI.home.alertsTabTitle"
defaultMessage="Alerts"
/>
),
});
}
tabs.push({
id: 'alerts',
name: (
<FormattedMessage id="xpack.triggersActionsUI.home.alertsTabTitle" defaultMessage="Alerts" />
),
});

if (canShowActions) {
tabs.push({
Expand Down Expand Up @@ -151,17 +145,15 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<
)}
/>
)}
{canShowAlerts && (
<Route
exact
path={routeToAlerts}
component={() => (
<HealthCheck docLinks={docLinks} http={http}>
<AlertsList />
</HealthCheck>
)}
/>
)}
<Route
exact
path={routeToAlerts}
component={() => (
<HealthCheck docLinks={docLinks} http={http}>
<AlertsList />
</HealthCheck>
)}
/>
</Switch>
</EuiPageContent>
</EuiPageBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { BUILT_IN_ALERTS_FEATURE_ID } from '../../../../alerting_builtins/common';
import { Alert, AlertType } from '../../types';

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

type Capabilities = Record<string, any>;

const apps = ['apm', 'siem', 'uptime', 'infrastructure', 'actions', BUILT_IN_ALERTS_FEATURE_ID];

function hasCapability(capabilities: Capabilities, capability: string) {
return apps.some((app) => capabilities[app]?.[capability]);
}

function createCapabilityCheck(capability: string) {
return (capabilities: Capabilities) => hasCapability(capabilities, capability);
}

export const hasShowAlertsCapability = createCapabilityCheck('alerting:show');

export const hasShowActionsCapability = (capabilities: Capabilities) => capabilities?.actions?.show;
export const hasSaveActionsCapability = (capabilities: Capabilities) => capabilities?.actions?.save;
export const hasExecuteActionsCapability = (capabilities: Capabilities) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ jest.mock('../../../app_context', () => ({
http: jest.fn(),
capabilities: {
get: jest.fn(() => ({})),
securitySolution: {
'alerting:show': true,
},
},
actionTypeRegistry: jest.fn(),
alertTypeRegistry: {
Expand Down
Loading

0 comments on commit f410474

Please sign in to comment.