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

Simplify Collection; Add prefetch vulnerabilities step #124

Merged
merged 14 commits into from
May 14, 2024

Conversation

zemberdotnet
Copy link
Member

Description

This PR is intended to simplify collection of data by:

  • removing cross step dependencies and data
  • adding a prefetch vulnerabilities step
  • fixing iterateVulnerabilities control flow

const assetEntity = createIntegrationEntity({
entityData: {
source: {},
source: {
vulnerabilities: asset.vulnerabilities,
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding just the vulnerabilities part to rawData will simplify data collection later allowing us to not build the assetVulnCountMap

@@ -33,16 +31,13 @@ export async function fetchSiteAssets({
await apiClient.iterateSiteAssets(
siteEntity.id as string,
async (assets) => {
const siteAssetRelationships: ReturnType<
typeof createDirectRelationship
>[] = [];
Copy link
Member Author

Choose a reason for hiding this comment

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

No longer keeping these in memory. Just writing them like normal to the jobState.

Comment on lines +14 to +24
return {
_key: getAssetVulnerabilityKey(assetId, finding.id),
_type: entities.FINDING._type,
_class: entities.FINDING._class,
id: `${finding.id}`,
name: finding.id,
category: 'host',
open: finding.status === VulnerabilityState.VULNERABLE ? true : undefined,
severity: vulnerability.severity,
numericSeverity: vulnerability.numericSeverity,
};
Copy link
Member Author

Choose a reason for hiding this comment

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

Creating entity manually to avoid the extra allocation that createIntegrationEntity does. Also dropping rawData for the moment.

}

export async function fetchAssetVulnerabilityFindings(
export async function prefetchVulnerabilities(
Copy link
Member Author

Choose a reason for hiding this comment

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

Prefetch vulnerabilities is designed to be able to run as soon as the integration starts and alongside any other steps. It will collect and store the vulnerabilities as entities on disk. It's results will be used later by the vulnerabilities step where it will first try to get it from the cache and then collect it individually if it isn't found.

Comment on lines +96 to +106
if (severityMask === 0 && asset.vulnerabilities.total) {
return true;
} else if (
severityMask === 1 &&
(asset.vulnerabilities.critical || asset.vulnerabilities.severe)
) {
return true;
} else if (severityMask === 2 && asset.vulnerabilities.critical) {
return true;
}
return false;
Copy link
Member Author

Choose a reason for hiding this comment

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

If someone picks Critical & Moderate this will fail.

@zemberdotnet zemberdotnet merged commit 143dfbc into main May 14, 2024
8 checks passed
@zemberdotnet zemberdotnet deleted the INT-10872-improve-collection branch May 14, 2024 22:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants