【Pulumi】Pulumi ~ パスフレーズ省略を考える ~

■ はじめに

小ネタ。

https://dk521123.hatenablog.com/entry/2022/03/11/184041

で、pulumi up などした際に、いちいち、以下の文言
~~~~
Enter your passphrase to unlock config/secrets
  (set PULUMI_CONFIG_PASSPHRASE or PULUMI_CONFIG_PASSPHRASE_FILE to remember):
~~~~
がでてきて、パスフレーズの入力を促してきてうっとしいので、
その対策を調べてみた。

目次

【1】対策1:環境変数 PULUMI_CONFIG_PASSPHRASE
【2】対策2:Secrets providerを変更する
 1)サポートしているタイプ
 2)Secrets provider の変更
【3】補足:Pulumiにおける「Secrets」
 1)Secret (シークレット)とは?
 2)Secret の Config 設定

【1】対策1:環境変数 PULUMI_CONFIG_PASSPHRASE

* 環境変数 PULUMI_CONFIG_PASSPHRASE に
 パスフレーズをセットして置く
 => 文言に出ている通り。

環境変数 : PULUMI_CONFIG_PASSPHRASE_FILE
https://www.pulumi.com/docs/reference/cli/environment-variables/

PULUMI_CONFIG_PASSPHRASE_FILE="/tmp/passphrase.txt"

【2】対策2:Secrets providerを変更する

* シークレットプロバイダーを変更する

1)サポートしているタイプ

https://www.pulumi.com/docs/reference/cli/pulumi_stack_change-secrets-provider/#synopsis
https://www.pulumi.com/docs/intro/concepts/secrets/#available-encryption-providers

[1] default
[2] passphrase ... パスフレーズ
[3] awskms ... AWS KMS <= 今回、これを使ってみる
[4] azurekeyvault ... Azure Key Vault
[5] gcpkms ... Google Cloud Key Management Service (KMS)
[6] hashivault ... HashiCorp Vault Transit Secrets Engine

2)Secrets provider の変更

* Pulumiコマンド「pulumi stack change-secrets-provider」を実行

https://www.pulumi.com/blog/rotating-secret-providers/
コマンド例:AWS KMSへの変更

# KMSキー「alias/ExampleAlias」, Region「us-west-2」の場合
pulumi stack change-secrets-provider "awskms://alias/ExampleAlias?region=us-west-2"

https://www.pulumi.com/docs/intro/concepts/secrets/#aws-key-management-service-kms

【3】補足:Pulumiにおける「Secrets」

1)Secret (シークレット)とは?

* パスワードのような情報

公式サイト:「What Is a Secret?」より
https://www.pulumi.com/blog/keeping-your-secrets-secret/#what-is-a-secret

We’re going to define secrets as small, critical pieces of information.
シークレット(秘密文字) は、
小さく、極めて重要な情報として、定義します。
They’re no larger than a few KBs, and they’re necessary to run your infrastructure.
それらは、数KB程の大きさで、インフラを実行する際に必要になります
If they’re leaked, your infrastructure is compromised and bad things can happen.
もし、それらが欠けた場合、インフラは欠陥があり、悪い状況が発生するでしょう。
Some examples of secrets are passwords, API keys, and SSH keys.
シークレット の例として、パスワード、APIキーそしてSSHキーがある

2)Secret の Config 設定

# --secret を付ける
# pulumi config set --secret <key> <value>
$ pulumi config set --secret token xxxxx

# 設定を確認( [secret]と表示)
$ pulumi config
KEY    VALUE
token  [secret]

参考文献

https://dev.classmethod.jp/articles/pulumi-tips/
https://tech.guitarrapc.com/entry/2019/12/10/000000

関連記事

Pulumi ~ 基礎知識編 ~
https://dk521123.hatenablog.com/entry/2021/10/23/025230
Pulumi ~ 環境設定編 ~
https://dk521123.hatenablog.com/entry/2022/01/10/155206
Pulumi ~ 入門編 / Hello World in Local/k8s
https://dk521123.hatenablog.com/entry/2022/03/07/233752
Pulumi ~ 入門編 / Hello World in AWS
https://dk521123.hatenablog.com/entry/2022/03/11/184041
Pulumi ~ 基本編 / CLI
https://dk521123.hatenablog.com/entry/2021/10/25/215508
Pulumi ~ 基本編 / Config ~
https://dk521123.hatenablog.com/entry/2022/03/15/224217
Pulumi ~ 基本編 / Logging ~
https://dk521123.hatenablog.com/entry/2022/03/04/111618
Pulumi ~ 基本編 / Component ~
https://dk521123.hatenablog.com/entry/2022/03/05/100153
Pulumi ~ AWS S3 / KMS のデプロイ ~
https://dk521123.hatenablog.com/entry/2022/03/03/095415
Pulumi ~ AWS Glue のデプロイ ~
https://dk521123.hatenablog.com/entry/2022/03/02/122037
Pulumi に関するトラブル
https://dk521123.hatenablog.com/entry/2022/01/11/105319
KubernetesWindows / 環境構築編 ~
https://dk521123.hatenablog.com/entry/2020/05/01/000000
Kubernetes ~ 基本編 / kubectlコマンド ~
https://dk521123.hatenablog.com/entry/2022/01/12/110555
Node.js ~ 環境構築編 ~
https://dk521123.hatenablog.com/entry/2021/11/06/000000