[Security Solution] add policy_response_failure defend insight type#231908
Conversation
c116eef to
a34117f
Compare
|
Pinging @elastic/security-defend-workflows (Team:Defend Workflows) |
| * macOS: `sudo /Library/Elastic/Endpoint/elastic-endpoint test output` | ||
| * Windows: `C:\\Program Files\\Elastic\\Endpoint\\elastic-endpoint.exe test output` | ||
|
|
||
| If network connectivity is the problem and the output doesn't clarify the issue, consider using a tool like curl for further diagnosis. If incorrect proxy information is displayed, review the proxy configuration, noting that Defend advanced options can override these settings. For certificate issues, check the Fleet Server configuration and explore using one of the `advanced.artifacts.user.*` Defend advanced settings. |
There was a problem hiding this comment.
Can we include links to online webpages in these snippets?
There was a problem hiding this comment.
yeah, I think we can make it work.
There was a problem hiding this comment.
A few questions, but otherwise the code looks good to me. Two wishes though 😉:
- Could you add a script/tool to hydrate events with the policy response failure ones? It’ll make future development easier so we don’t have to generate them manually each time.
- Could you include usage examples - i.e., sample request and response? A quick reference for UI implementation phase
| /** | ||
| * The suggested remediation for the insight | ||
| */ | ||
| remediation: z.object({}).catchall(z.unknown()).optional(), |
There was a problem hiding this comment.
Q: Are we sure we cant tighten this?
There was a problem hiding this comment.
I'm intentionally leaving this more open since we're not sure what future remediation objects might look like.
| }, | ||
| index: number | ||
| ): string { | ||
| return `${event['actions.name'][index]}${splitKey}${event['actions.message'][index]}${splitKey}${event['host.os.name'][0]}`; |
There was a problem hiding this comment.
Could you leave a comment with an example of a returned value?
| .filter((bucket) => { | ||
| const actions = bucket.latest_event.hits.hits[0]._source.Endpoint.policy.applied.actions; | ||
| return actions.some((action) => action.status === 'failure' || action.status === 'warning'); | ||
| }) | ||
| .map((bucket) => { | ||
| const latestPolicyResponse = bucket.latest_event.hits.hits[0]; | ||
| const failedActions = latestPolicyResponse._source.Endpoint.policy.applied.actions.filter( | ||
| (action) => action.status === 'failure' || action.status === 'warning' | ||
| ); |
There was a problem hiding this comment.
We filter out failure || warning actions in both filter and map, is there a need for that?
There was a problem hiding this comment.
This is so that we don't have nulls in the returned array.
| promptGroupId: promptGroupId.defendInsights.policyResponseFailure, | ||
| promptIds: [ | ||
| promptDictionary.defendInsightsPolicyResponseFailureDefault, | ||
| promptDictionary.defendInsightsPolicyResponseFailureRefine, | ||
| promptDictionary.defendInsightsPolicyResponseFailureContinue, | ||
| promptDictionary.defendInsightsPolicyResponseFailureGroup, | ||
| promptDictionary.defendInsightsPolicyResponseFailureEvents, | ||
| promptDictionary.defendInsightsPolicyResponseFailureEventsId, | ||
| promptDictionary.defendInsightsPolicyResponseFailureEventsEndpointId, | ||
| promptDictionary.defendInsightsPolicyResponseFailureEventsValue, | ||
| promptDictionary.defendInsightsPolicyResponseFailureRemediation, | ||
| promptDictionary.defendInsightsPolicyResponseFailureRemediationMessage, |
There was a problem hiding this comment.
Q: Isnt there a mechanism to fetch all by promptGroupId?
There was a problem hiding this comment.
I don't think so, I only see getPrompt and getPromptsByGroupId in the exports and the promptIds arg is required.
| return getDefendInsightsIncompatibleVirusGenerationSchema(prompts); | ||
| switch (type) { | ||
| case DefendInsightType.Enum.incompatible_antivirus: | ||
| return getDefendInsightsIncompatibleVirusGenerationSchema(prompts); |
There was a problem hiding this comment.
getDefendInsightsIncompatibleVirusGenerationSchema can we stick to AntiVirus? Might be confusing to someone not familiar with this part of Kibana :D
| .describe(prompts.events), | ||
| remediation: z | ||
| .object({ | ||
| message: z.string().describe(prompts.remediationMessage ?? ''), |
There was a problem hiding this comment.
I see we expect a message field there. Maybe we can build the schema above step by step and start with message instead of leaving it open-ended for now?
There was a problem hiding this comment.
I might be misinterpreting your suggestion here but I think you're suggesting that we remove remediation and just have message? I did it this way:
- to make it clear it's a remediation message, not just a generic message
- to keep the schema for insights more consistent as we might have different remediation shapes in the future
| case DefendInsightType.Enum.policy_response_failure: | ||
| return buildPolicyResponseFailureWorkflowInsights(params); |
There was a problem hiding this comment.
Should we put it behind a feature flag?
There was a problem hiding this comment.
This is flagged at the API level. Agree that we'll want a flag at the UI level as well but that will be in separate PR when we add the API call for this insight type.
|
Thanks for taking a look @szwarckonrad 🙇.
I believe the
This is kind of chunky, I'll share with you on slack. |
2988783 to
7a46a7d
Compare
7a46a7d to
d06f7f7
Compare
Adds a new Defend Insight type, `policy_response_failure`. This Defend Insight type checks the endpoint policy responses for warnings and failures and provides remediation suggestions.
d06f7f7 to
c132340
Compare
| if (!ctx.licensing.license.hasAtLeast('enterprise')) { | ||
| return response.forbidden({ | ||
| body: { | ||
| message: | ||
| 'Your license does not support Defend Workflows. Please upgrade your license.', | ||
| 'Your license does not support Automatic Troubleshooting. Please upgrade your license.', | ||
| }, | ||
| }); | ||
| } |
There was a problem hiding this comment.
FYI, there's a helper utility for performing license, authenticated user and FF checks you can use:
There was a problem hiding this comment.
wasn't aware of this, thanks for the tip. since performChecks is explicitly checking the license req for AI assistant, going to leave this as is for now since we want defend insights to maintain a separate license req (even though technically it's the same level as AI assistant right now).
.../security/plugins/elastic_assistant/server/ai_assistant_data_clients/knowledge_base/index.ts
Outdated
Show resolved
Hide resolved
.../security/plugins/elastic_assistant/server/ai_assistant_data_clients/knowledge_base/index.ts
Outdated
Show resolved
Hide resolved
x-pack/platform/packages/shared/kbn-elastic-assistant-common/impl/capabilities/index.ts
Show resolved
Hide resolved
…ghts-policy-response-failures
natasha-moore-elastic
left a comment
There was a problem hiding this comment.
API doc changes LGTM
spong
left a comment
There was a problem hiding this comment.
Checked out, tested KB features locally with FF off, and code reviewed relevant GenAI changes -- LGTM! 👍
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
|
…lastic#231908) ## Summary Adds a new Defend Insight (AKA. Automatic Troubleshooting) type, `policy_response_failure`. This Defend Insight type checks the endpoint policy responses for warnings and failures and provides remediation suggestions. In order to provide better responses for policy response failures, this PR also introduces static KB assets for Defend Insights. `policy_response_failure` type requests are enriched with relevant KB assets. The new `policy_response_failure` Defend Insight type is feature flagged under `defendInsightsPolicyResponseFailure`. `anonymized_events_retriever` and `get_anonymized_events` directories renamed to `events_retriever` and `get_events` due to max path length restriction. This PR only contains the API changes for this feature. Corresponding [PR](elastic/integrations#14946) to update Security AI Prompt package. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Garrett Spong <spong@users.noreply.github.com>
| - combine duplicate insights into the same 'group' (e.g. AVG + AVG Free + AVG Hub + AVG Antivirus) | ||
| - remove insights with no events | ||
| `, | ||
| CONTINUE: `Continue exactly where you left off in the JSON output below, generating only the additional JSON output when it's required to complete your work. The additional JSON output MUST ALWAYS follow these rules: |
There was a problem hiding this comment.
Hey I'm updating the prompts for something else and I think you may have forgotten to update the integration when you made these changes. My PR will include your changes, so no action needed, but please remember to update the integration in the future
Summary
Adds a new Defend Insight (AKA. Automatic Troubleshooting) type,
policy_response_failure. This Defend Insight type checks the endpoint policy responses for warnings and failures and provides remediation suggestions.In order to provide better responses for policy response failures, this PR also introduces static KB assets for Defend Insights.
policy_response_failuretype requests are enriched with relevant KB assets.The new
policy_response_failureDefend Insight type is feature flagged underdefendInsightsPolicyResponseFailure.anonymized_events_retrieverandget_anonymized_eventsdirectories renamed toevents_retrieverandget_eventsdue to max path length restriction.This PR only contains the API changes for this feature.
Corresponding PR to update Security AI Prompt package.
Checklist