CredHub 后端
Spring Cloud Config Server 支持将 CredHub 作为配置属性的后端。你可以通过添加 Spring CredHub 依赖来启用此功能。
<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
<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 配置。可选。 |