Skip to content

[Cloud Security] Misconfiguration preview & Refactor CSP Plugin to include new package PHASE 4#191677

Merged
animehart merged 24 commits intoelastic:mainfrom
animehart:misconfiguration-preview-refactor-phase-4-implementation
Sep 4, 2024
Merged

[Cloud Security] Misconfiguration preview & Refactor CSP Plugin to include new package PHASE 4#191677
animehart merged 24 commits intoelastic:mainfrom
animehart:misconfiguration-preview-refactor-phase-4-implementation

Conversation

@animehart
Copy link
Copy Markdown
Contributor

@animehart animehart commented Aug 28, 2024

The previous #190105 was way too big and made it hard to review without missing any bugs or potential bugs, Thus we decided we are going to make series of smaller PR to make things more manageable

We will be splitting it into 4 PR
Phase 1: Creating empty packages for csp and csp-common
Phase 2: Move Types from CSP plugin to the Package + Deleting duplicates in the CSP plugin where possible
Phase 3: Move Functions, Utils or Helpers, Hooks to Package
Phase 4: Misconfiguration Preview feature (with Cypress test and other required test)

353329193-5ad22c4e-81c2-4a8b-89f7-fdbc2a686c2d

This is Phase 4 of the Process,

@animehart animehart marked this pull request as ready for review August 28, 2024 20:35
@animehart animehart requested review from a team as code owners August 28, 2024 20:35
@animehart animehart requested a review from tiansivive August 28, 2024 20:35
@animehart animehart added v8.16.0 Team:Cloud Security Cloud Security team related labels Aug 28, 2024
@elasticmachine
Copy link
Copy Markdown
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 Aug 28, 2024
@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod Bot requested a review from a team as a code owner August 28, 2024 20:59
Copy link
Copy Markdown
Contributor

@tiansivive tiansivive left a comment

Choose a reason for hiding this comment

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

LGTM from Entity Analytics

@animehart animehart requested a review from opauloh August 30, 2024 07:01
@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod Bot requested a review from a team as a code owner August 30, 2024 08:55
@maxcold maxcold added the ci:project-deploy-security Create a Security Serverless Project label Aug 30, 2024
@maxcold
Copy link
Copy Markdown
Contributor

maxcold commented Aug 30, 2024

/ci

Comment thread x-pack/packages/kbn-cloud-security-posture-common/utils/helpers.ts Outdated
Comment thread x-pack/packages/kbn-cloud-security-posture-common/utils/helpers.ts Outdated
…n' of github.com:animehart/kibana into misconfiguration-preview-refactor-phase-4-implementation
@MadameSheema
Copy link
Copy Markdown
Contributor

From Cypress perspective there is work pending to be done to merge this PR. As it is, this test is not going to be executed in any of our existing pipelines:

  • Is missing the integration with buildkite for both PRs and periodic pipeline.
  • Is missing the integration with the flaky test suite runner.
  • We need to make sure that the team understands the best practices and how to react in case of failure in any of the different stages.

Please feel free to setup a meeting with @elastic/security-engineering-productivity to let you know which are the correct steps to make this happen.

createMockFinding();
expandFirstAlertHostFlyout();
cy.log('check if Misconfiguration preview section rendered');
cy.get(HOST_INSIGHT_MISCONFIGURATION).should('exist');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For robustness, is better to check that the element is visible, since the element can exist on the dom but can be not visible for the end user.

cy.get(HOST_INSIGHT_MISCONFIGURATION).should('exist');

cy.log('check if Misconfiguration preview title shown');
cy.get(HOST_INSIGHT_MISCONFIGURATION_TITLE).should('exist');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@animehart
Copy link
Copy Markdown
Contributor Author

animehart commented Aug 30, 2024

I will move the cypress test in separate ticket/PR then as it seems that there's quite a lot of stuff to do (too much for this 1 PR)

…eeds to be done before we are able to run cypress on ci, will do this on separate PR later on
…n' of github.com:animehart/kibana into misconfiguration-preview-refactor-phase-4-implementation
Copy link
Copy Markdown
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.

