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][Exceptions] - Update exception item comments to include id #73129

Merged
merged 6 commits into from
Jul 27, 2020

Conversation

yctercero
Copy link
Contributor

@yctercero yctercero commented Jul 23, 2020

Summary

This PR is somewhat of an intermediary step. Comments on exception list items are denormalized. We initially decided that we would not add uuid to comments, but found that it is in fact necessary. This is intermediary in the sense that what we ideally want to have is a dedicated comments CRUD route.

Also just note that I added a callout for when a version conflict occurs (ie: exception item was updated by someone else while a user is editing the same item).

With this PR users are able to:

  • Create comments when creating exception list items
  • Add new comments on exception item update

Users will currently be blocked from:

  • Deleting comments
  • Updating comments
  • Updating exception item if version conflict is found

Conflict callout

Screen Shot 2020-07-23 at 3 01 01 PM

TO DO

Checklist

For maintainers

  • This was checked for breaking API changes and was labeled appropriately
    • Yes, it is breaking, API is not yet in prod

@@ -65,7 +65,7 @@ describe('create_endpoint_list_item_schema', () => {
expect(message.schema).toEqual({});
});

test('it should not validate a "list_id" since it does not required one', () => {
test('it should fail validation when supplied a "list_id" since it does not required one', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rylnd you'd mentioned the wording not validate was a bit misleading, so began updating the wording. Does this seem better?


import { Comments, CommentsArray } from './comments';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made these singular, was really confusing when it was plural but referred to a single comment schema.

created_at: t.string, // TODO: Make this into an ISO Date string check,
created_by: t.string,
comment: NonEmptyString,
created_at,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to use the same ones that are in common, so when we update those to be ISO Date types, these are good to go as well.

} else if (existingComment.created_at !== comment.created_at) {
throw new ErrorWithStatusCode('Unable to update comment', 403);
} else if (comment.comment.trim().length === 0) {
throw new ErrorWithStatusCode('Empty comments not allowed', 403);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now delegated to schema validation.

if (comments != null) {
return comments.map((c: CreateComments) => {
if (c.comment.trim().length === 0) {
throw new ErrorWithStatusCode('Empty comments not allowed', 403);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now delegated to schema validation.

@@ -377,7 +377,7 @@ export const ExceptionBuilder = ({
)}
<EuiFlexItem grow={1}>
<BuilderButtonOptions
isOrDisabled={disableOr}
isOrDisabled={isOrDisabled ? isOrDisabled : disableOr}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If builder consumer specifies that OR should be disabled no matter what, makes sure it does so and is not overwritten by disableOr logic.

addError(error, { title: i18n.EDIT_EXCEPTION_ERROR });
onCancel();
if (error.message.includes('Conflict')) {
setHasVersionConflict(true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If there's a conflict error, am showing a EuiCallout and not closing modal. Let's say a user spent 20 minutes writing a comment, for example, if we just close it, they lose it. This gives the user the chance to copy anything they need to.

@@ -172,11 +178,16 @@ export const EditExceptionModal = memo(function EditExceptionModal({
);

const enrichExceptionItems = useCallback(() => {
const [exceptionItemToEdit] = exceptionItemsToAdd;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Workaround as OR is disabled for now, so only need to update single item.

@@ -258,6 +269,14 @@ export const EditExceptionModal = memo(function EditExceptionModal({
</>
)}

{hasVersionConflict && (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marrasherrier @dontcallmesherryli Any feedback on where this should be shown?

@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@marrasherrier
Copy link
Contributor

marrasherrier commented Jul 23, 2020

would it be possible to have the error message outside the modal, like in the bottom right corner? if not, that error message placement looks ok to me. perhaps we could also disable everything besides the cancel button, so users can't ignore the message

}): Comments => {
if (comment.created_by !== user) {
}): Comment => {
if (incomingComment.id == null) {
Copy link
Contributor

@peluja1012 peluja1012 Jul 24, 2020

Choose a reason for hiding this comment

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

I'm seeing some issues when trying to edit an exception that has been changed at the same time by the same user (in another browser) or by another user. The steps I'm following are:

  1. Create an exception with one comment in one browser (Firefox)
  2. In another browser (Chrome) click "Edit" on that recently added exception but don't edit it and don't click submit.
  3. Back in the Firefox window edit the exception by adding a new comment
  4. In the Chrome window add a new comment and click submit

Before this change, in the master branch, I get a 403 on PUT /api/exception_lists/items error with the following message:

When trying to update a comment, "created_at" and "created_by" must be present

After this change, in this branch, I get a 401 unathorized error on PUT /api/exception_lists/items and get logged out of Kibana. It looks like this is the line that's throwing the error

throw new ErrorWithStatusCode(`Cannot delete comment id: ${matchingCommentByIndex.id}`, 401);

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks so much for catching this Pedro. I updated the API to currently be append only. I was doing validations and transformations prior to the version check. I removed much of this and am now just checking that the incoming comments are append only. Still working to have full CRUD in an upcoming release.

// cannot delete, only append at the moment
// TODO: Add new comments endpoint to fully support CRUD
if (!idMatches && index < existingComments.length) {
throw new ErrorWithStatusCode(`Cannot delete comment id: ${matchingCommentByIndex.id}`, 401);
Copy link
Contributor

@peluja1012 peluja1012 Jul 24, 2020

Choose a reason for hiding this comment

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

I think we're overusing the 401 error code in this file. This seems to be causing unexpected side effects like the user getting logged out of Kibana. We should consider using a different error code like 400 for these types of errors. @FrankHassanabad @madirey thoughts?

Copy link
Contributor

@madirey madirey Jul 24, 2020

Choose a reason for hiding this comment

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

Yes, these probably should be 400's. 401 should only be used on failure to authenticate, 403 for attempts to access a resource that the authenticated user does not have permission to access.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @peluja1012 and @madirey ! I simplified validations and made comments append only. Full CRUD is a wip for now.

Copy link
Contributor

@peluja1012 peluja1012 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 helping us fix these issues with the Edit flow! I left a couple of comments related to issues when editing exceptions concurrently with exception comments.

Copy link
Contributor

@peluja1012 peluja1012 left a comment

Choose a reason for hiding this comment

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

Pulled updated branch and verified that the issues that I was experiencing with editing an exception with existing comments are no longer there. Thanks for the changes, @yctercero!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

async chunks size

id value diff baseline
securitySolution 7.3MB +2.7KB 7.3MB

page load bundle size

id value diff baseline
lists 269.4KB +441.0B 269.0KB
securitySolution 870.7KB +98.0B 870.6KB
total - +539.0B -

Saved Objects .kibana field count

id value diff baseline
exception-list 38 +1 37
exception-list-agnostic 38 +1 37
total - +2 -

History

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

@yctercero yctercero merged commit 94ed783 into elastic:master Jul 27, 2020
yctercero added a commit to yctercero/kibana that referenced this pull request Jul 27, 2020
…nclude id (elastic#73129)

## Summary

This PR is somewhat of an intermediary step. Comments on exception list items are denormalized. We initially decided that we would not add `uuid` to comments, but found that it is in fact necessary. This is intermediary in the sense that what we ideally want to have is a dedicated `comments` CRUD route. 

Also just note that I added a callout for when a version conflict occurs (ie: exception item was updated by someone else while a user is editing the same item).

With this PR users are able to:
- Create comments when creating exception list items
- Add new comments on exception item update

Users will currently be blocked from:
- Deleting comments
- Updating comments
- Updating exception item if version conflict is found
yctercero added a commit to yctercero/kibana that referenced this pull request Jul 27, 2020
…nclude id (elastic#73129)

## Summary

This PR is somewhat of an intermediary step. Comments on exception list items are denormalized. We initially decided that we would not add `uuid` to comments, but found that it is in fact necessary. This is intermediary in the sense that what we ideally want to have is a dedicated `comments` CRUD route. 

Also just note that I added a callout for when a version conflict occurs (ie: exception item was updated by someone else while a user is editing the same item).

With this PR users are able to:
- Create comments when creating exception list items
- Add new comments on exception item update

Users will currently be blocked from:
- Deleting comments
- Updating comments
- Updating exception item if version conflict is found
yctercero added a commit that referenced this pull request Jul 28, 2020
…nclude id (#73129) (#73374)

## Summary

This PR is somewhat of an intermediary step. Comments on exception list items are denormalized. We initially decided that we would not add `uuid` to comments, but found that it is in fact necessary. This is intermediary in the sense that what we ideally want to have is a dedicated `comments` CRUD route. 

Also just note that I added a callout for when a version conflict occurs (ie: exception item was updated by someone else while a user is editing the same item).

With this PR users are able to:
- Create comments when creating exception list items
- Add new comments on exception item update

Users will currently be blocked from:
- Deleting comments
- Updating comments
- Updating exception item if version conflict is found
yctercero added a commit that referenced this pull request Jul 28, 2020
…nclude id (#73129) (#73375)

## Summary

This PR is somewhat of an intermediary step. Comments on exception list items are denormalized. We initially decided that we would not add `uuid` to comments, but found that it is in fact necessary. This is intermediary in the sense that what we ideally want to have is a dedicated `comments` CRUD route. 

Also just note that I added a callout for when a version conflict occurs (ie: exception item was updated by someone else while a user is editing the same item).

With this PR users are able to:
- Create comments when creating exception list items
- Add new comments on exception item update

Users will currently be blocked from:
- Deleting comments
- Updating comments
- Updating exception item if version conflict is found
@madirey
Copy link
Contributor

madirey commented Jul 28, 2020

I'm late to the party, but LGTM! Thanks for the updates!

gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 28, 2020
* master: (44 commits)
  [Search] add server logs (elastic#72454)
  [SIEM][Timelines] Updates timeline template callout text (elastic#73334)
  Fix App status  flaky test (elastic#72853)
  [Functional Tests] Increase the timeout when locating the tableview] (elastic#73243)
  Use "Apply_filter_trigger" in dashboard drilldown (elastic#71468)
  fix dashboard index pattern race condition (elastic#72899)
  [Functional Tests] Increase waitTime for timelion to fetch the results (elastic#73255)
  [Functional Tests] Fix flakiness on TSVB chart on switching index patterns test (elastic#73238)
  updates cypress to v4.11.0 (elastic#73327)
  [Metrics UI] Saved views bugs (elastic#72518)
  [Ingest Manager] Convert select agent config step to use combo box (elastic#73172)
  Exclude `version` from package config attributes that are copied, add safeguard to package config bulk create (elastic#73128)
  [Security Solution][ML] Updates siem group name to security (elastic#73218)
  [Security Solution] Show proper icon for termination status of all processes (elastic#73235)
  [Security Solution][Resolver] Show origin node details in panel on load (elastic#73313)
  [Security solution] Threat hunting test coverage improvements (elastic#73276)
  [Security Solution][Exceptions] - Update exception item comments to include id (elastic#73129)
  [Enterprise Search] Error state UI tweaks to account for current Cloud SSO behavior (elastic#73324)
  [dev/build/docker_generator] convert to typescript (elastic#73339)
  [APM] Fix focus map link on service map (elastic#73338)
  ...
@yctercero yctercero deleted the comments_again branch October 14, 2020 12:00
@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
release_note:enhancement Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.9.0 v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants