简体   繁体   English

Spring Cloud Data Flow 安全配置和与 RedHat SSO 的集成

[英]Spring Cloud Data Flow security configuracion and integration with RedHat SSO

We are trying to turn on the security for Spring Cloud Data Flow following the documentation ( https://docs.spring.io/spring-cloud-dataflow/docs/current-SNAPSHOT/reference/htmlsingle/#configuration-security ) but we have some knowledge gaps that we are not capable to fill.我们正在尝试按照文档( https://docs.spring.io#configuration-cloud-current-dataflow/sdocsle/有一些我们无法填补的知识空白。

According to the point 9.2, it is possible to configure the authentication with OAuth 2.0 and integrate it with SSO.根据第 9.2 点,可以使用 OAuth 2.0 配置身份验证并将其与 SSO 集成。 We use RedHat SSO, so we are trying to integrate both of them, but we are not capable to make it works, is it possible or there is a limitation about the SSO used?我们使用 RedHat SSO,因此我们正在尝试将两者集成,但我们无法使其正常工作,是否可能或使用的 SSO 存在限制?

Following the documentation, we have set these properties:根据文档,我们设置了这些属性:

  • spring.security.oauth2.client.registration.uaa.client-id=xxxxxxx spring.security.oauth2.client.registration.uaa.client-id=xxxxxxx
  • spring.security.oauth2.client.registration.uaa.client-secret=xxxxxx spring.security.oauth2.client.registration.uaa.client-secret=xxxxxx
  • spring.security.oauth2.client.registration.uaa.redirect-uri='{baseUrl}/login/oauth2/code/{registrationId}' spring.security.oauth2.client.registration.uaa.redirect-uri='{baseUrl}/login/oauth2/code/{registrationId}'
  • spring.security.oauth2.client.registration.uaa.authorization-grant-type=authorization_code spring.security.oauth2.client.registration.uaa.authorization-grant-type=authorization_code
  • spring.security.oauth2.client.registration.uaa.scope[0]=openid spring.security.oauth2.client.registration.uaa.scope[0]=openid
  • spring.security.oauth2.client.provider.uaa.jwk-set-uri=../openid-connect/certs spring.security.oauth2.client.provider.uaa.jwk-set-uri=../openid-connect/certs
  • spring.security.oauth2.client.provider.uaa.token-uri=../openid-connect/token spring.security.oauth2.client.provider.uaa.token-uri=../openid-connect/token
  • spring.security.oauth2.client.provider.uaa.user-info-uri=../openid-connect/userinfo spring.security.oauth2.client.provider.uaa.user-info-uri=../openid-connect/userinfo
  • spring.security.oauth2.client.provider.uaa.user-name-attribute=user_name spring.security.oauth2.client.provider.uaa.user-name-attribute=user_name
  • spring.security.oauth2.client.provider.uaa.authorization-uri=../openid-connect/auth spring.security.oauth2.client.provider.uaa.authorization-uri=../openid-connect/auth
  • spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=../openid-connect/token/introspect spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=../openid-connect/token/introspect
  • spring.security.oauth2.resourceserver.opaquetoken.client-id=xxxxxxx spring.security.oauth2.resourceserver.opaquetoken.client-id=xxxxxxx
  • spring.security.oauth2.resourceserver.opaquetoken.client-secret=xxxxxxx spring.security.oauth2.resourceserver.opaquetoken.client-secret=xxxxxxx

So we have some considerations:所以我们有一些考虑:

  • The properties resourceserver.opaquetoken are needed for the introspection of the token, so we are pretty sure that they are necessary for when we receive a REST request and it must have the Authorization header令牌的自省需要属性resourceserver.opaquetoken ,所以我们很确定当我们收到 REST 请求并且它必须具有授权header 时,它们是必需的
  • If we are not using UAA, should the properties be named uaa ?如果我们不使用 UAA,属性应该命名为uaa吗?
  • When we try to access to de UI, it redirects to the authorization-uri because the authorization-grant-type=authorization_code , so it will login in the SSO, is that right?当我们尝试访问de UI时,它会重定向到authorization-uri ,因为authorization-grant-type=authorization_code ,所以它会登录SSO,对吗?
  • If we use the grant-type Password it would request directly a username/password for login, where does it is validated?如果我们使用授权类型密码,它将直接请求用户名/密码进行登录,它在哪里验证?
  • The user-info URI is mandatory but, is it really used?用户信息 URI 是强制性的,但它真的被使用了吗?
  • What are the other URIs (jwk and token) used for?其他 URI(jwk 和令牌)用于什么?
  • Why the redirect URI has that format?为什么重定向 URI 有这种格式? where does that variables point to?这些变量指向哪里?

Finally, we have test the configuration in a SCDF running in a Docker container, but it does "nothing":最后,我们在 Docker 容器中运行的 SCDF 中测试了配置,但它“什么也没做”:

dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] org.apache.tomcat.util.http.Parameters   : Set query string encoding to UTF-8
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.a.t.util.http.Rfc6265CookieProcessor   : Cookies: Parsing b[]: JSESSIONID=55694CBB4F694DD2E345AF61AF90B05D
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.a.catalina.connector.CoyoteAdapter     :  Requested cookie session id is 55694CBB4F694DD2E345AF61AF90B05D
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.a.c.authenticator.AuthenticatorBase    : Security checking request POST /tasks/executions
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] org.apache.catalina.realm.RealmBase      :   No applicable constraints defined
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.a.c.a.jaspic.AuthConfigFactoryImpl     : Loading persistent provider registrations from [/tmp/tomcat.1807897745863872641.9393/conf/jaspic-providers.xml]
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.a.c.authenticator.AuthenticatorBase    : Not subject to any constraint
dataflow-server    |  INFO 1 --- [nio-9393-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.apache.catalina.core.StandardWrapper   :   Returning non-STM instance
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] org.apache.tomcat.util.http.Parameters   : Set encoding to UTF-8
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] org.apache.tomcat.util.http.Parameters   : Start processing with input [name=microapabatch&arguments=--my.arguments.sleep=2000+--my.arguments.forceFailure=false]
dataflow-server    | TRACE 1 --- [nio-9393-exec-1] s.n.www.protocol.http.HttpURLConnection  : ProxySelector Request for https://xxxxxxxxxxxxxxxxxxxxxxxx/openid-connect/token/introspect
dataflow-server    | TRACE 1 --- [nio-9393-exec-1] s.n.www.protocol.http.HttpURLConnection  : Looking for HttpClient for URL https://xxxxxxxxxxxxxxxxxxxxxxxx/openid-connect/token/introspect and proxy value of DIRECT
dataflow-server    | TRACE 1 --- [nio-9393-exec-1] s.n.www.protocol.http.HttpURLConnection  : Creating new HttpsClient with url:https://xxxxxxxxxxxxxxxxxxxxxxxx/openid-connect/token/introspect and proxy:DIRECT with connect timeout:-1
dataflow-server    | TRACE 1 --- [nio-9393-exec-1] s.n.www.protocol.http.HttpURLConnection  : Proxy used: DIRECT
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.a.tomcat.util.net.SocketWrapperBase    : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@1376a3b7:org.apache.tomcat.util.net.NioChannel@198ec8c7:java.nio.channels.SocketChannel[connected local=/172.18.0.4:9393 remote=/172.18.0.1:33758]], Read from buffer: [0]
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] org.apache.tomcat.util.net.NioEndpoint   : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@1376a3b7:org.apache.tomcat.util.net.NioChannel@198ec8c7:java.nio.channels.SocketChannel[connected local=/172.18.0.4:9393 remote=/172.18.0.1:33758]], Read direct from socket: [0]
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.apache.coyote.http11.Http11Processor   : Socket: [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@1376a3b7:org.apache.tomcat.util.net.NioChannel@198ec8c7:java.nio.channels.SocketChannel[connected local=/172.18.0.4:9393 remote=/172.18.0.1:33758]], Status in: [OPEN_READ], State out: [OPEN]
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] o.a.coyote.http11.Http11NioProtocol      : Pushed Processor [org.apache.coyote.http11.Http11Processor@17492586]
dataflow-server    | DEBUG 1 --- [nio-9393-exec-1] org.apache.tomcat.util.net.NioEndpoint   : Registered read interest for [org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper@1376a3b7:org.apache.tomcat.util.net.NioChannel@198ec8c7:java.nio.channels.SocketChannel[connected local=/172.18.0.4:9393 remote=/172.18.0.1:33758]]

It seems that the problem is the 'remote=/172.18.0.1:33758', but we can't explain how the introspect uri can be converted in this local IP.似乎问题出在'remote=/172.18.0.1:33758',但我们无法解释如何在这个本地IP中转换内省uri。

These are all plain Spring Security OAuth settings and concepts are better documented there.这些都是简单的 Spring 安全 OAuth 设置和概念在那里有更好的记录。 We're in a process to add better docks for keycloak but in a meanwhile my old test dataflow-keycloak might get you started.我们正在为 keycloak 添加更好的扩展坞,但与此同时,我的旧测试dataflow-keycloak可能会帮助您入门。

In a recent versions we added a better way to use plain jwt keys and we documented it for Azure/AD .在最近的版本中,我们添加了一种更好的方法来使用普通的 jwt 密钥,我们为Azure/AD记录了它。 Plan is to add similar section for keycloak.计划是为 keycloak 添加类似的部分。

I believe just by using issuer-uri and jwk-set-uri should give you a working setup(you still need to figure out scope to roles mappings) as Spring Security is using those to autoconfigure oauth settings.我相信仅通过使用issuer-urijwk-set-uri 就可以为您提供工作设置(您仍然需要弄清楚 scope 到角色映射),因为 Spring 安全性正在使用这些设置来自动配置 Z7C82E855B0415F27BD0Z92D2。 All the other settings are kinda legacy dating back times when we weren't fully on Spring Security 5.3 line.当我们还没有完全使用 Spring 安全 5.3 线时,所有其他设置都有点旧。

