JuliusBrussee/caveman · error
githubapp: permission
Error message
githubapp: permission %q=%q exceeds the least-agency allowlist
What it means
Token permissions are restricted to an explicit least-agency allowlist: only "contents" and "pull_requests", each limited to "read" or "write". Any other permission name or level (e.g. "administration", "workflows", "admin") is rejected before network I/O, so the app can never mint a token that merges code or alters repo settings.
Solutions
- Restrict perms to {"contents":"read"|"write", "pull_requests":"read"|"write"} or pass nil for the defaults (contents:write + pull_requests:write)
- Fix key spelling to GitHub's snake_case names within the allowlist
- Remove any broader permission (admin, workflows, etc.) — the library will not allow them by design
Example fix
// before
perms := map[string]string{"contents": "write", "workflows": "write"}
// after
perms := map[string]string{"contents": "write", "pull_requests": "write"} Defensive patterns
Strategy: validation
Validate before calling
var allowedPerms = map[string]bool{"contents": true, "pull_requests": true}
for name, level := range perms {
if !allowedPerms[name] || (level != "read" && level != "write") {
return fmt.Errorf("permission %s=%s not allowed", name, level)
}
} Type guard
func permsAllowlisted(perms map[string]string) bool {
for n, l := range perms {
if !(n == "contents" || n == "pull_requests") || (l != "read" && l != "write") {
return false
}
}
return true
} Try / catch
tok, err := app.MintInstallationToken(ctx, id, []string{repo}, perms)
if err != nil {
if strings.Contains(err.Error(), "least-agency allowlist") {
// drop the offending permission or pass nil for defaults
}
return err
} Prevention
- Pass nil perms to get the safe defaults (contents:write + pull_requests:write)
- Centralize permission constants instead of inline maps
- Never request admin/workflows/repo-level broad permissions — the allowlist forbids them by design
When it happens
Trigger: App.MintInstallationToken called with perms containing an unlisted key (e.g. {"contents":"write","workflows":"write"}), an unsupported level ("admin", "none"), or a mix of valid and invalid entries — one bad entry fails the whole call.
Common situations: Copy-pasting permission maps from GitHub's docs that include broader scopes; generic token-minting helpers passing through caller-supplied perms; typos like "pull-request" instead of "pull_requests".
Related errors
- githubapp: exactly one repository is required
- cannot persist MCP ownership journal at
- cave_sandbox_side_effect_denied
- create
- githubapp: app id is required
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/188bcabfd9f664f2.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/githubapp/githubapp.go:202
// `repos` and `perms`, returning a ~1h token. Defaults (perms nil) are
// contents:write + pull_requests:write — enough to push a branch and open a draft
// PR, never to merge.
func (a *App) MintInstallationToken(ctx context.Context, installationID int64, repos []string, perms map[string]string) (InstallationToken, error) {
if installationID <= 0 {
return InstallationToken{}, fmt.Errorf("githubapp: installation id must be positive")
}
if len(repos) != 1 || strings.TrimSpace(repos[0]) == "" {
return InstallationToken{}, fmt.Errorf("githubapp: exactly one repository is required")
}
repository := strings.TrimSpace(repos[0])
if perms == nil {
perms = map[string]string{"contents": "write", "pull_requests": "write"}
}
allowedPermissions := map[string]bool{"contents": true, "pull_requests": true}
scopedPermissions := make(map[string]string, len(perms))
for name, level := range perms {
if !allowedPermissions[name] || (level != "read" && level != "write") {
return InstallationToken{}, fmt.Errorf("githubapp: permission %q=%q exceeds the least-agency allowlist", name, level)
}
scopedPermissions[name] = level
}
jwt, err := a.AppJWT()
if err != nil {
return InstallationToken{}, err
}
body := map[string]any{"permissions": scopedPermissions, "repositories": []string{repository}}
status, raw, err := a.do(ctx, "Bearer "+jwt, http.MethodPost,
"/app/installations/"+strconv.FormatInt(installationID, 10)+"/access_tokens", body)
if err != nil {
return InstallationToken{}, err
}
if status != http.StatusCreated {
return InstallationToken{}, fmt.Errorf("githubapp: mint token: HTTP %d: %s", status, snippet(raw))
}
var out InstallationToken
if err := json.Unmarshal(raw, &out); err != nil {View on GitHub (pinned to 3ee70a1026)