just a few more comments

) => {
const passed = buckets.find((bucket) => bucket?.key === 'passed');
const failed = buckets.find((bucket) => bucket?.key === 'failed');
const noStatus = buckets.find((bucket) => bucket?.key === 'unknown');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it seems inconsistent to use noStatus pointing to unknown, I think it could be unknown instead.

Comment on lines +52 to +64
passed: { match: { 'result.evaluation': 'passed' } },
failed: { match: { 'result.evaluation': 'failed' } },
},
},
},
});

export const getMisconfigurationAggregationCount = (
buckets: Array<estypes.AggregationsStringRareTermsBucketKeys | undefined>
) => {
const passed = buckets.find((bucket) => bucket?.key === 'passed');
const failed = buckets.find((bucket) => bucket?.key === 'failed');
const noStatus = buckets.find((bucket) => bucket?.key === 'unknown');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

better to avoid those magic strings to avoid potential typos and improve maintainability, what about defining those status in a constant:

const RESULT_EVALUATION = {
  PASSED: 'passed',
  FAILED: 'failed',
  UNKNOWN: 'unknown',
};

export const getFindingsCountAggQueryMisconfigurationPreview = () => ({
  count: {
    filters: {
      other_bucket_key: RESULT_EVALUATION.UNKNOWN,
      filters: {
        [RESULT_EVALUATION.PASSED]: { match: { 'result.evaluation': RESULT_EVALUATION.PASSED } },
        [RESULT_EVALUATION.FAILED]: { match: { 'result.evaluation': RESULT_EVALUATION.FAILED } },
      },
    },
  },
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: maybe this can be improved to use a single .reducer function instead of 3 .find functions.

<EuiTitle
size="s"
css={css`
font-weight: ${euiTheme.font.weight.bold};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isn't EuiTitle bold by default?

Comment on lines +132 to +137
count: getMisconfigurationAggregationCount(
Object.entries(aggregations.count.buckets).map(([key, value]) => ({
key,
doc_count: value.doc_count || 0,
}))
),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since we already have a getMisconfigurationAggregationCount function, it's better to have it handle the object parsing so the function is easier to consume:

return {
    count: getMisconfigurationAggregationCount(aggregations.count.buckets)
};

Comment on lines +26 to +29
id="observedEntity-accordion"
data-test-subj="entityInsightTestSubj"
buttonProps={{
'data-test-subj': 'observedEntity-accordion-button',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

better avoid using existing identifiers:

Suggested change
id="observedEntity-accordion"
data-test-subj="entityInsightTestSubj"
buttonProps={{
'data-test-subj': 'observedEntity-accordion-button',
id="entityInsight-accordion"
data-test-subj="entityInsightTestSubj"
buttonProps={{
'data-test-subj': 'entityInsight-accordion-button',

Comment on lines +53 to +55
css={css`
font-weight: ${euiTheme.font.weight.bold};
`}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same question about the EuiTitle

…n' of github.com:animehart/kibana into misconfiguration-preview-refactor-phase-4-implementation
@animehart animehart requested a review from opauloh September 4, 2024 07:05
@kibana-ci
Copy link
Copy Markdown

kibana-ci commented Sep 4, 2024

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #8 / CasesParamsFields renders all params fields are rendered

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 5660 5673 +13

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
@kbn/cloud-security-posture-common 49 52 +3

Async chunks

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

id before after diff
securitySolution 20.7MB 20.7MB +33.5KB
Unknown metric groups

API count

id before after diff
@kbn/cloud-security-posture-common 49 52 +3

History

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

Copy link
Copy Markdown
Contributor

@maxcold maxcold left a comment

Choose a reason for hiding this comment

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

Small visual bug, otherwise looks good. Please don't forget to add a work item of adding e2e cypress tests in case you don't plan to do it right away in the follow up PR

Screenshot 2024-09-04 at 13 39 26

@animehart animehart merged commit 8b7d965 into elastic:main Sep 4, 2024
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Sep 4, 2024
animehart added a commit that referenced this pull request Sep 6, 2024
…lugin PHASE 1 (#192114)

## Summary

In an attempt to make Reviewing easier and more accurate, the
implementation of Misconfiguration Data grid on Host.name flyout in
Alerts Page will be split into 2 Phases

Phase 1: Move Functions, Utils or Helpers, Hooks, constants to Package
Phase 2: Implementing the feature

This is Phase 1 of the process

This PR also include a small bug fix mentioned here
#191677 (review)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting ci:project-deploy-security Create a Security Serverless Project release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related v8.16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants