--- title: "ADR 0011: GitHub credentials and API endpoints stay on allowlisted hosts" --- * Status: accepted * Code: [`pkg/provider/github/github.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/github/github.go), [`pkg/provider/github/endpoints.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/github/endpoints.go), [`pkg/provider/github/parse_payload.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/github/parse_payload.go), [`pkg/provider/github/app/token.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/github/app/token.go) ## Context The GitHub provider holds credentials the controller owns: a webhook or App token from a Repository secret, and a GitHub App private key that signs a JWT locally and sends it to an API host. The host comes from untrusted input: the webhook payload (`repository.html_url`, `X-GitHub-Enterprise-Host`), `event.Provider.URL`, or `spec.git_provider.url` and `spec.url` of a Repository CR. A global Repository can share a token from the controller namespace, so the CR author and the credential owner are not the same party. The controller owns the list of trusted hostnames (`hostpolicy`). Everything below exists to keep a tenant-supplied host away from a controller-owned credential. ## Decision ### Which host is allowed * `SetClient` resolves `event.Provider.URL` through the allowlist (`trustedAPIEndpointForProviderURL`) and rebuilds the endpoint from the approved hostname rather than from the string supplied. An empty URL is gated too, because it means github.com and an authoritative allowlist may refuse it. * The endpoint is rebuilt from the host the allowlist approved, keeping the scheme (`http` or `https`) so a self-hosted instance served over plain http keeps working. `TrustedAPIEndpointForRepository` requires a full `https://` URL instead: a repository URL is written in full by GitHub, so a value with no scheme or another scheme is rejected. * `resolveUntrustedAPIEndpoint` does no trust check and stays unexported. Its callers must pass a hostname already returned by `hostpolicy.Trusted` or `hostpolicy.TrustOnFirstUse`. * `authenticatedAPIEndpoint` is trust-on-first-use, for requests GitHub has already authenticated by signature. A signature is checked against a secret the tenant owns, so on its own it is not enough to reach a host outside a configured allowlist; the tests assert this. * `apiEndpointFor` yields two shapes: github.com has an API host and no base URL and is always https; any other host gets `:///api/v3` as API URL and `://` as base URL. `scheme` is honoured only for the second shape. * `BaseURLForClient` prefers the loopback override from `PAC_GIT_PROVIDER_TOKEN_APIURL` over the endpoint base URL, because with that override authentication and API live on two servers. Every caller must apply it the same way, so it is a method. ### Which client is exempt * The gate applies only to the client `SetClient` builds. A client already installed (`ghClient != nil`, which is how unit tests inject a fake) is left alone, and so is one installed with `UsePreauthenticatedClient`. * `UsePreauthenticatedClient` is for callers that chose the URL themselves, such as the end-to-end harness reading its own configuration. The URL must never come from a payload, and nothing in the controller may use it. ### Minting a token * `ParsePayload` validates the webhook signature (`validateAppWebhookSignature`) before `GetAppToken`, and resolves the endpoint from the payload (`authenticatedGitHubEndpoint`) before minting. A failure is logged as a blocked token mint. * In `GetAndUpdateInstallationID` the JWT is generated only after the repository URL has been resolved against the allowlisted endpoint, so the private key never signs a token for an unchecked host. If the installation is found but the token request fails, the function logs a warning and still returns the endpoint base URL and installation ID with an empty token, because some callers only need the ID. * A webhook verified with a per-Repository secret goes through `trustedGitHubEndpointFromPayload`: the host is checked against the allowlist and never recorded. That secret belongs to the tenant, and recording the host would let any namespace owner rewrite the controller-wide policy. * Deliveries that carry no repository (`ping`, `installation`, `installation_repositories`, `marketplace_purchase`) return `errNoRepositoryInPayload`. They need neither an endpoint nor an installation token, and are skipped, after signature validation when an installation ID is present. * The app slug lookup uses the URL-aware gate, because `apiURL` after `SetClient` is a full API URL on self-hosted instances, not a bare hostname. `fetchAppSlug` receives that URL, `/api/v3` included, and a test pins it. * `ghinstallation` is typed against `go-github/v88` (`InstallationTokenOptions`) while the rest of the provider uses v93. The two imports move in step with that module's `go.mod`. ## Consequences * A new code path that builds a client without `SetClient`, or that takes a host from a payload, bypasses the gate. Calling `resolveUntrustedAPIEndpoint` with raw input removes the check. * A caller of `UsePreauthenticatedClient` takes responsibility for the origin of the URL. * Plain-http provider URLs are still accepted. The allowlist, not the scheme, is what protects the credential. * Two go-github major versions are vendored until `ghinstallation` moves.