-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Cloud Security] Added textarea secret fields for GCP JSON file #187022
Changes from all commits
d36dbf7
1249962
29b30d7
a8ba211
3d32c85
8cde8ad
18d90dd
698c114
b0ce7a8
16de911
114e42a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React, { useEffect, useRef } from 'react'; | ||
import React, { Suspense, useEffect, useRef } from 'react'; | ||
import semverLt from 'semver/functions/lt'; | ||
import semverCoerce from 'semver/functions/coerce'; | ||
import semverValid from 'semver/functions/valid'; | ||
|
@@ -15,13 +15,13 @@ import { | |
EuiForm, | ||
EuiFormRow, | ||
EuiHorizontalRule, | ||
EuiLoadingSpinner, | ||
EuiSelect, | ||
EuiSpacer, | ||
EuiText, | ||
EuiTextArea, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import type { NewPackagePolicy } from '@kbn/fleet-plugin/public'; | ||
import { LazyPackagePolicyInputVarField, type NewPackagePolicy } from '@kbn/fleet-plugin/public'; | ||
import { NewPackagePolicyInput, PackageInfo } from '@kbn/fleet-plugin/common'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
@@ -30,6 +30,7 @@ import { GcpCredentialsType } from '../../../../common/types_old'; | |
import { CLOUDBEAT_GCP } from '../../../../common/constants'; | ||
import { CspRadioOption, RadioGroup } from '../csp_boxed_radio_group'; | ||
import { | ||
findVariableDef, | ||
getCspmCloudShellDefaultValue, | ||
getPosturePolicy, | ||
NewPackagePolicyPostureInput, | ||
|
@@ -193,7 +194,10 @@ const credentialOptionsList = [ | |
}, | ||
]; | ||
|
||
type GcpFields = Record<string, { label: string; type?: 'password' | 'text'; value?: string }>; | ||
type GcpFields = Record< | ||
string, | ||
{ label: string; type?: 'password' | 'text'; value?: string; isSecret?: boolean } | ||
>; | ||
interface GcpInputFields { | ||
fields: GcpFields; | ||
} | ||
|
@@ -222,7 +226,8 @@ export const gcpField: GcpInputFields = { | |
label: i18n.translate('xpack.csp.findings.gcpIntegration.gcpInputText.credentialJSONText', { | ||
defaultMessage: 'JSON blob containing the credentials and key used to subscribe', | ||
}), | ||
type: 'text', | ||
type: 'password', | ||
isSecret: true, | ||
}, | ||
'gcp.credentials.type': { | ||
label: i18n.translate( | ||
|
@@ -263,6 +268,7 @@ export interface GcpFormProps { | |
setIsValid: (isValid: boolean) => void; | ||
onChange: any; | ||
disabled: boolean; | ||
isEditPage?: boolean; | ||
} | ||
|
||
export const getInputVarsFields = (input: NewPackagePolicyInput, fields: GcpFields) => | ||
|
@@ -367,6 +373,7 @@ export const GcpCredentialsForm = ({ | |
setIsValid, | ||
onChange, | ||
disabled, | ||
isEditPage, | ||
}: GcpFormProps) => { | ||
/* Create a subset of properties from GcpField to use for hiding value of credentials json and credentials file when user switch from Manual to Cloud Shell, we wanna keep Project and Organization ID */ | ||
const subsetOfGcpField = (({ ['gcp.credentials.file']: a, ['gcp.credentials.json']: b }) => ({ | ||
|
@@ -489,6 +496,8 @@ export const GcpCredentialsForm = ({ | |
updatePolicy(getPosturePolicy(newPolicy, input.type, { [key]: { value } })) | ||
} | ||
isOrganization={isOrganization} | ||
packageInfo={packageInfo} | ||
isEditPage={isEditPage} | ||
/> | ||
)} | ||
|
||
|
@@ -504,11 +513,15 @@ export const GcpInputVarFields = ({ | |
onChange, | ||
isOrganization, | ||
disabled, | ||
packageInfo, | ||
isEditPage, | ||
}: { | ||
fields: Array<GcpFields[keyof GcpFields] & { value: string; id: string }>; | ||
onChange: (key: string, value: string) => void; | ||
isOrganization: boolean; | ||
disabled: boolean; | ||
packageInfo: PackageInfo; | ||
isEditPage?: boolean; | ||
}) => { | ||
const getFieldById = (id: keyof GcpInputFields['fields']) => { | ||
return fields.find((element) => element.id === id); | ||
|
@@ -581,15 +594,41 @@ export const GcpInputVarFields = ({ | |
</EuiFormRow> | ||
)} | ||
{credentialsTypeValue === credentialJSONValue && credentialJSONFields && ( | ||
<EuiFormRow fullWidth label={gcpField.fields['gcp.credentials.json'].label}> | ||
<EuiTextArea | ||
data-test-subj={CIS_GCP_INPUT_FIELDS_TEST_SUBJECTS.CREDENTIALS_JSON} | ||
id={credentialJSONFields.id} | ||
fullWidth | ||
value={credentialJSONFields.value || ''} | ||
onChange={(event) => onChange(credentialJSONFields.id, event.target.value)} | ||
/> | ||
</EuiFormRow> | ||
<div | ||
css={css` | ||
width: 100%; | ||
.euiFormControlLayout, | ||
.euiFormControlLayout__childrenWrapper, | ||
.euiFormRow, | ||
input { | ||
max-width: 100%; | ||
width: 100%; | ||
} | ||
`} | ||
> | ||
<EuiSpacer size="m" /> | ||
<EuiFormRow fullWidth label={gcpField.fields['gcp.credentials.json'].label}> | ||
<Suspense fallback={<EuiLoadingSpinner size="l" />}> | ||
<LazyPackagePolicyInputVarField | ||
data-test-subj={CIS_GCP_INPUT_FIELDS_TEST_SUBJECTS.CREDENTIALS_JSON} | ||
varDef={{ | ||
...findVariableDef(packageInfo, credentialJSONFields.id)!, | ||
required: true, | ||
type: 'textarea', | ||
secret: true, | ||
full_width: true, | ||
}} | ||
value={credentialJSONFields.value || ''} | ||
onChange={(value) => { | ||
onChange(credentialJSONFields.id, value); | ||
}} | ||
errors={[]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. im not familiar with this component, is this on purpose? what does this effects? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this error props is basically being used on EuiFormRow component inside this component |
||
forceShowErrors={false} | ||
isEditPage={isEditPage} | ||
/> | ||
</Suspense> | ||
</EuiFormRow> | ||
</div> | ||
)} | ||
</EuiForm> | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using this assertion is a red flag, i suggest to handle the situation of when its missing so we can actually know its there instead if asserting that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we did this same thing with Azure and AWS secret component, can't quite remember how we ended up with this assertion