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

[Security Solution] [Detections] Only display actions options if user has "read" privileges #78812

Merged
merged 9 commits into from
Oct 2, 2020

Conversation

dhurley14
Copy link
Contributor

@dhurley14 dhurley14 commented Sep 29, 2020

Summary

Fixes #74170

updates the detections privileges route to include checking for "read" privilege on actions. Also updates the rule create / edit steps to display a message if the user is missing the actions privileges while still allowing the user to create and activate a rule.

testing:

This script will post a role with the necessary detections permissions

curl -H 'Content-Type: application/json' -H 'kbn-xsrf: 123'\
 -u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
-XPUT ${KIBANA_URL}/api/security/role/my_detections_role \
-d '{
  "elasticsearch": {
    "cluster": ["manage"],
    "indices": [
      {
        "names": ["auditbeat-*", "packetbeat-*", ".siem-signals-*", ".lists*", ".items*"],
        "privileges": ["manage", "write", "read"]
      }
    ]
  },
  "kibana": [
    {
      "feature": {
        "siem": ["all"],
        "actions": ["read"], // change this to "none" to see the rule actions dropdown change
        "builtInAlerts": ["all"],
        "dev_tools": ["all"],
        "savedObjectsManagement": ["all"]
      },
      "spaces": ["*"]
    }
  ]
}'

This is what the "Rule Actions" step on the rule creation form looks like if the user does not have "read" privileges for actions:

Screen Shot 2020-10-01 at 11 48 54 AM

And here it is on the edit page

Screen Shot 2020-10-01 at 11 49 11 AM

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@dhurley14 dhurley14 force-pushed the create-rule-actions-priv branch 2 times, most recently from c94b7a0 to 490d4b0 Compare September 30, 2020 18:14
@dhurley14 dhurley14 self-assigned this Sep 30, 2020
@dhurley14 dhurley14 added Feature:Detection Rules Anything related to Security Solution's Detection Rules review Team:SIEM v7.10.0 v8.0.0 labels Sep 30, 2020
@dhurley14 dhurley14 marked this pull request as ready for review September 30, 2020 20:06
@dhurley14 dhurley14 requested review from a team as code owners September 30, 2020 20:06
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@FrankHassanabad
Copy link
Contributor

This all works as is. Just tested it, but instead of us showing the error message in the combo box and populating it and running the risk of us pushing the value from the combo box to the backend:

Screen Shot 2020-09-30 at 8 20 29 PM

Can we change the code around here to remove the combo box and use regular text elements to display the error?

