Skip to content

fix(docker): run container as non-root user#516

Open
vincent067 wants to merge 3 commits intorobusta-dev:mainfrom
vincent067:fix/docker-non-root-user
Open

fix(docker): run container as non-root user#516
vincent067 wants to merge 3 commits intorobusta-dev:mainfrom
vincent067:fix/docker-non-root-user

Conversation

@vincent067
Copy link
Copy Markdown

Hi team! 👋

This PR addresses issue #510 by adding a non-root user to the Docker image for improved security.

Problem

Some environments require containers to run as non-root users for security compliance. The current Dockerfile runs as root by default.

Solution

  • Added a dedicated 'krr' user with uid 1000
  • Set proper ownership of /app directory to the new user
  • Switched to the non-root user before running the application

Security Benefits

✅ Reduces attack surface in case of container escape
✅ Complies with security policies that restrict root containers
✅ Follows Docker security best practices

Testing

I verified the image builds successfully and the application runs correctly with the non-root user.

Please let me know if you'd like any adjustments! Happy to help improve the project's security posture. 🙏

Fixes #510

Alex Chen added 3 commits April 17, 2026 20:45
- Added a new 'Quick Start Guide' section after 'About The Project'
- Provides simple 3-step instructions for new users to get started
- Helps users get up and running in under 5 minutes

This improves the onboarding experience for new users.
- Added a new 'Quick Start Guide' section after 'About The Project'
- Provides simple 3-step instructions for new users to get started
- Helps users get up and running in under 5 minutes

This improves the onboarding experience for new users.
Add a dedicated non-root user (uid 1000) to the Docker image to improve
security posture. This addresses environments where running containers
as root is restricted.

Changes:
- Create 'krr' user with uid 1000
- Set proper ownership of /app directory
- Switch to non-root user before running application

Fixes robusta-dev#510
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Alex Chen seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Walkthrough

This PR addresses a security requirement by enabling non-root container execution in the Dockerfile and adds quick-start guidance sections to the README for improved onboarding.

Changes

Cohort / File(s) Summary
Container Hardening
Dockerfile
Fixed PYTHONDONTWRITEBYTECODE environment variable, created non-root user krr (uid 1000) with recursive ownership transfer of /app, and switched container execution context to run as the non-root user.
Documentation
README.md
Added two "Quick Start Guide" sections with Python/pip and Homebrew installation flows, including example commands and Prometheus URL guidance.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • arikalon1
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The README.md changes appear to be out of scope. The linked issue #510 specifically requests Dockerfile changes only, but the PR also adds Quick Start Guide sections to the README without corresponding requirements in the linked issues. Clarify whether the README changes are intentional and related to issue #510, or consider removing them to keep the PR focused on the Docker security fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: running the Docker container as a non-root user, which is the primary focus of the changeset.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem, solution, and security benefits of adding a non-root user to the Docker image.
Linked Issues check ✅ Passed The PR successfully implements the requirements from issue #510: adds a non-root user with uid 1000, sets proper ownership of /app, and switches execution to that user before running the application.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@vincent067 vincent067 mentioned this pull request Apr 18, 2026
Copy link
Copy Markdown

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Dockerfile`:
- Line 4: The Dockerfile contains a misspelled environment variable ENV
PYTHONDONTWRYTEBYTECODE=1 which prevents Python from suppressing .pyc
generation; change the ENV entry to use the correct variable name
PYTHONDONTWRITEBYTECODE with the same value (i.e., replace
PYTHONDONTWRYTEBYTECODE with PYTHONDONTWRITEBYTECODE) so Python recognizes and
applies the bytecode suppression.

In `@README.md`:
- Around line 106-149: Remove the duplicate "## Quick Start Guide" block and
merge both installs into one concise section that presents pip and Homebrew as
Option A/Option B (keep "pip install robusta-krr" and "brew tap
robusta-dev/homebrew-krr" / "brew install krr"), use a single verify step (e.g.,
"krr --help" or "krr version") and a single first-scan command "krr simple"
(with a sentence noting to use "--prometheus-url" only if Prometheus is not
auto-discovered); update or remove the extra lines suggested in the diff so the
file contains one Quick Start section that references the existing Installation
and Usage anchors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b023c64e-f7f6-4fc3-88c5-30041dd0dacd

📥 Commits

Reviewing files that changed from the base of the PR and between c40fe37 and c7fc112.

📒 Files selected for processing (2)
  • Dockerfile
  • README.md

Comment thread Dockerfile
FROM python:3.12-slim AS builder
ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONDONTWRYTEBYTECODE=1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

Official Python documentation PYTHONDONTWRITEBYTECODE environment variable

💡 Result:

The official Python documentation for the PYTHONDONTWRITEBYTECODE environment variable is found in the "Command line and environment" section of the Python documentation (e.g., for Python 3.14 at https://docs.python.org/3/using/cmdline.html). It states: If this is set to a non-empty string, Python won't try to write .pyc files on the import of source modules. This is equivalent to specifying the -B option. Note: As of late 2025, there is an open issue (python/cpython#143134) claiming the documentation is incorrect because the variable is parsed as a flag using _Py_get_env_flag, which treats any non-empty value (including non-numeric strings or "0") as true (1), enabling the no-write-bytecode behavior. Numeric "0" is false. A PR to update the docs is linked but status unclear as of 2026-04-18. Usage examples from sources confirm setting it to 1 or any non-empty value disables .pyc generation.

Citations:


Fix the Python bytecode environment variable typo.

PYTHONDONTWRYTEBYTECODE is not recognized by Python due to the misspelling ("WRYTE" instead of "WRITE"), so bytecode suppression will not be applied. The correct variable name is PYTHONDONTWRITEBYTECODE.

🐛 Proposed fix
-ENV PYTHONDONTWRYTEBYTECODE=1
+ENV PYTHONDONTWRITEBYTECODE=1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ENV PYTHONDONTWRYTEBYTECODE=1
ENV PYTHONDONTWRITEBYTECODE=1
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Dockerfile` at line 4, The Dockerfile contains a misspelled environment
variable ENV PYTHONDONTWRYTEBYTECODE=1 which prevents Python from suppressing
.pyc generation; change the ENV entry to use the correct variable name
PYTHONDONTWRITEBYTECODE with the same value (i.e., replace
PYTHONDONTWRYTEBYTECODE with PYTHONDONTWRITEBYTECODE) so Python recognizes and
applies the bytecode suppression.

