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] Update RBAC to manage es-query/generic o11y threshold rule #165182

Conversation

XavierM
Copy link
Contributor

@XavierM XavierM commented Aug 30, 2023

Summary

This PR is here to update the alerting authorization model to allow .es-query and observability.rules.threshold to work with different consumers. We also the rule find's API to allow to filter on consumers. We update the alert client from the rule_registry plugin to get the alert index through the rule type and the alerting plugin like we did for the search strategy.

Checklist

@XavierM XavierM added release_note:skip Skip the PR/issue when compiling release notes v8.11.0 labels Aug 30, 2023
@XavierM XavierM requested review from a team as code owners August 30, 2023 00:38
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.

@XavierM can you list the four testing scenarios / rules you used yesterday? I want to use them when reviewing the alerting_authorization.ts file.

@XavierM
Copy link
Contributor Author

XavierM commented Sep 1, 2023

@mikecote I will write jest test around this four scenario so it is easy to understand.

@XavierM XavierM requested review from a team as code owners September 2, 2023 01:39
@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 Sep 2, 2023
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/uptime (Team:uptime)

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

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

apm changes lgtm

@XavierM XavierM requested a review from a team as a code owner September 5, 2023 17:47
@@ -84,7 +85,7 @@ export function AlertsPopover({

return triggersActionsUi?.getAddRuleFlyout({
metadata: discoverMetadata,
consumer: 'discover',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

About this change we created an issue to the breaking changes committee -> https://github.com/elastic/dev/issues/2344

Copy link
Contributor

@JiaweiWu JiaweiWu left a comment

Choose a reason for hiding this comment

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

LGTM, pretty straight forward logic.

Have some nitpicks mostly, not blocking though.

@@ -232,7 +242,8 @@ export class AlertingAuthorization {
public async getAuthorizationFilter(
authorizationEntity: AlertingAuthorizationEntity,
filterOpts: AlertingAuthorizationFilterOpts,
operation: WriteOperations | ReadOperations
operation: WriteOperations | ReadOperations,
featuresIds?: Set<string>
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: does this have to be a set? seems like an array is enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we do not want duplicated of feature ids

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe its better to dedupe in the function and let it accept arrays, I think it makes the interface a bit friendlier to work with

if (!isEmpty(ruleTypeAuth.validLegacyConsumers)) {
ruleTypeAuth.validLegacyConsumers.forEach((consumer) => {
if (consumer === ALERTS_FEATURE_ID || isEmpty(featuresIds)) {
if (!allPossibleConsumers[consumer]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have to do this check? can we just set it regardless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you are right that we do not really need the check with our use cases but it feel safer for some reason.

@@ -47,6 +47,7 @@ const querySchema = schema.object({
),
fields: schema.maybe(schema.arrayOf(schema.string())),
filter: schema.maybe(schema.string()),
filter_consumers: schema.maybe(schema.arrayOf(schema.string())),
Copy link
Contributor

Choose a reason for hiding this comment

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

should we validate specifically against consumers instead of just strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering too to be honest let me think more

'apm.anomaly': [ALERTS_FEATURE_ID],
'apm.error_rate': [ALERTS_FEATURE_ID],
'apm.transaction_error_rate': [ALERTS_FEATURE_ID],
'test.always-firing': [ALERTS_FEATURE_ID],
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels weird to be keeping this list. WDYT about having the ruleType specify something like legacyConsumer: boolean | string[] where legacyConsumer: true resolves to setting validLegacyConsumers: [ALERTS_FEATURE_ID] on registration and legacyConsumer: ['discover'] resolves to validLegacyConsumers: [ALERTS_FEATURE_ID, 'discover'] on registration?

Copy link
Contributor Author

@XavierM XavierM Sep 6, 2023

Choose a reason for hiding this comment

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

That's a decision that @mikecote and I took to avoid to updating every rule type in the repo and also good catch I need to add some unit test so we know if someone is updating this list or not. Also, if we add it to the rule type, it will have to be a conditional type, it is not really safe.


let authorizationTuple;
try {
authorizationTuple = await context.authorization.getFindAuthorizationFilter(
AlertingAuthorizationEntity.Rule,
alertingAuthorizationFilterOpts
alertingAuthorizationFilterOpts,
isEmpty(filterConsumers) ? undefined : new Set(filterConsumers)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this respect RBAC? API users shouldn't be able to pass whatever set of consumers they want to aggregate over, they should just be able to limit which consumers to aggregate over that they already have access to correct?

Copy link
Contributor Author

@XavierM XavierM Sep 6, 2023

Choose a reason for hiding this comment

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

Yes it does follow RBAC, thanks for scaring me here ;) but we do, we are just saying that we only care about some consumers. It is helping us to only show o11y rules in the rule management page.

@kibana-ci
Copy link
Collaborator

kibana-ci commented Sep 7, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #7 / Discover alerting Search source Alert should navigate to alert results via view in app link
  • [job] [logs] FTR Configs #7 / Discover alerting Search source Alert should navigate to alert results via view in app link

Metrics [docs]

‼️ ERROR: no builds found for mergeBase sha [f83694a]

History

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

@XavierM XavierM merged commit 7337d16 into elastic:o11y-rbac-rule-feature-branch Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support Team:Uptime - DEPRECATED Synthetics & RUM sub-team of Application Observability v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants