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

976 - Introduce Security Scans for Go Packages #1053

Merged
merged 3 commits into from Jan 3, 2020

Conversation

BradleyBoutcher
Copy link
Contributor

What does this PR do (include background context, if relevant)?

A new bash script which runs gosec on our packages

We only flag issues of high severity with 'medium' or 'high' confidence by Gosec
Gosec only scans directories modified by checking the Git diff first. If the branch is master, it scans the entire project. This way we save time in our pipeline while developing.
Finally, the reports are exported as xml and parsed using Junit.

What ticket does this PR close?

Connected to #976 and #988

Where should the reviewer start?

bin/build_security_scan

What is the status of the manual tests?

NA

Links to open issues for related automated integration and unit tests

NA

Links to open issues for related documentation (in READMEs, docs, etc)

NA

@BradleyBoutcher BradleyBoutcher force-pushed the 976-security-scan branch 2 times, most recently from 2fe89c9 to adb87d1 Compare December 19, 2019 20:08
Copy link
Contributor

@hughsaunders hughsaunders left a comment

Choose a reason for hiding this comment

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

This looks great, thanks :D

Looking at the pipeline in blueocean, it struck me that the scanners (secretless image, go packages) could be parallelised as neither depends on the result of the other. That also groups them into a higher level security stage.

I noticed in the log that the xml doc is empty (apart from the xml declaration), is that the expected behaviour when there are no issues? Have you introduced a deliberate security issue to check it shows up in the Jenkins Test Results view?

@BradleyBoutcher
Copy link
Contributor Author

@hughsaunders Thanks for the review! Addressing your comments in order:

  • It absolutely can be parallelized, I'll make a few changes and re-submit it.
  • So far I've tested locally and made sure that issues are detected and output correctly, but currently there are none in our repository that meet the criteria for an issue. When there's no issues, the log should be empty.
  • On a related note, I realized there is an issue. Since we're scanning the git diff, we won't see which files are changed in that commit since technically nothing has been changed locally. I'll have to make a change there for sure.

izgeri
izgeri previously requested changes Dec 20, 2019
Copy link
Contributor

@izgeri izgeri left a comment

Choose a reason for hiding this comment

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

Looking forward to getting this integrated :) left a few comments - I think this could be simplified a bit by combining the scripts and the naming could be clearer

It would also be nice to clean up the pipeline stages for the tests in the Jenkinsfile - they're a little inconsistently labeled right now and it looks odd in blue ocean. But that's optional.

Jenkinsfile Outdated
@@ -31,6 +31,13 @@ pipeline {
}
}

stage('Scan Go Packages') {
steps {
sh "./bin/build_security_scan -s High -c 'Medium' -b ${env.BRANCH_NAME}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the filename be changed to run_gosec or similar? It would be clearer what it's actually doing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at the other bin/ files, it looks like we use the 'check_' format for file names. So for golint, it's check_style. How about for this we use 'check_security'?

Copy link
Contributor

Choose a reason for hiding this comment

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

is it your intention that the file becomes a general script to run security checks, so that when we have another we'd like to run we also do it from this file?

I'm still not sure I like check_security - security means a lot of different things to different people, so if we can find a way to be more clear I think that'd be good

bin/build_security_scan Outdated Show resolved Hide resolved
echo "directories regardless of what has been modified locally."
echo " "
echo "Format:"
echo "security_scan [arguments]"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be integrated into the other file? I'm not sure I see the need for two separate files in bin to run this. If I'm missing something, please lmk

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we wanted to run it within a docker container, I thought it would be easiest to have two separate files. I'm not very familiar with bash, but I assume that's the easiest way to run a large script like this inside a docker run command? Also, I thought it would be useful to have the script be able to run without using a docker container.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, so there are two scripts because one is meant to be run in a docker container (which docker container?) and the other one actually runs the the container?

I feel like there might be some patterns for how to name and organize these that would make their intended use more clear, but I'm not close enough to the code lately to remember exactly what to point you to. @sgnn7 @jonahx do you have any examples of how we've done something like this in other cases? in particular, I'm concerned that if I look at the bin/ dir, it's not going to be obvious which script I should run to do a gosec scan if we have two with similar names. I don't think this is the first time we've had to think about something like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently I have them named as such:

  • check_security: performs the gosec scan with whatever parameters you need
  • run_check_security: creates a docker container with secretless mounted as a volume, and runs check_security on the volume
    run_gosec_container may be clearer for the second one, and maybe something like run_gosec for the first?

Jenkinsfile Outdated Show resolved Hide resolved
@BradleyBoutcher BradleyBoutcher force-pushed the 976-security-scan branch 14 times, most recently from 003aead to b5fb744 Compare January 2, 2020 19:08
@BradleyBoutcher BradleyBoutcher self-assigned this Jan 2, 2020
sgnn7
sgnn7 previously requested changes Jan 2, 2020
Copy link
Contributor

@sgnn7 sgnn7 left a comment

Choose a reason for hiding this comment

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

@BradleyBoutcher just some minor nits

bin/check_security Outdated Show resolved Hide resolved
bin/check_security Outdated Show resolved Hide resolved
bin/check_security Outdated Show resolved Hide resolved
bin/check_security Outdated Show resolved Hide resolved
bin/run_check_security Outdated Show resolved Hide resolved
@BradleyBoutcher BradleyBoutcher force-pushed the 976-security-scan branch 2 times, most recently from f49d4ed to 4e6ba7a Compare January 2, 2020 19:49
Copy link
Contributor

@diverdane diverdane left a comment

Choose a reason for hiding this comment

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

Looks good. Just a couple of minor suggestions.

bin/check_security Outdated Show resolved Hide resolved
bin/run_check_security Outdated Show resolved Hide resolved
bin/check_security Outdated Show resolved Hide resolved
bin/check_security Outdated Show resolved Hide resolved
bin/check_security Outdated Show resolved Hide resolved
@BradleyBoutcher BradleyBoutcher dismissed stale reviews from sgnn7 and izgeri January 3, 2020 15:16

Comments addressed

@BradleyBoutcher BradleyBoutcher force-pushed the 976-security-scan branch 2 times, most recently from c3d9105 to 75053ab Compare January 3, 2020 15:59
Copy link
Contributor

@izgeri izgeri left a comment

Choose a reason for hiding this comment

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

@BradleyBoutcher what do you think about check_golang_security for the one that runs in the pipeline and run_gosec for the local runner? those still sound similar enough, though - each script should have comments at the top of the file or usage instructions that are clear about the purpose of each file

@BradleyBoutcher BradleyBoutcher force-pushed the 976-security-scan branch 5 times, most recently from c7515d0 to 7eec834 Compare January 3, 2020 18:05
A new bash script which runs gosec on our packages

We only flag issues of high severity with 'medium' or 'high' confidence by Gosec
Gosec only scans directories modified by checking the Git diff first. If the branch is master, it scans the entire project. This way we save time in our pipeline while developing.
Finally, the reports are exported as xml and parsed using Junit.
@@ -0,0 +1,69 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

as a follow-on to this PR, does it make sense to include this as a bash-lib script? cc @hughsaunders

Copy link
Contributor

@diverdane diverdane left a comment

Choose a reason for hiding this comment

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

LGTM

@BradleyBoutcher BradleyBoutcher merged commit 2dfd040 into master Jan 3, 2020
@BradleyBoutcher BradleyBoutcher deleted the 976-security-scan branch January 3, 2020 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants