-
Notifications
You must be signed in to change notification settings - Fork 42
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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,35 @@ | ||
#!/bin/bash | ||
|
||
# This script creates a docker container with | ||
# secretless mounted as a volume, and runs the | ||
# gosec security check script within this container | ||
|
||
set -eo pipefail | ||
|
||
current_dir=$("$(dirname "$0")/abspath") | ||
toplevel_dir="$current_dir/.." | ||
|
||
# Default values to pass to security_scan | ||
confidence='medium' | ||
severity='high' | ||
current_branch='master' | ||
|
||
while getopts 'b:c:s:' flag; do | ||
case "${flag}" in | ||
b) current_branch="${OPTARG}" ;; | ||
c) confidence="${OPTARG}" ;; | ||
s) severity="${OPTARG}" ;; | ||
esac | ||
done | ||
|
||
# Exclude test files | ||
excluded_directories=${toplevel_dir}/test | ||
|
||
# gosec => Scans go packages and flags security vulnerabilities | ||
docker run --rm \ | ||
-v "$toplevel_dir/:/secretless/" \ | ||
secretless-dev \ | ||
bash -exc " | ||
go get github.com/securego/gosec/cmd/gosec | ||
./bin/run_gosec -c ${confidence} -s ${severity} -b ${current_branch} -e ${excluded_directories} | ||
" |
This file contains 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,69 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eo pipefail | ||
|
||
# This script can run independently of secretless | ||
# i.e. in any given local repository | ||
# | ||
# Performs a gosec scan with given parameters on | ||
# the entire local repository (in the case of master branch) | ||
# or on just files modified, as detected in the git diff. | ||
|
||
print_usage() { | ||
echo "Security Scanner" | ||
echo | ||
echo "Description:" | ||
echo "Runs gosec on directories which git detects and marks in the diff." | ||
echo "If the branch is detected as 'master', it will scan all" | ||
echo "directories regardless of what has been modified locally." | ||
echo | ||
echo "Format:" | ||
echo "security_scan [arguments]" | ||
echo | ||
echo "Options:" | ||
echo "-h Show help" | ||
echo "-c Specify the minimum confidence gosec needs to report an issue." | ||
echo "-s Specify the minimum severity gosec needs to report an issue" | ||
echo "-b Specify the github branch to compare against master" | ||
exit 0 | ||
} | ||
|
||
# Default values for gosec | ||
confidence='medium' | ||
severity='high' | ||
current_branch='' | ||
excluded_directories='' | ||
|
||
while getopts 'b:c:e:s:h' flag; do | ||
case "${flag}" in | ||
b) current_branch="${OPTARG}" ;; | ||
e) excluded_directories="${OPTARG}" ;; | ||
c) confidence="${OPTARG}" ;; | ||
s) severity="${OPTARG}" ;; | ||
h) print_usage ;; | ||
*) print_usage ;; | ||
esac | ||
done | ||
|
||
# If we are on master, scan the entire repository | ||
modified_directories="./..." | ||
|
||
# Get an array of directories containing modified files | ||
if [[ ${current_branch} != 'master' ]]; then | ||
git fetch origin master:refs/remotes/origin/master | ||
modified_directories=($(git diff origin/master...origin/"${current_branch}" --name-only | xargs -L1 dirname | uniq)) | ||
fi | ||
|
||
# Remove output file just in case it exists | ||
rm -f "gosec.output" | ||
|
||
# Run our scan, flagging only 'high' level issues with 'medium' or higher severity | ||
gosec -fmt=junit-xml \ | ||
-out=gosec.output \ | ||
-severity="${severity}" \ | ||
-confidence="${confidence}" \ | ||
-exclude-dir="${excluded_directories}" \ | ||
"${modified_directories[@]}" | ||
|
||
# Display output of gosec | ||
cat gosec.output |
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.
as a follow-on to this PR, does it make sense to include this as a bash-lib script? cc @hughsaunders