Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,7 @@ x-pack/platform/plugins/shared/ml/server/models/data_recognizer/modules/security
/x-pack/solutions/security/test/api_integration/ftr_provider_context.d.ts @elastic/appex-qa
/x-pack/solutions/security/test/api_integration/services/index.ts @elastic/appex-qa
/x-pack/solutions/security/test/alerting_api_integration/ftr_provider_context.d.ts @elastic/appex-qa
/x-pack/test_serverless/functional/page_objects/cloud_security_posture_page_objects @elastic/appex-qa # temporarily due to SKA tests relocation

# Core
/src/platform/test/api_integration/fixtures/kbn_archiver/management/saved_objects/relationships.json @elastic/kibana-core @elastic/kibana-data-discovery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import expect from '@kbn/expect';
import type { GetBenchmarkResponse } from '@kbn/cloud-security-posture-plugin/common/types/latest';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { createPackagePolicy } from '@kbn/test-suites-xpack-security/api_integration/apis/cloud_security_posture/helper';
import { createPackagePolicy } from '../helper';
import { FtrProviderContext } from '../../../../ftr_provider_context';
import { RoleCredentials } from '../../../../../shared/services';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import expect from '@kbn/expect';
import type { GetBenchmarkResponse } from '@kbn/cloud-security-posture-plugin/common/types/latest';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { createPackagePolicy } from '@kbn/test-suites-xpack-security/api_integration/apis/cloud_security_posture/helper';
import { createPackagePolicy } from '../helper';
import { FtrProviderContext } from '../../../../ftr_provider_context';
import { RoleCredentials } from '../../../../../shared/services';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export interface MockTelemetryFindings {
rule: {
benchmark: { id: string; posture_type?: string | undefined; version: string; name: string };
};
resource: { type: string; sub_type: string; id: string };
agent: { id: string };
result: { evaluation: string };
host: { name: string };
cluster_id?: string;
cloud?: { account?: { id: string } };
cloudbeat?: { kubernetes: { version: string } };
}

export interface MockTelemetryData {
[key: string]: MockTelemetryFindings[];
}

export const data: MockTelemetryData = {
cspmFindings: [
{
rule: {
benchmark: {
id: 'cis_aws',
posture_type: 'cspm',
version: 'v1.5.0',
name: 'CIS Amazon Web Services Foundations',
},
},
resource: {
type: 'identifyingType',
sub_type: 'aws-password-policy',
id: '15e450b7-8980-5bca-ade2-a0c795f9ea9d',
},
agent: { id: '07bd3686-98ef-4b23-99cb-9ff544b25ae2' },
result: { evaluation: 'failed' },
cloud: { account: { id: 'my-aws-12345' } },
host: { name: 'docker-fleet-agent' },
},
{
rule: {
benchmark: {
id: 'cis_aws',
posture_type: 'cspm',
version: 'v1.5.0',
name: 'CIS Amazon Web Services Foundations',
},
},
resource: {
type: 'identifyingType',
sub_type: 'aws-password-policy',
id: '15e450b7-8980-5bca-ade2-a0c795f9ea99',
},
agent: { id: '07bd3686-98ef-4b23-99cb-9ff544b25ae2' },
result: { evaluation: 'passed' },
cloud: { account: { id: 'my-aws-12345' } },
host: { name: 'docker-fleet-agent' },
},
],
kspmFindings: [
{
cluster_id: 'my-k8s-cluster-5555',
rule: {
benchmark: {
id: 'cis_k8s',
version: 'v1.0.0',
name: 'CIS Kubernetes V1.23',
posture_type: 'kspm',
},
},
resource: {
type: 'k8s_object',
sub_type: 'ServiceAccount',
id: '1111',
},
agent: { id: '07bd3686-98ef-4b23-99cb-9ff544b25ae2' },
result: { evaluation: 'passed' },
host: { name: 'docker-fleet-agent' },
cloudbeat: { kubernetes: { version: 'v1.23.0' } },
},
{
cluster_id: 'my-k8s-cluster-5555',
rule: {
benchmark: {
id: 'cis_k8s',
version: 'v1.0.0',
name: 'CIS Kubernetes V1.23',
posture_type: 'kspm',
},
},
resource: {
type: 'process',
sub_type: 'process',
id: '1111',
},
agent: { id: '07bd3686-98ef-4b23-99cb-9ff544b25ae3' },
result: { evaluation: 'passed' },
host: { name: 'control-plane' },
cloudbeat: { kubernetes: { version: 'v1.23.0' } },
},
],
kspmFindingsNoPostureType: [
{
cluster_id: 'my-k8s-cluster-5555',
rule: {
benchmark: {
id: 'cis_k8s',
version: 'v1.0.0',
name: 'CIS Kubernetes V1.23',
},
},
resource: {
type: 'k8s_object',
sub_type: 'ServiceAccount',
id: '1111',
},
agent: { id: '07bd3686-98ef-4b23-99cb-9ff544b25ae2' },
result: { evaluation: 'passed' },
host: { name: 'docker-fleet-agent' },
cloudbeat: { kubernetes: { version: 'v1.23.0' } },
},
{
cluster_id: 'my-k8s-cluster-5555',
rule: {
benchmark: {
id: 'cis_k8s',
version: 'v1.0.0',
name: 'CIS Kubernetes V1.23',
},
},
resource: {
type: 'process',
sub_type: 'process',
id: '1111',
},
agent: { id: '07bd3686-98ef-4b23-99cb-9ff544b25ae3' },
result: { evaluation: 'passed' },
host: { name: 'control-plane' },
cloudbeat: { kubernetes: { version: 'v1.23.0' } },
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
FindCspBenchmarkRuleResponse,
} from '@kbn/cloud-security-posture-common/schema/rules/latest';

import { createPackagePolicy } from '@kbn/test-suites-xpack-security/api_integration/apis/cloud_security_posture/helper';
import { createPackagePolicy } from './helper';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
ELASTIC_HTTP_VERSION_HEADER,
X_ELASTIC_INTERNAL_ORIGIN_REQUEST,
} from '@kbn/core-http-common';
import { result } from '@kbn/test-suites-xpack-security/cloud_security_posture_api/utils';
import type { Agent } from 'supertest';
import type { GraphRequest } from '@kbn/cloud-security-posture-common/types/graph/v1';
import { result } from './utils';
import type { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService }: FtrProviderContext) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { Agent as SuperTestAgent } from 'supertest';

import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { CLOUD_SECURITY_PLUGIN_VERSION } from '@kbn/cloud-security-posture-plugin/common/constants';
import { RoleCredentials, SecurityService } from '@kbn/ftr-common-functional-services';
import { SECURITY_FEATURE_ID } from '@kbn/security-solution-plugin/common/constants';

export async function createPackagePolicy(
supertest: SuperTestAgent,
agentPolicyId: string,
policyTemplate: string,
input: string,
deployment: string,
posture: string,
packageName: string = 'cloud_security_posture-1',
roleAuthc?: RoleCredentials,
internalRequestHeader?: { 'x-elastic-internal-origin': string; 'kbn-xsrf': string }
) {
const version = CLOUD_SECURITY_PLUGIN_VERSION;
const title = 'Security Posture Management';
const streams = [
{
enabled: true,
data_stream: {
type: 'logs',
dataset: 'cloud_security_posture.vulnerabilities',
},
},
];

const inputTemplate = {
enabled: true,
type: input,
policy_template: policyTemplate,
};

const inputs = posture === 'vuln_mgmt' ? { ...inputTemplate, streams } : { ...inputTemplate };

const { body: postPackageResponse } =
roleAuthc && internalRequestHeader
? await supertest
.post(`/api/fleet/package_policies`)
.set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31')
.set(internalRequestHeader)
.set(roleAuthc.apiKeyHeader)
.send({
force: true,
name: packageName,
description: '',
namespace: 'default',
policy_id: agentPolicyId,
enabled: true,
inputs: [inputs],
package: {
name: 'cloud_security_posture',
title,
version,
},
vars: {
deployment: {
value: deployment,
type: 'text',
},
posture: {
value: posture,
type: 'text',
},
},
})
.expect(200)
: await supertest
.post(`/api/fleet/package_policies`)
.set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31')
.set('kbn-xsrf', 'xxxx')
.send({
force: true,
name: packageName,
description: '',
namespace: 'default',
policy_id: agentPolicyId,
enabled: true,
inputs: [inputs],
package: {
name: 'cloud_security_posture',
title,
version,
},
vars: {
deployment: {
value: deployment,
type: 'text',
},
posture: {
value: posture,
type: 'text',
},
},
})
.expect(200);

return postPackageResponse.item;
}

export const createUser = async (security: SecurityService, userName: string, roleName: string) => {
await security.user.create(userName, {
password: 'changeme',
roles: [roleName],
full_name: 'a reporting user',
});
};

export const createCSPRole = async (
security: SecurityService,
roleName: string,
indicesName?: string[]
) => {
await security.role.create(roleName, {
kibana: [
{
feature: { [SECURITY_FEATURE_ID]: ['read'], fleetv2: ['all'], fleet: ['read'] },
spaces: ['*'],
},
],
...(indicesName && indicesName.length > 0
? {
elasticsearch: {
indices: [
{
names: indicesName,
privileges: ['read'],
},
],
},
}
: {}),
});
};

export const deleteRole = async (security: SecurityService, roleName: string) => {
await security.role.delete(roleName);
};

export const deleteUser = async (security: SecurityService, userName: string) => {
await security.user.delete(userName);
};
Loading