Skip to content

Commit

Permalink
marshall's changes + edits to hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
parkiino committed Sep 29, 2020
1 parent 321546a commit 56d2c99
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
31 changes: 21 additions & 10 deletions x-pack/plugins/security_solution/common/endpoint/index_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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']> => {
Expand Down Expand Up @@ -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: {
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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
PostIngestSetupResponse,
} from '../../../ingest_manager/common/types/rest_spec';

class KbnClientWithApiKeySupport extends KbnClient {
export class KbnClientWithApiKeySupport extends KbnClient {
private kibanaUrlNoAuth: string;
constructor(log: ToolingLog, kibanaConfig: KibanaConfig) {
super(log, kibanaConfig);
Expand All @@ -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> {
return (fetch(
`${this.kibanaUrlNoAuth}${path}`,
Expand Down

0 comments on commit 56d2c99

Please sign in to comment.