Apache ITK MPM and PAM Authentication
The ITK MPM module for the Apache webserver is used to give different virtual hosts different user IDs. But it can also be used to give users a private webspace (with WebDAV enabled so that they can write to the webspace). I'm using it to give each mobile phone user on my home server a space to sync files via WebDAV. When I set this up I never figured out how to authenticate users directly from the pluggable authentication modules PAM – each user already has an account on that machine, so it should be possible to use the login credentials of that account. Note that I would not recommend this setup for an internet facing installation but it works well for our home server.
On the same server I'm running Radicale, a CalDAV and CardDav server that can be used to sync contacts and calendars from a mobile phone. With that server I was able to use PAM authentication but it stopped working when upgrading to the Debian trixie release.
Debugging this with the help of a coding agent (I'm using OMP) it turns out that the ITK MPM module filters the user ids that can be set using secure computing calls, see the manual page seccomp(2). In particular it is never allowed – for obvious reasons – to set it to the root user with user ID 0.
This collides with Apache's mechanism to set a user ID via PAM. For this
Apache uses the setuid-root program /sbin/pwauth. This calls
setuid(0) to set the root user and it no longer works with the
itk_mpm module loaded into Apache.
For problems like this there is the System Security Services Daemon
sssd. It already runs as root and can manage authentication instead
of going directly to PAM. So I installed sssd with a config file
already provided by Debian in:
/usr/lib/x86_64-linux-gnu/sssd/conf/sssd.conf
but this did not change anything. With Apache authentication for
Radicale was still failing. The error and logs looked exactly as
before. The coding agent concluded that now the failure was because of
the default Debian PAM configuration in /etc/pam.d/pwauth: It
simply included the default common-auth and common-account
configurations. The common-account starts with pam_unix.so which
again has a call to setuid(0) and fails. Changing the pwauth
PAM configuration file to:
auth required pam_sss.so account required pam_sss.so
which calls sssd directly fixed the problem.
Now I also wanted to use PAM authentication for the WebDAV
directories. For these I didn't get PAM authentication working when I
set it up and I figured that this should be possible with the same
mechanism. The idea was to get rid of htaccess files used for
WebDAV. With the help of the coding agent I'm now using the following
Apache config snippet:
<Directory /home/*/WebDav/>
DAV On
AuthType Basic
AuthName "Restricted area"
AuthBasicProvider PAM
AuthPAMService webdav
AssignUserIDExpr %{reqenv:ITKUID}
Require user %{reqenv:ITKUID}
</Directory>
This uses mpm_itk to map the user directories. Note that you should
not use the typical Require valid-user as this would allow users to
impersonate each other. Instead we explicitly match each user.
This needs the file webdav in /etc/pam.d with the same
configuration as the file pwauth above.
With this configuration I finally have authentication via PAM working for both, Radicale (for CalDAV and CardDAV sync) and WebDav. Without the coding agent I probably would not have found this (or given up too early).
I still do not know why the old config worked in the Debian bookworm release.