Repository navigation
Implement Basic Trivy Scanning Workflow - #256
Conversation
|
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
…permissions - Scan jobs now upload SARIF files as artifacts - New dedicated upload-sarif-results job with only security-events:write permission - Display steps show all security issues (CVEs + secrets) for visibility - Scan steps only fail on HIGH/CRITICAL CVE vulnerabilities
Viewing Security Scan ResultsThe workflow successfully uploads SARIF results to GitHub Security, but the default Security tab view filters by How to View Results
All six SARIF uploads are completing successfully:
This is standard GitHub behavior for code scanning - PR results are filtered separately from main branch results. |
Viewing Security Scan ResultsThe workflow successfully uploads SARIF results to GitHub Security, but the default Security tab view filters by 'is:open branch:main', which means results from PR branches are not visible in the default view. How to View Results
All six SARIF uploads are completing successfully with unique categories. This is standard GitHub behavior for code scanning - PR results are filtered separately from main branch results. |
- Add comment in workflow explaining filter behavior - Add section in ADR explaining how to view results by branch/PR - Add PR comment with direct links to view scan results The default Security tab filters by 'is:open branch:main' which hides PR branch results. Users must use specific PR/branch filters to see results before merging to main.
|
ACK 40dd234 |
Design Decision: Upload Steps PatternThe upload job currently uses 6 individual steps instead of a matrix. This is intentional for Phase 1 (hardcoded images). Why Not Matrix Now?Matrix would require duplicating the image list:
Future: Dynamic Array Passing (Issue #252)Phase 2 will implement dynamic image detection, where:
Example for Phase 2: scan-images:
outputs:
scanned_images: ${{ steps.collect.outputs.images }}
upload-sarif:
needs: scan-images
strategy:
matrix:
image: ${{ fromJSON(needs.scan-images.outputs.scanned_images) }}Decision RationaleKeep current implementation because:
References:
|
da2ce7
left a comment
There was a problem hiding this comment.
This is a post-merge review of the Docker image scanning workflow from #256 (merge 9d8c4b8), read as it stands at f782b40 on the default branch.
What still runs: .github/workflows/docker-security-scan.yml keeps the shape #256 gave it. It builds the project images locally and scans them, scans the third-party images the deployment uses, and sends one SARIF file per image to code scanning under its own category. It runs on pushes to main and develop, on pull requests that touch the scanned paths, daily at 06:00 UTC and on manual dispatch. Every scan uses exit code 0, as docs/decisions/docker-security-scan-exit-code-zero.md decides, so beyond the job log the Security tab is the only place a finding shows. Since the merge, the project matrix has grown to four images, the extract-images job now produces the third-party list, and the third-party upload has moved into the scan job. Two claims in the description do not match the merged bytes. It says builds fail on findings with exit code 1, which the decision record in the same pull request reverses. It also mentions a TODO for #252, which the workflow does not contain.
[Major] The two project images this repository publishes never reach code scanning. The project matrix builds and scans deployer and tracker-backup (.github/workflows/docker-security-scan.yml:37, :46) and stores their SARIF as artifacts. But upload-sarif-results (:251) has upload steps only for provisioned-instance (:278) and ssh-server (:286), one hand-written step per image as #256 laid it out. ff4a4d9 and bb3d5ea added the matrix entries without adding matching steps. So when the daily run finds a new HIGH or CRITICAL CVE in an image that .github/workflows/container.yaml or .github/workflows/backup-container.yaml publishes, the finding appears only in the log of a green run. The backup image is the one that templates/docker-compose/docker-compose.yml.tera:234 deploys. Meanwhile the two test containers are tracked in the Security tab. docs/security/production/scans/torrust-tracker-backup.md:212 states that the backup image's results are uploaded there. Smallest fix: add two upload steps with the categories docker-project-deployer and docker-project-tracker-backup. A sturdier fix makes the upload job a matrix over the same image names, so a new image cannot be left out again.
[Minor] The job that runs the third-party scanner action holds security-events: write. b397688 added the permission to scan-third-party-images (.github/workflows/docker-security-scan.yml:197), and that job runs [email protected] twice (:208, :218). #256 had confined the permission to a job that runs only GitHub-owned actions (382f430). The action is pinned by a tag, and whoever controls the action's repository can move a tag. On a push or the daily run, code behind a moved tag would get a token that can upload SARIF and change alert states in this repository's code scanning, so it could hide the findings this workflow exists to raise. The same tag pin at :67 and :81 would let such code rewrite the project SARIF artifacts before the upload job reads them. Smallest fix: pin all four uses to the full commit id behind 0.35.0 and keep the tag as a comment. Moving the third-party upload back into a job that runs no third-party action would also restore the separation.
[Minor] Every SARIF upload carries continue-on-error: true (.github/workflows/docker-security-scan.yml:249, :284, :292). Because every scan also uses exit code 0, a run is green whether or not any result reached code scanning. A rejected upload on a push or the daily run therefore leaves the Security tab stale with no signal, even though the decision record makes that tab the enforcement point. This has already happened once. Between af3fc7b and b397688, the third-party uploads were refused with HTTP 422 (as the message of b397688 records) while the runs stayed green, because the error was swallowed. Smallest fix: continue-on-error: ${{ github.event_name == 'pull_request' }}, so only pull request runs tolerate a refused upload.
[Minor] Third-party categories include the image tag. .github/workflows/docker-security-scan.yml:248 builds the category from the sanitised reference with its tag, as the hard-coded docker-third-party-mysql-8.0 and its siblings in #256 did. A version bump therefore starts a new code scanning configuration, and no later run ever analyses the old one again, so the old configuration's open alerts are never closed by a new analysis. After 36fd5c3 moved Caddy from 2.10.2 to 2.11.2, alerts filed under docker-third-party-caddy-2.10.2 stay open on main for an image that is no longer deployed, until someone deletes that configuration by hand. b5ae273 (Grafana) and 5a2b09a (Prometheus) did the same. Smallest fix: derive the category from the repository part of the reference only, for example by cutting at the first : or @ before the tr at :231. Each upload then replaces the previous analysis of the same image.
[Minor] The extract-images job (.github/workflows/docker-security-scan.yml:98) declares no permissions:, and the workflow has no top-level block, so its token gets the repository default. That job runs the Rust toolchain action at :112, which is referenced by a branch and not by a release or commit, the cache action at :115, and a release build of the whole workspace. If the repository default grants write access, all of this runs with that access on every push and every daily run. Smallest fix: a top-level permissions: contents: read, which leaves the three jobs that declare their own unchanged, plus a commit-id pin for the toolchain action.
[Nit] The deployer image is scanned as its debug stage. The build at .github/workflows/docker-security-scan.yml:59 passes no --target, so it builds the last stage, debug (docker/deployer/Dockerfile:173). That stage adds vim, less, procps and net-tools to the release stage that .github/workflows/container.yaml:61 publishes. Nothing shipped is missed, but the comment at :55 (scan exactly what this repository produces) does not hold for this image, and the debug-only packages add findings. Fix: add a target field to the matrix (release for the deployer, production for the backup image) and pass it as --target.
[Nit] docs/security/production/scans/torrust-tracker-backup.md:211 says the scan runs weekly, but the cron at .github/workflows/docker-security-scan.yml:22 runs it daily.
Checked and found sound:
- the triggers and path filters;
- the effect of exit code 0: it suppresses only the vulnerability verdict, so a scanner error such as a failed database download or image pull still fails its step and turns the run red;
scanners: vulnon the SARIF steps;- the project scan job (
:31) and the project upload job (:260), which hold only the permissions they use; - the
if: always()conditions, which keep partial results; - artifact names, which are unique per run;
- the build contexts at
:39to:48, which match each Dockerfile's COPY paths; - the
matrix.imagevalue interpolated into the shell at:231, which comes from the repository's own source, so a pull request gains nothing it could not already run through the build; - the generated third-party list, which matches the images in
templates/docker-compose/docker-compose.yml.tera.
Closes #251
Overview
Implements a GitHub Actions workflow that uses Trivy to scan Docker images for vulnerabilities. This initial implementation uses a hardcoded list of images and provides immediate security coverage.
Changes
1. GitHub Actions Workflow (
.github/workflows/docker-security-scan.yml)Created a new workflow with two jobs:
Scan Project-Built Images
torrust-tracker-deployer/provisioned-instancetorrust-tracker-deployer/ssh-serverScan Third-Party Images
torrust/tracker:developmysql:8.0grafana/grafana:11.4.0prom/prometheus:v3.0.1Workflow Features:
exit-code: 1)Notes:
templates/docker-compose/docker-compose.yml.tera2. README Update
Added workflow badge to display scan status.
Testing
./scripts/pre-commit.sh)Future Work
This is Phase 1 of the security scanning epic. Phase 2 (#252) will:
showcommand to list scanned imagesRelated