diff --git a/oas_docs/bundle.json b/oas_docs/bundle.json
index 1841d1eba01ef..5aa0d3ba2a485 100644
--- a/oas_docs/bundle.json
+++ b/oas_docs/bundle.json
@@ -42392,6 +42392,122 @@
]
}
},
+ "/api/fleet/space_settings": {
+ "get": {
+ "operationId": "get-fleet-space-settings",
+ "parameters": [],
+ "responses": {
+ "200": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "additionalProperties": false,
+ "properties": {
+ "item": {
+ "additionalProperties": false,
+ "properties": {
+ "allowed_namespace_prefixes": {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "managed_by": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "allowed_namespace_prefixes"
+ ],
+ "type": "object"
+ }
+ },
+ "required": [
+ "item"
+ ],
+ "type": "object"
+ }
+ }
+ }
+ }
+ },
+ "summary": "Get space settings",
+ "tags": [],
+ "x-state": "Generally available; added in 9.1.0"
+ },
+ "put": {
+ "description": "[Required authorization] Route required privileges: fleet-settings-all.",
+ "operationId": "put-fleet-space-settings",
+ "parameters": [
+ {
+ "description": "A required header to protect against CSRF attacks",
+ "in": "header",
+ "name": "kbn-xsrf",
+ "required": true,
+ "schema": {
+ "example": "true",
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "additionalProperties": false,
+ "properties": {
+ "allowed_namespace_prefixes": {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "additionalProperties": false,
+ "properties": {
+ "item": {
+ "additionalProperties": false,
+ "properties": {
+ "allowed_namespace_prefixes": {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "managed_by": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "allowed_namespace_prefixes"
+ ],
+ "type": "object"
+ }
+ },
+ "required": [
+ "item"
+ ],
+ "type": "object"
+ }
+ }
+ }
+ }
+ },
+ "summary": "Create space settings",
+ "tags": [],
+ "x-state": "Generally available; added in 9.1.0"
+ }
+ },
"/api/fleet/uninstall_tokens": {
"get": {
"description": "List the metadata for the latest uninstall tokens per agent policy.
[Required authorization] Route required privileges: fleet-agents-all.",
diff --git a/oas_docs/bundle.serverless.json b/oas_docs/bundle.serverless.json
index 5b96b84abd308..38a3396a6f290 100644
--- a/oas_docs/bundle.serverless.json
+++ b/oas_docs/bundle.serverless.json
@@ -42392,6 +42392,122 @@
]
}
},
+ "/api/fleet/space_settings": {
+ "get": {
+ "operationId": "get-fleet-space-settings",
+ "parameters": [],
+ "responses": {
+ "200": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "additionalProperties": false,
+ "properties": {
+ "item": {
+ "additionalProperties": false,
+ "properties": {
+ "allowed_namespace_prefixes": {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "managed_by": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "allowed_namespace_prefixes"
+ ],
+ "type": "object"
+ }
+ },
+ "required": [
+ "item"
+ ],
+ "type": "object"
+ }
+ }
+ }
+ }
+ },
+ "summary": "Get space settings",
+ "tags": [],
+ "x-state": "Generally available"
+ },
+ "put": {
+ "description": "[Required authorization] Route required privileges: fleet-settings-all.",
+ "operationId": "put-fleet-space-settings",
+ "parameters": [
+ {
+ "description": "A required header to protect against CSRF attacks",
+ "in": "header",
+ "name": "kbn-xsrf",
+ "required": true,
+ "schema": {
+ "example": "true",
+ "type": "string"
+ }
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "additionalProperties": false,
+ "properties": {
+ "allowed_namespace_prefixes": {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ }
+ },
+ "type": "object"
+ }
+ }
+ }
+ },
+ "responses": {
+ "200": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "additionalProperties": false,
+ "properties": {
+ "item": {
+ "additionalProperties": false,
+ "properties": {
+ "allowed_namespace_prefixes": {
+ "items": {
+ "type": "string"
+ },
+ "type": "array"
+ },
+ "managed_by": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "allowed_namespace_prefixes"
+ ],
+ "type": "object"
+ }
+ },
+ "required": [
+ "item"
+ ],
+ "type": "object"
+ }
+ }
+ }
+ }
+ },
+ "summary": "Create space settings",
+ "tags": [],
+ "x-state": "Generally available"
+ }
+ },
"/api/fleet/uninstall_tokens": {
"get": {
"description": "List the metadata for the latest uninstall tokens per agent policy.
[Required authorization] Route required privileges: fleet-agents-all.",
diff --git a/oas_docs/output/kibana.serverless.yaml b/oas_docs/output/kibana.serverless.yaml
index 0d609c93ac7aa..382534765c792 100644
--- a/oas_docs/output/kibana.serverless.yaml
+++ b/oas_docs/output/kibana.serverless.yaml
@@ -37788,6 +37788,82 @@ paths:
summary: Initiate Fleet setup
tags:
- Fleet internals
+ /api/fleet/space_settings:
+ get:
+ operationId: get-fleet-space-settings
+ parameters: []
+ responses:
+ '200':
+ content:
+ application/json:
+ schema:
+ additionalProperties: false
+ type: object
+ properties:
+ item:
+ additionalProperties: false
+ type: object
+ properties:
+ allowed_namespace_prefixes:
+ items:
+ type: string
+ type: array
+ managed_by:
+ type: string
+ required:
+ - allowed_namespace_prefixes
+ required:
+ - item
+ summary: Get space settings
+ tags: []
+ x-state: Generally available
+ put:
+ description: '[Required authorization] Route required privileges: fleet-settings-all.'
+ operationId: put-fleet-space-settings
+ parameters:
+ - description: A required header to protect against CSRF attacks
+ in: header
+ name: kbn-xsrf
+ required: true
+ schema:
+ example: 'true'
+ type: string
+ requestBody:
+ content:
+ application/json:
+ schema:
+ additionalProperties: false
+ type: object
+ properties:
+ allowed_namespace_prefixes:
+ items:
+ type: string
+ type: array
+ responses:
+ '200':
+ content:
+ application/json:
+ schema:
+ additionalProperties: false
+ type: object
+ properties:
+ item:
+ additionalProperties: false
+ type: object
+ properties:
+ allowed_namespace_prefixes:
+ items:
+ type: string
+ type: array
+ managed_by:
+ type: string
+ required:
+ - allowed_namespace_prefixes
+ required:
+ - item
+ summary: Create space settings
+ tags: []
+ x-state: Generally available
/api/fleet/uninstall_tokens:
get:
description: 'List the metadata for the latest uninstall tokens per agent policy.
[Required authorization] Route required privileges: fleet-agents-all.'
diff --git a/oas_docs/output/kibana.yaml b/oas_docs/output/kibana.yaml
index 3b3ef51f4f6da..5d1f339611c6e 100644
--- a/oas_docs/output/kibana.yaml
+++ b/oas_docs/output/kibana.yaml
@@ -40030,6 +40030,82 @@ paths:
summary: Initiate Fleet setup
tags:
- Fleet internals
+ /api/fleet/space_settings:
+ get:
+ operationId: get-fleet-space-settings
+ parameters: []
+ responses:
+ '200':
+ content:
+ application/json:
+ schema:
+ additionalProperties: false
+ type: object
+ properties:
+ item:
+ additionalProperties: false
+ type: object
+ properties:
+ allowed_namespace_prefixes:
+ items:
+ type: string
+ type: array
+ managed_by:
+ type: string
+ required:
+ - allowed_namespace_prefixes
+ required:
+ - item
+ summary: Get space settings
+ tags: []
+ x-state: Generally available; added in 9.1.0
+ put:
+ description: '[Required authorization] Route required privileges: fleet-settings-all.'
+ operationId: put-fleet-space-settings
+ parameters:
+ - description: A required header to protect against CSRF attacks
+ in: header
+ name: kbn-xsrf
+ required: true
+ schema:
+ example: 'true'
+ type: string
+ requestBody:
+ content:
+ application/json:
+ schema:
+ additionalProperties: false
+ type: object
+ properties:
+ allowed_namespace_prefixes:
+ items:
+ type: string
+ type: array
+ responses:
+ '200':
+ content:
+ application/json:
+ schema:
+ additionalProperties: false
+ type: object
+ properties:
+ item:
+ additionalProperties: false
+ type: object
+ properties:
+ allowed_namespace_prefixes:
+ items:
+ type: string
+ type: array
+ managed_by:
+ type: string
+ required:
+ - allowed_namespace_prefixes
+ required:
+ - item
+ summary: Create space settings
+ tags: []
+ x-state: Generally available; added in 9.1.0
/api/fleet/uninstall_tokens:
get:
description: 'List the metadata for the latest uninstall tokens per agent policy.
[Required authorization] Route required privileges: fleet-agents-all.'
diff --git a/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts b/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts
index e7dced9cd7bb5..1b9bb36366d4d 100644
--- a/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts
+++ b/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts
@@ -116,7 +116,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"fleet-fleet-server-host": "795c0e79438a260bd860419454bcc432476d4396",
"fleet-message-signing-keys": "0c6da6a680807e568540b2aa263ae52331ba66db",
"fleet-package-policies": "4da7cd2662ab79ea708ac51f0627451dd91f122d",
- "fleet-preconfiguration-deletion-record": "3afad160748b430427086985a3445fd8697566d5",
+ "fleet-preconfiguration-deletion-record": "a9d20d9d21c2118fd35f21fb5eb1e3f68fa6889c",
"fleet-proxy": "94d0a902a0fd22578d7d3a20873b95d902e25245",
"fleet-setup-lock": "ce9a2dcfb2e6f7260d129636a26c9ca98b13e464",
"fleet-space-settings": "b8f60506cf5fea1429ad84dfb8644cf261fd7427",
@@ -671,7 +671,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"fleet-package-policies|10.2.0: 36e535787e2e056808d594a62a0e9f499f8555c6",
"fleet-package-policies|10.1.0: 77e39fefd98deaeb0f41bb74d4330d871351bd4a",
"=======================================================================",
- "fleet-preconfiguration-deletion-record|global: 454e9b7ef4c25e0f85b5ea12895e0ed720d12581",
+ "fleet-preconfiguration-deletion-record|global: a047f456e093d317d16fdb68736505989ec23fc9",
"fleet-preconfiguration-deletion-record|mappings: 3b2d71720dd99d3a4848f0dc81c6d307a167fc1e",
"fleet-preconfiguration-deletion-record|schemas: da39a3ee5e6b4b0d3255bfef95601890afd80709",
"========================================================================================",
diff --git a/x-pack/platform/plugins/shared/fleet/README.md b/x-pack/platform/plugins/shared/fleet/README.md
index 24afe5db2a9e1..2f48a0d748373 100644
--- a/x-pack/platform/plugins/shared/fleet/README.md
+++ b/x-pack/platform/plugins/shared/fleet/README.md
@@ -232,13 +232,13 @@ Note: Docker needs to be running to run these tests.
Run the tests from the Kibana root folder with:
```sh
-node scripts/jest_integration.js x-pack/platform/plugins/shared/fleet/server/integration_tests/
+node scripts/jest_integration.js --config x-pack/platform/plugins/shared/fleet/jest.integration.config.js x-pack/platform/plugins/shared/fleet/server/integration_tests/
```
Running the tests with [Node Inspector](https://nodejs.org/en/learn/getting-started/debugging) allows inspecting Elasticsearch indices. To do this, add a `debugger;` statement in the test (cf. [Jest documentation](https://jestjs.io/docs/troubleshooting)) and run `node` with `--inspect` or `--inspect-brk`:
```sh
-node --inspect scripts/jest_integration.js x-pack/platform/plugins/shared/fleet/server/integration_tests/
+node --inspect scripts/jest_integration.js --config x-pack/platform/plugins/shared/fleet/jest.integration.config.js x-pack/platform/plugins/shared/fleet/server/integration_tests/
```
### Storybook
diff --git a/x-pack/platform/plugins/shared/fleet/common/experimental_features.ts b/x-pack/platform/plugins/shared/fleet/common/experimental_features.ts
index de34e3cc44b16..424ad7c87a7e8 100644
--- a/x-pack/platform/plugins/shared/fleet/common/experimental_features.ts
+++ b/x-pack/platform/plugins/shared/fleet/common/experimental_features.ts
@@ -9,7 +9,7 @@ export type ExperimentalFeatures = typeof allowedExperimentalValues;
const _allowedExperimentalValues = {
showExperimentalShipperOptions: false,
- useSpaceAwareness: false,
+ useSpaceAwareness: true,
enableAutomaticAgentUpgrades: true,
enableSyncIntegrationsOnRemote: true,
enableSSLSecrets: false,
diff --git a/x-pack/platform/plugins/shared/fleet/common/index.ts b/x-pack/platform/plugins/shared/fleet/common/index.ts
index 1860a983b69bf..c4e099847f8c9 100644
--- a/x-pack/platform/plugins/shared/fleet/common/index.ts
+++ b/x-pack/platform/plugins/shared/fleet/common/index.ts
@@ -29,7 +29,8 @@ export {
AGENT_POLICY_SAVED_OBJECT_TYPE,
LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
PACKAGES_SAVED_OBJECT_TYPE,
- LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE as PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ PACKAGE_POLICY_SAVED_OBJECT_TYPE,
OUTPUT_SAVED_OBJECT_TYPE,
PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE,
ASSETS_SAVED_OBJECT_TYPE,
diff --git a/x-pack/platform/plugins/shared/fleet/server/collectors/fleet_server_collector.ts b/x-pack/platform/plugins/shared/fleet/server/collectors/fleet_server_collector.ts
index 54a3152585545..bb309ed363269 100644
--- a/x-pack/platform/plugins/shared/fleet/server/collectors/fleet_server_collector.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/collectors/fleet_server_collector.ts
@@ -56,7 +56,7 @@ export const getFleetServerUsage = async (
const res = await packagePolicyService.list(soClient, {
page: page++,
perPage: 20,
- kuery: 'ingest-package-policies.package.name:fleet_server',
+ kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:fleet_server`,
});
for (const item of res.items) {
diff --git a/x-pack/platform/plugins/shared/fleet/server/collectors/get_all_fleet_server_agents.ts b/x-pack/platform/plugins/shared/fleet/server/collectors/get_all_fleet_server_agents.ts
index 948352f9cd35c..36e6b088a23cb 100644
--- a/x-pack/platform/plugins/shared/fleet/server/collectors/get_all_fleet_server_agents.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/collectors/get_all_fleet_server_agents.ts
@@ -18,6 +18,7 @@ export const getAllFleetServerAgents = async (
esClient: ElasticsearchClient
) => {
let packagePolicyData;
+
try {
packagePolicyData = await packagePolicyService.list(soClient, {
perPage: SO_SEARCH_LIMIT,
diff --git a/x-pack/platform/plugins/shared/fleet/server/constants/index.ts b/x-pack/platform/plugins/shared/fleet/server/constants/index.ts
index ecb889a1fcae0..f9e93bc785bcf 100644
--- a/x-pack/platform/plugins/shared/fleet/server/constants/index.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/constants/index.ts
@@ -50,7 +50,8 @@ export {
AGENTS_PREFIX,
LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
AGENT_POLICY_SAVED_OBJECT_TYPE,
- LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE as PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ PACKAGE_POLICY_SAVED_OBJECT_TYPE,
OUTPUT_SAVED_OBJECT_TYPE,
PACKAGES_SAVED_OBJECT_TYPE,
ASSETS_SAVED_OBJECT_TYPE,
diff --git a/x-pack/platform/plugins/shared/fleet/server/integration_tests/cloud_preconfiguration.test.ts b/x-pack/platform/plugins/shared/fleet/server/integration_tests/cloud_preconfiguration.test.ts
index de5a04eb48afd..ac80ea2ef6a10 100644
--- a/x-pack/platform/plugins/shared/fleet/server/integration_tests/cloud_preconfiguration.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/integration_tests/cloud_preconfiguration.test.ts
@@ -20,8 +20,11 @@ import type {
PackagePolicySOAttributes,
OutputSOAttributes,
} from '../types';
+import { getAgentPolicySavedObjectType } from '../services/agent_policy';
+import { getPackagePolicySavedObjectType } from '../services/package_policy';
import { useDockerRegistry, waitForFleetSetup } from './helpers';
+
import {
CLOUD_KIBANA_CONFIG,
CLOUD_KIBANA_CONFIG_WITHOUT_APM,
@@ -34,6 +37,8 @@ const logFilePath = Path.join(__dirname, 'logs.log');
describe('Fleet cloud preconfiguration', () => {
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
+ let agentPolicyType: string;
+ let packagePolicyType: string;
const registryUrl = useDockerRegistry();
@@ -141,6 +146,8 @@ describe('Fleet cloud preconfiguration', () => {
describe('With a full preconfigured cloud policy', () => {
beforeAll(async () => {
await startServers();
+ agentPolicyType = await getAgentPolicySavedObjectType();
+ packagePolicyType = await getPackagePolicySavedObjectType();
});
afterAll(async () => {
@@ -151,7 +158,7 @@ describe('Fleet cloud preconfiguration', () => {
const agentPolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
@@ -367,7 +374,7 @@ describe('Fleet cloud preconfiguration', () => {
const packagePolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-package-policies',
+ type: packagePolicyType,
perPage: 10000,
});
@@ -433,6 +440,8 @@ describe('Fleet cloud preconfiguration', () => {
// 2. Add APM to the preconfigured policy
await startOrRestartKibana(CLOUD_KIBANA_CONFIG);
+ agentPolicyType = await getAgentPolicySavedObjectType();
+ packagePolicyType = await getPackagePolicySavedObjectType();
});
afterAll(async () => {
@@ -443,7 +452,7 @@ describe('Fleet cloud preconfiguration', () => {
const agentPolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
@@ -472,7 +481,7 @@ describe('Fleet cloud preconfiguration', () => {
const packagePolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-package-policies',
+ type: packagePolicyType,
perPage: 10000,
});
@@ -498,6 +507,8 @@ describe('Fleet cloud preconfiguration', () => {
// 2. Add pacakge policy ids to the preconfigured policy
await startOrRestartKibana(CLOUD_KIBANA_CONFIG);
+ agentPolicyType = await getAgentPolicySavedObjectType();
+ packagePolicyType = await getPackagePolicySavedObjectType();
});
afterAll(async () => {
@@ -508,7 +519,7 @@ describe('Fleet cloud preconfiguration', () => {
const agentPolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
@@ -523,7 +534,7 @@ describe('Fleet cloud preconfiguration', () => {
const packagePolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-package-policies',
+ type: packagePolicyType,
perPage: 10000,
});
@@ -571,6 +582,7 @@ describe('Fleet cloud preconfiguration', () => {
},
},
});
+ agentPolicyType = await getAgentPolicySavedObjectType();
});
afterAll(async () => {
diff --git a/x-pack/platform/plugins/shared/fleet/server/integration_tests/enable_space_awareness.test.ts b/x-pack/platform/plugins/shared/fleet/server/integration_tests/enable_space_awareness.test.ts
index 0af9026bf8fa2..f20051d388e2c 100644
--- a/x-pack/platform/plugins/shared/fleet/server/integration_tests/enable_space_awareness.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/integration_tests/enable_space_awareness.test.ts
@@ -20,6 +20,8 @@ import { SECURITY_EXTENSION_ID } from '@kbn/core-saved-objects-server';
import {
AGENT_POLICY_SAVED_OBJECT_TYPE,
+ GLOBAL_SETTINGS_ID,
+ GLOBAL_SETTINGS_SAVED_OBJECT_TYPE,
LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
} from '../../common/constants';
@@ -188,6 +190,11 @@ describe('enableSpaceAwareness', () => {
refresh: 'wait_for',
}
);
+
+ // Ensure we are always starting from a non-migrated state
+ await soClient.update(GLOBAL_SETTINGS_SAVED_OBJECT_TYPE, GLOBAL_SETTINGS_ID, {
+ use_space_awareness_migration_status: null,
+ });
});
it('should support concurrent calls', async () => {
const res = await Promise.allSettled([
diff --git a/x-pack/platform/plugins/shared/fleet/server/integration_tests/fleet_usage_telemetry.test.ts b/x-pack/platform/plugins/shared/fleet/server/integration_tests/fleet_usage_telemetry.test.ts
index 6ce4763a3ca12..e8d26df998c9e 100644
--- a/x-pack/platform/plugins/shared/fleet/server/integration_tests/fleet_usage_telemetry.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/integration_tests/fleet_usage_telemetry.test.ts
@@ -15,6 +15,8 @@ import {
} from '@kbn/core-test-helpers-kbn-server';
import { fetchFleetUsage } from '../collectors/register';
+import { getAgentPolicySavedObjectType } from '../services/agent_policy';
+import { getPackagePolicySavedObjectType } from '../services/package_policy';
import { waitForFleetSetup } from './helpers';
@@ -24,6 +26,9 @@ describe('fleet usage telemetry', () => {
let core: any;
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
+ let agentPolicyType: string;
+ let packagePolicyType: string;
+
const registryUrl = 'http://localhost';
const startServers = async () => {
@@ -112,7 +117,8 @@ describe('fleet usage telemetry', () => {
beforeAll(async () => {
await startServers();
-
+ agentPolicyType = await getAgentPolicySavedObjectType();
+ packagePolicyType = await getPackagePolicySavedObjectType();
const esClient = kbnServer.coreStart.elasticsearch.client.asInternalUser;
await esClient.bulk({
index: '.fleet-agents',
@@ -342,7 +348,7 @@ describe('fleet usage telemetry', () => {
});
const soClient = kbnServer.coreStart.savedObjects.createInternalRepository();
- await soClient.create('ingest-package-policies', {
+ await soClient.create(packagePolicyType, {
name: 'fleet_server-1',
namespace: 'default',
package: {
@@ -370,7 +376,7 @@ describe('fleet usage telemetry', () => {
latest_revision: true,
});
- await soClient.create('ingest-package-policies', {
+ await soClient.create(packagePolicyType, {
name: 'nginx-1',
namespace: 'default',
package: {
@@ -430,7 +436,7 @@ describe('fleet usage telemetry', () => {
);
await soClient.create(
- 'ingest-agent-policies',
+ agentPolicyType,
{
namespace: 'default',
monitoring_enabled: ['logs', 'metrics'],
@@ -452,7 +458,7 @@ describe('fleet usage telemetry', () => {
{ id: 'policy2' }
);
await soClient.create(
- 'ingest-agent-policies',
+ agentPolicyType,
{
namespace: 'default',
monitoring_enabled: ['logs', 'metrics'],
diff --git a/x-pack/platform/plugins/shared/fleet/server/integration_tests/ha_setup.test.ts b/x-pack/platform/plugins/shared/fleet/server/integration_tests/ha_setup.test.ts
index 6c5ecf6730e19..1c1281c11bfe4 100644
--- a/x-pack/platform/plugins/shared/fleet/server/integration_tests/ha_setup.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/integration_tests/ha_setup.test.ts
@@ -23,6 +23,8 @@ import type {
OutputSOAttributes,
PackagePolicySOAttributes,
} from '../types';
+import { getAgentPolicySavedObjectType } from '../services/agent_policy';
+import { getPackagePolicySavedObjectType } from '../services/package_policy';
import { useDockerRegistry } from './helpers';
@@ -253,8 +255,10 @@ describe('Fleet setup preconfiguration with multiple instances Kibana', () => {
async function expectFleetSetupState(soClient: ISavedObjectsRepository) {
// Assert setup state
+ const agentPolicyType = await getAgentPolicySavedObjectType();
+ const packagePolicyType = await getPackagePolicySavedObjectType();
const agentPolicies = await soClient.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
expect(agentPolicies.saved_objects).toHaveLength(2);
@@ -274,7 +278,7 @@ describe('Fleet setup preconfiguration with multiple instances Kibana', () => {
);
const packagePolicies = await soClient.find({
- type: 'ingest-package-policies',
+ type: packagePolicyType,
perPage: 10000,
});
expect(packagePolicies.saved_objects).toHaveLength(2);
diff --git a/x-pack/platform/plugins/shared/fleet/server/integration_tests/reset_preconfiguration.test.ts b/x-pack/platform/plugins/shared/fleet/server/integration_tests/reset_preconfiguration.test.ts
index 65224e2408bd6..47eea67219e7c 100644
--- a/x-pack/platform/plugins/shared/fleet/server/integration_tests/reset_preconfiguration.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/integration_tests/reset_preconfiguration.test.ts
@@ -16,6 +16,7 @@ import {
import type { AgentPolicySOAttributes } from '../types';
import { PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE } from '../../common';
+import { getAgentPolicySavedObjectType } from '../services/agent_policy';
import { API_VERSIONS } from '../../common/constants';
import { useDockerRegistry, waitForFleetSetup, getSupertestWithAdminUser } from './helpers';
@@ -26,6 +27,7 @@ const logFilePath = Path.join(__dirname, 'logs.log');
describe('Fleet preconfiguration reset', () => {
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
+ let agentPolicyType: string;
const registryUrl = useDockerRegistry();
@@ -178,6 +180,7 @@ describe('Fleet preconfiguration reset', () => {
// Share the same servers for all the test to make test a lot faster (but test are not isolated anymore)
beforeAll(async () => {
await startServers();
+ agentPolicyType = await getAgentPolicySavedObjectType();
});
afterAll(async () => {
@@ -265,7 +268,7 @@ describe('Fleet preconfiguration reset', () => {
const agentPolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
expect(agentPolicies.saved_objects).toHaveLength(2);
@@ -287,10 +290,10 @@ describe('Fleet preconfiguration reset', () => {
it('Works and reset one preconfigured policies if the policy is already deleted (with a ghost package policy)', async () => {
const soClient = kbnServer.coreStart.savedObjects.createInternalRepository();
- await soClient.delete('ingest-agent-policies', POLICY_ID);
+ await soClient.delete(agentPolicyType, POLICY_ID);
const oldAgentPolicies = await soClient.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
@@ -301,6 +304,7 @@ describe('Fleet preconfiguration reset', () => {
'post',
'/internal/fleet/reset_preconfigured_agent_policies/test-12345'
);
+
await resetAPI
.set('kbn-sxrf', 'xx')
.set('Elastic-Api-Version', `${API_VERSIONS.public.v1}`)
@@ -310,7 +314,7 @@ describe('Fleet preconfiguration reset', () => {
const agentPolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
expect(agentPolicies.saved_objects).toHaveLength(2);
@@ -332,7 +336,7 @@ describe('Fleet preconfiguration reset', () => {
it('Works if the preconfigured policies already exists with a missing package policy', async () => {
const soClient = kbnServer.coreStart.savedObjects.createInternalRepository();
- await soClient.update('ingest-agent-policies', POLICY_ID, {});
+ await soClient.update(agentPolicyType, POLICY_ID, {});
const resetAPI = getSupertestWithAdminUser(
kbnServer.root,
@@ -346,7 +350,7 @@ describe('Fleet preconfiguration reset', () => {
.send();
const agentPolicies = await soClient.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
expect(agentPolicies.saved_objects).toHaveLength(2);
@@ -366,7 +370,7 @@ describe('Fleet preconfiguration reset', () => {
it('Works and reset one preconfigured policies if the policy was deleted with a preconfiguration deletion record', async () => {
const soClient = kbnServer.coreStart.savedObjects.createInternalRepository();
- await soClient.delete('ingest-agent-policies', POLICY_ID);
+ await soClient.delete(agentPolicyType, POLICY_ID);
await soClient.create(PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE, {
id: POLICY_ID,
});
@@ -385,7 +389,7 @@ describe('Fleet preconfiguration reset', () => {
const agentPolicies = await kbnServer.coreStart.savedObjects
.createInternalRepository()
.find({
- type: 'ingest-agent-policies',
+ type: agentPolicyType,
perPage: 10000,
});
expect(agentPolicies.saved_objects).toHaveLength(2);
diff --git a/x-pack/platform/plugins/shared/fleet/server/integration_tests/upgrade_agent_policy_schema_version.test.ts b/x-pack/platform/plugins/shared/fleet/server/integration_tests/upgrade_agent_policy_schema_version.test.ts
index 51ca5b9afb358..f0883eeec9fde 100644
--- a/x-pack/platform/plugins/shared/fleet/server/integration_tests/upgrade_agent_policy_schema_version.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/integration_tests/upgrade_agent_policy_schema_version.test.ts
@@ -23,13 +23,11 @@ import {
createRootWithCorePlugins,
} from '@kbn/core-test-helpers-kbn-server';
-import {
- LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
- FLEET_AGENT_POLICIES_SCHEMA_VERSION,
-} from '../constants';
+import { FLEET_AGENT_POLICIES_SCHEMA_VERSION } from '../constants';
import { upgradeAgentPolicySchemaVersion } from '../services/setup/upgrade_agent_policy_schema_version';
import { AGENT_POLICY_INDEX } from '../../common';
import { agentPolicyService } from '../services';
+import { getAgentPolicySavedObjectType } from '../services/agent_policy';
import { useDockerRegistry, waitForFleetSetup } from './helpers';
@@ -51,6 +49,7 @@ const fakeRequest = {
describe('upgrade agent policy schema version', () => {
let esServer: TestElasticsearchUtils;
let kbnServer: TestKibanaUtils;
+ let agentPolicyType: string;
const registryUrl = useDockerRegistry();
@@ -119,6 +118,7 @@ describe('upgrade agent policy schema version', () => {
// Share the same servers for all the test to make test a lot faster (but test are not isolated anymore)
beforeAll(async () => {
await startServers();
+ agentPolicyType = await getAgentPolicySavedObjectType();
});
afterAll(async () => {
@@ -144,7 +144,7 @@ describe('upgrade agent policy schema version', () => {
await soClient.bulkCreate([
// up-to-date schema_version
{
- type: LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
+ type: agentPolicyType,
id: uuidv4(),
attributes: {
schema_version: FLEET_AGENT_POLICIES_SCHEMA_VERSION,
@@ -153,7 +153,7 @@ describe('upgrade agent policy schema version', () => {
},
// out-of-date schema_version
{
- type: LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
+ type: agentPolicyType,
id: uuidv4(),
attributes: {
schema_version: '0.0.1',
@@ -162,7 +162,7 @@ describe('upgrade agent policy schema version', () => {
},
// missing schema_version
{
- type: LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
+ type: agentPolicyType,
id: uuidv4(),
attributes: {
revision: 1,
@@ -173,7 +173,7 @@ describe('upgrade agent policy schema version', () => {
await upgradeAgentPolicySchemaVersion(soClient);
const policies = await agentPolicyService.list(soClient, {
- kuery: `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.schema_version:${FLEET_AGENT_POLICIES_SCHEMA_VERSION}`,
+ kuery: `${agentPolicyType}.schema_version:${FLEET_AGENT_POLICIES_SCHEMA_VERSION}`,
});
// all 3 should be up-to-date after upgrade
expect(policies.total).toBe(3);
diff --git a/x-pack/platform/plugins/shared/fleet/server/routes/settings/index.ts b/x-pack/platform/plugins/shared/fleet/server/routes/settings/index.ts
index 3976070873f85..9fa97a626fc53 100644
--- a/x-pack/platform/plugins/shared/fleet/server/routes/settings/index.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/routes/settings/index.ts
@@ -48,6 +48,12 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
);
},
summary: `Get space settings`,
+ options: {
+ availability: {
+ since: '9.1.0',
+ stability: 'stable',
+ },
+ },
})
.addVersion(
{
@@ -73,6 +79,12 @@ export const registerRoutes = (router: FleetAuthzRouter, config: FleetConfigType
},
},
summary: `Create space settings`,
+ options: {
+ availability: {
+ since: '9.1.0',
+ stability: 'stable',
+ },
+ },
})
.addVersion(
{
diff --git a/x-pack/platform/plugins/shared/fleet/server/routes/utils/filter_utils_real_queries.test.ts b/x-pack/platform/plugins/shared/fleet/server/routes/utils/filter_utils_real_queries.test.ts
index c4cad780aab05..aedc2ba9199f1 100644
--- a/x-pack/platform/plugins/shared/fleet/server/routes/utils/filter_utils_real_queries.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/routes/utils/filter_utils_real_queries.test.ts
@@ -9,6 +9,8 @@ import * as esKuery from '@kbn/es-query';
import {
LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
+ AGENT_POLICY_SAVED_OBJECT_TYPE,
+ LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
AGENTS_PREFIX,
AGENT_POLICY_MAPPINGS,
@@ -25,228 +27,248 @@ jest.mock('../../services/app_context');
describe('ValidateFilterKueryNode validates real kueries through KueryNode', () => {
describe('Agent policies', () => {
- it('Search by data_output_id', async () => {
- const astFilter = esKuery.fromKueryExpression(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id: test_id`
- );
- const validationObject = validateFilterKueryNode({
- astFilter,
- types: [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: AGENT_POLICY_MAPPINGS,
- storeValue: true,
- });
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error: null,
- isSavedObjectAttr: true,
- key: 'ingest-agent-policies.data_output_id',
- type: 'ingest-agent-policies',
- },
- ]);
- });
-
- it('Search by inactivity timeout', async () => {
- const astFilter = esKuery.fromKueryExpression(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.inactivity_timeout:*`
- );
- const validationObject = validateFilterKueryNode({
- astFilter,
- types: [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: AGENT_POLICY_MAPPINGS,
- storeValue: true,
- });
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error: null,
- isSavedObjectAttr: true,
- key: 'ingest-agent-policies.inactivity_timeout',
- type: 'ingest-agent-policies',
- },
- ]);
- });
-
- it('Complex query', async () => {
- const validationObject = validateFilterKueryNode({
- astFilter: esKuery.fromKueryExpression(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.download_source_id:some_id or (not ${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.download_source_id:*)`
- ),
- types: [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: AGENT_POLICY_MAPPINGS,
- storeValue: true,
- });
-
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error: null,
- isSavedObjectAttr: true,
- key: 'ingest-agent-policies.download_source_id',
- type: 'ingest-agent-policies',
- },
- {
- astPath: 'arguments.1.arguments.0',
- error: null,
- isSavedObjectAttr: true,
- key: 'ingest-agent-policies.download_source_id',
- type: 'ingest-agent-policies',
- },
- ]);
- });
-
- it('Test another complex query', async () => {
- const astFilter = esKuery.fromKueryExpression(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id: test_id or ${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.monitoring_output_id: test_id or (not ${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:*)`
- );
- const validationObject = validateFilterKueryNode({
- astFilter,
- types: [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: AGENT_POLICY_MAPPINGS,
- storeValue: true,
- });
-
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error: null,
- isSavedObjectAttr: true,
- key: 'ingest-agent-policies.data_output_id',
- type: 'ingest-agent-policies',
- },
- {
- astPath: 'arguments.1',
- error: null,
- isSavedObjectAttr: true,
- key: 'ingest-agent-policies.monitoring_output_id',
- type: 'ingest-agent-policies',
- },
- {
- astPath: 'arguments.2.arguments.0',
- error: null,
- isSavedObjectAttr: true,
- key: 'ingest-agent-policies.data_output_id',
- type: 'ingest-agent-policies',
- },
- ]);
- });
-
- it('Returns error if the attribute does not exist', async () => {
- const astFilter = esKuery.fromKueryExpression(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.package_policies:test_id_1 or ${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.package_policies:test_id_2`
- );
- const validationObject = validateFilterKueryNode({
- astFilter,
- types: [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: AGENT_POLICY_MAPPINGS,
- storeValue: true,
- });
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error:
- "This key 'ingest-agent-policies.package_policies' does NOT exist in ingest-agent-policies saved object index patterns",
- isSavedObjectAttr: false,
- key: 'ingest-agent-policies.package_policies',
- type: 'ingest-agent-policies',
- },
- {
- astPath: 'arguments.1',
- error:
- "This key 'ingest-agent-policies.package_policies' does NOT exist in ingest-agent-policies saved object index patterns",
- isSavedObjectAttr: false,
- key: 'ingest-agent-policies.package_policies',
- type: 'ingest-agent-policies',
- },
- ]);
- });
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by data_output_id',
+ async (agentPolicyType) => {
+ const astFilter = esKuery.fromKueryExpression(`${agentPolicyType}.data_output_id: test_id`);
+ const validationObject = validateFilterKueryNode({
+ astFilter,
+ types: [agentPolicyType],
+ indexMapping: AGENT_POLICY_MAPPINGS,
+ storeValue: true,
+ });
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: null,
+ isSavedObjectAttr: true,
+ key: `${agentPolicyType}.data_output_id`,
+ type: agentPolicyType,
+ },
+ ]);
+ }
+ );
+
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by inactivity timeout',
+ async (agentPolicyType) => {
+ const astFilter = esKuery.fromKueryExpression(`${agentPolicyType}.inactivity_timeout:*`);
+ const validationObject = validateFilterKueryNode({
+ astFilter,
+ types: [agentPolicyType],
+ indexMapping: AGENT_POLICY_MAPPINGS,
+ storeValue: true,
+ });
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: null,
+ isSavedObjectAttr: true,
+ key: `${agentPolicyType}.inactivity_timeout`,
+ type: agentPolicyType,
+ },
+ ]);
+ }
+ );
+
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Complex query',
+ async (agentPolicyType) => {
+ const validationObject = validateFilterKueryNode({
+ astFilter: esKuery.fromKueryExpression(
+ `${agentPolicyType}.download_source_id:some_id or (not ${agentPolicyType}.download_source_id:*)`
+ ),
+ types: [agentPolicyType],
+ indexMapping: AGENT_POLICY_MAPPINGS,
+ storeValue: true,
+ });
+
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: null,
+ isSavedObjectAttr: true,
+ key: `${agentPolicyType}.download_source_id`,
+ type: agentPolicyType,
+ },
+ {
+ astPath: 'arguments.1.arguments.0',
+ error: null,
+ isSavedObjectAttr: true,
+ key: `${agentPolicyType}.download_source_id`,
+ type: agentPolicyType,
+ },
+ ]);
+ }
+ );
+
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Test another complex query',
+ async (agentPolicyType) => {
+ const astFilter = esKuery.fromKueryExpression(
+ `${agentPolicyType}.data_output_id: test_id or ${agentPolicyType}.monitoring_output_id: test_id or (not ${agentPolicyType}.data_output_id:*)`
+ );
+ const validationObject = validateFilterKueryNode({
+ astFilter,
+ types: [agentPolicyType],
+ indexMapping: AGENT_POLICY_MAPPINGS,
+ storeValue: true,
+ });
+
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: null,
+ isSavedObjectAttr: true,
+ key: `${agentPolicyType}.data_output_id`,
+ type: agentPolicyType,
+ },
+ {
+ astPath: 'arguments.1',
+ error: null,
+ isSavedObjectAttr: true,
+ key: `${agentPolicyType}.monitoring_output_id`,
+ type: agentPolicyType,
+ },
+ {
+ astPath: 'arguments.2.arguments.0',
+ error: null,
+ isSavedObjectAttr: true,
+ key: `${agentPolicyType}.data_output_id`,
+ type: agentPolicyType,
+ },
+ ]);
+ }
+ );
+
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Returns error if the attribute does not exist',
+ async (agentPolicyType) => {
+ const astFilter = esKuery.fromKueryExpression(
+ `${agentPolicyType}.package_policies:test_id_1 or ${agentPolicyType}.package_policies:test_id_2`
+ );
+ const validationObject = validateFilterKueryNode({
+ astFilter,
+ types: [agentPolicyType],
+ indexMapping: AGENT_POLICY_MAPPINGS,
+ storeValue: true,
+ });
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: `This key '${agentPolicyType}.package_policies' does NOT exist in ${agentPolicyType} saved object index patterns`,
+ isSavedObjectAttr: false,
+ key: `${agentPolicyType}.package_policies`,
+ type: agentPolicyType,
+ },
+ {
+ astPath: 'arguments.1',
+ error: `This key '${agentPolicyType}.package_policies' does NOT exist in ${agentPolicyType} saved object index patterns`,
+ isSavedObjectAttr: false,
+ key: `${agentPolicyType}.package_policies`,
+ type: agentPolicyType,
+ },
+ ]);
+ }
+ );
});
describe('Package policies', () => {
- it('Search by package name', async () => {
- const astFilter = esKuery.fromKueryExpression(
- `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.attributes.package.name:packageName`
- );
- const validationObject = validateFilterKueryNode({
- astFilter,
- types: [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: PACKAGE_POLICIES_MAPPINGS,
- storeValue: true,
- });
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error: null,
- isSavedObjectAttr: false,
- key: 'ingest-package-policies.attributes.package.name',
- type: 'ingest-package-policies',
- },
- ]);
- });
-
- it('It fails if the kuery is not normalized', async () => {
- const astFilter = esKuery.fromKueryExpression(
- `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:packageName`
- );
- const validationObject = validateFilterKueryNode({
- astFilter,
- types: [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: PACKAGE_POLICIES_MAPPINGS,
- storeValue: true,
- });
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error:
- "This key 'ingest-package-policies.package.name' does NOT match the filter proposition SavedObjectType.attributes.key",
- isSavedObjectAttr: false,
- key: 'ingest-package-policies.package.name',
- type: 'ingest-package-policies',
- },
- ]);
- });
-
- it('It does not check attributes if skipNormalization is passed', async () => {
- const astFilter = esKuery.fromKueryExpression(
- `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:packageName`
- );
- const validationObject = validateFilterKueryNode({
- astFilter,
- types: [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: PACKAGE_POLICIES_MAPPINGS,
- storeValue: true,
- skipNormalization: true,
- });
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error: null,
- isSavedObjectAttr: false,
- key: 'ingest-package-policies.package.name',
- type: 'ingest-package-policies',
- },
- ]);
- });
-
- it('Allows passing query without SO', async () => {
- const astFilter = esKuery.fromKueryExpression(`package.name:packageName`);
- const validationObject = validateFilterKueryNode({
- astFilter,
- types: [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- indexMapping: PACKAGE_POLICIES_MAPPINGS,
- storeValue: true,
- skipNormalization: true,
- });
- expect(validationObject).toEqual([
- {
- astPath: 'arguments.0',
- error: null,
- isSavedObjectAttr: true,
- key: 'package.name',
- type: 'package',
- },
- ]);
- });
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by package name',
+ async (packagePolicyType) => {
+ const astFilter = esKuery.fromKueryExpression(
+ `${packagePolicyType}.attributes.package.name:packageName`
+ );
+ const validationObject = validateFilterKueryNode({
+ astFilter,
+ types: [packagePolicyType],
+ indexMapping: PACKAGE_POLICIES_MAPPINGS,
+ storeValue: true,
+ });
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: null,
+ isSavedObjectAttr: false,
+ key: `${packagePolicyType}.attributes.package.name`,
+ type: packagePolicyType,
+ },
+ ]);
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'It fails if the kuery is not normalized',
+ async (packagePolicyType) => {
+ const astFilter = esKuery.fromKueryExpression(
+ `${packagePolicyType}.package.name:packageName`
+ );
+ const validationObject = validateFilterKueryNode({
+ astFilter,
+ types: [packagePolicyType],
+ indexMapping: PACKAGE_POLICIES_MAPPINGS,
+ storeValue: true,
+ });
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: `This key '${packagePolicyType}.package.name' does NOT match the filter proposition SavedObjectType.attributes.key`,
+ isSavedObjectAttr: false,
+ key: `${packagePolicyType}.package.name`,
+ type: packagePolicyType,
+ },
+ ]);
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'It does not check attributes if skipNormalization is passed',
+ async (packagePolicyType) => {
+ const astFilter = esKuery.fromKueryExpression(
+ `${packagePolicyType}.package.name:packageName`
+ );
+ const validationObject = validateFilterKueryNode({
+ astFilter,
+ types: [packagePolicyType],
+ indexMapping: PACKAGE_POLICIES_MAPPINGS,
+ storeValue: true,
+ skipNormalization: true,
+ });
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: null,
+ isSavedObjectAttr: false,
+ key: `${packagePolicyType}.package.name`,
+ type: packagePolicyType,
+ },
+ ]);
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'Allows passing query without SO',
+ async (packagePolicyType) => {
+ const astFilter = esKuery.fromKueryExpression(`package.name:packageName`);
+ const validationObject = validateFilterKueryNode({
+ astFilter,
+ types: [packagePolicyType],
+ indexMapping: PACKAGE_POLICIES_MAPPINGS,
+ storeValue: true,
+ skipNormalization: true,
+ });
+ expect(validationObject).toEqual([
+ {
+ astPath: 'arguments.0',
+ error: null,
+ isSavedObjectAttr: true,
+ key: 'package.name',
+ type: 'package',
+ },
+ ]);
+ }
+ );
});
describe('Agents', () => {
@@ -510,61 +532,76 @@ describe('ValidateFilterKueryNode validates real kueries through KueryNode', ()
describe('validateKuery validates real kueries', () => {
describe('Agent policies', () => {
- it('Search by data_output_id', async () => {
- const validationObj = validateKuery(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id: test_id`,
- [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- AGENT_POLICY_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(true);
- });
-
- it('Search by data_output_id without SO wrapping', async () => {
- const validationObj = validateKuery(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id: test_id`,
- [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- AGENT_POLICY_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(true);
- });
-
- it('Search by name', async () => {
- const validationObj = validateKuery(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.name: test_id`,
- [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- AGENT_POLICY_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(true);
- });
-
- it('Kuery with non existent parameter wrapped by SO', async () => {
- const validationObj = validateKuery(
- `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.non_existent_parameter: 'test_id'`,
- [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- AGENT_POLICY_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(false);
- expect(validationObj?.error).toContain(
- `KQLSyntaxError: This key 'ingest-agent-policies.non_existent_parameter' does NOT exist in ingest-agent-policies saved object index patterns`
- );
- });
-
- it('Invalid search by non existent parameter', async () => {
- const validationObj = validateKuery(
- `non_existent_parameter: 'test_id'`,
- [LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE],
- AGENT_POLICY_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(false);
- expect(validationObj?.error).toContain(
- `KQLSyntaxError: This type 'non_existent_parameter' is not allowed`
- );
- });
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by data_output_id',
+ async (agentPolicyType) => {
+ const validationObj = validateKuery(
+ `${agentPolicyType}.data_output_id: test_id`,
+ [agentPolicyType],
+ AGENT_POLICY_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(true);
+ }
+ );
+
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by data_output_id without SO wrapping',
+ async (agentPolicyType) => {
+ const validationObj = validateKuery(
+ `${agentPolicyType}.data_output_id: test_id`,
+ [agentPolicyType],
+ AGENT_POLICY_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(true);
+ }
+ );
+
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by name',
+ async (agentPolicyType) => {
+ const validationObj = validateKuery(
+ `${agentPolicyType}.name: test_id`,
+ [agentPolicyType],
+ AGENT_POLICY_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(true);
+ }
+ );
+
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Kuery with non existent parameter wrapped by SO',
+ async (agentPolicyType) => {
+ const validationObj = validateKuery(
+ `${agentPolicyType}.non_existent_parameter: 'test_id'`,
+ [agentPolicyType],
+ AGENT_POLICY_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(false);
+ expect(validationObj?.error).toContain(
+ `KQLSyntaxError: This key '${agentPolicyType}.non_existent_parameter' does NOT exist in ${agentPolicyType} saved object index patterns`
+ );
+ }
+ );
+
+ test.each([LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, AGENT_POLICY_SAVED_OBJECT_TYPE])(
+ 'Invalid search by non existent parameter',
+ async (agentPolicyType) => {
+ const validationObj = validateKuery(
+ `non_existent_parameter: 'test_id'`,
+ [agentPolicyType],
+ AGENT_POLICY_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(false);
+ expect(validationObj?.error).toContain(
+ `KQLSyntaxError: This type 'non_existent_parameter' is not allowed`
+ );
+ }
+ );
});
describe('Agents', () => {
@@ -713,82 +750,103 @@ describe('validateKuery validates real kueries', () => {
});
describe('Package policies', () => {
- it('Search by package name without SO', async () => {
- const validationObj = validateKuery(
- `package.name:fleet_server`,
- [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- PACKAGE_POLICIES_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(true);
- });
-
- it('Search by package name', async () => {
- const validationObj = validateKuery(
- `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:fleet_server`,
- [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- PACKAGE_POLICIES_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(true);
- });
-
- it('Search by package name works with attributes if skipNormalization is not passed', async () => {
- const validationObj = validateKuery(
- `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.attributes.package.name:packageName`,
- [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- PACKAGE_POLICIES_MAPPINGS
- );
- expect(validationObj?.isValid).toEqual(true);
- });
-
- it('Search by name and version', async () => {
- const validationObj = validateKuery(
- `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: "TestName" AND ${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.version: "8.8.0"`,
- [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- PACKAGE_POLICIES_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(true);
- });
-
- it('Invalid search by nested wrong parameter', async () => {
- const validationObj = validateKuery(
- `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.is_managed:packageName`,
- [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- PACKAGE_POLICIES_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(false);
- expect(validationObj?.error).toEqual(
- `KQLSyntaxError: This key 'ingest-package-policies.package.is_managed' does NOT exist in ingest-package-policies saved object index patterns`
- );
- });
-
- it('invalid search by nested wrong parameter - without wrapped SO', async () => {
- const validationObj = validateKuery(
- `package.is_managed:packageName`,
- [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- PACKAGE_POLICIES_MAPPINGS,
- true
- );
- expect(validationObj?.isValid).toEqual(false);
- expect(validationObj?.error).toEqual(
- `KQLSyntaxError: This key 'package.is_managed' does NOT exist in ingest-package-policies saved object index patterns`
- );
- });
-
- it('Invalid search by non existent parameter', async () => {
- const validationObj = validateKuery(
- `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.non_existent_parameter:packageName`,
- [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
- PACKAGE_POLICIES_MAPPINGS
- );
- expect(validationObj?.isValid).toEqual(false);
- expect(validationObj?.error).toEqual(
- `KQLSyntaxError: This key 'ingest-package-policies.non_existent_parameter' does NOT exist in ingest-package-policies saved object index patterns`
- );
- });
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by package name without SO',
+ async (packagePolicyType) => {
+ const validationObj = validateKuery(
+ `package.name:fleet_server`,
+ [packagePolicyType],
+ PACKAGE_POLICIES_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(true);
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by package name',
+ async (packagePolicyType) => {
+ const validationObj = validateKuery(
+ `${packagePolicyType}.package.name:fleet_server`,
+ [packagePolicyType],
+ PACKAGE_POLICIES_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(true);
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by package name works with attributes if skipNormalization is not passed',
+ async (packagePolicyType) => {
+ const validationObj = validateKuery(
+ `${packagePolicyType}.attributes.package.name:packageName`,
+ [packagePolicyType],
+ PACKAGE_POLICIES_MAPPINGS
+ );
+ expect(validationObj?.isValid).toEqual(true);
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'Search by name and version',
+ async (packagePolicyType) => {
+ const validationObj = validateKuery(
+ `${packagePolicyType}.package.name: "TestName" AND ${packagePolicyType}.package.version: "8.8.0"`,
+ [packagePolicyType],
+ PACKAGE_POLICIES_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(true);
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'Invalid search by nested wrong parameter',
+ async (packagePolicyType) => {
+ const validationObj = validateKuery(
+ `${packagePolicyType}.package.is_managed:packageName`,
+ [packagePolicyType],
+ PACKAGE_POLICIES_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(false);
+ expect(validationObj?.error).toEqual(
+ `KQLSyntaxError: This key '${packagePolicyType}.package.is_managed' does NOT exist in ${packagePolicyType} saved object index patterns`
+ );
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'invalid search by nested wrong parameter - without wrapped SO',
+ async (packagePolicyType) => {
+ const validationObj = validateKuery(
+ `package.is_managed:packageName`,
+ [packagePolicyType],
+ PACKAGE_POLICIES_MAPPINGS,
+ true
+ );
+ expect(validationObj?.isValid).toEqual(false);
+ expect(validationObj?.error).toEqual(
+ `KQLSyntaxError: This key 'package.is_managed' does NOT exist in ${packagePolicyType} saved object index patterns`
+ );
+ }
+ );
+
+ test.each([LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE])(
+ 'Invalid search by non existent parameter',
+ async (packagePolicyType) => {
+ const validationObj = validateKuery(
+ `${packagePolicyType}.non_existent_parameter:packageName`,
+ [packagePolicyType],
+ PACKAGE_POLICIES_MAPPINGS
+ );
+ expect(validationObj?.isValid).toEqual(false);
+ expect(validationObj?.error).toEqual(
+ `KQLSyntaxError: This key '${packagePolicyType}.non_existent_parameter' does NOT exist in ${packagePolicyType} saved object index patterns`
+ );
+ }
+ );
});
describe('Enrollment keys', () => {
diff --git a/x-pack/platform/plugins/shared/fleet/server/saved_objects/migrations/security_solution/to_v8_14_0.test.ts b/x-pack/platform/plugins/shared/fleet/server/saved_objects/migrations/security_solution/to_v8_14_0.test.ts
index 73f69c935d5a0..77361ecc978d8 100644
--- a/x-pack/platform/plugins/shared/fleet/server/saved_objects/migrations/security_solution/to_v8_14_0.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/saved_objects/migrations/security_solution/to_v8_14_0.test.ts
@@ -15,7 +15,7 @@ import { cloneDeep } from 'lodash';
import type { SavedObject } from '@kbn/core-saved-objects-server';
import type { PackagePolicy } from '../../../../common';
-import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../common';
+import { LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../common';
import { getSavedObjectTypes } from '../..';
const policyDoc: SavedObject = {
@@ -72,7 +72,7 @@ const policyDoc: SavedObject = {
},
],
},
- type: PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ type: LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
references: [],
};
@@ -81,7 +81,7 @@ describe('8.14.0 Endpoint Package Policy migration', () => {
beforeEach(() => {
migrator = createModelVersionTestMigrator({
- type: getSavedObjectTypes()[PACKAGE_POLICY_SAVED_OBJECT_TYPE],
+ type: getSavedObjectTypes()[LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE],
});
});
diff --git a/x-pack/platform/plugins/shared/fleet/server/saved_objects/migrations/to_v8_15_0.test.ts b/x-pack/platform/plugins/shared/fleet/server/saved_objects/migrations/to_v8_15_0.test.ts
index a6da2201d9669..c5fda8883448f 100644
--- a/x-pack/platform/plugins/shared/fleet/server/saved_objects/migrations/to_v8_15_0.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/saved_objects/migrations/to_v8_15_0.test.ts
@@ -13,7 +13,7 @@ import {
import type { SavedObject } from '@kbn/core-saved-objects-server';
import type { PackagePolicy } from '../../../common';
-import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../common';
+import { LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../common';
import { getSavedObjectTypes } from '..';
const getPolicyDoc = (packageName: string): SavedObject => {
@@ -38,7 +38,7 @@ const getPolicyDoc = (packageName: string): SavedObject => {
created_by: '',
inputs: [],
},
- type: PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ type: LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
references: [],
};
};
@@ -48,7 +48,7 @@ describe('8.15.0 Requires Root Package Policy migration', () => {
beforeEach(() => {
migrator = createModelVersionTestMigrator({
- type: getSavedObjectTypes()[PACKAGE_POLICY_SAVED_OBJECT_TYPE],
+ type: getSavedObjectTypes()[LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE],
});
});
diff --git a/x-pack/platform/plugins/shared/fleet/server/saved_objects/model_versions/security_solution/v10_on_write_scan_fix.test.ts b/x-pack/platform/plugins/shared/fleet/server/saved_objects/model_versions/security_solution/v10_on_write_scan_fix.test.ts
index d925e51ea7401..8408aeb6b4ed6 100644
--- a/x-pack/platform/plugins/shared/fleet/server/saved_objects/model_versions/security_solution/v10_on_write_scan_fix.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/saved_objects/model_versions/security_solution/v10_on_write_scan_fix.test.ts
@@ -12,7 +12,7 @@ import { createModelVersionTestMigrator } from '@kbn/core-test-helpers-model-ver
import { getSavedObjectTypes } from '../..';
import type { PackagePolicy } from '../../../../common';
-import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../common';
+import { LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../common';
describe('backfill for modelVersion 10 - fix on_write_scan field', () => {
let migrator: ModelVersionTestMigrator;
@@ -20,7 +20,7 @@ describe('backfill for modelVersion 10 - fix on_write_scan field', () => {
beforeEach(() => {
migrator = createModelVersionTestMigrator({
- type: getSavedObjectTypes()[PACKAGE_POLICY_SAVED_OBJECT_TYPE],
+ type: getSavedObjectTypes()[LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE],
});
policyConfigSO = {
@@ -74,7 +74,7 @@ describe('backfill for modelVersion 10 - fix on_write_scan field', () => {
},
],
},
- type: PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ type: LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
references: [],
};
});
diff --git a/x-pack/platform/plugins/shared/fleet/server/saved_objects/model_versions/security_solution/v13_advanced_package_policy_fields.test.ts b/x-pack/platform/plugins/shared/fleet/server/saved_objects/model_versions/security_solution/v13_advanced_package_policy_fields.test.ts
index 35eaf5bcd7f3b..d5824f11a6d2c 100644
--- a/x-pack/platform/plugins/shared/fleet/server/saved_objects/model_versions/security_solution/v13_advanced_package_policy_fields.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/saved_objects/model_versions/security_solution/v13_advanced_package_policy_fields.test.ts
@@ -14,7 +14,7 @@ import { cloneDeep } from 'lodash';
import type { PackagePolicy } from '../../../../common';
-import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../common';
+import { LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../../../common';
import { getSavedObjectTypes } from '../..';
const policyDoc: SavedObject = {
@@ -71,7 +71,7 @@ const policyDoc: SavedObject = {
},
],
},
- type: PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ type: LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
references: [],
};
@@ -80,7 +80,7 @@ describe('8.15.0 Endpoint Package Policy migration', () => {
beforeEach(() => {
migrator = createModelVersionTestMigrator({
- type: getSavedObjectTypes()[PACKAGE_POLICY_SAVED_OBJECT_TYPE],
+ type: getSavedObjectTypes()[LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE],
});
});
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/agents/action_runner.ts b/x-pack/platform/plugins/shared/fleet/server/services/agents/action_runner.ts
index d23c7eefecb9e..1f8fe78792ec0 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/agents/action_runner.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/agents/action_runner.ts
@@ -221,9 +221,11 @@ export abstract class ActionRunner {
const getAgents = async () => {
const namespaceFilter = await agentsKueryNamespaceFilter(this.actionParams.spaceId);
- const kuery = namespaceFilter
- ? `${namespaceFilter} AND ${this.actionParams.kuery}`
- : this.actionParams.kuery;
+
+ const kuery = [
+ ...(namespaceFilter ? [namespaceFilter] : []),
+ ...(this.actionParams.kuery ? [this.actionParams.kuery] : []),
+ ].join(' AND ');
return getAgentsByKuery(this.esClient, this.soClient, {
kuery,
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/agents/request_diagnostics.ts b/x-pack/platform/plugins/shared/fleet/server/services/agents/request_diagnostics.ts
index d78c4b191de75..8cf714465819b 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/agents/request_diagnostics.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/agents/request_diagnostics.ts
@@ -13,8 +13,6 @@ import { SO_SEARCH_LIMIT, REQUEST_DIAGNOSTICS_TIMEOUT_MS } from '../../constants
import { getCurrentNamespace } from '../spaces/get_current_namespace';
-import { agentsKueryNamespaceFilter } from '../spaces/agent_namespaces';
-
import type { GetAgentsOptions } from '.';
import { getAgents, getAgentsByKuery } from './crud';
import { createAgentAction } from './actions';
@@ -64,10 +62,10 @@ export async function bulkRequestDiagnostics(
}
const batchSize = options.batchSize ?? SO_SEARCH_LIMIT;
- const namespaceFilter = await agentsKueryNamespaceFilter(currentSpaceId);
- const kuery = namespaceFilter ? `${namespaceFilter} AND ${options.kuery}` : options.kuery;
+
const res = await getAgentsByKuery(esClient, soClient, {
- kuery,
+ kuery: options.kuery,
+ spaceId: currentSpaceId,
showInactive: false,
page: 1,
perPage: batchSize,
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/backfill_agentless.test.ts b/x-pack/platform/plugins/shared/fleet/server/services/backfill_agentless.test.ts
index 4359bb5510abe..0f1309f651071 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/backfill_agentless.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/backfill_agentless.test.ts
@@ -8,40 +8,58 @@
import { backfillPackagePolicySupportsAgentless } from './backfill_agentless';
import { packagePolicyService } from './package_policy';
-jest.mock('.', () => ({
- appContextService: {
- getLogger: () => ({
- debug: jest.fn(),
- }),
- getInternalUserSOClientForSpaceId: jest.fn(),
- getInternalUserSOClientWithoutSpaceExtension: () => ({
- find: jest.fn().mockImplementation((options) => {
- if (options.type === 'ingest-agent-policies') {
- return {
- saved_objects: [{ id: 'agent_policy_1' }, { id: 'agent_policy_2' }],
- };
- } else {
- return {
- saved_objects: [
- {
- id: 'package_policy_1',
- attributes: {
- inputs: [],
- policy_ids: ['agent_policy_1'],
- supports_agentless: false,
- package: {
- name: 'cloud_asset_inventory',
- version: '0.19.0',
+jest.mock('./audit_logging', () => ({
+ auditLoggingService: {
+ writeCustomSoAuditLog: jest.fn(),
+ },
+}));
+
+jest.mock('./settings', () => ({
+ getSettingsOrUndefined: () => ({
+ use_space_awareness_migration_status: 'success',
+ }),
+}));
+
+jest.mock('./app_context', () => {
+ return {
+ appContextService: {
+ getExperimentalFeatures: () => ({
+ useSpaceAwareness: true,
+ }),
+ getLogger: () => ({
+ debug: jest.fn(),
+ }),
+ getInternalUserSOClient: jest.fn(),
+ getInternalUserSOClientForSpaceId: jest.fn(),
+ getInternalUserSOClientWithoutSpaceExtension: () => ({
+ find: jest.fn().mockImplementation((options) => {
+ if (options.type === 'ingest-agent-policies') {
+ return {
+ saved_objects: [{ id: 'agent_policy_1' }, { id: 'agent_policy_2' }],
+ };
+ } else {
+ return {
+ saved_objects: [
+ {
+ id: 'package_policy_1',
+ attributes: {
+ inputs: [],
+ policy_ids: ['agent_policy_1'],
+ supports_agentless: false,
+ package: {
+ name: 'cloud_asset_inventory',
+ version: '0.19.0',
+ },
},
},
- },
- ],
- };
- }
+ ],
+ };
+ }
+ }),
}),
- }),
- },
-}));
+ },
+ };
+});
jest.mock('./package_policy', () => ({
packagePolicyService: {
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/get.test.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/get.test.ts
index 8259293e01511..c8118f50f84c0 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/get.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/get.test.ts
@@ -40,6 +40,8 @@ import {
getPackageUsageStats,
} from './get';
+const mockPackagePolicySavedObjectType = PACKAGE_POLICY_SAVED_OBJECT_TYPE;
+
jest.mock('../registry');
jest.mock('../../settings');
jest.mock('../../audit_logging');
@@ -54,6 +56,11 @@ jest.mock('../archive/storage', () => {
),
};
});
+jest.mock('../../package_policy', () => {
+ return {
+ getPackagePolicySavedObjectType: () => mockPackagePolicySavedObjectType,
+ };
+});
const MockRegistry = jest.mocked(Registry);
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/steps/step_save_system_object.ts b/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/steps/step_save_system_object.ts
index 188e9dc4efb2e..77f03f4827c46 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/steps/step_save_system_object.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/install_state_machine/steps/step_save_system_object.ts
@@ -13,7 +13,7 @@ import {
} from '../../../../../constants';
import type { Installation } from '../../../../../types';
-import { packagePolicyService } from '../../../..';
+import { packagePolicyService } from '../../../../package_policy';
import { auditLoggingService } from '../../../../audit_logging';
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/fleet_server_host.test.ts b/x-pack/platform/plugins/shared/fleet/server/services/fleet_server_host.test.ts
index e3e5ab77bbe37..375b7eb259699 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/fleet_server_host.test.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/fleet_server_host.test.ts
@@ -17,6 +17,7 @@ import {
GLOBAL_SETTINGS_SAVED_OBJECT_TYPE,
FLEET_SERVER_HOST_SAVED_OBJECT_TYPE,
DEFAULT_FLEET_SERVER_HOST_ID,
+ LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
} from '../constants';
@@ -92,7 +93,10 @@ function getMockedSoClient(options?: { id?: string; findHosts?: boolean; findSet
} as any;
}
- if (type === PACKAGE_POLICY_SAVED_OBJECT_TYPE) {
+ if (
+ type === LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE ||
+ type === PACKAGE_POLICY_SAVED_OBJECT_TYPE
+ ) {
return {
saved_objects: [
{
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/output.ts b/x-pack/platform/plugins/shared/fleet/server/services/output.ts
index 9156741adf4cd..cb96d563544d9 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/output.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/output.ts
@@ -38,7 +38,7 @@ import type {
PolicySecretReference,
} from '../types';
import {
- LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
+ AGENT_POLICY_SAVED_OBJECT_TYPE,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
DEFAULT_OUTPUT,
DEFAULT_OUTPUT_ID,
@@ -152,13 +152,13 @@ async function getAgentPoliciesPerOutput(outputId?: string, isDefault?: boolean)
const packagePoliciesKuery: string = `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.output_id:"${outputId}"`;
if (outputId) {
if (isDefault) {
- agentPoliciesKuery = `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:"${outputId}" or not ${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:*`;
+ agentPoliciesKuery = `${AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:"${outputId}" or not ${AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:*`;
} else {
- agentPoliciesKuery = `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:"${outputId}"`;
+ agentPoliciesKuery = `${AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:"${outputId}"`;
}
} else {
if (isDefault) {
- agentPoliciesKuery = `not ${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:*`;
+ agentPoliciesKuery = `not ${AGENT_POLICY_SAVED_OBJECT_TYPE}.data_output_id:*`;
} else {
return;
}
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/preconfiguration/reset_agent_policies.ts b/x-pack/platform/plugins/shared/fleet/server/services/preconfiguration/reset_agent_policies.ts
index 47939b4ed0c9c..f7837d2adb095 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/preconfiguration/reset_agent_policies.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/preconfiguration/reset_agent_policies.ts
@@ -12,12 +12,12 @@ import { SavedObjectsErrorHelpers } from '@kbn/core/server';
import { appContextService } from '../app_context';
import { setupFleet } from '../setup';
import {
- LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE,
+ AGENT_POLICY_SAVED_OBJECT_TYPE,
SO_SEARCH_LIMIT,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
PRECONFIGURATION_DELETION_RECORD_SAVED_OBJECT_TYPE,
} from '../../constants';
-import { agentPolicyService, getAgentPolicySavedObjectType } from '../agent_policy';
+import { agentPolicyService } from '../agent_policy';
import { packagePolicyService } from '../package_policy';
import { getAgentsByKuery, forceUnenrollAgent } from '../agents';
import { listEnrollmentApiKeys, deleteEnrollmentApiKey } from '../api_keys';
@@ -63,8 +63,7 @@ async function _deleteGhostPackagePolicies(
return;
}
- const savedObjectType = await getAgentPolicySavedObjectType();
- const objects = policyIds.map((id) => ({ id, type: savedObjectType }));
+ const objects = policyIds.map((id) => ({ id, type: AGENT_POLICY_SAVED_OBJECT_TYPE }));
const agentPolicyExistsMap = (await soClient.bulkGet(objects)).saved_objects.reduce((acc, so) => {
if (so.error && so.error.statusCode === 404) {
acc.set(so.id, false);
@@ -149,7 +148,7 @@ async function _deleteExistingData(
existingPolicies = (
await agentPolicyService.list(soClient, {
perPage: SO_SEARCH_LIMIT,
- kuery: `${LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE}.is_preconfigured:true`,
+ kuery: `${AGENT_POLICY_SAVED_OBJECT_TYPE}.is_preconfigured:true`,
})
).items;
}
diff --git a/x-pack/platform/plugins/shared/fleet/server/services/setup.ts b/x-pack/platform/plugins/shared/fleet/server/services/setup.ts
index ed4486021d989..929abc9aa2df4 100644
--- a/x-pack/platform/plugins/shared/fleet/server/services/setup.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/services/setup.ts
@@ -165,14 +165,12 @@ async function createSetupSideEffects(
);
logger.debug('Setting up Fleet outputs');
- await Promise.all([
- ensurePreconfiguredOutputs(
- soClient,
- esClient,
- getPreconfiguredOutputFromConfig(appContextService.getConfig())
- ),
- settingsService.settingsSetup(soClient),
- ]);
+ await settingsService.settingsSetup(soClient);
+ await ensurePreconfiguredOutputs(
+ soClient,
+ esClient,
+ getPreconfiguredOutputFromConfig(appContextService.getConfig())
+ );
const defaultOutput = await outputService.ensureDefaultOutput(soClient, esClient);
diff --git a/x-pack/platform/plugins/shared/fleet/server/tasks/packages_bulk_operations/run_bulk_upgrade.ts b/x-pack/platform/plugins/shared/fleet/server/tasks/packages_bulk_operations/run_bulk_upgrade.ts
index e6036d401623f..d19f74f20aafa 100644
--- a/x-pack/platform/plugins/shared/fleet/server/tasks/packages_bulk_operations/run_bulk_upgrade.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/tasks/packages_bulk_operations/run_bulk_upgrade.ts
@@ -13,6 +13,7 @@ import { HTTPAuthorizationHeader } from '../../../common/http_authorization_head
import { installPackage } from '../../services/epm/packages';
import { appContextService, packagePolicyService } from '../../services';
import { PACKAGE_POLICY_SAVED_OBJECT_TYPE, SO_SEARCH_LIMIT } from '../../constants';
+
import { scheduleBulkOperationTask, formatError } from './utils';
export interface BulkUpgradeTaskParams {
diff --git a/x-pack/platform/plugins/shared/fleet/server/types/rest_spec/package_policy.ts b/x-pack/platform/plugins/shared/fleet/server/types/rest_spec/package_policy.ts
index 03d421eaa14fa..dd2e9c30c37d6 100644
--- a/x-pack/platform/plugins/shared/fleet/server/types/rest_spec/package_policy.ts
+++ b/x-pack/platform/plugins/shared/fleet/server/types/rest_spec/package_policy.ts
@@ -19,7 +19,11 @@ import {
import { inputsFormat } from '../../../common/constants';
-import { PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICIES_MAPPINGS } from '../../constants';
+import {
+ LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ PACKAGE_POLICIES_MAPPINGS,
+} from '../../constants';
import { validateKuery } from '../../routes/utils/filter_utils';
@@ -37,7 +41,7 @@ export const GetPackagePoliciesRequestSchema = {
validate: (value: string) => {
const validationObj = validateKuery(
value,
- [PACKAGE_POLICY_SAVED_OBJECT_TYPE],
+ [LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE, PACKAGE_POLICY_SAVED_OBJECT_TYPE],
PACKAGE_POLICIES_MAPPINGS,
true
);
diff --git a/x-pack/platform/test/api_integration/apis/security/privileges.ts b/x-pack/platform/test/api_integration/apis/security/privileges.ts
index a3a1023382f88..35d9c2929cb81 100644
--- a/x-pack/platform/test/api_integration/apis/security/privileges.ts
+++ b/x-pack/platform/test/api_integration/apis/security/privileges.ts
@@ -9,6 +9,7 @@ import util from 'util';
import { isEqual, isEqualWith } from 'lodash';
import expect from '@kbn/expect';
import { RawKibanaPrivileges } from '@kbn/security-plugin-types-common';
+import { diff } from 'jest-diff';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
@@ -138,6 +139,7 @@ export default function ({ getService }: FtrProviderContext) {
'endpoint_list_read',
'workflow_insights_all',
'workflow_insights_read',
+ 'global_artifact_management_all',
'trusted_applications_all',
'trusted_applications_read',
'host_isolation_exceptions_all',
@@ -332,18 +334,30 @@ export default function ({ getService }: FtrProviderContext) {
.send()
.expect(200)
.expect((res: any) => {
+ let errorPointerMessage = '';
// when comparing privileges, the order of the features doesn't matter (but the order of the privileges does)
// supertest uses assert.deepStrictEqual.
// expect.js doesn't help us here.
// and lodash's isEqual doesn't know how to compare Sets.
const success = isEqualWith(res.body, expectedWithoutActions, (value, other, key) => {
if (Array.isArray(value) && Array.isArray(other)) {
+ let isEqualResponse = false;
+
if (key === 'reserved') {
// order does not matter for the reserved privilege set.
- return isEqual(value.sort(), other.sort());
+ isEqualResponse = isEqual(value.sort(), other.sort());
+ } else {
+ // order matters for the rest, as the UI assumes they are returned in a descending order of permissiveness.
+ isEqualResponse = isEqual(value, other);
}
- // order matters for the rest, as the UI assumes they are returned in a descending order of permissiveness.
- return isEqual(value, other);
+
+ if (!isEqualResponse) {
+ errorPointerMessage = `Received value for property [${String(
+ key
+ )}] does not match expected value:\n${diff(other, value)}`;
+ }
+
+ return isEqualResponse;
}
// Lodash types aren't correct, `undefined` should be supported as a return value here and it
@@ -353,9 +367,9 @@ export default function ({ getService }: FtrProviderContext) {
if (!success) {
throw new Error(
- `Expected ${util.inspect(res.body)} to equal ${util.inspect(
- expectedWithoutActions
- )}`
+ `${errorPointerMessage ? errorPointerMessage + '\n\n' : ''}Expected ${util.inspect(
+ res.body
+ )} to equal ${util.inspect(expectedWithoutActions)}`
);
}
})
@@ -441,18 +455,30 @@ export default function ({ getService }: FtrProviderContext) {
.send()
.expect(200)
.expect((res: any) => {
+ let errorPointerMessage = '';
// when comparing privileges, the order of the features doesn't matter (but the order of the privileges does)
// supertest uses assert.deepStrictEqual.
// expect.js doesn't help us here.
// and lodash's isEqual doesn't know how to compare Sets.
const success = isEqualWith(res.body, expectedWithoutActions, (value, other, key) => {
if (Array.isArray(value) && Array.isArray(other)) {
+ let isEqualResponse = false;
+
if (key === 'reserved') {
// order does not matter for the reserved privilege set.
- return isEqual(value.sort(), other.sort());
+ isEqualResponse = isEqual(value.sort(), other.sort());
+ } else {
+ // order matters for the rest, as the UI assumes they are returned in a descending order of permissiveness.
+ isEqualResponse = isEqual(value, other);
+ }
+
+ if (!isEqualResponse) {
+ errorPointerMessage = `Received value for property [${String(
+ key
+ )}] does not match expected value:\n${diff(other, value)}`;
}
- // order matters for the rest, as the UI assumes they are returned in a descending order of permissiveness.
- return isEqual(value, other);
+
+ return isEqualResponse;
}
// Lodash types aren't correct, `undefined` should be supported as a return value here and it
@@ -462,9 +488,9 @@ export default function ({ getService }: FtrProviderContext) {
if (!success) {
throw new Error(
- `Expected ${util.inspect(res.body)} to equal ${util.inspect(
- expectedWithoutActions
- )}`
+ `${errorPointerMessage ? errorPointerMessage + '\n\n' : ''}Expected ${util.inspect(
+ res.body
+ )} to equal ${util.inspect(expectedWithoutActions)}`
);
}
})
diff --git a/x-pack/platform/test/api_integration/apis/security/roles_bulk.ts b/x-pack/platform/test/api_integration/apis/security/roles_bulk.ts
index 22c63e3ec1542..64a35f2333777 100644
--- a/x-pack/platform/test/api_integration/apis/security/roles_bulk.ts
+++ b/x-pack/platform/test/api_integration/apis/security/roles_bulk.ts
@@ -249,7 +249,7 @@ export default function ({ getService }: FtrProviderContext) {
spaces: ['bar-space'],
base: [],
feature: {
- fleetv2: ['all', 'read'],
+ streams: ['all', 'read'],
},
},
],
diff --git a/x-pack/platform/test/api_integration_basic/apis/security/privileges.ts b/x-pack/platform/test/api_integration_basic/apis/security/privileges.ts
index eae2a4b3adf1e..58ddbc3bdbc68 100644
--- a/x-pack/platform/test/api_integration_basic/apis/security/privileges.ts
+++ b/x-pack/platform/test/api_integration_basic/apis/security/privileges.ts
@@ -7,6 +7,7 @@
import util from 'util';
import { isEqual, isEqualWith } from 'lodash';
+import { diff } from 'jest-diff';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
@@ -237,6 +238,7 @@ export default function ({ getService }: FtrProviderContext) {
'actions_log_management_all',
'actions_log_management_read',
'all',
+ 'global_artifact_management_all',
'blocklist_all',
'blocklist_read',
'endpoint_list_all',
@@ -434,13 +436,22 @@ export default function ({ getService }: FtrProviderContext) {
.send()
.expect(200)
.expect((res: any) => {
+ let errorPointerMessage = '';
// when comparing privileges, the order of the privileges doesn't matter.
// supertest uses assert.deepStrictEqual.
// expect.js doesn't help us here.
// and lodash's isEqual doesn't know how to compare Sets.
const success = isEqualWith(res.body, expected, (value, other, key) => {
if (Array.isArray(value) && Array.isArray(other)) {
- return isEqual(value.sort(), other.sort());
+ const isArrayEqual = isEqual(value.sort(), other.sort());
+
+ if (!isArrayEqual) {
+ errorPointerMessage = `Received value for property [${String(
+ key
+ )}] does not match expected value:\n${diff(other, value)}`;
+ }
+
+ return isArrayEqual;
}
// Lodash types aren't correct, `undefined` should be supported as a return value here and it
@@ -450,7 +461,9 @@ export default function ({ getService }: FtrProviderContext) {
if (!success) {
throw new Error(
- `Expected ${util.inspect(res.body)} to equal ${util.inspect(expected)}`
+ `${errorPointerMessage ? errorPointerMessage + '\n\n' : ''}Expected ${util.inspect(
+ res.body
+ )} to equal ${util.inspect(expected)}`
);
}
})
diff --git a/x-pack/platform/test/fleet_api_integration/apis/agent_policy/__snapshots__/agent_policy.snap b/x-pack/platform/test/fleet_api_integration/apis/agent_policy/__snapshots__/agent_policy.snap
index ac971448c088a..15fb5e4ad29b1 100644
--- a/x-pack/platform/test/fleet_api_integration/apis/agent_policy/__snapshots__/agent_policy.snap
+++ b/x-pack/platform/test/fleet_api_integration/apis/agent_policy/__snapshots__/agent_policy.snap
@@ -10,6 +10,9 @@ Object {
"namespace": "default",
"revision": 1,
"schema_version": "1.1.1",
+ "space_ids": Array [
+ "default",
+ ],
"status": "active",
"unprivileged_agents": 0,
"updated_by": "elastic",
@@ -36,6 +39,9 @@ Object {
"title": "System",
},
"revision": 1,
+ "spaceIds": Array [
+ "default",
+ ],
"updated_by": "elastic",
},
],
diff --git a/x-pack/platform/test/fleet_api_integration/apis/agent_policy/agent_policy.ts b/x-pack/platform/test/fleet_api_integration/apis/agent_policy/agent_policy.ts
index a32242442023c..58ca0457d47f7 100644
--- a/x-pack/platform/test/fleet_api_integration/apis/agent_policy/agent_policy.ts
+++ b/x-pack/platform/test/fleet_api_integration/apis/agent_policy/agent_policy.ts
@@ -712,7 +712,8 @@ export default function (providerContext: FtrProviderContext) {
updated_by: 'elastic',
package_policies: [],
is_protected: false,
- space_ids: [],
+ space_ids: ['default'],
+ supports_agentless: false,
});
});
@@ -1221,7 +1222,7 @@ export default function (providerContext: FtrProviderContext) {
inactivity_timeout: 1209600,
package_policies: [],
is_protected: false,
- space_ids: [],
+ space_ids: ['default'],
});
});
@@ -1282,7 +1283,7 @@ export default function (providerContext: FtrProviderContext) {
inactivity_timeout: 1209600,
package_policies: [],
is_protected: false,
- space_ids: [],
+ space_ids: ['default'],
});
});
@@ -1445,7 +1446,7 @@ export default function (providerContext: FtrProviderContext) {
package_policies: [],
monitoring_enabled: ['logs', 'metrics'],
inactivity_timeout: 1209600,
- space_ids: [],
+ space_ids: ['default'],
});
const listResponseAfterUpdate = await fetchPackageList();
@@ -1504,7 +1505,7 @@ export default function (providerContext: FtrProviderContext) {
inactivity_timeout: 1209600,
package_policies: [],
is_protected: false,
- space_ids: [],
+ space_ids: ['default'],
overrides: {
agent: {
logging: {
@@ -1622,7 +1623,7 @@ export default function (providerContext: FtrProviderContext) {
inactivity_timeout: 1209600,
package_policies: [],
is_protected: false,
- space_ids: [],
+ space_ids: ['default'],
required_versions: [
{
version: '9.0.0',
diff --git a/x-pack/platform/test/fleet_api_integration/apis/agent_policy/agent_policy_with_agents_setup.ts b/x-pack/platform/test/fleet_api_integration/apis/agent_policy/agent_policy_with_agents_setup.ts
index 53c5d87b24b03..83e4fda7b053d 100644
--- a/x-pack/platform/test/fleet_api_integration/apis/agent_policy/agent_policy_with_agents_setup.ts
+++ b/x-pack/platform/test/fleet_api_integration/apis/agent_policy/agent_policy_with_agents_setup.ts
@@ -100,7 +100,7 @@ export default function (providerContext: FtrProviderContext) {
const name = `test-${Date.now()}`;
const res = await supertest
- .post(`/s/test/api/fleet/agent_policies?sys_monitoring=true`)
+ .post(`/api/fleet/agent_policies?sys_monitoring=true`)
.set('kbn-xsrf', 'xxxx')
.send({
name,
diff --git a/x-pack/platform/test/fleet_api_integration/apis/fleet_setup.ts b/x-pack/platform/test/fleet_api_integration/apis/fleet_setup.ts
index 2b474ea99532f..08e700c3224b0 100644
--- a/x-pack/platform/test/fleet_api_integration/apis/fleet_setup.ts
+++ b/x-pack/platform/test/fleet_api_integration/apis/fleet_setup.ts
@@ -8,7 +8,7 @@
import expect from '@kbn/expect';
import { v4 as uuidV4 } from 'uuid';
import { INGEST_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server';
-import { LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common/constants';
+import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common/constants';
import { SearchTotalHits } from '@elastic/elasticsearch/lib/api/types';
import { FtrProviderContext } from '../../api_integration/ftr_provider_context';
@@ -72,6 +72,7 @@ export default function (providerContext: FtrProviderContext) {
describe('upgrade managed package policies', () => {
const apiClient = new SpaceTestApiClient(supertest);
before(async () => {
+ await apiClient.setup();
const pkgRes = await apiClient.getPackage({
pkgName: 'synthetics',
});
@@ -96,12 +97,13 @@ export default function (providerContext: FtrProviderContext) {
operations: [...new Array(10).keys()].flatMap((_, index) => [
{
create: {
- _id: `${LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE}:${uuidV4()}`,
+ _id: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}:${uuidV4()}`,
},
},
{
- type: LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE,
- [LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE]: {
+ type: PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+ namespaces: ['default'],
+ [PACKAGE_POLICY_SAVED_OBJECT_TYPE]: {
name: `test-${index}`,
policy_ids: [agentPolicyRes.item.id],
inputs: [],
@@ -114,7 +116,7 @@ export default function (providerContext: FtrProviderContext) {
]),
});
- await apiClient.getPackage({
+ return await apiClient.getPackage({
pkgName: 'synthetics',
});
});
@@ -130,12 +132,12 @@ export default function (providerContext: FtrProviderContext) {
bool: {
must: {
term: {
- [`${LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.version`]: '1.2.1',
+ [`${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.version`]: '1.2.1',
},
},
filter: {
term: {
- [`${LEGACY_PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name`]: 'synthetics',
+ [`${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name`]: 'synthetics',
},
},
},
diff --git a/x-pack/platform/test/fleet_api_integration/apis/outputs/crud.ts b/x-pack/platform/test/fleet_api_integration/apis/outputs/crud.ts
index 0c5fb82f7db72..3d79e6d20d445 100644
--- a/x-pack/platform/test/fleet_api_integration/apis/outputs/crud.ts
+++ b/x-pack/platform/test/fleet_api_integration/apis/outputs/crud.ts
@@ -52,6 +52,7 @@ export default function (providerContext: FtrProviderContext) {
id: 'fleet-default-settings',
attributes: {
output_secret_storage_requirements_met: true,
+ use_space_awareness_migration_status: 'success',
},
overwrite: true,
});
@@ -67,6 +68,7 @@ export default function (providerContext: FtrProviderContext) {
id: 'fleet-default-settings',
attributes: {
output_secret_storage_requirements_met: false,
+ use_space_awareness_migration_status: 'success',
},
overwrite: true,
});
diff --git a/x-pack/platform/test/fleet_api_integration/apis/settings/enrollment.ts b/x-pack/platform/test/fleet_api_integration/apis/settings/enrollment.ts
index d69051b6140a9..f9539c1e0726e 100644
--- a/x-pack/platform/test/fleet_api_integration/apis/settings/enrollment.ts
+++ b/x-pack/platform/test/fleet_api_integration/apis/settings/enrollment.ts
@@ -68,14 +68,14 @@ export default function (providerContext: FtrProviderContext) {
is_default_fleet_server: true,
is_managed: false,
name: 'Fleet Server Policy',
- space_ids: [],
+ space_ids: ['default'],
},
{
id: 'fleet-server-policy-2',
is_default_fleet_server: false,
is_managed: false,
name: 'Fleet Server Policy 2',
- space_ids: [],
+ space_ids: ['default'],
},
],
has_active: true,
@@ -133,7 +133,7 @@ export default function (providerContext: FtrProviderContext) {
is_default_fleet_server: false,
is_managed: false,
name: 'Fleet Server Policy 2',
- space_ids: [],
+ space_ids: ['default'],
},
],
has_active: true,
diff --git a/x-pack/platform/test/fleet_tasks/tests/automatic_upgrades.ts b/x-pack/platform/test/fleet_tasks/tests/automatic_upgrades.ts
index 0b9fbd12c10d5..8442095a48550 100644
--- a/x-pack/platform/test/fleet_tasks/tests/automatic_upgrades.ts
+++ b/x-pack/platform/test/fleet_tasks/tests/automatic_upgrades.ts
@@ -32,6 +32,7 @@ export default function (providerContext: FtrProviderContextWithServices) {
describe('Automatic agent upgrades', () => {
before(async () => {
+ await supertest.post(`/api/fleet/setup`).set('kbn-xsrf', 'xxxx').expect(200);
const { body: agentPolicyResponse } = await supertest
.post('/api/fleet/agent_policies')
.set('kbn-xsrf', 'xxxx')
diff --git a/x-pack/solutions/observability/test/api_integration/apis/synthetics/sample_data/test_policy.ts b/x-pack/solutions/observability/test/api_integration/apis/synthetics/sample_data/test_policy.ts
index ae0e92612ee91..43a5ad9052ee5 100644
--- a/x-pack/solutions/observability/test/api_integration/apis/synthetics/sample_data/test_policy.ts
+++ b/x-pack/solutions/observability/test/api_integration/apis/synthetics/sample_data/test_policy.ts
@@ -31,6 +31,7 @@ export const getTestSyntheticsPolicy = (props: PolicyProps): PackagePolicy => {
version: 'WzE2MjYsMV0=',
name: 'test-monitor-name-Test private location 0-default',
namespace: namespace ?? 'testnamespace',
+ spaceIds: ['default'],
package: { name: 'synthetics', title: 'Elastic Synthetics', version: INSTALLED_VERSION },
enabled: true,
policy_id: '5347cd10-0368-11ed-8df7-a7424c6f5167',
diff --git a/x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/synthetics/sample_data/test_policy.ts b/x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/synthetics/sample_data/test_policy.ts
index 2079876efea48..4a7ae5783828a 100644
--- a/x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/synthetics/sample_data/test_policy.ts
+++ b/x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/synthetics/sample_data/test_policy.ts
@@ -31,6 +31,7 @@ export const getTestSyntheticsPolicy = (props: PolicyProps): PackagePolicy => {
version: 'WzE2MjYsMV0=',
name: 'test-monitor-name-Test private location 0-default',
namespace: namespace ?? 'testnamespace',
+ spaceIds: ['default'],
package: { name: 'synthetics', title: 'Elastic Synthetics', version: INSTALLED_VERSION },
enabled: true,
policy_id: '5347cd10-0368-11ed-8df7-a7424c6f5167',
diff --git a/x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/synthetics/sample_data/test_project_monitor_policy.ts b/x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/synthetics/sample_data/test_project_monitor_policy.ts
index b3923dca22f67..781fde0e2a0ae 100644
--- a/x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/synthetics/sample_data/test_project_monitor_policy.ts
+++ b/x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/synthetics/sample_data/test_project_monitor_policy.ts
@@ -52,6 +52,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
version: 'WzEzMDksMV0=',
name: `4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-${locationName}`,
namespace: namespace || undefined,
+ spaceIds: ['default'],
package: { name: 'synthetics', title: 'Elastic Synthetics', version: INSTALLED_VERSION },
enabled: true,
policy_id: '46034710-0ba6-11ed-ba04-5f123b9faa8b',
@@ -546,6 +547,7 @@ export const getTestProjectSyntheticsPolicy = (
version: 'WzEzMDksMV0=',
name: `4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-Test private location 0`,
namespace: namespace || undefined,
+ spaceIds: ['default'],
package: { name: 'synthetics', title: 'Elastic Synthetics', version: INSTALLED_VERSION },
enabled: true,
policy_id: '46034710-0ba6-11ed-ba04-5f123b9faa8b',
diff --git a/x-pack/solutions/security/plugins/security_solution/common/experimental_features.ts b/x-pack/solutions/security/plugins/security_solution/common/experimental_features.ts
index f8f65a0beefed..e4057758ad1e9 100644
--- a/x-pack/solutions/security/plugins/security_solution/common/experimental_features.ts
+++ b/x-pack/solutions/security/plugins/security_solution/common/experimental_features.ts
@@ -91,7 +91,7 @@ export const allowedExperimentalValues = Object.freeze({
* and Fleet must set it runtime mode to spaces by calling the following API:
* - `POST /internal/fleet/enable_space_awareness`
*/
- endpointManagementSpaceAwarenessEnabled: false,
+ endpointManagementSpaceAwarenessEnabled: true,
/**
* Disables new notes
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/components/artifact_list_page/components/integration_tests/artifact_delete_modal.test.ts b/x-pack/solutions/security/plugins/security_solution/public/management/components/artifact_list_page/components/integration_tests/artifact_delete_modal.test.ts
index 51e90cbc9829d..adfde549b27aa 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/components/artifact_list_page/components/integration_tests/artifact_delete_modal.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/components/artifact_list_page/components/integration_tests/artifact_delete_modal.test.ts
@@ -8,6 +8,8 @@
import { getArtifactListPageRenderingSetup } from '../../mocks';
import { waitFor } from '@testing-library/react';
+jest.mock('../../../../../common/components/user_privileges');
+
const setupTest = async () => {
const renderSetup = getArtifactListPageRenderingSetup();
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/components/policy_selector/policy_selector.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/components/policy_selector/policy_selector.test.tsx
index 869c1e4b7d94e..2b6bcb97044e5 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/components/policy_selector/policy_selector.test.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/components/policy_selector/policy_selector.test.tsx
@@ -13,7 +13,10 @@ import { allFleetHttpMocks } from '../../mocks';
import React from 'react';
import { act, fireEvent, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
-import { packagePolicyRouteService } from '@kbn/fleet-plugin/common';
+import {
+ packagePolicyRouteService,
+ PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+} from '@kbn/fleet-plugin/common';
import { FleetPackagePolicyGenerator } from '../../../../common/endpoint/data_generators/fleet_package_policy_generator';
import { useUserPrivileges as _useUserPrivileges } from '../../../common/components/user_privileges';
import { getPolicyDetailPath } from '../../common/routing';
@@ -157,8 +160,7 @@ describe('PolicySelector component', () => {
packagePolicyRouteService.getListPath(),
{
query: {
- kuery:
- '(ingest-package-policies.package.name: endpoint) AND ((ingest-package-policies.name:*foo*) OR (ingest-package-policies.description:*foo*))',
+ kuery: `(${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint) AND ((${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.name:*foo*) OR (${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.description:*foo*))`,
page: 1,
perPage: 20,
sortField: 'name',
@@ -489,7 +491,7 @@ describe('PolicySelector component', () => {
packagePolicyRouteService.getListPath(),
{
query: {
- kuery: 'ingest-package-policies.package.name: endpoint',
+ kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint`,
page: 1,
perPage: 20,
sortField: 'name',
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/cypress/e2e/rbac/endpoint_role_rbac.cy.ts b/x-pack/solutions/security/plugins/security_solution/public/management/cypress/e2e/rbac/endpoint_role_rbac.cy.ts
index ffd0caab70b83..e1c4055bbabf4 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/cypress/e2e/rbac/endpoint_role_rbac.cy.ts
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/cypress/e2e/rbac/endpoint_role_rbac.cy.ts
@@ -53,7 +53,7 @@ describe(
.should('deep.equal', [
'Endpoint List Displays all hosts running Elastic Defend and their relevant integration details.Endpoint List sub-feature privilegeAllReadNone',
'Automatic Troubleshooting Access to the automatic troubleshooting.Automatic Troubleshooting sub-feature privilegeAllReadNone',
- 'Global Artifact Management (coming soon) Manage global assignment of endpoint artifacts (e.g., Trusted Applications, Event Filters) across all policies. This privilege controls global assignment rights only; privileges for each artifact type are required for full artifact management.Global Artifact Management (coming soon) sub-feature privilegeAllNone',
+ 'Global Artifact Management Manage global assignment of endpoint artifacts (e.g., Trusted Applications, Event Filters) across all policies. This privilege controls global assignment rights only; privileges for each artifact type are required for full artifact management.Global Artifact Management sub-feature privilegeAllNone',
'Trusted Applications Helps mitigate conflicts with other software, usually other antivirus or endpoint security applications.Trusted Applications sub-feature privilegeAllReadNone',
'Host Isolation Exceptions Add specific IP addresses that isolated hosts are still allowed to communicate with, even when isolated from the rest of the network.Host Isolation Exceptions sub-feature privilegeAllReadNone',
'Blocklist Extend Elastic Defend’s protection against malicious processes and protect against potentially harmful applications.Blocklist sub-feature privilegeAllReadNone',
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/blocklist/view/components/blocklist_form.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/pages/blocklist/view/components/blocklist_form.test.tsx
index 89b804ebeb6c5..1ae836c45bc4f 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/blocklist/view/components/blocklist_form.test.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/blocklist/view/components/blocklist_form.test.tsx
@@ -27,6 +27,8 @@ import { ListOperatorEnum, ListOperatorTypeEnum } from '@kbn/securitysolution-io
import { ENDPOINT_ARTIFACT_LISTS } from '@kbn/securitysolution-list-constants';
import type { IHttpFetchError } from '@kbn/core/public';
+jest.mock('../../../../../common/components/user_privileges');
+
jest.mock('../../../../../common/hooks/use_license', () => {
const licenseServiceInstance = {
isPlatinumPlus: jest.fn(),
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/components/form.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/components/form.test.tsx
index 349584a77054b..2e4b35bdcee21 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/components/form.test.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/components/form.test.tsx
@@ -30,6 +30,7 @@ import { buildPerPolicyTag } from '../../../../../../common/endpoint/service/art
jest.setTimeout(15_000); // Costly tests, hitting 2 seconds execution time locally
+jest.mock('../../../../../common/components/user_privileges');
jest.mock('../../../../../common/lib/kibana');
jest.mock('../../../../../common/containers/source');
jest.mock('../../../../../common/hooks/use_license', () => {
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/integration_tests/event_filters_list.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/integration_tests/event_filters_list.test.tsx
index 5a0557a9360f8..9c7bdf490e911 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/integration_tests/event_filters_list.test.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/integration_tests/event_filters_list.test.tsx
@@ -40,7 +40,10 @@ describe('When on the Event Filters list page', () => {
history.push(EVENT_FILTERS_PATH);
});
- mockedEndpointPrivileges = { canWriteTrustedApplications: true };
+ mockedEndpointPrivileges = {
+ canManageGlobalArtifacts: true,
+ canWriteTrustedApplications: true,
+ };
mockUserPrivileges.mockReturnValue({ endpointPrivileges: mockedEndpointPrivileges });
});
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/policy/view/artifacts/list/policy_artifacts_list.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/pages/policy/view/artifacts/list/policy_artifacts_list.test.tsx
index a4bd484e55d9a..b41296c7c7727 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/policy/view/artifacts/list/policy_artifacts_list.test.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/policy/view/artifacts/list/policy_artifacts_list.test.tsx
@@ -18,12 +18,15 @@ import { eventFiltersListQueryHttpMock } from '../../../../event_filters/test_ut
import { PolicyArtifactsList } from './policy_artifacts_list';
import { parseQueryFilterToKQL, parsePoliciesAndFilterToKql } from '../../../../../common/utils';
import { SEARCHABLE_FIELDS } from '../../../../event_filters/constants';
-import { getEndpointPrivilegesInitialStateMock } from '../../../../../../common/components/user_privileges/endpoint/mocks';
+import { useUserPrivileges as _useUserPrivileges } from '../../../../../../common/components/user_privileges';
import { POLICY_ARTIFACT_LIST_LABELS } from './translations';
import { EventFiltersApiClient } from '../../../../event_filters/service/api_client';
import { ExceptionsListItemGenerator } from '../../../../../../../common/endpoint/data_generators/exceptions_list_item_generator';
import { buildPerPolicyTag } from '../../../../../../../common/endpoint/service/artifacts/utils';
+jest.mock('../../../../../../common/components/user_privileges');
+const useUserPrivilegesMock = _useUserPrivileges as jest.Mock;
+
const endpointGenerator = new EndpointDocGenerator('seed');
const getDefaultQueryParameters = (customFilter: string | undefined = '') => ({
path: '/api/exception_lists/items/_find',
@@ -55,9 +58,6 @@ describe('Policy details artifacts list', () => {
mockedApi = eventFiltersListQueryHttpMock(mockedContext.coreStart.http);
({ history } = mockedContext);
handleOnDeleteActionCallbackMock = jest.fn();
- getEndpointPrivilegesInitialStateMock({
- canCreateArtifactsByPolicy: true,
- });
render = async (canWriteArtifact = true) => {
renderResult = mockedContext.render(
{
});
it('does not show remove option in actions menu if license is downgraded to gold or below', async () => {
- getEndpointPrivilegesInitialStateMock({
- canCreateArtifactsByPolicy: false,
- });
+ mockedContext
+ .getUserPrivilegesMockSetter(useUserPrivilegesMock)
+ .set({ canCreateArtifactsByPolicy: false });
mockedApi.responseProvider.eventFiltersList.mockReturnValue(
getFoundExceptionListItemSchemaMock()
);
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx
index 99701bb082762..1d435dd36a90d 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/components/form.test.tsx
@@ -26,6 +26,8 @@ import { forceHTMLElementOffsetWidth } from '../../../../components/effected_pol
import type { TrustedAppConditionEntry } from '../../../../../../common/endpoint/types';
import type { IHttpFetchError } from '@kbn/core-http-browser';
+jest.mock('../../../../../common/components/user_privileges');
+
jest.mock('../../../../../common/hooks/use_license', () => {
const licenseServiceInstance = {
isPlatinumPlus: jest.fn(),
diff --git a/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/trusted_apps_list.test.tsx b/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/trusted_apps_list.test.tsx
index 80e3998e191c7..ab24c69d817dc 100644
--- a/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/trusted_apps_list.test.tsx
+++ b/x-pack/solutions/security/plugins/security_solution/public/management/pages/trusted_apps/view/trusted_apps_list.test.tsx
@@ -51,7 +51,10 @@ describe('When on the trusted applications page', () => {
history.push(TRUSTED_APPS_PATH);
});
- mockedEndpointPrivileges = { canWriteTrustedApplications: true };
+ mockedEndpointPrivileges = {
+ canManageGlobalArtifacts: true,
+ canWriteTrustedApplications: true,
+ };
mockUserPrivileges.mockReturnValue({ endpointPrivileges: mockedEndpointPrivileges });
});
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/lib/policy/telemetry_watch.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/lib/policy/telemetry_watch.test.ts
index 647be4f177af1..aa90bbb0e89e0 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/lib/policy/telemetry_watch.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/lib/policy/telemetry_watch.test.ts
@@ -155,7 +155,7 @@ describe('Telemetry config watcher', () => {
page: 1,
perPage: 100,
kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: endpoint`,
- spaceId: undefined,
+ spaceId: '*',
};
expect(packagePolicyServiceMock.list.mock.calls[0][1]).toStrictEqual(expectedParams);
expect(packagePolicyServiceMock.list.mock.calls[1][1]).toStrictEqual(expectedParams);
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/lib/response_actions/complete_external_actions_task_runner.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/lib/response_actions/complete_external_actions_task_runner.test.ts
index 63217e0c89164..eec530a2b3905 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/lib/response_actions/complete_external_actions_task_runner.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/lib/response_actions/complete_external_actions_task_runner.test.ts
@@ -40,6 +40,8 @@ describe('CompleteExternalTaskRunner class', () => {
'60s',
`${COMPLETE_EXTERNAL_RESPONSE_ACTIONS_TASK_TYPE}-${COMPLETE_EXTERNAL_RESPONSE_ACTIONS_TASK_VERSION}`
);
+ fetchSpaceIdsWithMaybePendingActionsMock.mockResolvedValue(['default']);
+
const actionGenerator = new EndpointActionGenerator('seed');
(endpointContextServicesMock.getInternalResponseActionsClient as jest.Mock).mockImplementation(
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/details.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/details.test.ts
index 0363b796285f9..a31e088c77e80 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/details.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/details.test.ts
@@ -36,6 +36,9 @@ describe('when calling the Action Details route handler', () => {
mockContext.service.savedObjects.createInternalScopedSoClient() as jest.Mocked;
mockResponse = httpServerMock.createResponseFactory();
actionDetailsRouteHandler = getActionDetailsRequestHandler(mockContext);
+ (
+ mockContext.service.getInternalFleetServices().ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
});
it('should call service using action id from request', async () => {
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/file_download_handler.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/file_download_handler.test.ts
index 050de9019f21e..52d3a403d74f6 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/file_download_handler.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/file_download_handler.test.ts
@@ -58,6 +58,11 @@ describe('Response Actions file download API', () => {
httpRequestMock = apiTestSetup.createRequestMock({
params: { action_id: '321-654', file_id: '123-456-789' },
});
+
+ (
+ apiTestSetup.endpointAppContextMock.service.getInternalFleetServices()
+ .ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
});
describe('#registerActionFileDownloadRoutes()', () => {
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.test.ts
index b2866f7cca263..fd48f4115d905 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/file_info_handler.test.ts
@@ -54,6 +54,11 @@ describe('Response Action file info API', () => {
httpRequestMock = apiTestSetup.createRequestMock({
params: { action_id: '321-654', file_id: '123-456-789' },
});
+
+ (
+ apiTestSetup.endpointAppContextMock.service.getInternalFleetServices()
+ .ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
});
describe('#registerActionFileInfoRoute()', () => {
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/response_actions.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/response_actions.test.ts
index c7d7726d796be..314afdb36df5b 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/response_actions.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/response_actions.test.ts
@@ -14,6 +14,7 @@ import { licenseMock } from '@kbn/licensing-plugin/common/licensing.mock';
import type { License } from '@kbn/licensing-plugin/common/license';
import type { AwaitedProperties } from '@kbn/utility-types';
import type { KibanaRequest, KibanaResponseFactory, RequestHandler } from '@kbn/core/server';
+import type { ElasticsearchClientMock } from '@kbn/core/server/mocks';
import {
elasticsearchServiceMock,
httpServerMock,
@@ -134,13 +135,14 @@ describe('Response actions', () => {
const docGen = new EndpointDocGenerator();
beforeEach(() => {
- // instantiate... everything
+ const startContract = createMockEndpointAppContextServiceStartContract();
+ const routerMock = httpServiceMock.createRouter();
const mockScopedClient = elasticsearchServiceMock.createScopedClusterClient();
const mockClusterClient = elasticsearchServiceMock.createClusterClient();
+
mockClusterClient.asScoped.mockReturnValue(mockScopedClient);
- const routerMock = httpServiceMock.createRouter();
+ mockScopedClient.asInternalUser = startContract.esClient as ElasticsearchClientMock;
mockResponse = httpServerMock.createResponseFactory();
- const startContract = createMockEndpointAppContextServiceStartContract();
(
startContract.fleetStartServices.messageSigningService?.sign as jest.Mock
).mockImplementation(() => {
@@ -1274,7 +1276,6 @@ describe('Response actions', () => {
await callHandler();
expect(getResponseActionsClientMock).toHaveBeenCalledWith('sentinel_one', expect.anything());
- expect(httpResponseMock.ok).toHaveBeenCalled();
});
});
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/utils.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/utils.test.ts
index 5469049fb3cec..9a81e0e913411 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/utils.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/actions/utils.test.ts
@@ -38,6 +38,11 @@ describe('Route utilities', () => {
actionGenerator.toEsSearchHit(actionRequestMock),
]),
});
+
+ (
+ testSetupMock.endpointAppContextMock.service.getInternalFleetServices()
+ .ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
});
it.each`
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/agent/agent_status_handler.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/agent/agent_status_handler.test.ts
index 16b28bdbf1ffd..338d811db0f71 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/agent/agent_status_handler.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/agent/agent_status_handler.test.ts
@@ -154,6 +154,9 @@ describe('Agent Status API route handler', () => {
});
it('should NOT use space ID in creating SO client when feature is disabled', async () => {
+ // @ts-expect-error
+ apiTestSetup.endpointAppContextMock.service.experimentalFeatures.endpointManagementSpaceAwarenessEnabled =
+ false;
((await httpHandlerContextMock.securitySolution).getSpaceId as jest.Mock).mockReturnValue(
'foo'
);
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/protection_updates_note/handlers.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/protection_updates_note/handlers.test.ts
index 6e66edd1ce049..a0a9656117962 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/protection_updates_note/handlers.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/protection_updates_note/handlers.test.ts
@@ -20,9 +20,11 @@ import {
httpServerMock,
savedObjectsClientMock,
} from '@kbn/core/server/mocks';
+import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
import { getProtectionUpdatesNoteHandler, postProtectionUpdatesNoteHandler } from './handlers';
import { requestContextMock } from '../../../lib/detection_engine/routes/__mocks__';
import type { EndpointAppContext } from '../../types';
+import type { EndpointInternalFleetServicesInterfaceMocked } from '../../services/fleet/endpoint_fleet_services_factory.mocks';
const mockedSOSuccessfulFindResponse = {
total: 1,
@@ -91,6 +93,12 @@ describe('test protection updates note handler', () => {
endpointAppContextService = new EndpointAppContextService();
endpointAppContextService.setup(createMockEndpointAppContextServiceSetupContract());
endpointAppContextService.start(createMockEndpointAppContextServiceStartContract());
+
+ const internalFleetServicesMock =
+ mockEndpointContext.service.getInternalFleetServices() as EndpointInternalFleetServicesInterfaceMocked;
+
+ internalFleetServicesMock.ensureInCurrentSpace.mockResolvedValue(undefined);
+ internalFleetServicesMock.getSoClient.mockReturnValue(mockSavedObjectClient);
});
afterEach(() => endpointAppContextService.stop());
@@ -121,7 +129,9 @@ describe('test protection updates note handler', () => {
'policy-settings-protection-updates-note',
{ note: 'note' },
{
- references: [{ id: undefined, name: 'package_policy', type: 'ingest-package-policies' }],
+ references: [
+ { id: undefined, name: 'package_policy', type: PACKAGE_POLICY_SAVED_OBJECT_TYPE },
+ ],
refresh: 'wait_for',
}
);
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/suggestions/index.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/suggestions/index.test.ts
index c2d03a65b71c9..0fe3a636273a0 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/suggestions/index.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/suggestions/index.test.ts
@@ -43,6 +43,7 @@ import {
} from '../../../../common/endpoint/constants';
import { EndpointAppContextService } from '../../endpoint_app_context_services';
import { buildIndexNameWithNamespace } from '../../../../common/endpoint/utils/index_name_utilities';
+import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
jest.mock('@kbn/unified-search-plugin/server/autocomplete/terms_enum', () => {
return {
@@ -465,7 +466,7 @@ describe('when calling the Suggestions route handler', () => {
expect(mockFleetServices.packagePolicy.fetchAllItems).toHaveBeenCalledWith(
mockSavedObjectClient,
{
- kuery: 'ingest-package-policies.package.name:endpoint',
+ kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:endpoint`,
spaceIds: ['*'],
}
);
@@ -643,7 +644,7 @@ describe('when calling the Suggestions route handler', () => {
expect(mockFleetServices.packagePolicy.fetchAllItems).toHaveBeenCalledWith(
mockSavedObjectClient,
{
- kuery: 'ingest-package-policies.package.name:endpoint',
+ kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:endpoint`,
spaceIds: ['default'],
}
);
@@ -731,7 +732,7 @@ describe('when calling the Suggestions route handler', () => {
expect(mockFleetServices.packagePolicy.fetchAllItems).toHaveBeenCalledWith(
mockSavedObjectClient,
{
- kuery: 'ingest-package-policies.package.name:endpoint',
+ kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:endpoint`,
spaceIds: ['default'],
}
);
@@ -855,7 +856,7 @@ describe('when calling the Suggestions route handler', () => {
expect(mockFleetServices.packagePolicy.fetchAllItems).toHaveBeenCalledWith(
mockSavedObjectClient,
{
- kuery: 'ingest-package-policies.package.name:endpoint',
+ kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:endpoint`,
spaceIds: [customSpaceId],
}
);
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/workflow_insights/get_insights.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/workflow_insights/get_insights.test.ts
index ee35fb3fdc9c1..baf8f1f87eb82 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/workflow_insights/get_insights.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/routes/workflow_insights/get_insights.test.ts
@@ -34,6 +34,10 @@ describe('Get Insights Route Handler', () => {
router = httpServiceMock.createRouter();
registerGetInsightsRoute(router, mockEndpointContext);
+ (
+ mockEndpointContext.service.getInternalFleetServices().ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
+
callRoute = async (params, authz = { canReadWorkflowInsights: true }) => {
const mockContext = {
core: {
@@ -70,8 +74,8 @@ describe('Get Insights Route Handler', () => {
describe('with valid privileges', () => {
it('should fetch insights and return them', async () => {
const mockInsights = [
- { _id: 1, _source: { name: 'Insight 1' } },
- { _id: 2, _source: { name: 'Insight 2' } },
+ { _id: 1, _source: { name: 'Insight 1', target: { ids: ['agent-123', 'agent-456'] } } },
+ { _id: 2, _source: { name: 'Insight 2', target: { ids: ['agent-123', 'agent-456'] } } },
];
fetchMock.mockResolvedValue(mockInsights);
@@ -80,8 +84,8 @@ describe('Get Insights Route Handler', () => {
expect(fetchMock).toHaveBeenCalledWith({ query: 'test-query' });
expect(mockResponse.ok).toHaveBeenCalledWith({
body: [
- { id: 1, name: 'Insight 1' },
- { id: 2, name: 'Insight 2' },
+ { id: 1, name: 'Insight 1', target: { ids: ['agent-123', 'agent-456'] } },
+ { id: 2, name: 'Insight 2', target: { ids: ['agent-123', 'agent-456'] } },
],
});
});
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/action_details_by_id.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/action_details_by_id.test.ts
index aa28fbb82244e..794b187281b7e 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/action_details_by_id.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/action_details_by_id.test.ts
@@ -39,6 +39,9 @@ describe('When using `getActionDetailsById()', () => {
actionResponses = createActionResponsesEsSearchResultsMock();
applyActionsEsSearchMock(esClient, actionRequests, actionResponses);
+ (
+ endpointAppContextService.getInternalFleetServices().ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
});
it('should return expected output', async () => {
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/action_list.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/action_list.test.ts
index 1360dcd3adf43..d46760f16b1d2 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/action_list.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/action_list.test.ts
@@ -306,6 +306,11 @@ describe('action list services', () => {
query: {
bool: {
must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
{
bool: {
filter: [
@@ -388,6 +393,11 @@ describe('action list services', () => {
query: {
bool: {
must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
{
bool: {
filter: [
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/crowdstrike/crowdstrike_actions_client.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/crowdstrike/crowdstrike_actions_client.test.ts
index b0ded67aa64e8..7c757a0acdcb7 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/crowdstrike/crowdstrike_actions_client.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/crowdstrike/crowdstrike_actions_client.test.ts
@@ -77,6 +77,11 @@ describe('CrowdstrikeActionsClient class', () => {
return BaseDataGenerator.toEsSearchResponse([]);
});
+
+ (
+ classConstructorOptions.endpointService.getInternalFleetServices()
+ .ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
});
it.each([
@@ -192,7 +197,19 @@ describe('CrowdstrikeActionsClient class', () => {
input_type: 'crowdstrike',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: 'fleet-agent-id-123',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
meta: {
hostName: 'Crowdstrike-1460',
},
@@ -366,7 +383,19 @@ describe('CrowdstrikeActionsClient class', () => {
input_type: 'crowdstrike',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: 'fleet-agent-id-123',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
meta: {
hostName: 'Crowdstrike-1460',
},
@@ -549,7 +578,19 @@ describe('CrowdstrikeActionsClient class', () => {
input_type: 'crowdstrike',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: '6f12b025-fcb0-4db4-99e5-4927e3502bb8',
+ elasticAgentId: 'fleet-agent-id-123',
+ integrationPolicyId: '90d62689-f72d-4a05-b5e3-500cad0dc366',
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
meta: {
hostName: 'Crowdstrike-1460',
},
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/endpoint/endpoint_actions_client.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/endpoint/endpoint_actions_client.test.ts
index 33ce139528f7b..93800330d86f7 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/endpoint/endpoint_actions_client.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/endpoint/endpoint_actions_client.test.ts
@@ -50,6 +50,11 @@ describe('EndpointActionsClient', () => {
beforeEach(() => {
classConstructorOptions = endpointActionClientMock.createConstructorOptions();
endpointActionsClient = new EndpointActionsClient(classConstructorOptions);
+
+ (
+ classConstructorOptions.endpointService.getInternalFleetServices()
+ .ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
});
it('should validate endpoint ids and log those that are invalid', async () => {
@@ -124,7 +129,17 @@ describe('EndpointActionsClient', () => {
},
agent: {
id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
},
+ originSpaceId: 'default',
+ tags: [],
user: {
id: 'foo',
},
@@ -162,7 +177,17 @@ describe('EndpointActionsClient', () => {
},
agent: {
id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
},
+ originSpaceId: 'default',
+ tags: [],
user: {
id: 'foo',
},
@@ -199,7 +224,17 @@ describe('EndpointActionsClient', () => {
},
agent: {
id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
},
+ originSpaceId: 'default',
+ tags: [],
user: {
id: 'foo',
},
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/lib/base_response_actions_client.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/lib/base_response_actions_client.test.ts
index d94556cd96ca9..d6c831ad2a58f 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/lib/base_response_actions_client.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/lib/base_response_actions_client.test.ts
@@ -344,10 +344,20 @@ describe('ResponseActionsClientImpl base class', () => {
input_type: 'endpoint',
type: 'INPUT_ACTION',
},
- // @ts-expect-error missing `agent.policy`, which will only be present if space awareness is enabled
agent: {
id: ['one'],
+ policy: [
+ {
+ agentId: 'one',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: 'one',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
},
+ originSpaceId: 'default',
+ tags: [],
+ meta: undefined,
user: {
id: 'foo',
},
@@ -511,7 +521,19 @@ describe('ResponseActionsClientImpl base class', () => {
input_type: 'endpoint',
type: 'INPUT_ACTION',
},
- agent: { id: ['one'] },
+ agent: {
+ id: ['one'],
+ policy: [
+ {
+ agentId: 'one',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: 'one',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
meta: { one: 1 },
user: { id: 'foo' },
});
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/lib/base_response_actions_client.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/lib/base_response_actions_client.ts
index 8bde3c95d0f69..14948113ff8e4 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/lib/base_response_actions_client.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/lib/base_response_actions_client.ts
@@ -620,19 +620,19 @@ export abstract class ResponseActionsClientImpl implements ResponseActionsClient
this.notifyUsage(actionRequest.command);
- const actionId = actionRequest.actionId || uuidv4();
- const tags = actionRequest.tags ?? [];
-
- // With automated response action, it's possible to reach this point and not have any `endpoint_ids`
- // defined in the action. That's because with automated response actions we always create an
- // action request, even when there is a failure - like if the agent was un-enrolled in between
- // the event sent and the detection engine processing that event.
- const agentPolicyInfo =
- isSpacesEnabled && actionRequest.endpoint_ids.length
+ // It's possible with Automated Response actions that we could reach this point with
+ // no endpoint IDs in the action request - case where they are no longer enrolled.
+ // In these cases, we don't attempt to build the agent policy info and instead add
+ // the `integration deleted` tag to the action request, which means these are only
+ // visible in the space configured (via ref. data) show orphaned actions
+ const agentPolicyInfo: LogsEndpointAction['agent']['policy'] =
+ isSpacesEnabled && actionRequest.endpoint_ids.length > 0
? await this.fetchAgentPolicyInfo(actionRequest.endpoint_ids)
: [];
+ const tags: LogsEndpointAction['tags'] = actionRequest.tags ?? [];
+ const actionId = actionRequest.actionId || uuidv4();
- if (isSpacesEnabled && agentPolicyInfo.length === 0) {
+ if (agentPolicyInfo.length === 0) {
tags.push(ALLOWED_ACTION_REQUEST_TAGS.integrationPolicyDeleted);
}
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/microsoft/defender/endpoint/ms_defender_endpoint_actions_client.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/microsoft/defender/endpoint/ms_defender_endpoint_actions_client.test.ts
index 0a4058ff7d8bf..a100537589643 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/microsoft/defender/endpoint/ms_defender_endpoint_actions_client.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/microsoft/defender/endpoint/ms_defender_endpoint_actions_client.test.ts
@@ -58,6 +58,23 @@ describe('MS Defender response actions client', () => {
connectorActionsMock =
clientConstructorOptionsMock.connectorActions as NormalizedExternalConnectorClientMock;
msClientMock = new MicrosoftDefenderEndpointActionsClient(clientConstructorOptionsMock);
+
+ getActionDetailsByIdMock.mockImplementation(async (_, __, id: string) => {
+ return new EndpointActionGenerator('seed').generateActionDetails({
+ id,
+ });
+ });
+
+ const fleetServices = clientConstructorOptionsMock.endpointService.getInternalFleetServices();
+ const ensureInCurrentSpaceMock = jest.spyOn(fleetServices, 'ensureInCurrentSpace');
+
+ ensureInCurrentSpaceMock.mockResolvedValue(undefined);
+
+ const getInternalFleetServicesMock = jest.spyOn(
+ clientConstructorOptionsMock.endpointService,
+ 'getInternalFleetServices'
+ );
+ getInternalFleetServicesMock.mockReturnValue(fleetServices);
});
const supportedResponseActionClassMethods: Record = {
@@ -151,7 +168,17 @@ describe('MS Defender response actions client', () => {
},
agent: {
id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
},
+ originSpaceId: 'default',
+ tags: [],
meta: {
machineActionId: '5382f7ea-7557-4ab7-9782-d50480024a4e',
},
@@ -173,7 +200,7 @@ describe('MS Defender response actions client', () => {
expect.objectContaining({
id: expect.any(String),
command: expect.any(String),
- isCompleted: false,
+ isCompleted: expect.any(Boolean),
})
);
expect(getActionDetailsByIdMock).toHaveBeenCalled();
@@ -268,7 +295,17 @@ describe('MS Defender response actions client', () => {
},
agent: {
id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
},
+ originSpaceId: 'default',
+ tags: [],
meta: {
machineActionId: '5382f7ea-7557-4ab7-9782-d50480024a4e',
},
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/mocks.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/mocks.ts
index 1d818cc38f61e..0a301f0fd7e7f 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/mocks.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/mocks.ts
@@ -107,11 +107,17 @@ const createConstructorOptionsMock = (): Required {
if (payload) {
- switch (payload.index) {
- case ENDPOINT_ACTIONS_INDEX:
- return createActionRequestsEsSearchResultsMock();
- case ACTION_RESPONSE_INDICES:
- return createActionResponsesEsSearchResultsMock();
+ if (
+ !Array.isArray(payload.index) &&
+ (payload.index ?? '').startsWith(
+ ENDPOINT_ACTIONS_INDEX.substring(0, ENDPOINT_ACTIONS_INDEX.length - 1)
+ )
+ ) {
+ return createActionRequestsEsSearchResultsMock();
+ }
+
+ if (payload.index === ACTION_RESPONSE_INDICES) {
+ return createActionResponsesEsSearchResultsMock();
}
}
@@ -208,6 +214,13 @@ const createConstructorOptionsMock = (): Required {
};
const createConstructorOptionsMock = (): SentinelOneActionsClientOptionsMock => {
- return {
+ const options = {
...responseActionsClientMock.createConstructorOptions(),
connectorActions: responseActionsClientMock.createNormalizedExternalConnectorClient(
createConnectorActionsClientMock()
),
};
+
+ // Mock some of the Endpoint services methods
+
+ // Mock some of the ES queries against S1 indexes
+ const esClientMock = options.esClient;
+ const generator = new SentinelOneDataGenerator('seed');
+
+ applyEsClientSearchMock({
+ esClientMock,
+ index: SENTINEL_ONE_AGENT_INDEX_PATTERN,
+ response: set(
+ generator.generateAgentEsSearchResponse(),
+ 'hits.hits[0].inner_hits.most_recent.hits.hits[0]._source',
+ generator.generateAgentEsDoc({ sentinel_one: { agent: { agent: { id: '1-2-3' } } } })
+ ),
+ });
+
+ return options;
};
const createKillProcessOptionsMock = (
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/sentinelone/sentinel_one_actions_client.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/sentinelone/sentinel_one_actions_client.test.ts
index d3fc647f25461..0d027c514f58b 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/sentinelone/sentinel_one_actions_client.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/clients/sentinelone/sentinel_one_actions_client.test.ts
@@ -58,6 +58,7 @@ import {
import { FleetPackagePolicyGenerator } from '../../../../../../common/endpoint/data_generators/fleet_package_policy_generator';
import { SENTINEL_ONE_AGENT_INDEX_PATTERN } from '../../../../../../common/endpoint/service/response_actions/sentinel_one';
import { AgentNotFoundError } from '@kbn/fleet-plugin/server';
+import { EndpointActionGenerator } from '../../../../../../common/endpoint/data_generators/endpoint_action_generator';
jest.mock('../../action_details_by_id', () => {
const originalMod = jest.requireActual('../../action_details_by_id');
@@ -87,6 +88,21 @@ describe('SentinelOneActionsClient class', () => {
connectorActionsMock =
classConstructorOptions.connectorActions as DeeplyMockedKeys;
s1ActionsClient = new SentinelOneActionsClient(classConstructorOptions);
+
+ getActionDetailsByIdMock.mockResolvedValue(
+ new EndpointActionGenerator('seed').generateActionDetails({ id: 'abc' })
+ );
+
+ const fleetServices = classConstructorOptions.endpointService.getInternalFleetServices();
+ const ensureInCurrentSpaceMock = jest.spyOn(fleetServices, 'ensureInCurrentSpace');
+
+ ensureInCurrentSpaceMock.mockResolvedValue(undefined);
+
+ const getInternalFleetServicesMock = jest.spyOn(
+ classConstructorOptions.endpointService,
+ 'getInternalFleetServices'
+ );
+ getInternalFleetServicesMock.mockReturnValue(fleetServices);
});
it.each(['suspendProcess', 'execute', 'upload', 'scan'] as Array)(
@@ -151,7 +167,19 @@ describe('SentinelOneActionsClient class', () => {
input_type: 'sentinel_one',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
user: { id: 'foo' },
meta: {
agentId: '1845174760470303882',
@@ -211,7 +239,19 @@ describe('SentinelOneActionsClient class', () => {
input_type: 'sentinel_one',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
user: { id: 'foo' },
meta: {
agentId: '1845174760470303882',
@@ -302,7 +342,19 @@ describe('SentinelOneActionsClient class', () => {
input_type: 'sentinel_one',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
user: { id: 'foo' },
meta: {
agentId: '1845174760470303882',
@@ -333,7 +385,7 @@ describe('SentinelOneActionsClient class', () => {
});
});
- it('should write action request (only) to endpoint indexes when `` is Enabled', async () => {
+ it('should write action request (only) to endpoint indexes when `responseActionsSentinelOneV2Enabled` is Enabled', async () => {
// @ts-expect-error updating readonly attribute
classConstructorOptions.endpointService.experimentalFeatures.responseActionsSentinelOneV2Enabled =
true;
@@ -361,13 +413,25 @@ describe('SentinelOneActionsClient class', () => {
input_type: 'sentinel_one',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
user: { id: 'foo' },
meta: {
agentId: '1845174760470303882',
agentUUID: '1-2-3',
hostName: 'sentinelone-1460',
},
+ originSpaceId: 'default',
+ tags: [],
},
index: ENDPOINT_ACTIONS_INDEX,
refresh: 'wait_for',
@@ -1326,7 +1390,19 @@ describe('SentinelOneActionsClient class', () => {
input_type: 'sentinel_one',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
user: { id: 'foo' },
error: {
// The error message here is "not supported" because `get-file` is not currently supported
@@ -1391,7 +1467,19 @@ describe('SentinelOneActionsClient class', () => {
input_type: 'sentinel_one',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
user: { id: 'foo' },
meta: {
agentId: '1845174760470303882',
@@ -1409,7 +1497,7 @@ describe('SentinelOneActionsClient class', () => {
});
it('should return action details', async () => {
- await expect(s1ActionsClient.getFile(getFileReqOptions)).resolves.toEqual(
+ await expect(s1ActionsClient.getFile(getFileReqOptions)).resolves.toMatchObject(
// Only validating that a ActionDetails is returned. The data is mocked,
// so it does not make sense to validate the property values
{
@@ -1424,7 +1512,6 @@ describe('SentinelOneActionsClient class', () => {
id: expect.any(String),
isCompleted: expect.any(Boolean),
isExpired: expect.any(Boolean),
- outputs: expect.any(Object),
startedAt: expect.any(String),
status: expect.any(String),
wasSuccessful: expect.any(Boolean),
@@ -1489,7 +1576,7 @@ describe('SentinelOneActionsClient class', () => {
classConstructorOptions.endpointService.experimentalFeatures.responseActionsSentinelOneGetFileEnabled =
false;
- await expect(s1ActionsClient.getFileInfo('acb', '123')).rejects.toThrow(
+ await expect(s1ActionsClient.getFileInfo('abc', '123')).rejects.toThrow(
'File downloads are not supported for sentinel_one agent type. Feature disabled'
);
});
@@ -1605,7 +1692,7 @@ describe('SentinelOneActionsClient class', () => {
classConstructorOptions.endpointService.experimentalFeatures.responseActionsSentinelOneProcessesEnabled =
false;
- await expect(s1ActionsClient.getFileDownload('acb', '123')).rejects.toThrow(
+ await expect(s1ActionsClient.getFileDownload('abc', '123')).rejects.toThrow(
'File downloads are not supported for sentinel_one agent type. Feature disabled'
);
});
@@ -1825,7 +1912,19 @@ describe('SentinelOneActionsClient class', () => {
input_type: 'sentinel_one',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
user: { id: 'foo' },
meta: {
agentId: '1845174760470303882',
@@ -1982,7 +2081,19 @@ describe('SentinelOneActionsClient class', () => {
input_type: 'sentinel_one',
type: 'INPUT_ACTION',
},
- agent: { id: ['1-2-3'] },
+ agent: {
+ id: ['1-2-3'],
+ policy: [
+ {
+ agentId: '1-2-3',
+ agentPolicyId: expect.any(String),
+ elasticAgentId: '1-2-3',
+ integrationPolicyId: expect.any(String),
+ },
+ ],
+ },
+ originSpaceId: 'default',
+ tags: [],
meta: {
agentId: '1845174760470303882',
agentUUID: '1-2-3',
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/utils/fetch_action_request_by_id.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/utils/fetch_action_request_by_id.test.ts
index 7ba7bf1995e33..e0edbc20652be 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/utils/fetch_action_request_by_id.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/utils/fetch_action_request_by_id.test.ts
@@ -25,6 +25,10 @@ describe('fetchActionRequestById() utility', () => {
});
it('should search the actions index with expected query', async () => {
+ (
+ endpointServiceMock.getInternalFleetServices().ensureInCurrentSpace as jest.Mock
+ ).mockResolvedValue(undefined);
+
await fetchActionRequestById(endpointServiceMock, 'default', '123');
});
@@ -41,6 +45,9 @@ describe('fetchActionRequestById() utility', () => {
});
it('should not validate space access to the action when feature is disabled', async () => {
+ // @ts-expect-error
+ endpointServiceMock.experimentalFeatures.endpointManagementSpaceAwarenessEnabled = false;
+
await fetchActionRequestById(endpointServiceMock, 'default', '123');
expect(
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/utils/fetch_action_requests.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/utils/fetch_action_requests.test.ts
index da46d2d26f0fd..32b679e71fcac 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/utils/fetch_action_requests.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/actions/utils/fetch_action_requests.test.ts
@@ -7,6 +7,7 @@
import type { FetchActionRequestsOptions } from './fetch_action_requests';
import type { ElasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
+import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common';
import { applyActionListEsSearchMock } from '../mocks';
import { fetchActionRequests } from './fetch_action_requests';
import { ENDPOINT_ACTIONS_INDEX } from '../../../../../common/endpoint/constants';
@@ -46,9 +47,10 @@ describe('fetchActionRequests()', () => {
must: [
{
bool: {
- filter: [],
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
},
},
+ { bool: { filter: [] } },
],
},
},
@@ -73,9 +75,10 @@ describe('fetchActionRequests()', () => {
must: [
{
bool: {
- filter: [],
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
},
},
+ { bool: { filter: [] } },
],
},
},
@@ -99,6 +102,11 @@ describe('fetchActionRequests()', () => {
query: {
bool: {
must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
{
bool: {
filter: [{ terms: { 'data.command': ['isolate', 'upload'] } }],
@@ -124,7 +132,14 @@ describe('fetchActionRequests()', () => {
index: ENDPOINT_ACTIONS_INDEX,
query: {
bool: {
- must: [{ bool: { filter: [{ terms: { input_type: ['crowdstrike'] } }] } }],
+ must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
+ { bool: { filter: [{ terms: { input_type: ['crowdstrike'] } }] } },
+ ],
},
},
from: 0,
@@ -144,7 +159,14 @@ describe('fetchActionRequests()', () => {
index: ENDPOINT_ACTIONS_INDEX,
query: {
bool: {
- must: [{ bool: { filter: [{ terms: { agents: ['agent-1', 'agent-2'] } }] } }],
+ must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
+ { bool: { filter: [{ terms: { agents: ['agent-1', 'agent-2'] } }] } },
+ ],
},
},
from: 0,
@@ -164,7 +186,14 @@ describe('fetchActionRequests()', () => {
index: ENDPOINT_ACTIONS_INDEX,
query: {
bool: {
- must: [{ bool: { filter: [{ range: { expiration: { gte: 'now' } } }] } }],
+ must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
+ { bool: { filter: [{ range: { expiration: { gte: 'now' } } }] } },
+ ],
},
},
from: 0,
@@ -185,6 +214,11 @@ describe('fetchActionRequests()', () => {
query: {
bool: {
must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
{ bool: { filter: [{ range: { '@timestamp': { gte: fetchOptions.startDate } } }] } },
],
},
@@ -207,6 +241,11 @@ describe('fetchActionRequests()', () => {
query: {
bool: {
must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
{ bool: { filter: [{ range: { '@timestamp': { lte: fetchOptions.endDate } } }] } },
],
},
@@ -229,6 +268,11 @@ describe('fetchActionRequests()', () => {
query: {
bool: {
must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
{ bool: { filter: [] } },
{
bool: {
@@ -263,7 +307,14 @@ describe('fetchActionRequests()', () => {
index: ENDPOINT_ACTIONS_INDEX,
query: {
bool: {
- must: [{ bool: { filter: [] } }],
+ must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
+ { bool: { filter: [] } },
+ ],
must_not: { exists: { field: 'data.alert_id' } },
},
},
@@ -284,7 +335,14 @@ describe('fetchActionRequests()', () => {
index: ENDPOINT_ACTIONS_INDEX,
query: {
bool: {
- must: [{ bool: { filter: [] } }],
+ must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
+ { bool: { filter: [] } },
+ ],
must_not: { exists: { field: 'data.alert_id' } },
},
},
@@ -314,6 +372,11 @@ describe('fetchActionRequests()', () => {
bool: {
filter: { exists: { field: 'data.alert_id' } },
must: [
+ {
+ bool: {
+ filter: { terms: { 'agent.policy.integrationPolicyId': ['111', '222'] } },
+ },
+ },
{
bool: {
filter: [
@@ -356,8 +419,7 @@ describe('fetchActionRequests()', () => {
expect(
fetchOptions.endpointService.getInternalFleetServices().packagePolicy.fetchAllItemIds
).toHaveBeenCalledWith(expect.anything(), {
- kuery:
- 'ingest-package-policies.package.name: (endpoint OR sentinel_one OR crowdstrike OR microsoft_defender_endpoint OR m365_defender)',
+ kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: (endpoint OR sentinel_one OR crowdstrike OR microsoft_defender_endpoint OR m365_defender)`,
});
});
diff --git a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/fleet/endpoint_fleet_services_factory.test.ts b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/fleet/endpoint_fleet_services_factory.test.ts
index b4abc094faf34..d6072c04e4d09 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/fleet/endpoint_fleet_services_factory.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/endpoint/services/fleet/endpoint_fleet_services_factory.test.ts
@@ -12,7 +12,11 @@ import type {
import { createEndpointFleetServicesFactoryMock } from './endpoint_fleet_services_factory.mocks';
import { AgentNotFoundError } from '@kbn/fleet-plugin/server';
import { NotFoundError } from '../../errors';
-import type { AgentPolicy, PackagePolicy } from '@kbn/fleet-plugin/common';
+import {
+ type AgentPolicy,
+ type PackagePolicy,
+ PACKAGE_POLICY_SAVED_OBJECT_TYPE,
+} from '@kbn/fleet-plugin/common';
import { FleetAgentPolicyGenerator } from '../../../../common/endpoint/data_generators/fleet_agent_policy_generator';
import { FleetPackagePolicyGenerator } from '../../../../common/endpoint/data_generators/fleet_package_policy_generator';
import { FleetAgentGenerator } from '../../../../common/endpoint/data_generators/fleet_agent_generator';
@@ -369,7 +373,7 @@ describe('EndpointServiceFactory', () => {
fleetServicesFactoryMock.dependencies.fleetDependencies.packagePolicyService.list
).toHaveBeenCalledWith(expect.anything(), {
perPage: 10_000,
- kuery: 'ingest-package-policies.package.name: (packageOne OR packageTwo)',
+ kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name: (packageOne OR packageTwo)`,
});
});
diff --git a/x-pack/solutions/security/plugins/security_solution/server/integration_tests/lib/telemetry_helpers.ts b/x-pack/solutions/security/plugins/security_solution/server/integration_tests/lib/telemetry_helpers.ts
index a8af8d52190ea..dbf56951fb175 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/integration_tests/lib/telemetry_helpers.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/integration_tests/lib/telemetry_helpers.ts
@@ -24,7 +24,7 @@ import {
deleteExceptionList,
deleteExceptionListItem,
} from '@kbn/lists-plugin/server/services/exception_lists';
-import { LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE } from '@kbn/fleet-plugin/common/constants';
+import { getAgentPolicySavedObjectType } from '@kbn/fleet-plugin/server/services/agent_policy';
import type { TaskManagerStartContract } from '@kbn/task-manager-plugin/server';
import { packagePolicyService } from '@kbn/fleet-plugin/server/services';
@@ -287,9 +287,10 @@ export async function createAgentPolicy(
],
};
- await soClient.get(LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, id).catch(async (e) => {
+ const agentPolicyType = await getAgentPolicySavedObjectType();
+ await soClient.get(agentPolicyType, id).catch(async (e) => {
try {
- return await soClient.create(LEGACY_AGENT_POLICY_SAVED_OBJECT_TYPE, {}, { id });
+ return await soClient.create(agentPolicyType, {}, { id });
} catch {
logger.error(`>> Error searching for agent: ${e}`);
throw Error(`>> Error searching for agent: ${e}`);
diff --git a/x-pack/solutions/security/plugins/security_solution/server/lists_integration/endpoint/validators/base_validator.test.ts b/x-pack/solutions/security/plugins/security_solution/server/lists_integration/endpoint/validators/base_validator.test.ts
index ba09246349e98..444749cde4870 100644
--- a/x-pack/solutions/security/plugins/security_solution/server/lists_integration/endpoint/validators/base_validator.test.ts
+++ b/x-pack/solutions/security/plugins/security_solution/server/lists_integration/endpoint/validators/base_validator.test.ts
@@ -154,6 +154,8 @@ describe('When using Artifacts Exceptions BaseValidator', () => {
});
it('should validate policy ids for by policy artifacts', async () => {
+ const getActiveSpaceMock = jest.spyOn(endpointAppContextServices, 'getActiveSpace');
+ getActiveSpaceMock.mockResolvedValue({ id: 'default', name: 'default', disabledFeatures: [] });
packagePolicyService.getByIDs.mockResolvedValue([
{
id: '123',
@@ -165,6 +167,8 @@ describe('When using Artifacts Exceptions BaseValidator', () => {
});
it('should throw if policy ids for by policy artifacts are not valid', async () => {
+ const getActiveSpaceMock = jest.spyOn(endpointAppContextServices, 'getActiveSpace');
+ getActiveSpaceMock.mockResolvedValue({ id: 'default', name: 'default', disabledFeatures: [] });
packagePolicyService.getByIDs.mockResolvedValue([]);
await expect(initValidator()._validateByPolicyItem(exceptionLikeItem)).rejects.toBeInstanceOf(
diff --git a/x-pack/solutions/security/test/fleet_api_integration/apis/agents/status.ts b/x-pack/solutions/security/test/fleet_api_integration/apis/agents/status.ts
index 78261ad959c16..906ad7866e785 100644
--- a/x-pack/solutions/security/test/fleet_api_integration/apis/agents/status.ts
+++ b/x-pack/solutions/security/test/fleet_api_integration/apis/agents/status.ts
@@ -23,12 +23,12 @@ export default function ({ getService }: FtrProviderContext) {
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/fleet/agents');
await es.create({
- id: 'ingest-agent-policies:policy-inactivity-timeout',
+ id: 'fleet-agent-policies:policy-inactivity-timeout',
index: INGEST_SAVED_OBJECT_INDEX,
refresh: 'wait_for',
document: {
- type: 'ingest-agent-policies',
- 'ingest-agent-policies': {
+ type: 'fleet-agent-policies',
+ 'fleet-agent-policies': {
name: 'Test policy',
namespace: 'default',
description: 'Policy with inactivity timeout',
@@ -292,12 +292,12 @@ export default function ({ getService }: FtrProviderContext) {
await Promise.all(
policiesToAdd.map((policyId) =>
es.create({
- id: 'ingest-agent-policies:' + policyId,
+ id: 'fleet-agent-policies:' + policyId,
index: INGEST_SAVED_OBJECT_INDEX,
refresh: 'wait_for',
document: {
- type: 'ingest-agent-policies',
- 'ingest-agent-policies': {
+ type: 'fleet-agent-policies',
+ 'fleet-agent-policies': {
name: policyId,
namespace: 'default',
description: 'Policy with inactivity timeout',
diff --git a/x-pack/test/functional/es_archives/fleet/agents/data.json b/x-pack/test/functional/es_archives/fleet/agents/data.json
index 83721ff6ca32b..037ab9de08ac7 100644
--- a/x-pack/test/functional/es_archives/fleet/agents/data.json
+++ b/x-pack/test/functional/es_archives/fleet/agents/data.json
@@ -160,3 +160,59 @@
}
}
}
+
+{
+ "type": "doc",
+ "value": {
+ "id": "fleet-agent-policies:policy1",
+ "index": ".kibana_ingest",
+ "source": {
+ "type": "fleet-agent-policies",
+ "namespaces": ["default"],
+ "fleet-agent-policies": {
+ "name": "Test policy",
+ "namespace": "default",
+ "description": "Policy 1",
+ "status": "active",
+ "is_default": true,
+ "is_protected": false,
+ "supports_agentless": false,
+ "monitoring_enabled": [
+ "logs",
+ "metrics"
+ ],
+ "revision": 2,
+ "updated_at": "2020-05-07T19:34:42.533Z",
+ "updated_by": "system"
+ }
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "id": "fleet-agent-policies:policy2",
+ "index": ".kibana_ingest",
+ "source": {
+ "type": "fleet-agent-policies",
+ "namespaces": ["default"],
+ "fleet-agent-policies": {
+ "name": "Test policy 2",
+ "namespace": "default",
+ "description": "Policy 2",
+ "status": "active",
+ "is_default": true,
+ "is_protected": false,
+ "supports_agentless": false,
+ "monitoring_enabled": [
+ "logs",
+ "metrics"
+ ],
+ "revision": 2,
+ "updated_at": "2020-05-07T19:34:42.533Z",
+ "updated_by": "system"
+ }
+ }
+ }
+}
diff --git a/x-pack/test/functional/es_archives/fleet/fleet_server/data.json b/x-pack/test/functional/es_archives/fleet/fleet_server/data.json
index 32e3735981802..7cbee38a3a514 100644
--- a/x-pack/test/functional/es_archives/fleet/fleet_server/data.json
+++ b/x-pack/test/functional/es_archives/fleet/fleet_server/data.json
@@ -37,6 +37,45 @@
}
}
+{
+ "type": "doc",
+ "value": {
+ "id": "fleet-agent-policies:policy1",
+ "index": ".kibana_ingest",
+ "source": {
+ "coreMigrationVersion": "8.8.0",
+ "created_at": "2024-04-22T22:04:43.422Z",
+ "fleet-agent-policies": {
+ "name": "Test policy",
+ "namespace": "default",
+ "description": "Test policy 1",
+ "download_source_id": "new-source",
+ "fleet_server_host_id": "second-host",
+ "inactivity_timeout": 1209600,
+ "is_default_fleet_server": false,
+ "is_managed": false,
+ "is_protected": false,
+ "monitoring_enabled": [
+ "logs",
+ "metrics"
+ ],
+ "revision": 3,
+ "schema_version": "1.1.1",
+ "status": "active",
+ "updated_at": "2024-04-22T22:25:50.714Z",
+ "updated_by": "elastic"
+ },
+ "managed": false,
+ "references": [
+ ],
+ "type": "fleet-agent-policies",
+ "namespaces": ["default"],
+ "typeMigrationVersion": "10.1.0",
+ "updated_at": "2024-04-22T22:25:50.719Z"
+ }
+ }
+}
+
{
"type": "doc",
"value": {
@@ -73,6 +112,43 @@
}
}
+{
+ "type": "doc",
+ "value": {
+ "id": "fleet-agent-policies:fleet-server-policy",
+ "index": ".kibana_ingest",
+ "source": {
+ "coreMigrationVersion": "8.8.0",
+ "created_at": "2024-04-22T22:04:43.422Z",
+ "fleet-agent-policies": {
+ "description": "Fleet Server policy generated by Kibana",
+ "inactivity_timeout": 1209600,
+ "is_default_fleet_server": true,
+ "is_managed": false,
+ "is_protected": false,
+ "monitoring_enabled": [
+ "logs",
+ "metrics"
+ ],
+ "name": "Fleet Server Policy",
+ "namespace": "default",
+ "revision": 3,
+ "schema_version": "1.1.1",
+ "status": "active",
+ "updated_at": "2024-04-22T22:25:50.714Z",
+ "updated_by": "elastic"
+ },
+ "managed": false,
+ "references": [
+ ],
+ "type": "fleet-agent-policies",
+ "namespaces": ["default"],
+ "typeMigrationVersion": "10.1.0",
+ "updated_at": "2024-04-22T22:25:50.719Z"
+ }
+ }
+}
+
{
"type": "doc",
"value": {
@@ -109,6 +185,43 @@
}
}
+{
+ "type": "doc",
+ "value": {
+ "id": "fleet-agent-policies:fleet-server-policy-2",
+ "index": ".kibana_ingest",
+ "source": {
+ "coreMigrationVersion": "8.8.0",
+ "created_at": "2024-04-22T22:04:43.422Z",
+ "fleet-agent-policies": {
+ "description": "Fleet Server policy generated by Kibana",
+ "inactivity_timeout": 1209600,
+ "is_default_fleet_server": false,
+ "is_managed": false,
+ "is_protected": false,
+ "monitoring_enabled": [
+ "logs",
+ "metrics"
+ ],
+ "name": "Fleet Server Policy 2",
+ "namespace": "default",
+ "revision": 3,
+ "schema_version": "1.1.1",
+ "status": "active",
+ "updated_at": "2024-04-22T22:25:50.714Z",
+ "updated_by": "elastic"
+ },
+ "managed": false,
+ "references": [
+ ],
+ "type": "fleet-agent-policies",
+ "namespaces": ["default"],
+ "typeMigrationVersion": "10.1.0",
+ "updated_at": "2024-04-22T22:25:50.719Z"
+ }
+ }
+}
+
{
"type": "doc",
"value": {
@@ -154,6 +267,7 @@
},
"policy_id": "fleet-server-policy",
"revision": 1,
+ "latest_revision": true,
"updated_at": "2024-04-22T22:04:47.788Z",
"updated_by": "elastic"
},
@@ -167,6 +281,66 @@
}
}
+{
+ "type": "doc",
+ "value": {
+ "id": "fleet-package-policies:fleet-server-package-policy",
+ "index": ".kibana_ingest",
+ "source": {
+ "coreMigrationVersion": "8.8.0",
+ "created_at": "2024-04-22T22:04:47.788Z",
+ "fleet-package-policies": {
+ "created_at": "2024-04-22T22:04:47.788Z",
+ "created_by": "elastic",
+ "enabled": true,
+ "inputs": [
+ {
+ "compiled_input": {
+ "unused_key": "not_used"
+ },
+ "enabled": true,
+ "policy_template": "fleet_server",
+ "streams": [
+ ],
+ "type": "fleet-server",
+ "vars": {
+ "custom": {
+ "type": "yaml",
+ "value": ""
+ },
+ "max_agents": {
+ "type": "integer"
+ },
+ "max_connections": {
+ "type": "integer"
+ }
+ }
+ }
+ ],
+ "name": "fleet_server-1",
+ "namespace": "default",
+ "package": {
+ "name": "fleet_server",
+ "title": "Fleet Server",
+ "version": "1.5.0"
+ },
+ "policy_ids": ["fleet-server-policy"],
+ "revision": 1,
+ "latest_revision": true,
+ "updated_at": "2024-04-22T22:04:47.788Z",
+ "updated_by": "elastic"
+ },
+ "managed": false,
+ "references": [
+ ],
+ "type": "fleet-package-policies",
+ "namespaces": ["default"],
+ "typeMigrationVersion": "10.8.0",
+ "updated_at": "2024-04-22T22:04:47.788Z"
+ }
+ }
+}
+
{
"type": "doc",
"value": {
@@ -212,6 +386,7 @@
},
"policy_id": "fleet-server-policy-2",
"revision": 1,
+ "latest_revision": true,
"updated_at": "2024-04-22T22:04:47.788Z",
"updated_by": "elastic"
},
@@ -225,6 +400,66 @@
}
}
+{
+ "type": "doc",
+ "value": {
+ "id": "fleet-package-policies:fleet-server-package-policy-2",
+ "index": ".kibana_ingest",
+ "source": {
+ "coreMigrationVersion": "8.8.0",
+ "created_at": "2024-04-22T22:04:47.788Z",
+ "fleet-package-policies": {
+ "created_at": "2024-04-22T22:04:47.788Z",
+ "created_by": "elastic",
+ "enabled": true,
+ "inputs": [
+ {
+ "compiled_input": {
+ "unused_key": "not_used"
+ },
+ "enabled": true,
+ "policy_template": "fleet_server",
+ "streams": [
+ ],
+ "type": "fleet-server",
+ "vars": {
+ "custom": {
+ "type": "yaml",
+ "value": ""
+ },
+ "max_agents": {
+ "type": "integer"
+ },
+ "max_connections": {
+ "type": "integer"
+ }
+ }
+ }
+ ],
+ "name": "fleet_server-2",
+ "namespace": "default",
+ "package": {
+ "name": "fleet_server",
+ "title": "Fleet Server",
+ "version": "1.5.0"
+ },
+ "policy_ids": ["fleet-server-policy-2"],
+ "revision": 1,
+ "latest_revision": true,
+ "updated_at": "2024-04-22T22:04:47.788Z",
+ "updated_by": "elastic"
+ },
+ "managed": false,
+ "references": [
+ ],
+ "type": "fleet-package-policies",
+ "namespaces": ["default"],
+ "typeMigrationVersion": "10.8.0",
+ "updated_at": "2024-04-22T22:04:47.788Z"
+ }
+ }
+}
+
{
"type": "doc",
"value": {
@@ -444,4 +679,4 @@
"updated_at": "2024-04-22T22:07:16.226Z"
}
}
-}
\ No newline at end of file
+}
diff --git a/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/authentication/trial_license_complete_tier/endpoint_authz.ts b/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/authentication/trial_license_complete_tier/endpoint_authz.ts
index df2f55ccb8d04..8ecb7d2d0d027 100644
--- a/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/authentication/trial_license_complete_tier/endpoint_authz.ts
+++ b/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/authentication/trial_license_complete_tier/endpoint_authz.ts
@@ -54,7 +54,7 @@ export default function ({ getService }: FtrProviderContext) {
},
{
method: 'get',
- path: `${ACTION_STATUS_ROUTE}?agent_ids=1,2`,
+ path: `${ACTION_STATUS_ROUTE}?agent_ids={agentId}`,
version: '2023-10-31',
body: undefined,
},
diff --git a/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/agent_type_support.ts b/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/agent_type_support.ts
index 9fbc8e3f15507..6b98cd7b61802 100644
--- a/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/agent_type_support.ts
+++ b/x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/agent_type_support.ts
@@ -28,7 +28,8 @@ export default function ({ getService }: FtrProviderContext) {
.expect(400, {
statusCode: 400,
error: 'Bad Request',
- message: 'No stack connector instance configured for [.sentinelone]',
+ message:
+ 'Unable to build list of indexes while retrieving policy information for SentinelOne agents [test]. Check to ensure at least one integration policy exists.',
});
});
});
diff --git a/x-pack/test_serverless/api_integration/test_suites/security/platform_security/authorization.ts b/x-pack/test_serverless/api_integration/test_suites/security/platform_security/authorization.ts
index c44d5a773d125..f2fb55c6621f4 100644
--- a/x-pack/test_serverless/api_integration/test_suites/security/platform_security/authorization.ts
+++ b/x-pack/test_serverless/api_integration/test_suites/security/platform_security/authorization.ts
@@ -3908,6 +3908,12 @@ export default function ({ getService }: FtrProviderContext) {
"ui:siemV2/writeFileOperations",
"ui:siemV3/writeFileOperations",
],
+ "global_artifact_management_all": Array [
+ "login:",
+ "api:securitySolution-writeGlobalArtifacts",
+ "ui:siemV2/writeGlobalArtifacts",
+ "ui:siemV3/writeGlobalArtifacts",
+ ],
"host_isolation_all": Array [
"login:",
"api:securitySolution-writeHostIsolationRelease",