外观
lib-samlSso 库参考
原文: https://finproducts.atlassian.net/wiki/spaces/JIDD3/pages/34793914725/FIN+5.3.1+lib-samlSso 中文整理基于 FIN 5.3.1
导读: SAML 单点登录认证系统模块
以下为 API 参考,保留英文以便对照源码;目录已列出(英文标题便于检索);概述已尽量中译。
目录(导读)
- lib
- meta
- docs
- tags
- views
- Overview
- Logging in with Local Accounts
- Using SamlSso Authentication
- Setup
- SAML Attributes
- SAML SSO Settings
- Manually Import IdP Signing Certificate
- Login Update Mode
- User Prototype Mapping
- Optional User Attributes
- Example applyTagsFunc
- SAML IdP Configuration
- SkySpark Entity Id
- SkySpark Assertion Consumer Service Uri
- Encrypted Assertions
概述(中译)
SAML 单点登录认证系统模块
API 正文(英文)
docs
Overview • Logging in with Local Accounts • Using SamlSso Authentication • Setup • Encrypted Assertions
tags
| samlSsoUserProtoAttrVal | The value of this tag is used to help the SAML SSO auth mod determine which user prototypes a SAML SSO user matches |
views
| samlSsoSettings | Settings for the SAML system module |
lib samlSso
Overview
The SAML SSO AuthMod incorporates single sign-on functionality into the login process:
- Enables single sign-on (SSO) functionality via SAML allowing users to skip the standard SkySpark username/password login page if they are already logged in to their SSO environment.
- User record tags can be dynamically mapped or updated during SAML login with a user prototype.
- SkySpark uses the HTTP Redirect Binding for logging in to the Identity Provider (IdP).
The Settings|SAML SSO view allows configuration of the single sign-on properties.
Logging in with Local Accounts
After setting up SAML, navigating to the SkySpark Uri will automatically attempt SAML login via single sign-on so the standard SkySpark login page will not be displayed. During initial setup or in the rare instance where the SkySpark host is having communication issues with the SAML server, it may be necessary to login with a local SkySpark user account. To login with local SkySpark accounts, such as the su account created during setup, access {SkySpark URL:port}/user/login directly, which will display the standard SkySpark user login page (bypassing single sign-on).
Using SamlSso Authentication
After configuring SamlSso, users will no longer see the standard login page when they navigate to the SkySpark Server Url (unless the Uri described in Local Account Login is accessed directly). The SamlSso AuthMod will verify SAML assertions sent by the IdP to authenticate the user and read configured attributes from the assertion to authorize the user.
SkySpark provides flexibility in how user records are managed when using SAML. User roles and access filters can be managed entirely in the SkySpark User app or users can be synthesized during login by mapping the user to a configured prototype in SkySpark and using the synthesized user to create a local user record. Therefore, users do not need to be setup prior to login, but SkySpark can be configured to require that a local user record exists. Review the details of the Login Update Mode setting for more information.
Setup
The following steps are required to configure SAML SSO authentication:
- Enable the samlSso SysMod from the
Host|SysModsview - Identify required user attributes (see SAML Attributes)
- Enter the required SAML Settings (see SAML SSO Settings)
- Configure one or more user prototypes for SAML (see User Prototype Mapping)
- Configure IdP (see SAML IdP Configuration)
- If using the
authOnlyLogin Update Mode, theuserAuthtag must be set toAuthMod - samlSso
IMPORTANT: If there are already local user records created in the SkySpark user database that will now use SAML, the userAuth tag must be manually changed to AuthMod - samlSso.
SAML Attributes
Two attributes must be included in an Assertion sent by the IdP:
- The attribute (
samlResponseUsernameAttribute) that identifies the username of the user. - The attribute (
userProtoAttr) that identifies what prototype to map the user to in SkySpark. If a default prototype is configured, this attribute is not required.
Record the names of these attributes as they must be configured in SkySpark.
IMPORTANT: When configuring the attributes, make sure the value of Name is used, not FriendlyName.
In the example below from a SAML attribute statement, this attribute has a FriendlyName of uid and a Name of urn:oid:0.9.2342.19200300.100.1.1. In SkySpark, the value that must be configured for the samlResponseUsernameAttribute is urn:oid:0.9.2342.19200300.100.1.1 assuming this is the attribute that will be used to identify the username.
<saml2:Attribute FriendlyName="uid"
Name="urn:oid:0.9.2342.19200300.100.1.1"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
>
<saml2:AttributeValue xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xsd:string"
>samlusername</saml2:AttributeValue>
</saml2:Attribute>SAML SSO Settings
After enabling the samlSso SysMod on the Host|SysMods view, navigate to Settings|SAML SSO view.
The easiest way to configure SAML, is by using the SAML IdP Metadata. SkySpark can import the IdP Metadata from a Uri or from text.
Click the Import IdP Metadata (Uri) or Import IdP Metadata (Text) button and enter either the Uri to the IdP's XML metadata location or copy and paste the IdP Metadata into the xml field. Importing from a Uri is preferred, but if the IdP does not host the metadata, then the Text option can be used. SkySpark will read the XML document and automatically configure the host, port, tls, idpLoginPath, and idpEntityId settings. SkySpark will also automatically import the IdP Signing Certificate(s) to verify digitally signed assertions sent by the IdP. SkySpark requires all messages sent from the IdP to be digitally signed.
After the import, the samlResponseUsernameAttribute and userProtoAttr must be manually configured with the names identified in the SAML Attributes section. The userProtoPriority setting must also be manually configured. See the prototype example for guidance on how to configure the userProtoPriority setting.
IMPORTANT: All these settings may be manually configured if the IdP XML Metadata is not accessible from SkySpark. In that case, be sure to Manually Import the IdP Signing Certificate.
- autoUpdateIdPMetadataUri - Read Only setting configured via Import IdP Metadata Action. This setting is used to identify the Uri that will be used to check for and automatically update IdP Signing Certs. The IdP Metadata must be digitally signed to support the auto update workflow. If the IdP Metadata is not digitally signed or the IdP Metadata was imported via Text, no Uri will be displayed and auto updates will not occur.
- host - Enter the hostname or IP address of the SAML server.
- Example:
saml.acme.com
- Example:
- port - Enter the port of the SAML server
- tls - Use TLS to connect to the SAML server
- idpLoginPath - Path to the login HTTP REDIRECT binding on the IdP.
- idpEntityId - Entity ID of the IdP, which will be verified by SkySpark in each message.
- loginUpdateMode - See Login Update Mode for details.
- samlResponseUsernameAttribute - Required The attribute in the SAML assertion to use for the synthesized user's username.
- userProtoAttr - When using updateOnLogin loginUpdateMode, this setting is Required unless userProtoDefault is configured. This setting defines the attribute in the user's SAML assertion that is used to determine the user's prototype. See User Prototype Mapping for details.
- userProtoPriority - When using updateOnLogin loginUpdateMode, this setting is Required unless userProtoDefault is configured. If a user maps to multiple user prototypes, this list specifies the priority of which one should be chosen. See User Prototype Mapping for details.
- userProtoDefault - Optional setting. If a user cannot be mapped to a prototype via the
userProtoAttr, then use the prototype with this name as the default. - applyTagsFunc - Optional setting. Axon callback function used to set/change tags on a user before a session is created. The function should take two parameters (user, attrs) where
useris the current User tags (with prototype already applied) andattrsis the SAML assertion attributes Dict for that user. Return the updated User Dict. See Example applyTagsFunc. - supportText - Optional setting. Fandoc formatted text that will display on samlSso/authFailed page that can be used to help users troubleshoot login issues.
Manually Import IdP Signing Certificate
SkySpark requires all SAML Assertions to be digitally signed. SkySpark must trust the certificate used by the IdP to digitally sign SAML Assertions. Refer to Trusted Certificates for steps to manually import the IdP Signing Certificate.
Login Update Mode
The SAML mod can be configured to interact with users in the user database in several, flexible ways. Choose the option that meets the project requirements:
authOnly: ( default ) SAML will only be used for authenticating the user. The user must exist in the user database in order to log in.updateOnLogin: Creates or updates the user database rec every time the user logs in by applying the configured prototype and invoking theapplyTagsFunc(if configured). The user rec is only updated if the prototype assignment changes, or tags are modified by the theapplyTagsFunc.
User Prototype Mapping
When a user successfully authenticates using SamlSso, the user is not prompted for a username or password so the SAML assertion is used to lookup a SkySpark User in the local user database. If a local user record cannot be found and Login Update Mode is configured to updateOnLogin then to construct a valid user, an authenticated user must be mapped to a User Prototype.
- Create the user prototypes required for the host.
- Configure the
samlSsoUserProtoAttrValfor each prototype that will be used for SamlSso:- When the SamlSso SysMod is enabled, a new tag is available to add to a user prototype called
samlSsoUserProtoAttrVal - The value of this tag is used to help the SamlSsoMod determine which user prototypes a SamlSso user maps to. The SamlSsoMod will check the values of the
userProtoAttr(as configured in the Saml SSO settings) - After a user is authenticated using SamlSso, the SamlSsoMod looks up the user's attribute in the SAML assertion
- When reading the user's attributes SAML assertion, if one of them matches this tag's value, then this prototype is a potential match for the user attempting to log in.
- When the SamlSso SysMod is enabled, a new tag is available to add to a user prototype called
- Configure one or more user prototypes as a comma separated list (enter
userProtoNameof eachuserProtorecord) for theuserProtoPrioritysetting. - Optionally configure a default user prototype (enter
userProtoNameofuserProtorecord) so users can still login when they cannot be mapped to an existing prototype. As a best practice, this prototype should have an operator role and limited access.
Example
SAML SSO Settings:
userProtoAttr: "SkySparkUserPrototype"
userProtoPriority:"engineering, si, default"User Prototypes
id: @engineering
userProto
userProtoName: "engineering"
dis:"Engineering"
userRole:"admin"
samlSsoUserProtoAttrVal: "Engineering"
id: @si
userProto
userProtoName: "si"
dis:"System Integrator"
userRole:"op"
samlSsoUserProtoAttrVal: "SI"
appAccess: "energy"SAML assertion for user bob (represented as a Dict for clarity).
username: "bob"
email: "bob@company.com"
SkySparkUserPrototype: "SI"
... other attributes ...- User
bobauthenticates via SamlSso. - The SamlSsoMod will determine the username from the SAML assertion is
bob. - The SamlSsoMod now checks prototype priorities specified by the
userProtoPrioritysetting in order to try and find the best prototype match for bob:- The first prototype in this list is
engineering. ThesamlSsoUserProtoAttrValfor this prototype isEngineering. This value is not in theSkySparkUserPrototypelist specified in Bob's SAML assertion. - The next prototype in the list is
si. ThesamlSsoUserProtoAttrValfor this prototype isSI. This value is in theSkySparkUserPrototypelist for Bob.
- The first prototype in this list is
- The
siprototype is used to create a synthetic user for Bob's session and Bob is successfully logged in. (Bob will be an operator with access only to the energy app).
NOTE: It is an error for a user to exist in the local user database with a username that matches the username of a user logging in via SamlSso. If this condition is detected, the user will not be allowed to log in. An error to this effect will be logged to the console.
Optional User Attributes
The following optional SAML attributes will be set while synthesizing the user if they exist:
- Display Name (dis) - Assertion Attribute: displayName
- Email Address (email) - Assertion Attribute: email
NOTE: The dis tag is set to the username if a displayName attribute does not exist.
Example applyTagsFunc
A simple example use case for the applyTagsFunc is to add the email address to the synthesized user. In this example, the user's email address is provided in the Assertion with the attribute name skysparkEmailAddress.
NOTE: Every key in the attrs Dict is a List of values (a single value will be a List with one item). Additionally, each attribute returned from the identity provider is converted to a valid tag name using toTagName() so accessing the name of the attribute may differ from what is shown in the encoded SAML authentication response message. During initial configuration, echo(attrs) can be helpful to verify attribute names.
(user, attrs) => do
emailList: attrs["skysparkEmailAddress"]
if (emailList != null and emailList.size == 1)
user = user.set("email", emailList.first)
return user
endSAML IdP Configuration
On the Settings|SAML SSO view, click the Show SkySpark SP Metadata button to display the SkySpark SAML Metadata. Some IdPs will support configuring the SkySpark Service Provider by copying and pasting this XML into the IdP SP configuration page. By default, the siteUri setting is used in the two locations specified below as {siteUri}.
The entityId does not include the port. The SkySpark siteUri is configured on the Settings|HTTP view. When configuring the IdP it is important to use the address that users will connect to SkySpark with as the IdP will likely reject a request for an unknown Entity ID. Additionally, SkySpark will check that the Audience lists the SkySpark Entity ID in the response.
<?xml version='1.0' encoding='UTF-8'?>
<md:EntityDescriptor xmlns:md='urn:oasis:names:tc:SAML:2.0:metadata' entityID='{siteUri without port}'>
<md:SPSSODescriptor WantAssertionsSigned='true' protocolSupportEnumeration='urn:oasis:names:tc:SAML:2.0:protocol'>
<md:NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:transient</md:NameIDFormat>
<md:AssertionConsumerService Binding='urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST' Location='{siteUri}/samlSso/assertionConsumerService' index='0' isDefault='true'/>
</md:SPSSODescriptor>
</md:EntityDescriptor>For convenience when displaying the SkySpark SP Metadata, the SkySpark Entity ID and Assertion Consumer binding are called out below the XML. When copying the SkySpark Metadata to an IdP, do not include the lines shown below:
SkySpark Entity ID: {siteUri without port}
SkySpark Assertion Consumer HTTP-POST Binding: {siteUri}/samlSso/assertionConsumerServiceSkySpark Entity Id
By default, the siteUri of the SkySpark server is used for the SkySpark Entity Id, excluding the port. This can be overridden by adding a tag to the samlSso entry in var/host/folio.trio called skysparkEntityId and specify a Str value.
Restart SkySpark after making the change.
SkySpark Assertion Consumer Service Uri
By default, the siteUri of the SkySpark server is used to build the Assertion Consumer Service Uri using this format: {siteUri}/samlSso/assertionConsumerService
Most of the time, it is recommended to use the siteUri, but when working across numerous dev and test environments it can simplify testing to use something other than the siteUri. To do that, add a tag to the samlSso entry in var/host/folio.trio called skysparkBaseUri and specify a Uri value. Remember to include the port if necessary. When adding this tag, the default Entity Id will also change. See SkySpark Entity Id section to change the SkySpark Entity Id.
Restart SkySpark after making the change.
Encrypted Assertions
Support for encrypted assertions is not enabled by default. Additional support pods are required.
def
samlSsoUserProtoAttrVal
The value of this tag is used to help the SAML SSO auth mod determine which user prototypes a SAML SSO user matches. The SAML SSO mod checks the values of the userProtoAttr (as configured in the SAML SSO settings) when reading assertion from the configured SAML server, and if one of them matches this tag's value, then this prototype is a potential match for the user attempting to log in.
meta
| def | samlSsoUserProtoAttrVal |
| is | str |
| lib | lib:samlSso |
| tagOn | userProto |
supertypes
| val | Data value type |
| scalar | Scalar is an atomic value kind |
| str | Unicode string of characters |
def
view:samlSsoSettings
Settings for the SAML system module
meta
| appName | settings |
| def | view:samlSsoSettings |
| disKey | samlSsoMod::samlSsoSettings |
| icon | view |
| is | view |
| lib | lib:samlSso |
| su | ✓ |
supertypes
| feature | Feature namespace of definitions formatted as feature:name |
| view | Fresco UI view |
src
view: {inherit:"form"}
submit: {action:"hostCommit"}
import: {action:"samlImportIdPMetadataUri" templateName:"importIdPMetadataUriTemplate"}
importText: {action:"samlImportIdPMetadataText" templateName:"importIdPMetadataTextTemplate"}
print: {action:"samlShowSkySparkMetadata"}
validate: {action:"samlValidateConfig"}
data: {expr:"hostSettings(\"samlSso\")"}