てくなべ (tekunabe)

ansible / network automation / 学習メモ

HashiCorp Vault によるシークレットの登録と確認を気軽に試してみた

はじめに

Software Design 2022年4月号で始まった連載「HashiCorp Vaultではじめるシークレット管理」を読んで、HashiCorp Vault(以下 Vault)に興味を持ちました。

他、HashiCorp Learn の Vualt のコンテンツも参照してみました。

あくまでお試しレベルですが、インストールからシークレットの登録、確認までやってみたことをまとめます。

インストール

ドキュメントに掲載されていた、yum コマンドによるインストールを行いました。

$ sudo yum install -y yum-utils
$ sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
$ sudo yum -y install vault

インストールできたら、バージョンの確認をします。今回はこちらです。

$ vault --version
Vault v1.10.0 (7738ec5d0d6f5bf94a809ee0f6ff0142cfa525a6)

起動・接続準備

簡易的な、開発モードでサーバーを起動します。

$ vault server -dev
==> Vault server configuration:
...(略)...
WARNING! dev mode is enabled! In this mode, Vault runs entirely in-memory
and starts unsealed with a single unseal key. The root token is already
authenticated to the CLI, so you can immediately begin using Vault.

You may need to set the following environment variable:

    $ export VAULT_ADDR='http://127.0.0.1:8200'

The unseal key and root token are displayed below in case you want to
seal/unseal the Vault or re-authenticate.

Unseal Key: dummyxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Root Token: hvs.dummyxxxxxxxxx

Development mode should NOT be used in production installations!

サーバーを起動したターミナルはそのままにして、別のターミナルを開きます。

接続の準備として、サーバーへの接続先を環境変数に設定します。

export VAULT_ADDR='http://127.0.0.1:8200'

今回は、サーバーもクライアントも同じマシンの上です。

参考 Starting the Server | Vault | HashiCorp Developer

シークレットの追加

さっそく kv シークレットエンジンを使ってシークレットを登録します。

今回は secret/mypassword 内に password の値として p@ssw0rd を登録します。

$ vault kv put secret/mypassword password=p@ssw0rd
===== Secret Path =====
secret/data/mypassword

======= Metadata =======
Key                Value
---                -----
created_time       2022-04-07T13:34:41.03484313Z
custom_metadata    <nil>
deletion_time      n/a
destroyed          false
version            1

参考 Your First Secret | Vault | HashiCorp Developer

シークレットの確認

登録できたことを vault kv get で確認します。

$ vault kv get secret/mypassword
===== Secret Path =====
secret/data/mypassword

======= Metadata =======
Key                Value
---                -----
created_time       2022-04-07T13:34:41.03484313Z
custom_metadata    <nil>
deletion_time      n/a
destroyed          false
version            1

====== Data ======
Key         Value
---         -----
password    p@ssw0rd

password の値として p@ssw0rd が登録されていることが確認できました。

参考 Your First Secret | Vault | HashiCorp Developer

おわりに

かんたんですが Vault で試したことをまとめました。おそらくまだ Vault が持っている機能のうちのほんの少しだけだと思います。

Software Design での連載の次の記事も楽しみです。

このブログととしては別途、Ansible からシークレットを呼び出す方法を書きたいと思います。

[追記]

tekunabe.hatenablog.jp