Contextualize credentials used by GitSCMFileSystem
when possible
#1802
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
After jenkinsci/github-branch-source-plugin#822, credential lookups for
GitHubAppCredentials
configured to use an inference-based repository access strategy fail when usingGitSCMFileSystem
. NormallyGitHubSCMFileSystem
is used instead ofGitSCMFileSystem
, and that works fine, butGitSCMFileSystem
gets used in cases where you have to configure aGitSCM
directly, since there is no GitHub-specific SCM implementation.For example, you can run into this problem if you use "Pipeline script from SCM" to configure a Pipeline, enable lightweight checkout, and use
GitHubAppCredentials
for theGitSCM
credentials.For more context, credential lookups for
GitHubAppCredentials
were expected to fall into one of two cases:Connector.lookupScanCredentials
. This ensures proper owner inference and bypasses repository inference because the credential usage context is trusted. Plugins that need to do this kind of lookup may require changes like Use Connector.lookupScanCredentials to contextualize GitHubAppCredentials github-checks-plugin#398 (but others were already usingConnector.lookupScanCredentials
).withCredentials
step. Plugins that need to do this kind of lookup need to useCredentialsProvider.findCredentialById
and pass an appropriateRun
context for proper owner and repository inference, like is already done in this plugin inGitSCM.lookupScanCredentials
.GitSCMFileSystem
is a bit of an awkward spot. Conceptually, it falls under case 1 and should useConnector.lookupScanCredentials
to contextualizeGitHubAppCredentials
for a trusted context, but we can't add agithub-branch-source
dependency here or else we'll have circular dependencies. This leaves us with two options:credentials
that is comparable toCredentials.forRun
that allows contextualization of generic credential lookups, and avoids the need to useConnector.lookupScanCredentials
directly when working withGitHubAppCredentials
GitHubSCMFileSystem
withGitSCM
, or a GitHub-specific SCM implementation or similar that bypassesGitSCMFileSystem
in this caseGitSCMFileSystem
, although repository inference strategies would still not be supportedCC @jeromepochat
Testing done
See new automated test.
Submitter checklist