forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Endpoint] Fix Manifest Manger so that it works wi…
…th large (>10k) (elastic#174411) ## Summary ### Fleet Changes: - Two new utilities that return `AsyncIterator`'s: - one for working with ElasticSearch `.search()` method - one for working with SavedObjects `.find()` method - NOTE: although the `SavedObjects` client already supports getting back an `find` interface that returns an `AysncIterable`, I was not convenient to use in our use cases where we are returning the data from the SO back to an external consumer (services exposed by Fleet). We need to be able to first process the data out of the SO before returning it to the consumer, thus having this utility facilitates that. - both handle looping through ALL data in a given query (even if >10k) - new `fetchAllArtifacts()` method in `ArtifactsClient`: Returns an `AsyncIterator` enabling one to loop through all artifacts (even if >10k) - new `fetchAllItemIds()` method in `PackagePolicyService`: return an `AsyncIterator` enabling one to loop through all item IDs (even if >10k) - new `fetchAllItems()` method in `PackagePolicyService`: returns an `AsyncIterator` enabling one to loop through all package policies (even if >10k) ### Endpoint Changes: - Retrieval of existing artifacts as well as list of all policies and policy IDs now use new methods introduced into fleet services (above) - Added new config property - `xpack.securitySolution.packagerTaskTimeout` - to enable customer to adjust the timeout value for how long the artifact packager task can run. Default has been set to `20m` - Efficiencies around batch processing of updates to Policies and artifact creation - improved logging ### 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
- Loading branch information
1 parent
31fbc86
commit 9150f9f
Showing
26 changed files
with
1,580 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
x-pack/plugins/fleet/server/mocks/package_policy.mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { SavedObjectsFindResponse } from '@kbn/core-saved-objects-api-server'; | ||
|
||
import type { SavedObjectsFindResult } from '@kbn/core-saved-objects-api-server'; | ||
|
||
import { mapPackagePolicySavedObjectToPackagePolicy } from '../services/package_policies'; | ||
|
||
import type { PackagePolicy } from '../../common'; | ||
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../common'; | ||
|
||
import type { PackagePolicySOAttributes } from '../types'; | ||
|
||
const generatePackagePolicySOAttributesMock = ( | ||
overrides: Partial<PackagePolicySOAttributes> = {} | ||
): PackagePolicySOAttributes => { | ||
return { | ||
name: `Package Policy 1`, | ||
description: 'Policy for things', | ||
created_at: '2024-01-24T15:21:13.389Z', | ||
created_by: 'elastic', | ||
updated_at: '2024-01-25T15:21:13.389Z', | ||
updated_by: 'user-a', | ||
policy_id: '444-555-666', | ||
enabled: true, | ||
inputs: [], | ||
namespace: 'default', | ||
package: { | ||
name: 'endpoint', | ||
title: 'Elastic Endpoint', | ||
version: '1.0.0', | ||
}, | ||
revision: 1, | ||
is_managed: false, | ||
secret_references: [], | ||
vars: {}, | ||
elasticsearch: { | ||
privileges: { | ||
cluster: [], | ||
}, | ||
}, | ||
agents: 2, | ||
|
||
...overrides, | ||
}; | ||
}; | ||
|
||
const generatePackagePolicyMock = (overrides: Partial<PackagePolicy> = {}) => { | ||
return { | ||
...mapPackagePolicySavedObjectToPackagePolicy(generatePackagePolicySavedObjectMock()), | ||
...overrides, | ||
}; | ||
}; | ||
|
||
const generatePackagePolicySavedObjectMock = ( | ||
soAttributes: PackagePolicySOAttributes = generatePackagePolicySOAttributesMock() | ||
): SavedObjectsFindResult<PackagePolicySOAttributes> => { | ||
return { | ||
score: 1, | ||
id: 'so-123', | ||
type: PACKAGE_POLICY_SAVED_OBJECT_TYPE, | ||
version: 'abc', | ||
created_at: soAttributes.created_at, | ||
updated_at: soAttributes.updated_at, | ||
attributes: soAttributes, | ||
references: [], | ||
sort: ['created_at'], | ||
}; | ||
}; | ||
|
||
const generatePackagePolicySavedObjectFindResponseMock = ( | ||
soResults?: PackagePolicySOAttributes[] | ||
): SavedObjectsFindResponse<PackagePolicySOAttributes> => { | ||
const soList = soResults ?? [ | ||
generatePackagePolicySOAttributesMock(), | ||
generatePackagePolicySOAttributesMock(), | ||
]; | ||
|
||
return { | ||
saved_objects: soList.map((soAttributes) => { | ||
return { | ||
score: 1, | ||
id: 'so-123', | ||
type: PACKAGE_POLICY_SAVED_OBJECT_TYPE, | ||
version: 'abc', | ||
created_at: soAttributes.created_at, | ||
updated_at: soAttributes.updated_at, | ||
attributes: soAttributes, | ||
references: [], | ||
sort: ['created_at'], | ||
}; | ||
}), | ||
total: soList.length, | ||
per_page: 10, | ||
page: 1, | ||
pit_id: 'pit-id-1', | ||
}; | ||
}; | ||
|
||
export const PackagePolicyMocks = Object.freeze({ | ||
generatePackagePolicySOAttributes: generatePackagePolicySOAttributesMock, | ||
generatePackagePolicySavedObjectFindResponse: generatePackagePolicySavedObjectFindResponseMock, | ||
generatePackagePolicy: generatePackagePolicyMock, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.