簡體   English   中英

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

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

我們正在嘗試按照文檔( https://docs.spring.io#configuration-cloud-current-dataflow/sdocsle/有一些我們無法填補的知識空白。

根據第 9.2 點,可以使用 OAuth 2.0 配置身份驗證並將其與 SSO 集成。 我們使用 RedHat SSO,因此我們正在嘗試將兩者集成,但我們無法使其正常工作,是否可能或使用的 SSO 存在限制?

根據文檔,我們設置了這些屬性:

  • spring.security.oauth2.client.registration.uaa.client-id=xxxxxxx
  • 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.authorization-grant-type=authorization_code
  • 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.token-uri=../openid-connect/token
  • 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.authorization-uri=../openid-connect/auth
  • 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-secret=xxxxxxx

所以我們有一些考慮:

  • 令牌的自省需要屬性resourceserver.opaquetoken ,所以我們很確定當我們收到 REST 請求並且它必須具有授權header 時,它們是必需的
  • 如果我們不使用 UAA,屬性應該命名為uaa嗎?
  • 當我們嘗試訪問de UI時,它會重定向到authorization-uri ,因為authorization-grant-type=authorization_code ,所以它會登錄SSO,對嗎?
  • 如果我們使用授權類型密碼,它將直接請求用戶名/密碼進行登錄,它在哪里驗證?
  • 用戶信息 URI 是強制性的,但它真的被使用了嗎?
  • 其他 URI(jwk 和令牌)用於什么?
  • 為什么重定向 URI 有這種格式? 這些變量指向哪里?

最后,我們在 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]]

似乎問題出在'remote=/172.18.0.1:33758',但我們無法解釋如何在這個本地IP中轉換內省uri。

這些都是簡單的 Spring 安全 OAuth 設置和概念在那里有更好的記錄。 我們正在為 keycloak 添加更好的擴展塢,但與此同時,我的舊測試dataflow-keycloak可能會幫助您入門。

在最近的版本中,我們添加了一種更好的方法來使用普通的 jwt 密鑰,我們為Azure/AD記錄了它。 計划是為 keycloak 添加類似的部分。

我相信僅通過使用issuer-urijwk-set-uri 就可以為您提供工作設置(您仍然需要弄清楚 scope 到角色映射),因為 Spring 安全性正在使用這些設置來自動配置 Z7C82E855B0415F27BD0Z92D2。 當我們還沒有完全使用 Spring 安全 5.3 線時,所有其他設置都有點舊。

對於 RH SSO,我不確定您是在談論一些全局共享實例還是您的私有設置。

對於像我這樣的新手,我將添加一些在 SCDF 中配置安全性時要考慮的要點

首先,對原始考慮的一些評論:

  • 令牌的自省需要屬性 resourceserver.opaquetoken ,所以我們很確定當我們收到 REST 請求並且它必須具有授權 header 時,它們是必需的--> 就是這樣。
  • 如果我們不使用 UAA,是否應該將屬性命名為 uaa? --> 它只是一個label,你可以放任何你想要的東西。 它創建了所有相關屬性之間的關系,並且是出現在登錄頁面中的文本。
  • 當我們嘗試訪問de UI時,它會重定向到authorization-uri,因為authorization-grant-type=authorization_code,所以它會登錄SSO,對嗎? --> 是的,這顯示了一個頁面,其中包含上一點中使用的 label(鏈接)重定向到您的 SSO 登錄頁面。
  • 如果我們使用授權類型密碼,它將直接請求用戶名/密碼進行登錄,它在哪里驗證? --> 在舊版本的 SCDF 中,可以直接在配置文件中設置用戶名和密碼,但這不再可用。 我沒有繼續研究這個選項,因為我們使用了授權代碼。
  • 用戶信息 URI 是強制性的,但它真的被使用了嗎? --> 是的,它是用在認證流程的一個點上。
  • 其他 URI(jwk 和令牌)用於什么? --> 是身份驗證流程的一部分
  • 為什么重定向 URI 有這種格式? 這些變量指向哪里? --> 通過身份驗證后,您將被重定向到此 url,其中“baseUrl”是您的主機名,它會自動解析。

現在,我們用來使其工作的配置:

  • spring.security.oauth2.client.registration.RedHatSSO.client-id=XXXXXXX
  • spring.security.oauth2.client.registration.RedHatSSO.client-secret=YYYYYYY
  • 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.scope[0]=openid
  • 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 --> 所有這些端點 URI 都應根據 SSO 提供的端點進行設置。
  • 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.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.client-id=XXXXXXX
  • spring.security.oauth2.resourceserver.opaquetoken.client-secret=YYYYYYY
  • 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 服務器。
  • 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_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_SCHEDULE=dataflow.schedule
  • spring.cloud.dataflow.security.authorization.provider-role-mappings.RedHatSSO.role-mappings.ROLE_VIEW=dataflow.view

最后,SSO 方面的一些注意事項(這可能因使用的工具而異,這是針對 Keycloak/RedHatSSO 的):

  • 激活所有必要的 URI(令牌、用戶信息、自省...)。
  • 為 7 個 SCDF 角色定義 7 個客戶端范圍。
  • 在 SSO 中為 SCDF 定義一個客戶端,其中:激活服務帳戶,為客戶端定義所有所需的角色(管理員、操作、普通用戶......),分配 7 個客戶端范圍,為用戶名字段定義一個映射器以避免當它是 null 時出錯,並在有效重定向 URI列表中包含重定向 uri (真實的,SCDF 的主機名)(它適用於 http://myhostname/*)。
  • 完成上一點后,將每個客戶端 scope分配給正確的客戶端角色

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM