wrappers service: make /run/wrappers a mountpoint

Also remove some compatibility code because the directory in question would be
shadowed by a mountpoint anyway.
This commit is contained in:
Nikolay Amiantov 2017-02-18 20:06:09 +03:00
parent 8e5b630b49
commit 2cc4703a2d
2 changed files with 12 additions and 17 deletions

View File

@ -3,6 +3,8 @@ let
inherit (config.security) wrapperDir wrappers; inherit (config.security) wrapperDir wrappers;
parentWrapperDir = dirOf wrapperDir;
programs = programs =
(lib.mapAttrsToList (lib.mapAttrsToList
(n: v: (if v ? "program" then v else v // {program=n;})) (n: v: (if v ? "program" then v else v // {program=n;}))
@ -15,8 +17,7 @@ let
hardeningEnable = [ "pie" ]; hardeningEnable = [ "pie" ];
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
parentWrapperDir=$(dirname ${wrapperDir}) gcc -Wall -O2 -DWRAPPER_DIR=\"${parentWrapperDir}\" \
gcc -Wall -O2 -DWRAPPER_DIR=\"$parentWrapperDir\" \
-lcap-ng -lcap ${./wrapper.c} -o $out/bin/security-wrapper -lcap-ng -lcap ${./wrapper.c} -o $out/bin/security-wrapper
''; '';
}; };
@ -156,6 +157,11 @@ in
security.wrappers.fusermount.source = "${pkgs.fuse}/bin/fusermount"; security.wrappers.fusermount.source = "${pkgs.fuse}/bin/fusermount";
boot.specialFileSystems.${parentWrapperDir} = {
fsType = "tmpfs";
options = [ "nodev" ];
};
# Make sure our wrapperDir exports to the PATH env variable when # Make sure our wrapperDir exports to the PATH env variable when
# initializing the shell # initializing the shell
environment.extraInit = '' environment.extraInit = ''
@ -183,19 +189,15 @@ in
# Remove the old /run/setuid-wrappers-dir path from the # Remove the old /run/setuid-wrappers-dir path from the
# system as well... # system as well...
# #
# TDOO: this is only necessary for ugprades 16.09 => 17.x; # TODO: this is only necessary for ugprades 16.09 => 17.x;
# this conditional removal block needs to be removed after # this conditional removal block needs to be removed after
# the release. # the release.
if [ -d /run/setuid-wrapper-dirs ]; then if [ -d /run/setuid-wrapper-dirs ]; then
rm -rf /run/setuid-wrapper-dirs rm -rf /run/setuid-wrapper-dirs
fi fi
# Get the "/run/wrappers" path, we want to place the tmpdirs # We want to place the tmpdirs for the wrappers to the parent dir.
# for the wrappers there wrapperDir=$(mktemp --directory --tmpdir="${parentWrapperDir}" wrappers.XXXXXXXXXX)
parentWrapperDir="$(dirname ${wrapperDir})"
mkdir -p "$parentWrapperDir"
wrapperDir=$(mktemp --directory --tmpdir="$parentWrapperDir" wrappers.XXXXXXXXXX)
chmod a+rx $wrapperDir chmod a+rx $wrapperDir
${lib.concatStringsSep "\n" mkWrappedPrograms} ${lib.concatStringsSep "\n" mkWrappedPrograms}
@ -207,13 +209,6 @@ in
ln --symbolic --force --no-dereference $wrapperDir ${wrapperDir}-tmp ln --symbolic --force --no-dereference $wrapperDir ${wrapperDir}-tmp
mv --no-target-directory ${wrapperDir}-tmp ${wrapperDir} mv --no-target-directory ${wrapperDir}-tmp ${wrapperDir}
rm --force --recursive $old rm --force --recursive $old
elif [ -d ${wrapperDir} ]; then
# Compatibility with old state, just remove the folder and symlink
rm -f ${wrapperDir}/*
# if it happens to be a tmpfs
${pkgs.utillinux}/bin/umount ${wrapperDir} || true
rm -d ${wrapperDir}
ln -d --symbolic $wrapperDir ${wrapperDir}
else else
# For initial setup # For initial setup
ln --symbolic $wrapperDir ${wrapperDir} ln --symbolic $wrapperDir ${wrapperDir}

View File

@ -291,7 +291,7 @@ in
# Sync mount options with systemd's src/core/mount-setup.c: mount_table. # Sync mount options with systemd's src/core/mount-setup.c: mount_table.
boot.specialFileSystems = { boot.specialFileSystems = {
"/proc" = { fsType = "proc"; options = [ "nosuid" "noexec" "nodev" ]; }; "/proc" = { fsType = "proc"; options = [ "nosuid" "noexec" "nodev" ]; };
"/run" = { fsType = "tmpfs"; options = [ "nodev" "strictatime" "mode=755" "size=${config.boot.runSize}" ]; }; "/run" = { fsType = "tmpfs"; options = [ "nosuid" "nodev" "strictatime" "mode=755" "size=${config.boot.runSize}" ]; };
"/dev" = { fsType = "devtmpfs"; options = [ "nosuid" "strictatime" "mode=755" "size=${config.boot.devSize}" ]; }; "/dev" = { fsType = "devtmpfs"; options = [ "nosuid" "strictatime" "mode=755" "size=${config.boot.devSize}" ]; };
"/dev/shm" = { fsType = "tmpfs"; options = [ "nosuid" "nodev" "strictatime" "mode=1777" "size=${config.boot.devShmSize}" ]; }; "/dev/shm" = { fsType = "tmpfs"; options = [ "nosuid" "nodev" "strictatime" "mode=1777" "size=${config.boot.devShmSize}" ]; };
"/dev/pts" = { fsType = "devpts"; options = [ "nosuid" "noexec" "mode=620" "gid=${toString config.ids.gids.tty}" ]; }; "/dev/pts" = { fsType = "devpts"; options = [ "nosuid" "noexec" "mode=620" "gid=${toString config.ids.gids.tty}" ]; };