diff --git a/lib/base-permissions.nix b/lib/base-permissions.nix index fc51198..99efa57 100644 --- a/lib/base-permissions.nix +++ b/lib/base-permissions.nix @@ -11,17 +11,5 @@ pkgs: let helpers = import ./helpers.nix pkgs; in combinators: with combinators; (fwd-env "LANG") (fwd-env "HOME") (fwd-env "TERM") - - (add-runtime '' - if [ ! -e ${helpers.dataDirSubPath "passwd"} ] || [ ! -e ${helpers.dataDirSubPath "group"} ]; then - NOLOGIN=${pkgs.shadow}/bin/nologin - mkdir -p ${helpers.dataDir} - echo "root:x:0:0:System administrator:/root:$NOLOGIN" > ${helpers.dataDirSubPath "passwd"} - echo "$(id -un):x:$(id -u):$(id -g)::$HOME:$NOLOGIN" >> ${helpers.dataDirSubPath "passwd"} - echo "root:x:0:" > ${helpers.dataDirSubPath "group"} - echo "$(id -gn):x:$(id -g):" >> ${helpers.dataDirSubPath "group"} - fi - '') - (ro-bind (noescape (helpers.dataDirSubPath "passwd")) "/etc/passwd") - (ro-bind (noescape (helpers.dataDirSubPath "group")) "/etc/group") + fake-passwd ] diff --git a/lib/combinators.nix b/lib/combinators.nix index 2a9f87c..b744538 100644 --- a/lib/combinators.nix +++ b/lib/combinators.nix @@ -230,6 +230,37 @@ in rec { ; }; + fake-passwd = { + sig = "Permission"; + includedInBasePermissions = true; + doc = '' + Generates and mounts fake `/etc/passwd` and `/etc/group` files in the jail. + + The fake `/etc/passwd` and `/etc/group` files contains a root user, and + forward the calling user's user id, username, group id and group name. + + If you do not want to hide the users and groups that exist on your system, + you may consider just bind mounting `/etc/passwd` and `/etc/group` inside + the jail instead. + ''; + __functor = _: + compose [ + (add-runtime '' + if [ ! -e ${helpers.dataDirSubPath "passwd"} ] || [ ! -e ${helpers.dataDirSubPath "group"} ]; then + NOLOGIN=${pkgs.shadow}/bin/nologin + mkdir -p ${helpers.dataDir} + echo "root:x:0:0:System administrator:/root:$NOLOGIN" > ${helpers.dataDirSubPath "passwd"} + echo "$(id -un):x:$(id -u):$(id -g)::$HOME:$NOLOGIN" >> ${helpers.dataDirSubPath "passwd"} + echo "root:x:0:" > ${helpers.dataDirSubPath "group"} + echo "$(id -gn):x:$(id -g):" >> ${helpers.dataDirSubPath "group"} + fi + '') + (ro-bind (noescape (helpers.dataDirSubPath "passwd")) "/etc/passwd") + (ro-bind (noescape (helpers.dataDirSubPath "group")) "/etc/group") + ] + ; + }; + wrap-entry = { sig = "(String -> String) -> Permission"; doc = '' diff --git a/website/flake.nix b/website/flake.nix index 0e57766..5b17ebe 100644 --- a/website/flake.nix +++ b/website/flake.nix @@ -54,7 +54,17 @@ funciton, as well as [`basePermissions`](../advanced-configuration/#basepermissions). - ${formatSection (v: !(v ? deprecated))} + ${formatSection (v: !(v ? deprecated || v ? includedInBasePermissions))} + + ${hr} + + ## Default Included Combinators + + The following combinators are enabled by default, and do not need to be + explicitly added to your jails unless you [override + `basePermissions`](../advanced-configuration/#basepermissions). + + ${formatSection (v: v ? includedInBasePermissions)} ${hr} diff --git a/website/static-docs/advanced-configuration.md b/website/static-docs/advanced-configuration.md index 9417b89..e31b080 100644 --- a/website/static-docs/advanced-configuration.md +++ b/website/static-docs/advanced-configuration.md @@ -43,6 +43,9 @@ inherit by default. This configuration option allows you to override these. The goal of the base permissions are to provide a reasonably secure default with enough permissions to have most software behave correctly. +If you override this, you may want to take a look at the [default included +combinators](../combinators/#default-included-combinators). + Example: ```nix jail = jail-nix.lib.extend {