Installation Access Tokens: Mechanism and Best Practices

    This article explains how installation access tokens work and why they are a practical credential model for automation and platform engineering. It covers the token lifecycle and revocation paths, the three-layer least-privilege model, implementation in CI pipelines, rate limit considerations, compatibility risks from token format evolution, and troubleshooting with security auditing. Readers will learn how to design short-lived, fine-grained, machine-identity credentials that are revocable, auditable, and automatically expiring.

    1. Why Machine Credentials Need Installation Tokens

    In automation and platform engineering, programs must access code hosting platforms and development toolchains with a machine identity. Long-lived personal access credentials have three structural problems: their permission scope is often too broad and tied to a natural person’s account; they lack an expiration time, so a leak is hard to contain automatically; and they are difficult to audit, because operation records do not map to the actual calling entity.

    Installation Access Tokens are short-lived credentials designed to solve these problems. Their core characteristics can be summarized in four points:

    • Recognizable prefix: The credential carries a fixed prefix (typically ghs_), making it easy for log searches, secret scanning rules, and leak detection policies to identify it consistently.
    • Short lifetime: A typical lifetime is about 1 hour, making it a temporary credential that is discarded after use.
    • Automatic expiration: No manual intervention is required; the token becomes invalid on expiry, and revocation is essentially early termination.
    • Bound to an installation, not a user: The credential belongs to “an app’s installation on an organization or repository” and is decoupled from any natural person, making it very similar to a service token.

    The value of this design is that it turns the hard problem of safeguarding long-term keys into the much cheaper engineering problem of issuing and rotating short-lived tokens.

    2. Lifecycle and Revocation Paths

    Understanding the lifecycle is a prerequisite for security design. The full chain for an installation token is:

    1. The app side uses the app private key to sign a short-lived JSON Web Token (JWT).
    2. Using that JWT as a Bearer credential, it sends a request to the installation-level token issuance endpoint, carrying the target installation identifier.
    3. After validating the JWT, the platform returns an installation access token.
    4. Application code uses the token to perform reads and writes over REST, GraphQL, or the Git protocol.
    5. The token expires automatically, or is explicitly revoked.

    There are three typical revocation paths:

    • App owner revokes proactively: Call the token revocation API to invalidate a specific token immediately.
    • Organization or enterprise owner uninstalls the app: All tokens under that installation are disabled together.
    • Natural expiration: The token becomes invalid automatically after about 1 hour, with no action required.

    It is important to note that the installation ID is the only locator. The same app usually has only one installation record on a given organization. There are three common ways to obtain the installation ID: directly from a webhook event payload, by enumerating the installation list through an app-level API, or by confirming it in the installation details on the organization settings page.

    3. Permission Model: Three Layers of Least Privilege

    The key reason installation tokens suit automation is that they support fine-grained scoping on three layers:

    • Repository scoping: Access can be limited to a single repository or span multiple repositories.
    • Capability scoping: Fine-grained permission items are granted individually, such as content read, issue write, or check run result reporting.
    • Subject scoping: The token is not bound to any user, avoiding both the “broken chain when someone leaves” problem and the “account has excessive privileges” problem.

    The practical recommendation is to treat permission planning as upfront design work rather than adding permissions after launch. The recommended flow:

    1. Define the read/write list for the automation task (list only what is required).
    2. Determine app visibility (public or internal to the organization only).
    3. Create the app on the organization’s app settings page and record the app ID (note that the app ID and the client ID are not the same concept).
    4. Generate and download the private key, hand it to a key management service, and never commit it to a repository or bake it into an image layer.
    5. Complete installation authorization only on the target repositories.

    4. Implementation in Continuous Integration

    After enabling the code hosting platform’s automation pipeline capability, the platform installs an internal app on the repository and injects an installation token as a runtime secret on every run. The key constraint is that the token’s permissions are limited to the repository where the current workflow resides; cross-repository operations require explicit authorization.

    An illustrative token acquisition and usage flow (pseudocode, with API paths expressed as placeholders):

    1. # 1. Sign a JWT with the app private key (5-10 minutes validity recommended)
    2. jwt = sign_jwt(app_id, private_key, expires_in=540)
    3. # 2. Exchange for an installation token
    4. resp = POST "/app/installations/{installation_id}/access_tokens"
    5. Authorization: Bearer <jwt>
    6. Body: { "permissions": {...}, "repositories": [...] }
    7. token = resp.access_token # in the form ghs_xxx
    8. # 3. Use the token to access resources
    9. GET "/repos/{owner}/{repo}/contents/{path}"
    10. Authorization: Bearer <token>

    In engineering terms, treat the token as an ephemeral resource within a single task: obtain it when the task starts, discard it when the task ends, and never write it to a cache, log, or build artifact.

    5. Rate Limits and Quota Awareness

    An installation token’s rate quota matches the size tier of the organization it belongs to, rather than being tied to a personal account. This means splitting automation across multiple installations does not scale the quota linearly. What actually works is consolidating calls, using conditional requests and local caching, avoiding idle polling, and converting high-frequency reads into event-driven patterns.

    6. Compatibility Risks from Format Evolution

    The industry is moving toward stateless installation tokens. The new format encodes the app identifier and signature segment into the credential itself (in the form ghs_app-id_signature-segment) to improve issuance performance and API reliability. The direct consequence is a risk: the token length is no longer fixed.

    Historically, many systems assumed the credential was exactly 40 characters and designed database field widths, log truncation, regex validation, or front-end display around that assumption. Once the format changes, hidden failures appear: truncated database writes, failed validation, and broken redaction rules.

    Compatibility checklist:

    • Design database and configuration fields as variable-length strings with spare capacity.
    • Change validation logic to “prefix plus minimum length” and prohibit exact-length assertions.
    • Identify tokens by prefix for log redaction, without relying on fixed-offset substring extraction.
    • Update secret scanning rules to cover both the old and new forms.
    • During the gradual rollout, use a temporary request header to explicitly select the token format, enabling on-demand switching and rollback.

    7. Troubleshooting and Security Auditing

    Common problems and how to locate them:

    • 401 with an invalid credential message: Usually an expired JWT, clock drift, or a wrong installation ID.
    • 403 with an insufficient permissions message: Check whether the fine-grained permission items and repository scope include the target repository.
    • The actor shows up as a bot: This is normal and indicates personal credentials were not misused.
    • All tokens suddenly become invalid: Confirm whether the app was uninstalled or the owner revoked them.

    For auditing, it is recommended to set up three routine monitors: abnormal token issuance frequency, sudden spikes in calls for a single token, and alerts for ghs_ prefix strings appearing in code repositories. Combined with general-purpose cloud logging and monitoring/alerting capabilities, this forms closed-loop visibility across issuance, usage, and expiration.

    8. Conclusion

    The essence of an installation token is trading the risk exposure of long-term keys for “short-lived + fine-grained + subject decoupling.” Three things capture most of the benefit in practice: designing least privilege upfront, treating tokens as ephemeral with automatic rotation, and leaving elasticity in length and validation for format evolution. In the continuous integration and artifact management practices of cloud platforms such as Baidu AI Cloud, this model applies equally well: making machine identity a revocable, auditable, automatically expiring temporary credential is the most economical starting point for automation security governance.