githubapp

package
v0.205.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package githubapp is muster's GitHub identity when a GitHub App is configured (MUSTER_GITHUB_APP_ID + MUSTER_GITHUB_APP_PRIVATE_KEY): the `github` connector's credential, the dispatch dialog's repository list, and the "is this a connected repository" check behind every dispatch door.

🔴 ONLY INSTALLATIONS ON ALLOWLISTED ACCOUNTS EXIST (Config.Accounts, MUSTER_GITHUB_APP_ACCOUNTS, required). The App must be public ("Any account") to be installable on an organization its owner does not own, so ANYONE can install it on their own account. An installation on an account that is not on the list contributes no repository, mints no token and passes no connected-repository check: it is ignored, and logged once by login.

🔴 THE LIST IS MATCHED ON THE ACCOUNT'S NUMERIC ID, NEVER ITS LOGIN. A login is renamable and, once freed, re-registrable: if an allowlisted `acme` renames, anyone can register `acme`, install the public App, and — matched by login — pass the allowlist. The id never changes and is never reused. The login in each entry is a label and a cross-check only: an installation whose id matches but whose login differs (a legitimate rename) is still used, and the rename is logged once and reported (App.Renames, the boot check line).

🔴 AN AGENT'S TOKEN IS MINTED FOR THAT AGENT'S ONE REPOSITORY, WITH EXACTLY FOUR PERMISSIONS. Each proxied request from an approved agent to its own repository is served with an installation access token minted by POST /app/installations/{id}/access_tokens with `repositories: [<the agent's repo>]` and, in the default write mode (Config.Access, AccessWrite), `permissions: {contents: write, pull_requests: write, checks: read, statuses: read}`; in read mode (AccessRead, MUSTER_GITHUB_APP_ACCESS=read) every one of the four is `read`, so a push or a pull-request write through the proxy is refused by GitHub, never upgraded (GitHub adds metadata: read implicitly in both). A caller marked ReadOnly (connectors.Caller.ReadOnly — an officer instance) is minted in read mode whatever the App's mode (accessFor), and the mode is part of the token cache's key. Nothing wider is ever asked for on an agent's behalf: the request body is a fixed struct (mintRequest), pinned literally by the tests for each mode.

🔴 THE TOKEN NEVER LEAVES MUSTER. It is injected by the connector proxy (internal/connectors, /connect/github/...) on the way out, exactly as a stored connector's secret is, and is held only in this process's memory: cached per (agent, repository, mode) until refreshBefore of its expiry (GitHub issues them for one hour), never written to the database, a log line or a response.

ONE EXCEPTION, READ ONLY: a caller's further read repositories (connectors.Caller.ReadRepos — an officer's `read_repos`). A request that targets one of them is served with a token minted for THAT one repository, always in AccessRead (the four read levels; metadata read implicitly), whatever Config.Access and the caller's ReadOnly say. Each is cached under its own (agent, repository, mode) key like any other.

🔴 A REQUEST FOR ANY OTHER REPOSITORY CARRIES NO CREDENTIAL AT ALL. It is forwarded anonymously (a public dependency or submodule clones as it would for anyone; a private one fails as it would for anyone), and the App token is never attached to it. A path whose repository cannot be decided — a `.`/`..` or encoded traversal, a leading empty segment, a `repositories/<id>` path — is refused outright. See targetRepo.

The App's own credential (a 10-minute RS256 JWT signed with the private key) is used only for /app/... calls — listing installations and minting tokens — and never leaves muster either.

🔴 THE APP IS THE ADMIN'S, NOT EVERY USER'S. The OAuth connection it replaced (since removed) was one GitHub account per muster user; the App is the deployment's. So it is offered only to admin-role principals: the `github` connector is presented to them alone (connectors.WithVirtual's allow), and internal/api's github_source.go gives the App's repositories to them alone. A member keeps their stored connectors and has no connected repositories.

Index

Constants

View Source
const (
	DefaultGitHost = "github.com"
	DefaultAPIHost = "api.github.com"
)

