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]Memory protection configuration card for policies …
…integration. (elastic#101365) (elastic#106129) Co-authored-by: Esteban Beltran <academo@users.noreply.github.com>
- Loading branch information
1 parent
e68d613
commit 74e944e
Showing
21 changed files
with
611 additions
and
59 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
174 changes: 174 additions & 0 deletions
174
x-pack/plugins/fleet/server/saved_objects/migrations/security_solution/to_v7_15_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,174 @@ | ||
/* | ||
* 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 { SavedObjectMigrationContext, SavedObjectUnsanitizedDoc } from 'kibana/server'; | ||
|
||
import type { PackagePolicy } from '../../../../common'; | ||
|
||
import { migratePackagePolicyToV7150 as migration } from './to_v7_15_0'; | ||
|
||
describe('7.15.0 Endpoint Package Policy migration', () => { | ||
const policyDoc = ({ | ||
windowsMemory = {}, | ||
windowsPopup = {}, | ||
windowsMalware = {}, | ||
windowsRansomware = {}, | ||
}) => { | ||
return { | ||
id: 'mock-saved-object-id', | ||
attributes: { | ||
name: 'Some Policy Name', | ||
package: { | ||
name: 'endpoint', | ||
title: '', | ||
version: '', | ||
}, | ||
id: 'endpoint', | ||
policy_id: '', | ||
enabled: true, | ||
namespace: '', | ||
output_id: '', | ||
revision: 0, | ||
updated_at: '', | ||
updated_by: '', | ||
created_at: '', | ||
created_by: '', | ||
inputs: [ | ||
{ | ||
type: 'endpoint', | ||
enabled: true, | ||
streams: [], | ||
config: { | ||
policy: { | ||
value: { | ||
windows: { | ||
...windowsMalware, | ||
...windowsRansomware, | ||
...windowsMemory, | ||
...windowsPopup, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
type: ' nested', | ||
}; | ||
}; | ||
|
||
it('adds windows memory protection alongside malware and ramsomware', () => { | ||
const initialDoc = policyDoc({ | ||
windowsMalware: { malware: { mode: 'off' } }, | ||
windowsRansomware: { ransomware: { mode: 'off', supported: true } }, | ||
windowsPopup: { | ||
popup: { | ||
malware: { | ||
message: '', | ||
enabled: true, | ||
}, | ||
ransomware: { | ||
message: '', | ||
enabled: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
const migratedDoc = policyDoc({ | ||
windowsMalware: { malware: { mode: 'off' } }, | ||
windowsRansomware: { ransomware: { mode: 'off', supported: true } }, | ||
// new memory protection | ||
windowsMemory: { memory_protection: { mode: 'off', supported: true } }, | ||
windowsPopup: { | ||
popup: { | ||
malware: { | ||
message: '', | ||
enabled: true, | ||
}, | ||
ransomware: { | ||
message: '', | ||
enabled: true, | ||
}, | ||
// new memory popup setup | ||
memory_protection: { | ||
message: '', | ||
enabled: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(migration(initialDoc, {} as SavedObjectMigrationContext)).toEqual(migratedDoc); | ||
}); | ||
|
||
it('does not modify non-endpoint package policies', () => { | ||
const doc: SavedObjectUnsanitizedDoc<PackagePolicy> = { | ||
id: 'mock-saved-object-id', | ||
attributes: { | ||
name: 'Some Policy Name', | ||
package: { | ||
name: 'notEndpoint', | ||
title: '', | ||
version: '', | ||
}, | ||
id: 'notEndpoint', | ||
policy_id: '', | ||
enabled: true, | ||
namespace: '', | ||
output_id: '', | ||
revision: 0, | ||
updated_at: '', | ||
updated_by: '', | ||
created_at: '', | ||
created_by: '', | ||
inputs: [ | ||
{ | ||
type: 'notEndpoint', | ||
enabled: true, | ||
streams: [], | ||
config: {}, | ||
}, | ||
], | ||
}, | ||
type: ' nested', | ||
}; | ||
|
||
expect( | ||
migration(doc, {} as SavedObjectMigrationContext) as SavedObjectUnsanitizedDoc<PackagePolicy> | ||
).toEqual({ | ||
attributes: { | ||
name: 'Some Policy Name', | ||
package: { | ||
name: 'notEndpoint', | ||
title: '', | ||
version: '', | ||
}, | ||
id: 'notEndpoint', | ||
policy_id: '', | ||
enabled: true, | ||
namespace: '', | ||
output_id: '', | ||
revision: 0, | ||
updated_at: '', | ||
updated_by: '', | ||
created_at: '', | ||
created_by: '', | ||
inputs: [ | ||
{ | ||
type: 'notEndpoint', | ||
enabled: true, | ||
streams: [], | ||
config: {}, | ||
}, | ||
], | ||
}, | ||
type: ' nested', | ||
id: 'mock-saved-object-id', | ||
}); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
x-pack/plugins/fleet/server/saved_objects/migrations/security_solution/to_v7_15_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,43 @@ | ||
/* | ||
* 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, SavedObjectUnsanitizedDoc } from 'kibana/server'; | ||
import { cloneDeep } from 'lodash'; | ||
|
||
import type { PackagePolicy } from '../../../../common'; | ||
|
||
export const migratePackagePolicyToV7150: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = ( | ||
packagePolicyDoc | ||
) => { | ||
if (packagePolicyDoc.attributes.package?.name !== 'endpoint') { | ||
return packagePolicyDoc; | ||
} | ||
|
||
const updatedPackagePolicyDoc: SavedObjectUnsanitizedDoc<PackagePolicy> = cloneDeep( | ||
packagePolicyDoc | ||
); | ||
|
||
const input = updatedPackagePolicyDoc.attributes.inputs[0]; | ||
const memory = { | ||
mode: 'off', | ||
// This value is based on license. | ||
// For the migration, we add 'true', our license watcher will correct it, if needed, when the app starts. | ||
supported: true, | ||
}; | ||
const memoryPopup = { | ||
message: '', | ||
enabled: false, | ||
}; | ||
if (input && input.config) { | ||
const policy = input.config.policy.value; | ||
|
||
policy.windows.memory_protection = memory; | ||
policy.windows.popup.memory_protection = memoryPopup; | ||
} | ||
|
||
return updatedPackagePolicyDoc; | ||
}; |
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/fleet/server/saved_objects/migrations/to_v7_15_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,26 @@ | ||
/* | ||
* 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 { migratePackagePolicyToV7150 as SecSolMigratePackagePolicyToV7150 } from './security_solution'; | ||
|
||
export const migratePackagePolicyToV7150: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = ( | ||
packagePolicyDoc, | ||
migrationContext | ||
) => { | ||
let updatedPackagePolicyDoc = packagePolicyDoc; | ||
|
||
// Endpoint specific migrations | ||
if (packagePolicyDoc.attributes.package?.name === 'endpoint') { | ||
updatedPackagePolicyDoc = SecSolMigratePackagePolicyToV7150(packagePolicyDoc, migrationContext); | ||
} | ||
|
||
return updatedPackagePolicyDoc; | ||
}; |
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.