ghp acts as a transparent proxy for GitHub's API and web endpoints. Your
administrator configures DNS so that api.github.com and github.com resolve
to the ghp server on your network. Agents set GH_TOKEN to a ghp-issued token
and make standard GitHub API calls — no code changes or special SDKs required.
Request Flow
sequenceDiagram
participant Agent as Agent<br/>(GH_TOKEN=ghx_xxx)
participant ghp as ghp<br/>(api.github.com virtualhost)
participant GitHub as GitHub<br/>(real api.github.com)
Agent->>ghp: GET /repos/owner/repo/pulls
ghp->>ghp: Validate token
ghp->>ghp: Check scope
ghp->>ghp: Inject real credential
ghp->>GitHub: GET /repos/owner/repo/pulls
GitHub-->>ghp: 200 OK
ghp-->>Agent: 200 OK
For each request, the proxy:
- Validates the token and checks it hasn't expired or been revoked
- Verifies the request targets an allowed repository and permitted operation.
For a scoped token, this is deny-by-default: a REST request that does not
target an allowed
/repos/{owner}/{repo}path (apart from a few identity endpoints such as/user), or that matches no permission rule, gets403 Forbidden. Paths with.,..or empty segments are rejected first - Swaps in the real GitHub credentials (stored server-side, encrypted at rest)
- Forwards the request to GitHub and returns the response unchanged
Virtualhost Routing
ghp serves several distinct roles depending on which hostname the request arrives on:
| Hostname | Role |
|---|---|
api.github.com |
API proxy — validates tokens, enforces scopes, injects credentials, logs every request |
github.com |
Git passthrough — proxy for git clone, git push, archive and release downloads with token interception; scoped tokens are checked and unmapped paths are denied (see Token Scoping) |
codeload.github.com |
Codeload redirect/passthrough — optionally redirects repo archive downloads to a caching mirror (see Codeload Redirect); passthrough otherwise. Client tokens are resolved and scoped tokens are checked before the redirect or forward |
*.githubcopilot.com |
Copilot passthrough — forwards Copilot traffic transparently; all requests are logged |
| Your management host | Dashboard — web UI, GitHub OAuth login (web), CLI device-authorization endpoints, token management API |
In TLS mode (recommended for production), ghp terminates TLS directly and uses
SNI to select the correct certificate for each hostname. In plain HTTP mode
(for development or behind a reverse proxy), routing is based on the Host
header alone.
High Availability
ghp can run as multiple instances behind a load balancer. All transient auth
state — browser sessions, in-flight OAuth state tokens for the GitHub login
redirect, OAuth broker state, and CLI device-authorization records — is
stored in the configured database (PostgreSQL, SQLite, or Vault), not in
process memory. A user signed in on instance A can be served their next
request from instance B, the GitHub OAuth callback for a redirect launched
on instance A is valid against instance B, and a CLI device flow whose
/cli/auth/device and /cli/auth/device/token calls land on different
instances completes correctly.
A background cleanup goroutine on each instance periodically purges expired sessions, OAuth state rows, and device-auth records (default every 5 minutes). For the SQLite backend this is in-process; for PostgreSQL and Vault it is shared by all instances and idempotent.
Security Model
- Token isolation — agents never see real GitHub credentials; they only hold short-lived ghp tokens
- Scope enforcement — tokens can be restricted to specific repositories and permission levels. For scoped tokens, REST endpoints that ghp cannot classify are denied, not forwarded (see Token Scoping). GraphQL root lookups (
node,nodes,resource,search) need the scope of each fragment type they read (see Root object lookups). For repository-restricted tokens, fields that can reach another repository (headRepository,parent,subIssues, user-levelissues/pullRequests, and similar) allow only metadata or a pinnedrepository(owner, name)parent, and introspection-only queries need no repository reference (see Cross-repository subtrees). Repository allowlists compare names with ASCII-only case folding - GitHub-side narrowing for agent tokens — an agent (
gha_) token's repositories must belong to the installation's account; ghp checks this when the token is created and again when it mints the installation token, and sends GitHub the bare repository names so the installation token is narrowed to them too. If the check fails, or ghp cannot read the installation account, no installation token is minted - Encryption at rest — for SQLite and PostgreSQL backends, all stored GitHub credentials are encrypted with AES-256-GCM using a server-managed key. For the Vault backend, Vault provides encryption at rest natively, so no application-level encryption key is required
- Audit trail — all requests produce OpenTelemetry access log records (method, path, status, duration) described using HTTP semantic conventions. API proxy requests additionally produce audit log records under the
github.com/goodtune/ghp/auditinstrumentation scope that include token, user, session, repository details, and request context. Token lifecycle events (creation, revocation, scope updates) also emit audit records but may omit repository and request-related fields. All records are written to the same console stream (and, when configured, exported to an OTLP collector). Capturing and indexing these logs is the responsibility of the deployment environment (e.g. Splunk, Elastic, Datadog). See Monitoring → Logging for the full attribute reference - Expiration — tokens have a configurable lifetime (default 24 hours, up to a server-configured maximum; default maximum 7 days). Operators can enable
tokens.allow_no_expiryto permit creating tokens that never expire ("duration": "never"in the API). Non-expiring tokens are useful for long-lived automation managed via infrastructure-as-code (e.g. Terraform) where token lifecycle is controlled externally through revocation rather than time-based expiry - Revocation — tokens can be revoked immediately from the CLI or web dashboard
- Hard deletion — expired and revoked token records are periodically removed from the database after a configurable retention period (default 30 days, controlled by
tokens.expired_token_retention_period). This prevents unbounded growth of the token table and ensures that token hashes are physically erased after the retention window, limiting the exposure surface if the database is compromised. Tokens with no expiry are only hard-deleted once they have been revoked and the retention period has elapsed - Management host API requires a ghp token — the management host serves GitHub Enterprise Server-style paths (
/api/v3/and/api/graphql) only for ghp-issued tokens (ghx_orgha_). A request with no credential gets401 Unauthorized. A request with any other credential, such as a nativegho_,ghp_,ghs_orgithub_pat_token, gets403 Forbidden, whatever the border policy settings are. This stops the management host from acting as an open, anonymous proxy to api.github.com that shares the instance's egress rate limit. There is no setting to turn this off. Clients that need transparent pass-through use the api.github.com virtual host, where the border policy applies - Border policy — administrators can block specific GitHub token types from passing through the proxy (see Token Type Border Policy)
- Enterprise access restriction — when
github.enterprise_slugis set, ghp injects GitHub Enterprise Cloud'ssec-GitHub-allowed-enterpriseheader so GitHub rejects requests from accounts outside the enterprise. Specific external owners or repositories can be exempted viagithub.enterprise_exceptions, optionally gated on org team membership and optionally substituting a managed GitHub App identity for the caller's credential (see Enterprise Restriction)
Feature Summary
Token Scoping
Tokens can be scoped to specific repositories and permission levels, ensuring
agents only access what they need. Open-scoped tokens (no restrictions) are
also supported when full access is appropriate. Permission names are checked
against one canonical list when a token is created; an unknown name (for
example pulls instead of pull_requests) is rejected with HTTP 400. Two
aliases exist: projects is satisfied by repository_projects or
organization_projects, and the deprecated workflows:read is treated as
actions:read. Agent tokens send GitHub only App permission names.
See Token Scoping for details.
Blocking Anonymous Git Traffic
Administrators can block unauthenticated git operations (clone, fetch, ls-remote) from passing through the proxy. When enabled, requests without credentials are rejected immediately rather than being forwarded to GitHub.
block:
anonymous_git: true
This setting can be changed without restarting the server (see Configuration).
Requires Git protocol version 2
Anonymous git blocking relies on the Git-Protocol header that Git 2.26+
sends by default. Older Git clients that use protocol v0 or v1 are not
detected and will pass through unblocked.
Release Download Controls
GitHub release assets (binaries, installers, archives) are fetched via direct HTTPS downloads, outside the scope model that ghp applies to API traffic. The release controls feature lets administrators block or redirect these downloads.
See Release Download Controls for configuration and details.
Copilot Passthrough
Traffic to *.githubcopilot.com is forwarded transparently. Copilot clients
manage their own credentials, so ghp does not intercept tokens or enforce
scopes on this traffic. All Copilot requests are still logged and counted
in metrics for full visibility.
Git Cache
For frequently-cloned repositories, ghp can cache git objects locally and serve subsequent clone/fetch requests from cache. This reduces load on GitHub and improves clone performance. Caching is opt-in per repository and always verifies GitHub access before serving cached data.
See Git Cache for configuration and details.
Forward Proxy Rulesets
Outbound GitHub traffic honours the process environment (HTTPS_PROXY et al.)
by default. Forward proxy rulesets let operators steer traffic out through
specific egress proxies at runtime — for example splitting heavy CI traffic
80/20 across two egress IPs, or pinning CI runner subnets to a dedicated path
so an IP ban never takes down interactive users.
Rulesets bind proxy targets and a routing algorithm (round robin, weighted,
sticky-by-source-IP) to traffic selected by token, app, source network (CIDR),
system-wide, or control rules; more specific layers win. Control rules cover
ghp's own GitHub-destined calls (OAuth flows and token refresh, installation
token minting, username resolution) so the proxy's control-plane traffic can
be pinned to a dedicated egress path; release HEAD probes target the
operator's mirror and go direct unless the control rule opts them in via
include_non_github. They are managed via the admin
API (/api/forward-proxy-rulesets) and take effect without a restart.
Anything not matched by a ruleset continues to use the ambient environment.
See Forward Proxy Rulesets for details.
Webhook Ingress
ghp can be the single receiving point for GitHub webhooks across every
registered app. Deliveries arrive at one ingress path (on the management host
and, optionally, on a public URL served by an embedded ngrok tunnel), are
verified against the targeted app's webhook secret using X-Hub-Signature-256,
and are stored in an embedded NATS JetStream stream. Nothing unsigned or
unverifiable is ever stored.
Each delivery is published under
github.webhooks.{app}.{event}.{action}.{owner}.{repo} with GitHub's headers
preserved as message headers, so subscribers filter by app, event type, action
or repository with ordinary NATS wildcards. GitHub redeliveries are
deduplicated by delivery GUID. Subscribers consume through native NATS clients
(when a listener is configured), the authenticated server-sent-events stream
on the admin API, or ghp webhooks tail; durable consumers resume where they
left off. Both embedded services are optional and off by default, and ghp
remains a single static binary.
See Webhooks for details.
Multi-App Support
ghp supports multiple GitHub Apps simultaneously. Each app can have its own
set of installations, and agent tokens (gha_) can be scoped to a specific
app. This is useful for organizations that need to separate concerns across
different GitHub Apps (e.g., CI vs. code review vs. deployment).
Apps are managed dynamically via the admin UI or API (/api/apps). Changes
take effect immediately — no restart or config reload is needed.
On first startup, if no apps exist in the database, the config-based GitHub App
(github.app_id, github.private_key, etc.) is automatically seeded as a
default App record in the store. Any existing agent tokens that have no app
association are backfilled to point to the newly created default app. After
seeding, all app management goes through the store — the config-based values
are not used as an independent provider in parallel with store apps.
If apps exist in the store but none can be loaded (e.g. all private keys are invalid), agent token creation returns HTTP 503 rather than creating tokens that would fail at use-time.
Storage Backends
ghp supports three storage backends:
- SQLite — single-file database, ideal for development and small deployments
- PostgreSQL — production-grade relational database
- HashiCorp Vault — secrets-native storage using KV v2 secrets engine, authenticating via AppRole or Kubernetes service-account auth
All backends implement the same Store interface and provide identical
feature parity. The Vault backend stores all data (users, tokens, apps) as
KV v2 secrets and uses index entries for lookups. It does not require SQL
migrations and does not need an encryption_key (Vault encrypts at rest).
When ghp runs on Kubernetes, the Vault backend can authenticate using the pod's projected service account JWT directly — no AppRole role-id / secret-id provisioning is needed and Vault Secret Operator (VSO) is not required for the auth path. ghp re-reads the projected token from disk on every re-authentication, so kubelet-rotated tokens are picked up automatically.
Vault concurrency limitation
Vault KV does not support atomic increments. Token usage counters use a read-modify-write pattern protected by an in-process mutex. In multi-instance deployments sharing the same Vault backend, concurrent usage counter updates may be lost. The counters are best-effort in this configuration.
See Configuration for backend-specific settings and Vault Backend for a complete Vault setup guide.
OAuth Broker
ghp can act as an OAuth broker for other services on your network, allowing them to authenticate users via GitHub without needing their own OAuth credentials.
See OAuth Broker for integration details.