Files
gh-action-readme/.github/workflows/security.yml
2025-09-11 10:17:49 +03:00

139 lines
4.3 KiB
YAML

---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: 'Security Scanning'
on:
push:
branches: ['main']
pull_request:
branches: ['main']
schedule:
# Run security scans every Sunday at 2:00 AM UTC
- cron: '0 2 * * 0'
merge_group:
permissions:
contents: read
security-events: write
actions: read
pull-requests: write
jobs:
# Comprehensive security coverage:
# - govulncheck: Go-specific vulnerability scanning
# - trivy: Multi-language dependency & filesystem scanning
# - gitleaks: Secrets detection in code history
# - dependency-review: PR-level dependency analysis
govulncheck:
name: Go Vulnerability Check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Set up Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6
with:
go-version-file: 'go.mod'
check-latest: true
- name: Install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
- name: Run govulncheck
run: govulncheck ./...
trivy:
name: Trivy Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@master # 0.32.0
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
- name: Run Trivy in GitHub SBOM mode and submit results to Dependency Graph
uses: aquasecurity/trivy-action@master # 0.32.0
with:
scan-type: 'fs'
format: 'github'
output: 'dependency-results.sbom.json'
image-ref: '.'
github-pat: ${{ secrets.GITHUB_TOKEN }}
secrets:
name: Secrets Detection
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
with:
fetch-depth: 0 # Full history for gitleaks
- name: Run gitleaks to detect secrets
uses: gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}} # Only required for gitleaks-action pro
docker-security:
name: Docker Image Security
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' # Skip on PRs to avoid building images unnecessarily
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Set up Go
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6
with:
go-version-file: 'go.mod'
check-latest: true
- name: Build the bin
shell: bash
run: make build
- name: Build Docker image
run: docker build -t gh-action-readme:test .
- name: Run Trivy vulnerability scanner on Docker image
uses: aquasecurity/trivy-action@master # 0.32.0
with:
image-ref: 'gh-action-readme:test'
format: 'sarif'
output: 'trivy-docker-results.sarif'
- name: Upload Docker Trivy scan results
uses: github/codeql-action/upload-sarif@51f77329afa6477de8c49fc9c7046c15b9a4e79d # v3
if: always()
with:
sarif_file: 'trivy-docker-results.sarif'
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
- name: Dependency Review
uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4
with:
fail-on-severity: high
comment-summary-in-pr: always