Skip to content

Document minimum required v2 fine grain PAT scopes in gh auth login #9461

Open

Description

@andyfeller

Describe the feature or problem you’d like to solve

The GitHub CLI predates the introduction of fine grained PATs. While we generally recommend users authenticate using the GitHub CLI OAuth app, we understand our users might prefer this alternative.

The gh auth login help docs explain the minimum required permission scopes for v1 coarse grain PATs, however it has no information about exactly which v2 scopes are needed to use the majority of gh commands.

Proposed solution

I propose the GitHub CLI exercises the various gh commands and document the minimum required v2 permission scopes needed to use gh without unexpected errors.

Additional context

#9403

Activity

  1. added
    enhancement
    on Aug 14, 2024
  2. added
    needs-triage
    on Aug 14, 2024
  3. removed
    needs-triage
    on Aug 20, 2024
  4. aryanbhosale commented on Aug 25, 2024

    @aryanbhosale
    Contributor

    Describe the feature or problem you’d like to solve

    The GitHub CLI predates the introduction of fine grained PATs. While we generally recommend users authenticate using the GitHub CLI OAuth app, we understand our users might prefer this alternative.

    The gh auth login help docs explain the minimum required permission scopes for v1 coarse grain PATs, however it has no information about exactly which v2 scopes are needed to use the majority of gh commands.

    Proposed solution

    I propose the GitHub CLI exercises the various gh commands and document the minimum required v2 permission scopes needed to use gh without unexpected errors.

    Additional context

    #9403

    hey @andyfeller , where can i find the repo for these docs?(i have written the updated docs for this issue)

    gh auth login

    Authenticate with a GitHub host.

    Usage

    gh auth login [flags]
    

    Description

    The default authentication mode is a web-based browser flow. After completion, an authentication token will be stored securely in the system credential store. If a credential store is not found or there is an issue using it, gh will fallback to writing the token to a plain text file. See gh auth status for its stored location.

    Alternatively, use --with-token to pass in a token on standard input.

    For classic personal access tokens, the minimum required scopes are:
    repo, read:org, and gist.

    For fine-grained personal access tokens, the following permissions are typically required for full functionality:

    • Repository permissions:
      • Actions: Read and write
      • Administration: Read and write
      • Contents: Read and write
      • Environments: Read and write
      • Issues: Read and write
      • Metadata: Read-only (automatically added)
      • Pull requests: Read and write
      • Workflows: Read and write
    • Organization permissions:
      • Members: Read-only
    • Account permissions:
      • Gists: Read and write

    Note: Specific gh commands may require fewer permissions. Refer to our online documentation for detailed permission requirements per command.

    Alternatively, gh will use the authentication token found in environment variables. This method is most suitable for "headless" use of gh such as in automation. See gh help environment for more info.

    To use gh in GitHub Actions, add GH_TOKEN: ${{ github.token }} to env.

    The git protocol to use for git operations on this host can be set with --git-protocol, or during the interactive prompting. Although login is for a single account on a host, setting the git protocol will take effect for all users on the host.

    Specifying ssh for the git protocol will detect existing SSH keys to upload, prompting to create and upload a new key if one is not found. This can be skipped with --skip-ssh-key flag.

    Options

    Flag Description
    -p, --git-protocol <string> The protocol to use for git operations on this host: {ssh|https}
    -h, --hostname <string> The hostname of the GitHub instance to authenticate with
    --insecure-storage Save authentication credentials in plain text instead of credential store
    -s, --scopes <strings> Additional authentication scopes to request
    --skip-ssh-key Skip generate/upload SSH key prompt
    -w, --web Open a browser to authenticate
    --with-token Read token from standard input

    Examples

    # Start interactive setup
    $ gh auth login
    
    # Authenticate against github.com by reading the token from a file
    $ gh auth login --with-token < mytoken.txt
    
    # Authenticate with a fine-grained PAT
    $ gh auth login --with-token
    
    # Authenticate with a specific host
    $ gh auth login --hostname enterprise.internal

    See Also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions