Skip to content

Enable authentication using GitHub App #8747

Open

Description

@abhishekmukherg

Describe the feature or problem you’d like to solve

Currently the gh cli enables authentication against GitHub via two ways, going off my reading of the manual

  1. Personal Access Token
  2. OAuth apps

Another way to make calls against the GitHub API is via GitHub Apps. GitHub Apps have some different features from the above but, crucially, allow you to separate out the credential from a given service user. This can be valuable in cases such as CI systems, where you want something to last longer than the tenure of a specific employee, or to not have to leverage a service user which might have its own complexities depending on the organization.

Proposed solution

The proposed solution is to enable, in a CI pipeline, to be able to execute something like

./get-secret-from-secret-provider.sh > github-app-private-key.pem

# Validate the app id and private key
gh auth login --github-app-id 12345 --github-app-private-key github-app-private-key.pem

# Create a pull request, maybe
cd ./repo/
gh pr create --fill
# This would
#   1. look up the "installation id" from the app, maybe leveraging a cache
#   2. create an installation access token bound to the organization for the repository
#   3. do the operation as requested by the user

Additional context

I did look for an issue having already been created but did not find anything relevant

Activity

  1. added
    enhancement
    on Feb 23, 2024
  2. added
    needs-triage
    on Feb 23, 2024
  3. MichaMican commented on Mar 26, 2025

    @MichaMican

    This would be super usefull!

  4. added
    core
    gh-auth
    and removed
    needs-triage
    on Jul 14, 2025
  5. andyfeller commented on Jul 15, 2025

    @andyfeller
    Contributor

    @abhishekmukherg : Firstly, I want to sincerely apologize for not engaging with this issue sooner. 🙇 The GitHub CLI maintainers are working to improve our backlog review processes to provide more timely and confident feedback for suggestions and bugs.

    I would love to ask some questions to understand this use case as well as share some additional information you might find useful.

    Questions

    1. In your scenario, is gh authenticating a) as a GitHub App, b) as an app installation, c) on behalf of the user?

    2. Is this inside or outside a GitHub Actions workflow?

    3. Are there any other gh commands that might be necessary with this support?

    Thoughts

    The first question is important because it affects the complexity of the work as well as the REST endpoints or GraphQL queries/mutations you want to use:

    If you need to authenticate as an app installation with access to repositories, there are 2 short term solutions while this issue awaits prioritization depending on whether you're using this in GitHub Actions:

    1. actions/create-github-app-token action can be used within GitHub Actions workflow:

      name: Run tests on staging
      on:
        push:
          branches:
            - main
      
      jobs:
        hello-world:
          runs-on: ubuntu-latest
          steps:
            - uses: actions/create-github-app-token@v2
              id: app-token
              with:
                app-id: ${{ vars.APP_ID }}
                private-key: ${{ secrets.PRIVATE_KEY }}
            - uses: ./actions/staging-tests
              with:
                token: ${{ steps.app-token.outputs.token }}
    2. link-/gh-token GitHub CLI extension can be used locally or within GitHub Actions workflow:

      gh token generate \
          --key ./.keys/private-key.pem \
          --app-id 1122334 \
          --installation-id 5566778

      Thanks to fellow hubber, @Link-, for this work! 🫶

    The installation access token generated from either of these solutions can be used to authenticate as the GitHub App with access to repositories the GitHub App is installed in.

    Finally, I can see several additional commands being needed around authenticating as an GitHub App installation:

    # To securely store GitHub App credentials for generating installation access tokens
    gh app auth store [-h,--hostname]
    gh app auth store [-h,--hostname] <application-id> <application-private-key-file>
    gh app auth store [-h,--hostname] <application-id> --with-private-key < private-key.pem
    
    # To review the status of GitHub App credentials stored
    gh app auth status [-h,--hostname]
    
    # To remove securely stored GitHub App credentials from future use
    gh app auth remove [-h,--hostname] <application-id>
    gh app auth remove [-h,--hostname] <application-slug>
    
    # To view information about a GitHub App that has credentials stored
    gh app view [-h,--hostname] <application-id>
    gh app view [-h,--hostname] <application-slug>
    
    # To view and manage various GitHub App installations used for tokens
    gh app installation list <application-id>
    gh app installation list <application-slug>
    gh app installation view [-h,--hostname] [--web]
    gh app installation delete <installation-id>
    gh app installation suspend <installation-id>
    gh app installation unsuspend <installation-id>
  6. added
    more-info-needed
    on Jul 15, 2025
  7. stefankuehnel commented on Aug 1, 2025

    @stefankuehnel

    Hi @andyfeller,

    Thanks so much for the detailed response and for taking the time to engage with this issue — really appreciate it! 🫶

    While I’m not the original poster, I upvoted this issue because I think my use case closely aligns with theirs. I’d like to share my perspective and a demo I created to help clarify the need for this functionality.

    My Use Case

    I’m aiming to use a GitHub App as a replacement for Personal Access Tokens. GitHub Apps offer more fine-grained access controls and are decoupled from individual user accounts, which improves both security and maintainability.

    My goal is to run the GitHub CLI externally — for example, in a Bash script on a remote server — to trigger workflows in a repository using a GitHub App. This would allow me to automate tasks securely and independently of GitHub Actions or user-scoped credentials.

    Demo Setup

    To illustrate this, I created an example organization GH-CLI-8747 containing two repositories:

    What I'm Hoping For

    The steps in the workflow_dispatcher.yml work well inside GitHub Actions, but ideally, they should be supported directly by the GitHub CLI so that the same logic can seamlessly be executed externally — without relying on third-party extensions or custom GitHub App token generation scripts.

    In short, I’d love to see native CLI support for:

    • Authenticating as a GitHub App installation
    • Triggering workflows using that authentication

    Thanks again for your detailed response. I hope this example helps clarify the need for this functionality. I’d be happy to provide additional feedback or collaborate further if helpful!

    Best regards,
    Stefan Kühnel

  8. lkiii commented on May 19, 2026

    @lkiii

    This would be really useful for automation.

    I’d like to have a remote container with the gh installed that can perform actions on repositories. I’d also like the ability to grant the app the necessary permissions within my organization.

    App tokens are much more flexible than PATs. PATs inherit the same permissions as the user who created them, which makes it hard to enforce strict access controls. For my use case, I’d like to configure precise permissions - for example mostly read-only access, with limited write permissions only where explicitly needed.

  9. jessehouwing commented on Sep 4, 2026

    @jessehouwing
    Contributor

    A good reason for this is the new throttling for anonymous access:

    The recent change to redirect anonymous clones to authenticate (See #14329 and https://github.com/orgs/community/discussions/206581#discussioncomment-18269083) creates a cannondrum for users of ghe.com and competing platforms when they consume public repos as subtree, submodules or package manager dependencies (like npm git urls or terraform modules).

    Requiring every user to create a public github account, then auth or mint an access token won't create a more secure github environment in most organizations.

    It would be useful if these people could share an organization owned access key.

    I propose the ability for gh to be able to authenticate as a github app (by passing installation id and secret) to mint a temporary token.

    Similar to how many people are already doing this in github actions workflows using https://github.com/actions/create-github-app-token.

    But then from the commandline and to store these in the credential manager storage as well.

    Proposed solution
    It will allow non-github clients to provide authenticated access to public github repos (linked to their organization's identity) without requiring every user to create their own personal github account or to setup EMU purely for the benefit of accessing public github repos in the above mentiond scenarios.

    Additional context
    Add any other context like screenshots or mockups are helpful, if applicable.

    Reported issues so far for which this could help:

    • Repo not hosted on github installs hook scripts from public github repos. Repo fails to initialize properly after clone due to redirect to auth.
    • Repo fetching terraform modules from public repos in gitlab workflow, bitbucket pipelines, azure devops etc
    • Repo not hosted on github fetching npm modules referenced by git url
    • Repo not hosted on github having submodule or subtree config'd against public github repo fails to clone or fetch updates intermittently.
    • Repo hosted on ghe.com also share the above issues.

    The poposed link-/gh-token extension looks promising, but for usage in enterprise context, especially given how sensitive tokens are, a native, official github owned solution is preferable.

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

    coreenhancementgh-authmore-info-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions