Config安全控制

一、config server引入依賴spring

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

 

二、config server配置bootstrap.yml文件bootstrap

security: basic: enabled: true user: name: lynch password: 123456 encrypt: key-store: location: configserver.keystore alias: mydevkey password: 123456 secret: 123456

 

三、訪問application-prod.properties配置文件
安全

四、config client配置bootstrap.yml文件
4.一、單機配置安全驗證app

#注意config-client的配置須要放到bootstrap.yml中
management:
  security:
    enabled: false
spring:
  application:
    name: mima-cloud-config-client
  cloud:
 config: #安全認證設置用戶名密碼 uri: http://kevin:123456@localhost:6061/ #指定profile,對應mmima-cloud-config-server所獲取的配置文件中的{profile} profile: prod label: master
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true
    instanceId: ${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port}

 

4.二、集羣配置安全驗證spring-boot

#注意config-client的配置須要放到bootstrap.yml中
management:
  security:
    enabled: false
spring:
  application:
    name: mima-cloud-config-client
  cloud:
    consul:
      discovery: 
        instanceId: ${spring.application.name}:${server.port}
      host: localhost
      port: 8500
      config:
        enabled: true #false\u7981\u7528Consul\u914d\u7f6e\uff0c\u9ed8\u8ba4true
        format: YAML    # \u8868\u793aconsul\u4e0a\u9762\u6587\u4ef6\u7684\u683c\u5f0f \u6709\u56db\u79cd YAML PROPERTIES KEY-VALUE FILES
        #data-key: configuration    #\u8868\u793aconsul\u4e0a\u9762\u7684KEY\u503c(\u6216\u8005\u8bf4\u6587\u4ef6\u7684\u540d\u5b57) \u9ed8\u8ba4\u662fdata
        data-key: data    #\u8868\u793aconsul\u4e0a\u9762\u7684KEY\u503c(\u6216\u8005\u8bf4\u6587\u4ef6\u7684\u540d\u5b57) \u9ed8\u8ba4\u662fdata
        #prefix\u8bbe\u7f6e\u914d\u7f6e\u503c\u7684\u57fa\u672c\u6587\u4ef6\u5939
        #defaultContext\u8bbe\u7f6e\u6240\u6709\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u6587\u4ef6\u5939\u540d\u79f0
        #profileSeparator\u8bbe\u7f6e\u7528\u4e8e\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u5728\u5c5e\u6027\u6e90\u4e2d\u5206\u9694\u914d\u7f6e\u6587\u4ef6\u540d\u79f0\u7684\u5206\u9694\u7b26\u7684\u503c 
 config: profile: prod label: master username: lynch password: 123456 discovery: # 默認false,設爲true表示使用註冊中心中的configserver配置而不本身配置configserver的uri enabled: true # 指定config server在服務發現中的serviceId,默認爲:configserver serviceId: mima-cloud-config-server
相關文章
相關標籤/搜索