Loading
Add granular token support for design image endpoints
What does this MR do and why?
Follow-up to !246866 (merged), which added token authentication for design management images but denies granular PATs outright, because no design permission was assignable and authorize_granular_token! therefore had nothing to enforce (see the AppSec discussion in !246866 (comment 3598447904)).
This MR adds real granular token support for the design image endpoints:
- Defines the
read_designraw permission (config/authz/permissions/design/read.yml) and removes it fromdefinitions_todo.txt. - Grants
read_designthrough the existing Work Item: Read assignable permission rather than a standalone "Design: Read" toggle. Designs are subordinate to work items, and keeping discovery (GraphQL design metadata) and retrieval (image endpoints) under one permission avoids tokens that can fetch images they cannot discover, and vice versa. Correction: an earlier version of this description claimed design metadata was already granted to granular tokens throughread_issueonTypes::IssueType— that was wrong.DesignType/DesignCollectionTypecarry noauthorize_granular_tokendirective, and granular tokens are denied by default on types without one, so granular tokens currently cannot read design metadata through GraphQL at all, regardless of scope. Adding those directives (gated byread_design) is a follow-up — see the discussion in !246945 (comment 3607328280). - Maps the
:designsessionless format toread_designinGranularTokenAuthorization::GRANULAR_FORMAT_PERMISSIONS, soauthorize_granular_token!enforces granular scopes on these requests like it does forarchiveanddownload. - Removes the temporary outright denial of granular tokens from
Projects::DesignManagement::DesignsController. - Adds
read_designto thepublic_anonymousrole so granular tokens without an explicit scope keep working on public projects, matching anonymous access (authorize_read_design!still applies). - Replaces the granular-deny shared example with three cases: a granular PAT with Work Item: Read on the project is served the image; one holding only an unrelated permission (Release: Read) on the same project gets a 404; one without any scope gets a 404.
Dependency: this MR targets the branch of !246866 (merged) and is marked Draft until that MR merges; it should be retargeted to master afterwards (GitLab does this automatically when the parent branch is deleted on merge).
How to set up and validate locally
- On a private project, add a design to an issue and create a granular PAT whose scope grants Work Item: Read on that project.
curl -i -H "PRIVATE-TOKEN: <token>" "<raw_image url>"returns the image (200).- A granular PAT without that permission (for example, scoped to an unrelated project) gets a
404. bundle exec rake gitlab:permissions:validatepasses.
References
- Parent MR: !246866 (merged)
- AppSec review discussion: !246866 (comment 3598447904)
Edited by Marcel van Remmerden