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

[Timeline][RBAC] - Add RBAC logic to timeline alerts search strategy #105333

Merged
merged 29 commits into from
Jul 28, 2021

Conversation

yctercero
Copy link
Contributor

@yctercero yctercero commented Jul 12, 2021

Summary

Adds RBAC layer to timeline plugin search strategy for alerts. Alerts RBAC is built off of the alerting plugin's authorization class. A few things that I came across:

Users will not have ES privileges - they will have Kibana privileges - so need to query using Kibana user

The existing search strategy implementation does not expose a method for querying using the Kibana user. Upon discussions with @lukasolson figured out a simple way to expose this option to us in a way that does not expose it to existing search strategies. There may be a need to revisit this code, but seemed like a good option to keep things moving. A comment is added in the code to explain why this option was added.

Because of the need to query alerts using Kibana user, can't query other non-alerts indices at the same time (those need to be queried using asCurrentUser)

For the time being, this logic will be separated. So you can either query for alerts by specifying the entityType: EntityType.ALERTS or for events by specifying entityType: EntityType.EVENTS.

Timeline search strategy needs access to alerting's auth class and full Kibana request

@lukasolson was kind enough to expose the full Kibana request in the search strategy dependencies in a previous #98566. To get the alerting auth class, added alerting as a dependency. Should be added as optional as security can be disabled, in which case no auth is performed.

Client should be able to specify that they want to get more than one solution's alerts

Added a prop to timeline search strategy - alertsConsumers - an array of alert consumers for which solution alerts to search/return. An enum (non enum) of all alertsConsumers options can be found in a kbn package - packages/kbn-rule-data-utils/src/alerts_as_data_rbac.ts. Based off of this array, we determine which indices to query.

TO DO

  • Update integration tests to expect 403 instead of 500 for unauthorized users after [Search Strategy] - Errors being swallowed and reported as 500 #106005 is fixed
  • Update timeline search strategy types to specify that when querying alerts, you do not need to specify an index
  • Add logic for determining custom alerts index names
  • Timeline event details search strategy parser needs to be updated to expect new alert fields @angorayc
  • Move alerting plugin to optional in timelines plugin and add test to ensure auth is not conducted when alerting client is not included (@dhurley14 )

Checklist

Risk Matrix

Risk Probability Severity Mitigation/Notes
Multiple Spaces—users should only have access to alerts in their space. High High Integration tests will verify that: when user with access to SPACE-1 queries for alerts, they only receive alerts from SPACE-1, when user without access to SPACE-1 queries for alerts, they do not receive SPACE-1 alerts, when a user with access to SPACE-1 and SPACE-2 queries alerts in SPACE-1 they receive SPACE-1 alerts and when they query alerts in SPACE-2 they receive alerts in SPACE-2.
Multiple Solutions—users can have access to alerts from multiple solutions. High High Integration tests will verify that when user with access to SOLUTION-1 queries for alerts, they only receive alerts from SOLUTION-1, when a user has access to multiple solutions they receive alerts from multiple solutions.
Code should handle case where security plugin is disabled. Medium High Integration tests will verify that when security plugin is disabled, users can still access alerts (no auth check conducted).
See more potential risk examples

For maintainers

@yctercero yctercero force-pushed the alerts_as_data_tgrid branch from 14582e6 to fb865ab Compare July 14, 2021 01:12
…h strategy all, need to update details search strategy
@yctercero yctercero force-pushed the alerts_as_data_tgrid branch from 4d4d6f8 to 7f93d65 Compare July 20, 2021 18:58
…ng internal user. does not affect or expose to existing search strategies
@@ -6,6 +6,6 @@
"extraPublicDirs": ["common"],
"server": true,
"ui": true,
"requiredPlugins": ["data", "dataEnhanced", "kibanaReact", "kibanaUtils"],
"requiredPlugins": ["alerting", "data", "dataEnhanced", "kibanaReact", "kibanaUtils"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Would timeline still work if alerting was optional instead of required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. So it's kind of interesting. If security is enabled, then yes, alerting is required because we have to do auth. But if security is disabled, then no, it's not required.

Guess I should move this to optional and add a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

TBD in follow up pr.


const queryFactory: TimelineFactory<T> = timelineFactory[factoryQueryType];

if (entityType != null && entityType === EntityType.ALERTS) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to force entityType to be required on the request so we don't have to do these null checks?

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! So my plan was to have a separate PR to update the front end code and that's when I would flip this to required. This allows me to not have to do it all in one PR>

Copy link
Contributor

Choose a reason for hiding this comment

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

or you can do something simple like that [EntityType.ALERTS].includes(entityType)

Copy link
Contributor

@dhurley14 dhurley14 left a comment

Choose a reason for hiding this comment

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

This is still in draft so mostly just pointed out a few questions I had, a few nits. Otherwise this looks great!

@yctercero yctercero self-assigned this Jul 20, 2021
@yctercero yctercero changed the title Alerts as data tgrid [Timeline][RBAC] - Add RBAC logic to timeline alerts search strategy Jul 20, 2021
Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

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

Good to go!!! and good job on it much appreciated!

@yctercero
Copy link
Contributor Author

jenkins test this

@ymao1
Copy link
Contributor

ymao1 commented Jul 27, 2021

@yctercero #106519 just got merged, looks like there are merge conflicts

Copy link
Member

@lukasolson lukasolson left a comment

Choose a reason for hiding this comment

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

Code LGTM

@yctercero yctercero enabled auto-merge (squash) July 28, 2021 03:16
@yctercero yctercero added the auto-backport Deprecated - use backport:version if exact versions are needed label Jul 28, 2021
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
infra 939 940 +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
securitySolution 1245 1247 +2
timelines 763 768 +5
total +7

Async chunks

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

id before after diff
infra 1.7MB 1.7MB +6.0B

Page load bundle

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

id before after diff
infra 145.3KB 146.2KB +880.0B
securitySolution 208.2KB 208.2KB -2.0B
timelines 320.0KB 320.3KB +243.0B
total +1.1KB
Unknown metric groups

API count

id before after diff
data 3716 3717 +1
securitySolution 1296 1298 +2
timelines 882 887 +5
total +8

References to deprecated APIs

id before after diff
alerting 32 23 -9

History

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

cc @yctercero

@yctercero yctercero merged commit 44a9dad into elastic:master Jul 28, 2021
@kibanamachine
Copy link
Contributor

💔 Backport failed

Status Branch Result
7.x Commit could not be cherrypicked due to conflicts

To backport manually run:
node scripts/backport --pr 105333

yctercero added a commit to yctercero/kibana that referenced this pull request Jul 28, 2021
…lastic#105333)

## Summary

Adds RBAC layer to timeline plugin search strategy for alerts.
# Conflicts:
#	x-pack/plugins/alerting/server/alerting_authorization_client_factory.ts
yctercero added a commit that referenced this pull request Jul 29, 2021
…105333) (#107005)

## Summary

Adds RBAC layer to timeline plugin search strategy for alerts.
# Conflicts:
#	x-pack/plugins/alerting/server/alerting_authorization_client_factory.ts

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
streamich pushed a commit to vadimkibana/kibana that referenced this pull request Aug 8, 2021
…lastic#105333)

## Summary
 
Adds RBAC layer to timeline plugin search strategy for alerts.
@KOTungseth KOTungseth added the Feature:Timeline Security Solution Timeline feature label Sep 1, 2021
@yctercero yctercero deleted the alerts_as_data_tgrid branch October 13, 2021 06:26
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:RAC label obsolete Feature:Timeline Security Solution Timeline feature release_note:enhancement Theme: rac label obsolete v7.15.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants