Skip to content

refactor(bootstrap): 秘密を値のファイルに入れ、versions.yaml を talos.sops.yaml に畳む - #636

Merged
5ym merged 1 commit into
mainfrom
bootstrap-inline-secrets
Oct 30, 2026
Merged

5ym merged 1 commit into
mainfrom
bootstrap-inline-secrets

Conversation

@5ym

@5ym 5ym commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

#635 の続き。bootstrap/ のファイルを部品ごとに 1 本へ寄せる。render.sh の生成物は前と 1 バイトも変わらない(cmp で確認)ので当て直しは要らない。

秘密を値のファイルに入れる

  • argocd-secret-values.sops.yaml → argocd-values.sops.yaml に、infisical-secret-values.sops.yaml → infisical-values.sops.yaml に入れた。
  • .sops.yaml の <name>-values.sops.yaml の規則で、秘密のキー(service.webhook.mattermost・githubAppPrivateKey・password・postgresPassword・ENCRYPTION_KEY・AUTH_SECRET・CLIENT_*_GITHUB_LOGIN・CF_DNS_API_TOKEN)の値だけを暗号化する。mac_only_encrypted: true なので、平文の部分は sops を通さずに直せる。
    • コメントは encrypted_regex に当たらないので平文のまま残る。
    • 試したこと: # version: と平文の値(server.insecure)を sed で書き換えても sops -d は通る。infisical と cert-manager も同じ。
  • infisical-secrets.sops.yaml は infisical-values.sops.yaml の 2 つめのドキュメントに、cert-manager-cloudflare-secret.sops.yaml は cert-manager-values.sops.yaml の 2 つめのドキュメントにした。render.sh が復号したあと --- で分け、今までと同じ名前の inlineManifest(infisical-secrets・cloudflare-secret)にする。
    • chart の extraObjects には入れなかった。そうすると Secret が chart の inlineManifest に移り、machine config が変わるため。
  • cilium は秘密が無いので cilium-values.yaml のまま。render.sh は <name>-values.sops.yaml があればそれを、無ければ <name>-values.yaml を読む。
  • CI(talos-boot)は ARGOCD_VALUES / INFISICAL_VALUES / CERT_MANAGER_VALUES に、ENC[…] を yq でダミーにしたファイルを丸ごと渡す。外に出すものを抜くのは前と同じ。
    • 抜くもの: argocd の extraObjects・通知先・鍵、infisical の SMTP の env。
    • infisical の Secret は前と同じく作り直す。yq の式は mikefarah/yq v4.54 で手元で試した。

versions.yaml を talos.sops.yaml に畳む

talos.sops.yaml の先頭のコメントにした。形は chart と同じ # renovate: / # version: で、schematic は # schematic:。

  • render.sh と talos-boot は、# renovate: の行の depName でその次の # version: を引く。
  • Renovate の customManager は talos.sops.yaml を見る。Talos のグループ規則(versioning: semver と allowedVersions)はそのまま当たる。

確かめたこと

  • render.sh の前後の controlplane.yaml を cmp で比べて同一(main の refactor(bootstrap): argocd/repos.yaml を bootstrap/argocd-repos.yaml へ #635 の状態と比べた)。CI と同じ上書きでも通り、SMTP と repo-creds が抜けることを見た。
  • Renovate の dry-run(lookup)の結果:
    • talos.sops.yaml から talos・kubernetes・gateway-api を拾う。versioning: semver が付いている。
    • <name>-values(.sops).yaml から cilium・cert-manager・argo-cd・infisical-standalone と、redis・infisical のイメージを拾う。infisical は 2 ドキュメントのファイルでも helm-values が読む。
    • renovate-config-validator --strict は通る。
  • 平文の秘密がコミットに入っていないことを grep で確認した。

🤖 Generated with Claude Code

https://claude.ai/code/session_01T9PbUfqG4pPxus99UeLiJs

- <name>-secret-values.sops.yaml を <name>-values.sops.yaml に入れる(argocd・infisical)。
  .sops.yaml の encrypted_regex で秘密のキーの値だけ暗号化し、mac_only_encrypted で
  平文の部分(Renovate が書き換える `# version:` も)を sops を通さず直せるようにする
- infisical-secrets.sops.yaml と cert-manager-cloudflare-secret.sops.yaml は、それぞれ
  infisical-values.sops.yaml と cert-manager-values.sops.yaml の 2 つめのドキュメントにする。
  render.sh が `---` で分けて今までと同じ名前の inlineManifest にする(chart の extraObjects に
  入れると machine config が変わるので使わない)
- versions.yaml の版と schematic を talos.sops.yaml の先頭のコメントにする(chart と同じ
  `# renovate:` / `# version:` の形)。render.sh・talos-boot・Renovate・文書をそこに向ける

render.sh の生成物は前と 1 バイトも変わらないので、当て直しは要らない。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T9PbUfqG4pPxus99UeLiJs
@claude

claude Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Claude finished @5ym's task in 33s —— View job


レビュー結果

結論: 差し戻すほどの問題は見つかりませんでした。

実際に確認した点:

  • .sops.yaml の encrypted_regex の対象キー(service.webhook.mattermost・githubAppPrivateKey・password・postgresPassword・ENCRYPTION_KEY・AUTH_SECRET・CLIENT_*_GITHUB_LOGIN・CF_DNS_API_TOKEN)は、3 つの *-values.sops.yaml の秘密の値と一致していました。どの値も ENC[...] になっていて、平文の秘密は見当たりません。
  • 複数ドキュメントのファイルでは、どのドキュメントにも同じ sops: メタデータ(MAC も同じ)が付きます。これは SOPS の仕様どおりで、問題ではありません。
  • render.sh の decrypt は sops -d の失敗が set -e で止まる形になっています。cert-manager-secret.yaml / infisical-secret.yaml が無いときも、inline … < のリダイレクト失敗で止まります。暗号文の残りも検査しています。
  • CI(talos-boot.yml)で抜く対象は、notifications.notifiers(通知先)、githubAppPrivateKey、infisical の SMTP_* の env で、値ファイルの中身と合っています。ENC[ の残り検査もあります。
  • tver は $NF == depName で引きます。talos.sops.yaml の # renovate: 行は depName= が末尾にあるので正しく引けます。render.sh と CI の読み方も同一です。
  • renovate.json の managerFilePatterns は talos.sops.yaml と -values(.sops).yaml を拾い、versions.yaml の参照も残っていません。

要確認(指摘ではなく運用上の注意)

  • .sops.yaml の encrypted_regex は、-values.sops.yaml 全体で共通です。今後 password 以外の名前で秘密を足すと、規則に追記しない限り平文でコミットされます。コメントで注意喚起はされていますが、ENC[ が入っているかをコミット前にチェックする仕組みは無さそうです。必須ではありませんが、検討の余地があります。
  • 生成物が cmp で同一という検証は、私の環境では復号鍵が無いため再現していません。PR の記述を信頼しています。

テストは、このリポジトリに単体テストの枠組みは無く、cmp の比較と CI(talos-boot)での検証が代わりになっています。変更の性質上、これで妥当だと思います。

@5ym
5ym merged commit 5453252 into main Oct 30, 2026
7 of 8 checks passed
@5ym
5ym deleted the bootstrap-inline-secrets branch October 30, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant