Skip to content

[Alerting] Refactor alerts authorization client#99078

Merged
ymao1 merged 30 commits intoelastic:masterfrom
ymao1:alerting/refactor-alerts-authorization
May 18, 2021
Merged

[Alerting] Refactor alerts authorization client#99078
ymao1 merged 30 commits intoelastic:masterfrom
ymao1:alerting/refactor-alerts-authorization

Conversation

@ymao1
Copy link
Contributor

@ymao1 ymao1 commented May 3, 2021

Resolves #98818

Summary

Refactoring alerts authorization client to be more generic. This uses the existing alerting feature privilege model to provide all and read privileges to rules and alerts. There will be a followup issue to handle subfeature privilege specification. There should be no change to how the rules RBAC works functionally.

  • Updated alerting feature privilege builder to include entity in the feature privilege string. Allowed entities are rule and alert
  • Added ability to specify exemptConsumers in authorization client to handle the alerting use case where alerts was a special consumer id with special handling
  • Updated terminology within AlertsAuthorization class to reflect updated rule terminology
  • Updated authorization filter builder to return EsQuery or KQL
  • Updated authorization filter to allow field names to be specified
  • Exposing getAlertingAuthorizationWithRequest through alerting plugin start to be used by other plugins
  • Renamed AlertsAuthorization to AlertingAuthorization
  • Changes formatting of recorded audit events
    • Audit event types have changed from using alerts_ prefix to alerting_ prefix:
      • alerts_authorization_failure is now alerting_authorization_failure
      • alerts_unscoped_authorization_failure is now alerting_unscoped_authorization_failure
      • alerts_authorization_success is now alerting_authorization_success
    • Audit events have been updated to reflect new alerting terminology
      • alerts have been renamed to rules, for example the audit event user Authorized to create a ".index-threshold" alert by "app" will now read user Authorized to create a ".index-threshold" rule by "app"
      • alert instances have been renamed to alert, for example audit events for muteInstance and unmuteInstance operations will now reference muteAlert and unmuteAlert

To Verify

  • Verify that existing roles that give different levels of access to rules for different features still work with this PR
  • Verify that new roles created in this PR branch work as expected in terms of giving different levels of access to rules for different features.

Checklist

@ymao1 ymao1 requested a review from gmmorris May 3, 2021 19:56
authorizationType: string
): string {
return `${authorizationResult} to ${operation} a "${alertTypeId}" alert ${
return `${authorizationResult} to ${operation} a "${alertTypeId}" ${authorizationType} ${
Copy link
Contributor

Choose a reason for hiding this comment

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

One thought that crosses my mind - once customers upgrade to 7.14 their audit logs will say rule where they used to say alert, and alert on the new Alert entities.
This means that if a user looks at their audit logs across versions they might have two audit log rows that say Alert, but in one its a Rule and in the other an Alert.

I'm not sure what we can do about that, but perhaps it's worth making it easier to distinguish between them by changing the format in 7.14 so that the sentences at least appear different in some manner? 🤔

@gmmorris
Copy link
Contributor

gmmorris commented May 5, 2021

This looks like the right direction to me 👍
I haven't done a full review and leaving that to the team, but I think this approach fits in with the ideal endstate of having the Rules and Alerts share the core semantics, while leaving room for change later where they diverge on specific operations.

This sparks joy 🎉 😉

Copy link
Contributor

@yctercero yctercero left a comment

Choose a reason for hiding this comment

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

LGTM! I integrated this PR into the work Devin and I have been doing for RAC. There are some open questions about possible changes needed to the feature privilege builder, but I think those can be addressed as follow up to keep things flowing 🌊

Thanks so much for all these changes and the quick turnaround!

@ymao1 ymao1 requested a review from legrego May 13, 2021 14:08
@ymao1
Copy link
Contributor Author

ymao1 commented May 13, 2021

@elasticmachine merge upstream

Copy link
Contributor

@YulNaumenko YulNaumenko 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!

}

const readOperations: Record<AlertingType, string[]> = {
rule: ['get', 'getAlertState', 'getAlertInstanceSummary', 'find'],
Copy link
Member

Choose a reason for hiding this comment

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

This is probably a lack of understanding on my part -- why does the rule alerting type have operations called getAlertState and getAlertInstanceSummary? Are these names holdovers from the old terminology, or are they actually operations against the alert alerting type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, these are holdovers from the old terminology and you are right, they are confusing. I will open an issue to update these separately.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can change these as part of this PR if we want, as it's under the hood and shouldn't break anything if we change it in 7.14, right? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in this commit: ce70ff2

Authorized = 'Authorized',
}

export class AlertsAuthorizationAuditLogger {
Copy link
Member

Choose a reason for hiding this comment

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

Since we are changing the recorded audit events, we should document this as a breaking change for the release notes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@legrego I have added the release_note:breaking label and added a line in the PR description about the change to audit events.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, @ymao1! I think it would be beneficial to our users if we also gave some examples of the changes made to the audit log. For example, mentioning that the audit event types have changed (alerts_authorization_failure -> alerting_authorization_failure, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@legrego PR description updated!

@ymao1 ymao1 added release_note:breaking and removed release_note:skip Skip the PR/issue when compiling release notes labels May 14, 2021
@ymao1 ymao1 requested a review from legrego May 14, 2021 20:31
Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

LGTM! I did some basic testing around creating rules on master with various permission sets and ensuring they still work properly on the PR and it looks great to me!

@ymao1
Copy link
Contributor Author

ymao1 commented May 18, 2021

@elasticmachine merge upstream

@ymao1 ymao1 added the auto-backport Deprecated - use backport:version if exact versions are needed label May 18, 2021
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

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
alerting 201 203 +2

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
alerting 9 10 +1
Unknown metric groups

API count

id before after diff
alerting 201 203 +2

History

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

cc @ymao1

@ymao1 ymao1 merged commit 0f0cee2 into elastic:master May 18, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request May 18, 2021
* WIP - creating alerting authorization client factory and exposing authorization client on plugin start contract

* Updating alerting feature privilege builder to handle different alerting types

* Passing in alerting authorization type to AlertingActions class string builder

* Passing in authorization type in each function call

* Passing in exempt consumer ids. Adding authorization type to audit logger

* Changing alertType to ruleType

* Changing alertType to ruleType

* Updating unit tests

* Updating unit tests

* Passing field names into authorization query builder. Adding kql/es dsl option

* Converting to es query if requested

* Fixing functional tests

* Removing ability to specify feature privilege name in constructor

* Fixing some types and tests

* Consolidating alerting authorization kuery filter options

* Cleanup and tests

* Cleanup and tests

* Throwing error when AlertingAuthorizationClientFactory is not defined

* Renaming authorizationType to entity

* Renaming AlertsAuthorization to AlertingAuthorization

* Fixing unit tests

* Updating privilege string terminology

* Updating privilege string terminology

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request May 19, 2021
* WIP - creating alerting authorization client factory and exposing authorization client on plugin start contract

* Updating alerting feature privilege builder to handle different alerting types

* Passing in alerting authorization type to AlertingActions class string builder

* Passing in authorization type in each function call

* Passing in exempt consumer ids. Adding authorization type to audit logger

* Changing alertType to ruleType

* Changing alertType to ruleType

* Updating unit tests

* Updating unit tests

* Passing field names into authorization query builder. Adding kql/es dsl option

* Converting to es query if requested

* Fixing functional tests

* Removing ability to specify feature privilege name in constructor

* Fixing some types and tests

* Consolidating alerting authorization kuery filter options

* Cleanup and tests

* Cleanup and tests

* Throwing error when AlertingAuthorizationClientFactory is not defined

* Renaming authorizationType to entity

* Renaming AlertsAuthorization to AlertingAuthorization

* Fixing unit tests

* Updating privilege string terminology

* Updating privilege string terminology

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: ymao1 <ying.mao@elastic.co>
yctercero pushed a commit to yctercero/kibana that referenced this pull request May 25, 2021
* WIP - creating alerting authorization client factory and exposing authorization client on plugin start contract

* Updating alerting feature privilege builder to handle different alerting types

* Passing in alerting authorization type to AlertingActions class string builder

* Passing in authorization type in each function call

* Passing in exempt consumer ids. Adding authorization type to audit logger

* Changing alertType to ruleType

* Changing alertType to ruleType

* Updating unit tests

* Updating unit tests

* Passing field names into authorization query builder. Adding kql/es dsl option

* Converting to es query if requested

* Fixing functional tests

* Removing ability to specify feature privilege name in constructor

* Fixing some types and tests

* Consolidating alerting authorization kuery filter options

* Cleanup and tests

* Cleanup and tests

* Throwing error when AlertingAuthorizationClientFactory is not defined

* Renaming authorizationType to entity

* Renaming AlertsAuthorization to AlertingAuthorization

* Fixing unit tests

* Updating privilege string terminology

* Updating privilege string terminology

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@peluja1012 peluja1012 mentioned this pull request Jul 20, 2021
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Deprecated - use backport:version if exact versions are needed Feature:Alerting release_note:breaking Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v7.14.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Alerting] Refactor AlertsAuthorization class so it can be reused

8 participants