.gitlocal:Gitでの機密ファイルのデフォルト無視を提案する新概念
本文の状態
日本語全文を表示中
詳細モードで約3分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Andrej Karpathy 厳選
著者はCLIツールの機密情報を.gitフォルダに保存する際、意図せずGitにコミットされる問題を解決するため、.gitlocalファイルや特定の命名規則により、ツールビルダーがファイルをデフォルトで無視できるようにする提案を行った。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
私は、ドットフォルダに機密情報を記録するCLIツールを開発しており、そのフォルダが誤ってgitにコミットされないようにするためのベストプラクティスを探していました。驚いたことに、gitはツール開発者が「このファイルはコミットすべきでない」と宣言する方法を、実際には提供していなかったのです。そこで私は考えました。もし、ドットフォルダ内に置くだけで、あるいはファイルの先頭に一行追加するだけで、あるいは特定の命名規則を使うだけで、gitがデフォルトでそのファイルを無視してくれるような仕組みがあればどうだろうか、と。
現在、ツール作者ができる最善の方法は、.gitignoreに行を一つ追加することです。
Gitの既存の無視メカニズムはすべて、ツール以外の誰か(ユーザー)が行動を起こす必要があります。.gitignore
--assume-unchanged
--skip-worktree
.git/info/exclude
.sometool/config.json
.sometool/credentials.json
credentials.json
機密ファイルを書き込むツールは通常、独自の設定ディレクトリにファイルを書き込むため、ディレクトリマーカーがあればほとんどのケースをカバーできます。スタンドアロンファイルを書き込み、かつファイル名を制御できるツールは、.local.jsonという拡張子を利用できます。
.sometool/credentials.local.json
.sometool/credentials.json
新しいツールは日々リリースされていますが、その作者は現在、ユーザーの.gitignoreを変更するか、ユーザー自身に追加してもらうよう依頼するかの選択を迫られています。
ツールの動作を変えるマーカーファイルという発想は目新しいものではありません。Androidの.nomediaファイルは、メディアスキャナーにそのディレクトリをスキップするよう指示します。rsyncには--exclude-if-presentオプションがあります。
明らかな反論は、不可視の挙動という点です。自身の追跡を抑制するファイルは、ユーザーを驚かせる可能性があります。しかし私は、秘密漏洩問題の深刻さが、その懸念を上回る段階に来ていると考えます。GitHubは年間数百万ものトークンを失効させており、それは検知できたものに過ぎません。セマンティクス(動作規則)を厳密に定義すれば、予期せぬ事態は避けられます。例えば.gitlocalファイルは、git check-ignoreコマンドで問い合わせ可能であるべきです。
この機能をgit本体に組み込むには、gitメーリングリストを通じてパッチを提出し、メンテナーにコア機能として相応しいと納得してもらう必要があり、そのハードルは高いものです。そこで当面、私は3つの規約(マーカーファイル、ファイル拡張子、先頭行コメント)をすべてチェックする概念実証のpre-commitフックを構築しました。gitが自動的に認識してくれる体験は失われますが、ツール作者は今すぐこの規約を使い始め、本体への提案の根拠となる実績を積むことができます。これは、空のディレクトリをコミット可能にする.gitkeepファイルが普及した経緯とほぼ同じです。
確かに、増え続けるドットファイルの一つにまた加わることになります。しかし、秘密が一つ漏れるごとに、認証情報の更新や監査済みアクセスログの調査が必要となり、時にはさらに深刻な事態を招きます。ツールの設定ディレクトリに空のマーカーファイルを一つ置くことは、特に、どのファイルが機密であるかを正確に把握していながら、それを防ぐ有効な手段を持たない開発者が「今まさに」書いているツールにとっては、合理的な代償と言えるでしょう。
原文を表示
I was building a CLI tool that records sensitive info in a dot folder, and went looking for best practices to avoid those folders being accidentally committed to git. To my surprise, git doesn’t really provide a way for tool builders to declare that their files shouldn’t be committed. That got me thinking: what if there was a file you could drop in your dot folder, or a comment you could add to the top of a file, or a naming convention you could use, that git would ignore by default?
Today, the best a tool author can do is append a line to .gitignore
Git’s existing ignore mechanisms all require someone other than the tool to act. .gitignore
--assume-unchanged
--skip-worktree
.git/info/exclude
.sometool/config.json
.sometool/credentials.json
credentials.json
Tools that write sensitive files usually write them into their own config directory, so the directory marker covers most cases. A tool that writes standalone files and controls the filename could use a .local.json
.sometool/credentials.local.json
.sometool/credentials.json
New tools ship all the time, and their authors currently have to choose between modifying the user’s .gitignore
The idea of a marker file that changes tool behavior isn’t new. Android’s .nomedia
--exclude-if-present
The obvious objection is invisible behavior: a file that suppresses its own tracking could surprise people. I think the scale of the secret-leaking problem has outgrown that concern. GitHub is revoking millions of tokens a year, and that’s just the ones they can detect. The semantics can be tight enough to avoid surprises: .gitlocal
git check-ignore
Getting this into git itself means a patch through the git mailing list and convincing the maintainers it belongs in core, a high bar. In the meantime, I built a proof of concept pre-commit hook that checks for all three conventions: marker files, file extensions, and first-line comments. You lose the experience where git just knows, but tool authors could start using the convention today and build an evidence base for a core proposal. That’s more or less how .gitkeep
Sure, another dotfile in the growing pile. But every leaked secret means rotated credentials and audited access logs, sometimes worse. An empty marker file in a tool’s config directory seems like a reasonable tradeoff, especially for tools being written right now by authors who know exactly which files are sensitive and have no good way to act on that.
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み