forked from gardener/machine-controller-manager
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
gosec
for Static Application Security Testing (SAST) (gar…
…dener#954) * Introduce make targets for sast and address security issues. * Address review comments
- Loading branch information
Showing
21 changed files
with
192 additions
and
49 deletions.
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 |
---|---|---|
|
@@ -31,3 +31,6 @@ tags | |
|
||
# dont check in tool binariess | ||
hack/tools/bin/ | ||
|
||
# gosec | ||
gosec-report.sarif |
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
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,44 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -e | ||
|
||
root_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )" | ||
|
||
gosec_report="false" | ||
gosec_report_parse_flags="" | ||
|
||
parse_flags() { | ||
while test $# -gt 1; do | ||
case "$1" in | ||
--gosec-report) | ||
shift; gosec_report="$1" | ||
;; | ||
*) | ||
echo "Unknown argument: $1" | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
} | ||
|
||
parse_flags "$@" | ||
|
||
echo "> Running gosec" | ||
gosec --version | ||
if [[ "$gosec_report" != "false" ]]; then | ||
echo "Exporting report to $root_dir/gosec-report.sarif" | ||
gosec_report_parse_flags="-track-suppressions -fmt=sarif -out=gosec-report.sarif -stdout" | ||
fi | ||
|
||
# MCM uses code-generators https://github.com/kubernetes/code-generator which create lots of G103 (CWE-242: | ||
# Use of unsafe calls should be audited) & G104 (CWE-703: Errors unhandled) errors. | ||
# However, those generators are best-pratice in Kubernetes environment and their results are tested well. | ||
# Thus, generated code is excluded from gosec scan. | ||
# Nested go modules are not supported by gosec (see https://github.com/securego/gosec/issues/501), so the ./hack folder | ||
# is excluded too. It does not contain productive code anyway. | ||
gosec -exclude-generated -exclude-dir=hack $gosec_report_parse_flags ./... |
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,43 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set -e | ||
|
||
echo "> Installing gosec" | ||
|
||
TOOLS_BIN_DIR=${TOOLS_BIN_DIR:-$(dirname $0)/bin} | ||
|
||
platform=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
version=$GOSEC_VERSION | ||
echo "gosec version:$GOSEC_VERSION" | ||
case $(uname -m) in | ||
aarch64 | arm64) | ||
arch="arm64" | ||
;; | ||
x86_64) | ||
arch="amd64" | ||
;; | ||
*) | ||
echo "Unknown architecture" | ||
exit -1 | ||
;; | ||
esac | ||
|
||
archive_name="gosec_${version#v}_${platform}_${arch}" | ||
file_name="${archive_name}.tar.gz" | ||
|
||
temp_dir="$(mktemp -d)" | ||
function cleanup { | ||
rm -rf "${temp_dir}" | ||
} | ||
trap cleanup EXIT ERR INT TERM | ||
echo "Downloading from: https://github.com/securego/gosec/releases/download/${version}/${file_name}" | ||
curl -L -o ${temp_dir}/${file_name} "https://github.com/securego/gosec/releases/download/${version}/${file_name}" | ||
|
||
|
||
tar -xzm -C "${temp_dir}" -f "${temp_dir}/${file_name}" | ||
mv "${temp_dir}/gosec" $TOOLS_BIN_DIR | ||
chmod +x $TOOLS_BIN_DIR/gosec |
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
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
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
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
Oops, something went wrong.