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 Assistant] Adds Security Labs Knowledge Base content #184885

Merged
merged 38 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7a9c882
Adds Security Labs Knowledge Base content
spong Jun 5, 2024
19d6b12
Migrates seclabs kb tool to use esStore instead of chain
spong Jun 6, 2024
9fa89fe
Merge branch 'main' into security-labs-kb
spong Jun 17, 2024
4348ce0
Fix the curious case of the snake
spong Jun 17, 2024
645e7ec
Merge branch 'main' of github.com:elastic/kibana into security-labs-kb
spong Jul 9, 2024
879c78a
Up ML node memory for ci-cloud-deploy, and enable assistantKnowledgeB…
spong Jul 9, 2024
35eb568
Merge branch 'main' into security-labs-kb
spong Jul 9, 2024
7da5efc
Enable assistantModelEvaluation FF
spong Jul 9, 2024
cb4e9d1
Fix LangSmith tracing for streaming
spong Jul 10, 2024
2e92072
Merge branch 'main' of github.com:elastic/kibana into security-labs-kb
spong Jul 15, 2024
180e8a0
Fix types and lint errors
spong Jul 15, 2024
ddc4e3d
Type fix and renamed kb content from mdx to md to get around doc buil…
spong Jul 16, 2024
847292f
Merge branch 'main' of github.com:elastic/kibana into security-labs-kb
spong Jul 16, 2024
576ffd2
Merge branch 'main' into security-labs-kb
spong Jul 17, 2024
81145e6
Merge branch 'main' of github.com:elastic/kibana into security-labs-kb
spong Jul 22, 2024
fba6149
Merge branch 'main' of github.com:elastic/kibana into security-labs-kb
spong Aug 13, 2024
7848453
Merge branch 'main' of github.com:elastic/kibana into security-labs-kb
patrykkopycinski Sep 30, 2024
6758c61
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 30, 2024
27324c9
fix
patrykkopycinski Oct 1, 2024
d1d78f9
Merge branch 'security-labs-kb' of github.com:spong/kibana into secur…
patrykkopycinski Oct 1, 2024
969dc19
fix
patrykkopycinski Oct 1, 2024
1f15547
fix
patrykkopycinski Oct 1, 2024
f2ec668
fix
patrykkopycinski Oct 1, 2024
79938ae
PR comments
patrykkopycinski Oct 1, 2024
883cbb9
esStore and chain cleanup
patrykkopycinski Oct 1, 2024
73ab5eb
PR comments
patrykkopycinski Oct 1, 2024
03f8587
fix
patrykkopycinski Oct 2, 2024
deeefe1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Oct 2, 2024
412cc26
Update docs
patrykkopycinski Oct 2, 2024
2393430
Merge branch 'security-labs-kb' of github.com:spong/kibana into secur…
patrykkopycinski Oct 2, 2024
07545e7
fix naming
patrykkopycinski Oct 2, 2024
5a59533
naming
patrykkopycinski Oct 2, 2024
deb26d2
fix
patrykkopycinski Oct 2, 2024
c71396f
change to .md format
patrykkopycinski Oct 2, 2024
c871ca4
fix security_labs_exists for v1 FF
patrykkopycinski Oct 2, 2024
9c60dca
include required esql queries
patrykkopycinski Oct 3, 2024
534a814
Merge branch 'main' into security-labs-kb
spong Oct 3, 2024
57c0b12
Merge branch 'main' into security-labs-kb
patrykkopycinski Oct 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ export const ReadKnowledgeBaseResponse = z.object({
is_setup_available: z.boolean().optional(),
is_setup_in_progress: z.boolean().optional(),
pipeline_exists: z.boolean().optional(),
security_labs_exists: z.boolean().optional(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ paths:
type: boolean
pipeline_exists:
type: boolean
security_labs_exists:
type: boolean
400:
description: Generic Error
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const isKnowledgeBaseSetup = (kbStatus: ReadKnowledgeBaseResponse | undef
return (
(kbStatus?.elser_exists &&
kbStatus?.esql_exists &&
kbStatus?.security_labs_exists &&
kbStatus?.index_exists &&
kbStatus?.pipeline_exists) ??
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export const useChatSend = ({
kbStatus?.elser_exists &&
kbStatus?.index_exists &&
kbStatus?.pipeline_exists &&
kbStatus?.esql_exists;
kbStatus?.esql_exists &&
kbStatus?.security_labs_exists;

// Handles sending latest user prompt to API
const handleSendMessage = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ export const KnowledgeBaseSettings: React.FC<Props> = React.memo(
// Resource enabled state
const isElserEnabled = kbStatus?.elser_exists ?? false;
const isESQLEnabled = kbStatus?.esql_exists ?? false;
const isSecurityLabsEnabled = kbStatus?.security_labs_exists ?? false;
const isKnowledgeBaseSetup =
(isElserEnabled && isESQLEnabled && kbStatus?.index_exists && kbStatus?.pipeline_exists) ??
(isElserEnabled &&
isESQLEnabled &&
isSecurityLabsEnabled &&
kbStatus?.index_exists &&
kbStatus?.pipeline_exists) ??
false;
const isSetupInProgress = kbStatus?.is_setup_in_progress ?? false;
const isSetupAvailable = kbStatus?.is_setup_available ?? false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import {
} from '@kbn/elastic-assistant-common';
import { z } from '@kbn/zod';

export const isEsqlSystemEntry = (
export const isSystemEntry = (
entry: KnowledgeBaseEntryResponse
): entry is KnowledgeBaseEntryResponse & {
type: DocumentEntryType;
kbResource: 'esql';
kbResource: 'esql' | 'security_labs';
} => {
return entry.type === DocumentEntryType.value && entry.kbResource === 'esql';
return (
entry.type === DocumentEntryType.value && ['esql', 'security_labs'].includes(entry.kbResource)
);
};

export const isKnowledgeBaseEntryCreateProps = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { KnowledgeBaseSettings } from '../knowledge_base_settings';
import { SetupKnowledgeBaseButton } from '../setup_knowledge_base_button';
import { useDeleteKnowledgeBaseEntries } from '../../assistant/api/knowledge_base/entries/use_delete_knowledge_base_entries';
import {
isEsqlSystemEntry,
isSystemEntry,
isKnowledgeBaseEntryCreateProps,
isKnowledgeBaseEntryResponse,
} from './helpers';
Expand Down Expand Up @@ -152,13 +152,13 @@ export const KnowledgeBaseSettingsManagement: React.FC = React.memo(() => {
openFlyout();
},
isDeleteEnabled: (entry: KnowledgeBaseEntryResponse) => {
return !isEsqlSystemEntry(entry);
return !isSystemEntry(entry);
},
onDeleteActionClicked: ({ id }: KnowledgeBaseEntryResponse) => {
deleteEntry({ ids: [id] });
},
isEditEnabled: (entry: KnowledgeBaseEntryResponse) => {
return !isEsqlSystemEntry(entry);
return !isSystemEntry(entry);
},
onEditActionClicked: ({ id }: KnowledgeBaseEntryResponse) => {
const entry = entries.data.find((e) => e.id === id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useAssistantContext } from '../../..';
import * as i18n from './translations';
import { BadgesColumn } from '../../assistant/common/components/assistant_settings_management/badges';
import { useInlineActions } from '../../assistant/common/components/assistant_settings_management/inline_actions';
import { isEsqlSystemEntry } from './helpers';
import { isSystemEntry } from './helpers';

export const useKnowledgeBaseTable = () => {
const { currentUserAvatar } = useAssistantContext();
Expand All @@ -29,7 +29,7 @@ export const useKnowledgeBaseTable = () => {
if (entry.kbResource === 'user') {
return 'userAvatar';
}
if (entry.kbResource === 'esql') {
if (['esql', 'security_labs'].includes(entry.kbResource)) {
return 'logoElastic';
}
return 'visText';
Expand Down Expand Up @@ -77,8 +77,8 @@ export const useKnowledgeBaseTable = () => {
render: (entry: KnowledgeBaseEntryResponse) => {
// TODO: Look up user from `createdBy` id if privileges allow
const userName = entry.users?.[0]?.name ?? 'Unknown';
const badgeItem = isEsqlSystemEntry(entry) ? 'Elastic' : userName;
const userImage = isEsqlSystemEntry(entry) ? (
const badgeItem = isSystemEntry(entry) ? 'Elastic' : userName;
const userImage = isSystemEntry(entry) ? (
<EuiIcon
type={'logoElastic'}
css={css`
Expand Down Expand Up @@ -118,7 +118,7 @@ export const useKnowledgeBaseTable = () => {
{
name: i18n.COLUMN_ENTRIES,
render: (entry: KnowledgeBaseEntryResponse) => {
return isEsqlSystemEntry(entry)
return isSystemEntry(entry)
? entry.text
: entry.type === DocumentEntryType.value
? '1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const SetupKnowledgeBaseButton: React.FC<Props> = React.memo(({ display }
kbStatus?.elser_exists &&
kbStatus?.index_exists &&
kbStatus?.pipeline_exists &&
kbStatus?.esql_exists;
kbStatus?.esql_exists &&
kbStatus?.security_labs_exists;

const onInstallKnowledgeBase = useCallback(() => {
setupKB(ESQL_RESOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { MappingRuntimeFields, Sort } from '@elastic/elasticsearch/lib/api/types';
import {
AggregationsAggregationContainer,
MappingRuntimeFields,
Sort,
} from '@elastic/elasticsearch/lib/api/types';
import { ElasticsearchClient, Logger } from '@kbn/core/server';

import { estypes } from '@elastic/elasticsearch';
Expand All @@ -22,6 +26,7 @@ interface FindOptions {
index: string;
runtimeMappings?: MappingRuntimeFields | undefined;
logger: Logger;
aggs?: Record<string, AggregationsAggregationContainer>;
}

export interface FindResponse<T> {
Expand All @@ -41,6 +46,7 @@ export const findDocuments = async <TSearchSchema>({
fields,
sortOrder,
logger,
aggs,
}: FindOptions): Promise<FindResponse<TSearchSchema>> => {
const query = getQueryFilter({ filter });
let sort: Sort | undefined;
Expand All @@ -67,6 +73,7 @@ export const findDocuments = async <TSearchSchema>({
index,
seq_no_primary_term: true,
size: perPage,
aggs,
});
return {
data: response,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ export class AIAssistantDataClient {
sortOrder,
filter,
fields,
aggs,
}: {
perPage: number;
page: number;
sortField?: string;
sortOrder?: string;
filter?: string;
fields?: string[];
aggs?: Record<string, estypes.AggregationsAggregationContainer>;
}): Promise<Promise<FindResponse<TSearchSchema>>> => {
const esClient = await this.options.elasticsearchClientPromise;
return findDocuments<TSearchSchema>({
Expand All @@ -118,6 +120,7 @@ export class AIAssistantDataClient {
index: this.indexTemplateAndPattern.alias,
sortOrder: sortOrder as estypes.SortOrder,
logger: this.options.logger,
aggs,
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ import {
} from './create_knowledge_base_entry';
import { EsDocumentEntry, EsIndexEntry, EsKnowledgeBaseEntrySchema } from './types';
import { transformESSearchToKnowledgeBaseEntry } from './transforms';
import { ESQL_DOCS_LOADED_QUERY } from '../../routes/knowledge_base/constants';
import {
ESQL_DOCS_LOADED_QUERY,
SECURITY_LABS_RESOURCE,
} from '../../routes/knowledge_base/constants';
import {
getKBVectorSearchQuery,
getStructuredToolForIndexEntry,
isModelAlreadyExistsError,
} from './helpers';
import { getKBUserFilter } from '../../routes/knowledge_base/entries/utils';
import { loadSecurityLabs } from '../../lib/langchain/content_loaders/security_labs_loader';

/**
* Params for when creating KbDataClient in Request Context Factory. Useful if needing to modify
Expand Down Expand Up @@ -203,9 +207,11 @@ export class AIAssistantKnowledgeBaseDataClient extends AIAssistantDataClient {
public setupKnowledgeBase = async ({
soClient,
installEsqlDocs = true,
installSecurityLabsDocs = true,
}: {
soClient: SavedObjectsClientContract;
installEsqlDocs?: boolean;
installSecurityLabsDocs?: boolean;
}): Promise<void> => {
if (this.options.getIsKBSetupInProgress()) {
this.options.logger.debug('Knowledge Base setup already in progress');
Expand Down Expand Up @@ -257,6 +263,16 @@ export class AIAssistantKnowledgeBaseDataClient extends AIAssistantDataClient {
this.options.logger.debug(`Knowledge Base docs already loaded!`);
}
}

if (installSecurityLabsDocs) {
const labsDocsLoaded = await this.isSecurityLabsDocsLoaded();
if (!labsDocsLoaded) {
this.options.logger.debug(`Loading Security Labs KB docs...`);
await loadSecurityLabs(this, this.options.logger);
} else {
this.options.logger.debug(`Security Labs Knowledge Base docs already loaded!`);
}
}
} catch (e) {
this.options.setIsKBSetupInProgress(false);
this.options.logger.error(`Error setting up Knowledge Base: ${e.message}`);
Expand Down Expand Up @@ -352,6 +368,18 @@ export class AIAssistantKnowledgeBaseDataClient extends AIAssistantDataClient {
return esqlDocs.length > 0;
};

/**
* Returns if Security Labs KB docs have been loaded
*/
public isSecurityLabsDocsLoaded = async (): Promise<boolean> => {
const securityLabsDocs = await this.getKnowledgeBaseDocumentEntries({
query: '',
kbResource: SECURITY_LABS_RESOURCE,
required: false,
});
return securityLabsDocs.length > 0;
};

/**
* Performs similarity search to retrieve LangChain Documents from the knowledge base
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: "2022 Elastic Global Threat Report Announcement"
slug: "2022-elastic-global-threat-report-announcement"
date: "2022-11-30"
description: "Discover our latest findings & strategic recommendations to better stay informed of potential directions threat actors may focus on."
author:
- slug: devon-kerr
image: "gtr-blog-image-720x420.jpg"
category:
- slug: reports
---

Today Elastic Security Labs celebrates another milestone: launching the [2022 Elastic Global Threat Report](https://www.elastic.co/explore/security-without-limits/global-threat-report), our inaugural summary of threat trends, forecasts, and recommendations. We analyzed millions of telemetry events from sources around the world to share these insights with you; all part of our continued commitment to transparency, and our mission to protect the world's data.

You can find the report [here](https://www.elastic.co/explore/security-without-limits/global-threat-report), we're excited to share it with you.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: "2022 Elastic Global Threat Report: Helping security leaders navigate today’s threat landscape"
slug: "2022-elastic-global-threat-report-helping-security-leaders-navigate-todays-threat-landscape"
date: "2022-11-30"
description: "A significant percentage of all cyber threats achieve a degree of success against technical, procedural, and human mitigations. So what is a company to do in the face of such unfavorable odds? Find out in this article."
author:
- slug: ken-exner
image: "gtr-blog-image-720x420.jpg"
category:
- slug: reports
---

As the threat landscape continues to evolve, cybersecurity stakes are growing exponentially higher for today’s organizations. Between Log4j, geopolitical tension, and increasing ransomware threats, security is not just at the top of the business agenda but also the societal agenda. Meanwhile, threat actors have adopted new capabilities and methods while increasing their cadence of activity.

Threat detection and response has come a long way since the firewall dissolved and the cloud took center stage. AI and machine learning, for example, have been major contributors to the advancement of cybersecurity. Machine learning is being used to identify malicious behavior from bad actors by modeling network behavior and improving overall threat detection.

What’s been difficult is the sea of sameness filled with vendors promising products to mitigate today’s threats while preparing for the next one. As the [2022 Elastic Global Threat Report](https://www.elastic.co/explore/security-without-limits/global-threat-report) outlines, a significant percentage of all threats achieve a degree of success against technical, procedural, and human mitigations. So what is a company to do in the face of such unfavorable odds? At Elastic, we believe there are several ingredients that are critical to managing today’s threat landscape.

## Build a program, not just a tool

Vendors need to start thinking about security products as more than software. They are part of a living, breathing program that takes care and feeding. For Elastic, it’s not just about shipping a solution; it’s about offering a holistic approach to security that happens to come with a great product. It’s sharing insights and best practices and creating a community focused on security data intelligence that extends the value of Elastic Security for customers.

The 2022 Elastic Threat Report is an important part of that program, and we’re excited to share our knowledge with the community. In addition to vital information from the Elastic Security Labs team, the report provides actionable guidance to security practitioners about how to maximize positive outcomes for their organizations.

## It takes an (open) community

The foundation of any good program is a strong community that can support and foster it. Take Elastic’s commitment to open security, for example. The community born from vendors being transparent about their security controls, detection rules, and threat logic can be a force multiplier of best practices across the entire industry.

When vendors engage their experts with experts from across the broader security community about new threats they’ve observed or innovative methods for detecting nuanced attacks, it creates greater scalability of system defenses — not just for the enterprise but also for their customers.

For example, at Elastic we recently opened our Endpoint Security [protections-artifacts repo](https://github.com/elastic/protections-artifacts), adding to our already open [detection-rules repo](https://github.com/elastic/detection-rules/tree/main/rules), to foster further collaboration with our community and be transparent about how we protect users.

## Treat the cause, not the symptom

Despite the ever-growing threat landscape and the risks that it poses, many organizations are still treating security symptoms instead of the cause. Companies can no longer afford to keep the security team siloed and separate from the engineering team. The two functions must work closely to build products and solutions that can withstand the barrage of advancing threats.

At Elastic, we design and build products with security in mind from the start, so it’s baked into every solution we ship to our customers. In fact, we take security so seriously that the office of InfoSec is part of the engineering organization.

We hope that the 2022 Elastic Global Threat Report will help your understanding of the important shifts in the threat landscape, and provide the information you need to make your organization more resilient, prepared, and protected.

[Download the 2022 Elastic Global Threat Report](https://www.elastic.co/explore/security-without-limits/global-threat-report).
Loading