Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Remove setup_access from gcp package policy (#209126) #211957

Merged
merged 1 commit into from
Feb 20, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,16 @@ export const getInputVarsFields = (input: NewPackagePolicyInput, fields: GcpFiel
});

const getSetupFormatFromInput = (
input: Extract<
NewPackagePolicyPostureInput,
{ type: 'cloudbeat/cis_aws' | 'cloudbeat/cis_eks' | 'cloudbeat/cis_gcp' }
>
input: Extract<NewPackagePolicyPostureInput, { type: 'cloudbeat/cis_gcp' }>
): SetupFormatGCP => {
const credentialsType = input.streams[0].vars?.setup_access?.value;
const credentialsType = getGcpCredentialsType(input);

// Google Cloud shell is the default value
if (!credentialsType) {
return GCP_SETUP_ACCESS.CLOUD_SHELL;
}
if (credentialsType !== GCP_SETUP_ACCESS.CLOUD_SHELL) {

if (credentialsType !== GCP_CREDENTIALS_TYPE.CREDENTIALS_NONE) {
return GCP_SETUP_ACCESS.MANUAL;
}

Expand Down Expand Up @@ -474,10 +473,6 @@ export const GcpCredentialsForm = ({

updatePolicy(
getPosturePolicy(newPolicy, input.type, {
setup_access: {
value: GCP_SETUP_ACCESS.CLOUD_SHELL,
type: 'text',
},
'gcp.credentials.type': {
value: GCP_CREDENTIALS_TYPE.CREDENTIALS_NONE,
type: 'text',
Expand All @@ -490,10 +485,6 @@ export const GcpCredentialsForm = ({
} else {
updatePolicy(
getPosturePolicy(newPolicy, input.type, {
setup_access: {
value: GCP_SETUP_ACCESS.MANUAL,
type: 'text',
},
'gcp.credentials.type': {
// Restoring last manual credentials type
value: lastCredentialsType.current || GCP_CREDENTIALS_TYPE.CREDENTIALS_FILE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,6 @@ describe('<CspPolicyTemplateForm />', () => {
let policy = getMockPolicyGCP();
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
credentials_type: { value: 'credentials-file' },
setup_access: { value: 'manual' },
});

const { getByText } = render(
Expand All @@ -1191,7 +1190,6 @@ describe('<CspPolicyTemplateForm />', () => {
let policy = getMockPolicyGCP();
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
credentials_type: { value: 'credentials-file' },
setup_access: { value: 'manual' },
});

const { getByText } = render(
Expand All @@ -1208,7 +1206,6 @@ describe('<CspPolicyTemplateForm />', () => {
let policy = getMockPolicyGCP();
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
'gcp.account_type': { value: GCP_ORGANIZATION_ACCOUNT },
setup_access: { value: 'google_cloud_shell' },
});

const { getByTestId } = render(
Expand All @@ -1228,7 +1225,6 @@ describe('<CspPolicyTemplateForm />', () => {
let policy = getMockPolicyGCP();
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
'gcp.credentials.type': { value: 'credentials-file' },
setup_access: { value: 'manual' },
});

const { getByLabelText, getByRole } = render(
Expand All @@ -1247,7 +1243,6 @@ describe('<CspPolicyTemplateForm />', () => {
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
'gcp.project_id': { value: 'a' },
'gcp.credentials.type': { value: 'credentials-file' },
setup_access: { value: 'manual' },
});

const { getByTestId } = render(
Expand Down Expand Up @@ -1289,7 +1284,6 @@ describe('<CspPolicyTemplateForm />', () => {
let policy = getMockPolicyGCP();
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
'gcp.account_type': { value: GCP_ORGANIZATION_ACCOUNT },
setup_access: { value: 'google_cloud_shell' },
});

const { getByLabelText, getByTestId } = render(
Expand All @@ -1305,7 +1299,6 @@ describe('<CspPolicyTemplateForm />', () => {
let policy = getMockPolicyGCP();
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
'gcp.account_type': { value: GCP_ORGANIZATION_ACCOUNT },
setup_access: { value: 'manual' },
});

const { getByLabelText, getByTestId } = render(
Expand All @@ -1321,7 +1314,6 @@ describe('<CspPolicyTemplateForm />', () => {
let policy = getMockPolicyGCP();
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
'gcp.account_type': { value: GCP_SINGLE_ACCOUNT },
setup_access: { value: 'google_cloud_shell' },
});

const { queryByLabelText, queryByTestId } = render(
Expand All @@ -1337,7 +1329,6 @@ describe('<CspPolicyTemplateForm />', () => {
let policy = getMockPolicyGCP();
policy = getPosturePolicy(policy, CLOUDBEAT_GCP, {
'gcp.account_type': { value: GCP_ORGANIZATION_ACCOUNT },
setup_access: { value: 'manual' },
});

const { getByTestId } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ describe('getDefaultGcpHiddenVars', () => {

expect(result).toMatchObject({
'gcp.credentials.type': { value: 'credentials-json', type: 'text' },
setup_access: { value: 'manual', type: 'text' },
});
});

Expand All @@ -456,7 +455,6 @@ describe('getDefaultGcpHiddenVars', () => {

expect(result).toMatchObject({
'gcp.credentials.type': { value: 'credentials-none', type: 'text' },
setup_access: { value: 'google_cloud_shell', type: 'text' },
});
});

Expand All @@ -483,7 +481,6 @@ describe('getDefaultGcpHiddenVars', () => {

expect(result).toMatchObject({
'gcp.credentials.type': { value: 'credentials-file', type: 'text' },
setup_access: { value: 'manual', type: 'text' },
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
DEFAULT_AWS_CREDENTIALS_TYPE,
DEFAULT_MANUAL_AWS_CREDENTIALS_TYPE,
} from './aws_credentials_form/get_aws_credentials_form_options';
import { GCP_CREDENTIALS_TYPE, GCP_SETUP_ACCESS } from './gcp_credentials_form/gcp_credential_form';
import { GCP_CREDENTIALS_TYPE } from './gcp_credentials_form/gcp_credential_form';
import { AZURE_CREDENTIALS_TYPE } from './azure_credentials_form/azure_credentials_form';

// Posture policies only support the default namespace
Expand Down Expand Up @@ -257,10 +257,6 @@ export const getDefaultGcpHiddenVars = (
value: GCP_CREDENTIALS_TYPE.CREDENTIALS_JSON,
type: 'text',
},
setup_access: {
value: GCP_SETUP_ACCESS.MANUAL,
type: 'text',
},
};
}

Expand All @@ -271,10 +267,6 @@ export const getDefaultGcpHiddenVars = (
value: GCP_CREDENTIALS_TYPE.CREDENTIALS_NONE,
type: 'text',
},
setup_access: {
value: GCP_SETUP_ACCESS.CLOUD_SHELL,
type: 'text',
},
};
}

Expand All @@ -283,10 +275,6 @@ export const getDefaultGcpHiddenVars = (
value: GCP_CREDENTIALS_TYPE.CREDENTIALS_FILE,
type: 'text',
},
setup_access: {
value: GCP_SETUP_ACCESS.MANUAL,
type: 'text',
},
};
};

Expand Down