Repository navigation
Harden image and fix Snyk URL sanitization #14
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| .git | ||
| .github | ||
| .venv | ||
| __pycache__ | ||
| *.py[cod] | ||
| .pytest_cache | ||
| .ruff_cache | ||
| .mypy_cache | ||
| .env | ||
| .env.* | ||
| !.env.example | ||
| data | ||
| tests | ||
| *.md | ||
| .snyk | ||
| docker-compose*.yml |
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
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 |
|---|---|---|
| @@ -1,20 +1,36 @@ | ||
| FROM python:3.12-slim | ||
| # syntax=docker/dockerfile:1 | ||
|
|
||
| FROM python:3.12.16-alpine3.24 AS build | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| RUN python -m venv /opt/venv | ||
| ENV PATH="/opt/venv/bin:$PATH" | ||
|
|
||
| RUN --mount=type=bind,source=requirements.txt,target=requirements.txt \ | ||
| pip install --no-cache-dir --no-compile -r requirements.txt | ||
|
|
||
| FROM python:3.12.16-alpine3.24 AS runtime | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
| PYTHONUNBUFFERED=1 \ | ||
| TZ=Australia/Brisbane | ||
|
|
||
| RUN apt-get update \ | ||
| && apt-get install -y --no-install-recommends tzdata \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
| TZ=Australia/Brisbane \ | ||
| PATH="/opt/venv/bin:$PATH" | ||
|
|
||
| COPY requirements.txt . | ||
| RUN pip install --no-cache-dir -r requirements.txt | ||
| # uid/gid 1000 matches the usual first host user, so the ./data bind mount stays | ||
| # writable; compose can override it via APP_UID/APP_GID when the host differs. | ||
| RUN --mount=type=cache,target=/etc/apk/cache,sharing=locked \ | ||
| apk add tzdata \ | ||
| && addgroup -S -g 1000 appgroup \ | ||
| && adduser -S -u 1000 -G appgroup appuser \ | ||
| && mkdir -p /app/data \ | ||
| && chown appuser:appgroup /app/data | ||
|
|
||
| COPY src ./src | ||
| COPY --from=build --chown=appuser:appgroup /opt/venv /opt/venv | ||
| COPY --chown=appuser:appgroup src ./src | ||
|
|
||
| RUN mkdir -p /app/data | ||
| USER appuser | ||
|
|
||
| CMD ["python", "-m", "src", "--schedule"] | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 MEDIUM: Non-root user (uid 1001) cannot write to the bind-mounted ./data directory
The image now runs as
appuser(uid 1001) and only chowns/app/datainside the image. docker-compose.yml bind-mounts./data:/app/data, and that mount hides the chowned directory. On a Linux host,./datais owned by the host user (commonly uid 1000) or by root, so uid 1001 gets no write access.data/seen.jsonthen can't be saved, so seen-URL state is lost or the run errors, and the digest re-emails the same items every day. Fix: make the container uid configurable and match the host, for exampleuser: "${UID:-1000}:${GID:-1000}"in compose. Alternatively, document a requiredchown 1001:1001 datastep, or use a named volume.Additional Locations
docker-compose.yml:12— The bind mount ./data:/app/data overrides the in-image chown of /app/dataThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in bb80a15. The image user is now uid/gid 1000, and compose runs as
${APP_UID:-1000}:${APP_GID:-1000}(documented in.env.example). The README has a one-timechownstep for existing root-owneddata/directories left by the old root image. I checked locally that the container runs as 1000 and thatsave_seen/load_seenround-trip under/app/data.