mirror of
https://github.com/appleboy/drone-scp.git
synced 2026-06-04 10:15:05 +08:00
ci: add Trivy security scanning for source code and Docker image
- Add independent trivy.yml workflow with repo scan and image scan jobs - Add Trivy image scan step in docker.yml before pushing Docker image - Add security-events permission for SARIF upload - Add Trivy Security Scan badge to README
This commit is contained in:
@@ -10,6 +10,11 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- "master"
|
- "master"
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
security-events: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-docker:
|
build-docker:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -59,6 +64,31 @@ jobs:
|
|||||||
type=semver,pattern={{major}}.{{minor}}
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
type=semver,pattern={{major}}
|
type=semver,pattern={{major}}
|
||||||
|
|
||||||
|
- name: Build image for scanning
|
||||||
|
uses: docker/build-push-action@v7
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: docker/Dockerfile
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: false
|
||||||
|
load: true
|
||||||
|
tags: drone-scp:scan
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner
|
||||||
|
uses: aquasecurity/trivy-action@v0.35.0
|
||||||
|
with:
|
||||||
|
image-ref: "drone-scp:scan"
|
||||||
|
format: "sarif"
|
||||||
|
output: "trivy-image-results.sarif"
|
||||||
|
severity: "CRITICAL,HIGH"
|
||||||
|
|
||||||
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
sarif_file: "trivy-image-results.sarif"
|
||||||
|
category: "trivy-docker-image"
|
||||||
|
|
||||||
- name: Build and push
|
- name: Build and push
|
||||||
uses: docker/build-push-action@v7
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
name: Trivy Security Scan
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
schedule:
|
||||||
|
# Run daily at 00:00 UTC
|
||||||
|
- cron: "0 0 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
trivy-repo-scan:
|
||||||
|
name: Trivy Repository Scan
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner (repo)
|
||||||
|
uses: aquasecurity/trivy-action@v0.35.0
|
||||||
|
with:
|
||||||
|
scan-type: "fs"
|
||||||
|
scan-ref: "."
|
||||||
|
format: "sarif"
|
||||||
|
output: "trivy-repo-results.sarif"
|
||||||
|
severity: "CRITICAL,HIGH"
|
||||||
|
|
||||||
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
sarif_file: "trivy-repo-results.sarif"
|
||||||
|
|
||||||
|
trivy-image-scan:
|
||||||
|
name: Trivy Image Scan
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
|
||||||
|
- name: Setup go
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version-file: go.mod
|
||||||
|
check-latest: true
|
||||||
|
|
||||||
|
- name: Build binary
|
||||||
|
run: |
|
||||||
|
make build_linux_amd64
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v4
|
||||||
|
|
||||||
|
- name: Build Docker image for scanning
|
||||||
|
uses: docker/build-push-action@v7
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: docker/Dockerfile
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: false
|
||||||
|
load: true
|
||||||
|
tags: drone-scp:scan
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner (image)
|
||||||
|
uses: aquasecurity/trivy-action@v0.35.0
|
||||||
|
with:
|
||||||
|
image-ref: "drone-scp:scan"
|
||||||
|
format: "sarif"
|
||||||
|
output: "trivy-image-results.sarif"
|
||||||
|
severity: "CRITICAL,HIGH"
|
||||||
|
|
||||||
|
- name: Upload Trivy image scan results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v4
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
sarif_file: "trivy-image-results.sarif"
|
||||||
|
category: "trivy-image"
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
[](https://godoc.org/github.com/appleboy/drone-scp)
|
[](https://godoc.org/github.com/appleboy/drone-scp)
|
||||||
[](https://github.com/appleboy/drone-scp/actions/workflows/testing.yml)
|
[](https://github.com/appleboy/drone-scp/actions/workflows/testing.yml)
|
||||||
|
[](https://github.com/appleboy/drone-scp/actions/workflows/trivy.yml)
|
||||||
[](https://codecov.io/gh/appleboy/drone-scp)
|
[](https://codecov.io/gh/appleboy/drone-scp)
|
||||||
[](https://goreportcard.com/report/github.com/appleboy/drone-scp)
|
[](https://goreportcard.com/report/github.com/appleboy/drone-scp)
|
||||||
[](https://hub.docker.com/r/appleboy/drone-scp/)
|
[](https://hub.docker.com/r/appleboy/drone-scp/)
|
||||||
|
|||||||
Reference in New Issue
Block a user