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

[Cloud Security] Added textarea secret fields for GCP JSON file #187022

Merged
merged 11 commits into from
Jul 10, 2024

Conversation

animehart
Copy link
Contributor

@animehart animehart commented Jun 26, 2024

Summary

Currently GCP Json Blob field might contain input variables that can be considered secrets, and we are not hiding it. As such user can see the value when previewing the integration after saving them.

This PR makes it so that the JSON Blob field acts like a Password field once user save them as in they won't be able to see it when editing it (they can only replace but not edit)

It also encrypt the content on Preview, preventing User from seeing it from the Preview.

Screenshot 2024-06-26 at 1 45 54 PM Screenshot 2024-07-02 at 7 52 58 PM
Screen.Recording.2024-07-02.at.7.50.57.PM.mov

TODO:

@animehart animehart marked this pull request as ready for review June 26, 2024 21:04
@animehart animehart requested review from a team as code owners June 26, 2024 21:04
@animehart animehart added v8.15.0 Team:Cloud Security Cloud Security team related labels Jun 27, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security)

@animehart animehart added the release_note:skip Skip the PR/issue when compiling release notes label Jun 27, 2024
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Jun 27, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
fleet 1226 1227 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 450.4KB 450.9KB +485.0B
fleet 1.4MB 1.4MB +25.0B
total +510.0B
Unknown metric groups

API count

id before after diff
fleet 1348 1349 +1

ESLint disabled line counts

id before after diff
fleet 45 46 +1

Total ESLint disabled count

id before after diff
fleet 58 59 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@JordanSh JordanSh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a video of the component when creating new and then when editing?

Comment on lines 1530 to 1535
// const credentialsJsonField = queryByTestId(
// CIS_GCP_INPUT_FIELDS_TEST_SUBJECTS.CREDENTIALS_JSON
// );
// await waitFor(() =>
// expect(getByTestId(CIS_GCP_INPUT_FIELDS_TEST_SUBJECTS.CREDENTIALS_JSON)).toBeInTheDocument()
// );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this if its not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops
i missed this

<LazyPackagePolicyInputVarField
data-test-subj={CIS_GCP_INPUT_FIELDS_TEST_SUBJECTS.CREDENTIALS_JSON}
varDef={{
...findVariableDef(packageInfo, credentialJSONFields.id)!,
Copy link
Contributor

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

Copy link
Contributor Author

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

onChange={(value) => {
onChange(credentialJSONFields.id, value);
}}
errors={[]}
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

@animehart animehart Jul 2, 2024

Choose a reason for hiding this comment

The 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

}}
errors={[]}
forceShowErrors={false}
isEditPage={true}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this always be set to true? shouldn't it be conditional, using our isEdit parameter?

@animehart animehart requested a review from JordanSh July 4, 2024 09:29
Copy link
Contributor

@juliaElastic juliaElastic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fleet change LGTM

Copy link
Contributor

@opauloh opauloh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks ok, just got some questions before approving

CIS_GCP_INPUT_FIELDS_TEST_SUBJECTS.CREDENTIALS_JSON
);

screen.logTestingPlaygroundURL();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better remove this log, even if the test is skipped

@@ -185,7 +185,8 @@ function getInputComponent({
fieldTestSelector,
setIsDirty,
}: InputComponentProps) {
const { multi, type, options } = varDef;
// eslint-disable-next-line @typescript-eslint/naming-convention
const { multi, type, options, full_width } = varDef;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would that work instead of disabling the rule?

const { multi, type, options, full_width : fullWidth } = varDef;

@@ -629,7 +637,7 @@ describe('<CspPolicyTemplateForm />', () => {
});
});

it(`renders ${CLOUDBEAT_EKS} Direct Access Keys fields`, async () => {
it.skip(`renders ${CLOUDBEAT_EKS} Direct Access Keys fields`, async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why all the tests are skipped?

@@ -1577,7 +1541,7 @@ describe('<CspPolicyTemplateForm />', () => {
expect(setupTechnologySelector).toBeInTheDocument();
expect(setupTechnologySelector).toHaveTextContent(/agentless/i);
expect(orgIdField).toBeInTheDocument();
expect(credentialsJsonField).toBeInTheDocument();
// expect(credentialsJsonField).toBeInTheDocument();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the LazyPackagePolicyInputVarField mock at the beginning of the file suggests this assertion should not be commented

Comment on lines 172 to 176
await cisIntegration.navigateToIntegrationCspList();
expect(
(await cisIntegration.getFieldValueInEditPage(CREDENTIALS_JSON_TEST_ID)) ===
credentialJsonName
).to.be(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of just removing the assertion, we should test that it's really a secret field, when going to the edit page, we shouldn't be able to see the credential anywhere. Instead, we should be able to see the following message: "The saved secret access key is hidden."

Comment on lines 273 to 277
await cisIntegration.navigateToIntegrationCspList();
expect(
(await cisIntegration.getFieldValueInEditPage(CREDENTIALS_JSON_TEST_ID)) ===
credentialJsonName
).to.be(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment are before

@animehart animehart removed the v8.15.0 label Jul 9, 2024
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
fleet 1226 1227 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 452.9KB 453.4KB +522.0B
fleet 1.8MB 1.8MB +25.0B
total +547.0B
Unknown metric groups

API count

id before after diff
fleet 1348 1349 +1

History

Copy link
Contributor

@opauloh opauloh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Just need to link the tech debt for removing the tests skips to this PR

@animehart animehart merged commit 0e62867 into elastic:main Jul 10, 2024
21 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related Team:Fleet Team label for Observability Data Collection Fleet team v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants