Skip to content
Light Dark

GitLab 19.x demands Repository: Create for the Files API

(Updated: ) - 1 min

Drafted with AI assistance from notes I took during real work.

GitLab 19.x now refuses classic api tokens on the Repository Files API create endpoint. A file-creation call that used to work returns 403 insufficient_granular_scope and names the missing permission: Repository: Create. The fix is a new fine-grained personal access token scoped to the project.

I hit this in a Cloudflare Worker that creates “comment” merge requests. Submitting a comment returned “Sorry, there was an error”, and the Worker log showed GitLab rejecting the file-creation call with that exact 403.

First I chased the wrong fixes. The token had been rotated in July and was still valid, so expiry was out. Removing author_name and author_email from the Files API body changed nothing; the 403 stayed byte-for-byte identical. Classic scopes api and write_repository looked right, and with the same token GET and POST /repository/branches succeeded. The token already had API-level write access. Only the file and commit step was refused.

Mapping the flow to fine-grained permissions made it clear: GET branch needs Branch: Read, POST branch needs Branch: Create, POST files needs Repository: Create, and POST merge_requests needs Merge Request: Create.

I created a new fine-grained token scoped to the project with Repository: Read and Create, Branch: Read and Create, and Merge Request: Create. Rotating the Cloudflare secret restored comment MRs.

Fine-grained grants are immutable: you cannot add a permission to an existing token, so you must create a new one. Branch: Create, Code: Push, or Commit: Create do not satisfy Repository: Create. When the 403 names the permission, read it literally.

Antenore Gatta

Antenore Gatta

A proud and busy Hacker, Father and Kyndrol

Support This Work

If this field note saved you an outage, consider supporting the blog.

Most readers scroll past. Less than 3% of readers contribute to keeping independent technical content free and accessible.

Post comment

Markdown is allowed, HTML is not. All comments are moderated.