Skip to content

[Security Solution] blocklist create/edit form#127098

Merged
joeypoon merged 2 commits intoelastic:mainfrom
joeypoon:feature/blocklist-create
Mar 16, 2022
Merged

[Security Solution] blocklist create/edit form#127098
joeypoon merged 2 commits intoelastic:mainfrom
joeypoon:feature/blocklist-create

Conversation

@joeypoon
Copy link
Member

@joeypoon joeypoon commented Mar 8, 2022

Summary

Add blocklist create/edit form.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@joeypoon joeypoon added Team:Defend Workflows “EDR Workflows” sub-team of Security Solution release_note:feature Makes this part of the condensed release notes auto-backport Deprecated - use backport:version if exact versions are needed ci:deploy-cloud v8.2.0 labels Mar 8, 2022
@joeypoon
Copy link
Member Author

joeypoon commented Mar 8, 2022

Still doing some cleanup, validation, and missing tests but functionally it's complete and works. Feel free to start reviewing.

@joeypoon joeypoon force-pushed the feature/blocklist-create branch 5 times, most recently from f97fdb0 to 77b13d6 Compare March 9, 2022 18:11
@joeypoon joeypoon marked this pull request as ready for review March 9, 2022 18:12
@joeypoon joeypoon requested a review from a team as a code owner March 9, 2022 18:12
@joeypoon joeypoon requested review from paul-tavares and pzl March 9, 2022 18:12
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-onboarding-and-lifecycle-mgt (Team:Onboarding and Lifecycle Mgt)

@joeypoon
Copy link
Member Author

joeypoon commented Mar 9, 2022

still working on tests but everything works now so ready for review. there is a bug where adding first blocklist doesn't auto refresh list page as well, looking into this.

@joeypoon joeypoon force-pushed the feature/blocklist-create branch 2 times, most recently from 94e471d to b35b9bd Compare March 9, 2022 19:21
@joeypoon joeypoon requested a review from a team as a code owner March 9, 2022 19:21
@kevinlog
Copy link
Contributor

kevinlog commented Mar 9, 2022

@joeypoon this is looking great! I checked it out and tried it. The basic functionality is there, I can add/edit/delete entries and the manifest creates the entries.

I did find some issues.

Width of is one of component

When I try to copy/paste hashes it work as expected, however the width of the component breaks the flyout.

Blocklist:
image

A similar component in Event Filters works much better, can we fix the width of the input/component to make it work better?

Event Filters:
image

Per policy works, but I'm not seeing the right UI feedback:

I'm not see the checkbox check when I click it.
image

I do the Policy actually get selected when created, however:
image

Manifest generation for hash.*

When we generate the manifest for hashes, we need to split them out based on type - sha256, md5, etc. Trusted Apps does something like this.

In Trusted Apps, we add something as a hash, it's represented as hash.* in the UI
image

However, if you look at the manifest, it will be linked up to a specific hash type.


{
  "entries": [
    {
      "type": "simple",
      "entries": [
        {
          "field": "process.hash.sha256",
          "operator": "included",
          "type": "exact_cased",
          "value": "559e66074a45750f5244809b316a63c6c09abd3d0969d4616f7d4bec6328583f"
        }
      ]
    }
  ]
}

We need to do something similar for Blocklist.

UI:
image

Manifest entry:

{
  "entries": [
    {
      "type": "simple",
      "entries": [
        {
          "field": "process.hash.*",
          "operator": "included",
          "type": "exact_cased_any",
          "value": [
            "559e66074a45750f5244809b316a63c6c09abd3d0969d4616f7d4bec6328583f"
          ]
        }
      ]
    }
  ]
}

I know we can have multiple hash types here. When creating the manifest, we can check and split those into the correct categories by checking which hash type it is and splitting it into separate entries.

Something like:

