-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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][ENDPOINT] Improve Endpoint Host data generator to also integrate with Ingest #74305
[SECURITY_SOLUTION][ENDPOINT] Improve Endpoint Host data generator to also integrate with Ingest #74305
Changes from 1 commit
293eeaf
2b5ab65
ad39d54
c2aea57
b71e438
73a0754
a8221bb
e3ef509
4deebbf
0e61d00
dfb9627
76db23b
a6b6d3f
848eec5
4caaf96
02cd8fa
58ef6d5
7b82e05
e8ead7f
51730fa
65596ec
047925b
c6ee44e
2f4d043
c3d9282
02d122f
321546a
56d2c99
edd7bde
575282e
369318c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,11 @@ import { | |
} from '../../../ingest_manager/common'; | ||
import { factory as policyConfigFactory } from './models/policy_config'; | ||
import { HostMetadata } from './types'; | ||
import { KbnClientWithApiKeySupport } from '../../scripts/endpoint/resolver_generator_script'; | ||
|
||
export async function indexHostsAndAlerts( | ||
client: Client, | ||
kbnClient: KbnClient & { | ||
requestWithApiKey: (path: string, init?: RequestInit | undefined) => Promise<Response>; | ||
}, | ||
kbnClient: KbnClientWithApiKeySupport, | ||
seed: string, | ||
numHosts: number, | ||
numDocs: number, | ||
|
@@ -85,9 +84,7 @@ function delay(ms: number) { | |
async function indexHostDocs( | ||
numDocs: number, | ||
client: Client, | ||
kbnClient: KbnClient & { | ||
requestWithApiKey: (path: string, init?: RequestInit | undefined) => Promise<Response>; | ||
}, | ||
kbnClient: KbnClientWithApiKeySupport, | ||
realPolicies: Record<string, CreatePackagePolicyResponse['item']>, | ||
epmEndpointPackage: GetPackagesResponse['response'][0], | ||
metadataIndex: string, | ||
|
@@ -273,9 +270,7 @@ const getEndpointPackageInfo = async ( | |
}; | ||
|
||
const fleetEnrollAgentForHost = async ( | ||
kbnClient: KbnClient & { | ||
requestWithApiKey: (path: string, init?: RequestInit | undefined) => Promise<Response>; | ||
}, | ||
kbnClient: KbnClientWithApiKeySupport, | ||
endpointHost: HostMetadata, | ||
agentPolicyId: string | ||
): Promise<undefined | PostAgentEnrollResponse['item']> => { | ||
|
@@ -321,17 +316,33 @@ const fleetEnrollAgentForHost = async ( | |
return; | ||
} | ||
|
||
const kibanaVersion = await kbnClient.fetchKibanaVersion().number; | ||
// Enroll an agent for the Host | ||
const body: PostAgentEnrollRequest['body'] = { | ||
type: 'PERMANENT', | ||
metadata: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a better {
//...
metadata: {
local: {
"elastic": {
"agent": {
"version": versionNumber
}
},
"host": {
"architecture": "x86_64",
"hostname": `artifact-downloader.${Date.now()}.elastic.co`,
"name": "artifact-downloader",
"id": "1c032ec0-3a94-4d54-9ad2-c5610c0eaba4",
"ip": [
"fe80::703b:b9e6:887d:7f5/64",
"10.0.2.15/24",
"::1/128",
"127.0.0.1/8"
],
"mac": [
"08:00:27:d8:c5:c0"
]
},
"os": {
"family": "windows",
"kernel": "10.0.19041.388 (WinBuild.160101.0800)",
"platform": "windows",
"version": "10.0",
"name": "Windows 10 Pro",
"full": "Windows 10 Pro(10.0)"
}
},
} change |
||
local: { | ||
host: endpointHost.host, | ||
elastic: { | ||
agent: { | ||
version: '8.0.0', | ||
}, | ||
}, | ||
host: { | ||
architecture: 'x86_64', | ||
hostname: endpointHost.host, | ||
name: endpointHost.host, | ||
id: '1c032ec0-3a94-4d54-9ad2-c5610c0eaba4', | ||
ip: ['fe80::703b:b9e6:887d:7f5/64', '10.0.2.15/24', '::1/128', '127.0.0.1/8'], | ||
mac: ['08:00:27:d8:c5:c0'], | ||
}, | ||
os: { | ||
family: 'windows', | ||
kernel: '10.0.19041.388 (WinBuild.160101.0800)', | ||
platform: 'windows', | ||
version: '10.0', | ||
name: 'Windows 10 Pro', | ||
full: 'Windows 10 Pro(10.0)', | ||
}, | ||
}, | ||
user_provided: { | ||
dev_agent_version: '0.0.1', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ import { | |
PostIngestSetupResponse, | ||
} from '../../../ingest_manager/common/types/rest_spec'; | ||
|
||
class KbnClientWithApiKeySupport extends KbnClient { | ||
export class KbnClientWithApiKeySupport extends KbnClient { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you move this to another file and import it from the files you need it, you should get rid of the cyclic dependency |
||
private kibanaUrlNoAuth: string; | ||
constructor(log: ToolingLog, kibanaConfig: KibanaConfig) { | ||
super(log, kibanaConfig); | ||
|
@@ -31,6 +31,9 @@ class KbnClientWithApiKeySupport extends KbnClient { | |
? matches[1] + matches[3].replace('/', '') | ||
: kibanaUrl.replace('/', ''); | ||
} | ||
/** | ||
* The fleet api to enroll and agent requires an api key when you mke the request, however KbnClient currently does not support sending an api key with the request. This function allows you to send an api key with a request. | ||
*/ | ||
requestWithApiKey(path: string, init?: RequestInit | undefined): Promise<Response> { | ||
marshallmain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return (fetch( | ||
`${this.kibanaUrlNoAuth}${path}`, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import from
resolver_generator_script.ts
is causing a cyclic dependency since that file also imports from here: https://github.com/elastic/kibana/blob/master/x-pack/plugins/security_solution/scripts/endpoint/resolver_generator_script.ts#L13