Repository navigation
feat(ghtkn): authenticate aqua, gh, and C-FO git through the ghtkn agent on business - #254
Merged
Merged
Conversation
Prompt for the shared GitHub App client ID in business mode, render ~/.config/ghtkn/ghtkn.yaml with the agent backend, and install ghtkn through the global aqua config. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Business gh runs under `ghtkn exec -e GH_TOKEN` so the token only lives in the child env. aqua switches from the keyring token to AQUA_GHTKN_ENABLED. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A LaunchAgent starts the agent through aqua and an onchange script reloads it when the plist or the ghtkn version changes. The agent restarts locked, so the script reminds the operator to unlock it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… ID map Client IDs are carried forward from the local chezmoi.yaml (data.ghtkn_client_ids) and never enter the repo. ghtkn.yaml renders only apps with an ID, aqua selects C-FO/read through GHTKN_APP, and gh uses C-FO/write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep C-FO URLs on HTTPS with an insteadOf override of the global SSH rewrite, and give them a path-aware ghtkn helper. The work include moves below the gh helper sections so its helper reset applies last. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shells started under a multiplexer that predates the switch to ghtkn still inherit AQUA_KEYRING_ENABLED=true. aqua checks the keyring before ghtkn, so it sent the stale keyring token and the private C-FO registry failed with 401 Bad credentials. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
business プロファイルの GitHub 認証を、ghtkn が発行する GitHub App の短命 token(8 時間)に切り替えます。aqua、
gh、C-FO 配下の git の 3 経路が対象です。#223 で入れた keyring 方式(AQUA_KEYRING_ENABLEDとaqua-token-sync)はこの PR で置き換えます。7 月に ghtkn をやめたのは、8 時間ごとに Device Flow で再認証する手間が理由でした。ghtkn v0.3.4 以降は agent バックエンドで refresh token を使えるので、この再認証が不要になります。残る手間は、ログインや agent の再起動のたびに
ghtkn agent unlock --enable-refreshで passphrase を 1 回入れることです。personal プロファイルは対象外です。personal には aqua がなく、App の user token では他人のリポジトリに書き込めない(OSS への
gh pr createが通らない)ためです。変更内容
home/dot_config/ghtkn/ghtkn.yaml.tmpl(新規):backend: agentと 4 つの App(C-FO/none、C-FO/read、C-FO/git、C-FO/write)。先頭のC-FO/noneが既定になるdata.ghtkn_client_ids.{none,read,git,write}に手で書き、.chezmoi.yaml.tmplが次のchezmoi initに引き継ぐ。値のない App はテンプレートが出力しないsuzuki-shunsuke/ghtkn@v0.4.1を追加し、.zshenvでAQUA_GHTKN_ENABLED=trueとGHTKN_APP=C-FO/readを設定する。aqua には App を選ぶ設定がなく、指定しないと先頭のC-FO/noneが使われて private registry を読めないgh:features/ghtkn-gh.zshでghtkn exec -e GH_TOKEN:C-FO/write -- ghに包む。token を取れないときは gh を実行せず、unlock を促して止まる。GH_TOKENやGITHUB_TOKENを明示したときは素通しする!ghtkn git-credentialを使う。それ以外の github.com は従来どおりgh auth git-credentialと SSHlocal.ghtkn-agentがaqua exec -- ghtkn agent startを常駐させる。run_onchange_after_load-ghtkn-agent.shは plist か ghtkn のバージョンが変わったときだけ再起動するfeatures/aqua-token-sync.zshとそのテストレビューの観点
includeIfの位置を移した(dot_config/git/config): credential helper のリストはファイル順に積み上がる。work のhelper =リセットを gh のセクションより後ろに置かないと、ghtkn の helper が gh の helper に負けるinsteadOfの自己書き換え(dot_config/git/work.tmpl): business では github.com の HTTPS をすべて SSH に書き換えており、SSH では credential helper が呼ばれない。[url "https://github.com/C-FO/"] insteadOf = https://github.com/C-FO/は最長一致で優先されるので、C-FO だけが HTTPS のまま残るunset AQUA_KEYRING_ENABLED(dot_zshenv.tmpl): 行を消すだけでは、apply 前に起動した herdr や tmux のサーバーから新しいペインへ値が受け継がれる。aqua は keyring を ghtkn より先に調べるので、古い token で 401 になる。実機でこの現象を踏んだため追加したGHTKN_APP=C-FO/readがあっても、git はC-FO/gitを使う。ghtkn は owner の一致をGHTKN_APPより先に評価するため(ghtkn-go-sdk のconfig/app.goのResolveApp)検証
just testとjust fmt-checkは exit 0 です。追加したテストは次の 2 本です。tests/zsh/ghtkn-gh.test.sh: ラッパーの各分岐、business と personal の描画の差、App の出し分け、受け継いだAQUA_KEYRING_ENABLEDを.zshenvが消すことtests/zsh/ghtkn-git-helper.test.sh: C-FO だけが HTTPS に残ること、C-FO で ghtkn の helper が最後に来ること、personal には何も入らないこと実装を 1 箇所ずつ壊して、テストが red になることを確認しました。
:C-FO/writeを外すinsteadOfを外す.zshenvからunset AQUA_KEYRING_ENABLEDを外すgot: keyring=true ghtkn=true)business の実機(worktree をソースに対象ファイルだけ apply)で確認した結果です。
AQUA_ROOT_DIR=$(mktemp -d))で clusterops のaqua i -lgh api repos/C-FO/clusteropsghu_、取得できたGHTKN_LOG_LEVEL=debug git fetch --dry-run(clusterops)app_name=C-FO/git、exit 0launchctl print、ghtkn inforunning、socket は~/.cache/ghtkn/agent.sock適用時の注意
chezmoi applyは~/.config/ghtkn/ghtkn.yamlを上書きする。先にghtkn_client_idsを埋めておかないと App が 0 件になり、3 経路すべてが止まるghtkn agent unlock --enable-refreshで passphrase を設定し、ghtkn auth C-FO/read、C-FO/write、C-FO/gitを 1 回ずつ実行する。ghtkn execと aqua は Device Flow を自分では始めない🤖 Generated with Claude Code