Skip to content

[Security Solution] [Endpoint] Add endpoint details activity log#99795

Merged
ashokaditya merged 34 commits intoelastic:masterfrom
ashokaditya:sec-team-1105/endpoint-details-activity-log
Jun 3, 2021
Merged

[Security Solution] [Endpoint] Add endpoint details activity log#99795
ashokaditya merged 34 commits intoelastic:masterfrom
ashokaditya:sec-team-1105/endpoint-details-activity-log

Conversation

@ashokaditya
Copy link
Copy Markdown
Member

@ashokaditya ashokaditya commented May 11, 2021

add tabs for endpoint details

Summary

Screenshot 2021-05-12 at 21 14 21

Checklist

Delete any items that are not applicable to this PR.

For maintainers

add tabs for endpoint details
this is work in progress with dummy data
@ashokaditya ashokaditya requested review from paul-tavares and pzl May 12, 2021 19:04
@ashokaditya
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

Copy link
Copy Markdown
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.

Some feedback left. I did not check it out, but its looking good.

Just FYI - I'm also making changes to the endpoint details in support of Host Isolation, so you, me or both might encounter some merge conflicts

const esClient = context.core.elasticsearch.client.asCurrentUser;
let result;
try {
result = await esClient.search({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a simple one, but if it get a bit more complicated we should consider moving the retrieval, status code validation of the result mapping to a service and leave the route handler as light as possible.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm inclined to move it to a service already. Also cause I'm doing a bunch of refactoring already.

@ashokaditya
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@ashokaditya
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

kibanamachine and others added 4 commits May 20, 2021 02:02
@ashokaditya
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

merge conflict between base and head

@elastic elastic deleted a comment from kibanamachine May 25, 2021
@ashokaditya
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

merge conflict between base and head

Copy link
Copy Markdown
Member

@pzl pzl left a comment

Choose a reason for hiding this comment

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

This doesn't seem to include action-responses yet, is that going to be a different PR?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can either leave this off this PR until we add the query definition, or at least add a comment saying this is for yet-to-come pagination query params

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

getting a bit long. Can probably refactor ( ['...',].includes(value) is probably fine, or extract up if it makes sense)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This doesn't seem to include action-responses yet, is that going to be a different PR?

Yes, I'll do that in the PR for the API that we discussed. Else the types were getting complex and hence more changes in this PR.

Copy link
Copy Markdown
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.

Provided some comments and will wait to hear from you on them.

if (
value === 'policy_response' ||
value === 'details' ||
value === 'activity-log' ||
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

perhaps it does not matter - but for the most part, we been using _ in values like this instead of -.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed. Let's keep it consistent with naming conventions. Snake case it is. 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done 1c54aaa

import { EuiAvatar, EuiComment, EuiText } from '@elastic/eui';
import { Immutable, EndpointAction } from '../../../../../../../common/endpoint/types';

export const TimelineEntry = memo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not for this PR.

The naming "timeline" might get confusing in our code based because we actually have an entire section of security solution named timeline. My suggestion would be to rename anything with timeline to a more specific name - like log_entry?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That makes sense 👍 I'd change that.

Copy link
Copy Markdown
Member Author

@ashokaditya ashokaditya May 31, 2021

Choose a reason for hiding this comment

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

done e38e202


const StyledEuiTabbedContent = styled(EuiTabbedContent)`
overflow: hidden;
padding-bottom: 48px;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should not be using hard coded px values (or colors), but rather grabbing these values from the theme variable that is available when you defined the value here as a code function in the string template. Example:

Suggested change
padding-bottom: 48px;
padding-bottom: {(props) => props.theme.eui.paddingSizes.xl};

In this case, it seems as if you need a padding value that might not exist. I would work with Bonnie to see if we can keep to defined sizes (xs, s, m, l, xl). If not then this might work (never tried it):

  padding-bottom: calc( {(props) => props.theme.eui.paddingSizes.l} + {(props) => props.theme.eui.paddingSizes.l}  );

styled components might also already provide some calc like functions - not sure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FYI - a while back I created this gist for my use in trying to understand what's available for use in the theme.eui:

https://gist.github.com/paul-tavares/303d718ac7f514d6ee681a3851407a7e

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree that hardcoded values are not maintainable. I'm quite sure this won't be needed when we refactor the tabs component to use the flyout#more-complicated-flyout component version. I'll change this to use the xl padding for now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done 31cf7af

<EuiComment
type={commentType}
username={endpointAction.user_id}
timestamp={moment(endpointAction['@timestamp']).fromNow().toString()}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should be using our own relative date component -

export const FormattedDateAndTime: React.FC<{ date: Date }> = ({ date }) => {
// If date is greater than or equal to 1h (ago), then show it as a date
// else, show it as relative to "now"
return Date.now() - date.getTime() >= 3.6e6 ? (
<>
<FormattedDate value={date} year="numeric" month="short" day="2-digit" />
{' @'}
<FormattedTime value={date} />
</>
) : (
<>
<FormattedRelative value={date} />
</>
);
};

Looks like timestamp prop accepts a ReactNode, so there should be no problem defining a component here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done e38e202

import { FlyoutBodyNoTopPadding } from './components/flyout_body_no_top_padding';
import { getEndpointListPath } from '../../../../common/routing';

const contentLoadingMarkup = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of a singleton, can you either convert this to a function (or Component) or defined inside of EndpointDetailsFlyout using useMemo().

Just not sure that we want to reuse the same JSX across multiple instances of EndpointDetailsFlyout

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done e38e202

});
}
if (result?.statusCode !== 200) {
return res.customError({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need to use customError() - kibana takes care of 500 errors if you just throw.

Suggestion:

throw new Error(`Error fetching actions log for agent_id ${req.params.agent_id}`);

Also, since this is a controlled failure and we're not returning anything about the actual error that happen in elasticsearch, you should log the error to kibana logs. You can get a logger instance from the endpoint context I think.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Does Kibana take care of 4xx errors as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done 8d46a98

@ashokaditya
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

expected head sha didn’t match current head ref.

@ashokaditya
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

Copy link
Copy Markdown
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 minor comments, but nothing that should hold this up. I'm good if you merge it. Great Job on this. Looks awesome.

import { EndpointAction } from '../../../../../common/endpoint/types';

export const mockActivityLogResponse = (agentId: string): EndpointAction[] => {
const activityLog: EndpointAction[] = [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ we also now have an Action generator, case that helps here in minimizing amount of mocks. See:

export class FleetActionGenerator extends BaseDataGenerator {

If you do end up using it, I would suggest you initialize the class instance with a seed (argument to the class constructor)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done 6a2cace

export const FormattedDateAndTime: React.FC<{ date: Date }> = ({ date }) => {
export const FormattedDateAndTime: React.FC<{ date: Date; showRelativeTime?: boolean }> = ({
date,
showRelativeTime = false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why add the new prop? do you want relative time to always be shown? if so, you might just want to use <FormattedRelativeTime> directly in your component. But if that is the case, I would also talk to Bonnie about that - always showing relative time (IMO) is not a good after the first 1h.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, I see what you mean. I guess I misunderstood you earlier. I assumed that we always want to show relative time. At least that's what it looked like in the mocks. This UX is still going to be worked on more in subsequent PRs. So we've time to make this slicker. 🙏

const activityLog: EndpointAction[] = [
{
action_id: `${agentId}-action_id`,
'@timestamp': new Date().toJSON(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👏 did not know about the .toJSON() method of the Date class 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

now I redundant mock file 6a2cace 😄

defaultMessage: 'Could not find activity log for host',
}),
text: i18n.translate('xpack.securitySolution.endpoint.activityLog.errorBody', {
defaultMessage: 'Please exit the flyout and select another host with actions.',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ Seems a bit weird to me that we're instructing the user to go find another host with actions. I don't think that is an activity that the user is normally doing across hosts (or is it? 🤔 😄 ). If they came to the actions log for the host it is because they are investigating this particular host.

cc/ @bfishel

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed. This is going to be part of the empty state and the not-found details banner that we saw the other day. Not sure if we've nailed it down yet. So the idea is if we don't have a host then we also won't have host actions log.

Screenshot 2021-06-02 at 14 49 00

Here's the link https://www.figma.com/file/BeTJy7bpHRPtHiNJtWU7Pj/OLM-7.12%2B?node-id=4476%3A0

@ashokaditya ashokaditya added the auto-backport Deprecated - use backport:version if exact versions are needed label Jun 2, 2021
@ashokaditya
Copy link
Copy Markdown
Member Author

@kibanamachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2225 2229 +4

Async chunks

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

id before after diff
securitySolution 6.9MB 6.9MB +10.2KB

History

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

@ashokaditya ashokaditya merged commit d4ecee6 into elastic:master Jun 3, 2021
@ashokaditya ashokaditya deleted the sec-team-1105/endpoint-details-activity-log branch June 3, 2021 07:23
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Jun 3, 2021
…stic#99795)

* WIP

add tabs for endpoint details

* fetch activity log for endpoint

this is work in progress with dummy data

* refactor to hold host details and activity log within endpointDetails

* api for fetching actions log

* add a selector for getting selected agent id

* use the new api to show actions log

* review changes

* move util function to common/utils

in order to use it in endpoint_hosts as well as in trusted _apps

review suggestion

* use util function to get API path

review suggestion

* sync url params with details active tab

review suggestion

* fix types due to merge commit

refs 3722552

* use AsyncResourseState type

review suggestions

* sort entries chronologically with recent at the top

* adjust icon sizes within entries to match mocks

* remove endpoint list paging stuff (not for now)

* fix import after sync with master

* make the search bar work (sort of)

this needs to be fleshed out in a later PR

* add tests to middleware for now

* use snake case for naming routes

review changes

* rename and use own relative time function

review change

* use euiTheme tokens

review change

* add a comment

review changes

* log errors to kibana log and unwind stack

review changes

* use FleetActionGenerator for mocking data

review changes

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Jun 3, 2021
) (#101244)

* WIP

add tabs for endpoint details

* fetch activity log for endpoint

this is work in progress with dummy data

* refactor to hold host details and activity log within endpointDetails

* api for fetching actions log

* add a selector for getting selected agent id

* use the new api to show actions log

* review changes

* move util function to common/utils

in order to use it in endpoint_hosts as well as in trusted _apps

review suggestion

* use util function to get API path

review suggestion

* sync url params with details active tab

review suggestion

* fix types due to merge commit

refs 3722552

* use AsyncResourseState type

review suggestions

* sort entries chronologically with recent at the top

* adjust icon sizes within entries to match mocks

* remove endpoint list paging stuff (not for now)

* fix import after sync with master

* make the search bar work (sort of)

this needs to be fleshed out in a later PR

* add tests to middleware for now

* use snake case for naming routes

review changes

* rename and use own relative time function

review change

* use euiTheme tokens

review change

* add a comment

review changes

* log errors to kibana log and unwind stack

review changes

* use FleetActionGenerator for mocking data

review changes

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Ashokaditya <am.struktr@gmail.com>
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 release_note:skip Skip the PR/issue when compiling release notes Team:Defend Workflows “EDR Workflows” sub-team of Security Solution v7.14.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants