Conversation
Add three environment variables that, when all present, authenticate octx as a GitHub App installation: - GITHUB_APP_ID - GITHUB_APP_PRIVATE_KEY (RSA PEM body) - GITHUB_APP_INSTALLATION_ID GITHUB_API_TOKEN and the App triple are mutually exclusive; exactly one must be provided. The installation token is obtained by Octocrab::installation(InstallationId) and refreshed automatically by octocrab before it expires.
Replace GITHUB_APP_PRIVATE_KEY with GITHUB_APP_PRIVATE_KEY_PATH. Passing the PEM body through an environment variable exposes it via /proc/<pid>/environ, core dumps, environment logging, and child-process inheritance. Reading from disk lets deployments mount the secret as a file (e.g. Secret Manager volume mount on Cloud Run) so the raw key never touches the process environment.
n01e0
left a comment
There was a problem hiding this comment.
GHES + App 認証でもページング時に Authorization が付くようにする必要がありそうです。
この PR で追加される App installation 認証は、GHES かつ複数ページになる抽出で 2 ページ目以降が認証なしになりそうです。
1 ページ目は /repos/... のような相対 URI なので installation token の Authorization が付きます。一方、各 fetcher は以降のページ取得で get_page(&page.next) を使っており、page.next は GitHub API の Link ヘッダー由来の絶対 URL です。GHES では https://git.example.com/api/v3/... のような URL になります。
octocrab 0.49 の installation 認証は、動的 Authorization を付ける対象を authority == None または authority == "api.github.com" に限定しています。そのため GHES の絶対 URL には Authorization が付かず、2 ページ目以降が 401/403 になる可能性があります。
page.next を get_page に渡す前に scheme/authority を落として path/query の相対 URI に正規化するなど、GHES + App 認証でもページングが認証付きで続く形にしておきたいです。
octocrab 0.49 only attaches the installation Bearer token when the outgoing request authority is empty or equals `api.github.com`, so the absolute URL returned via GitHub's `Link` header (which uses the GHES authority) would otherwise be sent without Authorization and fail with 401/403 on page 2 and beyond. Normalize `page.next` down to path and query before handing it to `Octocrab::get_page`. `BaseUriLayer` re-applies the base_uri to a scheme-less and authority-less URI just as it does for the initial route string, and `AuthHeaderLayer` treats it as a GitHub-destined request so both Installation and PAT auth continue to work.
|
@n01e0 内訳としては、auth header の付与が 2 経路に分かれていました。
実証として wiremock で 4 シナリオ (Installation / PAT × base_uri と同一 authority / 別 authority) を流し、 修正として、 authority が落ちると |
|
ページング用の ただ、 ここも |
The users-detailed extractor previously passed the absolute `user.url` from the list response straight into `Octocrab::get`. On GHES this is an absolute URL on the GHES authority, which hits the same installation-auth gap as `page.next` did: octocrab's execute() only attaches the Bearer token for api.github.com or empty authorities. Run the URL through `to_relative_uri` first so the request is dispatched with path+query only, which makes BaseUriLayer re-apply the base_uri and execute() treat it as a GitHub-destined request.
|
@n01e0 具体的には、 |
|
レビューありがとうございました!! |
Summary
GitHub App の installation token で認証できるようにします。
Changes
GITHUB_APP_ID: App ID (整数)GITHUB_APP_PRIVATE_KEY_PATH: App の秘密鍵 (RSA PEM) のファイルパスGITHUB_APP_INSTALLATION_ID: Installation ID (整数)GITHUB_API_TOKENと上記 3 変数は排他です。両方セットされている / 片方だけ中途半端に埋まっている状態は起動時に panic して弾きますsrc/main.rsの認証箇所をOctocrab::builder().app(app_id, key).build()?.installation(installation_id)?に切り替えました。 installation token は octocrab 側が送信直前にキャッシュ検証して必要なら自動で再発行します ( https://github.com/XAMPPRocky/octocrab/blob/v0.49.7/src/lib.rs 内のCachedToken周辺)Cargo.tomlにjsonwebtoken = "10"を追加しました。Octocrab::builder().app(AppId, EncodingKey)がjsonwebtoken::EncodingKeyを引数に取るためです (octocrab 0.49 側がjsonwebtoken = "10"を使っているのでバージョンを合わせています)Review points
/proc/<pid>/environ/ クラッシュダンプ / 環境変数を拾うロガー / 子プロセスへの暗黙継承などで秘密鍵が漏れるリスクを減らしたかったためです。 Secret Manager → Cloud Run の連携でもファイルマウント方式 (--set-secrets "/secrets/github-app-key.pem=projects/.../secrets/.../versions/latest") が使えますmatchの全パターンで行い、不正な組み合わせで起動した場合はpanic!で明示メッセージ出力にしています。anyhow::bail!にする手もありましたが、 main の戻り値型を変えたくなかったので現状のまま panic にしていますContext
octx に GitHub App installation token 認証を追加する 3 本立ての最終 PR です。
3 本立ての最後の PR として、本 PR で
Cargo.tomlの version を0.6.2→0.7.0に上げています。