Skip to content
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

darkhttpd service: chroot option #103991

Closed
wants to merge 1 commit into from
Closed

darkhttpd service: chroot option #103991

wants to merge 1 commit into from

Conversation

80aff123-9163-4f3e-a93d-4a2f35af9be1
Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • [X ] Fits CONTRIBUTING.md.

I added the option to enable the chroot in the darkhttpd service.
@aanderse
Copy link
Member

Given this service already uses DynamicUser I'm not sure how much value specifying this option to darkhttpd will add. If you instead used systemd to achieve the isolation you desire I think that would be more valuable for this service.

Are you familiar with systemd sandboxing/isolation options?

@jgarte
Copy link
Contributor

jgarte commented Jan 14, 2021

Given this service already uses DynamicUser I'm not sure how much value specifying this option to darkhttpd will add. If you instead used systemd to achieve the isolation you desire I think that would be more valuable for this service.

Is there any benefit of exposing systemd's sandboxing and darkhttpd's built-in chroot in the service api as options?

@aanderse
Copy link
Member

Depends how much systemd kool-aid you've drank. Seems like a redundant set of options to me, but then again I've drank quite a bit of systemd kool-aid...

@80aff123-9163-4f3e-a93d-4a2f35af9be1
Copy link
Author

@aanderse Thank you for your reply!

Some thoughts:

Depends how much systemd kool-aid you've drank.

If the implementation is different or doesn't use systemd then it might not seem redundant for the kool-aid abstainers. I'd prefer to have the choice and I think adding this feature would only introduce a trivial amount of code to the darkhttpd service definition.

Seems like a redundant set of options to me, but then again I've drank quite a bit of systemd kool-aid...

A different implementation of the same thing is not necessarily redundant in my eyes but pragmatists may object. Additionally, it would make the darkhttpd service API a bit more complete/comprehensive.

If in the future NixOS decides to support an alternative init system (sounds like that might not happen for a very long time) that does not bundle a sandboxing feature then the darkhttpd chroot option might already be somewhat ready to go with providing that option or at the very least (given nobody ever cares to use the darkhttpd chroot option and always favor the systemd service over the native option) serve as documentation of a comprehensive api for darkhttpd.

What do you think? Could we have both? What do other people in the nix community think? I don't mind opening it up for further discussion on the discourse if we'd like to weigh the pros and cons and think through it more.

@aanderse
Copy link
Member

@80aff123-9163-4f3e-a93d-4a2f35af9be1 no problem - I wouldn't stand in the way of someone adding some flexibility to this module 😄. We could ping the module author if you are keen on proceeding and I'm pretty sure they would be happy to accept a change like that 👍

The obstacle this PR has, though, is that I don't believe this would even work as-is. You need capabilities to call chroot, which darkhttpd tries to do if the --chroot flag is passed. Did you test this?

@jgarte
Copy link
Contributor

jgarte commented Jan 15, 2021

The obstacle this PR has, though, is that I don't believe this would even work as-is. You need capabilities to call chroot, which darkhttpd tries to do if the --chroot flag is passed.

@aanderse Thanks! Could you give an example of what would be needed to add the capabilities?

Did you test this?

It looks like the pull request branch from @80aff123-9163-4f3e-a93d-4a2f35af9be1 was deleted.

We could ping the module author if you are keen on proceeding and I'm pretty sure they would be happy to accept a change like that

@bobvanderlinden What are your thoughts on adding this feature to the darkhttpd service module?

@aanderse
Copy link
Member

@peterhoeg is the module author I believe.

You need to add CAP_SYS_CHROOT to AmbientCapabilities, conditional on the chroot option being set of course.

@jgarte
Copy link
Contributor

jgarte commented Jan 15, 2021

@peterhoeg is the module author I believe.

@aanderse Thanks for catching that. I confused the package maintainer with the service module author.

You need to add CAP_SYS_CHROOT to AmbientCapabilities, conditional on the chroot option being set of course.

Thanks! I found two extant examples of AmbientCapabilities and CAP_SYS_CHROOT being set in nixpkgs in case anyone would like to take a look. Below are the links for convenience:

  1. unbound service

  2. icecream service

I'd be happy to make a pull request with the additions for code review after @peterhoeg advises.

@stale
Copy link

stale bot commented Jul 15, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 15, 2021
@Artturin Artturin closed this Feb 3, 2023
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.

None yet

5 participants