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

ASA 8404 (#218) #220

Merged
merged 24 commits into from
Jul 30, 2024
Merged

ASA 8404 (#218) #220

merged 24 commits into from
Jul 30, 2024

Conversation

vishalhcl-5960
Copy link
Collaborator

Include-SCA implementation

Include-SCA implementation
@vishalhcl-5960 vishalhcl-5960 requested a review from mattmurp June 25, 2024 16:33
Copy link
Contributor

@mattmurp mattmurp left a comment

Choose a reason for hiding this comment

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

I understand that a lot of the changes here were made in order to run 2 scans at once (i.e. call the perform method twice). However, there is a lot of if/else/if/else logic that's hard to follow and there are a lot of classes (e.g. AppScanBuildStep, ResultsRetriever) that now have specific knowledge of different types of scans.
One solution to these problems would be to create a new type of scan that will run both a SAST and SCA scan.

public boolean hasOptions() {
return m_hasOptions;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The methods getHasOptionsUploadDirect() and hasOptionsUploadDirect() do the same thing. Why do we have 2 methods? Also, upload direct is specific to SAST scans, so why are these methods being added to the Scanner base class that is used by DAST and SCA, as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay sure, added the "hasOptionsUploadDirect()" methods in the StaticAnalyzer class.

}

public boolean getHasOptions() {
return m_hasOptions;
}

public boolean hasOptions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method returns the same thing as the existing method getHasOptions(). Why do we need it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"hasOptions" was used as a checker method in the jelly files. Now, using the getHasOptions() itself in the jelly files too.

@@ -23,15 +23,29 @@ public abstract class Scanner extends AbstractDescribableImpl<Scanner> implement

private String m_target;
private boolean m_hasOptions;
private boolean m_hasOptionsUploadDirect;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we adding a SAST specific property to the base Scanner class?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moving this property to the StaticAnalyzer class.

@@ -235,11 +236,33 @@ public boolean getPersonalScan() {
public DescriptorImpl getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
}

//to execute SAST & SCA scans consecutively, 1st perform method call to execute SAST then after changing the scan type to SCA
private void includeSCAImplementation(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

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

These checks are all specific to StaticAnalyzer to see if we should only run SCA or if we should include SCA. I suggest moving all of these checks to the StaticAnalyzer.getProperties() method. If necessary, the getProperties() method can be overloaded with a version that takes in an IAuthenticationProvider for doing any checks that require it.

Copy link
Collaborator Author

@vishalhcl-5960 vishalhcl-5960 Jul 3, 2024

Choose a reason for hiding this comment

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

Moved the validations in the respective scan classes by adding an "validations()" method in the abstract class.

@@ -309,6 +338,8 @@ private void validations(boolean isAppScan360, Map<String, String> properties, I
if(isAppScan360) {
if (m_type.equals(Scanner.DYNAMIC_ANALYZER) && properties.containsKey(Scanner.PRESENCE_ID)) {
throw new AbortException(Messages.error_presence_AppScan360());
} if(properties.containsKey(CoreConstants.INCLUDE_SCA)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can all of these validations be moved to the getProperties() method of the individual scanners?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved the validations in the respective scan classes by adding an "validations()" method in the abstract class.

@@ -48,4 +61,55 @@ private boolean exceedsThreshold(String type, int threshold) {
return false;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The additional code in this method requires the ResultsInspector to be aware of different types of scans. I suggest doing this differently. Some options would be:

  • Subclassing the ResultsInspector (e.g. create a new CombinedResultsInspector).
  • Using 2 ResultsInpector instances.
  • Creating a new type of IResultsProvider that can handle 2 sets of results.
  • Updating the existing NonCompliantIssuesResultProvider to handle 2 sets of results.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have created a new class "CombinedResultsInspector" which is being extended from the base "ResultsInspector" class.

@@ -328,89 +364,122 @@ private void validations(boolean isAppScan360, Map<String, String> properties, I
throw new AbortException(Messages.error_url_validation(target));
}
}

private String updatedScanTypesForBuildSummaryName(String scanType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than having the AppScanBuildStep figure out this logic, I suggest adding a new method to the Scanner class. Something like getShortName() that returns these values.

Copy link
Collaborator Author

@vishalhcl-5960 vishalhcl-5960 Jul 2, 2024

Choose a reason for hiding this comment

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

If i add this method in the Scanner class from which i have to call this method in respective scan class. During the inlcudeSCA(SAST+SCA) execution, I have to call this method during runtime as i am utilizing the same properties in the SCA scan runtime.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can define this method in the Utils class of the SDK.

super(target, hasOptions);
m_openSourceOnly=false;
m_sourceCodeOnly=false;
m_scanMethod=CoreConstants.CREATE_IRX;
m_scanSpeed="";
}
m_includeSCAGenerateIRX="true";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason we need both m_includeSCAGenerateIRX and m_includeSCAUploadDirect? Shouldn't there just be m_includeSCA and m_uploadDirect?

Copy link
Collaborator Author

@vishalhcl-5960 vishalhcl-5960 Jul 4, 2024

Choose a reason for hiding this comment

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

I think it is better to have two different names for these checkbox as the position of these checks are different in jelly file, it will hamper the value of the checkbox if one of the check is false.

@@ -38,7 +40,9 @@ public String getTarget() {
}

public abstract Map<String, String> getProperties(VariableResolver<String> resolver) throws AbortException;


public abstract void validations(IAuthenticationProvider authProvider, Map<String, String> properties, IProgress progress) throws AbortException;
Copy link
Contributor

Choose a reason for hiding this comment

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

The function name should be a verb, like "validate" or "validateSettings".

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, Now, Using the "validateSettings()" method name.

@@ -38,7 +40,9 @@ public String getTarget() {
}

public abstract Map<String, String> getProperties(VariableResolver<String> resolver) throws AbortException;


public abstract void validations(IAuthenticationProvider authProvider, Map<String, String> properties, IProgress progress) throws AbortException;
Copy link
Contributor

Choose a reason for hiding this comment

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

In all instances, the IAuthenticationProvider is being passed in and then cast to a JenkinsAuthenticationProvider just to check if this is AppScan 360. Why not just pass a boolean here instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In DynamicAnalyzer class we are doing the URL validity check & for that we need to call the getProxy() method from authProvider class. Instead of passing the IAuthenticationProvider, I will pass the JenkinsAuthenaticationProvider itself.

@@ -196,8 +198,18 @@ public String upgradeLoginScenario(){
}
}

public void validations(IAuthenticationProvider authProvider, Map<String, String> properties, IProgress progress) throws AbortException {
if (((JenkinsAuthenticationProvider) authProvider).isAppScan360()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The 2 "if" conditions should be "anded" together rather than nesting them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay, sure.

@@ -10,14 +10,13 @@

import com.hcl.appscan.sdk.results.IResultsProvider;

public class ResultsInspector {
public class ResultsInspector extends CombinedResultsInspector {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the ResultsInspector extend the CombinedResultsInseptor? It seems this should be the other way around, where the CombinedResultsInspector adds to the logic of the ResultsInspector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed the CombinedResultsInspector class as we are now handling the results in the SDK.

import java.util.List;
import java.util.Map;

public class CombinedResultsInspector {
Copy link
Contributor

Choose a reason for hiding this comment

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

The results inspector should not require knowledge of the scan type or issue types (there are mentions of totalCountSAST for example).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed the CombinedResultsInspector class as we are now handling the results in the SDK.

perform((Run<?,?>)build, launcher, listener);
return true;

//to execute SAST & SCA scans consecutively, 1st perform method call to execute SAST then after changing the scan type to SCA
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than having all of these checks for SCA and SAST and rather than trying to execute the perform() method twice, we should create a new scanner type in the SDK that will execute both a SAST scan and an SCA scan. That would eliminate the need for most, if not all, of these changes.

Copy link
Collaborator Author

@vishalhcl-5960 vishalhcl-5960 Jul 22, 2024

Choose a reason for hiding this comment

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

SAST_SCA class had been made in the SDK to handle the SAST+SCA scans execution.

@@ -151,7 +151,7 @@ public File getReport() {
}

private String getReportName() {
String name = (getScanType() + FileUtil.getValidFilename(getName())).replaceAll(" ", ""); //$NON-NLS-1$ //$NON-NLS-2$
String name = (FileUtil.getValidFilename(getName())).replaceAll(" ", ""); //$NON-NLS-1$ //$NON-NLS-2$
Copy link
Contributor

Choose a reason for hiding this comment

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

The extra ( ) should be removed around the FileUtil.getValidFileName() call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure, Matt.

warning.sca= Note: AppScan on Cloud (ASoC) now performs SAST and SCA analysis as separate scans. To execute an open-source only scan, use the Software Composition Analysis (SCA) scan type. The open-source only option will be removed from SAST scans in a future release.
error.url.dynamic.unsupported= Either your A360 instance does not support dynamic scans or the starting URL is invalid: {0}.
warning.sca= AppScan on Cloud (ASoC) now performs SAST and SCA analysis as separate scans. To execute an open-source only scan, use the Software Composition Analysis (SCA) scan type.
warning.include.sca.AppScan360= Only SAST scan execution takes place as SCA is applicable for AppScan on Cloud only.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you run these new messages by Jen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have reviewed the attached statement with Binoy, updating the warning message to "Only the SAST scan is being executed. SCA is only available with AppScan on Cloud and is not included in this job"

@@ -28,31 +32,40 @@ public class StaticAnalyzer extends Scanner {
private static final String STATIC_ANALYZER = "Static Analyzer"; //$NON-NLS-1$

private boolean m_openSourceOnly;
private String m_includeSCAGenerateIRX;
private boolean m_additionalOptionsUploadDirect;
private boolean m_includeSCAUploadDirect;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can simplify this with shorter variable names and we only need 2 new member variables:

private boolean m_includeSCA;
private boolean m_uploadDirect;

The value of m_includeSCAGenerateIRX is just m_includeSCA && !m_uploadDirect. Likewise, the value of m_includeSCAUploadDirect is just m_includeSCA && m_uploadDirect. So I don't think we need a third variable here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Matt, Are you referring that we should use the same name for both the checkbox(under "generateIRX" & "upload Files & folders" scan menthod) in config file?

  1. There is difference in the UI names for the both the checkboxes.
  2. Third variable is for the value of the optionalBlock checkbox under the "upload files & folders" scan method. We can remove that optionalBlock as it contains only 1 element into it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have changed the variable name for the additional option under "upload Files & folders" scan method. New variable name would be "m_hasOptionsUploadDirect".
Also, changed the variable type of the "m_includeSCAUploadDirect" to String so that we have a parity between the both checkboxes of "includeSCA".

Copy link
Contributor

@mattmurp mattmurp left a comment

Choose a reason for hiding this comment

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

There are too many hard coded strings for "true" and "false". When checking for boolean values from strings, you should use Boolean.parseBoolean(stringValue) and for setting a string to "true" or "false" you should use Boolean.toString(booleanValue).


@DataBoundSetter
public void setIncludeSCAGenerateIRX(String includeSCAGenerateIRX) {
if(getHasOptions() && includeSCAGenerateIRX.equals("true")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified to:
return getHashOptions() && Boolean.parseBoolean(includeSCAGenerateIRX);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, sure


@DataBoundSetter
public void setIncludeSCAUploadDirect(String includeSCAUploadDirect) {
if(m_hasOptionsUploadDirect && includeSCAUploadDirect.equals("true")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should use Boolean.parseBoolean(string).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, sure.

Copy link
Contributor

@mattmurp mattmurp left a comment

Choose a reason for hiding this comment

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

The StaticAnalyzer class needs to be cleaned up, but approving in order to get the release done.

@vishalhcl-5960 vishalhcl-5960 merged commit 06a676d into master Jul 30, 2024
3 checks passed
@vishalhcl-5960 vishalhcl-5960 deleted the ASA-8404 branch July 30, 2024 04:32
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.

2 participants