Somewhere down here add the conditional logic and html:

  return isReadOnlyView ? (
    <StepContentWrapper addPadding={addPadding}>
      <StepRuleDescription schema={schema} data={initialState} columns="single" />
    </StepContentWrapper>
  ) : (
    <>
      <StepContentWrapper addPadding={!isUpdateView}>
        <Form form={form} data-test-subj="stepRuleActions">
          <EuiForm>
            <UseField
              path="throttle"
              component={ThrottleSelectField}
              componentProps={throttleFieldComponentProps}
            />
            {throttle !== stepActionsDefaultValue.throttle ? (

@dhurley14 dhurley14 closed this Oct 1, 2020
@dhurley14 dhurley14 reopened this Oct 1, 2020
@dhurley14
Copy link
Contributor Author

dhurley14 commented Oct 1, 2020

Technically the value is still the default value of DEFAULT_THROTTLE_OPTION.value I'm just changing the text. I tried not rendering the form but then the submission button wanted a value for actions from that combo box So I figured rather than messing with the logic for submission and changing the request to the backend I would just update the text in the combo box and remove the options. I'll look into doing your suggestion though 👍

form={form}
style={{ display: application.capabilities.actions.show ? 'block' : 'none' }}
data-test-subj="stepRuleActions"
>
Copy link
Contributor

Choose a reason for hiding this comment

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

If things begin to feel or get messy in here, feel ok to drop all the boolean logic weirdness with expressions. That is meant to be a helper for when things look very templatey and nice in React but as time marches on along with permission booleans and things begin getting complex where we have branching logic within branching logic and things look like a bunch of && and ! mashed together we can refactor out the expressions and do regular:

if/else if/else if/else

or if we want to we can do the regular:
if (condition) return this chunk of code early/if (second condition) return this chunk of code ...

Since that will allow us to execute more than one block of code within brackets compared to excessive and hard to reason about expressions within expressions and React doing odd things like adding {false/null/undefined<></>} to its tree to later parse out and remove.

I would avoid having elements with block vs none on them compared to just not displaying the component altogether based on conditional logic. Usually it is better to omit an HTML element altogether and DOM weight unless we have a bunch of DOM elements that are constantly being added and removed in which case doing a shown vs. being hidden is better (It will then prevent reflows from happening).

Already looking at this logic if it was me writing the code I would drop all the boolean template expressions and just use normal if/else if logic rather than mixing all these booleans together and trying to get them all correct.

Already we have these that cause us to keep a lot of state in our head:

  • isReadOnlyView
  • isUpdateView
  • application.capabilities.actions.show

And the way the logic flows it's not clear branches that show relationships between the booleans but rather the booleans look rather disjointed from each other and nested within each other.

Copy link
Contributor

@FrankHassanabad FrankHassanabad Oct 1, 2020

Choose a reason for hiding this comment

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

Other tips is there is an unset css keyword if you're going this route you can utilize maybe instead of assuming that your form is always going to be a block:
https://developer.mozilla.org/en-US/docs/Web/CSS/unset#:~:text=The%20unset%20CSS%20keyword%20resets,its%20initial%20value%20if%20not.

Also you might be able to use destructoring to avoid assuming the block?

...{ application.capabilities.actions.show ? { display: 'block' } : {} }

But you will always render the form there when you have data as you introduce a new object but I don't think that's going to be a big deal.

Copy link
Contributor

@peluja1012 peluja1012 Oct 1, 2020

Choose a reason for hiding this comment

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

I agree with @FrankHassanabad's comment here. We could just do something like this to avoid having to use style block or none, right?

{ application.capabilities.actions.show && (
   <Form ...>...</Form>
)}

Copy link
Contributor Author

@dhurley14 dhurley14 Oct 2, 2020

Choose a reason for hiding this comment

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

The result of not rendering the actions step form is having to increase the complexity of the state of the whole rule creation form. The state of the rule creation form depends on pulling a default value from this and when the actions step form is not rendered, the rule creation form blows up. I'm going to look into using the GhostFormField and maybe rendering that with the throttle default somehow so that I don't need to mess with state.

Also a good thing to note, after talking with @rylnd I learned that we are submitting the entire form on edit. This implies that an analyst with no privileges on actions goes to edit a rule created by another analyst with actions privileges and they will be greeted with this error upon "save" in the "edit rules" page and the rule changes will not be saved.

Screen Shot 2020-10-01 at 5 11 30 PM

Copy link
Contributor

@FrankHassanabad FrankHassanabad left a comment

Choose a reason for hiding this comment

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

lgtm

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id before after diff
securitySolution 10.3MB 10.3MB +1.3KB

History

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

@dhurley14 dhurley14 merged commit 43cf97e into elastic:master Oct 2, 2020
@dhurley14 dhurley14 deleted the create-rule-actions-priv branch October 2, 2020 20:46
dhurley14 added a commit that referenced this pull request Oct 2, 2020
…f user has "read" privileges (#78812) (#79364)

* adds new 'can_read_actions' property to privileges api

* only display rule actions piece if user has 'read' privileges for actions

* display dropdown with custom text telling user they do not have read privileges for actions

* fixes type error

* update tests

* utilize application capabilities instead of making a server request

* remove changes to route tests

* don't show form unless user has read permissions for actions, display text saying user is missing required privileges

* pr feedback: refactor logic for rendering form fields
gmmorris added a commit to gmmorris/kibana that referenced this pull request Oct 5, 2020
* master: (128 commits)
  add core-js production dependency (elastic#79395)
  Add support for sharing saved objects to all spaces (elastic#76132)
  [Alerting UI] Display a banner to users when some alerts have failures, added alert statuses column and filters (elastic#79038)
  load js-yaml lazily (elastic#79092)
  skip flaky suite (elastic#77278)
  Fix agentPolicyUpdateEventHandler() to use app context soClient for creation of actions (elastic#79341)
  [Security Solution] Untitled Timeline created when first action is to add note (elastic#78988)
  [Security Solutions][Detection Engine] Updates the edit rules page to:wq! only have what is selected for editing (elastic#79233)
  Cleanup yarn.lock from duplicates (elastic#66617)
  [kbn/optimizer] implement more efficient auto transpilation for node (elastic#79052)
  [Ingest Manager] Rename Fleet setup and requirement, Fleet => Central… (elastic#79291)
  [core/server/plugins] don't run discovery in dev server parent process (take 2) (elastic#79358)
  [babel/register] remove from build (take 2) (elastic#79379)
  [Security Solution] Changes rules table tag display (elastic#77102)
  define integrationTestRoot in config file and use to define screensho… (elastic#79247)
  Revert "[babel/register] remove from build (elastic#79176)"
  skip flaky suite (elastic#75241)
  [Uptime] Synthetics UI (elastic#77960)
  [Security Solution] [Detections] Only display actions options if user has "read" privileges (elastic#78812)
  [babel/register] remove from build (elastic#79176)
  ...
gmmorris added a commit to gmmorris/kibana that referenced this pull request Oct 5, 2020
* master: (288 commits)
  add core-js production dependency (elastic#79395)
  Add support for sharing saved objects to all spaces (elastic#76132)
  [Alerting UI] Display a banner to users when some alerts have failures, added alert statuses column and filters (elastic#79038)
  load js-yaml lazily (elastic#79092)
  skip flaky suite (elastic#77278)
  Fix agentPolicyUpdateEventHandler() to use app context soClient for creation of actions (elastic#79341)
  [Security Solution] Untitled Timeline created when first action is to add note (elastic#78988)
  [Security Solutions][Detection Engine] Updates the edit rules page to only have what is selected for editing (elastic#79233)
  Cleanup yarn.lock from duplicates (elastic#66617)
  [kbn/optimizer] implement more efficient auto transpilation for node (elastic#79052)
  [Ingest Manager] Rename Fleet setup and requirement, Fleet => Central… (elastic#79291)
  [core/server/plugins] don't run discovery in dev server parent process (take 2) (elastic#79358)
  [babel/register] remove from build (take 2) (elastic#79379)
  [Security Solution] Changes rules table tag display (elastic#77102)
  define integrationTestRoot in config file and use to define screensho… (elastic#79247)
  Revert "[babel/register] remove from build (elastic#79176)"
  skip flaky suite (elastic#75241)
  [Uptime] Synthetics UI (elastic#77960)
  [Security Solution] [Detections] Only display actions options if user has "read" privileges (elastic#78812)
  [babel/register] remove from build (elastic#79176)
  ...
@MindyRS MindyRS added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Sep 23, 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
Feature:Detection Rules Anything related to Security Solution's Detection Rules release_note:fix review Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kibana alerting RBAC - impact on detection rules' actions
7 participants