Apps that sign in with SAML
Most apps sign people in with OpenID Connect (apps). Some only speak SAML 2.0: older enterprise software, or a vendor's product that asks for "your IdP's metadata". For those, Nod is the SAML identity provider (IdP), and the app is a service provider (SP).
Usually the person opens the app, the app sends them to Nod with an AuthnRequest, and Nod posts a signed response back (SP-initiated). An app can also take sign-ins started from Nod (see below).
Registering an app
The app's administrator gives you two things: its entity ID and its assertion consumer service (ACS) URL.
curl -X POST "$ISSUER/api/v1/saml-apps" -H "authorization: Bearer $TOKEN" -H 'content-type: application/json' \
-d '{"id": "wiki", "name": "Team wiki", "entity_id": "https://wiki.example/saml", "acs_url": "https://wiki.example/saml/acs"}'
You need clients:write to register or delete an app, and clients:read to list them (GET $ISSUER/api/v1/saml-apps, GET …/saml-apps/{id}). Deleting one stops its sign-ins (DELETE …/saml-apps/{id}).
- **
entity_id:** theIssuerof the app's requests, and theAudienceof Nod's assertions. Each entity ID is registered once per realm. - **
acs_url:** the one address Nod posts responses to. It must be https (http is allowed on localhost only). - **
name_id:** who the person is to the app.id(the default): a persistent NameID, their Nod user id. It never changes, and it means nothing to another app.email: their email address. Use it only for apps that insist. People without a verified email are refused.
- **
encryption_cert_pem** (optional): the app's encryption certificate, for an app that wants assertions encrypted. Every assertion it gets is then encrypted to it: AES-256-GCM for the content, RSA-OAEP for the key. The assertion is signed before encryption, and the response is signed around the encrypted assertion. The certificate is checked, and a trial encryption run, when the app is registered. - **
idp_initiated(optional, off) andstart_relay_state**: let Nod sign people in to the app unasked (see below). - **
slo_url** (optional): where the app takes Nod's answer to its logout requests (see below). - **
cert_pem** (optional): the app's signing certificate, for an app that signs its requests. From then on, only requests it signed are answered. By HTTP-Redirect, the query's signature (SigAlg,Signature, RSA-SHA256) must verify. By HTTP-POST, an enveloped signature over the whole request must verify. Nod checks a POSTed request, then moves it to the Redirect form signed by its own key, which that form accepts in the app's place.
What to give the app
- Metadata:
$ISSUER/saml/metadata. This URL is also Nod's entity ID. It names the signing certificate and the SSO URL. The list endpoint returns it asidp_metadata. - SSO URL:
$ISSUER/saml/sso. Requests can arrive by HTTP-Redirect or HTTP-POST. - Signing certificate: the one in the metadata. Each realm has its own IdP key. It is separate from the key Nod uses as a service provider (
$ISSUER/federation/saml-metadata). It is made the first time it's needed and sealed at rest.
Signing in from Nod (IdP-initiated)
For an app registered with "idp_initiated": true, a link to $ISSUER/saml/apps/<id>/start signs the person in to the app directly. They get Nod's sign-in page first if they aren't signed in. The response answers no request, so it has no InResponseTo. It goes to the registered ACS, with start_relay_state (if set) as its RelayState, which is where the app should land.
Turn this on only for apps that ask for it. An unsolicited response can't be tied to a request the app's browser made, so the app must accept that risk. Nod's own SP side refuses such responses. Apps without the flag get 404 there. Each sign-in is logged as saml.assertion, with detail ending "(started from Nod)".
Signing out (single logout)
An app that signs people out through Nod sends its LogoutRequest to $ISSUER/saml/slo (HTTP-Redirect; the metadata names it). Register its slo_url to get an answer there.
- What ends: only the session in that browser, and only when it is the one the request names. That means the person the app knows by that NameID and, if the request names a
SessionIndex, the sign-in Nod gave it. A request naming anyone or anything else gets an error page, and nothing ends. - Signing out: Nod signs out as
$ISSUER/logoutdoes. Apps signed in with OpenID Connect hear by back-channel logout, and an upstream SAML IdP the person signed in through is told too. - The answer: a
LogoutResponse, signed by Nod's IdP key, goes to the app's registeredslo_url(never an address from the request), with the app'sRelayState. An app without anslo_urlgets Nod's signed-out page. - Signed requests: an app that registered
cert_pemmust sign its logout requests too. - Log: the sign-out goes in the security log as
signout, withclient_idsaml:<app id>.
Signing out tells the other apps
When the person signs out of Nod in the browser, Nod tells the SAML apps that session signed in to. This covers Nod's own logout, an OpenID Connect app's logout, or a SAML app's LogoutRequest. Only apps that registered an slo_url are told; the app that asked isn't told again.
Nod's session ends at once. Then the browser goes to each app's slo_url in turn, carrying a LogoutRequest signed by Nod. Each request names the person as that app knows them, with the SessionIndex it was given. Each app answers at $ISSUER/saml/slo, and Nod moves the browser on to the next app. After the last app, the browser goes where it was going: an upstream IdP's logout, the app that asked, or the signed-out page.
Each answer is used once, within ten minutes. An app that registered cert_pem must sign its answers. An answer that doesn't check out ends the chain at the signed-out page. Nod's session is already over by then, so nothing is lost.
Rotating the signing key
Apps pin Nod's certificate, so switching keys takes two steps:
nod saml idp-next-key acme # a next key, published in the metadata beside the current one, which still signs
# give the new certificate (printed, and in the metadata) to every app that pinned the old one
nod saml idp-switch-key acme # the next key signs from now on; the old one is gone from the metadata
Apps that read the metadata pick up the next key on their own. The switch is refused when no next key is published, and a second next key is refused until the switch. Both commands go in the realm's security log as admin.change.
What Nod sends
Nod sends one assertion, and signs both the assertion and the response around it (RSA-SHA256, exclusive C14N), so an app that checks either one is covered. The assertion contains:
- **
Issuer:** Nod's entity ID. - **
Subject:** the NameID, with bearer confirmation for the ACS URL andInResponseToset to the request's ID. - **
Audience:** the app's entity ID. - Validity: five minutes from issue.
- **
AuthnInstant:** when the person signed in, not when the response was made. - **
SessionIndex:** Nod's public id for the session. - Attributes:
email(only when verified) andname.
The RelayState comes back unchanged. SAML limits it to 80 bytes.
Each response goes in the realm's security log as saml.assertion, with client_id set to saml:<app id>.
Signing in again (ForceAuthn)
When a request has ForceAuthn="true", a session from before the request isn't enough. Nod notes when it first saw the request by adding nod_asked=<unix seconds> to the SSO URL. A session that started before then gets the sign-in page, and the page comes back to the same request. Only a sign-in made after that moment is answered.
The request is unsigned, so ForceAuthn protects against a session left open in the browser. It doesn't protect against the person at that browser, who could equally drop the flag.
What Nod refuses
- A request naming a different ACS URL from the registered one gets an error page, and nothing is posted. Requests are usually unsigned, so the URL in one can't be trusted. Pinning it means a forged request can only make Nod answer the registered app, through the person's own browser.
- A request from an app that registered a certificate, unsigned or signed by another key, gets an error page.
- A request from an entity ID that isn't registered, one sent to another SSO URL, one issued more than ten minutes from now, and one that isn't plain SAML get an error page. That includes any DTD, nesting deeper than 64 elements, or anything that inflates past 256 KiB.
- **
IsPassivewithout a session:** Nod answers the app withNoPassive. So doesIsPassivewithForceAuthn, which can't both be met. - A binding other than HTTP-POST for the answer, or a NameID format the app isn't registered for: Nod answers with
RequestUnsupportedorInvalidNameIDPolicy.
Not yet
- Telling SAML apps when a session ends without a browser to carry the messages: an administrator ending it, or it expiring. Only sign-outs in the browser reach the apps.