git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #66338 from worldofpeace/installer/no-root

installer: Don't run as root

commitdd49cf711e3139fec2eca26f31c2ffd8b5c5873b authorworldofpeace <worldofpeace@protonmail.ch> dateWed 14 Aug 2019, 11:20 (7 years ago) parent8f1566915f5535
7 files changed+96−31
nixos/doc/manual/installation/installing.xml+7−6 nixos/doc/manual/release-notes/rl-1909.xml+6 nixos/modules/installer/cd-dvd/installation-cd-graphical-base.nix+16−3 nixos/modules/installer/cd-dvd/installation-cd-graphical-kde.nix+11−6 nixos/modules/profiles/installation-device.nix+20−7 pkgs/tools/misc/gparted/default.nix+24−9 pkgs/tools/misc/gparted/polkit.patch+12
nixos/doc/manual/installation/installing.xml+7−6
@@ -29,13 +29,14 @@
2929 </para>
3030
3131 <para>
32− You are logged-in automatically as <literal>root</literal>. (The
33− <literal>root</literal> user account has an empty password.)
32+ You are logged-in automatically as <literal>nixos</literal>.
33+ The <literal>nixos</literal> user account has an empty password so you
34+ can use <command>sudo</command> without a password.
3435 </para>
3536
3637 <para>
3738 If you downloaded the graphical ISO image, you can run <command>systemctl
38− start display-manager</command> to start KDE. If you want to continue on the
39+ start display-manager</command> to start the desktop environment. If you want to continue on the
3940 terminal, you can use <command>loadkeys</command> to switch to your
4041 preferred keyboard layout. (We even provide neo2 via <command>loadkeys de
4142 neo</command>!)
@@ -65,9 +66,9 @@
6566
6667 <para>
6768 If you would like to continue the installation from a different machine you
68− need to activate the SSH daemon via <literal>systemctl start
69− sshd</literal>. In order to be able to login you also need to set a
70− password for <literal>root</literal> using <literal>passwd</literal>.
69+ need to activate the SSH daemon via <command>systemctl start
70+ sshd</command>. You then must set a password for either <literal>root</literal> or
71+ <literal>nixos</literal> with <command>passwd></command> to be able to login.
7172 </para>
7273 </section>
7374 </section>
nixos/doc/manual/release-notes/rl-1909.xml+6
@@ -42,6 +42,12 @@
4242 set up binfmt interpreters for each of those listed systems.
4343 </para>
4444 </listitem>
45+ <listitem>
46+ <para>
47+ The installer now uses a less privileged <literal>nixos</literal> user whereas before we logged in as root.
48+ To gain root privileges use <literal>sudo -i</literal> without a password.
49+ </para>
50+ </listitem>
4551 </itemizedlist>
4652 </section>
4753
nixos/modules/installer/cd-dvd/installation-cd-graphical-base.nix+16−3
@@ -8,16 +8,30 @@ with lib;
88{
99 imports = [ ./installation-cd-base.nix ];
1010
11+ # Whitelist wheel users to do anything
12+ # This is useful for things like pkexec
13+ #
14+ # WARNING: this is dangerous for systems
15+ # outside the installation-cd and shouldn't
16+ # be used anywhere else.
17+ security.polkit.extraConfig = ''
18+ polkit.addRule(function(action, subject) {
19+ if (subject.isInGroup("wheel")) {
20+ return polkit.Result.YES;
21+ }
22+ });
23+ '';
24+
1125 services.xserver = {
1226 enable = true;
1327
1428 # Don't start the X server by default.
1529 autorun = mkForce false;
1630
17− # Automatically login as root.
31+ # Automatically login as nixos.
1832 displayManager.slim = {
1933 enable = true;
20− defaultUser = "root";
34+ defaultUser = "nixos";
2135 autoLogin = true;
2236 };
2337
@@ -33,7 +47,6 @@ with lib;
3347
3448 # Enable sound in graphical iso's.
3549 hardware.pulseaudio.enable = true;
36− hardware.pulseaudio.systemWide = true; # Needed since we run plasma as root.
3750
3851 environment.systemPackages = [
3952 # Include gparted for partitioning disks.
nixos/modules/installer/cd-dvd/installation-cd-graphical-kde.nix+11−6
@@ -1,5 +1,5 @@
11# This module defines a NixOS installation CD that contains X11 and
2−# Plasma5.
2+# Plasma 5.
33
44{ config, lib, pkgs, ... }:
55
@@ -30,15 +30,20 @@ with lib;
3030 Version=1.0
3131 Type=Application
3232 Name=NixOS Manual
33− Exec=firefox ${config.system.build.manual.manualHTMLIndex}
33+ Exec=firefox ${config.system.build.manual.manual}/share/doc/nixos/index.html
3434 Icon=text-html
3535 '';
3636
37+ homeDir = "/home/nixos/";
38+ desktopDir = homeDir + "Desktop/";
39+
3740 in ''
38− mkdir -p /root/Desktop
39− ln -sfT ${manualDesktopFile} /root/Desktop/nixos-manual.desktop
40− ln -sfT ${pkgs.konsole}/share/applications/org.kde.konsole.desktop /root/Desktop/org.kde.konsole.desktop
41− ln -sfT ${pkgs.gparted}/share/applications/gparted.desktop /root/Desktop/gparted.desktop
41+ mkdir -p ${desktopDir}
42+ chown nixos ${homeDir} ${desktopDir}
43+
44+ ln -sfT ${manualDesktopFile} ${desktopDir + "nixos-manual.desktop"}
45+ ln -sfT ${pkgs.gparted}/share/applications/gparted.desktop ${desktopDir + "gparted.desktop"}
46+ ln -sfT ${pkgs.konsole}/share/applications/org.kde.konsole.desktop ${desktopDir + "org.kde.konsole.desktop"}
4247 '';
4348
4449}
nixos/modules/profiles/installation-device.nix+20−7
@@ -32,19 +32,35 @@ with lib;
3232 #services.rogue.enable = true;
3333
3434 # Disable some other stuff we don't need.
35− security.sudo.enable = mkDefault false;
3635 services.udisks2.enable = mkDefault false;
3736
37+ # Use less privileged nixos user
38+ users.users.nixos = {
39+ isNormalUser = true;
40+ extraGroups = [ "wheel" "networkmanager" "video" ];
41+ # Allow the graphical user to login without password
42+ initialHashedPassword = "";
43+ };
44+
45+ # Allow the user to log in as root without a password.
46+ users.users.root.initialHashedPassword = "";
47+
48+ # Allow passwordless sudo from nixos user
49+ security.sudo = {
50+ enable = mkDefault true;
51+ wheelNeedsPassword = mkForce false;
52+ };
53+
3854 # Automatically log in at the virtual consoles.
39− services.mingetty.autologinUser = "root";
55+ services.mingetty.autologinUser = "nixos";
4056
4157 # Some more help text.
4258 services.mingetty.helpLine =
4359 ''
4460
45− The "root" account has an empty password. ${
61+ The "nixos" and "root" account have empty passwords. ${
4662 optionalString config.services.xserver.enable
47− "Type `systemctl start display-manager' to\nstart the graphical user interface."}
63+ "Type `sudo systemctl start display-manager' to\nstart the graphical user interface."}
4864 '';
4965
5066 # Allow sshd to be started manually through "systemctl start sshd".
@@ -86,8 +102,5 @@ with lib;
86102 # because we have the firewall enabled. This makes installs from the
87103 # console less cumbersome if the machine has a public IP.
88104 networking.firewall.logRefusedConnections = mkDefault false;
89−
90− # Allow the user to log in as root without a password.
91− users.users.root.initialHashedPassword = "";
92105 };
93106}
pkgs/tools/misc/gparted/default.nix+24−9
@@ -1,6 +1,6 @@
1−{ stdenv, fetchurl, intltool, gettext, makeWrapper
2−, parted, glib, libuuid, pkgconfig, gtkmm3, libxml2, hicolor-icon-theme
3−, gpart, hdparm, procps, utillinux
1+{ stdenv, fetchurl, intltool, gettext, makeWrapper, coreutils, gnused, gnome3
2+, gnugrep, parted, glib, libuuid, pkgconfig, gtkmm3, libxml2, hicolor-icon-theme
3+, gpart, hdparm, procps, utillinux, polkit, wrapGAppsHook, substituteAll
44}:
55
66stdenv.mkDerivation rec {
@@ -11,16 +11,31 @@ stdenv.mkDerivation rec {
1111 sha256 = "0mdvn85jvy72ff7nds3dakx9kzknh8gx1z8i0w2sf970q03qp2z4";
1212 };
1313
14+ # Tries to run `pkexec --version` to get version.
15+ # however the binary won't be suid so it returns
16+ # an error preventing the program from detection
17+ patches = [
18+ (substituteAll {
19+ src = ./polkit.patch;
20+ polkit_version = polkit.version;
21+ })
22+ ];
23+
1424 configureFlags = [ "--disable-doc" ];
1525
16− buildInputs = [ parted glib libuuid gtkmm3 libxml2 hicolor-icon-theme ];
17− nativeBuildInputs = [ intltool gettext makeWrapper pkgconfig ];
26+ buildInputs = [ parted glib libuuid gtkmm3 libxml2 hicolor-icon-theme polkit.bin gnome3.adwaita-icon-theme ];
27+ nativeBuildInputs = [ intltool gettext pkgconfig wrapGAppsHook ];
28+
29+ preFixup = ''
30+ gappsWrapperArgs+=(
31+ --prefix PATH : "${stdenv.lib.makeBinPath [ gpart hdparm utillinux procps coreutils gnused gnugrep ]}"
32+ )
33+ '';
1834
35+ # Doesn't get installed automaticallly if PREFIX != /usr
1936 postInstall = ''
20− wrapProgram $out/bin/gparted \
21− --prefix PATH : "${procps}/bin"
22− wrapProgram $out/sbin/gpartedbin \
23− --prefix PATH : "${stdenv.lib.makeBinPath [ gpart hdparm utillinux ]}"
37+ install -D -m0644 org.gnome.gparted.policy \
38+ $out/share/polkit-1/actions/org.gnome.gparted.policy
2439 '';
2540
2641 meta = with stdenv.lib; {
pkgs/tools/misc/gparted/polkit.patchnew file+12
@@ -0,0 +1,12 @@
1+diff -ru old/gparted-1.0.0/configure gparted-1.0.0/configure
2+--- old/gparted-1.0.0/configure 2019-05-29 12:02:13.000000000 -0400
3++++ gparted-1.0.0/configure 2019-08-08 18:09:52.792795781 -0400
4+@@ -16145,7 +16145,7 @@
5+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for pkexec >= $PKEXEC_REQUIRED_VERSION" >&5
6+ $as_echo_n "checking for pkexec >= $PKEXEC_REQUIRED_VERSION... " >&6; }
7+ PKEXEC_REQUIRED_INT=`echo "$PKEXEC_REQUIRED_VERSION" | $AWK -F. '{print $1 * 10000 + $2}'`
8+-PKEXEC_VERSION_OUTPUT=`pkexec --version 2> /dev/null` ||
9++PKEXEC_VERSION_OUTPUT='pkexec version @polkit_version@' ||
10+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
11+ $as_echo "not found" >&6; }
12+ if test "x$PKEXEC_VERSION_OUTPUT" != 'x'; then