LoginSignup
21
13

More than 5 years have passed since last update.

kubesecを使ってkubernetesのsecret定義を暗号化する

Posted at

https://github.com/shyiko/kubesec を使ってみたので調べたことをメモ。

kubesecとは

kubernetesのsecret.ymlの管理ツール。(secret.ymlはsecretリソースの定義ファイル)
secret.ymlのデータ構造を保ったまま、必要なところだけをGoogle Cloud KMSAWS KMSなどを使って暗号化してくれる。
ついでに、base64のエンコードもやってくれるので便利。

詳しい内容はkubesecのreadmeを要参照。

kubesecを使う目的

  • dbのcredentialなどを平文のままgitにcommitすることを避ける
  • そのために必要な手続きがkubesecを使うと多少楽にする

使用の流れ

事前準備

Google Cloud KMSAWS KMSなどでkeyを作成しておく

開発時

  1. kubesecのインストール
  2. credentialなどをkubesecで暗号化(事前に作成したkeyを使う)しsecret.ymlに追加
  3. git commit

デプロイ時

  1. デプロイ用のサーバーでkubesecのインストール
  2. kubesecでdecrypt
  3. kubectl applyでsecretリソースを作成

基本的なコマンド

インストール

mac

brew install shyiko/kubesec/kubesec

linux

curl -sSL https://github.com/shyiko/kubesec/releases/download/0.9.2/kubesec-0.9.2-linux-amd64 \
  -o kubesec && chmod a+x kubesec

Encryption

kubesec encrypt --key=gcp:<resource-id of Google Cloud KMS key> secret.yml --cleartext

Google Cloud KMSを使う場合は上記のようにgcp:を付ける。
--cleartextを付けるとbase64のencodeをしてくれる。

Modification(secret dataの追加)

kubesec patch -i secret.yml --data my_key=secret_value

Decryption

kubesec decrypt -i secret.yml

こちらも--cleartextを付けるとbase64のdecodeをしてくれるが、
基本的にはdecryptした後はそのままkubectl apply -f secret.ymlすることになるので不要な場合が多い。

21
13
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
21
13