|
| 1 | +name: Security scan |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [opened, synchronize, reopened] |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | +jobs: |
| 9 | + security-scan: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + env: |
| 12 | + PR_NUMBER: ${{ github.event.number }} |
| 13 | + COMMIT_SHA: ${{ github.sha }} |
| 14 | + TAG: hub-pipeline-sprite-pr${{ github.event.number }}-${{ github.sha }} |
| 15 | + steps: |
| 16 | + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v2 |
| 19 | + - name: Set up Docker Buildx |
| 20 | + uses: docker/setup-buildx-action@v1 |
| 21 | + - name: Log in to Docker Hub |
| 22 | + uses: docker/login-action@v1 |
| 23 | + with: |
| 24 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 25 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 26 | + |
| 27 | + # Build the Docker image with the latest tag and the release tag |
| 28 | + # Build the Docker image with the latest tag and the release tag |
| 29 | + - name: Build Docker image with PR tag |
| 30 | + run: | |
| 31 | + docker build -t uugai/pullrequests:${{ env.TAG }} \ |
| 32 | + --build-arg github_username=${{ secrets.USERNAME }} \ |
| 33 | + --build-arg github_token=${{ secrets.TOKEN }} . |
| 34 | +
|
| 35 | + # This is a workaround for the issue with the Trivy DBs not being available due to |
| 36 | + # rate limiting. The workaround is to download the DBs and cache them. |
| 37 | + - name: Setup oras |
| 38 | + uses: oras-project/setup-oras@v1 |
| 39 | + - name: Download and extract the vulnerability DB |
| 40 | + run: | |
| 41 | + mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db |
| 42 | + oras pull ghcr.io/aquasecurity/trivy-db:2 |
| 43 | + tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db |
| 44 | +
|
| 45 | + # Scan the Docker image for vulnerabilities |
| 46 | + - name: Run Trivy vulnerability scanner |
| 47 | + uses: aquasecurity/[email protected] |
| 48 | + with: |
| 49 | + skip-setup-trivy: false |
| 50 | + scan-type: "image" |
| 51 | + image-ref: "uugai/pullrequests:${{ env.TAG }}" |
| 52 | + format: "table" |
| 53 | + exit-code: "0" |
| 54 | + ignore-unfixed: false |
| 55 | + vuln-type: "os,library" |
| 56 | + severity: "CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN" |
| 57 | + #Below only works on the main branch |
| 58 | + #format: "github" |
| 59 | + #github-pat: ${{ secrets.TOKEN }} |
| 60 | + env: |
| 61 | + TRIVY_SKIP_DB_UPDATE: true |
0 commit comments