-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLEET][SECURITY_SOLUTION] Fix .fleet-artifacs index property names a…
…nd add endpoint package policy migrations (#94977) * migration of Endpoint Integration policies to adjust artifact relative urs * Fix ``.fleet-artifacts` property name to be snake_cased
- Loading branch information
1 parent
416eea7
commit 7ebffc3
Showing
16 changed files
with
318 additions
and
55 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
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
145 changes: 145 additions & 0 deletions
145
x-pack/plugins/fleet/server/saved_objects/migrations/security_solution/to_v7_13_0.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,145 @@ | ||
/* | ||
* 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 { SavedObjectUnsanitizedDoc } from 'kibana/server'; | ||
import { cloneDeepWith, cloneDeep } from 'lodash'; | ||
|
||
import type { PackagePolicy } from '../../../../common'; | ||
|
||
import { migrationMocks } from '../../../../../../../src/core/server/mocks'; | ||
|
||
import { migrateEndpointPackagePolicyToV7130 } from './to_v7_13_0'; | ||
|
||
describe('7.13.0 Endpoint Package Policy migration', () => { | ||
const createOldPackagePolicySO = (): SavedObjectUnsanitizedDoc<PackagePolicy> => { | ||
return { | ||
id: 'mock-saved-object-id', | ||
attributes: { | ||
name: 'Some Policy Name', | ||
package: { | ||
name: 'endpoint', | ||
title: '', | ||
version: '', | ||
}, | ||
id: 'mock-saved-object-id', | ||
policy_id: '', | ||
enabled: true, | ||
namespace: '', | ||
output_id: '', | ||
revision: 0, | ||
updated_at: '', | ||
updated_by: '', | ||
created_at: '', | ||
created_by: '', | ||
inputs: [ | ||
{ | ||
type: 'endpoint', | ||
enabled: true, | ||
streams: [], | ||
config: { | ||
artifact_manifest: { | ||
value: { | ||
manifest_version: '1.0.0', | ||
schema_version: 'v1', | ||
artifacts: { | ||
'endpoint-exceptionlist-macos-v1': { | ||
encryption_algorithm: 'none', | ||
decoded_sha256: | ||
'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
decoded_size: 14, | ||
encoded_sha256: | ||
'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda', | ||
encoded_size: 22, | ||
relative_url: | ||
'/api/endpoint/artifacts/download/endpoint-exceptionlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
compression_algorithm: 'zlib', | ||
}, | ||
'endpoint-exceptionlist-windows-v1': { | ||
encryption_algorithm: 'none', | ||
decoded_sha256: | ||
'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
decoded_size: 14, | ||
encoded_sha256: | ||
'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda', | ||
encoded_size: 22, | ||
relative_url: | ||
'/api/endpoint/artifacts/download/endpoint-exceptionlist-windows-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
compression_algorithm: 'zlib', | ||
}, | ||
'endpoint-trustlist-macos-v1': { | ||
encryption_algorithm: 'none', | ||
decoded_sha256: | ||
'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
decoded_size: 14, | ||
encoded_sha256: | ||
'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda', | ||
encoded_size: 22, | ||
relative_url: | ||
'/api/endpoint/artifacts/download/endpoint-trustlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
compression_algorithm: 'zlib', | ||
}, | ||
'endpoint-trustlist-windows-v1': { | ||
encryption_algorithm: 'none', | ||
decoded_sha256: | ||
'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
decoded_size: 14, | ||
encoded_sha256: | ||
'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda', | ||
encoded_size: 22, | ||
relative_url: | ||
'/api/endpoint/artifacts/download/endpoint-trustlist-windows-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
compression_algorithm: 'zlib', | ||
}, | ||
'endpoint-trustlist-linux-v1': { | ||
encryption_algorithm: 'none', | ||
decoded_sha256: | ||
'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
decoded_size: 14, | ||
encoded_sha256: | ||
'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda', | ||
encoded_size: 22, | ||
relative_url: | ||
'/api/endpoint/artifacts/download/endpoint-trustlist-linux-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658', | ||
compression_algorithm: 'zlib', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
type: ' nested', | ||
}; | ||
}; | ||
const createNewPackagePolicySO = (): SavedObjectUnsanitizedDoc<PackagePolicy> => { | ||
return cloneDeepWith(createOldPackagePolicySO(), (value, key) => { | ||
if (key === 'relative_url') { | ||
return value.replace('/api/endpoint/artifacts/download/', '/api/fleet/artifacts/'); | ||
} | ||
}); | ||
}; | ||
|
||
const migrationContext = migrationMocks.createContext(); | ||
|
||
it('should adjust the relative url for all artifact manifests', () => { | ||
expect( | ||
migrateEndpointPackagePolicyToV7130(createOldPackagePolicySO(), migrationContext) | ||
).toEqual(createNewPackagePolicySO()); | ||
}); | ||
|
||
it('should NOT touch non-endpoint package policies', () => { | ||
const packagePolicySo = createOldPackagePolicySO(); | ||
packagePolicySo.attributes.package!.name = 'not endpoint'; | ||
|
||
const unchangedPackagePolicySo = cloneDeep(packagePolicySo); | ||
|
||
expect(migrateEndpointPackagePolicyToV7130(packagePolicySo, migrationContext)).toEqual( | ||
unchangedPackagePolicySo | ||
); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/fleet/server/saved_objects/migrations/security_solution/to_v7_13_0.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,39 @@ | ||
/* | ||
* 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 { SavedObjectMigrationFn } from 'kibana/server'; | ||
|
||
import type { PackagePolicy } from '../../../../common'; | ||
import { relativeDownloadUrlFromArtifact } from '../../../services/artifacts/mappings'; | ||
import type { ArtifactElasticsearchProperties } from '../../../services'; | ||
|
||
type ArtifactManifestList = Record< | ||
string, | ||
Pick<ArtifactElasticsearchProperties, 'identifier' | 'decoded_sha256' | 'relative_url'> | ||
>; | ||
|
||
export const migrateEndpointPackagePolicyToV7130: SavedObjectMigrationFn< | ||
PackagePolicy, | ||
PackagePolicy | ||
> = (packagePolicyDoc) => { | ||
if (packagePolicyDoc.attributes.package?.name === 'endpoint') { | ||
// Adjust all artifact URLs so that they point at fleet-server | ||
const artifactList: ArtifactManifestList = | ||
packagePolicyDoc.attributes?.inputs[0]?.config?.artifact_manifest.value.artifacts; | ||
|
||
if (artifactList) { | ||
for (const [identifier, artifactManifest] of Object.entries(artifactList)) { | ||
artifactManifest.relative_url = relativeDownloadUrlFromArtifact({ | ||
identifier, | ||
decodedSha256: artifactManifest.decoded_sha256, | ||
}); | ||
} | ||
} | ||
} | ||
|
||
return packagePolicyDoc; | ||
}; |
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
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
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
Oops, something went wrong.