😀

アクセス権のない Azure Key Vault のシークレットに何があるか Azure REST API で確認してみ

に公開

例えば、アクセスポリシーや RBAC でアクセス権を付与されていない Azure Key Vault があったとします。下記のように、シークレットにアクセスすると「このコンテンツを表示する権限がありません。」と表示される状態です。

azure-keyvault-secret-01.png

当然 Azure CLI で下記のように実行すると AccessDenied と表示されます。

bash
$ az keyvault secret list --vault-name mnrlabo
Inner error: {
    "code": "AccessDenied"
}

Azure REST API でシークレットに何があるか確認

helloworld というシークレットが 1 つあることが確認できます。また、シークレットの値はアクセス権がないと表示できません。

bash
$ az rest --url "https://management.azure.com/subscriptions/25695fc8-000-0000-0000-f98a857adbe2/resourceGroups/mnrlabo-rg/providers/Microsoft.KeyVault/vaults/mnrlabo/secrets?api-version=2015-06-01"
{
  "value": [
    {
      "id": "/subscriptions/25695fc8-000-0000-0000-f98a857adbe2/resourceGroups/mnrlabo-rg/providers/Microsoft.KeyVault/vaults/mnrlabo/secrets/helloworld",
      "location": "japaneast",
      "name": "helloworld",
      "properties": {
        "attributes": {
          "created": 1673483266,
          "enabled": true,
          "exp": 7980681854,
          "nbf": 1673481854,
          "updated": 1673483266
        },
        "contentType": "application/x-pkcs12",
        "secretUri": "https://mnrlabo.vault.azure.net/secrets/helloworld",
        "secretUriWithVersion": "https://mnrlabo.vault.azure.net/secrets/helloworld/fceba66c23d24b9a93121bbec3f9ae99"
      },
      "type": "Microsoft.KeyVault/vaults/secrets"
    }
  ]
}

参考

https://learn.microsoft.com/ja-jp/rest/api/keyvault/keys/get-keys/get-keys?view=rest-keyvault-keys-7.4&tabs=HTTP

https://learn.microsoft.com/ja-jp/rest/api/keyvault/secrets/get-secrets/get-secrets?view=rest-keyvault-secrets-7.4&tabs=HTTP

Discussion