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 配置。可選。