-
-
Notifications
You must be signed in to change notification settings - Fork 64
Report with results of both SCA and SAST from Jenkins Plugin #117
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
Open
swatiawate1
wants to merge
3
commits into
march23-integration
Choose a base branch
from
plug_49_sca_report
base: march23-integration
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,6 +155,7 @@ public class CxScanBuilder extends Builder implements SimpleBuildStep { | |
| private boolean failBuildOnNewResults; | ||
| private String failBuildOnNewSeverity; | ||
| private boolean generatePdfReport; | ||
| private boolean generateScaReport; | ||
| private boolean enableProjectPolicyEnforcement; | ||
| @Nullable | ||
| private Integer osaHighThreshold; | ||
|
|
@@ -194,6 +195,7 @@ public class CxScanBuilder extends Builder implements SimpleBuildStep { | |
| CxLoggerAdapter log; | ||
|
|
||
| private JobStatusOnError jobStatusOnError; | ||
| private ScaReportFormat scaReportFormat; | ||
| private String exclusionsSetting; | ||
| private String thresholdSettings; | ||
| private Result vulnerabilityThresholdResult; | ||
|
|
@@ -223,6 +225,7 @@ public CxScanBuilder( | |
| Boolean sastEnabled, | ||
| @Nullable String preset, | ||
| JobStatusOnError jobStatusOnError, | ||
| ScaReportFormat scaReportFormat, | ||
| boolean presetSpecified, | ||
| String exclusionsSetting, | ||
| @Nullable String excludeFolders, | ||
|
|
@@ -245,6 +248,7 @@ public CxScanBuilder( | |
| @Nullable Integer osaMediumThreshold, | ||
| @Nullable Integer osaLowThreshold, | ||
| boolean generatePdfReport, | ||
| boolean generateScaReport, | ||
| boolean enableProjectPolicyEnforcement, | ||
| String thresholdSettings, | ||
| String vulnerabilityThresholdResult, | ||
|
|
@@ -271,6 +275,7 @@ public CxScanBuilder( | |
| this.sastEnabled = sastEnabled; | ||
| this.preset = (preset != null && !preset.startsWith("Provide Checkmarx")) ? preset : null; | ||
| this.jobStatusOnError = jobStatusOnError; | ||
| this.scaReportFormat = scaReportFormat; | ||
| this.presetSpecified = presetSpecified; | ||
| this.exclusionsSetting = exclusionsSetting; | ||
| this.globalExclusions = "global".equals(exclusionsSetting); | ||
|
|
@@ -294,6 +299,7 @@ public CxScanBuilder( | |
| this.osaMediumThreshold = osaMediumThreshold; | ||
| this.osaLowThreshold = osaLowThreshold; | ||
| this.generatePdfReport = generatePdfReport; | ||
| this.generateScaReport = generateScaReport; | ||
| this.enableProjectPolicyEnforcement = enableProjectPolicyEnforcement; | ||
| this.thresholdSettings = thresholdSettings; | ||
| if (vulnerabilityThresholdResult != null) { | ||
|
|
@@ -590,6 +596,10 @@ public void setOsaInstallBeforeScan(boolean osaInstallBeforeScan) { | |
| public boolean isGeneratePdfReport() { | ||
| return generatePdfReport; | ||
| } | ||
|
|
||
| public boolean isGenerateScaReport() { | ||
| return generateScaReport; | ||
| } | ||
|
|
||
| public boolean isEnableProjectPolicyEnforcement() { | ||
| return enableProjectPolicyEnforcement; | ||
|
|
@@ -747,6 +757,11 @@ public void setLowThreshold(@Nullable Integer lowThreshold) { | |
| public void setGeneratePdfReport(boolean generatePdfReport) { | ||
| this.generatePdfReport = generatePdfReport; | ||
| } | ||
|
|
||
| @DataBoundSetter | ||
| public void setGenerateScaReport(boolean generateScaReport) { | ||
| this.generateScaReport = generateScaReport; | ||
| } | ||
|
|
||
| @DataBoundSetter | ||
| public void setEnableProjectPolicyEnforcement(boolean enableProjectPolicyEnforcement) { | ||
|
|
@@ -911,8 +926,10 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul | |
| EnvVars env = run.getEnvironment(listener); | ||
| setJvmVars(env); | ||
| Map<String, String> fsaVars = getAllFsaVars(env); | ||
| CxScanConfig config = resolveConfiguration(run, descriptor, env, log); | ||
|
|
||
| CxScanConfig config; | ||
| try { | ||
| config = resolveConfiguration(run, descriptor, env, log); | ||
|
|
||
| if (configAsCode) { | ||
| try { | ||
| overrideConfigAsCode(config, workspace); | ||
|
|
@@ -975,6 +992,30 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul | |
| scanResults.getSastResults().setSastPDFLink(pdfUrl); | ||
| } | ||
| } | ||
|
|
||
| if (config.isGenerateScaReport()) { | ||
| if(config.getScaReportFormat() != null) { | ||
| String path = ""; | ||
| // run.getUrl() returns a URL path similar to job/MyJobName/124/ | ||
| //getRootUrl() will return the value of "Manage Jenkins->configuration->Jenkins URL" | ||
| String baseUrl = Jenkins.getInstance().getRootUrl(); | ||
| if (StringUtils.isNotEmpty(baseUrl)) { | ||
| URL parsedUrl = new URL(baseUrl); | ||
| path = parsedUrl.getPath(); | ||
| } | ||
| if (!(path.equals("/"))) { | ||
| //to handle this Jenkins root url,EX: http://localhost:8081/jenkins | ||
| Path pdfUrlPath = Paths.get(path, run.getUrl(), PDF_URL); | ||
| scanResults.getScaResults().setScaPDFLink(pdfUrlPath.toString()); | ||
| } else { | ||
| //to handle this Jenkins root url,EX: http://localhost:8081/ | ||
| String pdfUrl = String.format(PDF_URL_TEMPLATE, run.getUrl()); | ||
| scanResults.getScaResults().setScaPDFLink(pdfUrl); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| //in case of async mode, do not create reports (only the report of the latest scan) | ||
| //and don't assert threshold vulnerabilities | ||
|
|
@@ -1004,7 +1045,7 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul | |
| if (osaResults != null && osaResults.isOsaResultsReady()) { | ||
| createOsaReports(osaResults, checkmarxBuildDir); | ||
| } else if (scaResults != null && scaResults.isScaResultReady()) { | ||
| createScaReports(scaResults, checkmarxBuildDir); | ||
| createScaReports(scaResults, checkmarxBuildDir, workspace); | ||
| } | ||
| return; | ||
| } | ||
|
|
@@ -1015,7 +1056,11 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul | |
| cxScanResult.setHtmlReportName(reportName); | ||
| } | ||
| run.addAction(cxScanResult); | ||
| } catch (ConfigurationException e1) { | ||
| e1.printStackTrace(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private void overrideConfigAsCode(CxScanConfig config, FilePath workspace) throws ConfigurationException { | ||
| String configFilePath = | ||
|
|
@@ -1242,10 +1287,19 @@ private void mapSastConfiguration(Optional<SastConfig> sast, CxScanConfig scanCo | |
| } | ||
|
|
||
|
|
||
| private void createScaReports(AstScaResults scaResults, File checkmarxBuildDir) { | ||
| private void createScaReports(AstScaResults scaResults, File checkmarxBuildDir, @Nonnull FilePath workspace) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i dont see use of new argument workspace in this method. Kindly check if it is required. |
||
| writeJsonObjectToFile(scaResults.getSummary(), new File(checkmarxBuildDir, SCA_SUMMERY_JSON), "OSA summary json report"); | ||
| writeJsonObjectToFile(scaResults.getPackages(), new File(checkmarxBuildDir, SCA_LIBRARIES_JSON), "OSA libraries json report"); | ||
| writeJsonObjectToFile(scaResults.getFindings(), new File(checkmarxBuildDir, SCA_VULNERABILITIES_JSON), "OSA vulnerabilities json report"); | ||
|
|
||
| if (scaResults.getPDFReport() != null) { | ||
| File pdfReportFile = new File(checkmarxBuildDir, CxScanResult.PDF_REPORT_NAME); | ||
| try { | ||
| FileUtils.writeByteArrayToFile(pdfReportFile, scaResults.getPDFReport()); | ||
| } catch (IOException e) { | ||
| log.warn("Failed to write SCA PDF report to workspace: " + e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1330,7 +1384,7 @@ private Boolean verifyCustomCharacters(String inputString) { | |
| } | ||
| return true; | ||
| } | ||
| private CxScanConfig resolveConfiguration(Run<?, ?> run, DescriptorImpl descriptor, EnvVars env, CxLoggerAdapter log) throws IOException { | ||
| private CxScanConfig resolveConfiguration(Run<?, ?> run, DescriptorImpl descriptor, EnvVars env, CxLoggerAdapter log) throws IOException, ConfigurationException { | ||
| CxScanConfig ret = new CxScanConfig(); | ||
|
|
||
| ret.setIsOverrideProjectSetting(overrideProjectSetting); | ||
|
|
@@ -1498,6 +1552,20 @@ private CxScanConfig resolveConfiguration(Run<?, ?> run, DescriptorImpl descript | |
| } | ||
| ret.setEnablePolicyViolations(enableProjectPolicyEnforcement); | ||
|
|
||
| if (!ret.isAstScaEnabled() && !ret.getSynchronous()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check if the condition should be && or || |
||
| generateScaReport = false; | ||
| } | ||
| if (ret.isAstScaEnabled()) { | ||
| ret.setGenerateScaReport(generateScaReport); | ||
| ret.setScaReportFormat(scaReportFormat.name()); | ||
| if (ret.getScaReportFormat() != null && !ret.getScaReportFormat().isEmpty()) { | ||
| ret.setGenerateScaReport(true); | ||
| } else { | ||
| ret.setGenerateScaReport(false); | ||
| throw new ConfigurationException("Invalid SCA report format:" + scaReportFormat + "."); | ||
| } | ||
| } | ||
|
|
||
| // Set the Continue build flag to Configuration object if Option from UI is choosen as useContinueBuildOnError | ||
| if (useContinueBuildOnError(getDescriptor())) { | ||
| ret.setContinueBuild(Boolean.TRUE); | ||
|
|
@@ -1791,6 +1859,7 @@ private void printConfiguration(CxScanConfig config, CxLoggerAdapter log) { | |
| log.info("CxSCA web app URL: " + config.getAstScaConfig().getWebAppUrl()); | ||
| log.info("Account: " + config.getAstScaConfig().getTenant()); | ||
| log.info("Team: " + config.getAstScaConfig().getTeamPath()); | ||
| log.info("is generate SCA report: "+ config.isGenerateScaReport()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2139,8 +2208,19 @@ protected Object readResolve() { | |
| public DescriptorImpl getDescriptor() { | ||
| return (DescriptorImpl) super.getDescriptor(); | ||
| } | ||
|
|
||
| public ScaReportFormat getScaReportFormat() { | ||
| return scaReportFormat; | ||
| } | ||
|
|
||
| @DataBoundSetter | ||
| public void setScaReportFormat(ScaReportFormat scaReportFormat) { | ||
| this.scaReportFormat = scaReportFormat; | ||
| } | ||
|
|
||
| @Extension | ||
|
|
||
|
|
||
| @Extension | ||
| public static final class DescriptorImpl extends BuildStepDescriptor<Builder> { | ||
|
|
||
| public static final String DEFAULT_FILTER_PATTERNS = CxConfig.defaultFilterPattern(); | ||
|
|
@@ -2642,6 +2722,20 @@ public FormValidation doCheckIncremental(@QueryParameter boolean value, @QueryPa | |
|
|
||
| return FormValidation.ok(); | ||
| } | ||
| @POST | ||
| public FormValidation doCheckGenerateScaReport(@QueryParameter boolean value, @QueryParameter boolean dependencyScanConfig, @QueryParameter boolean generateScaReport,@AncestorInPath Item item) { | ||
| if (item == null) { | ||
| return FormValidation.ok(); | ||
| } | ||
| item.checkPermission(Item.CONFIGURE); | ||
| if (!dependencyScanConfig && value) { | ||
| generateScaReport=false; | ||
| dependencyScanConfig = false; | ||
| return FormValidation.error("Enable dependency scanner as SCA"); | ||
| } | ||
|
|
||
| return FormValidation.ok(); | ||
| } | ||
|
|
||
| @POST | ||
| public FormValidation doTestScaSASTConnection(@QueryParameter final String scaSastServerUrl, @QueryParameter final String password, | ||
|
|
@@ -3068,6 +3162,19 @@ public ListBoxModel doFillVulnerabilityThresholdResultItems(@AncestorInPath Item | |
|
|
||
| return listBoxModel; | ||
| } | ||
|
|
||
| @POST | ||
| public ListBoxModel doFillScaReportFormat(@AncestorInPath Item item) { | ||
| if (item == null) { | ||
| return new ListBoxModel(); | ||
| } | ||
| item.checkPermission(Item.CONFIGURE); | ||
| ListBoxModel listBoxModel = new ListBoxModel(); | ||
| for (ScaReportFormat status : ScaReportFormat.values()) { | ||
| listBoxModel.add(new ListBoxModel.Option(status.getDisplayName(), status.name())); | ||
| } | ||
| return listBoxModel; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
|
|
@@ -3371,4 +3478,4 @@ public void setDependencyScanConfig(DependencyScanConfig dependencyScanConfig) { | |
| this.dependencyScanConfig = dependencyScanConfig; | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.checkmarx.jenkins; | ||
|
|
||
| public enum ScaReportFormat { | ||
| PDF("PDF"), XML("XML"), CSV("CSV"), JSON("JSON"), cyclonedxjson("cyclonedxjson"), cyclonedxxml("cyclonedxxml"); | ||
|
|
||
| private final String displayName; | ||
|
|
||
| ScaReportFormat(String displayName) { | ||
| this.displayName = displayName; | ||
| } | ||
|
|
||
| public String getDisplayName() { | ||
| return displayName; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
src/main/resources/com/checkmarx/jenkins/CxScanBuilder/help-generateScaReport.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <div> | ||
| Downloads a report with scan results from the Checkmarx server. The report is available via a link on "Checkmarx Scan Results" page. | ||
| </div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if additional argument workspace is needed in this method.