security #1202
This file contains 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
name: security | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
# The branches below must be a subset of the branches above | |
branches: ["main"] | |
schedule: | |
- cron: '28 0 * * 4' | |
permissions: | |
contents: read | |
jobs: | |
build: | |
permissions: | |
contents: read # for actions/checkout to fetch code | |
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results | |
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status | |
name: Trivy | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install trivy | |
run: | | |
sudo apt-get install 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 $(lsb_release -sc) main" | sudo tee -a /etc/apt/sources.list.d/trivy.list | |
sudo apt-get update && sudo apt-get install trivy | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@master | |
with: | |
install: true | |
config-inline: | | |
[registry."docker.io"] | |
mirrors = ["mirror.gcr.io"] | |
- name: Build and load Backend | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
builder: ${{ steps.buildx.outputs.name }} | |
file: ./Dockerfile | |
target: backend | |
load: true | |
build-args: | | |
BUNDLE_WITHOUT_GROUPS=test development | |
BUNDLE_IS_PRD=true | |
tags: | | |
fth-backend | |
fth-backend:${{ github.sha }} | |
cache-from: type=gha,scope=backend | |
cache-to: type=gha,scope=backend,mode=max | |
- name: Run Trivy vulnerability scanner | |
run: | | |
trivy image --format sarif --vuln-type os,library \ | |
--severity CRITICAL,HIGH --output trivy-results.sarif \ | |
fth-backend:${{ github.sha }} | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@v2 | |
if: github.event_name != 'pull_request' | |
with: | |
sarif_file: 'trivy-results.sarif' |