Skip to content

feat(auth): sign in with LDAP and SAML 2.0 - #119

Merged
letreset merged 3 commits into
mainfrom
feature/ldap-saml-sign-in
Nov 21, 2026
Merged

letreset merged 3 commits into
mainfrom
feature/ldap-saml-sign-in

Conversation

@letreset

Copy link
Copy Markdown
Owner

Sign in with LDAP / Active Directory accounts and SAML 2.0 identity providers

  • LDAP (Authentication:Ldap) works next to local accounts in Local and Hybrid mode, for the web sign-in form and for Basic auth from client tools. PaGetto binds with a search account (or anonymously), finds the user with UserFilter, reads its groups from memberOf or GroupSearchFilter, then binds as the user. Accounts are keyed by entryUUID (objectGUID in Active Directory), so a renamed or moved user keeps its account.
  • A username of a local account is only checked locally and never reaches the directory, so a directory user admin can't take over the local admin. The typed name is escaped in the filter, and an empty password is refused (it would be an anonymous bind).
  • A successful LDAP sign-in is remembered for CacheSeconds (60 by default) in LdapSignInCache, keyed by an HMAC of the username and password with a per-process key, so client requests don't each bind.
  • Directory groups link to role-linked PaGetto groups by their cn or full DN; a group named Admin makes its members administrators.
  • SAML (new Authentication:Mode Saml, or Hybrid with Authentication:Saml): SamlAuthenticationHandler is a RemoteAuthenticationHandler on ITfoxtec.Identity.Saml2. It sends an authentication request with the HTTP-Redirect binding and asks for an HTTP-POST response, keeps the request id in a cookie, and checks the response's signature (against the certificates of the IdP metadata), audience, lifetime and InResponseTo. The metadata is read from MetadataUrl and refreshed daily. Not supported: signed requests, encrypted assertions, single logout.
  • Entra ID, OIDC, SAML and LDAP users are now provisioned by one ExternalAccountService (upsert, username clash refusal, Admin and group sync); SingleSignOnSyncService maps the claims onto it.
  • Startup validation for both sections. Hybrid mode now accepts only one of Entra, Oidc and Saml; the LDAP section is refused in modes without local accounts.
  • The sign-in, Connect, Upload, Change password and Groups pages name the directory and the new providers. User.AuthProvider gets Saml (3) and Ldap (4); no migration is needed.
  • New packages: Novell.Directory.Ldap.NETStandard 4.0.0 (managed, so the Alpine image needs no native LDAP library) and ITfoxtec.Identity.Saml2 4.22.3.
  • Docs: new pages ldap.md and saml.md, config keys in configuration.md, and updates to authentication.md, web-ui.md, the readme, appsettings.json, the Helm values and AGENTS.md.
  • CI: the ubuntu job runs an OpenLDAP service container (ghcr.io/rroemhild/docker-test-openldap, pinned by digest) for LdapDirectoryTests; they are skipped on windows.

Testing:

  • Unit tests for the LDAP service (provisioning, group sync, cache, clashes, directory failures), Basic auth with LDAP, the validation and the SAML claim mapping. LdapDirectoryTests run against the test OpenLDAP server, including filter injection and the group search.
  • Integration tests for LDAP sign-in in the web UI and with Basic auth (directory groups granting feed permissions), and for SAML with responses signed by a certificate made in the test: a valid response signs in and syncs groups; unsigned responses, other certificates, responses to another request, responses without the sign-in cookie and username clashes are refused.
  • XunitLogger no longer throws after its test has ended: Microsoft.IdentityModel logs through one process-wide logger, which made a SAML test fail randomly in the full run.
  • Full suite passes locally (3,495 tests, none skipped).
  • End to end in Docker, through chrome-devtools in Hybrid mode with Keycloak 26 (SAML) and the test OpenLDAP: Keycloak alice became an administrator through SAML and the Keycloak user admin was refused; fry signed in through LDAP and got the Default feed through a group linked to ship_crew; curl with fry:fry 200, a wrong password 401, zoidberg (no permission) 404, and admin with a wrong password was checked only against the local account (rows SM1, SM2, SM4, LD1 to LD4 and LD6 of testenv/UI-TESTS.md).

Addresses #91

LDAP (Authentication:Ldap) works next to local accounts in Local and
Hybrid mode, for the web sign-in form and Basic auth alike. PaGetto binds
with a search account, finds the user, reads its groups from memberOf or
GroupSearchFilter and binds as the user. A username of a local account is
only checked locally, the typed name is escaped in the filter, and a
success is remembered for CacheSeconds. Accounts are keyed by entryUUID or
objectGUID.

SAML (Mode Saml, or Hybrid with Authentication:Saml) goes through a
RemoteAuthenticationHandler on ITfoxtec.Identity.Saml2: an authentication
request with the HTTP-Redirect binding, and a signed response posted back,
checked for its signature, audience, lifetime and InResponseTo against the
request id kept in a cookie. The identity provider's metadata is read from
MetadataUrl and refreshed daily.

Entra ID, OIDC, SAML and LDAP users are provisioned by one
ExternalAccountService, which refuses a new user whose username belongs to
another account and syncs the Admin flag and role-linked groups. Startup
validation covers both sections, and Hybrid mode accepts only one of the
Entra, Oidc and Saml sections.

Tests run LdapDirectoryTests against a test OpenLDAP server when
PAGETTO_TEST_LDAP is set, which CI does on ubuntu. testenv gets a SAML
client in the Keycloak realm and UI checks SM1-SM5 and LD1-LD6.
The image's own check searches cn=admin,dc=planetexpress,dc=com, which isn't an entry, so the container never became healthy and the ubuntu job failed to start it.
@letreset
letreset merged commit 1bb31b1 into main Nov 21, 2026
10 checks passed
@letreset
letreset deleted the feature/ldap-saml-sign-in branch November 21, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant