JuliusBrussee/caveman · error
githubapp: sign app jwt
Error message
githubapp: sign app jwt: %w
What it means
AppJWT signs the GitHub App JWT with RS256 (rsa.SignPKCS1v15 over a SHA-256 digest of the signing input) and wraps any signing failure in this error. Signing failure means the App's private key could not produce a signature — almost always a malformed or unsupported key rather than a runtime condition.
Solutions
- Confirm the PEM is an RSA private key (openssl rsa -in key.pem -check); re-export from GitHub App settings if unsure
- Verify parseRSAPrivateKey handles both PKCS#1 and PKCS#8 PEM blocks and that the secret wasn't mangled (line endings, HTML-escaped characters)
- Check the error wrapped in %w for the exact crypto reason and fix accordingly
- If rand.Reader failed, investigate OS entropy availability (rare; mostly containers with restricted /dev/urandom)
Example fix
// before: EC key passed where RSA required
keyPEM := loadECKey()
app, _ := githubapp.New(githubapp.Config{AppID: id, PrivateKeyPEM: keyPEM})
// after: ensure RSA key
if !strings.Contains(string(keyPEM), "RSA PRIVATE KEY") && !isPKCS8RSA(keyPEM) {
return fmt.Errorf("github app key must be RSA")
} Defensive patterns
Strategy: try-catch
Validate before calling
if blk, _ := pem.Decode(keyPEM); blk == nil || !strings.Contains(blk.Type, "PRIVATE KEY") {
return errors.New("key must be a PEM RSA private key")
}
if _, err := x509.ParsePKCS1PrivateKey(blk.Bytes); err != nil {
if _, err2 := x509.ParsePKCS8PrivateKey(blk.Bytes); err2 != nil {
return errors.New("key is not a valid RSA private key")
}
} Try / catch
jwt, err := app.AppJWT(ctx)
if err != nil && strings.Contains(err.Error(), "sign app jwt") {
// key unusable for RS256: reload/re-export the RSA key, alert ops
return ErrAppKeyUnusable
} Prevention
- Verify key type with openssl at deploy time (must be RSA)
- Round-trip secrets as raw bytes, never through JSON/HTML escaping
- Add a startup self-test that mints and parses one AppJWT
When it happens
Trigger: Calling AppJWT (directly or via GetInstallation, MintInstallationToken, GetRepoInstallation) when rsa.SignPKCS1v15 errors — typically because a.privateKey is not a valid RSA key (e.g. an EC key parsed into the wrong field) or rand.Reader fails.
Common situations: The configured PEM contained an EC or Ed25519 key instead of an RSA private key; the key was corrupted during base64/secret round-tripping; exotic crypto builds lacking PKCS#1 v1.5 support.
Related errors
- githubapp: app id is required
- githubapp: base_url rejected by SSRF guard
- githubapp: installation id must be positive
- githubapp: private key is not RSA
- aes cipher
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/e0c9cdd7ad5aac48.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/githubapp/githubapp.go:133
header := map[string]string{"alg": "RS256", "typ": "JWT"}
claims := map[string]any{
"iat": now.Add(-60 * time.Second).Unix(),
"exp": now.Add(10 * time.Minute).Unix(),
"iss": a.appID,
}
hb, err := json.Marshal(header)
if err != nil {
return "", err
}
cb, err := json.Marshal(claims)
if err != nil {
return "", err
}
signingInput := base64.RawURLEncoding.EncodeToString(hb) + "." + base64.RawURLEncoding.EncodeToString(cb)
digest := sha256.Sum256([]byte(signingInput))
sig, err := rsa.SignPKCS1v15(rand.Reader, a.privateKey, crypto.SHA256, digest[:])
if err != nil {
return "", fmt.Errorf("githubapp: sign app jwt: %w", err)
}
return signingInput + "." + base64.RawURLEncoding.EncodeToString(sig), nil
}
// InstallationToken is the JIT, least-agency credential. It is scoped to the
// single repo named and to the supplied permissions only, and is NEVER
// persisted. The caller revokes it via RevokeToken at job end.
type InstallationToken struct {
Token string `json:"token"`
ExpiresAt time.Time `json:"expires_at"`
}
// Installation is the App-authenticated identity GitHub assigns to an install.
// Callers use it to reject callback-supplied ids that do not belong to this App.
type Installation struct {
ID int64 `json:"id"`
Account struct {
Login string `json:"login"`View on GitHub (pinned to 3ee70a1026)