CredHub 后端

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

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

以下配置使用双向 TLS 访问 CredHub

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

属性应以 JSON 格式存储,例如:

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 的客户端应用都将拥有以下属性:

{
    toggle.button: "blue",
    toggle.link: "red",
    marketing.enabled: true,
    external.enabled: false
}
未指定 label 时,将使用 master 作为默认值。您可以通过设置 spring.cloud.config.server.credhub.defaultLabel 来更改此项。
未指定 profile 时,将使用 default
添加到 application 的值将由所有应用共享。

OAuth 2.0

您可以使用 UAA 作为提供者,通过 OAuth 2.0 进行认证。

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:
  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 配置属性。

属性名称 备注

url

CredHub 服务器 URL。

path

所有凭据的基本路径。可选,默认为空。

defaultLabel

当客户端应用未提供 label 时使用的默认 label。可选,默认为 master

oauth2

访问 CredHub 的 OAuth2 配置。可选。