diff --git a/.github/workflows/snapshot-build.yml b/.github/workflows/snapshot-build.yml index b4b5b22568..9d8df9ac06 100644 --- a/.github/workflows/snapshot-build.yml +++ b/.github/workflows/snapshot-build.yml @@ -95,12 +95,11 @@ jobs: build-args: | SUBSTRATE_CLI_GIT_COMMIT_HASH=${{ github.sha }} - - name: Trigger trivy-security-scan Workflow + - name: Trigger snyk-container-scan Workflow uses: peter-evans/repository-dispatch@ff45666b9427631e3450c54a1bcbee4d9ff4d7c0 # @v3.0.0 with: token: ${{ secrets.GITHUB_TOKEN }} - event-type: trivy-scan-dispatch - client-payload: '{"image": "${{ fromJSON(steps.meta.outputs.json).tags[0] }}"}' + event-type: snyk-scan-dispatch - name: Prepare executables for uploading run: | diff --git a/.github/workflows/snyk-security-scan.yml b/.github/workflows/snyk-security-scan.yml new file mode 100644 index 0000000000..79d44a8a68 --- /dev/null +++ b/.github/workflows/snyk-security-scan.yml @@ -0,0 +1,138 @@ +## +# This action runs Snyk container vulnerability scanner for Docker images. +## + +name: Snyk Container +on: + repository_dispatch: + types: [snyk-scan-dispatch] + workflow_dispatch: + push: + branches: + - snyk-vulnerability-scan + + +jobs: + snyk-container-scan: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + # we can just scan the images, but we are building the image and scanning from the Dockerfile as it can be more accurate and find more obscured vulnerabilities than simply scanning the pre-built image. + # See https://docs.snyk.io/scan-with-snyk/snyk-container/use-snyk-container/detect-the-container-base-image#how-snyk-container-identifies-base-images + - name: Build Farmer Docker image + run: docker build -t autonomys/farmer:snyk -f docker/farmer.Dockerfile . + + - name: Run Snyk to check Docker image for vulnerabilities + uses: snyk/actions/docker@b98d498629f1c368650224d6d212bf7dfa89e4bf # v0.4.0 + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + with: + image: autonomys/farmer:snyk + args: --file=docker/farmer.Dockerfile --severity-threshold=high + continue-on-error: true + + - name: Post-process sarif output for security severities set to "undefined" + run: | + sed -i 's/"security-severity": "undefined"/"security-severity": "0"/g' snyk.sarif + # Replace any "null" security severity values with 0. The undefined value is used in the case + # the NVD CVSS Score is not available. + # https://github.com/github/codeql-action/issues/2187 for more context. + - name: Post-process sarif output for security severities set to "null" + run: | + sed -i 's/"security-severity": "null"/"security-severity": "0"/g' snyk.sarif + + - name: Upload result to GitHub Code Scanning + uses: github/codeql-action/upload-sarif@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9 + with: + sarif_file: snyk.sarif + category: snyk-farmer-image + + # we can just scan the images, but we are building the image and scanning from the Dockerfile as it can be more accurate and find more obscured vulnerabilities than simply scanning the pre-built image. + # See https://docs.snyk.io/scan-with-snyk/snyk-container/use-snyk-container/detect-the-container-base-image#how-snyk-container-identifies-base-images + - name: Build Node Docker image + run: docker build -t autonomys/node:snyk -f docker/node.Dockerfile . + + - name: Run Snyk to check Docker image for vulnerabilities + uses: snyk/actions/docker@b98d498629f1c368650224d6d212bf7dfa89e4bf # v0.4.0 + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + with: + image: autonomys/node:snyk + args: --file=docker/node.Dockerfile --severity-threshold=high + continue-on-error: true + + - name: Post-process sarif output for security severities set to "undefined" + run: | + sed -i 's/"security-severity": "undefined"/"security-severity": "0"/g' snyk.sarif + # Replace any "null" security severity values with 0. The undefined value is used in the case + # the NVD CVSS Score is not available. + # https://github.com/github/codeql-action/issues/2187 for more context. + - name: Post-process sarif output for security severities set to "null" + run: | + sed -i 's/"security-severity": "null"/"security-severity": "0"/g' snyk.sarif + + - name: Upload result to GitHub Code Scanning + uses: github/codeql-action/upload-sarif@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9 + with: + sarif_file: snyk.sarif + category: snyk-node-image + + # we can just scan the images, but we are building the image and scanning from the Dockerfile as it can be more accurate and find more obscured vulnerabilities than simply scanning the pre-built image. + # See https://docs.snyk.io/scan-with-snyk/snyk-container/use-snyk-container/detect-the-container-base-image#how-snyk-container-identifies-base-images + - name: Build Bootstrap node Docker image + run: docker build -t autonomys/bootstrap-node:snyk -f docker/bootstrap-node.Dockerfile . + + - name: Run Snyk to check Docker image for vulnerabilities + uses: snyk/actions/docker@b98d498629f1c368650224d6d212bf7dfa89e4bf # v0.4.0 + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + with: + image: autonomys/bootstrap-node:snyk + args: --file=docker/bootstrap-node.Dockerfile --severity-threshold=high + continue-on-error: true + + - name: Post-process sarif output for security severities set to "undefined" + run: | + sed -i 's/"security-severity": "undefined"/"security-severity": "0"/g' snyk.sarif + # Replace any "null" security severity values with 0. The undefined value is used in the case + # the NVD CVSS Score is not available. + # https://github.com/github/codeql-action/issues/2187 for more context. + - name: Post-process sarif output for security severities set to "null" + run: | + sed -i 's/"security-severity": "null"/"security-severity": "0"/g' snyk.sarif + + - name: Upload result to GitHub Code Scanning + uses: github/codeql-action/upload-sarif@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9 + with: + sarif_file: snyk.sarif + category: snyk-bootstrap-node-image + + # we can just scan the images, but we are building the image and scanning from the Dockerfile as it can be more accurate and find more obscured vulnerabilities than simply scanning the pre-built image. + # See https://docs.snyk.io/scan-with-snyk/snyk-container/use-snyk-container/detect-the-container-base-image#how-snyk-container-identifies-base-images + - name: Build Gateway Docker image + run: docker build -t autonomys/gateway:snyk -f docker/gateway.Dockerfile . + + - name: Run Snyk to check Docker image for vulnerabilities + uses: snyk/actions/docker@b98d498629f1c368650224d6d212bf7dfa89e4bf # v0.4.0 + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + with: + image: autonomys/gateway:snyk + args: --file=docker/gateway.Dockerfile --severity-threshold=high + continue-on-error: true + + - name: Post-process sarif output for security severities set to "undefined" + run: | + sed -i 's/"security-severity": "undefined"/"security-severity": "0"/g' snyk.sarif + # Replace any "null" security severity values with 0. The undefined value is used in the case + # the NVD CVSS Score is not available. + # https://github.com/github/codeql-action/issues/2187 for more context. + - name: Post-process sarif output for security severities set to "null" + run: | + sed -i 's/"security-severity": "null"/"security-severity": "0"/g' snyk.sarif + + - name: Upload result to GitHub Code Scanning + uses: github/codeql-action/upload-sarif@9e8d0789d4a0fa9ceb6b1738f7e269594bdd67f0 # v3.28.9 + with: + sarif_file: snyk.sarif + category: snyk-gateway-image diff --git a/.github/workflows/trivy-security-scan.yml b/.github/workflows/trivy-security-scan.yml deleted file mode 100644 index e2e63d9b5c..0000000000 --- a/.github/workflows/trivy-security-scan.yml +++ /dev/null @@ -1,68 +0,0 @@ -## -# This action runs Trivy container and repository vulnerability -# scanner for Docker images and filesystem. -## - -name: trivy-security-scan - -on: - repository_dispatch: - types: [trivy-scan-dispatch] - -jobs: - trivy_scan: - runs-on: ubuntu-latest - permissions: - contents: read - security-events: write - - steps: - - name: Checkout code - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - - # Image availability check with retry logic - - name: Check Docker image availability with retry - id: check-image - if: github.event.client_payload.image != '' - run: | - image="${{ github.event.client_payload.image }}" - interval=300 - retry_limit=5 - attempt=0 - - while ! docker pull $image; do - attempt=$((attempt + 1)) - if [ "$attempt" -gt "$retry_limit" ]; then - echo "::error::Image $image is not available after $retry_limit attempts." - exit 1 - fi - - echo "Waiting for $image to be available. Attempt $attempt/$retry_limit. Retrying in $interval seconds..." - sleep $interval - done - - echo "Image $image is now available." - - # Image scanning - - name: Run Trivy vulnerability scanner on image - if: github.event.client_payload.image != '' - uses: aquasecurity/trivy-action@915b19bbe73b92a6cf82a1bc12b087c9a19a5fe2 # v0.28.0 - with: - version: 'latest' - image-ref: ${{ github.event.client_payload.image }} - cache: 'true' - format: "sarif" - output: "trivy-image-results.sarif" - exit-code: "1" - ignore-unfixed: true - vuln-type: "os,library" - severity: "CRITICAL,HIGH" - env: - TRIVY_CACHE_DIR: .cache/trivy - - # Upload image scan results - - name: Upload Trivy image scan results - uses: github/codeql-action/upload-sarif@1b1aada464948af03b950897e5eb522f92603cc2 # v3.24.9 - with: - sarif_file: "trivy-image-results.sarif" - category: trivy-image