kibana/x-pack/solutions/observability/plugins/infra/server/features.ts
Dominique Clarke f15d325e3c
[Observability] [Serverless] Introduce custom roles (#219861)
## Summary

Closes https://github.com/elastic/observability-dev/issues/4539
Fixes https://github.com/elastic/kibana/issues/221035

Enables custom roles for Observability projects in serverless.

The following is a summary of the changes:

## Feature renaming

1. Renamed `Uptime and Synthetics` to `Synthetics`
2. Renamed `APM and User Experience` to `Applications`
3. Renamed `Metrics` to `Infrastructure`

## Category reassignment

1. Changed `Dashboard` category from `Analytics` to `Observability` 
2. Changed `Discover` category from `Analytics` to `Observability`
3. Changed `ML` category from `Analytics` to `Observability`

## Feature hiding

1. Hides the `Stack Alerts` feature.
2. Provides backwards compatibility for alerts created via Stack Alerts.
This enables our users to import rules created within Stack Alerts and
expect to see them in the Observability rules table.

## Navigation updates

1. Adds a `Custom Roles` link under the `Access` section in the
management navigation
2. Adds a `Manage Organization Members` link under the `Access` section
in the management navigation
3. Removes the `Users and Roles` link from the navigation footer (in
favor of the `Manage Organization Members link)

## Bug fixes

1. Fixes a bug where the `Alerts` link was not shown for Synthetics only
user (in stateful and serverless)
2. Fixes a bug where the `Alerts` link was not shown for Logs only user
(in stateful and serverless)

## Alert Override Removal

In the alerting framework, each rule is assigned a `consumer` value.
This `consumer` value changes depending on where the rule is created in
Kibana. However, in serverless we introduced an override that caused the
`consumer` value to be `Observability` in nearly every case. This logic
branched from stateful causing complexity and a large mental burden for
our engineers. Ultimately, this override became the source of bugs,
uncertainty, and unintended user experiences. Because of this, we've
removed this overrides.

If we kept this override, it would have the unfortunate side effect of
making all rules created in serverless visible from all custom roles (an
APM only user would have been can see Synthetics rules, and vice
versus). To make things more unpredictable, when users import their
rules from stateful the behavior would be different (access would be
properly mapped to the specific feature).

To address these specific user experience issues, and remove the source
of complexity, branching logic, and bugs, we removed this override logic
and restored the rule access behavior to match with stateful.

We did this while introducing backwards compatibility logic, ensuring
rules created in earlier versions of an oblt stateful cluster continue
to work and are accessible by a user with the right role access.

# Testing

1. Run local ES
```
yarn es serverless --projectType=oblt -E xpack.security.authc.native_roles.enabled=true    
```

2. Run local Kibana
```
yarn start --serverless=oblt --xpack.security.roleManagementEnabled=true --xpack.cloud.users_and_roles_url="https://test_users_and_roles_url"
```
3. Login to Kibana with the admin role. Navigate to the Custom Roles
page via the management navigation.
4. Create a custom role 
5. Log out of Kibana
6. Log back in with your custom role. You can do so by typing the custom
role name into the mock saml auth
<img width="460" alt="Screenshot 2025-05-22 at 9 23 13 PM"
src="https://github.com/user-attachments/assets/8e7f659b-5fe9-4e74-8c57-b420467d309e"
/>

---------

Co-authored-by: Jason Rhodes <jason.rhodes@elastic.co>
Co-authored-by: Faisal Kanout <faisal.kanout@elastic.co>
Co-authored-by: “jeramysoucy” <jeramy.soucy@elastic.co>
2025-06-13 22:03:49 -04:00

185 lines
5.6 KiB
TypeScript

/*
* 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 { i18n } from '@kbn/i18n';
import { DEFAULT_APP_CATEGORIES } from '@kbn/core/server';
import { logViewSavedObjectName } from '@kbn/logs-shared-plugin/server';
import {
DEPRECATED_ALERTING_CONSUMERS,
ML_ANOMALY_DETECTION_RULE_TYPE_ID,
OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
} from '@kbn/rule-data-utils';
import { ES_QUERY_ID } from '@kbn/rule-data-utils';
import { metricsDataSourceSavedObjectName } from '@kbn/metrics-data-access-plugin/server';
import { ALERTING_FEATURE_ID } from '@kbn/alerting-plugin/common';
import type { KibanaFeatureConfig } from '@kbn/features-plugin/common';
import { KibanaFeatureScope } from '@kbn/features-plugin/common';
import { LOG_DOCUMENT_COUNT_RULE_TYPE_ID } from '../common/alerting/logs/log_threshold/types';
import {
METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID,
METRIC_THRESHOLD_ALERT_TYPE_ID,
} from '../common/alerting/metrics';
import { LOGS_FEATURE_ID, METRICS_FEATURE_ID } from '../common/constants';
import { infraSourceConfigurationSavedObjectName } from './lib/sources/saved_object_type';
const metricRuleTypes = [
METRIC_THRESHOLD_ALERT_TYPE_ID,
METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID,
ES_QUERY_ID,
OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
ML_ANOMALY_DETECTION_RULE_TYPE_ID,
];
export const getMetricsFeature = (): KibanaFeatureConfig => {
const metricAlertingFeatures = metricRuleTypes.map((ruleTypeId) => {
const consumers = [METRICS_FEATURE_ID, ALERTING_FEATURE_ID, ...DEPRECATED_ALERTING_CONSUMERS];
return {
ruleTypeId,
consumers,
};
});
const METRICS_FEATURE = {
id: METRICS_FEATURE_ID,
name: i18n.translate('xpack.infra.featureRegistry.linkInfrastructureTitle', {
defaultMessage: 'Infrastructure',
}),
order: 800,
category: DEFAULT_APP_CATEGORIES.observability,
scope: [KibanaFeatureScope.Spaces, KibanaFeatureScope.Security],
app: ['infra', 'metrics', 'kibana'],
catalogue: ['infraops', 'metrics'],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: metricAlertingFeatures,
privileges: {
all: {
app: ['infra', 'metrics', 'kibana'],
catalogue: ['infraops', 'metrics'],
api: ['infra', 'rac'],
savedObject: {
all: ['infrastructure-ui-source', metricsDataSourceSavedObjectName],
read: ['index-pattern'],
},
alerting: {
rule: {
all: metricAlertingFeatures,
},
alert: {
all: metricAlertingFeatures,
},
},
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show', 'configureSource', 'save'],
},
read: {
app: ['infra', 'metrics', 'kibana'],
catalogue: ['infraops', 'metrics'],
api: ['infra', 'rac'],
savedObject: {
all: [],
read: ['infrastructure-ui-source', 'index-pattern', metricsDataSourceSavedObjectName],
},
alerting: {
rule: {
read: metricAlertingFeatures,
},
alert: {
read: metricAlertingFeatures,
},
},
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show'],
},
},
};
return METRICS_FEATURE;
};
const logsRuleTypes = [
LOG_DOCUMENT_COUNT_RULE_TYPE_ID,
ES_QUERY_ID,
OBSERVABILITY_THRESHOLD_RULE_TYPE_ID,
ML_ANOMALY_DETECTION_RULE_TYPE_ID,
];
export const getLogsFeature = (): KibanaFeatureConfig => {
const logsAlertingFeatures = logsRuleTypes.map((ruleTypeId) => {
const consumers = [LOGS_FEATURE_ID, ALERTING_FEATURE_ID, ...DEPRECATED_ALERTING_CONSUMERS];
return {
ruleTypeId,
consumers,
};
});
const LOGS_FEATURE = {
id: LOGS_FEATURE_ID,
name: i18n.translate('xpack.infra.featureRegistry.linkLogsTitle', {
defaultMessage: 'Logs',
}),
order: 700,
category: DEFAULT_APP_CATEGORIES.observability,
scope: [KibanaFeatureScope.Spaces, KibanaFeatureScope.Security],
app: ['infra', 'logs', 'kibana', 'observability-logs-explorer'],
catalogue: ['infralogging', 'logs'],
management: {
insightsAndAlerting: ['triggersActions'],
},
alerting: logsAlertingFeatures,
privileges: {
all: {
app: ['infra', 'logs', 'kibana', 'observability-logs-explorer'],
catalogue: ['infralogging', 'logs'],
api: ['infra', 'rac'],
savedObject: {
all: [infraSourceConfigurationSavedObjectName, logViewSavedObjectName],
read: [],
},
alerting: {
rule: {
all: logsAlertingFeatures,
},
alert: {
all: logsAlertingFeatures,
},
},
management: {
insightsAndAlerting: ['triggersActions'],
},
ui: ['show', 'configureSource', 'save'],
},
read: {
app: ['infra', 'logs', 'kibana', 'observability-logs-explorer'],
catalogue: ['infralogging', 'logs'],
api: ['infra', 'rac'],
alerting: {
rule: {
read: logsAlertingFeatures,
},
alert: {
read: logsAlertingFeatures,
},
},
management: {
insightsAndAlerting: ['triggersActions'],
},
savedObject: {
all: [],
read: [infraSourceConfigurationSavedObjectName, logViewSavedObjectName],
},
ui: ['show'],
},
},
};
return LOGS_FEATURE;
};