Skip to content

feat(github-app): share installation tokens as host rules - #780

Open
meik99 wants to merge 1 commit into
mogenius:mainfrom
meik99:main
Open

meik99 wants to merge 1 commit into
mogenius:mainfrom
meik99:main

Conversation

@meik99

@meik99 meik99 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This allows presets from one organization to be discoverable easily from renovate jobs running for different organizations of the same enterprise.

Comment on lines +675 to +690
if name := hostRulesSecretName(job); name != "" {
volumes = append(volumes, v1.Volume{
Name: hostRulesVolumeName,
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: name,
Items: []v1.KeyToPath{{Key: github.HostRulesConfigFileKey, Path: github.HostRulesConfigFileKey}},
},
},
})
volumeMounts = append(volumeMounts, v1.VolumeMount{
Name: hostRulesVolumeName,
MountPath: hostRulesMountPath,
ReadOnly: true,
})
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This volume projects host-rules.json and isn't optional, so the pod can only start if the Secret exists and has that key.

This breaks when app credentials are revoked or when a install token generation fails. Pods get then hang with a "ContainerCreating" blocking a parallelism slot.

I'd make the "empty" state valid config {"hostRules":[]} rather than no data. Pods would start and simply get no shared rules

@meik99 meik99 Nov 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both is implemented now, the secret mount has the optional flag in case the creation of the "empty" secret still fails. also a secret holding empty host rules is now created at the start of ensureHostRules if it does not exist yet, so if something fails afterwards at least there is a secret to mount
https://github.com/mogenius/renovate-operator/pull/780/changes#diff-31b5c456966fc05bd3f5bfc7b9d734e44810a5aef1ba7adee6b6d9b681db71f9R59-R63

Hope it is okay if I resolve the other comments referencing this issue

Comment thread src/github/githubAppHostRules.go Outdated
}

func (g *githubappToken) MintInstallationToken(appID, installationID, pemString, githubApi string) (string, time.Time, error) {
return g.createGithubAppTokenDetailed(appID, installationID, pemString, githubApi)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tokens are minted without a permissions body, so each one can do everything the App can do on that org, typically contents: write and pull_requests: write.

For presets and lookups, read access is enough: {"permissions":{"contents":"read","metadata":"read"}} POST /app/installations/{id}/access_tokens accepts that. Scoping the tokens down limits the damage the Security note in the docs warns about.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +79 to +80
// The previous Secret stays: its tokens may still be valid.
return fmt.Errorf("minting hostRules token for installation %d (%s): %w", inst.ID, inst.Account, err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any single installation fails to generate a token this returns and throws away the tokens already generated. Renewal is then blocked for every installation, and within about 30 minutes all shared tokens have expired. The retry runs every minute and mints N tokens each time, only to drop them again. Could we skip the installation that fails, keep the rest, and report it through failures?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, tokens that have not expired are now reused and failures are collected

Comment on lines +160 to +163
Each generated `RenovateJob` reads only the repositories of its own
installation. With `hostRules` enabled, every generated `RenovateJob` also gets
the tokens of other installations of the App, so a run for one account can
resolve presets and GitHub API lookups hosted in another:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules match only /repos//. Graphql isn't covered which is used for github-tags and github-releases datasources and github.com//... for git-refs, Go modules and clones

I'd narrow the wording to presets and REST repos/ calls, so nobody expects private release lookups across orgs to work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread src/github/githubAppHostRules.go Outdated
cfg := hostRulesConfig{HostRules: make([]hostRule, 0, len(tokens))}
for _, t := range tokens {
cfg.HostRules = append(cfg.HostRules, hostRule{
MatchHost: base + "/repos/" + t.Account + "/",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renovate matches matchHost paths case-sensitively, and these rules use the login exactly as GitHub returns it. A preset referenced as github>org-a/… won't match an org whose login is Org-A. Could you add a sentence to the hostRules section of the docs saying that preset references must use the exact login?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@meik99
meik99 force-pushed the main branch 4 times, most recently from 28ba40a to 30807ed Compare November 30, 2026 12:36
Signed-off-by: Michael Rynkiewicz <michael.rynkiewicz@dynatrace.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants