Skip to content

GitHub 認証・署名を Secure Enclave SSH キーに移行 - #56

Closed
thinceller-hermes wants to merge 1 commit into
masterfrom
hermes/secure-enclave-github-ssh
Closed

GitHub 認証・署名を Secure Enclave SSH キーに移行#56
thinceller-hermes wants to merge 1 commit into
masterfrom
hermes/secure-enclave-github-ssh

Conversation

@thinceller-hermes

Copy link
Copy Markdown
Collaborator

概要

Claude Code のリモートコントロール中に 1Password SSH エージェントの生体認証プロンプトが操作できなくて作業が止まる問題を解決するため、GitHub への push 認証と commit 署名を macOS Secure Enclave に格納した SSH キーに移行する。

変更点

  • home-manager/programs/git/default.nix
    • user.signingkey を 1Password の公開鍵文字列から ~/.ssh/id_github_se へ変更
    • gpg.ssh.program~/.local/bin/ssh-sign ラッパースクリプトに変更
    • ssh-sign スクリプトを ~/.local/bin に配置(SSH_SK_PROVIDER 設定済み)
  • home-manager/programs/ssh/default.nix
    • Host github.comIdentityFile ~/.ssh/id_github_se を使用し、IdentityAgent none で 1Password agent を無効化
  • home-manager/programs/fish/default.nix
    • SSH_SK_PROVIDER=/usr/lib/ssh-keychain.dylib をセッション変数に設定

Mac 上での事前作業(必須)

各 Mac で以下を実行して、Secure Enclave 内に SSH キーを生成し、GitHub に登録する必要がある。

# 1. Secure Enclave 内に鍵を生成
sc_auth create-ctk-identity -l github-se -k p-256-ne -t none

# 2. SSH キーハンドルを書き出し
ssh-keygen -w /usr/lib/ssh-keychain.dylib -K -N ""
mv id_ecdsa_sk_rk     ~/.ssh/id_github_se
mv id_ecdsa_sk_rk.pub ~/.ssh/id_github_se.pub

# 3. GitHub に認証キーと署名キーをそれぞれ登録
gh ssh-key add ~/.ssh/id_github_se.pub --type authentication --title "$(hostname)-secure-enclave"
gh ssh-key add ~/.ssh/id_github_se.pub --type signing    --title "$(hostname)-secure-enclave-sign"

確認

  • macOS 14 Sonoma 以降が対象
  • 各 Mac で上記コマンドを実行済み
  • ssh -T git@github.com がプロンプトなしで成功する
  • git commit --allow-empty -m "test" がプロンプトなしで署名される
  • 旧 1Password SSH キーを GitHub から削除(不要になったら)

注意

  • キーハンドルファイルは各 Mac の Secure Enclave に紐づくため、使用する毎に生成する必要がある
  • 秘密鍵は Secure Enclave に格納されるため抽出不可
  • ロック中の Mac 上で動作するマルウェアによる使用は防げない

- 1Password SSH エージェントから macOS Secure Enclave 管理の SSH キーへ移行

- commit 署名は ~/.ssh/id_github_se を使うように変更

- push 認証も Host github.com で Secure Enclave キーを使用

- SSH_SK_PROVIDER を fish セッション変数に設定
@github-actions

Copy link
Copy Markdown

Nix Diff

Compare changes

kohei-m4-mac-mini

Attribute: darwinConfigurations.kohei-m4-mac-mini.system

Diff Output
<<< /nix/store/a65s9jr6d46wbjv9vra1mhxn2rc4wijs-darwin-system-26.11.d8a6661.drv
>>> /nix/store/qz1xgg0x126150nd348pasadvxk9hf4p-darwin-system-26.11.d8a6661.drv

ADDED
[A.] hm_.localbinsshsign <none>

PATHS: 14454 -> 14455 (+23, -22)
SIZE: 411 MiB -> 411 MiB
DIFF: 2.49 KiB

SC-N-843

Attribute: darwinConfigurations.SC-N-843.system

Diff Output
<<< /nix/store/0idnf9lvpjkb6p3ycacj64bpkrbkkbd5-darwin-system-26.11.d8a6661.drv
>>> /nix/store/mdlq93bqmfmafhlj6idslx4f3i0alj23-darwin-system-26.11.d8a6661.drv

ADDED
[A.] hm_.localbinsshsign <none>

PATHS: 12742 -> 12743 (+23, -22)
SIZE: 292 MiB -> 292 MiB
DIFF: 2.49 KiB

📄 View diff as HTML in the Artifacts section


Generated by nix-diff-action using dix

@thinceller-hermes

Copy link
Copy Markdown
Collaborator Author

別セッションで架構を練り直すため一旦 close します。

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