[JENKINS-73060] Fix missing authorities #302
Open
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.
This should fix JENKINS-73060.
This updates
loadByUsername2to always use the authorities retrieved in theGithubAuthenticationTokenwhen constructing theGithubOAuthUserDetailsobject. Previously, this plugin would try to load aGHUserobject (either from theuserByIdCacheor the Github API) and would pass an empty list of authorities when theGHUserwasnull.I couldn't find a logical reason for why we would need this check when we do not use the
GHUserobject to set the authorities. This check seems to be a carry over from when theGHUserwas used in thegetGrantedAuthoritiesmethod to fetch/set authorities before 99e3d13.There's also a secondary bug here where
loadUserwill not make the API call to retrieve theGHUserfrom the Github API ifghisnull(which is usually the case when the token used to constructGithubAuthenticationTokenis in theusersByTokenCache). This null check shouldn't be needed due to changes introduced in #61. However, I chose not to remove this check due to possible performance degradation as seen in #256.Testing done
We've been running this patch in our Production environment without issue since June 12. We're not seeing any performance degradation on our Jenkins instance with this patch.
Steps to Reproduce
Clone this project & execute
mvn hpi:runInstall the following additional plugins:
Authorize ProjectRole-based Authorization StrategyConfigure the Github plugin as the security realm
Configure
Authorizationto use theRole-Based StrategyAssign a Github team (i.e.
ORG*TEAMNAME) the defaultadminpermission in<jenkins_url>/manage/role-strategy/assign-rolesConfigure
Access Control for Buildsto useProject default Build Authorization->Run as User who Triggered BuildCreate a pipeline
Example
pipeline { agent any stages { stage('Test') { steps { echo "Hello world!" } } } }Navigate to the build page -> Select
log outin the top right -> Hit back button -> SelectBuild NowBuild should hang for roughly 1 minute with the following error even though the user should be a member of a Github team with
adminpermissions on the Jenkins instance.Install this patch
Navigate to the build page -> Select
log outin the top right -> Hit back button -> SelectBuild NowIssue should no longer occur
Submitter checklist