79.5. sudo-1.9.17p2
Runs commands as root or another user by policy, logging each command and its arguments
| Version | 1.9.17p2, release 1 |
| Shelf | auth — Authentication, authorisation, accounts and directory services |
| Phase | 41_system (System), 170 of 1047 in build order |
| Licence | ISC |
| Homepage | https://www.sudo.ws/ |
| Build time | 1.1 SBU |
| Installed size | 6.0 MiB in 53 files |
| Recipe | ports/core/auth/sudo/kpkgbuild |
About
sudo runs a command as root or as another user when the policy in /etc/sudoers allows it, asking for the caller’s own password and logging each command with its arguments. It is how KDOS is administered from the session: members of wheel may run anything, and the kdos subcommands that need root, such as kdos clone, are run through it. It authenticates through PAM, so a finger on an enrolled reader is accepted before the password is asked.
Sources
sudo-1.9.17p2.tar.gz(5.2 MiB)
sha2564a38a1ab3adb1199257edc2a7c4a2bd714665eb605b04368843b06dada2cfcfb
upstream: https://www.sudo.ws/dist/sudo-1.9.17p2.tar.gz
archive copy: sources-1/auth--sudo-1.9.17p2.tar.gz
Dependencies
Depends on: pam, zlib, openssl.
Required by (3): kde-cli-tools, kdesu, veracrypt.
Patches
build.sh applies these; kpkg applies nothing by itself.
eventlog-mailer-gid.patch— Makes the child that runs the mailer set its group, and its supplementary groups, to the mail user’s before it switches to that user, and exit when any of these calls fails instead of running the mailer anyway.eventlog_set_mailuid()becomeseventlog_set_mailuser(), taking a group ID beside the user ID.openssl4-asn1-string-length.patch— Use accessor for getting an ASN1_STRING's lengthOpenSSL 4 makes ASN1_STRING opaque. Upstream commit f97a34bc7b39, applied to 1.9.17p2's hostcheck.c.
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/41_system/phase.env && kpkg install sudo'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/auth/sudo.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/auth/sudo
echo '4a38a1ab3adb1199257edc2a7c4a2bd714665eb605b04368843b06dada2cfcfb sudo-1.9.17p2.tar.gz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/sudo
SRC=$SRC_ROOT/sudo-1.9.17p2
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf sudo-1.9.17p2.tar.gz -C "$SRC" --strip-components=1
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
patch -p1 -i $PORT_SRC/openssl4-asn1-string-length.patch
patch -p1 -i $PORT_SRC/eventlog-mailer-gid.patch
./configure \
--prefix=/usr \
--libexecdir=/usr/lib \
--with-secure-path \
--with-all-insults \
--with-env-editor \
--with-editor=/usr/bin/nvim:/usr/bin/nano \
--with-rundir=/run/sudo \
--with-vardir=/var/lib/sudo \
--without-lecture \
--with-passprompt="[sudo] password for %p: " \
--with-pam \
--enable-zlib=system \
--enable-openssl \
--without-sendmail
make
make DESTDIR=$PKG install
rm -rf $PKG/run
mkdir -m 755 $PKG/etc/pam.d
cat > $PKG/etc/pam.d/sudo << "EOF"
# Begin /etc/pam.d/sudo
# an enrolled finger, when there is a reader and one is on file; the leading
# dash skips the line on an image without fprintd rather than failing it
-auth sufficient pam_fprintd.so
# include the default auth settings
auth include system-auth
# include the default account settings
account include system-account
# Set default environment variables for the service user
session required pam_env.so
# include system session defaults
session include system-session
# End /etc/pam.d/sudo
EOF
chmod 644 $PKG/etc/pam.d/sudo
cat > $PKG/etc/sudoers.d/00-sudo << "EOF"
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
Defaults env_keep += "EDITOR VISUAL SUDO_EDITOR"
%wheel ALL=(ALL) ALL
EOF
chmod 440 $PKG/etc/sudoers.d/00-sudo
The switches, and why each is set:
--libexecdir=/usr/lib— Install the helpers and plug-ins (sesh,sudo_noexec.so,sudoers.soand the rest) under/usr/lib/sudoinstead of/usr/libexec/sudo.sudo’s ownconfigureputs the configuration in/etcwhatever the prefix, so no--sysconfdiris needed.--with-secure-path— Run every command with a setPATHinstead of the caller’s. The compiled-in value starts with/usr/local/sbin:/usr/local/bin, and the filebuild.shwrites in/etc/sudoers.dsets the same list without/sbinand/bin./usr/localmust stay on it:kdos-toolslinkskdosand its other commands into/usr/local/bin, andsudo kdos clonefinds nothing on a path without it.--with-all-insults— Compile in every insult set. They have an effect only wheninsultsis enabled insudoers, which nothing here does.--with-env-editor— Letvisudoandsudoedittake the editor fromSUDO_EDITOR,VISUALorEDITOR, which is also upstream’s default. The shippedsudoers.dfile adds the three toenv_keepso they survive into the command’s environment.--with-editor=/usr/bin/nvim:/usr/bin/nano— The editors to fall back on, in order, when none of those variables names one; both are ports.--with-rundir=/run/sudo— Where the time stamps that let a secondsudoskip the password are kept; a tmpfs, so they do not survive a reboot.--with-vardir=/var/lib/sudo— Where the files that should survive a reboot go.--without-lecture— Print no first-use lecture before the password prompt. KDE’s kdesu drivessudoon a pseudo-terminal and takes the first line ending in a colon with nothing after it for the prompt; the lecture’s lines in front of it break that exchange, so every graphical root action, KSystemLog from the launcher among them, is refused as a wrong password. sudo records a lecture as seen only after a password is accepted, so an account that never ransudoin a terminal would be refused for ever.--with-passprompt="[sudo] password for %p: "— The prompt, naming the user whose password is wanted.--with-pam— Authenticate through PAM, using/etc/pam.d/sudo.--enable-zlib=system— Compress I/O logs with the systemzlibrather than sudo’s bundled copy.--enable-openssl— Take TLS and the SHA-2 digests from OpenSSL.--without-sendmail— Send no mail at all. sudo would otherwise mail the administrator about events such as a user who is not insudoersrunning it.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/sudo, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf sudo-1.9.17p2-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/sudo, and runs the triggers its paths call for.
Contents
Installed programs: cvtsudoers, sudo, sudo_logsrvd, sudo_sendlog, sudoedit, sudoreplay, visudo.
Installed directories: /etc/sudoers.d, /usr/lib/sudo, /usr/share/doc/sudo, /usr/share/licenses/sudo, /var/lib/sudo.
Short descriptions
cvtsudoers |
convert between sudoers file formats |
sudo |
execute a command as another user |
sudo_logsrvd |
sudo event and I/O log server |
sudo_sendlog |
send sudo I/O log to log server |
sudoreplay |
replay sudo session logs |
visudo |
edit the sudoers file |
Notes
- The PAM file tries the finger first.
/etc/pam.d/sudoopens with-auth sufficient pam_fprintd.so; the leading dash skips the line wherefprintdis not installed, and a refused or absent finger falls through to the password insystem-auth. /runis removed from the package.make installcreates/run/sudo, and the package lint refusesrunin a port’s payload; sudo creates the directory at run time.- The
sudoers.dfile is mode 0440, the mode of sudo’s ownsudoers: sudo refuses a policy file that anyone but root can write. sudois one of the setuid binaries.