Skip to content

Instantly share code, notes, and snippets.

@RoseSecurity
Created June 20, 2024 19:33
Show Gist options
  • Save RoseSecurity/e3629578eaf45273cd44ac812b6500e7 to your computer and use it in GitHub Desktop.
Save RoseSecurity/e3629578eaf45273cd44ac812b6500e7 to your computer and use it in GitHub Desktop.
Scan your IaC repositories using this nifty GitLab CI Pipeline for identifying Terraform misconfigurations and vulnerabilities
stage:
- test
trivy:
stage: test
image: docker:stable
services:
- name: docker:dind
entrypoint: ["env", "-u", "DOCKER_HOST"]
command: ["dockerd-entrypoint.sh"]
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
IMAGE: trivy-ci-test:$CI_COMMIT_SHA
TRIVY_NO_PROGRESS: "true"
TRIVY_CACHE_DIR: ".trivycache/"
before_script:
- export TRIVY_VERSION=$(wget -qO - "https://api.github.com/repos/aquasecurity/trivy/releases/latest" | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/')
- echo $TRIVY_VERSION
- wget --no-verbose https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.tar.gz -O - | tar -zxvf -
allow_failure: true
script:
# Filesystem report
- ./trivy filesystem --scanners misconfig,vuln --exit-code 0 --format template --template "@contrib/gitlab-codequality.tpl" -o terraform_scan.json .
cache:
paths:
- .trivycache/
artifacts:
paths:
- terraform_scan.json
reports:
codequality: terraform_scan.json
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment