Skip to content

Support multiple SAML 2.0 Identity Providers (IdPs) - #106

Open
subbareddyalamur1 wants to merge 1 commit into
openanalytics:masterfrom
subbareddyalamur1:feat/saml-multiple-idps
Open

subbareddyalamur1 wants to merge 1 commit into
openanalytics:masterfrom
subbareddyalamur1:feat/saml-multiple-idps

Conversation

@subbareddyalamur1

Copy link
Copy Markdown

Summary

Adds backward-compatible support for configuring multiple SAML 2.0 Identity Providers (proxy.saml.providers), while preserving 100% legacy single-IdP behavior when flat proxy.saml.* properties are used.

GET /login
  ├── 1 IdP configured             -> 302 /saml2/authenticate/{id}
  ├── ?idp={id} matches provider   -> 302 /saml2/authenticate/{id}
  ├── Host matches provider        -> 302 /saml2/authenticate/{id}
  └── >1 IdPs configured           -> renders IdP chooser in login.html

SAML endpoints (multi-IdP mode):
  /saml2/authenticate/{id}         -> OpenSaml5AuthenticationRequestResolver (per-IdP ForceAuthn)
  /saml/SSO/{id}                   -> Saml2AuthenticationTokenConverter + ResponseAuthenticationConverter
  /saml/metadata/{id}              -> Saml2MetadataFilter (permitAll via /saml/metadata/**)
  /saml/logout                     -> OpenSaml5LogoutRequestResolver (uses principal.relyingPartyRegistrationId)
  /saml/SingleLogout/{id}          -> per-IdP LogoutSuccessHandler redirect
 src/main/java/eu/openanalytics/containerproxy/
 ├── auth/impl/
 │   ├── SAMLAuthenticationBackend.java           # multi-IdP login/SLO URLs, per-user logout, IdP routing
 │   └── saml/
+│       ├── SamlProviderConfig.java              # YAML & env-var relaxed binding + shared defaults + validation
 │       ├── SAMLConfiguration.java               # multi-registration repo, DefaultRelyingPartyRegistrationResolver, per-IdP ForceAuthn
 │       ├── ResponseAuthenticationConverter.java # per-IdP name/roles/prefixes + preserve registrationId & sessionIndexes (Serializable)
 │       └── Saml2MetadataFilter.java             # serves /saml/metadata and /saml/metadata/{registrationId}
 ├── security/WebSecurityConfig.java              # permitAll /saml/metadata/**
 └── ui/AuthController.java                       # IdP chooser, ?idp= shortcut, hostname routing
 src/main/resources/
 ├── templates/login.html                         # renders IdP selection buttons when samlProviders is present
 └── static/css/login.css                         # IdP button spacing

Example Multi-IdP Configuration

proxy:
  authentication: saml
  saml:
    app-base-url: https://shinyproxy.example.com
    logout-method: LOCAL
    logout-url: /logout-success
    providers:
      - id: okta
        display-name: Sign in with Okta
        idp-metadata-url: https://company.okta.com/app/.../sso/saml/metadata
        app-entity-id: https://shinyproxy.example.com/saml/metadata/okta
        roles-attribute: groups
        username-prefix: "okta:"
        roles-prefix: "OKTA_"
        hostnames: [ okta.shinyproxy.example.com ]
      - id: entra
        display-name: Sign in with Microsoft Entra ID
        idp-metadata-url: file:///etc/shinyproxy/saml/entra-metadata.xml
        app-entity-id: https://shinyproxy.example.com/saml/metadata/entra
        name-attribute: https://shinyproxy.io/nameid
        force-authn: true
        logout-method: SAML

Evidence

  • Before: Only a single RelyingPartyRegistration (REG_ID = "shinyproxy") was registered; SAMLConfiguration hardcoded "shinyproxy" in token/logout resolvers, Saml2MetadataFilter served only /saml/metadata, AuthController unconditionally redirected /login to /saml2/authenticate/shinyproxy, and Saml2AuthenticatedPrincipal dropped relyingPartyRegistrationId and sessionIndexes.
  • After:
    • mvn test -Dtest=TestSamlProviderConfig,TestSamlResponseAuthenticationConverter,SamlMultiIdpAuthenticationTest,SimpleAuthenticationTest,TestOpenIdParseClaimRoles: 16/16 passing (covers legacy single-IdP backward compatibility, multi-IdP metadata/chooser/?idp=/Host routing, per-IdP ForceAuthn, signed SAML responses to /saml/SSO/{id}, cross-IdP signature rejection, LOCAL vs SAML per-IdP logout, env-var relaxed binding for Docker/Kubernetes, and Java serialization round-trip for Redis sessions).
    • mvn -DskipTests clean install (including license-maven-plugin:check): passed.
    • End-to-end verification with ShinyProxy 3.2.5 against two live SAML 2.0 IdP containers (idp-alpha and idp-beta): both IdPs authenticated independently, mapped per-IdP usernames/roles, and enforced per-IdP SpEL access-expression: "#{samlCredential.relyingPartyRegistrationId == '...'}".

Merge Danger

Door: Two-way

All changes are isolated to the SAML authentication backend and opt-in proxy.saml.providers configuration; rollback is a clean revert.

Blast Radius: Low

Legacy flat proxy.saml.* configurations retain identical registration ID (shinyproxy), endpoints (/saml/SSO, /saml/metadata, /saml/logout, /saml/SingleLogout), and direct /login redirect behavior. Non-SAML authentication backends are unaffected.

@subbareddyalamur1

Copy link
Copy Markdown
Author

Hi @LEDfan, tagging you for review whenever you have a moment!

This PR adds backward-compatible multi-IdP SAML 2.0 support (proxy.saml.providers) while keeping existing single-IdP proxy.saml.* configurations unchanged. Happy to adjust any property names, endpoints, login template styling, or behavior to align with OpenAnalytics' conventions and roadmap.

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.

2 participants