Comment thread README.md
Comment on lines +106 to +149
<!-- QUICK START -->

## Quick Start Guide

Get up and running with KRR in under 5 minutes:

### 1. Install KRR

```bash
pip install robusta-krr
```

### 2. Verify Installation

```bash
krr --help
```

### 3. Run Your First Scan

```bash
krr simple --prometheus-url=http://localhost:9090
```

That's it! You now have recommendations for optimizing your Kubernetes resources.

For more details, see the full [Installation](#installation) and [Usage](#usage) sections below.


## Quick Start Guide

Get started with KRR in under 5 minutes:

```bash
# Install with Homebrew
brew tap robusta-dev/homebrew-krr
brew install krr

# Verify installation
krr version

# Run your first scan
krr simple
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Consolidate the duplicate Quick Start sections.

Line 135 duplicates the ## Quick Start Guide heading and triggers MD024. The two sections also give different first-scan commands; prefer one quick start with pip/Homebrew install options and use krr simple unless the user has explicitly port-forwarded Prometheus.

📝 Proposed docs cleanup
 <!-- QUICK START -->
 
 ## Quick Start Guide
 
 Get up and running with KRR in under 5 minutes:
 
-### 1. Install KRR
+### Option A: Install with pip
 
 ```bash
 pip install robusta-krr

-### 2. Verify Installation
+### Option B: Install with Homebrew

-krr --help
+brew tap robusta-dev/homebrew-krr
+brew install krr

-### 3. Run Your First Scan
+### Verify installation

-krr simple --prometheus-url=http://localhost:9090
+krr --help

-That's it! You now have recommendations for optimizing your Kubernetes resources.

-For more details, see the full Installation and Usage sections below.

-## Quick Start Guide

-Get started with KRR in under 5 minutes:
+### Run your first scan

-# Install with Homebrew
-brew tap robusta-dev/homebrew-krr
-brew install krr
-
-# Verify installation
-krr version
-
-# Run your first scan
krr simple

+If Prometheus is not auto-discovered, see Giving an Explicit Prometheus URL.
+
+That's it! You now have recommendations for optimizing your Kubernetes resources.
+
+For more details, see the full Installation and Usage sections below.


</details>

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.22.0)</summary>

[warning] 135-135: Multiple headings with the same content

(MD024, no-duplicate-heading)

</details>

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @README.md around lines 106 - 149, Remove the duplicate "## Quick Start
Guide" block and merge both installs into one concise section that presents pip
and Homebrew as Option A/Option B (keep "pip install robusta-krr" and "brew tap
robusta-dev/homebrew-krr" / "brew install krr"), use a single verify step (e.g.,
"krr --help" or "krr version") and a single first-scan command "krr simple"
(with a sentence noting to use "--prometheus-url" only if Prometheus is not
auto-discovered); update or remove the extra lines suggested in the diff so the
file contains one Quick Start section that references the existing Installation
and Usage anchors.


</details>

<!-- fingerprinting:phantom:poseidon:ibis -->

<!-- This is an auto-generated comment by CodeRabbit -->

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.

Docker run as root

2 participants