Fetch private project and group avatars through the API (#690)#767
Open
rpaasche wants to merge 1 commit into
Open
Fetch private project and group avatars through the API (#690)#767rpaasche wants to merge 1 commit into
rpaasche wants to merge 1 commit into
Conversation
The /uploads/-/system/.../avatar web URLs need a browser session, so anonymous fetches 401 on private projects and groups and we end up showing a generated avatar. Detect those URLs, take the id from the path and download the image via ProjectApi/GroupApi.getAvatar() using the matching server's credentials. The fetch runs on a background thread with no authenticated user, so the credential lookup is wrapped in ACL.as2(SYSTEM2). If the API call fails (e.g. an older GitLab without the endpoint) we fall back to the plain URL, which still works for public projects and groups; user avatars and unknown hosts keep using that path too.
rpaasche
force-pushed
the
fix/690-private-avatar-401
branch
from
July 21, 2026 16:01
a548dde to
a77d9da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
/uploads/-/system/.../avatarweb URLs need a browser session, so anonymous fetches 401 on private projects and groups and we end up showing a generated avatar. Detect those URLs, take the id from the path and download the image viaProjectApi/GroupApi.getAvatar()using the matching server's credentials.The fetch runs on a background thread with no authenticated user, so the credential lookup is wrapped in
ACL.as2(SYSTEM2). If the API call fails (e.g. an older GitLab without the endpoint) we fall back to the plain URL, which still works for public projects and groups; user avatars and unknown hosts keep using that path too.Fixes #690 (JENKINS-64814).
Trade-offs worth noting for review:
credentialsId, so credentials are resolved from the matching server's configuration. Setups that configure the token only on the folder/source (and leave the server without credentials) will still fall back to the placeholder for private resources.getAvatar()exposes noLast-Modified, so the browser re-fetches once per hourly cache refresh (304s still work within a refresh window).Testing done
GitLabAvatarCacheTest) cover the URL→server/type/id matching: project and group avatars, a server URL with a trailing slash, a server hosted under a sub-path, and the cases that must not match (user avatars, other hosts, an id too large to parse).JenkinsRuletest (GitLabAvatarCacheCredentialsTest) locks in the regression this PR fixes: on a secured instance, resolving the server credentials directly as the anonymous background user throwsAccessDeniedException, while the avatar fetch resolves the token successfully via theSYSTEMimpersonation.HTTP 401for.../uploads/-/system/group/avatar/<id>/...and rendered the generated placeholder; after the change (re-scan + reload) the real avatar renders. Confirmed viaFINElogging that the API path runs (Fetching avatar via API: ...) and decodes the image.Submitter checklist