Spring security 带令牌中继的Spring云安全:响应具有空集cookie头

Spring security 带令牌中继的Spring云安全:响应具有空集cookie头,spring-security,openid,spring-cloud-gateway,spring-cloud-security,Spring Security,Openid,Spring Cloud Gateway,Spring Cloud Security,我尝试构建一个最小的openid安全云环境。或多或少地跟随 我有一个SpringCloudGateway、一个Consor注册表、一个在okta上注册的应用程序和一个简单的测试应用程序,其中只有一个控制器返回字符串。网关和测试应用程序都依赖于'com.okta.spring',名称:'okta spring boot starter',版本:'1.4.0' 网关的配置如下(为了简洁起见,此处跳过ssl): 我添加了一个最低限度的安全配置: private final ReactiveClient

我尝试构建一个最小的openid安全云环境。或多或少地跟随

我有一个SpringCloudGateway、一个Consor注册表、一个在okta上注册的应用程序和一个简单的测试应用程序,其中只有一个控制器返回字符串。网关和测试应用程序都依赖于
'com.okta.spring',名称:'okta spring boot starter',版本:'1.4.0'

网关的配置如下(为了简洁起见,此处跳过ssl):

我添加了一个最低限度的安全配置:

private final ReactiveClientRegistrationRepository clientRegistrationRepository;

@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
    http
            .redirectToHttps()
            .and()
            .authorizeExchange()
            .pathMatchers("/login").permitAll()
            .pathMatchers("/actuator/**").permitAll()
            .anyExchange().authenticated()
            .and()
            .oauth2Login()
            .and()
            .logout(logout -> logout.logoutSuccessHandler(oidcLogoutSuccessHandler()))
            .oauth2ResourceServer()
            .jwt();
    return http.build();
}

private ServerLogoutSuccessHandler oidcLogoutSuccessHandler() {
    OidcClientInitiatedServerLogoutSuccessHandler oidcLogoutSuccessHandler =
            new OidcClientInitiatedServerLogoutSuccessHandler(clientRegistrationRepository);

    oidcLogoutSuccessHandler.setPostLogoutRedirectUri(URI.create("https://<my-uri>"));

    return oidcLogoutSuccessHandler;
}
我的问题是:

当我移除令牌中继并保持测试应用程序不安全时,网关将成功执行授权,并且响应包含一个
set cookie
头,可用于后续请求中,以防止再次通过所有授权流运行

但是,通过
'org.springframework.cloud:spring cloud starter security'
(如上所示配置为默认筛选器)添加令牌中继将返回一个空集cookie头,因此要运行的每个请求都会抛出整个授权流


我尝试了不同的解决方案方法,比如手动配置
reactiveOAuth2AuthorizedClient服务
。我的方法更像是猜测。

事实证明,解决方案是从下游请求中删除cookie头。这可以通过向网关添加另一个默认过滤器来实现:

spring:
  cloud:
    gateway:
      default-filters: 
        - TokenRelay=
        - RemoveRequestHeader=Cookie

仅供参考。。。我是Okta博客文章的作者。在YAML中为JHipster配置令牌中继筛选器时,我遇到了类似的问题@马特·雷布尔:谢谢你的提示。但我怀疑你的解决方案对我的情况会有帮助,因为我正面临上游问题。我必须检查TCP转储,但我猜响应头甚至会发送到网关。我认为
setcookie
头也需要某种中继。
@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
    http
            .authorizeExchange()
            .pathMatchers("/actuator/**").permitAll()
            .anyExchange().authenticated()
            .and()
            .oauth2ResourceServer()
            .jwt();

    Okta.configureResourceServer401ResponseBody(http);

    return http.build();
}
spring:
  cloud:
    gateway:
      default-filters: 
        - TokenRelay=
        - RemoveRequestHeader=Cookie