LoginSignup
0
0

More than 1 year has passed since last update.

Azure AppConfigurationでユーザー割り当てマネージドIDにアクセスするのに苦戦した話

Posted at

前回(SpringBootのProfileとAzure AppConfigurationの組み合わせでハマった話)の続きでさらに苦戦した(といってもそこまででもないけど)ので覚書を。
地味な罠多すぎ。

環境

  • SpringBoot 2.6+
  • Java 11
  • Azure Configuration
  • Spring Cloud Azure App Configuration version 2.5.0
  • ユーザー割り当てマネージドID を作成する(もしくは権限がある人に作ってもらう)

やること

  • 作成したユーザー割り当てマネージドIDを AppConfiguration の ロール割当の追加から、マネージドIDを選択して、App Configuration データ閲覧者 ロールを追加する
  • AppConfiguration の中から KeyVault の参照もしているようであれば、KeyVault のアクセスポリシーに ユーザー割り当てマネージドID を追加する必要がある
    • ないとAccessDenied になる
  • bootstrap-${profile}.yml の記述方法を以下にする
spring:
  cloud:
    azure:
      appconfiguration:
        managed-identity:
          client-id: <ユーザー割り当てマネージドID のclient id>
        stores:
          - endpoint: https://<AppConfiguration の Endpoint>-conf.azconfig.io
            selects:
              - label-filter: <任意のラベル>

補足

罠のハマりポイントとしては、Azure側のドキュメントのユーザー割り当てマネージドID のclient idの指定するプロパティが間違ってるっぽいところなんですよね。。
マネージド ID の使用

注意
ユーザー割り当てマネージド ID プロパティ spring.cloud.azure.appconfiguration.stores[0].managed-identity.client-id を使用する場合、ManagedIdentityCredential の作成時に必ず clientId を指定してください。

これに関しては、Spring Cloud Azureの公式のほうが正解です。
5.2. User Assigned Identity

spring.cloud.azure.appconfiguration.managed-identity.client-id= <your client id>
spring.cloud.azure.appconfiguration.stores[0].endpoint= <URI of your Configuration Store>

全然違うやんけ。
もしかしたらSpring側がバージョンアップとかで変わった可能性はあるかもしれないですが。

雑感

yamlで書いてたんでインデント間違ってるのかとか色々やりましたが、結局は公式をよく読みましょうってところですね。SpringとAzureのドキュメントは少ないし、ググってもあんまり出て来ないし、だいたい英語で辛いところではありますが。

参考

Spring Cloud Azure App Configuration

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0