fix(image): trivy image cache writable by scanner user (0.3.3) - #16
Merged
Conversation
v0.3.2's image-scan lane was non-functional under the non-root scanner user — every base-image scan failed with: trivy image <ref>: ... unable to initialize cache: ... mkdir /var/cache/trivy/fanal: permission denied The Dockerfile chmod'd /var/cache/trivy to a+rX (read-only for others). `trivy fs` is fine — it doesn't need to write under the cache dir. But `trivy image` creates a `fanal/` subdir at runtime to cache extracted image layers, and an a+rX parent fails that mkdir. Fix: chown -R 1000:1000 instead of chmod a+rX. The pre-baked DBs are still readable; the scanner user can now also create fanal/. Caught by a fresh-dir end-to-end test of the ai-skills security-scan skill against v0.3.2 — `trivy fs` succeeded but `trivy image python:3.14-slim` failed with the perms error above. No Python code change. Tests unaffected (302 passed). Version: 0.3.2 -> 0.3.3. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes the container image’s Trivy cache permissions so trivy image works when the scanner runs as the non-root scanner user, and bumps the project/image version to 0.3.3 to reflect the release.
Changes:
- Make
/var/cache/trivywritable by thescanneruser by switching fromchmod -R a+rXtochown -R 1000:1000. - Bump version from
0.3.2→0.3.3across the manifest and Python package metadata. - Add a 0.3.3 changelog entry documenting the fix and rationale.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Dockerfile | Adjusts Trivy cache ownership so trivy image can create runtime subdirectories under a non-root user. |
| SECURITY-SCAN-MANIFEST.yaml | Updates release metadata to 0.3.3, release date, and adds a detailed changelog entry. |
| security_scan/init.py | Updates __version__ to 0.3.3. |
| pyproject.toml | Updates [project].version to 0.3.3. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
v0.3.2's image-scan lane was non-functional under the non-root `scanner` user. Every `trivy image` call failed with:
```
trivy image : exit 1: unable to initialize cache: unable to initialize fs cache:
failed to create cache dir: mkdir /var/cache/trivy/fanal: permission denied
```
The Dockerfile pre-cached the trivy DBs and `chmod -R a+rX`-ed the dir (read-only for non-root). `trivy fs` is fine — it reads but doesn't write. `trivy image` needs to create `fanal/` at runtime to cache extracted image layers, and `a+rX` blocks that mkdir.
Fix: `chown -R 1000:1000` instead of `chmod a+rX` — DBs remain readable; the scanner user can now create the runtime subdirs.
How it was caught
Fresh-dir end-to-end test of the ai-skills `security-scan` skill against v0.3.2. `trivy fs` ran clean; `image:unknown — trivy image python:3.14-slim — exit 1: ...permission denied` came back from the image lane.
Changes
No Python code change. Tests unaffected (302 passed).
Test plan
🤖 Generated with Claude Code