註冊中心 eureka 和spring boot admin

官方文檔對Spring-Boot-Admin安全的介紹

保護Spring Boot Admin Server
因爲解決分佈式Web應用程序中的身份驗證和受權有多種方法,所以Spring Boot Admin不提供默認方法。 若是在依賴項中包含spring-boot-admin-server-ui-login,它將提供登陸頁面和註銷按鈕。css

Spring Security配置可能以下所示:
 html

@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();
    }
  }

 

注意:git

若是保護/api/applications端點,請不要忘記使用spring.boot.admin.username和spring.boot.admin.password在SBA客戶端上配置用戶名和密碼【不然你的client端信息註冊不到server端上】。github

官方示例地址:https://github.com/codecentric/spring-boot-admin/blob/1.5.x/spring-boot-admin-samplesspring

保護客戶端Actuator端點
使用HTTP基自己份驗證保護Actuator點時,SBA服務器須要憑據才能訪問它們。 註冊應用程序時,您能夠在元數據中提交憑據。 而後,BasicAuthHttpHeaderProvider使用此元數據添加Authorization標頭以訪問應用程序的執行器端點。 您能夠提供本身的HttpHeadersProvider來改變行爲(例如添加一些解密)或添加額外的標頭。api

使用SBA客戶端提交憑據:安全

application.yml服務器

spring.boot.admin:
  url: http://localhost:8080
  client:
    metadata:
      user.name: ${security.user.name}
      user.password: ${security.user.password}


使用Eureka提交憑據:app

application.yml分佈式

eureka:
  instance:
    metadata-map:
      user.name: ${security.user.name}
      user.password: ${security.user.password}


 注意:SBA服務器屏蔽HTTP接口中的某些元數據,以防止泄漏敏感信息。

在經過元數據提交憑據時,應爲SBA服務器或(服務註冊表)配置HTTPS。

使用Spring Cloud Discovery時,您必須意識到任何能夠查詢服務註冊表的人均可以獲取憑據。  

相關文章
相關標籤/搜索