英文:
Nginx reverse proxy allow only authenticated users to spring boot api
问题
我有一个任务,需要用Nginx替换Zuul反向代理。在Zuul代理中,安全性是通过以下方式实现的:implementation 'org.springframework.boot:spring-boot-starter-security'
@EnableWebSecurity
class ZuulSecurity(...) : WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
http.csrf().disable().httpBasic().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
.sessionFixation().changeSessionId()
.and().authorizeRequests()
.antMatchers(*dennyPatterns).denyAll()
.antMatchers(*loginPatterns).permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage(loginUrl)
}
}
类似地,Spring Boot API服务也是通过@EnableWebSecurity
进行保护的。
我将Zuul反向代理替换为Nginx作为反向代理。
我该如何在Nginx上强制执行安全性,以便不会将未经身份验证的请求“proxy_pass”到后端API服务?换句话说,我希望在Nginx上验证请求是否由经过身份验证的用户发出(对于loginPatterns URL有一些例外)。我应该学习nginx/admin-guide/security-controls中的哪一部分?
英文:
I have a task of replacing Zuul reverse proxy with Nginx.
Security in Zuul proxy is implemented with implementation 'org.springframework.boot:spring-boot-starter-security'
@EnableWebSecurity
class ZuulSecurity(...) : WebSecurityConfigurerAdapter() {
override fun configure(http: HttpSecurity) {
http.csrf().disable().httpBasic().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
.sessionFixation().changeSessionId()
.and().authorizeRequests()
.antMatchers(*dennyPatterns).denyAll()
.antMatchers(*loginPatterns).permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage(loginUrl)
}
}
Spring boot api services are protected in similar way with @EnableWebSecurity
I replace Zuul reverse proxy with Nginx as reverse proxy.
How can I enforce security on Nginx, so that no unathenticated request is proxy_pass
'ed to backend api servcies? - Other words, I would like to validate on Nginx if request is made by an authenticated user (with some exception for loginPatterns urls). Which one of nginx/admin-guide/security-controls should I study?
答案1
得分: 0
我已经按照configuring-subrequest-authentication/完成了。
英文:
I have done it with configuring-subrequest-authentication/
专注分享java语言的经验与见解,让所有开发者获益!
评论