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

Implement experimental Bandit scan check #762

Merged
merged 9 commits into from
Mar 29, 2022

Conversation

sourabhsparkala
Copy link
Member

Fixes #729

Copy link
Member

@SebastianWolf-SAP SebastianWolf-SAP left a comment

Choose a reason for hiding this comment

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

No detailed knowledge about Bandit and also not that much time to dig deeper here, so unfortunately I can't give an explicit approval.
However, code looks very good, I agree with the weighting of the Bandit score, also the test seem to cover the most relevant aspects. As the checks ran through properly, it should be OK...

@sourabhsparkala sourabhsparkala added the enhancement New feature or request label Jan 5, 2022
@sourabhsparkala sourabhsparkala added this to the 1.8.0 milestone Jan 5, 2022
Copy link
Collaborator

@artem-smotrakov artem-smotrakov left a comment

Choose a reason for hiding this comment

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

I've left several comments you may want to consider. Otherwise, looks fine. I can't officially approve the PR anymore because I am not in the org.

= Arrays.asList(".yaml", ".yml");

/**
* A step in a GitHub action that triggers analysis with CodeQL.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess, you need to update this comment.

* <li>{@link OssFeatures#USES_BANDIT_SCAN_CHECKS}</li>
* </ul>
*/
public class BanditDataProvider extends GitHubCachingDataProvider {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this provider is based on some existing one related to CodeQL. There may be opportunities to reduce duplicate code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Refactored it :)

/**
* Shows if an open-source project runs Bandit scans.
*
* @see <a href="https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#jobsjob_idstepsrun">GitHub workflow action job config to run Bandit code scanning for a repository</a>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd use a link to Bandit instead of GitHub Actions.

}

@Override
protected ValueSet fetchValuesFor(GitHubProject project) throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bandit can be run without GitHub actions. This data provider may be updated to catch it.

Copy link
Member Author

@sourabhsparkala sourabhsparkala Jan 17, 2022

Choose a reason for hiding this comment

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

"The score value is unknown because all required features are unknown.");
}

if (!languages.isUnknown() && !SUPPORTED_LANGUAGES.containsAnyOf(languages.get())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the languages feature is unknown, but the rest two features are false, then the scoring function produces 0 which may not be always correct. In this case, you may consider returning N/A but I am not sure though.

Copy link
Member Author

Choose a reason for hiding this comment

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

It could also be that

  • The languages data provider fails to collect the language information but the project still triggers the Bandit scan.
  • I guess it is up to us to decide how we want to take this up.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added a check for unknown language. I decided that it doesn't make sense to check for a Bandit scan if there is no mention that the project uses Python scripts.

@@ -97,7 +97,7 @@ private void testCodeqlRuns(String filename, InputStream content, Value<?>... ex
CodeqlDataProvider provider = new CodeqlDataProvider(fetcher);
ValueSet values = provider.fetchValuesFor(PROJECT);

assertEquals(2, expectedValues.length);
assertEquals(2, values.size());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess, this update is not necessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is already a Test confirming that the possible features that will be available here https://github.com/SAP/fosstars-rating-core/pull/762/files/f9d5d97620fce7554c112f9a58b257816e56aa96#diff-7567ba8d1e196c5107745af1dcfa55c3f64d94c9b85201c05247500f2c7944a8L59

But you are right. As we are ourselves passing the expected values. The test is the same.

Copy link
Collaborator

@artem-smotrakov artem-smotrakov left a comment

Choose a reason for hiding this comment

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

I had a quick look, looks fine. I am not sure whether you really need that new interface. I think the most important thing is to detect Bandit not only in GitHub actions. I guess you're going to address it separately.

* A step in a GitHub action that triggers analysis with Bandit.
*/
private static final Pattern RUN_STEP_BANDIT_REGEX_PATTERN
= Pattern.compile("^.*bandit .*$", Pattern.DOTALL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess, the whitespace is here for a reason.

Copy link
Member Author

@sourabhsparkala sourabhsparkala Mar 28, 2022

Choose a reason for hiding this comment

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

yes, the syntax goes bandit -r. Just to indicate that bandit is a function call during run: in GitHub actions and not randomly occuring command word. Maybe I should include all the parameters possible which comes with bandit run.

However to improve this, let me work on this here #789

@sourabhsparkala sourabhsparkala merged commit 10a5984 into SAP:master Mar 29, 2022
@sourabhsparkala sourabhsparkala deleted the bandit branch March 29, 2022 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PoC: Bandit in Python projects
3 participants