Join our Newsletter — 33% off our NHI Course
Home› Guides› GitHub App Private Key Security Guide: Storage, Rotation…
Guide Non-Human Identity (NHI)

GitHub App Private Key Security Guide: Storage, Rotation and Leak Response

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 18 November 2026 11 min read
On this page

A GitHub App private key is a non-expiring machine credential that can mint access tokens for every account where the app is installed, so a single leaked PEM file can stay usable for years. This guide covers how GitHub App keys work, where to store them, how to rotate them without downtime, how to find leaked keys and what to do when one is exposed.

The risk is measured, not hypothetical. In September 2026 GitGuardian reported that of more than 500,000 RSA private keys in its dataset of public leaks, 474 still authenticated to the GitHub API as 440 distinct GitHub Apps, including apps with write access to private repositories, organisation administration and control of self-hosted runners. GitHub's own documentation is clear on why: "Private keys do not expire and instead need to be manually revoked." For personal access tokens, see our GitHub Personal Access Tokens Security Guide; for choosing between credential types, see GitHub Apps vs Personal Access Tokens vs OAuth Apps.

This is an independent guide from NHI Mgmt Group, based on GitHub's public documentation as of November 2026. It is not sponsored or reviewed by GitHub. Product features change, so confirm settings against GitHub's current documentation.

Key takeaways

  • The private key is the root credential of a GitHub App. GitHub states it "grants access to every account that the app is installed on".
  • Keys never expire. Rotation and deletion are entirely your responsibility, and an unrotated leak is permanent until someone acts.
  • Store keys in a key vault configured as sign-only, never in code, and avoid plain environment variables where you can.
  • Keep at least two keys in the rotation process so you can replace a compromised key without downtime. GitHub allows up to 25 keys per app.
  • Minimum permissions limit the damage. GitGuardian found 207 of the 440 leaked-key apps could write to private repositories.

How GitHub App authentication works

A GitHub App is a first-class machine identity on GitHub. When you generate a key pair, GitHub keeps only the public half; the docs warn you to "store this file because GitHub only stores the public portion of the key". The downloaded PEM file is in PKCS#1 RSAPrivateKey format.

Authentication happens in two steps:

  1. App JWT. The app signs a JSON Web Token with its private key using RS256. The token carries iat (GitHub advises setting it 60 seconds in the past for clock drift), exp ("no more than 10 minutes into the future") and iss, the app's client ID or application ID. GitHub recommends the client ID.
  2. Installation access token. The app uses the JWT to request an installation access token for a specific installation. GitHub's best practices page states that installation access tokens expire after one hour.

This design means short-lived tokens are what touch repositories, but the private key can mint new ones at will, for any installation, for as long as it exists. A stolen installation token is a one-hour problem. A stolen private key is an indefinite one.

What a leaked key exposes

The blast radius of a key equals the app's permissions multiplied by its installations. GitGuardian's research, published on 22 September 2026, gives a picture of what that looks like in practice across the 440 apps whose leaked keys still worked:

  • 72% had some repository content permissions and 207 had content write permissions;
  • 44 had organisation administration privileges;
  • 40 could administer self-hosted runners and 98 could control workflows;
  • 59% had a single installation, which suggests internal automation, and 21 had none;
  • 156 keys had leaked in repositories that the app's maintainer does not own.

The most cited example involved a private app owned by the cdcent organisation whose key leaked in a CDCGov repository in April 2025. GitGuardian reported it through the HHS disclosure portal on 4 September, it was acknowledged on 9 September, and the credentials were revoked on 18 September. GitGuardian's analysis suggests the app could have been used to execute code in the agency's Azure tenant, though it did not interact with the repository. The full account is in our Leaked GitHub App Private Keys 2026 page.

Write access to workflows or runners is especially serious: it turns a code repository credential into code execution on build infrastructure and, through deployment credentials, into cloud access. This is why an app's permissions matter as much as where its key is stored.

Storing GitHub App private keys

GitHub's documentation sets out a clear order of preference:

  • Key vault, sign-only. GitHub suggests "storing the key in a key vault, such as Azure Key Vault, and making it sign-only". Once imported, the key "can never be read from there"; the app sends the JWT to the vault to be signed. An attacker with access to the app's environment can then sign tokens while they hold that access, but cannot take the key away.
  • Environment variable, as a fallback. GitHub notes this "is not as strong as storing the key in a key vault", because "if an attacker gains access to the environment, they can read the private key and gain persistent authentication as the GitHub App".
  • Never in code. "You should not hard-code your private key in your app, even if your code is stored in a private repository."

NHI Mgmt Group adds the following practical controls, which apply whichever vault or cloud key service you use:

  • Import the key into the vault, verify it works, then destroy the downloaded PEM file. Do not leave copies in download folders, chat attachments or ticket systems.
  • Restrict the signing permission to the workload identity of the app itself, and log every signing operation.
  • Keep the key out of CI variables shared across repositories; if CI must authenticate as the app, use a dedicated environment with approval rules.
  • Treat local development keys as production keys if they belong to an app with real installations. Create a separate development app with test installations instead.

For the wider problem of keys in source control, see our Private Keys in Repositories Guide.

Scoping the app to limit blast radius

GitHub's best practices page asks developers to "select the minimum permissions that your GitHub App needs", noting that this "will limit the amount of damage that can occur" if keys or tokens are compromised. In practice:

  • Grant read rather than write wherever possible, and avoid organisation administration, workflow and self-hosted runner permissions unless the app's purpose requires them.
  • Install the app on selected repositories, not all repositories in an organisation.
  • Split broad automation into several apps, one per purpose, so that a release bot, a labelling bot and a dependency bot each hold only the permissions their job needs. A leaked key for the labelling bot then cannot push code or change workflows.
  • Separate production apps from development and test apps, each with its own keys and installations, so that keys handled on developer machines never authenticate to production repositories.
  • When the app acts on behalf of a person, GitHub says it "should always use a user access token instead of an installation access token", so the user's own permissions also apply. GitHub "strongly encourages" expiring user access tokens, which last eight hours with refresh tokens that expire after six months.
  • Uninstall apps that are no longer used. GitGuardian's September 2026 research reports that the key for the Crusher-Test app, leaked in November 2020, still worked, leaving users who never uninstalled the app exposed.

Organisation owners should review installed apps regularly; our guide on How to audit GitHub Apps and OAuth apps in an organisation walks through the process.

Rotating keys without downtime

Because keys never expire, rotation is a scheduled control, not just an incident response. GitHub states: "You should use multiple keys in order to rotate keys without downtime in the event of a key compromise." It also enforces an important safety rule: "you must regenerate a new key before you can delete the existing key", so an app is never left with no key at all.

A typical rotation looks like this:

  1. Generate a new key in the app's settings under Credentials and Key pairs.
  2. Verify the new key's SHA-256 fingerprint locally against the fingerprint shown in the app's settings.
  3. Import the new key into the vault and point the app at it. Confirm it can mint a JWT and an installation token.
  4. Watch for errors from any instance still using the old key, then delete the old key in GitHub.
  5. Record the rotation date, fingerprint and owner.

NHI Mgmt Group recommends a fixed rotation interval for every production app key, with a shorter interval for apps that hold write, workflow or administration permissions. The step-by-step procedure, including webhook secrets, is in our planned guide How to rotate a GitHub App private key and webhook secret without downtime.

Webhook secrets need the same discipline. GitHub advises setting a webhook secret and verifying "that the signature of incoming webhook events matches the secret". A leaked webhook secret lets an attacker forge events to your app, which matters if those events trigger builds or deployments.

Detecting leaked keys

A PEM file on its own looks like any other RSA key; what makes it dangerous is an app ID or client ID nearby. GitGuardian found 4,802 of its 500,000+ keys in a GitHub context alongside an app ID. Detection should therefore cover:

  • Private key material in repositories, including -----BEGIN RSA PRIVATE KEY----- blocks in code, configuration, test fixtures and documentation, across public and private repositories and forks you control.
  • Adjacent identifiers, such as app IDs, client IDs and installation IDs in the same file or commit.
  • Locations outside your organisation. 156 of the leaked keys in GitGuardian's study sat in repositories the app's maintainer did not own, so organisation-level scanning alone is not enough. Public leak monitoring helps.
  • Key inventory. List the fingerprints of every key on every app you own and compare them with the keys your workloads actually use. Unused keys are pure risk and should be deleted.

GitGuardian's own advice is to "rotate a key as soon as it might have leaked, and monitor for it continuously, not once at setup."

Responding to a leaked key

When a key may have been exposed, act at GitHub first, then clean up. Removing the PEM file from a repository does not invalidate it; we cover that trap in Deleted but Not Revoked.

  1. Generate a replacement key and deploy it, so the app keeps working.
  2. Delete the exposed key in the app's settings. Match it by fingerprint to be sure you are deleting the right one.
  3. Revoke live tokens. GitHub's guidance is that compromised tokens should be revoked immediately. Installation tokens minted with the old key last up to an hour, so treat that hour as part of the exposure window.
  4. Review activity. Use the organisation audit log and repository history to look for actions attributed to the app since the earliest possible leak date: new commits, workflow changes, runner registrations, permission changes and new deploy keys.
  5. Check downstream credentials. If the app could modify workflows or administer runners, review the secrets those workflows could reach and rotate them.
  6. Notify installers. For apps installed outside your organisation, tell installation owners what was exposed and when it was revoked.
  7. Remove the leaked copy from history and other locations once the key is dead.

Common failure patterns

  • Single-key apps. No second key in place, so rotation is postponed because it would cause an outage.
  • Keys in repositories. PEM files committed "temporarily" for testing or deployment, sometimes in repositories the maintainer does not own.
  • Over-permissioned apps. Write, workflow or administration permissions granted at creation and never reviewed.
  • Abandoned apps. Unmaintained apps with live keys and live installations.
  • Delete instead of revoke. Removing the file from the repository and assuming the key is dead.
  • Slow disclosure handling. No route for researchers to report a leaked key, or no owner to act on the report.

Practitioner checklist

  • Inventory every GitHub App you own, its key fingerprints, permissions, installations and owner.
  • Move every production key into a sign-only key vault and delete downloaded PEM copies.
  • Reduce permissions to the minimum and install on selected repositories only.
  • Keep a documented rotation process with two keys and rotate on a fixed schedule.
  • Delete keys that no workload uses and uninstall apps that are no longer needed.
  • Scan repositories, forks and public sources for app private keys alongside app IDs.
  • Set and verify a webhook secret for every app that receives events.
  • Prepare a leak runbook: replace, delete by fingerprint, revoke tokens, review the audit log, notify installers.

Standards and references

Related NHI Mgmt Group resources: GitHub Personal Access Tokens Security Guide · GitHub Apps vs Personal Access Tokens vs OAuth Apps · GitHub and GitHub Actions Security Guide · Private Keys in Repositories Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.