{
  "entries": [
    {
      "type": "simple",
      "entries": [
        {
          "field": "process.hash.md5",
          "operator": "included",
          "type": "exact_cased_any",
          "value": [
            "559e66074a45750f5244809b316a63c6c09abd3d0969d4616f7d4bec6328583f",
            "559e66074a45750f5244809b316a63c6c09abd3d0969d4616f7d4bec6328583c"
          ]
        }
      ]
    },
    {
      "type": "simple",
      "entries": [
        {
          "field": "process.hash.sha256",
          "operator": "included",
          "type": "exact_cased_any",
          "value": [
            "559e66074a45750f5244809b316a63c6c09abd3d0969d4616f7d4bec6328583f"
          ]
        }
      ]
    }
  ]
}

In manifest generation, Linux entries for process paths should always be exact_cased_any for the type

When creating a Linux option, the manifest should always the process path to have the type exact_cased_any. Trusted Apps does something similar.

If you look at the Linux entry created now for process path, you get:

{
  "entries": [
    {
      "type": "simple",
      "entries": [
        {
          "field": "process.executable",
          "operator": "included",
          "type": "exact_caseless_any",
          "value": [
            "/opt/bin/asdad",
            "/opt/bin/adaseses"
          ]
        }
      ]
    }
  ]
}

You should get:

{
  "entries": [
    {
      "type": "simple",
      "entries": [
        {
          "field": "process.executable",
          "operator": "included",
          "type": "exact_cased_any",
          "value": [
            "/opt/bin/asdad",
            "/opt/bin/adaseses"
          ]
        }
      ]
    }
  ]
}

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

Left some feedback and will try to check this out tomorrow and run it locally.

Overall, I found the approach to keeping track of error/warning/visited a little confusing by storing it in a simple object with two properties that hold array's of React nodes, but lets see how others feel about that. I asked for a quick explanation on the Type you defined on how that data is used and what it holds

Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these react nodes?

I'm also having a hard time understanding the fact that they are both arrays. What is stored in them exactly?

Copy link
Member Author

@joeypoon joeypoon Mar 10, 2022

Choose a reason for hiding this comment

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

helpText (warnings) and errors on EuiFormRow are typed as React.ReactNode[]. these are the actual warning/error messages we're passing directly into EuiFormRow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. thanks for that. ReactNode alway accepts string, but Its ok to store JSX here if that is preferable.

Can you explain the relation ship between the array of nodes for name and the array of nodes for value in the same object? thats the part that is confusing me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can probably have better naming here. the only places we need validation messages are on the name input and value input. the values under ItemValidation.name are all the validation messages for the name input and the values under ItemValidation.value are all the validation messages for the value input.

@paul-tavares paul-tavares requested a review from dasansol92 March 9, 2022 20:51
@joeypoon joeypoon force-pushed the feature/blocklist-create branch from b35b9bd to fcfa3cc Compare March 10, 2022 00:16
Copy link
Contributor

@dasansol92 dasansol92 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 looking awesome! Left some questions/suggestions, let me know if anything is not clear at all 🙂

@joeypoon joeypoon force-pushed the feature/blocklist-create branch 2 times, most recently from d3cc4ce to 69abec6 Compare March 10, 2022 22:52
Copy link
Member

@ashokaditya ashokaditya left a comment

Choose a reason for hiding this comment

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

Look good so far.

I took it for a spin and I noticed a few things

  1. upon creating a blocklist from the empty page, the item is added and a success toast is shown, but the entry doesn't show on the list page right away. It does show up on a refresh.
  2. Also, I could add an entry without a name.
  3. On editing the entry, changing the field from hash/signature (with its corresponding input value) to path doesn't trigger a warning. Same if you change to hash/signature from path. I would expect the same kind of warnings as we see in TA for field changes when input value already exists.

Screenshot 2022-03-14 at 15 57 26

Screenshot 2022-03-14 at 15 51 51

Copy link
Member

Choose a reason for hiding this comment

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

Agree with @dasansol92. Better to keep this as a separate type from TA entry types. Besides blocklist expects only match_any for now and not the other two.

@joeypoon joeypoon force-pushed the feature/blocklist-create branch 2 times, most recently from cde9d37 to 6bcf21a Compare March 15, 2022 04:25
@joeypoon joeypoon force-pushed the feature/blocklist-create branch from 5f9f492 to e55a91f Compare March 15, 2022 18:55
@joeypoon
Copy link
Member Author

joeypoon commented Mar 15, 2022

linux manifest + policy edit selection fixed. noticed an issue with validation state being out of sync, looking into that now.

Copy link
Member Author

Choose a reason for hiding this comment

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

considered making this more extensible such as passing entry overrides or something but figured we shouldn't over-engineer it right now.

@joeypoon joeypoon force-pushed the feature/blocklist-create branch 2 times, most recently from 0c37ced to 429a6b7 Compare March 15, 2022 19:20
@joeypoon joeypoon added the backport:skip This PR does not require backporting label Mar 15, 2022
Copy link
Contributor

@paul-tavares paul-tavares 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 awesome. Thanks for all the changes from the prior review. I left a few more, but nothing that should hold this from commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe on next commit, consider renaming this to isLoadingPolicies instead?

Comment on lines 35 to 40
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like @dasansol92 comment here.
Ideally , we should not have read/write transforms in this base class because it should all be using ExceptionListItemSchema and so there should be no need for transformation of data. I understand from our discussion over slack that this was in response to the UI using just a hash field for the user to enter any of the supported hashes, which we then calculate the field name based on the value entered (ex. process.hash.md5|sha1|sha256).
I'm just not sure if pushing that data value manipulation down to the API service is the right thing to do - to me, it feels move like a UI component prop type of mapping when setting/reading the value the user entered.

That being said, having a "middleware" callback for read/write is not a bad idea, so I'm 👍 this for now. We should really discuss if we want to continue to use those TrustedApp** types, since we have been trying to remove all of them in support of only ExceptionListItemSchema

(FYI: the mappers you moved around were originally in the server API for trusted apps, but moved to the UI when we deleted the TA specific API and started using the List Exceptions API. Our intent was to then have a second pass through to delete all of the types and adjust TA to be just like every other artifact)

cc/ @ashokaditya since he also recently moved around some TA types to the @kbn/** library

Copy link
Contributor

Choose a reason for hiding this comment

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

After thinking a bit more about it and after reading the comment above, I'm agree with what @paul-tavares has written.

As this is needed for UI maybe would be better to have it in an upper level. Also, we have plans to remove this types so we can just add this on that removal plan.

I would say let's move forward with this approach but let's take note about it in order to move/remove it when we get rid of the TA types.

PS: I like the way @joeypoon included this as a kind of hooks in this class. Let's keep this in mind for future pre/post validations, modifications, transformations, etc in frontend side.

@kevinlog
Copy link
Contributor

check it out again and the earlier issues are resolved!

Process path entries for Linux should be exacted_cased_any.

I am now seeing exact_cased_any for Linux paths

{
  "entries": [
    {
      "type": "simple",
      "entries": [
        {
          "field": "process.executable",
          "operator": "included",
          "type": "exact_cased_any",
          "value": [
            "/usr/bin"
          ]
        }
      ]
    }
  ]
}

and Windows paths are also correct:

{
  "entries": [
    {
      "type": "simple",
      "entries": [
        {
          "field": "process.executable",
          "operator": "included",
          "type": "exact_caseless_any",
          "value": [
            "C:\\Name\\Name"
          ]
        }
      ]
    }
  ]
}

Policy selection on Edit
This is also working for me now. When I saw the policy selection and open it back up for editing, the changes are reflected in the UI.

Copy link
Contributor

@kevinlog kevinlog left a comment

Choose a reason for hiding this comment

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

LGTM!

@paul-tavares
Copy link
Contributor

@joeypoon one thing I noticed in Kevin's screen capture is that we truncate the values (good), but am wondering, since things like paths can be very long, if we should use a larger size value for the flyout.

@kevinlog ^^ what do you think?

@joeypoon joeypoon force-pushed the feature/blocklist-create branch from 429a6b7 to 672faf1 Compare March 15, 2022 20:25
@joeypoon
Copy link
Member Author

@joeypoon one thing I noticed in Kevin's screen capture is that we truncate the values (good), but am wondering, since things like paths can be very long, if we should use a larger size value for the flyout.

@kevinlog ^^ what do you think?

I like this idea. I bumped it up to L size along with test fix.

Copy link
Member

@ashokaditya ashokaditya left a comment

Choose a reason for hiding this comment

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

I notice that I can create blocklist item without a name.
Screenshot 2022-03-15 at 21 30 32

@joeypoon joeypoon force-pushed the feature/blocklist-create branch from 672faf1 to 7422451 Compare March 15, 2022 23:17
@joeypoon joeypoon force-pushed the feature/blocklist-create branch from 7422451 to 641f261 Compare March 16, 2022 04:43
@joeypoon joeypoon enabled auto-merge (squash) March 16, 2022 04:52
@joeypoon
Copy link
Member Author

@elasticmachine merge upstream

@kibana-ci
Copy link

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2934 2938 +4

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
@kbn/securitysolution-utils 26 27 +1

Async chunks

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

id before after diff
securitySolution 4.7MB 4.8MB +6.4KB

Page load bundle

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

id before after diff
securitySolution 245.6KB 245.6KB +7.0B
Unknown metric groups

API count

id before after diff
@kbn/securitysolution-utils 28 29 +1

History

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

@joeypoon joeypoon merged commit 93fc801 into elastic:main Mar 16, 2022
@joeypoon joeypoon deleted the feature/blocklist-create branch March 16, 2022 17:30
maksimkovalev pushed a commit to maksimkovalev/kibana that referenced this pull request Mar 18, 2022
ashokaditya added a commit to ashokaditya/kibana that referenced this pull request Mar 18, 2022
ashokaditya added a commit that referenced this pull request Mar 23, 2022
…wildcard) in wildcard-ed event filter `file.path.text` (#127432)

* update filename regex to include multiple hyphens and periods

Uses a much simpler pattern that covers a whole gamut file name patterns.
fixes elastic/security-team/issues/3294

* remove duplicated code

* add tests for `process.name` entry for filenames with wildcard path

refs
/pull/120349
/pull/125202

* Add file.name optimized entry when wildcard filepath in file.path.text has a filename

fixes elastic/security-team/issues/3294

* update regex to include unicode chars

review changes

* add tests for `file.name` and `process.name` entries if it already exists

This works out of the box and we don't add endpoint related `file.name` or `process.name` entry when it already is added by the user

refs
/pull/127958#discussion_r829086447
elastic/security-team/issues/3199

* fix `file.name` and `file.path.text` entries for linux and mac/linux

refs /pull/127098

* do not add endpoint optimized entry

Add `file.name` and `process.name` entry for wildcard path values only when file.name and process.name entries do not already exist.

The earlier commit 8a516ae was mistakenly labeled as this worked out of the box. In the same commit we notice that the test data had a wildcard file path that did not add a `file.name` or `process.name` entry.

For more see:
/pull/127958#discussion_r829086447
elastic/security-team/issues/3199

* update regex to include gamut of unicode characters

review suggestions

* remove regex altogether

simplifies the logic to check if path is without wildcard characters. This way it includes all other strings as valid filenames that do not have * or ?

* update artifact creation for `file.path.text` entries

Similar to when we normalize `file.path.caseless` entries, except that the `type` is `*_cased` for linux and `*_caseless` for non-linux
@tylersmalley tylersmalley added ci:cloud-deploy Create or update a Cloud deployment and removed ci:deploy-cloud labels Aug 17, 2022
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 backport:skip This PR does not require backporting ci:cloud-deploy Create or update a Cloud deployment release_note:feature Makes this part of the condensed release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v8.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants