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

はじめに

HashiCorp Vaultは、機密情報の安全な保存、アクセス制御、秘密管理を行うためのツールです。今回は、Vaultを使ってキーバリューの読み書きを試してみます。

前回の記事:

Vaultにログインする

まず、Vaultにログインします。以下のコマンドを使用します。

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

ログイン時には、トークンを入力する必要があります。以下のメッセージが表示されればログイン成功です。

Token (will be hidden):
Success! You are now authenticated. The token information displayed below
is already stored in the token helper. You do NOT need to run "vault login"
again. Future Vault requests will automatically use this token.

Key                  Value
---                  -----
token                hvs.cUc2WCAxO9JrYScSzJc2wbwo
token_accessor       YGSJU6WSEXgPnU6T3pMj7tms
token_duration       ∞
token_renewable      false
token_policies       ["root"]
identity_policies    []
policies             ["root"]

キーバリューの書き込み

次に、Vaultにキーバリューのペアを保存します。以下のコマンドを使用します。

vault kv put -mount=secret hello foo=world

このコマンドにより、helloというパスにfoo=worldというキーバリューのペアが保存されます。以下のようなメッセージが表示されます。

== Secret Path ==
secret/data/hello

======= Metadata =======
Key                Value
---                -----
created_time       2024-07-09T08:01:44.354577Z
custom_metadata    <nil>
deletion_time      n/a
destroyed          false
version            1

また、ブラウザでhttp://127.0.0.1:8200/ui/vault/secrets/secret/kv/listにアクセスすると、以下のように保存されたデータを確認できます。

スクリーンショット 2024-07-09 17.03.24.png

スクリーンショット 2024-07-09 17.03.45.png

キーバリューの読み取り

最後に、Vaultから保存したキーバリューのペアを読み取ります。以下のコマンドを使用します。

vault kv get -mount=secret hello

このコマンドにより、helloというパスに保存されたデータが表示されます。

== Secret Path ==
secret/data/hello

======= Metadata =======
Key                Value
---                -----
created_time       2024-07-09T08:01:44.354577Z
custom_metadata    <nil>
deletion_time      n/a
destroyed          false
version            1

=== Data ===
Key    Value
---    -----
foo    world

まとめ

今回は、HashiCorp Vaultを使ってキーバリューの読み書きを行う方法を紹介しました。Vaultを使用することで、機密情報を安全に管理することができます。詳細な手順については、HashiCorp Vaultの公式ドキュメントも参照してください。

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