Skip to content

fix: allow running as non-root #40642

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

Open
wants to merge 20 commits into
base: release
Choose a base branch
from
Open

Conversation

wyattwalter
Copy link
Contributor

@wyattwalter wyattwalter commented May 12, 2025

Description

Allows the Appsmith container to run as a non-root user, specified at runtime through either docker-compose or Kubernetes pod security context. I didn't specify the user in the Dockerfile because environments like OpenShift choose a user at runtime, so it can't be known at build time.

This needs to be followed by an update to docs and changes in the Helm chart to finish it off, but that has a separate release cycle and this needs to go ahead of that.

Ideally we would run as non-root by default, but since there's data persisted on the filesystem automatically transitioning the default is impossible without a lot of pain. This moves us in that direction and enables it in the future if we go down that path.

Required to fix #38787

Automation

/ok-to-test tags=""

🔍 Cypress test results

Warning

Tests have not run on the HEAD 50ba745 yet


Thu, 15 May 2025 15:56:31 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Added support for user identity emulation when running as a non-root user, improving compatibility in certain deployment environments.
    • Prevented embedded database initialization when running as a non-root user to ensure proper operation.
  • Chores

    • Installed additional system packages to the base image for enhanced functionality.
    • Optimized image size by consolidating and improving cleanup steps during the build process.
    • Updated base image and refined installation commands for improved build consistency.

Copy link
Contributor

coderabbitai bot commented May 12, 2025

Walkthrough

The changes update Docker build and entrypoint scripts to improve package installation, image cleanup, and user identity handling. The base Dockerfile now installs additional packages, consolidates cleanup steps, and sets up NSS Wrapper for non-root user support. The entrypoint script configures NSS Wrapper when running as a non-root user and prevents embedded Postgres initialization in non-root mode.

Changes

Files/Paths Change Summary
Dockerfile Reformatted the apt-get install command for improved readability; logic remains unchanged.
deploy/docker/base.dockerfile Added libnss-wrapper and git installation, consolidated cleanup steps, adjusted permissions on Redis config, set up NSS Wrapper symlink and environment variables.
deploy/docker/fs/opt/appsmith/entrypoint.sh Added logic to configure NSS Wrapper for non-root users, moved and updated UID logging, introduced fail_if_non_root() to block embedded Postgres init for non-root users.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Entrypoint Script
    participant NSS Wrapper

    User->>Entrypoint Script: Start container
    Entrypoint Script->>Entrypoint Script: Check if running as non-root
    alt Non-root user
        Entrypoint Script->>NSS Wrapper: Create temp passwd/group files with current UID/GID
        Entrypoint Script->>Entrypoint Script: Export LD_PRELOAD with NSS Wrapper symlink
    end
    Entrypoint Script->>Entrypoint Script: Log current UID
    Entrypoint Script->>Entrypoint Script: If init_postgres, call fail_if_non_root to prevent embedded DB init
    Entrypoint Script->>User: Continue application startup
Loading

Possibly related PRs

  • chore: update base image for appsmith #40058: Updates the base image version and upgrades database versions and key management in the same Dockerfile; both modify the base image and package setup but focus on different aspects.

Suggested labels

skip-changelog

Suggested reviewers

  • sharat87
  • nidhi-nair

Poem

In Docker’s halls, new packages arrive,
With cleanup so thorough, the images thrive.
NSS Wrapper stands ready for users not root,
Ensuring the entrypoint’s logic stays astute.
With tidy commands and a symlink in tow,
The container’s identity is ready to go!
🐳✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ 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.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between c0b3db2 and 0616138.

📒 Files selected for processing (1)
  • deploy/docker/fs/opt/appsmith/entrypoint.sh (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • deploy/docker/fs/opt/appsmith/entrypoint.sh

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 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.

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.

@github-actions github-actions bot added the Bug Something isn't working label May 12, 2025
@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/14976096450.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/14976813608.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/14980450347.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/14980505949.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/14980819023.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/14981979160.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/15005175710.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

Copy link
Contributor

@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

♻️ Duplicate comments (1)
deploy/docker/base.dockerfile (1)

25-25: Include git in base image for consistency
This aligns with the root Dockerfile change.

🧹 Nitpick comments (1)
deploy/docker/fs/opt/appsmith/entrypoint.sh (1)

16-23: Initialize NSS wrapper for non-root users
The setup block correctly generates temporary passwd/group files. For consistency, consider using the $TMP variable instead of hardcoding /tmp/appsmith.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74b7afe and 7bff585.

📒 Files selected for processing (3)
  • Dockerfile (1 hunks)
  • deploy/docker/base.dockerfile (2 hunks)
  • deploy/docker/fs/opt/appsmith/entrypoint.sh (1 hunks)
🔇 Additional comments (6)
deploy/docker/base.dockerfile (4)

24-24: Add libnss-wrapper for non-root user support
This package is necessary to enable NSS wrapper emulation at runtime.


33-42: Consolidated cleanup after package installation
Removing apt caches, docs, man pages, and temporary files effectively reduces image size.


88-91: Create symlink for libnss_wrapper.so
Linking the architecture-specific library to a stable path simplifies LD_PRELOAD activation.


92-94: Export NSS wrapper environment variables
Setting NSS_WRAPPER_PASSWD and NSS_WRAPPER_GROUP prepares the container for optional runtime emulation.

deploy/docker/fs/opt/appsmith/entrypoint.sh (1)

25-25: Retain user identity log placement
Moving the tlog "Running as: $(id)" call after the NSS wrapper setup improves clarity.

Dockerfile (1)

16-17: Refactor apt-get install formatting for readability
Moving apt-get install -y git to its own indented line aligns with best practices and has no functional impact.

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/15031515817.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/15031794549.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/15048572151.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com

@wyattwalter
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/15048924049.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 40642.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-40642.dp.appsmith.com


RUN mv /opt/caddy/caddy /opt/caddy/caddy_vanilla
| tar -xz -C /opt/caddy && \
mv /opt/caddy/caddy /opt/caddy/caddy_vanilla
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This removed an extra layer, removing ~50MB from the image.

@github-actions github-actions bot added Community Reported issues reported by community members DevOps Pod Issues related to devops K8s Kubernetes related issues Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production labels May 15, 2025
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Community Reported issues reported by community members DevOps Pod Issues related to devops K8s Kubernetes related issues Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Appsmith-EE helm chart refers to non-existing non-root user and group
1 participant