From 679716a20d4d5a7dafbcbeec00deb623630f41b3 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Thu, 10 Sep 2026 08:53:02 -0700 Subject: [PATCH] Automate Go dependency and builder image security updates (#4) * Add weekly Go dependency CVE automation Co-authored-by: spraveenio <58961022+spraveenio@users.noreply.github.com> * Clean merged Dependabot branches Co-authored-by: spraveenio <58961022+spraveenio@users.noreply.github.com> * Align Go toolchain with builder containers Co-authored-by: spraveenio <58961022+spraveenio@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: spraveenio <58961022+spraveenio@users.noreply.github.com> --- .github/dependabot.yml | 28 ++++++++++++ .github/workflows/ci.yml | 11 ++++- .github/workflows/dependabot-cleanup.yml | 33 ++++++++++++++ .github/workflows/trivy-dependency-scan.yml | 45 +++++++++++++++++++ Makefile | 2 + .../{Dokerfile.rhel9 => Dockerfile.rhel9} | 7 +-- .../{Dokerfile.ubu2204 => Dockerfile.ubu2204} | 7 +-- tools/build-container/Makefile | 6 ++- 8 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/dependabot-cleanup.yml create mode 100644 .github/workflows/trivy-dependency-scan.yml rename tools/build-container/{Dokerfile.rhel9 => Dockerfile.rhel9} (81%) rename tools/build-container/{Dokerfile.ubu2204 => Dockerfile.ubu2204} (84%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..730a69d9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,28 @@ +version: 2 +updates: + - package-ecosystem: gomod + directory: /sw/nic/gpuagent + schedule: + interval: weekly + day: monday + time: "08:00" + timezone: Etc/UTC + open-pull-requests-limit: 1 + groups: + go-dependencies: + patterns: + - "*" + labels: + - dependencies + - security + - package-ecosystem: docker + directory: /tools/build-container + schedule: + interval: weekly + day: monday + time: "08:00" + timezone: Etc/UTC + open-pull-requests-limit: 1 + labels: + - dependencies + - security diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fb36ed3c..037d5d5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,13 +28,22 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + - name: Read Go version + id: go-version + run: | + version=$(awk '$1 == "go" { print $2; exit }' sw/nic/gpuagent/go.mod) + test -n "$version" + echo "version=$version" >> "$GITHUB_OUTPUT" + - name: Build builder container uses: docker/build-push-action@v6 with: context: tools/build-container - file: tools/build-container/Dokerfile.rhel9 + file: tools/build-container/Dockerfile.rhel9 load: true tags: gpuagent-builder-rhel:9 + build-args: | + GO_VERSION=${{ steps.go-version.outputs.version }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/.github/workflows/dependabot-cleanup.yml b/.github/workflows/dependabot-cleanup.yml new file mode 100644 index 00000000..f1953883 --- /dev/null +++ b/.github/workflows/dependabot-cleanup.yml @@ -0,0 +1,33 @@ +name: Dependabot Cleanup + +on: + pull_request: + types: + - closed + +permissions: + contents: write + +jobs: + delete-merged-branch: + name: Delete merged Dependabot branch + if: >- + github.event.pull_request.merged && + github.event.pull_request.head.repo.full_name == github.repository && + startsWith(github.event.pull_request.head.ref, 'dependabot/') + runs-on: ubuntu-24.04 + + steps: + - name: Delete branch + uses: actions/github-script@v7.0.1 + with: + script: | + try { + await github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `heads/${context.payload.pull_request.head.ref}`, + }); + } catch (error) { + if (error.status !== 404) throw error; + } diff --git a/.github/workflows/trivy-dependency-scan.yml b/.github/workflows/trivy-dependency-scan.yml new file mode 100644 index 00000000..f014e036 --- /dev/null +++ b/.github/workflows/trivy-dependency-scan.yml @@ -0,0 +1,45 @@ +name: Trivy Dependency Scan + +on: + pull_request: + paths: + - sw/nic/gpuagent/go.mod + - sw/nic/gpuagent/go.sum + schedule: + - cron: "0 8 * * 1" + workflow_dispatch: + +permissions: + contents: read + security-events: write + +jobs: + scan-go-dependencies: + name: Scan Go dependencies + runs-on: ubuntu-24.04 + timeout-minutes: 15 + + steps: + - name: Check out repository + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Scan dependencies with Trivy + uses: aquasecurity/trivy-action@0.35.0 + with: + version: v0.74.0 + scan-type: fs + scan-ref: sw/nic/gpuagent + scanners: vuln + severity: HIGH,CRITICAL + ignore-unfixed: true + format: sarif + output: trivy-results.sarif + + - name: Upload Trivy results + uses: github/codeql-action/upload-sarif@v3.29.6 + if: always() + with: + sarif_file: trivy-results.sarif + category: trivy-go-dependencies diff --git a/Makefile b/Makefile index 9a525187..2ef04026 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,12 @@ CONTAINER_WORKDIR := /usr/src/github.com/ROCm/gpu-agent BUILD_DATE ?= $(shell date +%Y-%m-%dT%H:%M:%S%z) GIT_COMMIT ?= $(shell git rev-list -1 HEAD --abbrev-commit) BUILD_BASE_IMAGE ?= registry.access.redhat.com/ubi9/ubi:9.4 +GO_VERSION ?= $(shell awk '$$1 == "go" { print $$2; exit }' sw/nic/gpuagent/go.mod) export BUILD_BASE_IMAGE export GPUAGENT_BLD_CONTAINER_IMAGE export GPUAGENT_BLD_CONTAINER_IMAGE_UBUNTU +export GO_VERSION .PHONY: all all: diff --git a/tools/build-container/Dokerfile.rhel9 b/tools/build-container/Dockerfile.rhel9 similarity index 81% rename from tools/build-container/Dokerfile.rhel9 rename to tools/build-container/Dockerfile.rhel9 index df43eb65..02bd3652 100644 --- a/tools/build-container/Dokerfile.rhel9 +++ b/tools/build-container/Dockerfile.rhel9 @@ -2,6 +2,7 @@ # compilation and development tools pre-installed. ARG BUILD_BASE_IMAGE=registry.access.redhat.com/ubi9/ubi:9.8 FROM ${BUILD_BASE_IMAGE} +ARG GO_VERSION=1.25.13 LABEL maintainer="praveenkumar.shanmugam@amd.com" @@ -28,9 +29,9 @@ RUN dnf install -y --allowerasing \ RUN yum install -y sudo -RUN wget https://go.dev/dl/go1.25.13.linux-amd64.tar.gz && \ - tar -C /usr/local -xzf go1.25.13.linux-amd64.tar.gz && \ - rm -f go1.25.13.linux-amd64.tar.gz +RUN wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \ + tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \ + rm -f go${GO_VERSION}.linux-amd64.tar.gz ENV PATH=$PATH:/usr/local/go/bin:/root/go/bin ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH diff --git a/tools/build-container/Dokerfile.ubu2204 b/tools/build-container/Dockerfile.ubu2204 similarity index 84% rename from tools/build-container/Dokerfile.ubu2204 rename to tools/build-container/Dockerfile.ubu2204 index d1e486d8..1a14dde2 100644 --- a/tools/build-container/Dokerfile.ubu2204 +++ b/tools/build-container/Dockerfile.ubu2204 @@ -2,6 +2,7 @@ # compilation and development tools pre-installed. ARG BUILD_BASE_IMAGE=ubuntu:22.04 FROM ${BUILD_BASE_IMAGE} +ARG GO_VERSION=1.25.13 LABEL maintainer="praveenkumar.shanmugam@amd.com" @@ -30,9 +31,9 @@ RUN apt-get update && apt-get install -y \ WORKDIR /usr/src/github.com/Rocm/gpu-agent/ -RUN wget https://go.dev/dl/go1.25.13.linux-amd64.tar.gz && \ - tar -C /usr/local -xzf go1.25.13.linux-amd64.tar.gz && \ - rm -f go1.25.13.linux-amd64.tar.gz +RUN wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \ + tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \ + rm -f go${GO_VERSION}.linux-amd64.tar.gz ADD ./entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh diff --git a/tools/build-container/Makefile b/tools/build-container/Makefile index 3edd839c..1ecb01ec 100644 --- a/tools/build-container/Makefile +++ b/tools/build-container/Makefile @@ -8,18 +8,20 @@ rhel-builder: docker build --build-arg USER=$(shell id -un) \ --build-arg GROUP=$(shell id -gn) \ --build-arg BUILD_BASE_IMAGE=$(BUILD_BASE_IMAGE) \ + --build-arg GO_VERSION=$(GO_VERSION) \ --build-arg UID=$(shell id -u) \ --build-arg GID=$(shell id -g) \ -t ${GPUAGENT_BLD_CONTAINER_IMAGE} \ - . -f Dokerfile.rhel9 + . -f Dockerfile.rhel9 echo "dev container build complete : ${GPUAGENT_BLD_CONTAINER_IMAGE}" # create ubuntu based builder/developer container ubuntu-builder: docker build --build-arg USER=$(shell id -un) \ --build-arg GROUP=$(shell id -gn) \ + --build-arg GO_VERSION=$(GO_VERSION) \ --build-arg UID=$(shell id -u) \ --build-arg GID=$(shell id -g) \ -t ${GPUAGENT_BLD_CONTAINER_IMAGE_UBUNTU} \ - . -f Dokerfile.ubu2204 + . -f Dockerfile.ubu2204 echo "builder container build complete : ${GPUAGENT_BLD_CONTAINER_IMAGE_UBUNTU}"