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

[RAC] [RBAC] add space ids array to each alert document #105173

Merged
merged 21 commits into from
Jul 16, 2021

Conversation

dhurley14
Copy link
Contributor

@dhurley14 dhurley14 commented Jul 10, 2021

Summary

Since we cannot provide the space id during the generation of the security URI's in the feature privilege builder step (in plugin setup phase) we must filter them out during the fetch of the alert.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@dhurley14 dhurley14 self-assigned this Jul 11, 2021
@dhurley14 dhurley14 marked this pull request as ready for review July 14, 2021 20:00
@dhurley14 dhurley14 requested review from a team as code owners July 14, 2021 20:00
@dhurley14 dhurley14 added the auto-backport Deprecated - use backport:version if exact versions are needed label Jul 15, 2021
Copy link
Contributor

@xcrzx xcrzx left a comment

Choose a reason for hiding this comment

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

Thanks for the update, LGTM 👍

Comment on lines +263 to +265
// not sure why typescript needs the non-null assertion here
// we already assert the value is not undefined with the ternary
// still getting an error with the ternary.. strange.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a Typescript limitation. It is not smart enough to narrow down the type of a computed property inside if-else:

const obj: { prop?: string } = {}

if (obj.prop) {
  obj.prop.toLowerCase() // <- guard works, no type error
}

const prop: 'prop' = 'prop'
if (obj[prop]) {
  obj[prop].toLowerCase() // <- guard doesn't work, object is possibly 'undefined' error
}

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

Alerting changes LGTM

Copy link
Contributor

@ogupte ogupte left a comment

Choose a reason for hiding this comment

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

APM test updates LGTM

@dhurley14 dhurley14 enabled auto-merge (squash) July 16, 2021 17:56
@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 228 229 +1

Async chunks

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

id before after diff
apm 4.3MB 4.3MB +350.0B
observability 482.7KB 483.1KB +405.0B
total +755.0B

Page load bundle

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

id before after diff
apm 40.3KB 40.3KB +55.0B
infra 147.2KB 147.3KB +55.0B
total +110.0B
Unknown metric groups

API count

id before after diff
alerting 236 237 +1

History

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

cc @dhurley14

@dhurley14 dhurley14 merged commit dadeb78 into elastic:master Jul 16, 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 105173

Comment on lines +267 to +270
event[SPACE_IDS] =
event[SPACE_IDS] == null
? [spaceId]
: [spaceId, ...event[SPACE_IDS]!.filter((sid) => sid !== spaceId)];
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we're only adding space IDs for lifecycle alerts. Is there something preventing us from injecting the space ID inside the RuleDataClient bulk method so that persistence rule types and any future rule types will also automatically inject the space ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is true we could push down the space id from the plugins into the rule data client, which would then be accessible via the bulk method. I'll take a look at this.

Copy link
Contributor Author

@dhurley14 dhurley14 Jul 16, 2021

Choose a reason for hiding this comment

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

We would end up iterating over the data passed into bulk twice rather than once (like in the executor definitions), so not that optimal.

dhurley14 added a commit to dhurley14/kibana that referenced this pull request Jul 16, 2021
* kind of working solution... need to fix types.. would be great if all of this could go in the authorization class but I don't think we have access to the spaceids when we generate the kibana security action strings?

* update mapping type as array:true for space_ids field, fixes types, updates jest tests, adds integration tests

* undo changes in alerting authz class

* update snapshot for apm api integration test for rules writing alerts

* fix apm integration tests

* omit version and sequence from expected outcome

* re-add space id after this code was moved in master

* add another default space id to test

* fixes bug to remove duplicate spaceids

* add space ids filter to elasticsearch query, updates detection role

* update snapshot

* update type docs for alerts client

* remove dead code

* fix type error

* renames space ids field on alert documents from kibana.rac.alert.space_ids to kibana.space_ids

* fixes kb-rule-data-utils package

* update snapshots

* remove references to kibana.rac.alert.space_ids and replace with kibana.space_ids in rule registry integration tests and apm integration tests

* fix apm functional test snapshots

* undo index name changes I made in apm integration test configs

* update typedocs references to upstream, not local repo
# Conflicts:
#	x-pack/test/rule_registry/security_and_spaces/tests/trial/update_alert.ts
dhurley14 added a commit that referenced this pull request Jul 16, 2021
…06023)

* kind of working solution... need to fix types.. would be great if all of this could go in the authorization class but I don't think we have access to the spaceids when we generate the kibana security action strings?

* update mapping type as array:true for space_ids field, fixes types, updates jest tests, adds integration tests

* undo changes in alerting authz class

* update snapshot for apm api integration test for rules writing alerts

* fix apm integration tests

* omit version and sequence from expected outcome

* re-add space id after this code was moved in master

* add another default space id to test

* fixes bug to remove duplicate spaceids

* add space ids filter to elasticsearch query, updates detection role

* update snapshot

* update type docs for alerts client

* remove dead code

* fix type error

* renames space ids field on alert documents from kibana.rac.alert.space_ids to kibana.space_ids

* fixes kb-rule-data-utils package

* update snapshots

* remove references to kibana.rac.alert.space_ids and replace with kibana.space_ids in rule registry integration tests and apm integration tests

* fix apm functional test snapshots

* undo index name changes I made in apm integration test configs

* update typedocs references to upstream, not local repo
# Conflicts:
#	x-pack/test/rule_registry/security_and_spaces/tests/trial/update_alert.ts
@peluja1012 peluja1012 mentioned this pull request Jul 20, 2021
13 tasks
@KOTungseth KOTungseth added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Sep 1, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

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 release_note:enhancement Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Theme: rac label obsolete v7.15.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants