Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAM] .es-query and .observability.rules.threshold RBAC #166032

Merged
merged 30 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
47ea286
[Response Ops][RAM] Add RBAC Support for Multi-Consumer Rule Creation…
JiaweiWu Aug 16, 2023
e68adb7
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Aug 29, 2023
89427ff
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Aug 30, 2023
f83694a
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Sep 5, 2023
7337d16
[RAM] Update RBAC to manage es-query/generic o11y threshold rule (#1…
XavierM Sep 7, 2023
909bd94
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Sep 7, 2023
38ab867
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 7, 2023
3e3234b
messed up merge
XavierM Sep 7, 2023
682dedf
Merge branch 'o11y-rbac-rule-feature-branch' of github.com:elastic/ki…
XavierM Sep 7, 2023
a55a5cc
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 7, 2023
3c73949
fix discover FTR
XavierM Sep 8, 2023
fc1d68f
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Sep 8, 2023
444bf81
move back order
XavierM Sep 8, 2023
be7d5a1
Merge branch 'o11y-rbac-rule-feature-branch' of github.com:elastic/ki…
XavierM Sep 8, 2023
4c5d5e0
fix old merge issue
XavierM Sep 8, 2023
25b5fb8
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Sep 11, 2023
b6407b1
Merge branch 'main' into o11y-rbac-rule-feature-branch
XavierM Sep 11, 2023
ddb9f93
Merge branch 'main' into o11y-rbac-rule-feature-branch
XavierM Sep 13, 2023
06a8cea
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Sep 19, 2023
eaaca0a
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Sep 19, 2023
a85cb27
bad merge
XavierM Sep 19, 2023
e97fa67
fix filterCosumers validation
XavierM Sep 19, 2023
b47c446
only allow log and/or metrics
XavierM Sep 21, 2023
4b45345
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Sep 21, 2023
caa3180
fix rule add test
XavierM Sep 21, 2023
79eed87
fix tests
XavierM Sep 21, 2023
49f7c49
Merge branch 'main' of github.com:elastic/kibana into o11y-rbac-rule-…
XavierM Sep 21, 2023
a6babf2
fix view rule list in o11y
XavierM Sep 21, 2023
4bf2089
fix esQuery registration view in app
XavierM Sep 21, 2023
246d08b
Merge branch 'main' into o11y-rbac-rule-feature-branch
XavierM Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/kbn-rule-data-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './src/alerts_as_data_severity';
export * from './src/alerts_as_data_status';
export * from './src/alerts_as_data_cases';
export * from './src/routes/stack_rule_paths';
export * from './src/rule_types';
10 changes: 10 additions & 0 deletions packages/kbn-rule-data-utils/src/rule_types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export * from './stack_rules';
export * from './o11y_rules';
9 changes: 9 additions & 0 deletions packages/kbn-rule-data-utils/src/rule_types/o11y_rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export const OBSERVABILITY_THRESHOLD_RULE_TYPE_ID = 'observability.rules.custom_threshold';
10 changes: 10 additions & 0 deletions packages/kbn-rule-data-utils/src/rule_types/stack_rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export const STACK_ALERTS_FEATURE_ID = 'stackAlerts';
export const ES_QUERY_ID = '.es-query';
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import type { DataView } from '@kbn/data-plugin/common';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { STACK_ALERTS_FEATURE_ID } from '@kbn/rule-data-utils';
import { DiscoverStateContainer } from '../../services/discover_state';
import { DiscoverServices } from '../../../../build_services';

Expand Down Expand Up @@ -97,7 +98,7 @@ export function AlertsPopover({

return triggersActionsUi?.getAddRuleFlyout({
metadata: discoverMetadata,
consumer: 'discover',
consumer: STACK_ALERTS_FEATURE_ID,
onClose: (_, metadata) => {
onFinishFlyoutInteraction(metadata as EsQueryAlertMetaData);
onClose();
Expand Down
1 change: 1 addition & 0 deletions src/plugins/discover/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"@kbn/react-kibana-context-render",
"@kbn/unified-data-table",
"@kbn/no-data-page-plugin",
"@kbn/rule-data-utils",
"@kbn/global-search-plugin"
],
"exclude": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const aggregateRulesRequestBodySchema = schema.object({
)
),
filter: schema.maybe(schema.string()),
filter_consumers: schema.maybe(schema.arrayOf(schema.string())),
});

export const aggregateRulesResponseBodySchema = schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ import { SanitizedRule } from '../../common';
* originally registered to {@link PluginSetupContract.registerNavigation}.
*
*/
export type AlertNavigationHandler = (rule: SanitizedRule) => string;
export type AlertNavigationHandler = (rule: SanitizedRule) => string | undefined;
3 changes: 2 additions & 1 deletion x-pack/plugins/alerting/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export class AlertingPublicPlugin

if (this.alertNavigationRegistry!.has(rule.consumer, ruleType)) {
const navigationHandler = this.alertNavigationRegistry!.get(rule.consumer, ruleType);
return navigationHandler(rule);
const navUrl = navigationHandler(rule);
if (navUrl) return navUrl;
}

if (rule.viewInAppRelativeUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const ruleType: jest.Mocked<UntypedNormalizedRuleType> = {
mappings: { fieldMap: { field: { type: 'keyword', required: false } } },
shouldWrite: true,
},
validLegacyConsumers: [],
};

const mockLegacyAlertsClient = legacyAlertsClientMock.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const ruleType: jest.Mocked<UntypedNormalizedRuleType> = {
validate: {
params: schema.any(),
},
validLegacyConsumers: [],
};

const testAlert1 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const ruleType: jest.Mocked<UntypedNormalizedRuleType> = {
mappings: { fieldMap: { field: { type: 'keyword', required: false } } },
shouldWrite: true,
},
validLegacyConsumers: [],
};

describe('formatRule', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const ruleType: jest.Mocked<UntypedNormalizedRuleType> = {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
};

const ruleTypeWithAlertDefinition: jest.Mocked<UntypedNormalizedRuleType> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('aggregate()', () => {
enabledInLicense: true,
hasAlertsMappings: false,
hasFieldsForAAD: false,
validLegacyConsumers: [],
},
]);
beforeEach(() => {
Expand Down Expand Up @@ -166,6 +167,7 @@ describe('aggregate()', () => {
enabledInLicense: true,
hasAlertsMappings: false,
hasFieldsForAAD: false,
validLegacyConsumers: [],
},
])
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { KueryNode, nodeBuilder } from '@kbn/es-query';
import { isEmpty } from 'lodash';
import { findRulesSo } from '../../../../data/rule';
import { AlertingAuthorizationEntity } from '../../../../authorization';
import { ruleAuditEvent, RuleAuditAction } from '../../../../rules_client/common/audit_events';
Expand All @@ -21,13 +22,14 @@ export async function aggregateRules<T = Record<string, unknown>>(
params: AggregateParams<T>
): Promise<T> {
const { options = {}, aggs } = params;
const { filter, page = 1, perPage = 0, ...restOptions } = options;
const { filter, page = 1, perPage = 0, filterConsumers, ...restOptions } = options;

let authorizationTuple;
try {
authorizationTuple = await context.authorization.getFindAuthorizationFilter(
AlertingAuthorizationEntity.Rule,
alertingAuthorizationFilterOpts
alertingAuthorizationFilterOpts,
isEmpty(filterConsumers) ? undefined : new Set(filterConsumers)
);
validateRuleAggregationFields(aggs);
aggregateOptionsSchema.validate(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const aggregateOptionsSchema = schema.object({
id: schema.string(),
})
),
filterConsumers: schema.maybe(schema.arrayOf(schema.string())),
// filter type is `string | KueryNode`, but `KueryNode` has no schema to import yet
filter: schema.maybe(
schema.oneOf([schema.string(), schema.recordOf(schema.string(), schema.any())])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type AggregateOptions = TypeOf<typeof aggregateOptionsSchema> & {
filter?: string | KueryNode;
page?: AggregateOptionsSchemaTypes['page'];
perPage?: AggregateOptionsSchemaTypes['perPage'];
filterConsumers?: string[];
};

export interface AggregateParams<AggregationResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ describe('bulkEdit()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
});

(migrateLegacyActions as jest.Mock).mockResolvedValue(migrateLegacyActionsMock);
Expand Down Expand Up @@ -745,6 +746,7 @@ describe('bulkEdit()', () => {
mappings: { fieldMap: { field: { type: 'keyword', required: false } } },
shouldWrite: true,
},
validLegacyConsumers: [],
});
const existingAction = {
frequency: {
Expand Down Expand Up @@ -2351,6 +2353,7 @@ describe('bulkEdit()', () => {
return { state: {} };
},
producer: 'alerts',
validLegacyConsumers: [],
});

const result = await rulesClient.bulkEdit({
Expand Down Expand Up @@ -2395,6 +2398,7 @@ describe('bulkEdit()', () => {
return { state: {} };
},
producer: 'alerts',
validLegacyConsumers: [],
});

const result = await rulesClient.bulkEdit({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));
const data = getMockData({
params: ruleParams,
Expand Down Expand Up @@ -1738,6 +1739,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));
const data = getMockData({
params: ruleParams,
Expand Down Expand Up @@ -2557,6 +2559,7 @@ describe('create()', () => {
return { state: {} };
},
producer: 'alerts',
validLegacyConsumers: [],
});
await expect(rulesClient.create({ data })).rejects.toThrowErrorMatchingInlineSnapshot(
`"params invalid: [param1]: expected value of type [string] but got [undefined]"`
Expand Down Expand Up @@ -3031,6 +3034,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));
const createdAttributes = {
...data,
Expand Down Expand Up @@ -3103,6 +3107,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));

const data = getMockData({ schedule: { interval: '1s' } });
Expand Down Expand Up @@ -3140,6 +3145,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));

const data = getMockData({
Expand Down Expand Up @@ -3232,6 +3238,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));

const data = getMockData({
Expand Down Expand Up @@ -3281,6 +3288,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));

const data = getMockData({
Expand Down Expand Up @@ -3343,6 +3351,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));

const data = getMockData({
Expand Down Expand Up @@ -3423,6 +3432,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));

const data = getMockData({
Expand Down Expand Up @@ -3627,6 +3637,7 @@ describe('create()', () => {
mappings: { fieldMap: { field: { type: 'keyword', required: false } } },
shouldWrite: true,
},
validLegacyConsumers: [],
}));

const data = getMockData({
Expand Down Expand Up @@ -3679,6 +3690,7 @@ describe('create()', () => {
validate: {
params: { validate: (params) => params },
},
validLegacyConsumers: [],
}));

const data = getMockData({
Expand Down
Loading
Loading