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/uwsgi: run with capabilities instead of root #106082

Merged
merged 4 commits into from Jan 10, 2021
Merged

Conversation

rnhmjoj
Copy link
Contributor

@rnhmjoj rnhmjoj commented Dec 6, 2020

Motivation for this change

Being able to run uwsgi as emperor without root.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS
    • nixosTests.uwsgi
    • nixosTests.ihatemoney
  • Tested compilation of all pkgs that depend on this change (uwsgi, config.system.build.manual.manualHTML)
  • Tested execution of all binary files
  • 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.

@Mic92 Mic92 changed the title nixos/uwsgi: add support for POSIX capabilities nixos/uwsgi: add support for capabilities Dec 13, 2020
@Mic92 Mic92 changed the title nixos/uwsgi: add support for capabilities nixos/uwsgi: run with capabilities instead of root Dec 13, 2020
Copy link
Member

@Mic92 Mic92 left a comment

Choose a reason for hiding this comment

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

Not yet tested but changes look good.

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jan 7, 2021

Fixed conflict with PR #107403 and rebased.

@symphorien
Copy link
Member

To exercise this change, I migrated the ihatemoney module to use it: it works but I had to move from uid to immediate-uid. I think this is worth mentionning in the release notes.

Full diff

diff --git a/nixos/modules/services/web-apps/ihatemoney/default.nix b/nixos/modules/services/web-apps/ihatemoney/default.nix
index 68769ac8c03..81647d352e7 100644
--- a/nixos/modules/services/web-apps/ihatemoney/default.nix
+++ b/nixos/modules/services/web-apps/ihatemoney/default.nix
@@ -44,7 +44,7 @@ let
 in
   {
     options.services.ihatemoney = {
-      enable = mkEnableOption "ihatemoney webapp. Note that this will set uwsgi to emperor mode running as root";
+      enable = mkEnableOption "ihatemoney webapp. Note that this will set uwsgi to emperor mode";
       backend = mkOption {
         type = types.enum [ "sqlite" "postgresql" ];
         default = "sqlite";
@@ -116,16 +116,13 @@ in
       services.uwsgi = {
         enable = true;
         plugins = [ "python3" ];
-        # the vassal needs to be able to setuid
-        user = "root";
-        group = "root";
         instance = {
           type = "emperor";
           vassals.ihatemoney = {
             type = "normal";
             strict = true;
-            uid = user;
-            gid = group;
+            immediate-uid = user;
+            immediate-gid = group;
             # apparently flask uses threads: https://github.com/spiral-project/ihatemoney/commit/c7815e48781b6d3a457eaff1808d179402558f8c
             enable-threads = true;
             module = "wsgi:application";

Feel free to include this in the PR, otherwise I'll do a PR myself later)

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jan 9, 2021

Thank you, that should be indeed mentioned in the release notes. I'll also include your patch.

@rnhmjoj
Copy link
Contributor Author

rnhmjoj commented Jan 10, 2021

@symphorien patch included and manual updated. Thank you, again.

@symphorien
Copy link
Member

@GrahamcOfBorg test uwsgi ihatemoney

@symphorien symphorien merged commit 0fbc097 into NixOS:master Jan 10, 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