|
| 1 | +name: Snyk Security |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: ["main" ] |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +jobs: |
| 10 | + snyk: |
| 11 | + permissions: |
| 12 | + contents: read # for actions/checkout to fetch code |
| 13 | + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results |
| 14 | + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + - name: Set up Snyk CLI to check for security issues |
| 19 | + # Snyk can be used to break the build when it detects security issues. |
| 20 | + # In this case we want to upload the SAST issues to GitHub Code Scanning |
| 21 | + uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb |
| 22 | + |
| 23 | + # For Snyk Open Source you must first set up the development environment for your application's dependencies |
| 24 | + # For example for Node |
| 25 | + #- uses: actions/setup-node@v4 |
| 26 | + # with: |
| 27 | + # node-version: 20 |
| 28 | + |
| 29 | + env: |
| 30 | + # This is where you will need to introduce the Snyk API token created with your Snyk account |
| 31 | + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} |
| 32 | + |
| 33 | + # Runs Snyk Code (SAST) analysis and uploads result into GitHub. |
| 34 | + # Use || true to not fail the pipeline |
| 35 | + - name: Snyk Code test |
| 36 | + run: snyk code test --sarif > snyk-code.sarif # || true |
| 37 | + |
| 38 | + # Runs Snyk Open Source (SCA) analysis and uploads result to Snyk. |
| 39 | + - name: Snyk Open Source monitor |
| 40 | + run: snyk monitor --all-projects |
| 41 | + |
| 42 | + # Runs Snyk Infrastructure as Code (IaC) analysis and uploads result to Snyk. |
| 43 | + # Use || true to not fail the pipeline. |
| 44 | + - name: Snyk IaC test and report |
| 45 | + run: snyk iac test --report # || true |
| 46 | + |
| 47 | + # Build the docker image for testing |
| 48 | + - name: Build a Docker image |
| 49 | + run: docker build -t your/image-to-test . |
| 50 | + # Runs Snyk Container (Container and SCA) analysis and uploads result to Snyk. |
| 51 | + - name: Snyk Container monitor |
| 52 | + run: snyk container monitor your/image-to-test --file=Dockerfile |
| 53 | + |
| 54 | + # Push the Snyk Code results into GitHub Code Scanning tab |
| 55 | + - name: Upload result to GitHub Code Scanning |
| 56 | + uses: github/codeql-action/upload-sarif@v3 |
| 57 | + with: |
| 58 | + sarif_file: snyk-code.sarif |
0 commit comments