Skip to content

security: harden Dockerfile and add .dockerignore#40

Open
sylvainkalache wants to merge 4 commits intomainfrom
security/dockerfile-hardening
Open

security: harden Dockerfile and add .dockerignore#40
sylvainkalache wants to merge 4 commits intomainfrom
security/dockerfile-hardening

Conversation

@sylvainkalache
Copy link
Contributor

Summary

  • Add non-root user (appuser) to Dockerfile so the container process doesn't run as root, reducing blast radius if compromised
  • Create .dockerignore to exclude .git, .venv, tests, coverage files, CI configs, and other dev artifacts from the Docker image

Test plan

  • Verify all unit tests pass
  • Build Docker image and confirm it starts correctly as non-root user
  • Verify .git and other excluded files are not in the built image

Change auto_promote condition from 'main' to 'master' to match
the actual branch name used in Semaphore CI.
- Add non-root user (appuser) to run the container process,
  reducing blast radius if the container is compromised.
- Create .dockerignore to exclude .git, .venv, tests, coverage
  files, and other dev artifacts from the Docker image.
@greptile-apps
Copy link

greptile-apps bot commented Feb 6, 2026

Greptile Overview

Greptile Summary

This PR hardens the Docker configuration by running the container as a non-root user and excluding development files from the image.

Key changes:

  • Creates appuser (UID 1000) and switches to it before running the application
  • Adds .dockerignore to exclude .git, .venv, tests, cache files, and CI configs

Critical issue:

  • The application writes swagger.json to /app (server.py:3564) but appuser won't have write permissions to this directory since ownership wasn't transferred after file copying

Confidence Score: 2/5

  • This PR will cause runtime failures when the application attempts to write the swagger file
  • The non-root user implementation will prevent the application from writing required files to /app, causing the application to fail when fetching swagger specs
  • Dockerfile requires fixing ownership of /app directory for appuser

Important Files Changed

Filename Overview
Dockerfile Added non-root user for security, but missing write permissions for /app directory where application writes swagger.json
.dockerignore Comprehensive exclusions for dev artifacts, tests, cache files, and CI configs to reduce image size

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

RUN uv pip install --system --no-cache-dir -e .

# Create non-root user
RUN useradd -m -u 1000 appuser
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appuser won't have write permissions to /app but the application writes swagger.json there (server.py:3564). Either change ownership of /app to appuser after copying files, or create a writable cache directory.

Suggested change
RUN useradd -m -u 1000 appuser
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
Prompt To Fix With AI
This is a comment left during a code review.
Path: Dockerfile
Line: 22:22

Comment:
`appuser` won't have write permissions to `/app` but the application writes `swagger.json` there (server.py:3564). Either change ownership of `/app` to `appuser` after copying files, or create a writable cache directory.

```suggestion
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
```

How can I resolve this? If you propose a fix, please make it concise.

Pin codecov/codecov-action and astral-sh/setup-uv to specific
commit SHAs to prevent supply chain attacks via compromised tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant