Istio authservice oidc 无法为访问令牌交换授权代码

Istio authservice oidc fails to exchange authorization code for access token

我们正在尝试在我们的 k8s 集群中使用 istio 为 authZ 和 authN 设置一个 oidc 提供程序。我们在此处遵循此示例:Bookinfo with Authservice Example 进行集成。 以下是有关设置的详细信息:

OIDC 提供商:Keycloak
资助类型:authorization_code
Istio 版本:1.5

身份验证流程:

  1. 在第一次请求时,由于没有身份验证,authservice 成功重定向到 Keycloak,在那里我们能够成功登录。
  2. Keycloak 然后将请求重定向到 redirect_uri 上的应用程序。授权代码现在存在于此 uri 中。
  3. redirect_uri 再次被 authservice 拦截,它检测到 url 是 the configmap
  4. 中定义的 oidc 的过滤器 url
  5. 现在它尝试调用 keycloak 来交换访问令牌的授权码。

这是 authservice 失败并给出错误 IdP connection error 的步骤。请求日志如下:

Check: processing request ://microservice.url.com/appservice/oauth/callback?state=LeCNEqfwA6EUFGNGLt7JALx8jCWkPxjn7qCELbqkKrk&session_state=18f0e3b0-bee2-44a5-b049-6e349dbeda49&code=ddea1ea6-5616-416d-8291-c00bce6f2e9b.18f0e3b0-bee2-44a5-b049-6e349dbeda49.af7e7c31-fd4b-4a66-9856-25d1ac305d3f with filter chain idp_filter_chain
20/03/2020 17:27:48 [2020-03-20 11:57:48.546] [console] [trace] New
20/03/2020 17:27:48 [2020-03-20 11:57:48.547] [console] [trace] OidcFilter
20/03/2020 17:27:48 [2020-03-20 11:57:48.548] [console] [trace] Process
20/03/2020 17:27:48 [2020-03-20 11:57:48.548] [console] [debug] Call from @10.42.5.53 to @10.42.5.58
20/03/2020 17:27:48 [2020-03-20 11:57:48.549] [console] [trace] MatchesCallbackRequest: checking handler for ://microservice.url.com/appservice/oauth/callback?state=LeCNEqfwA6EUFGNGLt7JALx8jCWkPxjn7qCELbqkKrk&session_state=18f0e3b0-bee2-44a5-b049-6e349dbeda49&code=ddea1ea6-5616-416d-8291-c00bce6f2e9b.18f0e3b0-bee2-44a5-b049-6e349dbeda49.af7e7c31-fd4b-4a66-9856-25d1ac305d3f
20/03/2020 17:27:48 [2020-03-20 11:57:48.549] [console] [trace] RetrieveToken
20/03/2020 17:27:48 [2020-03-20 11:57:48.550] [console] [trace] Post
20/03/2020 17:27:48 [2020-03-20 11:57:48.618] [console] [info] Post: HTTP error encountered: stream truncated
20/03/2020 17:27:48 [2020-03-20 11:57:48.618] [console] [info] RetrieveToken: HTTP error encountered: IdP connection error
20/03/2020 17:27:48 [2020-03-20 11:57:48.618] [console] [trace] Request processing complete
20/03/2020 17:27:48 [2020-03-20 11:57:48.619] [console] [trace] Processing completion and deleting state

进一步检查代码,我发现这个错误是从这里触发的:Authservice oidc filter - Github

为了排除配置问题,我使用OpenID Debugger手动生成授权码,然后调用api将其换成api令牌。我能够成功取回它,没有问题。但不知何故,authservice 失败了。

我这边会不会有什么问题?有没有人遇到过这个问题?任何帮助表示赞赏。让我知道是否需要更多详细信息。

此问题现已由 authservice 团队修复。正如来自 authservice 的 Ryan 所说,这里的问题是:

The log indicates that the request was successful right up until the end, when the Authservice tried to gracefully shutdown the TLS connection, and the server on the other side did not participate fully in the graceful shutdown.

此处的修复是忽略截断错误。该修复程序现已合并到 master 中,并将在下一个版本中提供。您可以自己构建 docker 图像以快速修复。有关此问题和编译说明的更多详细信息,请参见 this github issue