1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Key Vaultからシークレットの値を取得する

Last updated at Posted at 2024-03-16

環境

Azure Virtual Machine - CentOS 8.2
Azure Cli - 2.38.1

今回はVMから取得するが、ロールが割り当てられた状態であればどこからでも可能。

前提

  • Key Vaultのシークレットが取得できるようにロールが設定できていること
  • キーコンテナーシークレットユーザー があればよい

image.png

az keyvault secret show コマンド

az keyvault secret show --vault-name <Key Vault名> --name <シークレット名> [--output table]

オプション 設定値
--vault-name Key Vaultのリソース名
--name シークレットの名前
--output table 省略可能。指定するとテーブル形式で出力される
  • すべてのシークレットを一度に取得するオプションは存在しない模様
  • もしやるなら、az keyvault secret list でシークレットの一覧を取得してからlistの数だけコマンドを実行すればよい

実行例

今回は、my-key-dev-001SECRET_PASSWORD を取得してみる。

# サインイン
$ az login --identity --username xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxx
{
  "attributes": {
    "created": "2024-03-16T06:33:18+00:00",
    ...
    }
}

# 取得
$ az keyvault secret show --vault-name my-key-dev-001 --name SECRET_PASSWORD
{
  "attributes": {
    "created": "2024-03-16T06:33:18+00:00",
    "enabled": true,
    "expires": null,
    "notBefore": null,
    "recoveryLevel": "CustomizedRecoverable+Purgeable",
    "updated": "2024-03-16T06:33:18+00:00"
  },
  "contentType": null,
  "id": "https://my-key-dev-001.vault.azure.net/secrets/SECRET_PASSWORD/xxxxxxxxxxxxxxxxxxxxxxxxx",
  "kid": null,
  "managed": null,
  "name": "SECRET_PASSWORD",
  "tags": {},
  "value": "Password-Value"
}

# テーブルにするとこのように出力される
$ az keyvault secret show --vault-name my-key-dev-001 --name SECRET_PASSWORD --output table
Name             Value
---------------  --------------
SECRET_PASSWORD  Password-Value

シークレットの設定値 Password-Value が取得できた。

(補足)ポータルからも参照は可能

image.png

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?