Skip to content

Conversation

@nanotaboada
Copy link
Owner

@nanotaboada nanotaboada commented May 12, 2025

All files in the runtime image are now owned by root and made read-only.
This prevents non-root users from modifying code or config at runtime,
in line with container immutability best practices.

Permissions are set using --chown and --chmod at COPY time
to avoid insecure defaults. No chown/chmod is performed at runtime.

Related to: CWE-732, docker:S6504


This change is Reviewable

Summary by CodeRabbit

  • Chores
    • Added a recommended list of Visual Studio Code extensions to help standardize the development environment.
    • Improved the Dockerfile with enhanced metadata, streamlined dependency installation, explicit file permissions, and increased security for the application runtime.

@coderabbitai
Copy link

coderabbitai bot commented May 12, 2025

Walkthrough

A new .vscode/extensions.json file is introduced to recommend a set of Visual Studio Code extensions for the development environment. The Dockerfile is refactored to improve build clarity, security, and metadata annotation, including renaming build stages, consolidating commands, setting explicit file ownership, and adding image labels, without changing the core application logic.

Changes

File(s) Change Summary
.vscode/extensions.json Added a configuration file recommending ten VS Code extensions for Python, GitHub, containers, YAML, and tooling.
Dockerfile Refactored: renamed build stage, consolidated commands, set file ownership/permissions, added metadata labels, and improved user creation.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant VSCode

    Developer ->> VSCode: Open project
    VSCode ->> .vscode/extensions.json: Read recommended extensions
    VSCode -->> Developer: Suggest installation of recommended extensions
Loading
sequenceDiagram
    participant Docker
    participant BuildStage as "builder (build stage)"
    participant RuntimeStage as "runtime (final stage)"

    Docker->>BuildStage: Install build dependencies
    BuildStage->>BuildStage: Copy requirements.txt, build wheels
    BuildStage->>BuildStage: Clean up caches
    Docker->>RuntimeStage: Add metadata labels
    RuntimeStage->>RuntimeStage: Copy wheels, install dependencies with ownership
    RuntimeStage->>RuntimeStage: Copy app files, README, assets with permissions
    RuntimeStage->>RuntimeStage: Create non-root user
    RuntimeStage->>RuntimeStage: Set environment, expose port, set CMD
Loading

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

@codacy-production
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2b83bb2) 111 99 89.19%
Head commit (caf556c) 111 (+0) 99 (+0) 89.19% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#357) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@codecov
Copy link

codecov bot commented May 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.18%. Comparing base (2b83bb2) to head (caf556c).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #357   +/-   ##
=======================================
  Coverage   89.18%   89.18%           
=======================================
  Files           2        2           
  Lines         111      111           
=======================================
  Hits           99       99           
  Misses         12       12           
Components Coverage Δ
Services 79.31% <ø> (ø)
Routes 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
Dockerfile (2)

7-9: Pin apt-get package versions for reproducible builds.

Currently, apt-get install -y build-essential gcc libffi-dev libssl-dev installs the latest packages which may change over time. Pinning these packages to specific versions will make the build deterministic and prevent unexpected updates. For example:

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
      build-essential=12.6ubuntu4 gcc-12-base=12.6.0-2 libffi-dev=3.4.2-3ubuntu1 libssl-dev=3.0.2-0ubuntu1 && \
    rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*.deb

Please adjust versions to match your target distribution release.

🧰 Tools
🪛 GitHub Check: Codeac Code Quality

[warning] 7-7: DL3008
Pin versions in apt get install. Instead of apt-get install <package> use apt-get install <package>=<version>


21-25: Optional: Include version and revision labels.

Consider adding org.opencontainers.image.version (e.g., image tag or application version) and org.opencontainers.image.revision (git commit SHA) to enhance traceability of your container images.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b83bb2 and caf556c.

📒 Files selected for processing (2)
  • .vscode/extensions.json (1 hunks)
  • Dockerfile (1 hunks)
🧰 Additional context used
🪛 GitHub Check: Codeac Code Quality
Dockerfile

[warning] 7-7: DL3008
Pin versions in apt get install. Instead of apt-get install <package> use apt-get install <package>=<version>

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (6)
.vscode/extensions.json (1)

1-14: Approve recommended VSCode extensions.

The list covers key tooling for Python development, GitHub integration, container workflows, YAML editing, code quality checks, formatting, conventional commits, and .gitignore support. This will help standardize and streamline the developer experience.

Dockerfile (5)

12-14: Verify BuildKit support for --chown and --chmod flags.

The --chmod flag on COPY requires Docker BuildKit (Docker 20.10+). Ensure that your CI pipeline and local builds enable BuildKit; otherwise, these flags will be ignored or cause errors. If BuildKit is not available, you may need to fall back to:

COPY requirements.txt .
RUN chown root:root requirements.txt && chmod 644 requirements.txt

Also applies to: 27-29


21-25: Metadata labels improve image discoverability.

The added org.opencontainers.image.* labels clearly document the image title, description, license, and source repository. This aligns with best practices for OCI image metadata.


33-39: Read-only file permissions for application code.

Application files (main.py, directories under /app) are copied with --chmod=644/755 and owned by root:root, ensuring immutability at runtime. This satisfies the SonarQube rule docker:S6504 and aligns with container immutability best practices.


45-49: Dropping to a non-root user enhances security.

Creating a system user (fastapi) and switching to it at runtime (USER fastapi) follows the principle of least privilege, preventing the application from running as root. Well done.


50-56: Entrypoint and environment configuration look solid.

Setting PYTHONUNBUFFERED=1 ensures timely logging, exposing port 9000 and the Uvicorn command are correct. This setup maintains application observability and network accessibility.

@nanotaboada nanotaboada merged commit e085f57 into master May 12, 2025
22 checks passed
@nanotaboada nanotaboada deleted the feature/sonarqube-docker-s6504 branch May 12, 2025 17:56
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.

2 participants