For RH SSO I'm not sure if you're talking about some global shared instance or your private setup.对于 RH SSO,我不确定您是在谈论一些全局共享实例还是您的私有设置。

For those as newbie as I was, I am going to add some points to take into account when configuring the security in SCDF对于像我这样的新手,我将添加一些在 SCDF 中配置安全性时要考虑的要点

First, some comments to the original considerations:首先,对原始考虑的一些评论:

  • The properties resourceserver.opaquetoken are needed for the introspection of the token, so we are pretty sure that they are necessary for when we receive a REST request and it must have the Authorization header --> That is.令牌的自省需要属性 resourceserver.opaquetoken ,所以我们很确定当我们收到 REST 请求并且它必须具有授权 header 时,它们是必需的--> 就是这样。
  • If we are not using UAA, should the properties be named uaa?如果我们不使用 UAA,是否应该将属性命名为 uaa? --> It is just a label, you can put whatever you want. --> 它只是一个label,你可以放任何你想要的东西。 It creates the relationship between all the related properties and is the text that appears in the page for login.它创建了所有相关属性之间的关系,并且是出现在登录页面中的文本。
  • When we try to access to de UI, it redirects to the authorization-uri because the authorization-grant-type=authorization_code, so it will login in the SSO, is that right?当我们尝试访问de UI时,它会重定向到authorization-uri,因为authorization-grant-type=authorization_code,所以它会登录SSO,对吗? --> Yes, this shows a page with the label (link) used in the previous point that redirect to your SSO login page. --> 是的,这显示了一个页面,其中包含上一点中使用的 label(链接)重定向到您的 SSO 登录页面。
  • If we use the grant-type Password it would request directly a username/password for login, where does it is validated?如果我们使用授权类型密码,它将直接请求用户名/密码进行登录,它在哪里验证? --> In older versions of SCDF it was possible to set usernames and passwords directly in the config file, but this is not available anymore. --> 在旧版本的 SCDF 中,可以直接在配置文件中设置用户名和密码,但这不再可用。 I have not continued investigating this option since with the authorization_code we made it work.我没有继续研究这个选项,因为我们使用了授权代码。
  • The user-info URI is mandatory but, is it really used?用户信息 URI 是强制性的,但它真的被使用了吗? --> Yes, it is used in a point of the authentication flow. --> 是的,它是用在认证流程的一个点上。
  • What are the other URIs (jwk and token) used for?其他 URI(jwk 和令牌)用于什么? --> Are part of the authentication flow --> 是身份验证流程的一部分
  • Why the redirect URI has that format?为什么重定向 URI 有这种格式? where does that variables point to?这些变量指向哪里? --> Once you are authenticated, you are redirected to this url, where 'baseUrl' is your hostname and it is automatically resolved. --> 通过身份验证后,您将被重定向到此 url,其中“baseUrl”是您的主机名,它会自动解析。

Now, the configuration we used to make it work:现在,我们用来使其工作的配置:

  • spring.security.oauth2.client.registration.RedHatSSO.client-id=XXXXXXX spring.security.oauth2.client.registration.RedHatSSO.client-id=XXXXXXX
  • spring.security.oauth2.client.registration.RedHatSSO.client-secret=YYYYYYY spring.security.oauth2.client.registration.RedHatSSO.client-secret=YYYYYYY
  • spring.security.oauth2.client.registration.RedHatSSO.redirect-uri={baseUrl}/login/oauth2/code/{registrationId} --> Beware of the feet mark symbols (') enclosing the value, they are necessary or not depending on the infraestructure used for the deployment. spring.security.oauth2.client.registration.RedHatSSO.redirect-uri={baseUrl}/login/oauth2/code/{registrationId} --> 注意包含值的脚标记符号 ('),它们是否必要取决于用于部署的基础设施。
  • spring.security.oauth2.client.registration.RedHatSSO.authorization-grant-type=authorization_code spring.security.oauth2.client.registration.RedHatSSO.authorization-grant-type=authorization_code
  • spring.security.oauth2.client.registration.RedHatSSO.scope[0]=openid spring.security.oauth2.client.registration.RedHatSSO.scope[0]=openid
  • spring.security.oauth2.client.provider.RedHatSSO.user-name-attribute=preferred_username --> This property is necessary to indicate the label of the property where the user name is located in the response of the SSO server (when it is not 'username'). spring.security.oauth2.client.provider.RedHatSSO.user-name-attribute=preferred_username --> 这个属性是必须的,在SSO服务器的响应中指明用户名所在属性的label(当它是不是“用户名”)。
  • spring.security.oauth2.client.provider.RedHatSSO.jwk-set-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/certs --> All these endpoint URIs should be set according to the endpoints provided by the SSO. spring.security.oauth2.client.provider.RedHatSSO.jwk-set-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/certs --> 所有这些端点 URI 都应根据 SSO 提供的端点进行设置。
  • spring.security.oauth2.client.provider.RedHatSSO.token-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/token spring.security.oauth2.client.provider.RedHatSSO.token-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/token
  • spring.security.oauth2.client.provider.RedHatSSO.user-info-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/userinfo spring.security.oauth2.client.provider.RedHatSSO.user-info-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/userinfo
  • spring.security.oauth2.client.provider.RedHatSSO.authorization-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/auth spring.security.oauth2.client.provider.RedHatSSO.authorization-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/auth
  • spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/token/introspect spring.security.oauth2.resourceserver.opaquetoken.introspection-uri=https://ZZZZZZZZZZZZ/protocol/openid-connect/token/introspect
  • spring.security.oauth2.resourceserver.opaquetoken.client-id=XXXXXXX spring.security.oauth2.resourceserver.opaquetoken.client-id=XXXXXXX
  • spring.security.oauth2.resourceserver.opaquetoken.client-secret=YYYYYYY spring.security.oauth2.resourceserver.opaquetoken.client-secret=YYYYYYY
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.map-oauth-scopes=true --> Activates the role mapping configuration spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.map-oauth-scopes=true --> 激活角色映射配置
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_CREATE=dataflow.create --> All these properties map each ROLE in SCDF to a client scope included in the user info retrieved by the SSO server. spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_CREATE=dataflow.create --> All these properties map each ROLE in SCDF to a client scope included in the user info retrieved by the SSO 服务器。
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_DEPLOY=dataflow.deploy spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_DEPLOY=dataflow.deploy
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_DESTROY=dataflow.destroy spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_DESTROY=dataflow.destroy
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_MANAGE=dataflow.manage spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_MANAGE=dataflow.manage
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_MODIFY=dataflow.modify spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_MODIFY=dataflow.modify
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_SCHEDULE=dataflow.schedule spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_SCHEDULE=dataflow.schedule
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_VIEW=dataflow.view spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_VIEW=dataflow.view

Finally, some considerations in the SSO side (this could vary depending on the used tool, this is for Keycloak/RedHatSSO):最后,SSO 方面的一些注意事项(这可能因使用的工具而异,这是针对 Keycloak/RedHatSSO 的):

  • Activate all the necessary URIs (token, userinfo, introspection...).激活所有必要的 URI(令牌、用户信息、自省...)。
  • Define the 7 client scopes for the 7 SCDF roles.为 7 个 SCDF 角色定义 7 个客户端范围。
  • Define a client in the SSO for SCDF where: activate the Service Accounts , define all the desired roles for the client (admin, operation, common user...), assign the 7 Client Scopes , define a mapper for the username field to avoid errors when it is null, and include the redirect uri (the real one, the hostname of the SCDF) in the list of Valid Redirect URIs (it works with a http://myhostname/*).在 SSO 中为 SCDF 定义一个客户端,其中:激活服务帐户,为客户端定义所有所需的角色(管理员、操作、普通用户......),分配 7 个客户端范围,为用户名字段定义一个映射器以避免当它是 null 时出错,并在有效重定向 URI列表中包含重定向 uri (真实的,SCDF 的主机名)(它适用于 http://myhostname/*)。
  • Once completed the previous point, assign each client scope to the correct Client Roles完成上一点后,将每个客户端 scope分配给正确的客户端角色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM