Added copa to the images build#247
Draft
bluvulture wants to merge 11 commits into
Draft
Conversation
Changed publishing process to publish only patched images
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Docker image release workflow to introduce an automated “scan + patch” stage (Trivy + Copa) before pushing images to registries, aiming to publish images after OS-level vulnerability remediation.
Changes:
- Defaults manual (
workflow_dispatch) runs to not publish images unless explicitly enabled. - Installs Trivy and Copa in the workflow, and starts a BuildKit daemon to support Copa patching.
- Changes the build/publish flow to build locally, scan + patch the image, then tag and push all tags manually.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+60
to
+66
| set -eux | ||
| # Install Trivy | ||
| sudo apt-get update | ||
| sudo apt-get install -y wget apt-transport-https gnupg lsb-release | ||
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null | ||
| echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list | ||
| sudo apt-get update |
Comment on lines
+63
to
+71
| sudo apt-get install -y wget apt-transport-https gnupg lsb-release | ||
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null | ||
| echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list | ||
| sudo apt-get update | ||
| sudo apt-get install -y trivy | ||
|
|
||
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" |
| -p 127.0.0.1:8888:8888/tcp \ | ||
| --name buildkitd \ | ||
| --entrypoint buildkitd \ | ||
| moby/buildkit:latest \ |
Comment on lines
+178
to
+186
| copa patch -i "${IMAGE_NAME}:${TAG}" \ | ||
| -r /tmp/trivy-report.json \ | ||
| -t "${TAG}-patched" \ | ||
| -a tcp://127.0.0.1:8888 | ||
|
|
||
| # Verify the patched image exists | ||
| if ! docker image inspect "${IMAGE_NAME}:${TAG}-patched" > /dev/null 2>&1; then | ||
| echo "::error::Patched image not found for ${IMAGE_NAME}:${TAG}" | ||
| exit 1 |
Comment on lines
+69
to
+74
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" | ||
| tar -xzf copa.tar.gz copa | ||
| sudo mv copa /usr/local/bin/copa | ||
| rm copa.tar.gz |
Comment on lines
+60
to
+65
| set -eux | ||
| # Install Trivy | ||
| sudo apt-get update | ||
| sudo apt-get install -y wget apt-transport-https gnupg lsb-release | ||
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null | ||
| echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list |
Comment on lines
+62
to
+71
| sudo apt-get update | ||
| sudo apt-get install -y wget apt-transport-https gnupg lsb-release | ||
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null | ||
| echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list | ||
| sudo apt-get update | ||
| sudo apt-get install -y trivy | ||
|
|
||
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" |
| sudo apt-get install -y trivy | ||
|
|
||
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') |
Comment on lines
+62
to
+71
| sudo apt-get update | ||
| sudo apt-get install -y wget apt-transport-https gnupg lsb-release | ||
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null | ||
| echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list | ||
| sudo apt-get update | ||
| sudo apt-get install -y trivy | ||
|
|
||
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" |
Comment on lines
+69
to
+72
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" | ||
| tar -xzf copa.tar.gz copa |
Comment on lines
+71
to
+74
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" | ||
| tar -xzf copa.tar.gz copa | ||
| sudo mv copa /usr/local/bin/copa | ||
| rm copa.tar.gz |
Comment on lines
+86
to
+93
| for i in $(seq 1 60); do | ||
| if docker exec buildkitd buildctl debug workers >/dev/null 2>&1; then | ||
| echo "BuildKit is ready" | ||
| break | ||
| fi | ||
| if [ "$i" -eq 60 ]; then | ||
| echo "::error::BuildKit failed to start within 60 seconds" | ||
| exit 1 |
Comment on lines
6
to
10
| publish: | ||
| description: 'Publish images to registries' | ||
| required: false | ||
| default: true | ||
| default: false | ||
| type: boolean |
Comment on lines
+186
to
+190
| -t "${TAG}-patched" \ | ||
| -a tcp://127.0.0.1:8888 | ||
|
|
||
| # Verify the patched image exists | ||
| if ! docker image inspect "${IMAGE_NAME}:${TAG}-patched" > /dev/null 2>&1; then |
Comment on lines
+207
to
+210
| echo "Running post-patch scan (fail on ${FAIL_SEVERITY}+)" | ||
| trivy image --vuln-type os --ignore-unfixed \ | ||
| --exit-code 1 \ | ||
| --severity "$FAIL_SEVERITY" \ |
Comment on lines
+74
to
+76
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" |
Comment on lines
+68
to
+76
| sudo apt-get install -y wget apt-transport-https gnupg lsb-release | ||
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null | ||
| echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list | ||
| sudo apt-get update | ||
| sudo apt-get install -y trivy | ||
|
|
||
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" |
Comment on lines
+184
to
+190
| copa patch -i "${IMAGE_NAME}:${TAG}" \ | ||
| -r /tmp/trivy-report.json \ | ||
| -t "${TAG}-patched" \ | ||
| -a tcp://127.0.0.1:8888 | ||
|
|
||
| # Verify the patched image exists | ||
| if ! docker image inspect "${IMAGE_NAME}:${TAG}-patched" > /dev/null 2>&1; then |
Comment on lines
+67
to
+76
| sudo apt-get update | ||
| sudo apt-get install -y wget apt-transport-https gnupg lsb-release | ||
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null | ||
| echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list | ||
| sudo apt-get update | ||
| sudo apt-get install -y trivy | ||
|
|
||
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" |
| fail_on_severity: | ||
| description: 'Fail build if post-patch CVEs remain at this severity (CRITICAL, HIGH, MEDIUM, LOW, or NONE to disable)' | ||
| required: false | ||
| default: 'CRITICAL,HIGH' |
Comment on lines
+74
to
+79
| # Install Copa | ||
| COPA_VERSION=$(curl -s https://api.github.com/repos/project-copacetic/copacetic/releases/latest | jq -r '.tag_name' | sed 's/^v//') | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" | ||
| tar -xzf copa.tar.gz copa | ||
| sudo mv copa /usr/local/bin/copa | ||
| rm copa.tar.gz |
|
|
||
| docker build --output "type=image,push=$PUSH" \ | ||
| # Build and load image locally | ||
| docker build --load \ |
| VERSION_OVERRIDE: "${{ matrix.build.version-override }}" | ||
| ARCH_TAG: ${{ contains(matrix.runner, 'arm') && 'arm64' || 'amd64' }} | ||
| PUSH: ${{ github.event_name != 'workflow_dispatch' || inputs.publish }} | ||
| FAIL_ON_SEVERITY: ${{ inputs.fail_on_severity || 'CRITICAL' }} |
| default: false | ||
| type: boolean | ||
| fail_on_severity: | ||
| description: 'Fail build if post-patch CVEs remain at this severity (CRITICAL, HIGH, MEDIUM, LOW, or NONE to disable)' |
Comment on lines
+74
to
+79
| # Install Copa | ||
| COPA_VERSION="0.14.1" | ||
| curl -fsSL -o copa.tar.gz "https://github.com/project-copacetic/copacetic/releases/download/v${COPA_VERSION}/copa_${COPA_VERSION}_linux_$(dpkg --print-architecture).tar.gz" | ||
| tar -xzf copa.tar.gz copa | ||
| sudo mv copa /usr/local/bin/copa | ||
| rm copa.tar.gz |
Comment on lines
+67
to
+72
| sudo apt-get update | ||
| sudo apt-get install -y wget apt-transport-https gnupg lsb-release | ||
| wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | gpg --dearmor | sudo tee /usr/share/keyrings/trivy.gpg > /dev/null | ||
| echo "deb [signed-by=/usr/share/keyrings/trivy.gpg] https://aquasecurity.github.io/trivy-repo/deb generic main" | sudo tee /etc/apt/sources.list.d/trivy.list | ||
| sudo apt-get update | ||
| sudo apt-get install -y trivy |
Comment on lines
+180
to
+184
| trivy image --pkg-types os --ignore-unfixed --format json \ | ||
| -o /tmp/trivy-report.json "${IMAGE_NAME}:${TAG}" | ||
|
|
||
| if [ -s /tmp/trivy-report.json ] && jq -e '.Results[]? | select(.Vulnerabilities != null and (.Vulnerabilities | length > 0))' /tmp/trivy-report.json > /dev/null 2>&1; then | ||
| copa patch -i "${IMAGE_NAME}:${TAG}" \ |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request updates the
release.ymlworkflow to add automated vulnerability scanning and patching to the Docker image build process, and refines how images are published and cleaned up. The main improvements are the integration of Trivy for vulnerability scanning, Copa for patching OS-level vulnerabilities, and enhanced image management during the build and publish steps.Security automation and image build improvements:
Vulnerability scanning and patching:
Build environment enhancements:
Publishing and workflow behavior:
Publishing control:
publishinput is changed fromtruetofalse, making image publishing opt-in for manual workflow dispatches.Image management and cleanup:
Other workflow refinements:
apt-get updatecall from the build step, as it is now handled during tool installation.