Skip to content

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

Merged
animehart merged 45 commits intoelastic:mainfrom
animehart:misconfiguration-preview-refactor-phase-3
Aug 28, 2024
Merged

[Cloud Security] Misconfiguration preview & Refactor CSP Plugin to include new package PHASE 3#191317
animehart merged 45 commits intoelastic:mainfrom
animehart:misconfiguration-preview-refactor-phase-3

Conversation

@animehart
Copy link
Copy Markdown
Contributor

@animehart animehart commented Aug 26, 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)

This is Phase 3 of the Process,
This also includes moving rule versions type

This PR is the continuation of this PR #190933

NOTE:
Merge phase 2 first before this

animehart and others added 24 commits August 20, 2024 15:31
…m:animehart/kibana into misconfiguration-preview-refactor-phase-2
…m:animehart/kibana into misconfiguration-preview-refactor-phase-2
…nt for types or interface to be directly from csp package now
…m:animehart/kibana into misconfiguration-preview-refactor-phase-2
… latest rule versions import on CSP plugin etc
@animehart
Copy link
Copy Markdown
Contributor Author

/ci

…ules are from rules/latest in common package instead of rules.ts, furthermore deleted unused file that was created during Phase 2
@animehart
Copy link
Copy Markdown
Contributor Author

/ci

@animehart
Copy link
Copy Markdown
Contributor Author

/ci

@animehart animehart requested review from a team as code owners August 27, 2024 07:30
@elasticmachine
Copy link
Copy Markdown
Contributor

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

Comment on lines +10 to +15
export const extractErrorMessage = (e: unknown, defaultMessage = 'Unknown Error'): string => {
if (e instanceof Error) return e.message;
if (typeof e === 'string') return e;

return defaultMessage; // TODO: i18n
};
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.

Let's fix this todo:

const defaultErrorMessage = i18n.translate('xpack.csp.common.utils.helpers.unknownError', {
  defaultMessage: 'Unknown Error',
});

export const extractErrorMessage = (e: unknown, fallbackMessage ?: string): string => {
  if (e instanceof Error) return e.message;
  if (typeof e === 'string') return e;

  return fallbackMessage ?? defaultErrorMessage;
};

Comment thread x-pack/packages/kbn-cloud-security-posture-common/utils/helpers.ts Outdated
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.

looks good overall, I only have some questions and nitpicks

Comment thread x-pack/packages/kbn-cloud-security-posture-common/utils/helpers.ts

export const useGetCspBenchmarkRulesStatesApi = () => {
const { http } = useKibana().services;
const { http } = useKibana<CoreStart & CspClientPluginStartDeps>().services;
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.

http is part of CoreStart so that's only what we need here:

const { http } = useKibana<CoreStart>().services;

options?: UseQueryOptions<CspSetupStatus, unknown, CspSetupStatus>
) => {
const { http } = useKibana().services;
const { http } = useKibana<CoreStart & CspClientPluginStartDeps>().services;
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.

Suggested change
const { http } = useKibana<CoreStart & CspClientPluginStartDeps>().services;
const { http } = useKibana<CoreStart>().services;

UpdatePackagePolicy,
} from '@kbn/fleet-plugin/common';
import type { BenchmarkRuleSelectParams } from '@kbn/cloud-security-posture-common/schema/rules/latest';
import type { BenchmarkRuleSelectParams as BenchmarkRuleSelectParamsV1 } from '@kbn/cloud-security-posture-common/schema/rules/v4';
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.

shouldn't be BenchmarkRuleSelectParamsV4?

Comment on lines +48 to +53
// export const extractErrorMessage = (e: unknown, defaultMessage = 'Unknown Error'): string => {
// if (e instanceof Error) return e.message;
// if (typeof e === 'string') return e;

return defaultMessage; // TODO: i18n
};
// return defaultMessage; // TODO: i18n
// };
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.

missed commented code

import { i18n } from '@kbn/i18n';
import { extractErrorMessage } from '../../../common/utils/helpers';
import { extractErrorMessage } from './helpers';

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.

shouldn't this file be in kbn-cloud-security-posture instead? A toast notification It's mainly a frontend function, not meant to be shared with the server.

…m:animehart/kibana into misconfiguration-preview-refactor-phase-3
@animehart animehart requested a review from opauloh August 28, 2024 06:46
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.

lgtm, one small comment on the duplicated types file

* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
export type BenchmarksCisId = 'cis_k8s' | 'cis_azure' | 'cis_aws' | 'cis_eks' | 'cis_gcp';
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.

let's either put it under ./types.ts or another way around split types.ts into meaningful files, eg. types/status.ts and types/finding.ts

@maxcold maxcold added the ci:project-deploy-security Create a Security Serverless Project label Aug 28, 2024
@maxcold
Copy link
Copy Markdown
Contributor

maxcold commented Aug 28, 2024

/ci

@animehart
Copy link
Copy Markdown
Contributor Author

/ci

1 similar comment
@animehart
Copy link
Copy Markdown
Contributor Author

/ci

@animehart
Copy link
Copy Markdown
Contributor Author

/ci

1 similar comment
@animehart
Copy link
Copy Markdown
Contributor Author

/ci

@kibana-ci
Copy link
Copy Markdown

kibana-ci commented Aug 28, 2024

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #35 / Cloud Security Posture Test adding Cloud Security Posture Integrations CSPM AWS CIS_AWS Organization Manual Direct Access CIS_AWS Organization Manual Direct Access Workflow

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cloudSecurityPosture 706 709 +3

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 19 22 +3
@kbn/cloud-security-posture-common 45 49 +4
total +7

Async chunks

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

id before after diff
cloudSecurityPosture 481.1KB 480.7KB -385.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cloudSecurityPosture 17.0KB 17.6KB +545.0B
Unknown metric groups

API count

id before after diff
@kbn/cloud-security-posture 19 22 +3
@kbn/cloud-security-posture-common 45 49 +4
total +7

History

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

@animehart animehart merged commit a78c69b into elastic:main Aug 28, 2024
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label Aug 28, 2024
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.

6 participants