Skip to content

Add githubAppClientID as an alternative to githubAppID - #1296

Open
Erik-Schuetze wants to merge 2 commits into
fluxcd:mainfrom
Erik-Schuetze:githubapp-client-id
Open

Add githubAppClientID as an alternative to githubAppID#1296
Erik-Schuetze wants to merge 2 commits into
fluxcd:mainfrom
Erik-Schuetze:githubapp-client-id

Conversation

@Erik-Schuetze

Copy link
Copy Markdown

Refs: #1291

GitHub accepts either the numeric AppID or the ClientID of GH Apps as the JWT iss claim, and recommends the ClientID in the official docs (GitHub, GHE). pkg currently only accepts the numeric AppID, so this PR adds githubAppClientID as an alternative across auth/githubapp (the JWT consumer) and runtime/secrets (the secret writer and reader). Existing secrets using only AppID are unaffected.

AppID and ClientID are treated as mutually exclusive. This is enforced in New, MakeGitHubAppSecret, and GitHubAppDataFromSecret, mirroring the existing installationOwner / installationID handling.
They identify the same app for a single iss claim, so this keeps the behaviour unambiguous and avoids silently ignoring one identity when both are supplied.
The ClientID is treated as a regular string, since GitHub documents no format for it (The ClientIDs I checked on GHE and GitHub also differed from each other with no common prefix).
As pkg is a GA dependency consumed by all Flux controllers, MakeGitHubAppSecret keeps appID as a positional parameter and adds clientID via an option, because any change to the positional parameters of this exported function would break every existing consumer.
If the preferred solution is to change to symmetric options (WithGitHubAppID + WithGitHubAppClientID) and accept the function signature break, I'm happy to switch.

Two behaviour changes to note, given the GA compatibility guarantee:

  • changed the error message of MakeGitHubAppSecret from "githubAppID is required" to "exactly one of githubAppID or githubAppClientID must be provided".
  • buildCacheKey now includes the ClientID, which causes a new token to be requested on version upgrade (a one-time, self-healing re-fetch of short-lived installation tokens).

I applied the change across auth/githubapp and runtime/secrets in pkg so the new ClientID is usable end-to-end. If you prefer I can split it into two PRs.

I added Tests for client-ID-only, both-set (rejected), and neither-set across writer, reader, and JWT issuer generation; make test-auth and make test-runtime pass.

GitHub recommends using the App client ID (e.g. Iv23li...) rather than the
numeric App ID as the JWT iss claim; both remain valid. This adds githubAppClientID
across both pkg modules, fully backward compatible.

auth/githubapp: new KeyAppClientID const and clientID field; WithAppData reads it
as an opaque string; New requires at least one of appID/clientID; createJWT uses
clientID as the issuer when set (else the numeric appID); buildCacheKey includes
clientID to avoid cache-key collisions for client-ID-only clients.

runtime/secrets: new KeyGitHubAppClientID const and WithGitHubAppClientID option;
MakeGitHubAppSecret keeps appID positional (non-breaking) and requires exactly one
of appID/clientID; GitHubAppDataFromSecret requires at least one and passes both
through when present.

Refs: fluxcd#1291
Signed-off-by: Erik Schuetze <erik.schuetze@sap.com>
Assisted-by: claude-code/claude-opus-4-8
Following review, treat appID and clientID as mutually exclusive identities
for one app (mirroring the existing installationOwner/installationID pattern),
rather than allowing both with clientID taking precedence.

New, MakeGitHubAppSecret, and GitHubAppDataFromSecret now all reject a secret
that sets both identities. This removes the JWT issuer precedence question
entirely and avoids silently ignoring one identity when a user supplies a valid
one alongside an invalid one. The reader names both keys in its error instead of
only githubAppID. Backward compatible: appID-only secrets are unaffected.

Also fold the jwt/v4 test import into the third-party group.

Signed-off-by: Erik Schuetze <erik.schuetze@sap.com>
Assisted-by: claude-code/claude-opus-4-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant