-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/snyk container scan #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6d01f3a
Add Snyk Container Scan workflow for Docker image security checks
dafneb 84b3769
Fix regex operator in Docker image name validation
dafneb 1b77191
Add Snyk vulnerability check and upload results to GitHub Code Scanning
dafneb 1d85c44
Update Snyk Code Scan and Container Scan workflows for improved SARIF…
dafneb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: Snyk Container Scan | ||
|
|
||
| # Controls when the workflow will run | ||
| on: | ||
| # This workflow uses the "workflow_call" event to allow it to be called from other workflows | ||
| workflow_call: | ||
| inputs: | ||
| working_directory: | ||
| required: false | ||
| type: string | ||
| default: "." | ||
| image_name: | ||
| required: true | ||
| type: string | ||
| default: "your/image-to-test" | ||
|
|
||
| # Assign permissions for the workflow | ||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| wrk_dir: ${{ inputs.working_directory }} | ||
| img: ${{ inputs.image_name }} | ||
|
|
||
| jobs: | ||
| security: | ||
| name: Snyk Container Scan | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| security-events: write | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@master | ||
| - name: Check directory | ||
| run: | | ||
| if [ ! -d "$WRK_DIR" ] | ||
| then | ||
| echo "Directory $WRK_DIR does not exist." | ||
| exit 1 | ||
| fi | ||
| shell: bash | ||
| env: | ||
| WRK_DIR: ${{ env.wrk_dir }} | ||
| - name: Check Dockerfile | ||
| run: | | ||
| if [ ! -f "$WRK_DIR/Dockerfile" ] | ||
| then | ||
| echo "Dockerfile not found in $WRK_DIR." | ||
| exit 1 | ||
| fi | ||
| shell: bash | ||
| env: | ||
| WRK_DIR: ${{ env.wrk_dir }} | ||
| - name: Check Docker image name | ||
| run: | | ||
| if [[ ! "$IMG" =~ ^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*(\/[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*)*$ ]] | ||
dafneb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| then | ||
| echo "Image name is not correct." | ||
| exit 1 | ||
| fi | ||
| shell: bash | ||
| env: | ||
| IMG: ${{ env.img }} | ||
| - name: Build a Docker image | ||
| run: | | ||
| docker build -t $IMG $WRK_DIR | ||
| shell: bash | ||
| env: | ||
| IMG: ${{ env.img }} | ||
| WRK_DIR: ${{ env.wrk_dir }} | ||
| - name: Run Snyk to check Docker image for vulnerabilities | ||
| # Snyk can be used to break the build when it detects vulnerabilities. | ||
| # In this case we want to upload the issues to GitHub Code Scanning | ||
| continue-on-error: true | ||
| uses: snyk/actions/docker@master | ||
Check warningCode scanning / CodeQL Unpinned tag for a non-immutable Action in workflow Medium
Unpinned 3rd party Action 'Snyk Container Scan' step
Uses Step Error loading related location Loading |
||
| env: | ||
| # In order to use the Snyk Action you will need to have a Snyk API token. | ||
| # See https://docs.snyk.io/integrations/ci-cd-integrations/github-actions-integration#getting-your-snyk-token | ||
| # or you can sign up for free at https://snyk.io/login | ||
| SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | ||
| with: | ||
| image: ${{ env.img }} | ||
| args: --file=${{ env.wrk_dir }}/Dockerfile | ||
| - name: Upload result to GitHub Code Scanning | ||
| if: ${{ hashFiles('**/snyk.sarif') != '' }} | ||
| uses: github/codeql-action/upload-sarif@main | ||
| with: | ||
| sarif_file: snyk.sarif | ||
| category: "snyk-container" | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.