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

[Response Ops][RAM] Add RBAC Support for Multi-Consumer Rule Creation in O11Y and Stack Management #162605

Merged
merged 33 commits into from
Aug 16, 2023

Conversation

JiaweiWu
Copy link
Contributor

@JiaweiWu JiaweiWu commented Jul 27, 2023

Summary

Resolves:

This PR adds the ability for logs and/or infrastructure only users to create and modify ES Query and new Generic Threshold rules. The ensureAuthorized function is modified and simplified to support this use case, by skipping producer authorization and only authorizing for consumers. When the consumer is alerts, we will consider this legacy and replace it with the rule’s producer (consumer = ruleType.producer)

There is now a dropdown in the rule form to prompt the user when creating ES Query/Generic threshold rules to select the consumer based on their authorized consumers (we can no longer use alerts for these). If there is only 1 option, then the dropdown will not be shown and the option will be chosen automatically.

Generic threshold rules will have the following possible consumers:

  • slo
  • infrastructure
  • logs
  • apm
  • uptime

ES query rules will have the following possible consumers:

  • slo
  • infrastructure
  • logs
  • apm
  • uptime
  • stackAlerts

To Test:

Single Consumer:

  1. Create a user with only logs feature enabled (ensuring stackAlerts is not enabled).
  2. Navigate to the O11Y rule management page
  3. Click the create rule button
  4. Assert that both ES query and generic threshold rules are available
  5. Click ES query and fill out the relevant information and create the rule
  6. Assert that the rule created has logs set in the consumer field
  7. Repeat 5-6 for the generic threshold rule
  8. Repeat 2-7 but on the Stack Management rules page
  9. Repeat 1-8 for the infrastructure feature.

Multiple Consumers:

  1. Create a user with logs, infrastructure and apm features enabled (ensuring stackAlerts is not enabled).
  2. Navigate to the O11Y rule management page
  3. Click the create rule button
  4. Assert that both ES query and generic threshold rules are available
  5. Click ES query and fill out the relevant information and create the rule
  6. A dropdown should prompt the user to select between 1 of the 3 consumers, select 1
  7. Assert that the rule was created with the selected consumer
  8. Repeat 5-7 for the generic threshold rule
  9. Repeat 2-8 but on the Stack Management rules page

Screenshot from 2023-08-08 16-45-43
consumer_dropdown_open

Checklist

@mdefazio
Copy link
Contributor

Nice one! Some thoughts on the modal copy:

Select rule association
This rule needs to be associated with a particular application for proper role access visibility.
[ Save ]

throw Boom.forbidden(
getUnauthorizedMessage(ruleTypeId, ScopeType.Consumer, consumer, operation, entity)
);
throw Boom.forbidden(getUnauthorizedMessage(ruleTypeId, consumer, operation, entity));
Copy link
Contributor

@mikecote mikecote Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By looking at the tests failures, if you feel the error messages are now misleading, you could change all the getUnauthorizedMessage calls to something like this (use legacyConsumer):

Suggested change
throw Boom.forbidden(getUnauthorizedMessage(ruleTypeId, consumer, operation, entity));
throw Boom.forbidden(getUnauthorizedMessage(ruleTypeId, legacyConsumer, operation, entity));

@JiaweiWu JiaweiWu changed the title [RAM] O11y RBAC consumer selection modal and auth changes [RAM] Add RBAC Support for Multi-Consumer Rules in O11Y and Stack Management Aug 3, 2023
@JiaweiWu JiaweiWu changed the title [RAM] Add RBAC Support for Multi-Consumer Rules in O11Y and Stack Management [RAM] Add RBAC Support for Multi-Consumer Rule Creation in O11Y and Stack Management Aug 3, 2023
@JiaweiWu JiaweiWu marked this pull request as ready for review August 3, 2023 20:02
@JiaweiWu JiaweiWu requested review from a team as code owners August 3, 2023 20:02
@JiaweiWu JiaweiWu added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.10.0 labels Aug 3, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@JiaweiWu JiaweiWu requested a review from a team as a code owner August 9, 2023 00:06
@@ -30,8 +30,8 @@ export default function ({ getService }: FtrProviderContext) {
return fieldStat.name === 'geo_point';
}
);
expect(geoPointFieldStats.count).to.be(31);
expect(geoPointFieldStats.index_count).to.be(9);
expect(geoPointFieldStats.count).to.be(39);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@nreese nreese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kibana-gis changes LGTM
code review only

@JiaweiWu JiaweiWu requested review from a team as code owners August 9, 2023 21:02
@botelastic botelastic bot added Team:APM All issues that need APM UI Team support Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability labels Aug 9, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:APM)

@elasticmachine
Copy link
Contributor

Pinging @elastic/uptime (Team:uptime)

Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM! I left a few nitpicks but overall the changes are looking great!

