-
Notifications
You must be signed in to change notification settings - Fork 0
Chore: [AEA-0000] - verify trivy download before installing it #58
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
Changes from all commits
da3b6d6
0364bf8
5b9ae00
c3fe81a
2b3b24e
1b0e1f2
e2329ac
3de3b9f
aaffd27
1f5d1b8
dc351a9
b52430d
3bd546c
d3111a9
859aa7a
b1f157e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ src/base/.devcontainer/language_versions/ | |
| .trivyignore_combined.yaml | ||
| .out/ | ||
| .envrc | ||
| .trivy_out/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,5 +5,4 @@ shellcheck 0.11.0 | |
| direnv 2.37.1 | ||
| actionlint 1.7.10 | ||
| ruby 3.3.0 | ||
| trivy 0.69.3 | ||
| yq 4.52.2 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,4 @@ shellcheck 0.11.0 | |
| direnv 2.37.1 | ||
| actionlint 1.7.11 | ||
| ruby 3.3.0 | ||
| trivy 0.69.3 | ||
| yq 4.52.4 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| FROM golang:1.26.1-bookworm AS build | ||
| RUN apt-get update && apt-get install -y \ | ||
| jq \ | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
| COPY src/base/.devcontainer/scripts/install_cosign.sh /tmp/install_cosign.sh | ||
| COPY src/base/.devcontainer/scripts/install_trivy.sh /tmp/install_trivy.sh | ||
| RUN INSTALL_DIR=/usr/local/bin /tmp/install_cosign.sh | ||
| RUN INSTALL_DIR=/tmp/trivy/ ARCH=64bit /tmp/install_trivy.sh | ||
|
|
||
| FROM scratch | ||
| COPY --from=build /tmp/trivy/trivy / | ||
| ENTRYPOINT ["/trivy"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| FROM golang:1.26.1-bookworm AS build | ||
| RUN apt-get update && apt-get install -y \ | ||
| jq \ | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
| COPY scripts/install_cosign.sh /tmp/install_cosign.sh | ||
| COPY scripts/install_trivy.sh /tmp/install_trivy.sh | ||
| RUN INSTALL_DIR=/usr/local/bin /tmp/install_cosign.sh | ||
| RUN INSTALL_DIR=/tmp/trivy/ ARCH=ARM64 /tmp/install_trivy.sh | ||
|
|
||
| FROM scratch | ||
| COPY --from=build /tmp/trivy/trivy / | ||
| ENTRYPOINT ["/trivy"] |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,109 @@ | ||||||
| #!/usr/bin/env bash | ||||||
| set -euo pipefail | ||||||
|
|
||||||
| DEFAULT_INSTALL_DIR="/usr/local/bin" | ||||||
| INSTALL_DIR="${INSTALL_DIR:-$DEFAULT_INSTALL_DIR}" | ||||||
| REQUESTED_VERSION="${1:-latest}" | ||||||
| OS="$(uname -s)" | ||||||
| ARCH="$(uname -m)" | ||||||
| API_URL="https://api.github.com/repos/sigstore/cosign/releases" | ||||||
|
|
||||||
| usage() { | ||||||
| cat <<'EOF' | ||||||
| Usage: install_cosign.sh [version] | ||||||
|
|
||||||
| Downloads the requested cosign release (default: latest) for Linux amd64, verifies | ||||||
| its signature, and installs it into $INSTALL_DIR (override via INSTALL_DIR env var). | ||||||
| EOF | ||||||
| } | ||||||
|
|
||||||
| if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then | ||||||
| usage | ||||||
| exit 0 | ||||||
| fi | ||||||
|
|
||||||
| if [[ "$OS" != "Linux" ]]; then | ||||||
| echo "Error: This installer currently supports Linux only" >&2 | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| case "$ARCH" in | ||||||
| x86_64|amd64) | ||||||
| BINARY_NAME="cosign-linux-amd64" | ||||||
| ;; | ||||||
| aarch64|arm64) | ||||||
| BINARY_NAME="cosign-linux-arm64" | ||||||
| ;; | ||||||
| *) | ||||||
| echo "Error: Unsupported architecture $ARCH" >&2 | ||||||
| exit 1 | ||||||
| ;; | ||||||
| esac | ||||||
|
|
||||||
| for cmd in curl openssl install go jq; do | ||||||
| if ! command -v "$cmd" >/dev/null 2>&1; then | ||||||
| echo "Error: $cmd is required but not found in PATH" >&2 | ||||||
| exit 1 | ||||||
| fi | ||||||
| done | ||||||
|
|
||||||
| get_latest_tag() { | ||||||
| local response | ||||||
| response="$(curl -fsSL "$API_URL/latest")" | ||||||
| awk -F'"' '/tag_name/ {print $4; exit}' <<<"$response" | ||||||
| } | ||||||
|
|
||||||
| VERSION="$REQUESTED_VERSION" | ||||||
| if [[ "$VERSION" == "latest" ]]; then | ||||||
| VERSION="$(get_latest_tag)" | ||||||
| fi | ||||||
|
|
||||||
| if [[ -z "$VERSION" ]]; then | ||||||
| echo "Error: Unable to determine cosign version" >&2 | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| BASE_URL="https://github.com/sigstore/cosign/releases/download/${VERSION}" | ||||||
| TMP_DIR="$(mktemp -d)" | ||||||
| trap 'rm -rf "$TMP_DIR"' EXIT | ||||||
|
|
||||||
| download() { | ||||||
| local url="${1}" dest="${2}" | ||||||
| echo "Downloading ${dest} ..." | ||||||
| curl -fsSL "${url}" -o "${dest}" | ||||||
| } | ||||||
|
|
||||||
| BIN_PATH="$TMP_DIR/${BINARY_NAME}" | ||||||
| SIGSTORE_PATH="$TMP_DIR/${BINARY_NAME}-kms.sigstore.json" | ||||||
| ARTIFACT_PATH="$TMP_DIR/artifact.pub" | ||||||
| DECODED_SIGSTORE_PATH="$TMP_DIR/cosign-kms.sig.decoded" | ||||||
|
|
||||||
| download "${BASE_URL}/${BINARY_NAME}" "$BIN_PATH" | ||||||
| download "${BASE_URL}/${BINARY_NAME}-kms.sigstore.json" "$SIGSTORE_PATH" | ||||||
|
|
||||||
| # install tuf-client | ||||||
| go install github.com/theupdateframework/go-tuf/cmd/tuf-client@latest | ||||||
|
|
||||||
| # setup tuf-client | ||||||
| SIGSTORE_ROOT_PATH="$TMP_DIR/sigstore-root.json" | ||||||
| curl -o "$SIGSTORE_ROOT_PATH" https://raw.githubusercontent.com/sigstore/root-signing/refs/heads/main/metadata/root_history/10.root.json | ||||||
|
||||||
| curl -o "$SIGSTORE_ROOT_PATH" https://raw.githubusercontent.com/sigstore/root-signing/refs/heads/main/metadata/root_history/10.root.json | |
| curl -o "$SIGSTORE_ROOT_PATH" https://raw.githubusercontent.com/sigstore/root-signing/39c787b931c9791667235b3a5229ae58f12f1b4a/metadata/root_history/10.root.json |
anthony-nhs marked this conversation as resolved.
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| DEFAULT_INSTALL_DIR="/usr/local/bin" | ||
| INSTALL_DIR="${INSTALL_DIR:-$DEFAULT_INSTALL_DIR}" | ||
| VERSION="v0.69.3" | ||
| DEFAULT_ARCH="64bit" | ||
| ARCH="${ARCH:-$DEFAULT_ARCH}" | ||
| RELEASE_NUMBER="${VERSION#v}" | ||
| BASE_URL="https://github.com/aquasecurity/trivy/releases/download/${VERSION}" | ||
| ARCHIVE="trivy_${RELEASE_NUMBER}_Linux-${ARCH}.tar.gz" | ||
| BUNDLE="${ARCHIVE}.sigstore.json" | ||
| CERT_IDENTITY="https://github.com/aquasecurity/trivy/.github/workflows/reusable-release.yaml@refs/tags/${VERSION}" | ||
|
|
||
| usage() { | ||
| cat <<'EOF' | ||
| Usage: install_trivy.sh [output_dir] | ||
|
|
||
| Downloads Trivy, its sigstore bundle, and checksum into output_dir (default: current directory), | ||
| then verifies the checksum and the sigstore bundle, following | ||
| https://github.com/aquasecurity/trivy/blob/main/docs/getting-started/signature-verification.md. | ||
| EOF | ||
| } | ||
|
|
||
| if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then | ||
| usage | ||
| exit 0 | ||
| fi | ||
|
|
||
| for cmd in curl cosign sha256sum; do | ||
| if ! command -v "$cmd" >/dev/null 2>&1; then | ||
| echo "Error: $cmd is required but not found in PATH" >&2 | ||
| exit 1 | ||
| fi | ||
|
Comment on lines
+15
to
+34
|
||
| done | ||
|
|
||
| TMP_DIR="$(mktemp -d)" | ||
| trap 'rm -rf "$TMP_DIR"' EXIT | ||
|
|
||
| download() { | ||
| local url="${1}" dest="${2}" | ||
| echo "Downloading ${dest} ..." | ||
| curl -fsSL "${url}" -o "${dest}" | ||
| } | ||
| ARCHIVE_PATH="${TMP_DIR}/${ARCHIVE}" | ||
| BUNDLE_PATH="${TMP_DIR}/${BUNDLE}" | ||
| download "${BASE_URL}/${ARCHIVE}" "${ARCHIVE_PATH}" | ||
| download "${BASE_URL}/${BUNDLE}" "${BUNDLE_PATH}" | ||
|
|
||
|
|
||
| cosign verify-blob-attestation "${ARCHIVE_PATH}" \ | ||
| --bundle "${BUNDLE_PATH}" \ | ||
| --certificate-oidc-issuer="https://token.actions.githubusercontent.com" \ | ||
| --certificate-identity "${CERT_IDENTITY}" | ||
|
|
||
| echo "Sigstore verification passed" | ||
| tar -xzf "${ARCHIVE_PATH}" -C "${TMP_DIR}" | ||
|
|
||
| mkdir -p "$INSTALL_DIR" | ||
| install -m 0755 "$TMP_DIR/trivy" "${INSTALL_DIR}/trivy" | ||
|
|
||
| echo "trivy ${VERSION} installed to ${INSTALL_DIR}" | ||
Uh oh!
There was an error while loading. Please reload this page.