.gitlocal:Gitでの機密ファイルのデフォルト無視を提案する新概念
Andrej Karpathyは、機密情報を扱うCLIツールが.gitignoreへの依存を避け、.gitlocalファイルや命名規則を通じてGitに「無視」を宣言する標準的な仕組み(.gitlocal)の提案とProof of Concept実装を発表した。
キーポイント
既存のGit無視メカニズムの問題点
.gitignoreや--skip-worktreeなどの既存機能はツール作者ではなくユーザー側が設定する必要があり、新しいツールの普及に伴う漏洩リスクを軽減できない。
.gitlocalという提案と実装
ツールディレクトリ内の.markerファイル、.local.json拡張子、またはファイル先頭のコメントをGitが無視するよう定義する「.gitlocal」の概念と、pre-commitフックを用いたPoC実装を示した。
セキュリティリスクとトレードオフ
機密情報の漏洩によるトークン失効や監査コストが、見えない動作への懸念を上回ると判断し、ツール作者が責任を持って適用できる標準化を推進している。
影響分析・編集コメントを表示
影響分析
この提案は、開発者体験(DX)とセキュリティのバランスを再定義する可能性がある。Gitエコシステムにおいて、ツール作者がユーザー環境に干渉せずに機密ファイルを安全に管理できる標準プロトコルが確立されれば、多数のオープンソースツールにおける機密漏洩事故を未然に防げる。ただし、Gitコアへの取り込みには維持者間の合意形成が必要であり、当面はコミュニティ主導の慣習として定着するかが鍵となる。
編集コメント
Karpathy氏によるこの提案は、実務レベルでの機密管理の課題を鋭く指摘しています。Gitのコア機能変更という大掛かりなアプローチではなく、フックと命名規則による「事実上の標準」を先取りする戦略は賢明です。
私は、ドットフォルダに機密情報を記録する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日報で今日の重要ニュースをまとめ読み