Skip to content

Commit

Permalink
fix(ci): use registry tokens for image license scanning (#1255)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwrau authored Nov 27, 2024
1 parent f2a29c7 commit 4969ebb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
10 changes: 1 addition & 9 deletions .github/scripts/generate-sarif-reports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
set -eu
set -o pipefail

declare -A IMAGE_PULL_TOKENS=(
["registry-gitlab.teuto.net"]="${TEUTO_PORTAL_WORKER_PULL_TOKEN}"
)
source "$(dirname "$0")/trivy-login-to-registries.sh"

function createSarifReports() {
local chart="${1?}"
Expand Down Expand Up @@ -47,12 +45,6 @@ function generateSarifReport() {
}
export -f generateSarifReport

trivy image --download-db-only

for registry in "${!IMAGE_PULL_TOKENS[@]}"; do
TRIVY_PASSWORD="${IMAGE_PULL_TOKENS["$registry"]}" trivy registry login --username github-cve-scanning "$registry"
done

if [[ "$#" == 1 && -d "$1" ]]; then
createSarifReports "$1"
else
Expand Down
2 changes: 2 additions & 0 deletions .github/scripts/scan-for-licenses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
set -eu
set -o pipefail

source "$(dirname "$0")/trivy-login-to-registries.sh"

WHITELIST=(
"AGPL-3.0" # We're not writing software 🤷
"CC-BY-SA-3.0"
Expand Down
16 changes: 16 additions & 0 deletions .github/scripts/trivy-login-to-registries.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

if ! (return 0 2>/dev/null); then
echo This must be sourced, not executed. >&2
exit 1
fi

declare -A IMAGE_PULL_TOKENS=(
["registry-gitlab.teuto.net"]="${TEUTO_PORTAL_WORKER_PULL_TOKEN?}"
)

trivy image --download-db-only

for registry in "${!IMAGE_PULL_TOKENS[@]}"; do
TRIVY_PASSWORD="${IMAGE_PULL_TOKENS["$registry"]}" trivy registry login --username github-cve-scanning "$registry"
done
4 changes: 3 additions & 1 deletion .github/workflows/check-licenses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: pip install yq
- run: /home/linuxbrew/.linuxbrew/bin/brew install trivy
- run: |
- env:
TEUTO_PORTAL_WORKER_PULL_TOKEN: ${{ secrets.TEUTO_PORTAL_WORKER_PULL_TOKEN }}
run: |
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
./.github/scripts/scan-for-licenses.sh ${{ needs.getChangedChart.outputs.chart }}
check-licenses-list:
Expand Down

0 comments on commit 4969ebb

Please sign in to comment.