为 WebSphere Liberty 操作程序配置单点登录 (SSO)
管理员可以为 WebSphere® Liberty 操作程序配置单点登录 (SSO),以便认证和管理用户。 身份验证可以委托给外部提供商,例如Google、脸书、 LinkedIn,、推特 GitHub, 或任何 OpenID (OIDC)或 2.0 客户端。
过程
使用指定的客户机标识和私钥来配置 SSO
操作程序可以提前指定客户机标识和私钥。 此配置的缺点是必须重复提供客户机标识和密钥以进行注册,而不是 自动由提供者管理员提供注册一次所需的信息 。
- 创建一个私钥,用于指定您在应用程序映像中选择的登录提供者的敏感信息,例如客户机标识、客户机私钥和令牌。
在 WebSphereLibertyApplication 实例所在的名称空间中创建名为
WebSphereLibertyApplication_name-wlapp-sso的Secret。 在以下样本片段中,WebSphereLibertyApplication 命名为my-app,因此该私钥必须命名为my-app-wlapp-sso。 这两者都位于名为demo的名称空间中。Secret中的密钥必须遵循provider_name-sensitive_field_name命名模式。 例如,google-clientSecret。 您还可以使用.或_来代替两者之间的-字符。 例如,oauth2_userApiToken。apiVersion: v1 kind: Secret metadata: # Name of the secret should be in this format: <WebSphereLibertyApplication_name>-wlapp-sso name: my-app-wlapp-sso # Secret must be created in the same namespace as the WebSphereLibertyApplication instance namespace: demo type: Opaque data: # The keys must be in this format: <provider_name>-<sensitive_field_name> github-clientId: bW9vb29vb28= github-clientSecret: dGhlbGF1Z2hpbmdjb3c= twitter-consumerKey: bW9vb29vb28= twitter-consumerSecret: dGhlbGF1Z2hpbmdjb3c= oidc-clientId: bW9vb29vb28= oidc-clientSecret: dGhlbGF1Z2hpbmdjb3c= oauth2-clientId: bW9vb29vb28= oauth2-clientSecret: dGhlbGF1Z2hpbmdjb3c= oauth2-userApiToken: dGhlbGF1Z2hpbmdjb3c=操作员监视 SSO 私钥的创建和删除以及对其进行的任何更新。 如果在私钥中添加、更新或移除密钥,这种更改会自动传播到应用程序。
- 在 WebSphereLibertyApplication 定制资源 (CR) 中配置单点登录。 至少设置 .spec.sso: {} 字段,以便操作程序可以将值从私钥传递到应用程序。 请参阅 WebSphereLibertyApplication CR 以了解更多 SSO 配置。
- 使用必要的证书来配置安全服务和安全路由。 有关更多信息,请参阅证书。
- 要自动信任来自常用身份提供者 (包括 Google 和 Facebook 等社交登录提供者) 的证书,请将
SEC_TLS_TRUSTDEFAULTCERTS环境变量设置为true。 要自动信任由 Kubernetes 集群发放的证书,请将SEC_IMPORT_K8S_CERTS环境变量设置为true。 或者,您可以在构建应用程序映像时手动包含必需的证书,或者在部署应用程序时使用卷安装这些证书。apiVersion: liberty.websphere.ibm.com/v1 kind: WebSphereLibertyApplication metadata: name: my-app namespace: demo spec: applicationImage: quay.io/my-repo/my-app:1.0 env: - name: SEC_TLS_TRUSTDEFAULTCERTS value: "true" - name: SEC_IMPORT_K8S_CERTS value: "true" sso: redirectToRPHostAndPort: https://redirect-url.mycompany.com github: hostname: github.mycompany.com oauth2: - authorizationEndpoint: specify-required-value tokenEndpoint: specify-required-value oidc: - discoveryEndpoint: specify-required-value service: certificateSecretRef: mycompany-service-cert port: 9443 type: ClusterIP expose: true route: certificateSecretRef: mycompany-route-cert termination: reencrypt
配置 OIDC 提供者的 SSO 自动注册
此操作程序可向提供程序请求客户机标识和客户机私钥,而不是提前需要它们。 此功能可以简化部署,因为提供者管理员可以一次性提供注册所需的信息,而不是重复提供客户机标识和私钥。 从提供者到客户机的回调 URL 由操作程序提供,因此不需要提前知道该 URL。
- 将名为
provider_name-autoreg-field_name的属性添加到 Kubernetes 私钥。首先,操作程序会向 .spec.sso.oidc[].discoveryEndpoint 字段发出 https 请求,以获取后续 REST 调用的 URL。 接下来,它会对提供程序进行其他 REST 调用,并获取客户机标识和客户机密钥。 将使用所获取的值来更新 Kubernetes 私钥。
- 对于 Red Hat® 单点登录 (RH-SSO) ,可以将 .spec.sso.oidc[].userNameAttribute 字段设置为
preferred_username以获取用于登录的用户标识。 对于 IBM Security Verify,请将该字段设置为given_name。在 Red Hat OpenShift® 上使用 RH-SSO 和 IBM® Security Verify 测试了以下示例私钥。
apiVersion: v1 kind: Secret metadata: # Name of the secret should be in this format: <WebSphereLibertyApplication_name>-wlapp-sso name: my-app-wlapp-sso # Secret must be created in the same namespace as the WebSphereLibertyApplication instance namespace: demo type: Opaque data: # base64 encode the data before entering it here. # # Leave the clientId and secret out, registration will obtain them and update their values. # oidc-clientId # oidc-clientSecret # # Reserved: <provider>-autoreg-RegisteredClientId and RegisteredClientSecret # are used by the operator to store a copy of the clientId and clientSecret values. # # Automatic registration attributes have -autoreg- after the provider name. # # Red Hat Single Sign On requires an initial access token for registration. oidc-autoreg-initialAccessToken: xxxxxyyyyy # # IBM Security Verify requires a special clientId and clientSecret for registration. # oidc-autoreg-initialClientId: bW9vb29vb28= # oidc-autoreg-initialClientSecret: dGhlbGF1Z2hpbmdjb3c= # # Optional: Grant types are the types of OAuth flows the resulting clients will allow # Default is authorization_code,refresh_token. Specify a comma separated list. # oidc-autoreg-grantTypes: base64 data goes here # # Optional: Scopes limit the types of information about the user that the provider will return. # Default is openid,profile. Specify a comma-separated list. # oidc-autoreg-scopes: base64 data goes here # # Optional: To skip TLS certificate checking with the provider during registration, specify insecureTLS as true. # Default is false. # oidc-autoreg-insecureTLS: dHJ1ZQ==
配置多个 OIDC 和 OAuth 2.0 提供者
您可以向多个 OIDC 和 OAuth 2.0 提供者进行认证。
- 使用多个 OIDC 或 OAuth 2.0 提供者来配置和构建应用程序映像。
例如,在 Dockerfile 中设置提供者名称。 提供程序名称必须唯一,并且只能包含字母数字字符。
ARG SEC_SSO_PROVIDERS="google oidc:provider1,provider2 oauth2:provider3,provider4" - 在 SSO
Secret中使用提供者名称来指定其客户机标识和私钥。例如,以下
Secret将为客户机标识和私钥设置provider1-clientSecret: dGhlbGF1Z2hpbmdjb3c=。apiVersion: v1 kind: Secret metadata: # Name of the secret should be in this format: <WebSphereLibertyApplication_name>-wlapp-sso name: my-app-wlapp-sso # Secret must be created in the same namespace as the WebSphereLibertyApplication instance namespace: demo type: Opaque data: # The keys must be in this format: <provider_name>-<sensitive_field_name> google-clientId: xxxxxxxxxxxxx google-clientSecret: yyyyyyyyyyyyyy provider1-clientId: bW9vb29vb28= provider1-clientSecret: dGhlbGF1Z2hpbmdjb3c= provider2-autoreg-initialClientId: bW9vb29vb28= provider2-autoreg-initialClientSecret: dGhlbGF1Z2hpbmdjb3c= provider3-clientId: bW9vb29vb28= provider3-clientSecret: dGhlbGF1Z2hpbmdjb3c= provider4-clientId: bW9vb29vb28= provider4-clientSecret: dGhlbGF1Z2hpbmdjb3c= - 在 WebSphereLibertyApplication CR 中为每个相应提供者配置一个字段。 使用 .spec.sso.oidc[].id 字段和/或 .spec.sso.oauth2[].id 字段。
sso: oidc: - id: provider1 discoveryEndpoint: specify-required-value - id: provider2 discoveryEndpoint: specify-required-value oauth2: - id: provider3 authorizationEndpoint: specify-required-value tokenEndpoint: specify-required-value - id: provider4 authorizationEndpoint: specify-required-value tokenEndpoint: specify-required-value