Skip to content

Commit

Permalink
Merge pull request kubevirt#4192 from xpivarc/gosec
Browse files Browse the repository at this point in the history
Add gosec to project
  • Loading branch information
kubevirt-bot authored Oct 8, 2020
2 parents 33cae25 + 5815ce2 commit 72d0d9b
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ client-python:
go-build:
hack/dockerized "KUBEVIRT_VERSION=${KUBEVIRT_VERSION} ./hack/build-go.sh install ${WHAT}" && ./hack/build-copy-artifacts.sh ${WHAT}

gosec:
hack/dockerized "GENERATE="true" ./hack/gosec.sh"
hack/dockerized "./hack/gosec.sh"

coverage:
hack/dockerized "./hack/coverage.sh ${WHAT}"

Expand Down
1 change: 1 addition & 0 deletions hack/builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ RUN set -x && \
go get -v github.com/golang/protobuf/protoc-gen-go@1643683 && \
go get -v k8s.io/code-generator/cmd/[email protected] && \
go get -v sigs.k8s.io/controller-tools/cmd/[email protected] && \
go get -v github.com/securego/gosec/v2/cmd/gosec@0ce48a5 && \
go clean -cache -modcache

RUN set -x && \
Expand Down
2 changes: 1 addition & 1 deletion hack/builder/version.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION=30-8.0.2
VERSION=30-8.0.33
# TODO: reenable ppc64le when new builds are available
ARCHITECTURES="amd64"
10 changes: 8 additions & 2 deletions hack/dockerized
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [ -z ${KUBEVIRT_CRI} ]; then
fi
fi

KUBEVIRT_BUILDER_IMAGE="kubevirt/builder@sha256:6c40c31d8537a3a48dd95d997d0775f480ea6976368cdf9c9720febf9c7b3e60"
KUBEVIRT_BUILDER_IMAGE="kubevirt/builder@sha256:3390fe22e515d653e8c2d5fb50b761f75990a9b67394120ff613cb01f15def93"

SYNC_OUT=${SYNC_OUT:-true}

Expand Down Expand Up @@ -135,7 +135,13 @@ fi

# Run the command
test -t 1 && USE_TTY="-it"
$KUBEVIRT_CRI exec ${USE_TTY} ${BUILDER}-bazel-server /entrypoint.sh "$@"
if ! $KUBEVIRT_CRI exec ${USE_TTY} ${BUILDER}-bazel-server /entrypoint.sh "$@"; then
# Copy the build output out of the container, make sure that _out exactly matches the build result
if [ "$SYNC_OUT" = "true" ]; then
_rsync --delete "rsync://[email protected]:${RSYNCD_PORT}/out" ${OUT_DIR}
fi
exit 1
fi

# Copy the whole kubevirt data out to get generated sources and formatting changes
_rsync \
Expand Down
11 changes: 11 additions & 0 deletions hack/gosec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

source hack/common.sh
export ARTIFACTS=${ARTIFACTS:-$KUBEVIRT_DIR/_out/artifacts}

mkdir -p $ARTIFACTS

echo "Run go sec in pkg"
cd $KUBEVIRT_DIR/pkg

gosec -sort -quiet -out=${ARTIFACTS}/junit-gosec.xml -exclude-dir=testutils -fmt=junit-xml ./...
9 changes: 9 additions & 0 deletions pkg/util/webhooks/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

func SetupPromTLS(certManager certificate.Manager) *tls.Config {
tlsConfig := &tls.Config{
MinVersion: tls.VersionTLS12,
GetCertificate: func(info *tls.ClientHelloInfo) (certificate *tls.Certificate, err error) {
cert := certManager.Current()
if cert == nil {
Expand All @@ -26,6 +27,7 @@ func SetupPromTLS(certManager certificate.Manager) *tls.Config {
return nil, fmt.Errorf("failed to get a certificate")
}
config := &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{*crt},
ClientAuth: tls.VerifyClientCertIfGiven,
}
Expand Down Expand Up @@ -58,6 +60,7 @@ func SetupTLSWithCertManager(caManager ClientCAManager, certManager certificate.
return nil, err
}
config := &tls.Config{
MinVersion: tls.VersionTLS12,
Certificates: []tls.Certificate{*cert},
ClientCAs: clientCAPool,
ClientAuth: clientAuth,
Expand All @@ -72,7 +75,10 @@ func SetupTLSWithCertManager(caManager ClientCAManager, certManager certificate.
}

func SetupTLSForVirtHandlerServer(caManager ClientCAManager, certManager certificate.Manager, externallyManaged bool) *tls.Config {
// #nosec cause: InsecureSkipVerify: true
// resolution: Neither the client nor the server should validate anything itself, `VerifyPeerCertificate` is still executed
return &tls.Config{
//
InsecureSkipVerify: true,
GetCertificate: func(info *tls.ClientHelloInfo) (certificate *tls.Certificate, err error) {
cert := certManager.Current()
Expand Down Expand Up @@ -142,7 +148,10 @@ func SetupTLSForVirtHandlerServer(caManager ClientCAManager, certManager certifi
}

func SetupTLSForVirtHandlerClients(caManager ClientCAManager, certManager certificate.Manager, externallyManaged bool) *tls.Config {
// #nosec cause: InsecureSkipVerify: true
// resolution: Neither the client nor the server should validate anything itself, `VerifyPeerCertificate` is still executed
return &tls.Config{
// Neither the client nor the server should validate anything itself, `VerifyPeerCertificate` is still executed
InsecureSkipVerify: true,
ClientAuth: tls.RequireAndVerifyClientCert,
GetCertificate: func(info *tls.ClientHelloInfo) (certificate *tls.Certificate, err error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/virtctl/imageupload/imageupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ func getHTTPClient(insecure bool) *http.Client {
client := &http.Client{}

if insecure {
// #nosec cause: InsecureSkipVerify: true resolution: this method explicitly ask for insecure http client
client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
Expand Down
6 changes: 6 additions & 0 deletions tools/gosec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# [GOSEC](https://github.com/securego/gosec)

Junit contains all issues in the project.
Use `// #nosec` on top of reported line to mark issue as false positive.


0 comments on commit 72d0d9b

Please sign in to comment.