Defaults for the hosts the connector serves. Config overrides them only in tests and the e2e build (a fake GitHub on loopback).

View Source
const ConnectorName = "github"

ConnectorName is the connector the App backs. It is the name ccd's checkout and git routing ask for (cmd/ccd: githubConnector) and the GitHub preset's key.

Variables

View Source
var ErrMintBusy = errors.New("githubapp: another token is being minted; not waiting for it")

ErrMintBusy is a pull-request read refused because another token is being minted: PullRequestState never waits on the mint lock, so its caller's deadline bounds the whole read (the caller reads it as "unknown").

Functions

func ParsePrivateKey

func ParsePrivateKey(v string) (*rsa.PrivateKey, error)

ParsePrivateKey reads the App's private key: the PEM file GitHub's "Generate a private key" button downloads (PKCS#1, `BEGIN RSA PRIVATE KEY`), or the same key re-encoded as PKCS#8 (`BEGIN PRIVATE KEY`).

A value whose line breaks were flattened to the two characters `\n` (a common result of pasting a PEM into a one-line field) is accepted too: those escapes cannot occur inside base64, so turning them back into newlines cannot change a well-formed key.

🔴 A KEY THAT DOES NOT PARSE IS A BOOT REFUSAL, NOT A LOG LINE (see cmd/muster-server's loadConfig): every token mint would fail with it, and the failure would surface hours later on an agent card instead of at deploy time.

Types

type Access added in v0.108.0

type Access string

Access is what an agent's token may do in its repository: AccessWrite (the default) or AccessRead. It is the ONLY input to the agent mint's permission levels (agentMintRequest).

const (
	// AccessWrite: contents + pull_requests write, checks + statuses read.
	AccessWrite Access = "write"
	// AccessRead: contents, pull_requests, checks and statuses all read.
	AccessRead Access = "read"
)

func ParseAccess added in v0.108.0

func ParseAccess(v string) (Access, error)

ParseAccess reads an access mode as the operator wrote it: "" (unset) is AccessWrite, so a deployment that never set it is unchanged; "read" and "write" (any case, surrounding space ignored) are themselves; anything else is an error — a typo must never fall back to a wider grant.

func (Access) Scope added in v0.108.0

func (m Access) Scope() string

Scope is what an agent's installation token may do in its own repository in mode m, as every user-visible description of the connector says it (the Connectors tab, the approve card, connector_requests_list, the boot banner). It is derived from the same permission levels the mint asks for, so the text cannot claim a level the token does not carry.

type Account

type Account struct {
	Login string
	ID    int64
}

Account is one allowlisted GitHub account: its immutable numeric ID (what is matched) and the login it was listed under (a label, and the rename check).

type App

type App struct {
	// contains filtered or unexported fields
}

App is a configured GitHub App.

func New

func New(cfg Config) (*App, error)

New builds an App. It makes no network call; Check does.

func (*App) Access added in v0.108.0

func (a *App) Access() Access

Access is the agent tokens' permission mode (never "").

func (*App) AppID

func (a *App) AppID() int64

AppID is the configured App ID.

func (*App) Check

func (a *App) Check(ctx context.Context) ([]string, error)

Check lists the (allowlisted) installations, recording the outcome as the App-wide problem. cmd/muster-server runs it once at boot, in the background.

func (*App) CreatedAt added in v0.175.0

func (a *App) CreatedAt(ctx context.Context) (time.Time, error)

CreatedAt reads when the App was created (GET /app's created_at, as the App): no pull request of its bot is older, so a shipping officer's listing of them stops there (internal/officership REST.OfficerPRs). An answer without it is an error, never a zero time.

func (*App) Credential

func (a *App) Credential(ctx context.Context, caller connectors.Caller, host, rest string) (string, bool, error)

Credential is the installation token for caller's own repository; a request for one of caller's read repositories (caller.ReadRepos) gets a READ-ONLY token for that repository; a request for ANY OTHER repository is anonymous (no credential at all); a request whose repository cannot be decided is refused (targetRepo). A path that names no repository (/graphql) is served with the own repository's token.

func (*App) DefaultBranch

func (a *App) DefaultBranch(ctx context.Context, repo string) (string, error)

DefaultBranch reads repo's default branch with the installation's listing token.

func (*App) Describe

func (a *App) Describe() connectors.Connector

Describe is the `github` connector's public description: the same hosts and auth shape as the GitHub preset (basic, username x-access-token — the one shape both git over HTTPS and the REST API accept), with no stored secret.

func (*App) ListPullRequests

func (a *App) ListPullRequests(ctx context.Context, agentID int64, repo, state string) ([]github.PullRequest, error)

ListPullRequests lists agentID's own repository's pull requests with that agent's repository token (server-side; the worker tool returns only the list).

func (*App) Problem

func (a *App) Problem(agentID int64) string

Problem is the operator-facing reason the App cannot currently serve agentID: an App-wide failure (its credentials refused, rate limited) first, else that agent's last mint failure. "" when nothing is known to be wrong.

func (*App) PullRequestCommits added in v0.193.0

func (a *App) PullRequestCommits(ctx context.Context, repo string, n int64) ([]string, error)

PullRequestCommits lists pull request n's commit shas, oldest first, with the same repository-limited read token as PullRequestState (pull requests read). A force-pushed-away head is not among them. Every failure is an error, which the caller reads as "order unknown".

func (*App) PullRequestState added in v0.137.0

func (a *App) PullRequestState(ctx context.Context, repo string, n int64) (PRState, error)

PullRequestState reads pull request n of repo with a token limited to that repository and pull requests read (prReadToken): muster's own server-side read, never handed to an agent. Every failure — a repository whose owner has no allowlisted installation, a 404, a 5xx, ctx's deadline, a busy mint lock — is an error, which the caller reads as "unknown".

func (*App) Rejected

func (a *App) Rejected(caller connectors.Caller)

Rejected drops every cached token of caller's: GitHub answered 401 to one (revoked, or the installation's access changed), so the next request mints.

func (*App) Renames

func (a *App) Renames() []string

Renames are the allowlisted accounts whose login on GitHub differs from the listed one, as "listed→current (id)", sorted.

func (*App) RepoToken added in v0.110.0

func (a *App) RepoToken(ctx context.Context, repo string) (string, error)

RepoToken is a token for repo minted in the App's own mode, for muster's own server-side calls on a shipping officer's behalf (merge, tag). It is never injected into an agent's request: the proxy takes its credential from Credential (or a connectors.Gate), not from here.

func (*App) Repos

func (a *App) Repos(ctx context.Context) ([]github.Repo, error)

Repos lists every repository the App's installation(s) can access — the Repos tab, the dispatch pickers and every connected-repository check.

func (*App) Slug added in v0.110.0

func (a *App) Slug(ctx context.Context) (string, error)

Slug reads the App's own slug (GET /app, as the App). The App's bot account is `<slug>[bot]`: the identity its pull requests are authored by, which a shipping officer's merge gate compares against (internal/officership). Read fresh on every call — a renamed App changes its slug.

type Config

type Config struct {
	AppID      int64
	PrivateKey *rsa.PrivateKey
	// Access is the agent tokens' permission mode; "" means AccessWrite. New
	// refuses any other value.
	Access Access
	// Accounts are the GitHub accounts (users or organizations) whose
	// installations are used, matched by ID. REQUIRED: New refuses an empty
	// list or an entry with no ID, because the App is installable by anyone.
	Accounts []Account
	// BaseURL is the REST API base; "" means github's (github.APIBaseURL()).
	BaseURL string
	// GitHost and APIHost are the hosts the connector serves; "" means
	// DefaultGitHost / DefaultAPIHost.
	GitHost, APIHost string
	HTTP             *http.Client
	Now              func() time.Time
	Logger           *log.Logger
}

Config is what New needs.

type PRState added in v0.137.0

type PRState struct {
	State  string
	Merged bool
}

PRState is a pull request's state as GitHub reports it: State "open" or "closed", and Merged when a closed one was merged.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL