|
1 | | -# This workflow uses actions that are not certified by GitHub. |
2 | | -# They are provided by a third-party and are governed by |
3 | | -# separate terms of service, privacy policy, and support |
4 | | -# documentation. |
5 | | - |
6 | | -# A sample workflow which sets up Snyk to analyze the full Snyk platform (Snyk Open Source, Snyk Code, |
7 | | -# Snyk Container and Snyk Infrastructure as Code) |
8 | | -# The setup installs the Snyk CLI - for more details on the possible commands |
9 | | -# check https://docs.snyk.io/snyk-cli/cli-reference |
10 | | -# The results of Snyk Code are then uploaded to GitHub Security Code Scanning |
11 | | -# |
12 | | -# In order to use the Snyk Action you will need to have a Snyk API token. |
13 | | -# More details in https://github.com/snyk/actions#getting-your-snyk-token |
14 | | -# or you can signup for free at https://snyk.io/login |
15 | | -# |
16 | | -# For more examples, including how to limit scans to only high-severity issues |
17 | | -# and fail PR checks, see https://github.com/snyk/actions/ |
18 | | - |
19 | | -name: Snyk Security |
20 | | - |
21 | | -on: |
22 | | - push: |
23 | | - branches: ["main" ] |
24 | | - pull_request: |
25 | | - branches: ["main"] |
26 | | - |
27 | | -permissions: |
28 | | - contents: read |
| 1 | +name: Build code, run unit test, run SAST, SCA, DAST security scans for NodeJs App |
| 2 | +on: push |
29 | 3 |
|
30 | 4 | jobs: |
31 | | - snyk: |
32 | | - permissions: |
33 | | - contents: read # for actions/checkout to fetch code |
34 | | - security-events: write # for github/codeql-action/upload-sarif to upload SARIF results |
35 | | - actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status |
| 5 | + build: |
36 | 6 | runs-on: ubuntu-latest |
| 7 | + name: Run unit tests and SAST scan on the source code |
37 | 8 | steps: |
38 | | - - uses: actions/checkout@v4 |
39 | | - - name: Set up Snyk CLI to check for security issues |
40 | | - # Snyk can be used to break the build when it detects security issues. |
41 | | - # In this case we want to upload the SAST issues to GitHub Code Scanning |
42 | | - uses: snyk/actions/setup@806182742461562b67788a64410098c9d9b96adb |
43 | | - |
44 | | - # For Snyk Open Source you must first set up the development environment for your application's dependencies |
45 | | - # For example for Node |
46 | | - #- uses: actions/setup-node@v4 |
47 | | - # with: |
48 | | - # node-version: 20 |
49 | | - |
| 9 | + - uses: actions/checkout@v4 |
| 10 | + - uses: actions/setup-node@v4 |
| 11 | + with: |
| 12 | + node-version: 21 |
| 13 | + cache: npm |
| 14 | + - run: npm install |
| 15 | + - name: SonarCloud Scan |
| 16 | + uses: sonarsource/sonarcloud-github-action@master |
| 17 | + env: |
| 18 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} |
| 20 | + with: |
| 21 | + args: > |
| 22 | + -Dsonar.organization=dotnetgithubactionsorg |
| 23 | + -Dsonar.projectKey=dotnetgithubactionsproject |
| 24 | + security: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + needs: build |
| 27 | + name: Run the SCA scan on the source code |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@master |
| 30 | + - name: RunSnyk to check for vulnerabilities |
| 31 | + uses: snyk/actions/node@master |
| 32 | + continue-on-error: true |
50 | 33 | env: |
51 | | - # This is where you will need to introduce the Snyk API token created with your Snyk account |
52 | 34 | SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} |
53 | | - |
54 | | - # Runs Snyk Code (SAST) analysis and uploads result into GitHub. |
55 | | - # Use || true to not fail the pipeline |
56 | | - - name: Snyk Code test |
57 | | - run: snyk code test --sarif > snyk-code.sarif # || true |
58 | | - |
59 | | - # Runs Snyk Open Source (SCA) analysis and uploads result to Snyk. |
60 | | - - name: Snyk Open Source monitor |
61 | | - run: snyk monitor --all-projects |
62 | | - |
63 | | - # Runs Snyk Infrastructure as Code (IaC) analysis and uploads result to Snyk. |
64 | | - # Use || true to not fail the pipeline. |
65 | | - - name: Snyk IaC test and report |
66 | | - run: snyk iac test --report # || true |
67 | | - |
68 | | - # Build the docker image for testing |
69 | | - - name: Build a Docker image |
70 | | - run: docker build -t your/image-to-test . |
71 | | - # Runs Snyk Container (Container and SCA) analysis and uploads result to Snyk. |
72 | | - - name: Snyk Container monitor |
73 | | - run: snyk container monitor your/image-to-test --file=Dockerfile |
74 | | - |
75 | | - # Push the Snyk Code results into GitHub Code Scanning tab |
76 | | - - name: Upload result to GitHub Code Scanning |
77 | | - uses: github/codeql-action/upload-sarif@v3 |
| 35 | + zap_scan: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + needs: security |
| 38 | + name: Run DAST scan on the web application |
| 39 | + steps: |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + ref: master |
| 44 | + - name: ZAP Scan |
| 45 | + uses: zaproxy/action-baseline@v0.14.0 |
78 | 46 | with: |
79 | | - sarif_file: snyk-code.sarif |
| 47 | + target: 'http://example.com/' |
| 48 | + rules_file_name: '.zap/rules.tsv' |
| 49 | + cmd_options: '-a' |
0 commit comments