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?

Codespacesからlocal移行時にcredentials.yml.encを復号できなくなった

Last updated at Posted at 2026-01-04

TL;DR

経緯

開発環境をCodespacesからlocalに移行したときに、config/master.keyをメモせずにCodespacesを削除してしまい、credentials.yml.encを復号できなくなった。

  1. localでリポジトリをclone
  2. Codespacesを削除
    としたところ、master.keyは.gitignoreに含まれていたため管理されておらず、master.keyがわからない状態になってしまった。

解決方法

rails credentials:editを実行し、新しいmaster.keyを生成

詳細

環境

  • Rails 8.0.2

credentials.yml.encとmaster.keyの関係

credentials.yml.enc

  • 暗号化された機密情報(APIキー, secret_key_baseなど)を保管するファイル
  • rails newで新しいアプリを作成時に自動的にconfig/credentials.yml.encconfig/master.keyが生成される
  • EDITOR=vim rails credentials:editなどで、暗号化して保存したいtokenなどを追加していく

master.key

  • credentials.yml.encを復号するための鍵

master.keyは.gitignoreに含まれる

  • master.keyは機密情報を復号できる鍵のため、GitHubには公開しない
  • チーム開発時は別の方法(パスワードマネージャなど)で共有

master.keyがない場合の対処

  • 古いcredentials.yml.encを削除してからrails credentials:editを実行すると、新しいmaster.keycredentials.yml.encが生成される
    • 新しいcredentials.yml.encにもう一度tokenなどを追加する必要がある

参考

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?