-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Add step to the security solution plugi…
…n `start` phase (non-blocking) to check endpoint policy indices (#198089) ## Summary - adds a step to the plugin `start` phase to retrieve all Endpoint policies from Fleet and check to ensure they have backing DOT indices. - This is a follow up to PR #196953 - this check will be removed once it is deployed to Serverless, since it only needs to run once in that flavor of kibana
- Loading branch information
1 parent
811a238
commit fd615c7
Showing
4 changed files
with
98 additions
and
15 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...s/security_solution/server/endpoint/migrations/ensure_indices_exists_for_policies.test.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,47 @@ | ||
/* | ||
* 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 { createMockEndpointAppContextService } from '../mocks'; | ||
import { ensureIndicesExistsForPolicies } from './ensure_indices_exists_for_policies'; | ||
import { createPolicyDataStreamsIfNeeded as _createPolicyDataStreamsIfNeeded } from '../../fleet_integration/handlers/create_policy_datastreams'; | ||
|
||
jest.mock('../../fleet_integration/handlers/create_policy_datastreams'); | ||
const createPolicyDataStreamsIfNeededMock = | ||
_createPolicyDataStreamsIfNeeded as unknown as jest.Mock; | ||
|
||
describe('Ensure indices exists for policies migration', () => { | ||
let endpointAppContextServicesMock: ReturnType<typeof createMockEndpointAppContextService>; | ||
|
||
beforeEach(() => { | ||
endpointAppContextServicesMock = createMockEndpointAppContextService(); | ||
|
||
( | ||
endpointAppContextServicesMock.getInternalFleetServices().packagePolicy.listIds as jest.Mock | ||
).mockResolvedValue({ | ||
items: ['foo-1', 'foo-2', 'foo-3'], | ||
}); | ||
}); | ||
|
||
it('should query fleet looking for all endpoint integration policies', async () => { | ||
const fleetServicesMock = endpointAppContextServicesMock.getInternalFleetServices(); | ||
await ensureIndicesExistsForPolicies(endpointAppContextServicesMock); | ||
|
||
expect(fleetServicesMock.packagePolicy.listIds).toHaveBeenCalledWith(expect.anything(), { | ||
kuery: fleetServicesMock.endpointPolicyKuery, | ||
perPage: 10000, | ||
}); | ||
}); | ||
|
||
it('should call createPolicyDataStreamsIfNeeded() with list of existing policies', async () => { | ||
await ensureIndicesExistsForPolicies(endpointAppContextServicesMock); | ||
|
||
expect(createPolicyDataStreamsIfNeededMock).toHaveBeenCalledWith({ | ||
endpointServices: endpointAppContextServicesMock, | ||
endpointPolicyIds: ['foo-1', 'foo-2', 'foo-3'], | ||
}); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
...lugins/security_solution/server/endpoint/migrations/ensure_indices_exists_for_policies.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,31 @@ | ||
/* | ||
* 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 { createPolicyDataStreamsIfNeeded } from '../../fleet_integration/handlers/create_policy_datastreams'; | ||
import type { EndpointAppContextService } from '../endpoint_app_context_services'; | ||
|
||
export const ensureIndicesExistsForPolicies = async ( | ||
endpointServices: EndpointAppContextService | ||
): Promise<void> => { | ||
const logger = endpointServices.createLogger('startupPolicyIndicesChecker'); | ||
|
||
const fleetServices = endpointServices.getInternalFleetServices(); | ||
const soClient = fleetServices.savedObjects.createInternalUnscopedSoClient(); | ||
const endpointPoliciesIds = await fleetServices.packagePolicy.listIds(soClient, { | ||
kuery: fleetServices.endpointPolicyKuery, | ||
perPage: 10000, | ||
}); | ||
|
||
logger.info( | ||
`Checking to ensure [${endpointPoliciesIds.items.length}] endpoint policies have backing indices` | ||
); | ||
|
||
await createPolicyDataStreamsIfNeeded({ | ||
endpointServices, | ||
endpointPolicyIds: endpointPoliciesIds.items, | ||
}); | ||
}; |
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
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