Some views on the common Apache modules for SAML or OIDC authentication

March 11, 2025

Suppose that you want to restrict access to parts of your Apache based website but you want something more sophisticated and modern than Apache Basic HTTP authentication. The traditional reason for this was to support 'single sign on' across all your (internal) websites; the modern reason is that a central authentication server is the easiest place to add full multi-factor authentication. The two dominant protocols for this are SAML and OIDC. There are commonly available Apache authentication modules for both protocols, in the form of Mellon (also) for SAML and OpenIDC for OIDC.

I've now used or at least tested the Ubuntu 24.04 version of both modules against the same SAML/OIDC identity provider, primarily because when you're setting up a SAML/OIDC IdP you need to be able to test it with something. Both modules work fine, but after my experiences I'm more likely to use OpenIDC than Mellon in most situations.

Mellon has two drawbacks and two potential advantages. The first drawback is that setting up a Mellon client ('SP') is more involved. Most of annoying stuff is automated for you with the mellon_create_metadata script (which you can get from the Mellon repository if it's not in your Mellon package), but you still have to give your IdP your XML blob and get their XML blob. The other drawback is that Mellon isn't integrated into the Apache 'Require' framework for authorization decisions; instead you have to make do with Mellon-specific directives.

The first potential advantage is that Mellon has a straightforward story for protecting two different areas of your website with two different IdPs, if you need to do that for some reason; you can just configure them in separate <Location> or <Directory> blocks and everything works out. If anything, it's a bit non-obvious how to protect various disconnected bits of your URL space with the same IdP without having to configure multiple SPs, one for each protected section of URL space. The second potential advantage is that in general SAML has an easier story for your IdP giving you random information, and Mellon will happily export every SAML attribute it gets into the environment your CGI or web application gets.

The first advantage of OpenIDC is that it's straightforward to configure when you have a single IdP, with no XML and generally low complexity. It's also straightforward to protect multiple disconnected URL areas with the same IdP but possibly different access restrictions. A third advantage is that OpenIDC is integrated into Apache's 'Require' system, although you have to use OpenIDC specific syntax like 'Require claim groups:agroup' (see the OpenIDC wiki on authorization).

In exchange for this, it seems to be quite involved to use OpenIDC if you need to use multiple OIDC identity providers to protect different bits of your website. It's apparently possible to do this in the same virtual host but it seems quite complex and requires a lot of parts, so if I was confronted with this problem I would try very hard to confine each web thing that needed a different IdP into a different virtual host. And OpenIDC has the general OIDC problem that it's harder to expose random information.

(All of the important OpenIDC Apache directives about picking an IdP can't be put in <Location> or <Directory> blocks, only in a virtual host as a whole. If you care about this, see the wiki on Multiple Providers and also access to different URL paths on a per-provider basis.)

We're very likely to only ever be working with a single IdP, so for us OpenIDC is likely to be easier, although not hugely so.

Sidebar: The easy approach for group based access control with either

Both Mellon and OpenIDC work fine together with the traditional Apache AuthGroupFile directive, provided (of course) that you have or build an Apache format group file using what you've told Mellon or OpenIDC to use as the 'user' for Apache authentication. If your IdP is using the same user (and group) information as your regular system is, then you may well already have this information around.

(This is especially likely if you're migrating from Apache Basic HTTP authentication, where you already needed to build this sort of stuff.)

Building your own Apache group file has the additional benefit that you can augment and manipulate group information in ways that might not fit well into your IdP. Your IdP has the drawback that it has to be general; your generated Apache group file can be narrowly specific for the needs of a particular web area.


Comments on this page:

From 193.219.181.219 at 2025-03-12 06:32:33:

The third and probably the most common of them, though, is Shibboleth SP aka mod_shib. It deals with XML for metadata and configuration, but supports Apache's Require valid-user or Require shib-session which you can set up per-<Location>.

It has its own gotchas, e.g. unlike Mellon, it relies on a standalone shibd daemon running alongside httpd to handle all of the XML parsing/validation (perhaps a good idea though, especially when dealing with many IdPs), and the whole "require session" part is slightly confusing, but overall:

<Location />
	AuthType Shibboleth
	ShibRequestSetting entityIDSelf "https://$hostname/sp"
	# In older versions, have to reference an <Application>
	#ShibRequestSetting applicationId "foo"
	ShibRequestSetting requireSession On
	Require shib-session
</Location>

(The stock conf-enabled/shib.conf comes with an exception to avoid putting its own /Shibboleth.sso endpoint behind SSO.)

It sets REMOTE_USER from the standard subject-id attributes, and any SAML attributes you list in attribute-map.xml are sent to the app either as CGI environment, or as HTTP headers (the module makes sure to unset any "spoofed" headers from clients).

Written on 11 March 2025.
« The web browser as an enabler of minority platforms
The commodification of desktop GUI behavior »

Page tools: View Source, View Normal.
Search:
Login: Password:

Last modified: Tue Mar 11 23:01:54 2025
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.