官方文档对Spring-Boot-Admin安全的介绍
保护Spring Boot Admin Server
由于解决分布式Web应用程序中的身份验证和授权有多种方法,因此Spring Boot Admin不提供默认方法。 如果在依赖项中包含spring-boot-admin-server-ui-login,它将提供登录页面和注销按钮。
Spring Security配置可能如下所示:
@Configuration
public static class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// Page with login form is served as /login.html and does a POST on /login
http.formLogin().loginPage("/login.html").loginProcessingUrl("/login").permitAll();
// The UI does a POST on /logout on logout
http.logout().logoutUrl("/logout");
// The ui currently doesn't support csrf
http.csrf().disable();
// Requests for the login page and the static assets are allowed
http.authorizeRequests()
.antMatchers("/login.html", "/**/*.css", "/img/**", "/third-party/**")
.permitAll();
// ... and any other request needs to be authorized
http.authorizeRequests().antMatchers("/**").authenticated();
// Enable so that the clients can authenticate via HTTP basic for registering
http.httpBasic();
}
}
注意:
如果保护/api/applications端点,请不要忘记使用spring.boot.admin.username和spring.boot.admin.password在SBA客户端上配置用户名和密码【否则你的client端信息注册不到server端上】。
官方示例地址:https://github.com/codecentric/spring-boot-admin/blob/1.5.x/spring-boot-admin-samples
保护客户端Actuator端点
使用HTTP基本身份验证保护Actuator点时,SBA服务器需要凭据才能访问它们。 注册应用程序时,您可以在元数据中提交凭据。 然后,BasicAuthHttpHeaderProvider使用此元数据添加Authorization标头以访问应用程序的执行器端点。 您可以提供自己的HttpHeadersProvider来改变行为(例如添加一些解密)或添加额外的标头。
使用SBA客户端提交凭据:
application.yml
spring.boot.admin:
url: http://localhost:8080
client:
metadata:
user.name: ${security.user.name}
user.password: ${security.user.password}
使用Eureka提交凭据:
application.yml
eureka:
instance:
metadata-map:
user.name: ${security.user.name}
user.password: ${security.user.password}
注意:SBA服务器屏蔽HTTP接口中的某些元数据,以防止泄漏敏感信息。
在通过元数据提交凭据时,应为SBA服务器或(服务注册表)配置HTTPS。
使用Spring Cloud Discovery时,您必须意识到任何可以查询服务注册表的人都可以获取凭据。
来源:oschina
链接:https://my.oschina.net/u/582040/blog/3043604