Scan docker image #36
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: Scan docker image | |
on: | |
schedule: | |
- cron: 0 4 * * 1 | |
workflow_dispatch: | |
permissions: | |
contents: read | |
env: | |
TRIVY_DB_REPOSITORY: "public.ecr.aws/aquasecurity/trivy-db" | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
image: ${{ steps.docker-push.outputs.image }} | |
permissions: | |
contents: write # dep-submission | |
id-token: write # nais docker-build-push | |
security-events: write # push sarif to github security | |
steps: | |
- name: Harden Runner | |
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0 | |
with: | |
disable-sudo: true | |
egress-policy: audit | |
allowed-endpoints: > | |
api.github.com:443 | |
auth.docker.io:443 | |
collector-internet.external.prod-gcp.nav.cloud.nais.io:443 | |
deploy.nav.cloud.nais.io:443 | |
d2glxqk2uabbnd.cloudfront.net:443 | |
europe-north1-docker.pkg.dev:443 | |
fulcio.sigstore.dev:443 | |
gcr.io:443 | |
github-registry-files.githubusercontent.com:443 | |
github.com:443 | |
iamcredentials.googleapis.com:443 | |
login.microsoftonline.com:443 | |
maven.pkg.github.com:443 | |
objects.githubusercontent.com:443 | |
production.cloudflare.docker.com:443 | |
public.ecr.aws:443 | |
registry-1.docker.io:443 | |
rekor.sigstore.dev:443 | |
repo.maven.apache.org:443 | |
sts.googleapis.com:443 | |
test.maskinporten.no:443 | |
tuf-repo-cdn.sigstore.dev:443 | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
java-version: 21 | |
distribution: 'temurin' | |
cache: 'maven' | |
- name: Bygg med maven | |
env: | |
GITHUB_USERNAME: x-access-token | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
mvn -B -DskipTests --no-transfer-progress package --settings .m2/maven-settings.xml --file pom.xml | |
- uses: nais/docker-build-push@v0 | |
id: docker-push | |
if: github.event.pull_request.user.login != 'dependabot[bot]' | |
with: | |
pull: true | |
team: teamfamilie | |
push_image: true | |
dockerfile: Dockerfile | |
docker_context: . | |
byosbom: target/classes/META-INF/sbom/application.cdx.json | |
- name: Run Trivy vulnerability scanner | |
if: github.event.pull_request.user.login != 'dependabot[bot]' | |
uses: aquasecurity/trivy-action@master | |
env: # Workaround for rate limiting inntil denne er fikset: https://github.com/aquasecurity/trivy-action/issues/389 | |
TRIVY_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-db,aquasec/trivy-db,ghcr.io/aquasecurity/trivy-db | |
TRIVY_JAVA_DB_REPOSITORY: public.ecr.aws/aquasecurity/trivy-java-db,aquasec/trivy-java-db,ghcr.io/aquasecurity/trivy-java-db | |
with: | |
image-ref: '${{ steps.docker-push.outputs.image }}' | |
format: 'sarif' | |
output: 'trivy.sarif' | |
severity: 'HIGH,CRITICAL' | |
limit-severities-for-sarif: true | |
- name: Upload results to GitHub Security | |
if: github.event.pull_request.user.login != 'dependabot[bot]' | |
uses: github/codeql-action/upload-sarif@v3 | |
with: | |
sarif_file: 'trivy.sarif' |