Skip to content

Commit 56d2c99

Browse files
committed
marshall's changes + edits to hostname
1 parent 321546a commit 56d2c99

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

x-pack/plugins/security_solution/common/endpoint/index_data.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ import {
3232
} from '../../../ingest_manager/common';
3333
import { factory as policyConfigFactory } from './models/policy_config';
3434
import { HostMetadata } from './types';
35+
import { KbnClientWithApiKeySupport } from '../../scripts/endpoint/resolver_generator_script';
3536

3637
export async function indexHostsAndAlerts(
3738
client: Client,
38-
kbnClient: KbnClient & {
39-
requestWithApiKey: (path: string, init?: RequestInit | undefined) => Promise<Response>;
40-
},
39+
kbnClient: KbnClientWithApiKeySupport,
4140
seed: string,
4241
numHosts: number,
4342
numDocs: number,
@@ -85,9 +84,7 @@ function delay(ms: number) {
8584
async function indexHostDocs(
8685
numDocs: number,
8786
client: Client,
88-
kbnClient: KbnClient & {
89-
requestWithApiKey: (path: string, init?: RequestInit | undefined) => Promise<Response>;
90-
},
87+
kbnClient: KbnClientWithApiKeySupport,
9188
realPolicies: Record<string, CreatePackagePolicyResponse['item']>,
9289
epmEndpointPackage: GetPackagesResponse['response'][0],
9390
metadataIndex: string,
@@ -273,9 +270,7 @@ const getEndpointPackageInfo = async (
273270
};
274271

275272
const fleetEnrollAgentForHost = async (
276-
kbnClient: KbnClient & {
277-
requestWithApiKey: (path: string, init?: RequestInit | undefined) => Promise<Response>;
278-
},
273+
kbnClient: KbnClientWithApiKeySupport,
279274
endpointHost: HostMetadata,
280275
agentPolicyId: string
281276
): Promise<undefined | PostAgentEnrollResponse['item']> => {
@@ -321,17 +316,33 @@ const fleetEnrollAgentForHost = async (
321316
return;
322317
}
323318

319+
const kibanaVersion = await kbnClient.fetchKibanaVersion().number;
324320
// Enroll an agent for the Host
325321
const body: PostAgentEnrollRequest['body'] = {
326322
type: 'PERMANENT',
327323
metadata: {
328324
local: {
329-
host: endpointHost.host,
330325
elastic: {
331326
agent: {
332327
version: '8.0.0',
333328
},
334329
},
330+
host: {
331+
architecture: 'x86_64',
332+
hostname: endpointHost.host,
333+
name: endpointHost.host,
334+
id: '1c032ec0-3a94-4d54-9ad2-c5610c0eaba4',
335+
ip: ['fe80::703b:b9e6:887d:7f5/64', '10.0.2.15/24', '::1/128', '127.0.0.1/8'],
336+
mac: ['08:00:27:d8:c5:c0'],
337+
},
338+
os: {
339+
family: 'windows',
340+
kernel: '10.0.19041.388 (WinBuild.160101.0800)',
341+
platform: 'windows',
342+
version: '10.0',
343+
name: 'Windows 10 Pro',
344+
full: 'Windows 10 Pro(10.0)',
345+
},
335346
},
336347
user_provided: {
337348
dev_agent_version: '0.0.1',

x-pack/plugins/security_solution/scripts/endpoint/resolver_generator_script.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
PostIngestSetupResponse,
2020
} from '../../../ingest_manager/common/types/rest_spec';
2121

22-
class KbnClientWithApiKeySupport extends KbnClient {
22+
export class KbnClientWithApiKeySupport extends KbnClient {
2323
private kibanaUrlNoAuth: string;
2424
constructor(log: ToolingLog, kibanaConfig: KibanaConfig) {
2525
super(log, kibanaConfig);
@@ -31,6 +31,9 @@ class KbnClientWithApiKeySupport extends KbnClient {
3131
? matches[1] + matches[3].replace('/', '')
3232
: kibanaUrl.replace('/', '');
3333
}
34+
/**
35+
* 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.
36+
*/
3437
requestWithApiKey(path: string, init?: RequestInit | undefined): Promise<Response> {
3538
return (fetch(
3639
`${this.kibanaUrlNoAuth}${path}`,

0 commit comments

Comments
 (0)