Skip to content

Commit

Permalink
Merge pull request #332 from helxplatform/trivy_action
Browse files Browse the repository at this point in the history
Trivy action - CICD-198
  • Loading branch information
YaphetKG authored Dec 4, 2023
2 parents 13b2113 + 1c9d31e commit 8775a5d
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 50 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-push-dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ jobs:
# https://github.com/marketplace/actions/build-and-push-docker-images

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=host
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true

- name: Login to Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: containers.renci.org
username: ${{ secrets.CONTAINERHUB_USERNAME }}
Expand All @@ -72,7 +72,7 @@ jobs:
# Notes on Cache:
# https://docs.docker.com/build/ci/github-actions/examples/#inline-cache
- name: Build Push Container
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: .
push: true
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-push-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ jobs:
# step
# https://github.com/marketplace/actions/build-and-push-docker-images
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=host
- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true

- name: Login to Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: containers.renci.org
username: ${{ secrets.CONTAINERHUB_USERNAME }}
Expand All @@ -86,7 +86,7 @@ jobs:
# Notes on Cache:
# https://docs.docker.com/build/ci/github-actions/examples/#inline-cache
- name: Build Push Container
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
push: true
# Push to renci-registry and dockerhub here.
Expand Down
91 changes: 49 additions & 42 deletions .github/workflows/code-checks.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
# Workflow responsible for core acceptance testing.
# Tests Currently Run:
# - flake8-linter
# - image-build-test
#
# This workflow only validates images can build
# but does not push images to any repository.
#
# - PYTest
# - Bandit
# For PR Vulnerability Scanning a separate workflow will run.
# The build-push-dev-image and build-push-release workflows
# handle the develop and release image storage respectively.
#
#

name: Code-Checks
on:
push:
branches-ignore:
- master
- main
# push:
# branches-ignore:
# - master
# - main
# - develop
pull_request:
branches:
- develop
- master
- main
types: [ opened, synchronize ]
paths-ignore:
- README.md
- .old_cicd/*
Expand All @@ -27,13 +31,6 @@ on:
- .gitignore
- .dockerignore
- .githooks
pull_request:
branches:
- develop
- master
- main
types: [ opened, synchronize ]


jobs:
############################## flake8-linter ##############################
Expand Down Expand Up @@ -69,35 +66,45 @@ jobs:
# flake8 --ignore=E,W --exit-zero .
continue-on-error: true

############################## test-image-build ##############################
test-image-build:
# needs: flake8-linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# ############################## build-vuln-test ##############################
# build-vuln-test:
# # needs: flake8-linter
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: |
network=host
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# with:
# driver-opts: |
# network=host

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true
# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}
# logout: true

# # Notes on Cache:
# # https://docs.docker.com/build/ci/github-actions/examples/#inline-cache
# - name: Build Container
# uses: docker/build-push-action@v5
# with:
# context: .
# push: false
# load: true
# tag: ${{ github.repository }}:vuln-test
# cache-from: type=registry,ref=${{ github.repository }}:buildcache
# cache-to: type=registry,ref=${{ github.repository }}:buildcache,mode=max
# ####### Run for Fidelity ######
# - name: Run Trivy vulnerability scanner
# uses: aquasecurity/trivy-action@master
# with:
# image-ref: '${{ github.repository }}:vuln-test'
# severity: 'CRITICAL,HIGH'
# exit-code: '1'

# Notes on Cache:
# https://docs.docker.com/build/ci/github-actions/examples/#inline-cache
- name: Build Container
uses: docker/build-push-action@v4
with:
context: .
push: false
cache-from: type=registry,ref=${{ github.repository }}:buildcache
cache-to: type=registry,ref=${{ github.repository }}:buildcache,mode=max
################################### PYTEST ###################################
pytest:
runs-on: ubuntu-latest
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/trivy-pr-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

name: trivy-pr-scan
on:
pull_request:
branches:
- develop
- master
- main
types: [ opened, synchronize ]
paths-ignore:
- README.md
- .old_cicd/*
- .github/*
- .github/workflows/*
- LICENSE
- .gitignore
- .dockerignore
- .githooks

jobs:
trivy-pr-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
network=host
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
logout: true

# Notes on Cache:
# https://docs.docker.com/build/ci/github-actions/examples/#inline-cache
- name: Build Container
uses: docker/build-push-action@v5
with:
context: .
push: false
load: true
tags: ${{ github.repository }}:vuln-test
cache-from: type=registry,ref=${{ github.repository }}:buildcache
cache-to: type=registry,ref=${{ github.repository }}:buildcache,mode=max

# We will not be concerned with Medium and Low vulnerabilities
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ github.repository }}:vuln-test'
format: 'sarif'
severity: 'CRITICAL,HIGH'
output: 'trivy-results.sarif'
exit-code: '1'
# Scan results should be viewable in GitHub Security Dashboard
# We still fail the job if results are found, so below will always run
# unless manually canceled.
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: '!cancelled()'
with:
sarif_file: 'trivy-results.sarif'
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,8 @@ TOPMed phenotypic concept data is [here](https://github.com/helxplatform/dug/tre
## Release
To release, commit the change and select feature.
#### Fail on Vulnerability Detection
During PR's several vulnerability scanners are run. If there are vulnerabilities detected, the pr checks will fail and a report will be sent to Github Security Dashboard for viewing. Please ensure the vulnerability is mitigated prior to continuing the merge to protected branches.

0 comments on commit 8775a5d

Please sign in to comment.