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] Versioning CSP rules type and api #172674

Merged
merged 20 commits into from
Dec 7, 2023

Conversation

CohenIdo
Copy link
Contributor

@CohenIdo CohenIdo commented Dec 6, 2023

This PR includes:

  • Versioning for types of CSP rules
  • Versioning for the CSP rules find API
  • Global renaming of csp_rule_template to csp_benchmark_rule throughout the code.

@CohenIdo CohenIdo added the release_note:skip Skip the PR/issue when compiling release notes label Dec 6, 2023
@CohenIdo CohenIdo marked this pull request as ready for review December 6, 2023 13:07
@CohenIdo CohenIdo requested a review from a team as a code owner December 6, 2023 13:07
Copy link
Contributor

@kfirpeled kfirpeled left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

I added bunch of nit's
Prefer to use import type when possible

And I think of maybe rename CspRule to CspBenchmarkRule. To give more context to any kibana developer outside of our team. wdyt?

x-pack/plugins/cloud_security_posture/common/types.ts Outdated Show resolved Hide resolved
x-pack/plugins/cloud_security_posture/common/types.ts Outdated Show resolved Hide resolved
request: {
query: findCspRuleRequest,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider to add response validation on the next PR/open a tech debt issue

Copy link
Contributor Author

@CohenIdo CohenIdo Dec 7, 2023

Choose a reason for hiding this comment

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

Comment on lines 26 to 51
export const getSortedCspRulesTemplates = (cspRulesTemplates: CspRule[]) => {
return cspRulesTemplates.slice().sort((a, b) => {
const ruleNumberA = a?.metadata?.benchmark?.rule_number;
const ruleNumberB = b?.metadata?.benchmark?.rule_number;

const versionA = semverValid(ruleNumberA);
const versionB = semverValid(ruleNumberB);

if (versionA !== null && versionB !== null) {
return semverCompare(versionA, versionB);
} else {
return String(ruleNumberA).localeCompare(String(ruleNumberB));
}
});
};

export const getBenchmarkIdFromPackagePolicyId = async (
soClient: SavedObjectsClientContract,
packagePolicyId: string
): Promise<string> => {
const res = await soClient.get<NewPackagePolicy>(
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
packagePolicyId
);
return getBenchmarkFromPackagePolicy(res.attributes.inputs);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

move the a utility.ts/common.ts under the same folder to prevent circular dependencies

@CohenIdo
Copy link
Contributor Author

CohenIdo commented Dec 6, 2023

maybe rename CspRule to CspBenchmarkRule. To give more context to any kibana developer outside of our team. wdyt?

I agree, will do.

@CohenIdo CohenIdo force-pushed the rules-types-versioning branch from 95324e8 to 8cd05f0 Compare December 6, 2023 17:48
Copy link
Contributor

@kfirpeled kfirpeled left a comment

Choose a reason for hiding this comment

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

💯
added another couple of comments

@@ -7,20 +7,20 @@
import React, { useState, useMemo } from 'react';
import { EuiPanel, EuiSpacer } from '@elastic/eui';
import { useParams } from 'react-router-dom';
import { CspRuleTemplate } from '../../../common/schemas';
import { CspBenchmarkRule } from '../../../common/types/latest';
Copy link
Contributor

Choose a reason for hiding this comment

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

use import type

Comment on lines 26 to 51
export const getSortedCspBenchmarkRulesTemplates = (cspBenchmarkRules: CspBenchmarkRule[]) => {
return cspBenchmarkRules.slice().sort((a, b) => {
const ruleNumberA = a?.metadata?.benchmark?.rule_number;
const ruleNumberB = b?.metadata?.benchmark?.rule_number;

const versionA = semverValid(ruleNumberA);
const versionB = semverValid(ruleNumberB);

if (versionA !== null && versionB !== null) {
return semverCompare(versionA, versionB);
} else {
return String(ruleNumberA).localeCompare(String(ruleNumberB));
}
});
};

export const getBenchmarkIdFromPackagePolicyId = async (
soClient: SavedObjectsClientContract,
packagePolicyId: string
): Promise<string> => {
const res = await soClient.get<NewPackagePolicy>(
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
packagePolicyId
);
return getBenchmarkFromPackagePolicy(res.attributes.inputs);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

move the a utility.ts/common.ts under the same folder to prevent circular dependencies

@CohenIdo CohenIdo force-pushed the rules-types-versioning branch from 2cad88c to fcf536a Compare December 7, 2023 08:38
@CohenIdo CohenIdo force-pushed the rules-types-versioning branch from 0b31a76 to 92a0e64 Compare December 7, 2023 09:20
@CohenIdo CohenIdo force-pushed the rules-types-versioning branch from 67aef70 to d9d2723 Compare December 7, 2023 09:49
@CohenIdo CohenIdo force-pushed the rules-types-versioning branch from fdd45a0 to cbfab6d Compare December 7, 2023 12:19
@CohenIdo CohenIdo force-pushed the rules-types-versioning branch from 06f697a to 636d53a Compare December 7, 2023 14:23
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

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

id before after diff
cloudSecurityPosture 446.3KB 446.3KB +8.0B

History

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

@CohenIdo CohenIdo merged commit d4701aa into elastic:main Dec 7, 2023
37 checks passed
@kibanamachine kibanamachine added v8.13.0 backport:skip This commit does not require backporting labels Dec 7, 2023
FindCspBenchmarkRuleRequest,
FindCspBenchmarkRuleResponse,
findCspBenchmarkRuleRequestSchema,
} from '../../../../common/types/latest';
Copy link
Contributor

Choose a reason for hiding this comment

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

better to explicitly use v1 here instead
think of the use case of adding a newer version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 will do as part of #173066

Copy link
Contributor Author

Choose a reason for hiding this comment

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

import { PACKAGE_POLICY_SAVED_OBJECT_TYPE } from '../../benchmarks/benchmarks';
import { getBenchmarkFromPackagePolicy } from '../../../../common/utils/helpers';

import type {
Copy link
Contributor

@kfirpeled kfirpeled Dec 12, 2023

Choose a reason for hiding this comment

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

this should explicitly use v1 here instead (FindCspBenchmarkRuleRequest and FindCspBenchmarkRuleResponse only. the SO should always be the latest)
think of the use case of adding a newer version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 will do as part of #173066

@bhavyarm bhavyarm added the Team:Cloud Security Cloud Security team related label Jan 17, 2024
@elasticmachine
Copy link
Contributor

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

@bhavyarm
Copy link
Contributor

Hey team, bunch of PRs were missing the team label. I added the labels in. Thanks!

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 v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants