Sign inSign up

unillett/apache-shibboleth

Sponsored OSS

By UNIL

Updated 7 days ago

Docker image providing Apache as reverse proxy with Shibboleth SP pre-configured for SWITCHaai.

Image
0

10K+

unillett/apache-shibboleth repository overview

Apache Shibboleth Proxy

Docker image providing Apache as reverse proxy with Shibboleth SP pre-configured for SWITCHaai.

Shibboleth Protection

Two ways to use Shibboleth, depending on whether your application manages its own users.

Case 1: Application with User Management

Only the login endpoint needs protection, the rest of the site stays public. Shibboleth authenticates there, your backend reads the X-Shib-* headers to create or update the user record, then runs on its own session (cookie, JWT).

SHIB_PROTECTED_PATHS: "/aai"     # Application login endpoint
Case 2: Application without User Management

Shibboleth guards the paths itself and blocks unauthenticated users. No session handling on your side.

SHIB_PROTECTED_PATHS: "/"                 # (default) Protect all site
# or
SHIB_PROTECTED_PATHS: "/admin,/secured"   # Protect specific sections

Configuration

Environment Variables
VariableRequiredDefaultDescription
SHIB_HOSTNAMEYes-Your domain name
SHIB_CONTACTYes-Contact email
SHIB_ENTITY_IDNo-If entityID is not the same as the hostname (when multiple locations registered for the same entityID). You must only specify the host part of the ID.
SHIB_PROTECTED_PATHSNo/Paths to protect with Shibboleth (comma-separated). Set to empty string "" to disable protection and configure manually.
SHIB_ALLOWED_USERSNo-Restrict access to specific users by uniqueID (comma-separated, e.g., [email protected],[email protected])
SHIB_ATTRIBUTESNo-Shibboleth attributes to forward as HTTP headers (comma-separated). Your backend must read only these. See Shibboleth Attributes.
SHIB_SESSION_PROPERTIESNoShib-Identity-Provider,Shib-Authentication-Instant,Shib-AuthnContext-ClassSession properties to forward as HTTP headers (comma-separated). Your backend must read only these. Set to "" to disable. See Session Properties.
SHIB_RETURN_URLNo/Return URL after authentication (e.g., /welcome, /dashboard)
SHIB_SP_KEYNo-Content of existing Shibboleth private key (sp-key.pem) to use instead of generating new ones. Can be plain text (starting with -----BEGIN) or base64 encoded.
SHIB_SP_CERTNo-Content of existing Shibboleth public certificate (sp-cert.pem) to use instead of generating new ones. Can be plain text (starting with -----BEGIN) or base64 encoded.
SECURITY_HEADERS_ENABLEDNofalseEnable or disable the Apache security headers config/security-headers.conf
APACHE_CUSTOM_CONFIGNo-Custom Apache directives for config

Security concern:

Your backend must be reachable only through this proxy, otherwise anyone can call it directly with forged headers and bypass Shibboleth entirely.

It must read only the headers derived from SHIB_ATTRIBUTES and SHIB_SESSION_PROPERTIES, the only ones the proxy clears from incoming requests.

Note: Environment variables are complementary and can be used together, including with custom Apache configuration files.

Important: Shibboleth and Apache configurations are generated only on first startup. Changing an environment variable requires recreating the container.

Note: SHIB_ALLOWED_USERS applies to all paths in SHIB_PROTECTED_PATHS at once. For per-path authorization, set SHIB_PROTECTED_PATHS="" and define your own <Location> blocks — see Advanced directives.

Apache Configuration

This image does not provide a default proxy behavior: you must supply your own Apache configuration, and it must define where Apache forwards requests. It is included inside the <VirtualHost>, so any directive Apache accepts is valid there — rewrite rules, <Location> blocks, headers, cache control.

Two ways to provide it, usable together — see examples/php-admin-protected/docker-compose.yml for both:

  1. APACHE_CUSTOM_CONFIG environment variable (recommended for Kubernetes)
  2. Mount configuration files to /etc/apache2/vhost.d/ (recommended for Docker Compose)

The image is designed to terminate Shibboleth, then forward every request to your application. Your files stay in your application image, so the same configuration works in Docker Compose and Kubernetes.

# Proxy everything to the backend
ProxyPass / http://backend:8080/
ProxyPassReverse / http://backend:8080/

Attributes are forwarded as X-Shib-* headers, so the backend still knows who the user is.

Advanced directives

Any Apache directive works, for example per-path authorization:

<Location /secured>
    AuthType shibboleth
    ShibRequestSetting requireSession true
    Require shib-attr uniqueID [email protected]
</Location>

For complex scenarios, set SHIB_PROTECTED_PATHS="" to disable automatic protection and manage every <Location> block yourself.

A complete docker-compose example is available in the examples folder.

Shibboleth Certificates

The SP authenticates to the Identity Provider with a key pair, sp-key.pem and sp-cert.pem, stored in /var/lib/shibboleth/. If they change, you must re-register the certificate on AAI Resource Registry and wait for propagation.

Either provide existing certificates through SHIB_SP_KEY and SHIB_SP_CERT — as plain text or base64-encoded — or let the container generate them on first startup, in which case you must persist them with a volume:

services:
  apache-shibboleth:
    volumes:
      - shibboleth-certs:/var/lib/shibboleth

volumes:
  shibboleth-certs:

.env example with existing certificates:

SHIB_SP_KEY="-----BEGIN PRIVATE KEY-----
[Your private key content here]
-----END PRIVATE KEY-----"

SHIB_SP_CERT="-----BEGIN CERTIFICATE-----
[Your certificate content here]
-----END CERTIFICATE-----"

Certificate rollover: when renewing (e.g. for expiration), follow the SWITCH certificate rollover guide to avoid service interruptions: add the new certificate alongside the old one, wait for metadata propagation (≈2 hours), then switch to the new one and remove the old one.

Ports

The Apache proxy listens on port 8080 (HTTP). This container is designed to run behind a TLS termination proxy that handles HTTPS.

Shibboleth Attributes

Attributes released by the Identity Provider are forwarded to your backend as X-Shib-* headers. Only those listed in SHIB_ATTRIBUTES are forwarded, and only those may be trusted: the list defines what your backend receives and what it is allowed to trust, so keep it to what the application actually needs.

SHIB_ATTRIBUTES: "mail,givenName,surname,uniqueID"

Header naming: the first letter is capitalized, and hyphens or underscores followed by a lowercase letter become uppercase.

  • mailX-Shib-Mail
  • persistent-idX-Shib-PersistentId

Important: use the attribute names defined in /etc/shibboleth/attribute-map.xml, not the FriendlyName from metadata. To see what you actually receive, authenticate then visit https://your-domain.ch/Shibboleth.sso/Session: it lists the attributes of the current session, under the names to use here. The complete federation catalog is in the SWITCH AAI Attributes Documentation.

Session Properties

Beyond the attributes released by the IdP, mod_shib exposes properties describing the session itself. They are configured separately, with SHIB_SESSION_PROPERTIES. Their name already starts with Shib-, so the header is simply the property prefixed with X-: Shib-Identity-ProviderX-Shib-Identity-Provider.

Forwarded by default:

PropertyContent
Shib-Identity-ProviderentityID of the IdP the user authenticated against
Shib-Authentication-InstantTimestamp of the authentication
Shib-AuthnContext-ClassAuthnContextClassRef, e.g. to detect MFA
SHIB_SESSION_PROPERTIES: "Shib-Identity-Provider,Shib-Session-Index"
SHIB_SESSION_PROPERTIES: ""   # Forward none

Docker images

GitHub Actions workflows generate Docker image tags based on these events:

  • Push to development: dev-latest
  • Push to main: latest
  • Push a git tag: vX.Y.Z (immutable)

Weekly cron jobs:

  • Create an updated production candidate: vX.Y.Z-<sha>-<timestamp> (immutable, from git tag)

Documentation

Tag summary

Content type

Image

Digest

sha256:760953eb7

Size

101.9 MB

Last updated

7 days ago

docker pull unillett/apache-shibboleth

This week's pulls

Pulls:

177

Last week