需要 Spring 引导以重定向到 F5 BigIP SSL 代理后面的 https 但在 http 上侦听
Need Spring Boot to redirect to https behind F5 BigIP SSL Proxy but listen on http
如何继续侦听端口 80 (http),但在登录页面的 Spring 启动应用程序中将 302 重定向发送到端口 443 (https)。我需要这个,因为我的应用程序位于 F5 BigIP 代理之后,该代理终止 SSL 证书并将 http 请求发送到我的应用程序,目前,我看到了这种行为:
这是当前的有缺陷的流程:
- 客户请求 https://myapp.example.com
- F5 BigIP 转换为 (HTTP)myapp.example.com
my Spring 引导应用程序重定向到 (HTTP)myapp.example.com/login 作为客户端的 302 指令
客户端请求 (HTTP)myapp.example.com/login
F5 BigIP 拒绝 HTTP 请求
求流量:
my Spring 引导应用程序将重定向发送到 (HTTPS)myapp.example.com/login 作为 302 到客户端 (Location=(HTTPS)myapp.example.com/login)
F5 BigIP 转换为 (HTTP)myapp.example.com/login
- 我的 Spring 引导应用程序以登录页面响应,一切都是 Honky Dory
我正在使用 Spring 引导版本 1.2.8,我的应用程序位于 F5 BigIp 负载平衡器之后。 BigIP 终止 SSL 证书并将所有 HTTPS 请求重定向到 Spring 仅侦听端口 80 (http) 的启动应用程序。
@Configuration
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/error", "/js/**", "/css/**", "/img/**", "/help", "/favicon.ico").permitAll()
.anyRequest().hasAuthority("USER")
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login-error")
.permitAll()
.and()
.exceptionHandling().accessDeniedPage("/403")
.and()
.logout()
.permitAll();
}
}
我按照 //docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-enable-https 文档添加:
这些application.properties:
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
server.tomcat.internal-proxies=x\.x\.x\.x|x\.x\.x\.x (I tested without this parameter as well)
顺便说一句:使用 http.requiresChannel().anyRequest().requiresSecure() 强制 HTTPS;在这种情况下不起作用,因为我需要来自 HTTP 上的 F5 BigIp 的第二个请求才能工作,使用此设置会循环整个重定向过程。
我需要配置我的应用程序以重定向客户端请求 https://myApp.example.com that is proxied by BigIP to http://myApp.example.com/
https://myApp.example.com/login 以便 F5 BigIP 接受它。
这是 curl 请求的结果:
curl -L -b -vk --url https://myApp.example.com --verbose -vs > curl-output.txt 2>&1
STATE: INIT => CONNECT handle 0x440f160; line 1392 (connection #-5000)
* Rebuilt URL to: https://myApp.example.com/
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x440f160; line 1428 (connection #0)
* Trying XXX.XX.XX.XXX...
…
* SSL certificate verify ok.
* STATE: PROTOCONNECT => DO handle 0x440f160; line 1596 (connection #0)
} [5 bytes data]
> GET / HTTP/1.1
> Host: myApp.example.com
> User-Agent: curl/7.58.0
> Accept: */*
…
< HTTP/1.1 302
…
< X-XSS-Protection: 1; mode=block
* Added cookie JSESSIONID="4CE1A6F2AB684C6E01774E5289AF2AC0" for domain myApp.example.com, path /, expire 0
< Set-Cookie: JSESSIONID=4CE1A6F2AB684C6E01774E5289AF2AC0;path=/;HttpOnly
****< Location: http://myApp.example.com/login <- this needs to be HTTPS****
< Date: Wed, 09 May 2018 22:30:36 GMT
…
* Connection #0 to host myApp.example.com left intact
* Issue another request to this URL: 'http://myApp.example.com/login' <- this needs to be HTTPS
* STATE: PERFORM => CONNECT handle 0x440f160; line 1949 (connection #-5000)
* Added connection 1. The cache now contains 2 members
* STATE: CONNECT => WAITRESOLVE handle 0x440f160; line 1428 (connection #1)
* Trying XXX.XX.XX.XXX...
* TCP_NODELAY set
* STATE: WAITRESOLVE => WAITCONNECT handle 0x440f160; line 1509 (connection #1)
* connect to XXX.XX.XX.XXX port 80 failed: Connection refused
* Failed to connect to myApp.example.com port 80: Connection refused<= Not the result we want
* Closing connection 1
这个问题在服务器端一直没有解决。负责 BIG IP 的系统工程师更改了一些配置设置,现在,它按照他们希望的方式工作。我还没有问过 Big-IP 配置是如何工作的。如果可能的话,我会 post 一些东西,当我发现的时候。
如何继续侦听端口 80 (http),但在登录页面的 Spring 启动应用程序中将 302 重定向发送到端口 443 (https)。我需要这个,因为我的应用程序位于 F5 BigIP 代理之后,该代理终止 SSL 证书并将 http 请求发送到我的应用程序,目前,我看到了这种行为:
这是当前的有缺陷的流程:
- 客户请求 https://myapp.example.com
- F5 BigIP 转换为 (HTTP)myapp.example.com
my Spring 引导应用程序重定向到 (HTTP)myapp.example.com/login 作为客户端的 302 指令
客户端请求 (HTTP)myapp.example.com/login
F5 BigIP 拒绝 HTTP 请求
求流量:
my Spring 引导应用程序将重定向发送到 (HTTPS)myapp.example.com/login 作为 302 到客户端 (Location=(HTTPS)myapp.example.com/login)
F5 BigIP 转换为 (HTTP)myapp.example.com/login
- 我的 Spring 引导应用程序以登录页面响应,一切都是 Honky Dory
我正在使用 Spring 引导版本 1.2.8,我的应用程序位于 F5 BigIp 负载平衡器之后。 BigIP 终止 SSL 证书并将所有 HTTPS 请求重定向到 Spring 仅侦听端口 80 (http) 的启动应用程序。
@Configuration
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/error", "/js/**", "/css/**", "/img/**", "/help", "/favicon.ico").permitAll()
.anyRequest().hasAuthority("USER")
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login-error")
.permitAll()
.and()
.exceptionHandling().accessDeniedPage("/403")
.and()
.logout()
.permitAll();
}
}
我按照 //docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-enable-https 文档添加:
这些application.properties:
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto
server.tomcat.internal-proxies=x\.x\.x\.x|x\.x\.x\.x (I tested without this parameter as well)
顺便说一句:使用 http.requiresChannel().anyRequest().requiresSecure() 强制 HTTPS;在这种情况下不起作用,因为我需要来自 HTTP 上的 F5 BigIp 的第二个请求才能工作,使用此设置会循环整个重定向过程。
我需要配置我的应用程序以重定向客户端请求 https://myApp.example.com that is proxied by BigIP to http://myApp.example.com/ https://myApp.example.com/login 以便 F5 BigIP 接受它。
这是 curl 请求的结果: curl -L -b -vk --url https://myApp.example.com --verbose -vs > curl-output.txt 2>&1
STATE: INIT => CONNECT handle 0x440f160; line 1392 (connection #-5000)
* Rebuilt URL to: https://myApp.example.com/
* Added connection 0. The cache now contains 1 members
* STATE: CONNECT => WAITRESOLVE handle 0x440f160; line 1428 (connection #0)
* Trying XXX.XX.XX.XXX...
…
* SSL certificate verify ok.
* STATE: PROTOCONNECT => DO handle 0x440f160; line 1596 (connection #0)
} [5 bytes data]
> GET / HTTP/1.1
> Host: myApp.example.com
> User-Agent: curl/7.58.0
> Accept: */*
…
< HTTP/1.1 302
…
< X-XSS-Protection: 1; mode=block
* Added cookie JSESSIONID="4CE1A6F2AB684C6E01774E5289AF2AC0" for domain myApp.example.com, path /, expire 0
< Set-Cookie: JSESSIONID=4CE1A6F2AB684C6E01774E5289AF2AC0;path=/;HttpOnly
****< Location: http://myApp.example.com/login <- this needs to be HTTPS****
< Date: Wed, 09 May 2018 22:30:36 GMT
…
* Connection #0 to host myApp.example.com left intact
* Issue another request to this URL: 'http://myApp.example.com/login' <- this needs to be HTTPS
* STATE: PERFORM => CONNECT handle 0x440f160; line 1949 (connection #-5000)
* Added connection 1. The cache now contains 2 members
* STATE: CONNECT => WAITRESOLVE handle 0x440f160; line 1428 (connection #1)
* Trying XXX.XX.XX.XXX...
* TCP_NODELAY set
* STATE: WAITRESOLVE => WAITCONNECT handle 0x440f160; line 1509 (connection #1)
* connect to XXX.XX.XX.XXX port 80 failed: Connection refused
* Failed to connect to myApp.example.com port 80: Connection refused<= Not the result we want
* Closing connection 1
这个问题在服务器端一直没有解决。负责 BIG IP 的系统工程师更改了一些配置设置,现在,它按照他们希望的方式工作。我还没有问过 Big-IP 配置是如何工作的。如果可能的话,我会 post 一些东西,当我发现的时候。