GitLab backend: login check depends on where the user's role comes from
Describe the bug
The login check of the GitLab backend (hasWriteAccess in packages/decap-cms-backend-gitlab/src/API.ts) gives different answers for the same GitLab role, depending on where the user gets it from. GitLab grants the same rights in all these cases:
| Where the Developer role comes from | Decap today |
|---|---|
| Direct member of the project | Let in |
| Member of the project's group or of an ancestor group | Let in |
| Group invited to the project | Let in only if developers_can_push and developers_can_merge are both true on the default branch |
| Group invited to an ancestor group of the project | Refused: "Your GitLab user account does not have access to this repo." |
Maintainers and Owners are let in in the first three cases, and refused in the last one.
Why:
- A group invited to an ancestor group appears nowhere in
GET /projects/:id:permissions.project_accessandpermissions.group_accessarenull, andshared_with_groupsonly lists the groups invited to the project itself. - For groups invited to the project, Decap reads the level of the invitation, not the user's role: a Reporter of a group invited as Maintainer is let in (noted while testing #3122).
developers_can_pushanddevelopers_can_mergeare only true on a protected branch that explicitly allows Developers. On an unprotected branch, both arefalse. A Developer through an invited group is therefore refused when the default branch is not protected at all.- The branch check added in #3122 does not apply to direct members, and ignores the publish mode, although with
publish_mode: editorial_workflow, saving an entry only pushes its owncms/…branch and opens a merge request.
To Reproduce
- Create a group
parentand a projectparent/site, withmainprotected (Maintainers allowed to push and merge). - Create a group
teamand add a user as Developer or Maintainer ofteamonly. - In
parent→ Manage → Members, invite the groupteam. - Configure Decap with the GitLab backend on
parent/siteand log in as that user. - See "Your GitLab user account does not have access to this repo."
For that user, GET /projects/parent%2Fsite/members/all/<user id> returns the role GitLab applies: "access_level": 30 or 40.
Expected behavior
The check depends on the user's effective role on the project, whatever gives it, and on the publish mode:
| Publish mode | Let in if |
|---|---|
editorial_workflow |
Effective access level ≥ Developer (30), whether the branch is protected or not |
| Simple | can_push is true on the configured branch, whatever the role |
Everyone else (Reporter, Guest…) is refused.
Proposed implementation, replacing the checks on permissions, shared_with_groups and developers_can_*:
- Effective role:
GET /projects/:id/members/all?user_ids[]=<id>&state=activereturns the highest active membership of the user across direct membership, ancestor groups, groups invited to the project and groups invited to ancestor groups. An empty list means no role. - Simple mode:
GET /projects/:id/repository/branches/:branchreturnscan_push, computed for the current user with the branch protection rules.
members/all/:user_id exists since GitLab 12.4, counts groups invited to the project at least since 13.7, and groups invited to ancestor groups since 16.0. On older versions, the last case stays refused, as today.
Out of scope, see #8015: with the editorial workflow, a Developer on a protected branch still sees Publish, which GitLab refuses to merge, and media library uploads and deletions, as well as deleting a published entry, still write to the base branch.
Applicable Versions:
- Decap CMS version: 3.16.3 (decap-cms-core 3.19.1), the check is unchanged on
main - Git provider: GitLab (self-managed)
- OS / Browser: not specific
CMS configuration
backend:
name: gitlab
repo: parent/site
branch: main
base_url: https://gitlab.example.com
api_root: https://gitlab.example.com/api/v4
auth_type: pkce
app_id: <application id>
publish_mode: editorial_workflowAdditional context
Follows #3120 and #3122, which added shared_with_groups for groups invited to the project. A PR will follow.
Source: decaporg/decap-cms