此版本仍在开发中,目前尚不稳定。如需最新稳定版本,请使用 Spring Cloud Config 5.0.1spring-doc.cadn.net.cn

CredHub 后端

Spring Cloud Config Server 支持 CredHub 作为配置属性的后端。
您可以通过添加对 Spring CredHub 的依赖来启用此功能。spring-doc.cadn.net.cn

pom.xml
<dependencies>
	<dependency>
		<groupId>org.springframework.credhub</groupId>
		<artifactId>spring-credhub-starter</artifactId>
	</dependency>
</dependencies>

以下配置使用双向 TLS 访问 CredHub:spring-doc.cadn.net.cn

spring:
  profiles:
    active: credhub
  cloud:
    config:
      server:
        credhub:
          url: https://credhub:8844

属性应以 JSON 格式存储,例如:spring-doc.cadn.net.cn

credhub set --name "/demo-app/default/master/toggles" --type=json
value: {"toggle.button": "blue", "toggle.link": "red"}
credhub set --name "/demo-app/default/master/abs" --type=json
value: {"marketing.enabled": true, "external.enabled": false}

所有名称为 spring.cloud.config.name=demo-app 的客户端应用程序都将拥有以下属性:spring-doc.cadn.net.cn

{
    toggle.button: "blue",
    toggle.link: "red",
    marketing.enabled: true,
    external.enabled: false
}
当未指定标签时,将使用默认值 master。您可以通过设置 spring.cloud.config.server.credhub.defaultLabel 来更改此值。
当未指定配置文件时,将使用 default
添加到 application 的值将被所有应用程序共享。

OAuth 2.0

您可以使用 OAuth 2.0 并以 UAA 作为提供商进行身份验证。spring-doc.cadn.net.cn

pom.xml
<dependencies>
	<dependency>
		<groupId>org.springframework.security</groupId>
		<artifactId>spring-security-config</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.security</groupId>
		<artifactId>spring-security-oauth2-client</artifactId>
	</dependency>
</dependencies>

以下配置使用 OAuth 2.0 和 UAA 访问 CredHub:spring-doc.cadn.net.cn

spring:
  profiles:
    active: credhub
  cloud:
    config:
      server:
        credhub:
          url: https://credhub:8844
          oauth2:
            registration-id: credhub-client
  security:
    oauth2:
      client:
        registration:
          credhub-client:
            provider: uaa
            client-id: credhub_config_server
            client-secret: asecret
            authorization-grant-type: client_credentials
        provider:
          uaa:
            token-uri: https://uaa:8443/oauth/token
所使用的 UAA 客户端 ID 应具有 credhub.read 作为作用域。

以下表格描述了 CredHub 的配置属性。spring-doc.cadn.net.cn

属性名称 备注

urlspring-doc.cadn.net.cn

CredHub 服务器 URL。spring-doc.cadn.net.cn

路径spring-doc.cadn.net.cn

所有凭证的基准路径。可选,默认为空。spring-doc.cadn.net.cn

defaultLabelspring-doc.cadn.net.cn

默认标签,当客户端应用程序未提供时使用。可选,默认为masterspring-doc.cadn.net.cn

OAuth2spring-doc.cadn.net.cn

OAuth2 配置,用于访问 CredHub。可选。spring-doc.cadn.net.cn