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

nixos/croc: init #93629

Merged
merged 1 commit into from Mar 13, 2021
Merged

nixos/croc: init #93629

merged 1 commit into from Mar 13, 2021

Conversation

ju1m
Copy link
Contributor

@ju1m ju1m commented Jul 22, 2020

Motivation for this change

Run a croc relay.

Things done
  • Add services.croc, with security parameters.
  • 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
  • Fits CONTRIBUTING.md.

Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

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

Looking good. A few minor comments.

nixos/modules/services/networking/croc.nix Show resolved Hide resolved
nixos/modules/services/networking/croc.nix Show resolved Hide resolved
nixos/modules/services/networking/croc.nix Show resolved Hide resolved
nixos/modules/services/networking/croc.nix Outdated Show resolved Hide resolved
@ju1m
Copy link
Contributor Author

ju1m commented Nov 21, 2020

Rebasing, nothing changed.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/prs-ready-for-review/3032/378

@ju1m ju1m requested a review from aanderse November 27, 2020 04:14
Copy link
Member

@aanderse aanderse left a comment

Choose a reason for hiding this comment

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

Full bonus points awarded for having upstream add the ability to specify a password file 🎉

I'm happy to merge this PR now. Thanks for your hard work. Call it a stretch goal... but if you were to submit a PR upstream to get your relevant changes into the upstream unit I'm sure it would be greatly appreciated. Then we could open a PR in nixpkgs to stop providing our own systemd unit and just include+customize the upstream unit via systemd.packages, significantly reducing the lines of code in this module.

@aanderse
Copy link
Member

@GrahamcOfBorg test croc

@aanderse
Copy link
Member

@GrahamcOfBorg eval

@aanderse
Copy link
Member

aanderse commented Dec 3, 2020

I'm not sure about the aarch64-linux failure 🤷‍♂️

@ju1m
Copy link
Contributor Author

ju1m commented Feb 18, 2021

Rebased after cc8a422 added a conflicting line in nixos/tests/all-tests.nix.

@aanderse indeed it would make sense to upstream a few relevant settings (eg. SystemCallFilter=), but other settings:

  • may be found too complex (eg. RootDirectory= needs InaccessiblePaths= and UMask= and RuntimeDirectory= and BindReadOnlyPaths= for paths specific to the Linux distribution);
  • or opinionated because redundant (eg. DynamicUser=true currently implies ProtectSystem="strict"), to prevent a future unintended relaxing, either in NixOS to make a new feature work, or by systemd changing implied options;
  • or would need to be removed from upstream or overridden (eg.: User=nobody or CapabilityBoundingSet=CAP_NET_BIND_SERVICE).

So, even though I can understand the immediate gain you mention in identifying and upstreaming relevant changes, my opinion so far is that:

  • on a human level, it's too much cognitive load for me to adapt, explain, justify and beg a new upstream each time I try to better harden a service. An hardening which has generally already taken me several hours of boring bisects and tests of the settings. The more I'm willing to do is to mention those settings to upstream to let it take what it wants on its own;
  • on a technical level, I find it is a pain to solve and maintain a coherent config with upstream's config in the mix, I find it more secure to not rely on upstream's knowledge and choices of security, but to have a single service config in NixOS, clearly using all the latest available hardening settings, and hopefully written by people who primarily care about security and are gaining experience by doing it on many other services.

@aanderse
Copy link
Member

aanderse commented Mar 4, 2021

I find it more secure to not rely on upstream's knowledge and choices of security

Alright, well as long as you know more about this software than developers of it do I completely support you 👍

I do find it unfortunate that other distributions won't be able to benefit from our (the NixOS community, a group of people generally keen on pushing the bar for security, as you mentioned) knowledge and efforts, though.

@ju1m
Copy link
Contributor Author

ju1m commented Mar 4, 2021

I find it more secure to not rely on upstream's knowledge and choices of security

Alright, well as long as you know more about this software than developers of it do I completely support you 👍

Of course I don't. But I would argue that even though developpers' intimate knowledge of their software may be useful to speed up elucidating all the permissions the software needs to have, and required in some cases, what matters most is knowledge of systemd/Linux and being concerned about security above other concerns. That is to say:

  1. Be knowledgeable and used to configure systemd services and Linux's hardening options (capabilities, seccomp, sysctl, namespaces, apparmor, ...). Knowledges which are not necessary for the developpers to develop their software nor have a working-enough systemd service. Hence they may just not have it nor want to acquire/maintain it. As examplified here by upstream's User=nobody and CapabilityBoundingSet=CAP_NET_BIND_SERVICE.

  2. Put security in a priority high enough to take the time to harden the service and have the will to make the usability and portability trade-offs required. For that matter I am personnally just not willing to go down a road hoping that each upstream (nor even each NixOS module's maintainers) holds security in such high priority. And I would prefer to have this concern handled by a dedicated security team acting transversaly accross all NixOS.

I do find it unfortunate that other distributions won't be able to benefit from our (the NixOS community, a group of people generally keen on pushing the bar for security, as you mentioned) knowledge and efforts, though.

I agree, and I'm not arguing against someone taking now time to argue with upstream to push some of those options, and this could be one of the secondary objectives of such NixOS security team. I'm just saying that concerning that software I'm exhausted and that:

The more I'm willing to do is to mention those settings to upstream to let it take what it wants on its own

@aanderse
Copy link
Member

aanderse commented Mar 4, 2021

You definitely have some good points. I have noticed some upstream developers are systemd friendly while others are not. Decisions should be made on a case by case basis, I guess.

@GrahamcOfBorg test croc

@wamserma
Copy link
Member

wamserma commented Mar 4, 2021

@ju1m I agree with you on deviating here. You have spent a reasonable amount of time to propose your changes to upstream.

To have users of other systems still benefit of your work, you might ask upstream to link back from their documentation to nixpkgs as an example for a more elaborate systemd setup.

@aanderse
Copy link
Member

aanderse commented Mar 5, 2021

I can merge this now, right?

@ju1m
Copy link
Contributor Author

ju1m commented Mar 5, 2021

I've notified upstream in schollz/croc#335 about this hardening.

Also, I've just seen that there are new hardening options ProtectProc= and ProcSubset= available on linux >=5.8, and it looks like they could be hardened too with ProtectProc=noaccess and ProcSubset=all but I first have to test them on a >=5.8 (currently linuxPackages = linuxPackages_5_4 in master).

@wamserma wamserma self-requested a review March 5, 2021 18:43
@aanderse
Copy link
Member

aanderse commented Mar 6, 2021

@ju1m would you like me to merge this now or wait on that?

@ju1m
Copy link
Contributor Author

ju1m commented Mar 8, 2021

I've successfully tested croc with ProtectProc=noaccess and ProcSubset=pid (more restrictive than all) on linux 5.10 and systemd 247, both manually and by adding boot.kernelPackages = pkgs.linuxPackages_latest_hardened to nixos/tests/croc.nix's relay.
I've also:

  • disabled @privileged syscalls.
  • disabled access to /etc.

@aanderse thanks, for me it's good for merging.

@wamserma
Copy link
Member

@aanderse i think you can merge

@aanderse
Copy link
Member

Thanks team!

@aanderse aanderse merged commit 47c5175 into NixOS:master Mar 13, 2021
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

4 participants