最新の安定バージョンについては、Spring Cloud Config 5.0.4 を使用してください! |
Google シークレットマネージャーバックエンド
Spring Cloud Config サーバーは Google Cloud Secret Manager を EnvironmentRepository として使用できます。秘密情報は PropertySource として公開され、そのエントリは秘密ペイロードから構築されます。
バックエンドを有効にする
以下のすべての条件が満たされた場合、リポジトリは登録されます。
Spring プロファイル
secret-managerはアクティブです。com.google.cloud.secretmanager.v1.SecretManagerServiceClientはクラスパス上にあります (通常はgoogle-cloud-secretmanagerを追加することによって)。
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-secretmanager</artifactId>
</dependency>spring-cloud-config-server をオプションの Google ライブラリなしで使用する場合は、ビルドに必要なアーティファクトを明示的に追加してください。以下で説明する権限チェックは Cloud Resource Manager API を使用します。この動作に依存する場合は、google-api-services-cloudresourcemanager と google-auth-library-oauth2-http を含めてください。
spring:
profiles:
active: secret-manager
cloud:
config:
server:
gcp-secret-manager:
order: 0
application-label: application
profile-label: profile
service-account: /path/to/service-account.json
token-mandatory: true
version: 1 構成プロパティは spring.cloud.config.server.gcp-secret-manager にバインドされています。
| プロパティ | デフォルト | 説明 |
|---|---|---|
| 他の環境リポジトリと同様 | 複合リポジトリ( |
|
| 構成サーバー |
|
| シークレットマネージャーのラベルキーは、各アクティブプロファイルを照合するために使用されます(マッピングアプリケーションとプロファイルを参照)。 |
| 空の | Google クラウドサービスアカウントの JSON キーファイルへのパス。設定されている場合、Secret Manager クライアントはこの認証情報を使用します。設定されていない場合、クライアントは Application Default Credentials (たとえば、Google Compute Engine 上のメタデータサーバー)を使用します。 |
|
|
|
| 空の |
|
| 空の | Fallback Google Cloud project when |
|
| API アクセス戦略バージョン( |
マッピングアプリケーションとプロファイル
サーバーは、Google クラウドプロジェクト(Google クラウドプロジェクトの解決を参照)内のシークレットを一覧表示し、各構成クライアントリクエストに対してフィルタリングします。
Label-based matching (default) : 特定の
{application}およびプロファイルに対して、シークレットマネージャーのラベルが、設定済みのキー (application-labelおよびprofile-label) 上で大文字小文字を区別せずに一致する場合に、シークレットが含まれます。シークレットにラベルがない場合、コードはそれをそれぞれデフォルトの文字列applicationまたはprofile(プロパティ名と同じキー) として扱うため、ラベルのないシークレットはこれらのデフォルト値に準拠します。Prefix-based matching : HTTP リクエストに空でない
X-Secret-Prefixヘッダーが含まれている場合、ショートネーム(projects/…/secrets/の後のセグメント)がそのプレフィックスで始まるシークレットも含まれます。プレフィックスはプロパティキーから削除されます。このパスは、同じループ内でラベルフィルタリングロジックと組み合わせることができます(GoogleSecretManagerEnvironmentRepositoryを参照)。
リポジトリは、他のバックエンドと同様に、default プロファイルが他のプロファイルよりも先に考慮されるように常に保証します。クライアントが最初に default を送信しない場合、サーバーはそれを先頭に追加します。
一致するシークレットごとに、プロパティ値は 最新の有効化されたシークレットバージョンのペイロードになります。「最新」は、数値バージョン ID を比較することによって決定されます(シークレットマネージャーの「最新」エイリアスではありません)。
プロパティソースの名前は gsm:{application}-{profile} です。
Config Server {label} パスセグメントは API で受け入れられますが、このバックエンドではシークレットの選択には使用されません。バージョン選択は、上記で説明したシークレットバージョンに基づいて行われます。
Google クラウドプロジェクトの解決
Secret Manager API 呼び出しはプロジェクト ID にスコープされます。解決は、GoogleSecretManagerV1AccessStrategy 内部の GcpProjectResolutionSupport によって、現在の HTTP リクエストヘッダー、オプションのメタデータ、構成情報を使用して実行されます。
プロジェクトは以下の順序で選ばれます。
Non-empty
X-Project-IDheader(トリミング後)。token-mandatoryがtrueの場合、ヘッダー値は許可リストのチェックなしで受け入れられ、そのプロジェクトへのアクセスは Optional permission check (token-mandatory) によって強制されます。token-mandatoryがfalseの場合、プロジェクトはallowed-project-idsに存在する必要があります。このリストが空の場合、クライアントから提供されたプロジェクト ID は許可されません。GCE metadata : GET
metadata.google.internal/computeMetadata/v1/project/project-id (英語)、ヘッダーMetadata-Flavor: Google。インスタンスのプロジェクトを使用します(クライアントはこのパスを介して操作できません)。許可リストは適用されません。project-idプロパティ :spring.cloud.config.server.gcp-secret-manager.project-id, when set and metadata did not yield a project. Server-admin configuration only; the allow-list is not applied.
If no project can be resolved, getSecrets() behaves as if there were no secrets (no GSM-backed entries), and checkRemotePermissions() returns false when token-mandatory is true — so the repository contributes no GSM PropertySource for that request, consistent with a failed permission check.
Setting token-mandatory to false allows clients to load secrets from any project in the allowed-project-ids list. It is recommended you never set token-mandatory to false so the Optional permission check (token-mandatory) is performed before loading any secrets. |
With token-mandatory false, clients that rely on X-Project-ID must list allowed project ID(s) in allowed-project-ids. |
Credentials for listing and reading secrets
Listing secrets and accessing secret values uses SecretManagerServiceClient only:
With
service-accountset: credentials from that JSON file.Without it: Application Default Credentials.
The OAuth access token in X-Config-Token is not passed to the Secret Manager client. Those credentials are always the server ’ s (or the key file ’ s), independent of the client token.
Optional permission check (token-mandatory)
When token-mandatory is true (default), before loading any secrets the server calls checkRemotePermissions() on the access strategy. That method resolves the target project the same way as Secret Manager calls (see Google クラウドプロジェクトの解決 ), then:
Reads the access token from the
X-Config-TokenHTTP header (required for this check; a missing or invalid header causes the check to fail).If the project could not be resolved, the check fails.
Uses the Cloud Resource Manager REST API
projects.testIamPermissionsfor that project with the permissionsecretmanager.versions.access.If that permission is reported for the token, the check passes and secrets are loaded. If not, or if the API call fails, the check fails and no GSM-backed property sources are added for that request.
So the token in X-Config-Token acts as a gate for whether GSM data is returned when token-mandatory is true, while reading secrets still uses the server ’ s Secret Manager credentials . The principal that passes IAM testing and the principal used for Secret Manager API calls can differ.
When token-mandatory is false, this remote check is not performed and secrets are loaded solely subject to server credentials and Secret Manager data access (subject to project resolution and allowed-project-ids when using X-Project-ID).
HTTP ヘッダー (Config Client to Config Server)
| ヘッダー | Required when | 目的 |
|---|---|---|
|
|
Bearer-style access token used only for Cloud Resource Manager |
| Recommended when not running on GCP with metadata | Google Cloud project ID for Secret Manager and IAM checks. |
| オプション | Restricts which secrets contribute properties when matching by name prefix (see マッピングアプリケーションとプロファイル ). |
Header names are case-insensitive per HTTP; the implementation uses X-Config-Token、X-Project-ID、X-Secret-Prefix.