x-pack/plugins/observability/common/constants.ts Outdated Show resolved Hide resolved
x-pack/plugins/observability/common/constants.ts Outdated Show resolved Hide resolved
enabled: schema.boolean({ defaultValue: false }),
enabled: schema.boolean({ defaultValue: true }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless O11y is ready, we may want to reverse this change in the PR and let O11y change the default when they are ready.(unless we can add it to a todo list on the feature branch PR).

If we revert this, the following changes will have to be undone as well:

  • x-pack/test/plugin_api_integration/test_suites/task_manager/check_registered_task_types.ts
  • x-pack/test/api_integration/apis/maps/maps_telemetry.ts

I had this code in my POC to bypass having to set the kibana.yml settings for testing.

Copy link
Contributor Author

@JiaweiWu JiaweiWu Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add it to a to-do list, since we have tests other than maps_telemetry that depend on this change. Also, this is merging to a feature branch so won't merge to main presumably until ES types are enabled in o11y (correct me if im wrong)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maryam-saeidi or @fkanout are best positioned to say whether this can be set to true already or not.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to not enable it for v8.10 and aim to either enable this in v8.11 or remove it and release the feature in beta.

| typeof AlertConsumers.UPTIME
| typeof AlertConsumers.SLO
| 'stackAlerts'
| 'discover';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an offline discussion last week, we'll be moving away from discover as a consumer, in favour of stackAlerts.

We'll need to do one of two things:

  1. Remove this usage if no underlying issues exist
  2. Add it to a list of tasks to complete before the feature branch is merged (if we have a draft PR on the feature branch, we can create a checklist list in the description)

@@ -15,6 +15,9 @@ export { BASE_ACTION_API_PATH, INTERNAL_BASE_ACTION_API_PATH } from '@kbn/action

export type Section = 'connectors' | 'rules' | 'alerts' | 'logs';

export const OBSERVABILITY_THRESHOLD_RULE_TYPE_ID = 'observability.rules.threshold';
export const ES_QUERY_RULE_TYPE_ID = '.es-query';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we re-use ES_QUERY_ID from x-pack/plugins/stack_alerts/server/rule_types/es_query/constants.ts, we'll have to move it into a common folder.

Copy link
Contributor Author

@JiaweiWu JiaweiWu Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried to do this, unfortunately, stack alerts has triggers actions UI as a dependency. If I import from stack alerts in triggers actions UI we get a circular dependency.

If we want to share this constantly then we probably move it to a package.

@@ -123,7 +126,7 @@ function InternalAlertsPage() {
try {
const response = await loadRuleAggregations({
http,
typesFilter: observabilityRuleTypeRegistry.list(),
typesFilter: filteredRuleTypes,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, way nicer.

@JiaweiWu JiaweiWu merged commit 47ea286 into elastic:o11y-rbac-rule-feature-branch Aug 16, 2023
@kibana-ci
Copy link
Collaborator

kibana-ci commented Aug 16, 2023

💔 Build Failed

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
triggersActionsUi 576 577 +1

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
stackAlerts 14 15 +1
triggersActionsUi 545 546 +1
total +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
observability 1023.8KB 1023.8KB +16.0B
stackAlerts 77.2KB 76.0KB -1.1KB
triggersActionsUi 1.4MB 1.5MB +2.8KB
total +1.7KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
observability 99.3KB 99.6KB +273.0B
stackAlerts 19.4KB 21.0KB +1.6KB
triggersActionsUi 89.0KB 89.1KB +82.0B
total +2.0KB
Unknown metric groups

API count

id before after diff
stackAlerts 14 15 +1
triggersActionsUi 571 572 +1
total +2

ESLint disabled line counts

id before after diff
triggersActionsUi 120 122 +2

Total ESLint disabled count

id before after diff
triggersActionsUi 126 128 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mdefazio
Copy link
Contributor

A small request on this (I know this is merged and we are close to FF—sorry).

Can we set the defaults of the dropdown to the following?:
If from Stack rule management --> dropdown defaults to Stack alerts
If from O11y rule management --> dropdown defaults to Logs

Rationale:
There are scenarios where customers are creating rules in Stack management vs Observability for purposes of locking down the rule from those without access to Stack Management / only access to O11y. Our concern is if this defaults to an Observability scope, then there's a chance the user may not notice that the current behavior has changed. (Creating a rule in stack and having it scoped to stack).

And, our expectation is that Logs will be the most common use case for this, so it makes sense to default to that.

@katrin-freihofner Can you confirm this request please?

Curious if there are any differing arguments to this as well.

cc/ @JiaweiWu @XavierM @katrin-freihofner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:cloud-deploy Create or update a Cloud deployment Feature:Alerting/RulesManagement Issues related to the Rules Management UX release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.