CredHub バックエンド

Spring Cloud Config サーバーは、構成プロパティのバックエンドとして 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
}
ラベルが指定されていない場合は、デフォルト値として master が使用されます。spring.cloud.config.server.credhub.defaultLabel を設定することでこれを変更できます。
プロファイルが指定されていない場合、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

クライアントアプリケーションによって提供されない場合に使用するデフォルトのラベル。オプションで、デフォルトは master です。

oauth2

CredHub にアクセスするための OAuth2 構成。オプション。