2
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 5 years have passed since last update.

KeyVaultを使ったARMテンプレートへの機密情報の記載方法

Posted at

ARMテンプレートを使った時にどうしてもパスワードなどの機密情報を記載しなければいけない部分が出てくる。
そこでコードとして直接記載するのではなくKeyVaultを使ったパスワードを隠す方法を記載する。
テンプレートの実施方法としてAzure DevOpsのPipelineを使用する

必要なもの

  • KeyVault
  • Azure DevOps

実施

準備

まずはkey vaultに情報を入れておく必要があります。
すでに使ったことある方や公式のほうが詳しいと思いますので割愛します。
https://docs.microsoft.com/ja-jp/azure/key-vault/about-keys-secrets-and-certificates

これからの例ではSecretsを使った方法です。

Azure DevOpsからのアクセスを許可する必要があります。

ARM template

下記の記載は要点整理のためかなり端折っています。

ポイントはkeyvaultからの参照の仕方と呼び出し方です。

paramater.json

    "databasePassword": {
      "reference": {
        "keyVault": {
          "id": "/subscriptions/[subscriptionID]/resourceGroups/[resouce group name]/providers/Microsoft.KeyVault/vaults/[keyvault name]"
        },
        "secretName": "[keyvault secret name]"
      }
    }

template

{
	"parameters": {
		"databasePassword": {
			"type": "securestring"
		}
	},
	"resources": [
		{
			"name": "database",
			"type": "Microsoft.Sql/servers",
			"apiVersion": "2015-05-01-preview",
			"location": "[resourceGroup().location]",
			"tags": {},
			"properties": {
				"administratorLogin": "admin",
				"administratorLoginPassword": "[parameters('databasePassword')]",
				"version": "12.0"
			}
		}
	]
}

type を「secretring」としていますが「string」でも構いません
その場合、Azure portal上からは参照できてしまうのでご注意ください

Azure DevOps

ここでは「Builds」を使用しますが「Releses」でも同じことができると思います。
(未検証です。すみません)

最低限必要なジョブは下記の2つ
設定についてはほぼ選択式なので割愛します。
デフォルトで埋まっている部分に関しては変更なしです。

azureDevOpsBuild.png

まとめ

keyvaultと連携することでコード上には記載することなくリソースを構築することができます。
ただし、keyvault自体のセキュリティが緩いと元も子もないので不要な許可はしないようにしましょう

2
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
2
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?