.. title: Apache ITK MPM and PAM Authentication
.. slug: 06-2
.. date: 2026-12-06 13:00
.. tags: documentation,english,howto,networking,open source
.. description:
.. wp-status: publish
.. has_math: false

.. |--|  unicode:: U+2013  .. en dash
.. |ohm| unicode:: U+02126 .. Omega
   :trim:
.. |_| unicode:: U+00A0 .. Non-breaking space
   :trim:
.. |mho| unicode:: U+2127 .. upside-down Omega

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.

.. _Apache: https://httpd.apache.org/
.. _`ITK MPM module`: http://mpm-itk.sesse.net/
.. _WebDAV: https://en.wikipedia.org/wiki/WebDAV
.. _Radicale: https://radicale.org/
.. _CalDAV:  https://en.wikipedia.org/wiki/CalDAV
.. _CardDAV: https://en.wikipedia.org/wiki/CardDAV
.. _PAM: https://en.wikipedia.org/wiki/Pluggable_Authentication_Module
.. _Debian: https://www.debian.org/
.. _OMP: https://omp.sh
