GitHubのPersonal Access Token(PAT)のパーミッションが細かすぎる
GitHubのPAT設定が細かすぎて草。
結論:Repository PermissionsのContentsをRead and writeにする。以上。
Personal Access Token
GitHubではSSHよりHTTPS接続を推奨しているが、HTTPS
接続でのパスワード認証は廃止済。代わりにPersonal Access Token(PAT)
を使う。
..んだけど、特にFine-grained tokens
は権限設定が細かすぎて読んでるうちに日が暮れる。
最後まで読んで、ひとまずContents
だけ設定すればOK、あとは使っているうちに必要なら追加していけばいい、と理解した。
PATの作成方法
GitHubサイトの右上アイコン→Settings
→Developer settings
→Personal access tokens
→Fine-grained tokens
を選択。(2025年2月時点でPreview
だが、公式はこっちを強く推奨)
Generate new token
→2段階認証。Token name
に後で分かるよう記入。Expiration
で有効期間設定。
で、Permissions
がメチャクチャ細かい。詳細は公式参照。特定の項目を有効にすると、連動してmandatory
になる項目がある。権限はPAT作った後でも変更できるので必要なら随時更新。
Generate token
でPATの作成完了。作成されたトークンは再表示できないので安全な場所にコピーしておく。
リファレンスとしてメモ。まだまだ変更とか入りそう。
Repository Access
どのリポジトリに対する権限か選択できる。
Repository access | Description |
---|---|
Public Repositories (read-only) |
パブリックリポジトリに適用。これを選択するとリポジトリに対する読取だけの権限が設定される(ので、Repository Permissions の選択肢は選べなくなる)。間違ってリポジトリを更新したりpull requestしたりしないよう、自動スクリプトに権限を付けたりするのに使える。 |
All repositories |
This applies to all current and future repositories you own.Also includes public repositories (read-only). リポジトリ(これから作るのも)全部に適用。パブリックリポジトリ(の読取権限)も含む。 |
Only select repositories |
Select at least one repository. Max 50 repositories.Also includes public repositories (read-only). 適用するリポジトリを選択(50まで)。パブリックリポジトリ(の読取権限)も含む。 |
Permissions
ここからが本題。権限はNo access
, Read-only
, Read and write
から選択。
Repository Permissions
リポジトリに対する権限。めちゃくちゃ多い。
※契約プランによっては使えないのも混じってる。
permissions | description | R | RW |
---|---|---|---|
Actions |
Workflows, workflow runs and artifacts. ワークフロー、及びその成果物の管理。 gh workflow run 等の実行権限。ワークフロー実行だけならRead-only でOK。GitHub Actions はCI/CD(Continuous Integration / Continuos Delivery)ツール。push 等をトリガにpytest 流したり、ビルド、デプロイ等を行える。cron 的にも使える。関係する Workflows 権限が一番下にあるっていうね..。 |
R |
RW |
Administration |
Repository creation, deletion, settings, teams, and collaborators. リポジトリ作成・削除・設定・チーム・コラボレーター管理。 |
R |
RW |
Attestations |
Create and retrieve attestations for a repository. 証明書の作成・取得。ここで言う attestations とはビルドした成果物に付与する署名メタデータ。GitHub Actions のattest-build-provenance で生成する。 |
R |
RW |
Code scanning alerts |
View and manage code scanning alerts. code scan による警告参照・管理。Code Scanningはリポジトリ内のコードを分析して、脆弱性やコーディングミスを見つけれくれる機能。GitHub Actionsで動かすもの。 |
R |
RW |
Codespaces |
Create, edit, delete and list Codespaces. Code spaces上での作成・編集・削除・閲覧(Code spacesはGitHubが提供するクラウド上の開発環境、VSCodeからアクセスできる)。 |
R |
RW |
Codespaces lifecycle admin |
Manage the lifecycle of Codespaces, including starting and stopping. Code space自体の作成・起動・停止など。 |
R |
RW |
Codespaces metadata |
Access Codespaces metadata including the devcontainers and machine type. Code spacesのメタ情報(コンテナ、マシン種類等)へのアクセス。 |
R |
|
Codespaces secrets |
Restrict Codespaces user secrets modifications to specific repositories. Code spaces上の機密情報(APIキー、DB接続情報等。Code spaceで環境変数としてアクセスできる)の編集を許可。 Account Permissions にも似たのがあるが、こちらのsecretsはリポジトリ単位に適用されるものを指す。 |
RW |
|
Commit statuses |
Commit statuses. コミットステータスの取得・変更。 |
R |
RW |
Contents |
Repository contents, commits, branches, downloads, releases, and merges. リポジトリ参照、コミット、ブランチング、pull/clone、リリース、マージ。 git push には最低限これが必要。 |
R |
RW |
Custom properties |
View and set values for a repository's custom properties, when allowed by the property. (可能なものについて)カスタムプロパティの参照・変更。 |
R |
RW |
Dependabot alerts |
Retrieve Dependabot alerts. Dependabot からの警告を受け取る。※Dependabotはリポジトリが依存するライブラリの更新・脆弱性を監視してくれるもの(リポジトリ毎に有効化してあげる必要がある)。 |
R |
RW |
Dependabot secrets |
Manage Dependabot repository secrets. Dependabotが必要とする機密情報(プライベートパッケージの更新、認証が必要なリポジトリのPAT等)の管理。 |
R |
RW |
Deployments |
Deployments and deployment statuses. デプロイ・デプロイ状態の取得 |
R |
RW |
Discussions |
Discussions and related comments and labels. ディスカッション・関連コメント・ラベル |
R |
RW |
Environments |
Manage repository environments. GitHub Actionsのデプロイを管理する環境情報(デプロイ先の環境制限、承認ワークフロー設定、デプロイ履歴等)の管理。 |
R |
RW |
Issues |
Issues and related comments, assignees, labels, and milestones. イシュー、関連コメント、担当、ラベル、マイルストンへのアクセス。 |
R |
RW |
Merge queues |
Manage a repository's merge queues リポジトリのmergeキュー管理 |
R |
RW |
Metadata |
Search repositories, list collaborators, and access repository metadata. リポジトリの検索、コラボレーターの参照、メタデータの取得。 Contents をRead and Write にすると自動的にRead が付与される
|
R |
|
Pages |
Retrieve Pages statuses, configuration, and builds, as well as create new builds. GitHub Pages のステータス取得、設定、ビルド。※GitHub Pagesはリポジトリの内容を静的コンテンツとして公開するホスティングサービス。HTML, CSS等を参照し、GitHubや独自ドメインでアクセスできる仕組み。 Jekyll で.md ファイルをHTMLに変換することもできる。 |
R |
RW |
Pull requests |
Pull requests and related comments, assignees, labels, milestones, and merges. Pull Requests 関連、コメント、アサイン、ラベル、マイルストン、マージ。 |
R |
RW |
Repository security advisories |
View and manage repository security advisories. リポジトリのセキュリティ勧告の参照・管理。開発者が脆弱性について報告・修正・公開するための仕組み。対応まで非公開に保つことができる。GitHubからCVE(Common Vulnerabilities and Exposures、脆弱性番号)を取得する機能もある(審査が必要)。 |
R |
RW |
Secret scanning alerts |
View and manage secret scanning alerts. GitHubの Secret Scanning (リポジトリに間違って上げた機密情報を見つけてくれる仕組み)による警告を受け取る。 |
R |
RW |
Secrets |
Manage Actions repository secrets. GitHub Actions (ワークフロー管理)に必要なキー情報(AWS, GitHub Token等のAPIキー、DB接続情報、SSHキー等)を管理する仕組みへのアクセス許可。通常は暗号化され、GitHub Actions内で環境変数として参照できるもの。ここで登録したキー情報はSecret scanning の対象から除外される。 |
R |
RW |
Variables |
Manage Actions repository variables. GitHub Actions で参照される環境変数情報へのアクセス許可。 |
R |
RW |
Webhooks |
Manage the post-receive hooks for a repository. Webhooks はGitHub上のイベントをフックしてHTTPリクエストを送信する仕組み。push , pull request 等を引っ掛けてSlackに投げたりできる。受け側はsignatureなどで正規のフックリクエストか検証したほうがいい。 |
R |
RW |
Workflows |
Update GitHub Action workflow files. GitHub Actions で参照される.github/workflows/ 下のファイル更新権限。 |
RW |
Account permissions
アカウントに対する権限。こっちはまだ分かりやすい。
permissions | description | R | RW |
---|---|---|---|
Block another user |
View and manage users blocked by the user. 他のユーザをブロック/解除したり、その情報を参照できる。 |
R |
RW |
Codespaces user secrets |
Manage Codespaces user secrets. Code spacesのsecrets管理。 Repository Permissions にも似たのがあるが、こっちはGitHub全体に適用される機密情報を指す。 |
R |
RW |
Copilot Chat |
This application will receive your GitHub ID, your GitHub Copilot Chat session messages (not including messages sent to another application), and timestamps of provided GitHub Copilot Chat session messages. This permission must be enabled for Copilot Extensions. Copilotを使うときに必要。 |
R |
|
Copilot Editor Context |
This application will receive bits of Editor Context (e.g. currently opened file) whenever you send it a message through Copilot Chat. Copilotがファイルを編集するために必要。 |
R |
|
Email addresses |
Manage a user's email addresses. メアド |
R |
RW |
Events |
View events triggered by a user's activity. イベント情報を見れる。 |
R |
|
Followers |
A user's followers フォロワーを見れる。 |
R |
RW |
GPG keys |
View and manage a user's GPG keys. GPGキーの参照・管理 |
R |
RW |
Gists |
Create and modify a user's gists and comments. Gist (スニペットやメモをサッと書くやつ)を使える。 |
RW |
|
Git SSH keys |
Git SSH keys SSHキーの管理 |
R |
RW |
Interaction limits |
Interaction limits on repositories 特定ユーザからの操作を制限。既存ユーザのみ、コントリビュータのみ、コラボレータのみ。制限期間も設定できる。スパムのブロック等に。 |
R |
RW |
Knowledge bases |
View knowledge bases for a user. Knowledge bases は複数リポジトリにあるMarkdownファイルを集約し、Copilot Chatで参照できるもの。 |
R |
RW |
Plan |
View a user's plan. ユーザのプランを見れる |
R |
|
Private repository invitations |
View a user's invitations to private repositories プライベートリポジトリへのユーザ招待を見れる |
R |
|
Profile |
Manage a user's profile settings. プロフィール設定 |
RW |
|
SSH signing keys |
View and manage a user's SSH signing keys. ユーザのSSHキー管理。GitHub接続に使うSSHキーは Git SSH keys のほう。こっちはGPG代わりに使う署名用。最近GitHubが始めたもので、Add new SSH Key でAuthentication Key の他にSigning Key が選択できるようになっている。 |
R |
RW |
Starring |
List and manage repositories a user is starring. 星つけてるリポジトリ管理 |
R |
RW |
Watching |
List and change repositories a user is subscribed to. サブスクライブしてるリポジトリ管理 |
R |
RW |
感想:GitHubの知らない機能を色々勉強できたのでよかったです。
Discussion