-
Notifications
You must be signed in to change notification settings - Fork 295
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
🌱 Add license scan for pull requests #2299
Merged
k8s-ci-robot
merged 1 commit into
kubernetes-sigs:main
from
killianmuldoon:pr-add-license-scan
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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,57 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2023 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
if [[ "${TRACE-0}" == "1" ]]; then | ||
set -o xtrace | ||
fi | ||
|
||
VERSION=${1} | ||
|
||
GO_OS="$(go env GOOS)" | ||
if [[ "${GO_OS}" == "linux" ]]; then | ||
TRIVY_OS="Linux" | ||
elif [[ "${GO_OS}" == "darwin"* ]]; then | ||
TRIVY_OS="macOS" | ||
fi | ||
|
||
GO_ARCH="$(go env GOARCH)" | ||
if [[ "${GO_ARCH}" == "amd" ]]; then | ||
TRIVY_ARCH="32bit" | ||
elif [[ "${GO_ARCH}" == "amd64"* ]]; then | ||
TRIVY_ARCH="64bit" | ||
elif [[ "${GO_ARCH}" == "arm" ]]; then | ||
TRIVY_ARCH="ARM" | ||
elif [[ "${GO_ARCH}" == "arm64" ]]; then | ||
TRIVY_ARCH="ARM64" | ||
fi | ||
|
||
TOOL_BIN=hack/tools/bin | ||
mkdir -p ${TOOL_BIN} | ||
|
||
TRIVY="${TOOL_BIN}/trivy/${VERSION}/trivy" | ||
|
||
# Downloads trivy scanner | ||
if [ ! -f "$TRIVY" ]; then | ||
curl -L -o ${TOOL_BIN}/trivy.tar.gz "https://github.com/aquasecurity/trivy/releases/download/v${VERSION}/trivy_${VERSION}_${TRIVY_OS}-${TRIVY_ARCH}.tar.gz" | ||
mkdir -p "$(dirname "$0")/tools/bin/trivy/${VERSION}" | ||
tar -xf "${TOOL_BIN}/trivy.tar.gz" -C "${TOOL_BIN}/trivy/${VERSION}" trivy | ||
chmod +x "${TOOL_BIN}/trivy/${VERSION}/trivy" | ||
rm "${TOOL_BIN}/trivy.tar.gz" | ||
fi |
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,38 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2023 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
if [[ "${TRACE-0}" == "1" ]]; then | ||
set -o xtrace | ||
fi | ||
|
||
# This list is from https://github.com/cncf/foundation/blob/main/allowed-third-party-license-policy.md | ||
CNCF_LICENSE_ALLOWLIST=Apache-2.0,MIT,BSD-2-Clause,SD-2-Clause-FreeBSD,BSD-3-Clause,ISC,Python-2.0,PostgreSQL,X11,Zlib | ||
|
||
VERSION=${1} | ||
|
||
REPO_ROOT=$(git rev-parse --show-toplevel) | ||
"${REPO_ROOT}/hack/ensure-trivy.sh" "${VERSION}" | ||
|
||
|
||
TRIVY="${REPO_ROOT}/hack/tools/bin/trivy/${VERSION}/trivy" | ||
$TRIVY filesystem . --license-full --ignored-licenses ${CNCF_LICENSE_ALLOWLIST} --scanners license --severity UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL -f json | \ | ||
# Specifically ignore 'github.com/hashicorp/hcl'. This is a known indirect dependency that we should remove where possible. | ||
# This query ensures we only skip github.com/hashicorp/hcl for as long as the license remains MPL-2.0 | ||
jq '.Results[] | select( .Licenses[]?.PkgName == "github.com/hashicorp/hcl" and .Licenses[]?.Name == "MPL-2.0" | not) | if . == {} then . else error(.) end' |
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.
Interesting that we don't have this line in core CAPI and probably just assume that GOARCH is set?
Maybe something to fix in core CAPI? (@killianmuldoon)
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.
The
GO_ARCH
here is only used to give the resulting image a name - I'm not sure if it's used for anything else at this point - the ensure-trivy script sets its ownGO_ARCH
.Maybe it's a good idea to just remove this here?
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.
I think it's not used to give it a name, it's used to match the name that is used by make docker-build.
I think if we drop this line we either:
I would avoid implicitly depending on an env variable being exported by someone calling that script (which I think is what is happening in core CAPI now). (Because this makes it harder to call the script standalone and just a bit too magical/implicit for my taste)
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.
You're right - I'll do a PR into CAPI to make them consistent and make CAPI's use of the GO_ARCH more explicit.