はじめに
tegata v0.3.1 の文書
クラウドのアカウントなしで、手元の機械で 10 分ほど tegata を試します。シークレットを作り、それで雛形を埋め、1 つを入れ替えます。そのあと、同じ設定を Google Cloud Secret Manager に移します。
tegata の実行ファイルが要ります(インストール)。この例は組み込みのプロバイダーだけを使うので、tegata init は要りません。
examples/minimal を写して、その中で作業します。
cp -r examples/minimal /tmp/tegata-try && cd /tmp/tegata-trytegata.yaml には、シークレットをどこに置くか、誰が読むか、何を作るかを書きます。シークレットごとに readers を書きます。previous は、写すもとの値の読み手が読みます。
stores: main: local: dir: ./store # plain-text JSON files: for trying tegata only
identities: app: [serviceAccount:app@example.iam.gserviceaccount.com]
resources: session_key: provider: random # 32 random bytes config: { bytes: 32 } stores: main: - { name: SESSION_KEY, readers: [app] } previous: { name: PREVIOUS_SESSION_KEY } admin_password: provider: manual # you type it stores: main: - { name: ADMIN_PASSWORD, readers: [app] } mail: provider: value # a fixed, non-secret value config: { from: "Example <noreply@example.com>" } stores: main: - { output: from, name: MAIL_FROM, readers: [app] }templates/app/app.env は、app として動くサーバーが埋めるファイルです。tegata check app templates/app で、その中のすべての名前を app が読めることを確かめます。
SESSION_KEY=__SESSION_KEY__PREVIOUS_SESSION_KEY=__PREVIOUS_SESSION_KEY__ADMIN_PASSWORD_SHA256=__ADMIN_PASSWORD|sha256__MAIL_FROM=__MAIL_FROM__2. 確かめて、apply する
Section titled “2. 確かめて、apply する”$ tegata check app templates/appok$ tegata applycreated secret ADMIN_PASSWORDreaders of ADMIN_PASSWORD: serviceAccount:app@example.iam.gserviceaccount.comadmin_password: no value yet (put it with `tegata set admin_password`)created secret MAIL_FROMreaders of MAIL_FROM: serviceAccount:app@example.iam.gserviceaccount.comMAIL_FROM: version 1 (from mail)created secret SESSION_KEYreaders of SESSION_KEY: serviceAccount:app@example.iam.gserviceaccount.comcreated secret PREVIOUS_SESSION_KEYreaders of PREVIOUS_SESSION_KEY: serviceAccount:app@example.iam.gserviceaccount.comSESSION_KEY: version 1session_key: generation 1PREVIOUS_SESSION_KEY: version 1 (the value of SESSION_KEY)apply がランダムな鍵を作り、app のメンバーが 4 つのシークレットを読めるようにしました。manual のパスワードは、入れるのを待っています。
$ echo 'correct horse' | tegata set admin_passwordADMIN_PASSWORD: version 1admin_password: generation 1$ tegata statusadmin_password (manual) generation 1 ADMIN_PASSWORD v1 appmail (value) - MAIL_FROM v1 appsession_key (random) generation 1 SESSION_KEY v1 app PREVIOUS_SESSION_KEY v1 app3. 埋める
Section titled “3. 埋める”サーバーの上では、render が保存先から雛形を埋めます。YAML もプロバイダーも要りません。
$ tegata render --store-dir store templates/app outfilled 1 files$ cat out/app.envSESSION_KEY=3f9c…PREVIOUS_SESSION_KEY=3f9c…ADMIN_PASSWORD_SHA256=9c0f…MAIL_FROM=Example <noreply@example.com>out はモード 0700 で、app.env は 0600 で作られます。
4. 入れ替える
Section titled “4. 入れ替える”$ tegata rotate session_keySESSION_KEY: version 2session_key: generation 2$ tegata render --store-dir store templates/app outfilled 1 files$ tegata settle session_keyPREVIOUS_SESSION_KEY: version 2 (the value of SESSION_KEY)$ tegata prune session_keySESSION_KEY: disabled version 1session_key: pruned generation 1PREVIOUS_SESSION_KEY: disabled version 1rotate から settle までの間、SESSION_KEY と PREVIOUS_SESSION_KEY の両方を受け付けるサービスは、入れ替えの前に作った値でも動き続けます。値の種類ごとの手順はシークレットを入れ替えるにあります。
5. Secret Manager に移す
Section titled “5. Secret Manager に移す”-
保存先を替え、
appのメンバーを、render するサーバーのサービスアカウントにします。stores:main:gcp:project: my-projectlocation: us-central1identities:app: [serviceAccount:app-vm@my-project.iam.gserviceaccount.com] -
そのプロジェクトの Secret Manager を管理できるアカウントで
tegata applyを流します(gcloudのログインを使います)。 -
サーバーの上で
tegata render templates/app /etc/appを流します。Compute Engine の VM なら、プロジェクトと認証情報は VM から取ります。ほかの場所では--project my-projectを足し、サーバーのアイデンティティが認証できるようにしておきます。
- ほかのサービスのトークンをプロバイダーで作る(
tegata initが入れます)。 - 届け先で、シークレットを GitHub Actions に写す。
- すべてのキーとコマンド:設定のリファレンスとコマンドのリファレンス。