Skip to content

Commit

Permalink
[Cloud Security] fix setupTechnology GCP credential type swapping (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
seanrathier authored Feb 13, 2025
1 parent ca81958 commit 4fe72b6
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import {
import { usePackagePolicyList } from '../../common/api/use_package_policy_list';
import {
GCP_CREDENTIALS_TYPE,
GCP_SETUP_ACCESS,
gcpField,
getInputVarsFields,
} from './gcp_credentials_form/gcp_credential_form';
Expand Down Expand Up @@ -727,7 +726,7 @@ export const CspPolicyTemplateForm = memo<PackagePolicyReplaceDefineStepExtensio
'gcp.credentials.type': {
value: isAgentless
? GCP_CREDENTIALS_TYPE.CREDENTIALS_JSON
: GCP_SETUP_ACCESS.CLOUD_SHELL,
: GCP_CREDENTIALS_TYPE.CREDENTIALS_NONE,
type: 'text',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import type { FtrConfigProviderContext } from '@kbn/test';
import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils';
import { CLOUD_CREDENTIALS_PACKAGE_VERSION } from '@kbn/cloud-security-posture-plugin/common/constants';
import { AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION } from './constants';
import { pageObjects } from './page_objects';

export default async function ({ readConfigFile }: FtrConfigProviderContext) {
Expand All @@ -32,7 +32,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
`--xpack.fleet.agentless.api.tls.ca=${CA_CERT_PATH}`,
`--xpack.cloud.id=something-anything`,
`--xpack.fleet.packages.0.name=cloud_security_posture`,
`--xpack.fleet.packages.0.version=${CLOUD_CREDENTIALS_PACKAGE_VERSION}`,
`--xpack.fleet.packages.0.version=${AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION}`,
],
},
// load tests in the index file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ export const testSubjectIds = {
'cloudSecurityGraphGraphInvestigationInvestigateInTimeline',
ALERT_TABLE_ROW_CSS_SELECTOR: '[data-test-subj="alertsTable"] .euiDataGridRow',
SETUP_TECHNOLOGY_SELECTOR: 'setup-technology-selector',
SETUP_TECHNOLOGY_SELECTOR_ACCORDION_TEST_SUBJ: 'setup-technology-selector-accordion',
SETUP_TECHNOLOGY_SELECTOR_AGENTLESS_OPTION: 'setup-technology-agentless-option',
DIRECT_ACCESS_KEYS: 'direct_access_keys',
SETUP_TECHNOLOGY_SELECTOR_AGENTLESS_RADIO: 'setup-technology-agentless-radio',
SETUP_TECHNOLOGY_SELECTOR_AGENT_BASED_RADIO: 'setup-technology-agent-based-radio',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,16 @@ export function AddCisIntegrationFormPageProvider({
await radio.click();
};

const getSetupTechnologyRadio = async (setupTechnology: 'agentless' | 'agent-based') => {
const radioGroup = await testSubjects.find(testSubjectIds.SETUP_TECHNOLOGY_SELECTOR);
return await radioGroup.findByCssSelector(`input[value='${setupTechnology}']`);
};

const showSetupTechnologyComponent = async () => {
return await testSubjects.exists(testSubjectIds.SETUP_TECHNOLOGY_SELECTOR);
};

const selectAwsCredentials = async (credentialType: 'direct' | 'temporary') => {
await clickOptionButton(AWS_CREDENTIAL_SELECTOR);
await selectValue(
AWS_CREDENTIAL_SELECTOR,
credentialType === 'direct' ? 'direct_access_keys' : 'temporary_keys'
Expand Down Expand Up @@ -415,7 +419,7 @@ export function AddCisIntegrationFormPageProvider({

await clickOptionButton(testSubjectIds.CIS_AWS_OPTION_TEST_ID);

await clickOptionButton(testSubjectIds.SETUP_TECHNOLOGY_SELECTOR_AGENTLESS_RADIO);
await selectSetupTechnology('agentless');
await selectValue(testSubjectIds.AWS_CREDENTIAL_SELECTOR, 'direct_access_keys');
await fillInTextField(testSubjectIds.DIRECT_ACCESS_KEY_ID_TEST_ID, directAccessKeyId);
await fillInTextField(testSubjectIds.DIRECT_ACCESS_SECRET_KEY_TEST_ID, directAccessSecretKey);
Expand All @@ -427,7 +431,7 @@ export function AddCisIntegrationFormPageProvider({

await clickOptionButton(testSubjectIds.CIS_GCP_OPTION_TEST_ID);
await clickOptionButton(testSubjectIds.GCP_SINGLE_ACCOUNT_TEST_ID);
await clickOptionButton(testSubjectIds.SETUP_TECHNOLOGY_SELECTOR_AGENTLESS_RADIO);
await selectSetupTechnology('agentless');
await fillInTextField(testSubjectIds.PRJ_ID_TEST_ID, projectId);
await fillInTextField(testSubjectIds.CREDENTIALS_JSON_TEST_ID, credentialJson);
};
Expand All @@ -452,6 +456,8 @@ export function AddCisIntegrationFormPageProvider({
await navigateToAddIntegrationCspmPage();
await PageObjects.header.waitUntilLoadingHasFinished();

await inputIntegrationName(`cloud_security_posture-${new Date().toISOString()}`);

await fillOutForm(cloudProvider);

// Click Save Button to create the Integration then navigate to Integration Policies Tab Page
Expand All @@ -469,6 +475,12 @@ export function AddCisIntegrationFormPageProvider({
// Fill out form to edit an agentless integration
await fillInTextField(testSubjectId, value);

// TechDebt: This is a workaround to ensure the form is saved
// const agentlessRadio = await getSetupTechnologyRadio('agentless');
// const agentBasedRadio = await getSetupTechnologyRadio('agent-based');
// expect(await agentlessRadio.isEnabled()).to.be(true);
// expect(agentBasedRadio.isEnabled()).to.be(true);

// Clicking Save Button updates and navigates to Integration Policies Tab Page
await clickSaveIntegrationButton();
await PageObjects.header.waitUntilLoadingHasFinished();
Expand Down Expand Up @@ -559,6 +571,7 @@ export function AddCisIntegrationFormPageProvider({
clickOptionButton,
selectAwsCredentials,
selectSetupTechnology,
getSetupTechnologyRadio,
clickSaveButton,
clickSaveIntegrationButton,
clickAccordianButton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { CLOUD_CREDENTIALS_PACKAGE_VERSION } from '@kbn/cloud-security-posture-plugin/common/constants';
import { CA_CERT_PATH, KBN_CERT_PATH, KBN_KEY_PATH } from '@kbn/dev-utils';
import { AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION } from './constants';
import { createTestConfig } from '../../config.base';

// TODO: Remove the agentless default config once Serverless API is merged and default policy is deleted
Expand All @@ -19,7 +19,7 @@ export default createTestConfig({
`--xpack.cloud.serverless.project_id=some_fake_project_id`,

`--xpack.fleet.packages.0.name=cloud_security_posture`,
`--xpack.fleet.packages.0.version=${CLOUD_CREDENTIALS_PACKAGE_VERSION}`,
`--xpack.fleet.packages.0.version=${AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION}`,
`--xpack.fleet.agentless.enabled=true`,
`--xpack.fleet.agents.fleet_server.hosts=["https://ftr.kibana:8220"]`,
`--xpack.fleet.internal.fleetServerStandalone=true`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*/

export const SECURITY_ES_ARCHIVES_DIR = 'x-pack/test/security_solution_cypress/es_archives';
export const AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION = '1.13.0-preview02';
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { CLOUD_CREDENTIALS_PACKAGE_VERSION } from '@kbn/cloud-security-posture-plugin/common/constants';
import expect from '@kbn/expect';
import * as http from 'http';
import { AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION } from '../../../constants';
import type { FtrProviderContext } from '../../../../../ftr_provider_context';
import { setupMockServer } from './mock_agentless_api';
export default function ({ getPageObjects, getService }: FtrProviderContext) {
Expand Down Expand Up @@ -39,7 +39,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
after(async () => {
await supertest
.delete(
`/api/fleet/epm/packages/cloud_security_posture/${CLOUD_CREDENTIALS_PACKAGE_VERSION}`
`/api/fleet/epm/packages/cloud_security_posture/${AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION}`
)
.set('kbn-xsrf', 'xxxx')
.send({ force: true })
Expand All @@ -48,18 +48,22 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});

describe('Serverless - Agentless CIS_AWS Single Account Launch Cloud formation', () => {
it(`should show CIS_AWS Launch Cloud formation button when credentials selector is direct access keys and package version is ${CLOUD_CREDENTIALS_PACKAGE_VERSION}`, async () => {
it(`should show CIS_AWS Launch Cloud formation button when credentials selector is direct access keys and package version is ${AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION}`, async () => {
await cisIntegration.navigateToAddIntegrationCspmWithVersionPage(
CLOUD_CREDENTIALS_PACKAGE_VERSION
AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION
);
await pageObjects.header.waitUntilLoadingHasFinished();

await cisIntegration.clickOptionButton(testSubjectIds.CIS_AWS_OPTION_TEST_ID);
await cisIntegration.clickOptionButton(testSubjectIds.AWS_SINGLE_ACCOUNT_TEST_ID);

await cisIntegration.inputIntegrationName(
`cloud_security_posture-${new Date().toISOString()}`
);

await cisIntegration.selectSetupTechnology('agentless');
await cisIntegration.selectAwsCredentials('direct');

await pageObjects.header.waitUntilLoadingHasFinished();
await cisIntegration.selectAwsCredentials('direct');

expect(
(await cisIntegrationAws.showLaunchCloudFormationAgentlessButton()) !== undefined
Expand All @@ -68,27 +72,22 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});

describe('Serverless - Agentless CIS_AWS ORG Account Launch Cloud formation', () => {
// tech debt: this test is failing because the credentials select is not working as expected
// https://github.com/orgs/elastic/projects/705/views/92?sliceBy%5Bvalue%5D=Agentless+-+API+-+ESS&pane=issue&itemId=73261952
it.skip(`should show CIS_AWS Launch Cloud formation button when credentials selector is direct access keys and package version is ${CLOUD_CREDENTIALS_PACKAGE_VERSION}`, async () => {
it(`should show CIS_AWS Launch Cloud formation button when credentials selector is direct access keys and package version is ${AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION}`, async () => {
await cisIntegration.navigateToAddIntegrationCspmWithVersionPage(
CLOUD_CREDENTIALS_PACKAGE_VERSION
AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION
);
await pageObjects.header.waitUntilLoadingHasFinished();

await cisIntegration.clickOptionButton(testSubjectIds.CIS_AWS_OPTION_TEST_ID);

await cisIntegration.selectSetupTechnology('agentless');

await cisIntegration.selectAwsCredentials('direct');

await pageObjects.header.waitUntilLoadingHasFinished();

expect(await cisIntegrationAws.showLaunchCloudFormationAgentlessButton()).to.be(true);
});
});

// TODO: Migrate test after Serverless default agentless policy is deleted.
describe.skip('Serverless - Agentless CIS_AWS edit flow', () => {
describe('Serverless - Agentless CIS_AWS edit flow', () => {
it(`user should save and edit agentless integration policy`, async () => {
const newDirectAccessKeyId = `newDirectAccessKey`;

Expand All @@ -109,15 +108,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
)
).to.be(newDirectAccessKeyId);
expect(await cisIntegrationAws.showLaunchCloudFormationAgentlessButton()).to.be(true);
expect(await cisIntegration.getElementText(testSubjectIds.SETUP_TECHNOLOGY_SELECTOR)).to.be(
'Agentless\nBETA'
);
expect(
await cisIntegration.getFieldAttributeValue(
testSubjectIds.SETUP_TECHNOLOGY_SELECTOR,
'disabled'
)
).to.be('true');
});
});
// FLAKY: https://github.com/elastic/kibana/issues/191017
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import expect from '@kbn/expect';
import { CLOUD_CREDENTIALS_PACKAGE_VERSION } from '@kbn/cloud-security-posture-plugin/common/constants';
import * as http from 'http';
import { AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION } from '../../../constants';
import type { FtrProviderContext } from '../../../../../ftr_provider_context';
import { setupMockServer } from './mock_agentless_api';
export default function ({ getPageObjects, getService }: FtrProviderContext) {
Expand Down Expand Up @@ -36,18 +36,18 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
after(async () => {
await supertest
.delete(
`/api/fleet/epm/packages/cloud_security_posture/${CLOUD_CREDENTIALS_PACKAGE_VERSION}`
`/api/fleet/epm/packages/cloud_security_posture/${AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION}`
)
.set('kbn-xsrf', 'xxxx')
.send({ force: true })
.expect(200);
mockApiServer.close();
});

describe.skip('Agentless CIS_GCP Single Account Launch Cloud shell', () => {
it(`should show CIS_GCP Launch Cloud Shell button when package version is ${CLOUD_CREDENTIALS_PACKAGE_VERSION}`, async () => {
describe('Agentless CIS_GCP Single Account Launch Cloud shell', () => {
it(`should show CIS_GCP Launch Cloud Shell button when package version is ${AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION}`, async () => {
await cisIntegration.navigateToAddIntegrationCspmWithVersionPage(
CLOUD_CREDENTIALS_PACKAGE_VERSION
AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION
);

await cisIntegration.clickOptionButton(testSubjectIds.CIS_GCP_OPTION_TEST_ID);
Expand All @@ -61,10 +61,10 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});
});

describe.skip('Agentless CIS_GCP ORG Account Launch Cloud Shell', () => {
it(`should show CIS_GCP Launch Cloud Shell button when package version is ${CLOUD_CREDENTIALS_PACKAGE_VERSION}`, async () => {
describe('Agentless CIS_GCP ORG Account Launch Cloud Shell', () => {
it(`should show CIS_GCP Launch Cloud Shell button when package version is ${AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION}`, async () => {
await cisIntegration.navigateToAddIntegrationCspmWithVersionPage(
CLOUD_CREDENTIALS_PACKAGE_VERSION
AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION
);

await cisIntegration.clickOptionButton(testSubjectIds.CIS_GCP_OPTION_TEST_ID);
Expand Down Expand Up @@ -97,16 +97,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
'value'
)
).to.be(newCredentialsJSON);
expect(await cisIntegrationGcp.showLaunchCloudShellAgentlessButton()).to.be(true);
expect(await cisIntegration.getElementText(testSubjectIds.SETUP_TECHNOLOGY_SELECTOR)).to.be(
'Agentless\nBETA'
);
expect(
await cisIntegration.getFieldAttributeValue(
testSubjectIds.SETUP_TECHNOLOGY_SELECTOR,
'disabled'
)
).to.be('true');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { CLOUD_CREDENTIALS_PACKAGE_VERSION } from '@kbn/cloud-security-posture-plugin/common/constants';
import * as http from 'http';
import expect from '@kbn/expect';
import { AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION } from '../../../constants';
import { setupMockServer } from './mock_agentless_api';
import type { FtrProviderContext } from '../../../../../ftr_provider_context';
export default function ({ getPageObjects, getService }: FtrProviderContext) {
Expand All @@ -21,8 +21,10 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
]);

const CIS_AWS_OPTION_TEST_ID = 'cisAwsTestId';

const AWS_SINGLE_ACCOUNT_TEST_ID = 'awsSingleTestId';
const AWS_MANUAL_TEST_ID = 'aws-manual-setup-option';
const DIRECT_ACCESS_KEY_ID_TEST_ID = 'awsDirectAccessKeyId';
const DIRECT_ACCESS_SECRET_KEY_TEST_ID = 'passwordInput-secret-access-key';

describe('Agentless API Serverless', function () {
this.tags(['skipMKI', 'cloud_security_posture_agentless']);
Expand All @@ -42,16 +44,17 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
it(`should create agentless-agent`, async () => {
const integrationPolicyName = `cloud_security_posture-${new Date().toISOString()}`;
await cisIntegration.navigateToAddIntegrationCspmWithVersionPage(
CLOUD_CREDENTIALS_PACKAGE_VERSION
AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION
);

await cisIntegration.clickOptionButton(CIS_AWS_OPTION_TEST_ID);
await cisIntegration.clickOptionButton(AWS_SINGLE_ACCOUNT_TEST_ID);

await cisIntegration.inputIntegrationName(integrationPolicyName);

await cisIntegration.selectSetupTechnology('agentless');
await cisIntegration.selectAwsCredentials('direct');
await cisIntegration.fillInTextField(DIRECT_ACCESS_KEY_ID_TEST_ID, 'test');
await cisIntegration.fillInTextField(DIRECT_ACCESS_SECRET_KEY_TEST_ID, 'test');

await pageObjects.header.waitUntilLoadingHasFinished();

Expand All @@ -74,13 +77,24 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const integrationPolicyName = `cloud_security_posture-${new Date().toISOString()}`;

await cisIntegration.navigateToAddIntegrationCspmWithVersionPage(
CLOUD_CREDENTIALS_PACKAGE_VERSION
AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION
);
await pageObjects.header.waitUntilLoadingHasFinished();

await cisIntegration.clickOptionButton(CIS_AWS_OPTION_TEST_ID);
await cisIntegration.clickOptionButton(AWS_SINGLE_ACCOUNT_TEST_ID);
await pageObjects.header.waitUntilLoadingHasFinished();

await cisIntegration.inputIntegrationName(integrationPolicyName);
await pageObjects.header.waitUntilLoadingHasFinished();

await cisIntegration.selectSetupTechnology('agent-based');
await pageObjects.header.waitUntilLoadingHasFinished();

await cisIntegration.clickOptionButton(AWS_MANUAL_TEST_ID);
await cisIntegration.selectAwsCredentials('direct');
await cisIntegration.fillInTextField(DIRECT_ACCESS_KEY_ID_TEST_ID, 'test');
await cisIntegration.fillInTextField(DIRECT_ACCESS_SECRET_KEY_TEST_ID, 'test');

await cisIntegration.clickSaveButton();
await pageObjects.header.waitUntilLoadingHasFinished();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import expect from '@kbn/expect';
import { AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION } from '../constants';
import { AGENTLESS_SECURITY_POSTURE_PACKAGE_VERSION } from '../../../../constants';
import type { FtrProviderContext } from '../../../../../../ftr_provider_context';
export default function ({ getPageObjects, getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
Expand Down

This file was deleted.

0 comments on commit 4fe72b6

Please sign in to comment.