Skip to content

Conversation

@kaysond
Copy link

@kaysond kaysond commented Mar 16, 2025

🎟️ Tracking

Fixes #247 and bitwarden/server#2903

📔 Objective

Support running the unified container fully rootless and/or with a readonly root filesystem. See the commit message for a detailed listing of the changes.

Generally, the strategy is to move everything into /etc/bitwarden in the container, which must be bind-mounted out to the host where the permissions can be managed (specifically, the user specified must have r/w). There are a few files created by the entry point that are needed in other locations. These are addressed with soft links in the image. supervisord and nginx pid/temp/etc files are moved to /tmp, following convention.

Note that I left the PUID/PGID environment variables and behavior for the sake of not introducing breaking changes. However, I would strongly urge you to remove them (I can do that in this PR if you'd like). Though it can be convenient to start as root to set everything up then drop privileges for running the actual service, it needlessly increases the attack surface. Having a single directory to chmod/chown on the host is very simple. Given the importance of security for a password manager, I updated the example docker compose file and settings to be the most secure ("true" rootless, read only filesystem, no new privileges).

Also note that not every configuration will work. For example, if you run with PUID/PGID, but want a read only file system, the container fails trying to add the group because it can't write to /run. (Using user: works fine, though, because group/user creation is skipped). This is a another argument for removing the env vars.

Built and tested (briefly) using bitwarden/server@27606e2. I'd encourage further testing before merging.

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@kaysond kaysond requested review from a team as code owners March 16, 2025 05:08
@CLAassistant
Copy link

CLAassistant commented Mar 16, 2025

CLA assistant check
All committers have signed the CLA.

@kaysond
Copy link
Author

kaysond commented Mar 25, 2025

Bump. @tangowithfoxtrot could you please approve the workflow runs?

@kaysond
Copy link
Author

kaysond commented Mar 28, 2025

Maybe @mandreko-bitwarden or @vgrassia can help?

@kaysond
Copy link
Author

kaysond commented Apr 9, 2025

Bumping again. Maybe @pixman20 can approve the workflows?

@kaysond
Copy link
Author

kaysond commented Apr 22, 2025

How about @michalchecinski or @Eeebru ?

@sonarqubecloud
Copy link

@github-actions
Copy link
Contributor

Logo
Checkmarx One – Scan Summary & Detailsfbcc10ad-b28b-48d7-9d5a-ad3e74432ca7

Great job, no security vulnerabilities found in this Pull Request

@mu88
Copy link

mu88 commented Sep 8, 2025

@kaysond / @tangowithfoxtrot: what's the current state of this PR? I'm deliberately waiting to run Bitwarden rootless 🤓

@kaysond
Copy link
Author

kaysond commented Sep 8, 2025

@kaysond / @tangowithfoxtrot: what's the current state of this PR? I'm deliberately waiting to run Bitwarden rootless 🤓

Looks like it needs to be rebased, which I'm happy to do, but doesn't seem clear that it's going to be merged...

If the maintainers commit to merging it I'm happy to update it. Otherwise don't really want to spend more time.

@djsmith85 djsmith85 changed the title Add support for running rootless and with readonly filesystem [PM-29484] Add support for running rootless and with readonly filesystem Dec 9, 2025
@djsmith85 djsmith85 linked an issue Dec 10, 2025 that may be closed by this pull request
1 task
Copy link

@djsmith85 djsmith85 left a comment

Choose a reason for hiding this comment

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

Hi @kaysond, thank you for your contribution 🎉 ❤️

With the recent announcement of bitwarden-unified being out of beta, it was also decided to change the name to bitwarden-lite. This unfortunately has caused a ton of conflicts with your changes.

As you mentioned previously you'd be up to rebase, if you hear back from Bitwarden. I spoke with someone from @bitwarden/dept-bre and product management, and they think this is a great addition. Once you have updated the PR, this is ready for review by @bitwarden/dept-bre and possibly also @bitwarden/team-platform-dev.

Please let us know if you are still interested in contribution to this PR.

Thanks again for taking the time to contribute and adding a highly requested feature!

Kind regards,
Daniel

@kaysond
Copy link
Author

kaysond commented Dec 11, 2025

Hi @kaysond, thank you for your contribution 🎉 ❤️

With the recent announcement of bitwarden-unified being out of beta, it was also decided to change the name to bitwarden-lite. This unfortunately has caused a ton of conflicts with your changes.

As you mentioned previously you'd be up to rebase, if you hear back from Bitwarden. I spoke with someone from @bitwarden/dept-bre and product management, and they think this is a great addition. Once you have updated the PR, this is ready for review by @bitwarden/dept-bre and possibly also @bitwarden/team-platform-dev.

Please let us know if you are still interested in contribution to this PR.

Thanks again for taking the time to contribute and adding a highly requested feature!

Kind regards, Daniel

Sure, I'll rebase it when I have a chance and let you know.

@kaysond kaysond reopened this Dec 14, 2025
@kaysond
Copy link
Author

kaysond commented Dec 14, 2025

Rebase completed by blindly re-applying the patches to the new dir and fixing some obvious issues.

Still need to test.

@patschi
Copy link

patschi commented Dec 14, 2025

Not wanting to hijack this - but would you have plans to implement rootless & read-only to the 'classic' Bitwarden deployment method too? I prefer the 'original' approach as it fits better to the best-practises of how docker/containers were designed.

@kaysond
Copy link
Author

kaysond commented Dec 14, 2025

Not wanting to hijack this - but would you have plans to implement rootless & read-only to the 'classic' Bitwarden deployment method too? I prefer the 'original' approach as it fits better to the best-practises of how docker/containers were designed.

No, sorry. That's a much more involved project covering many Dockerfile and entrypoint.sh files (see https://github.com/search?q=repo%3Abitwarden%2Fserver%20Dockerfile&type=code).

You could apply the same strategy as is used here, though.

@kaysond
Copy link
Author

kaysond commented Dec 20, 2025

@djsmith85 - this is ready for review. Tested with server v2025.12.0

I'd like to add a github action to run shellcheck on the entrypoint script. It's not clear to me where that should go, though, since it seems you're using azure.

@pixman20
Copy link
Collaborator

Hi @kaysond, thank you again for you contribution!

We'll do some internal testing and get this reviewed.

I'd like to add a github action to run shellcheck on the entrypoint script. It's not clear to me where that should go, though, since it seems you're using azure.

I've also created a task to look at adding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Run Bitwarden-selfhosted as non-root container on the read-only filesystem Container should not run as root

6 participants