Skip to content

Recognize GitLab token types (personal / project / group) and their reach when resolving repositories #2

Closed

Description

@gorlix

Context: the multi-repo project connections in Paca-AI/paca#648, and the follow-up to Paca-AI/paca-plugins#34. Related core proposal: Paca-AI/paca#649. Text-only proposal against feature/update-git-workflow, for agreement before code.

Problem

Once a Paca project links several GitLab repositories, users will often add one project access token per repository, or a group access token. Each kind reaches different projects. The provider doesn't tell them apart: identityRecord.Bot is true for both project and group tokens (accessTokenBotRe in gitlab.go), and nothing records what a token covers.

  1. A public repository can bind to the wrong connection.
    • ResolveRepository takes the first candidate that can GET /projects/:path. A public project answers any token (see the comment in spi_provider.go).
    • So acme/api (public) can be bound to the project token of acme/ui. The link succeeds and reads work, but pushes, comments and EnsureWebhook fail later.
    • MintCredential only refuses writes when GitLab reports 0 < access_level < Developer, so a non-member (level 0) still gets a credential.
  2. Users can't see what a connection covers. The connection list shows only the bot handle (project_123_bot_abc).
  3. Unhelpful error. When no connection covers a repo, the error is "no identity can see acme/api", with no hint that another connection or a group token is needed.

Proposal (provider only, no SDK change)

1. Detect the token type and reach at setup

In CompleteIdentitySetup, after validateToken, classify the token from the bot user name:

Username Type Reach Lookup
project_<id>_bot… project that project GET /projects/<id> → path_with_namespace
group_<id>_bot… group the group and its subgroups GET /groups/<id> → full_path
anything else personal the user's memberships none
  • Store TokenType, ResourceID and ResourcePath on identityRecord, with new columns on gitlab_identities (a new migration).
  • If the lookup fails (for example a token without read_api on the group), keep the type and leave the path empty.

2. Show the reach

identityOf sets Identity.DisplayName to, for example:

  • "Project token · acme/ui";
  • "Group token · acme/frontend";
  • "Personal token · alice".

Core already shows the display name in Project Settings → Git → Connections.

3. Filter candidates in ResolveRepository

Before any API call:

  • a project token is skipped unless ResourceID equals the project id (or ResourcePath equals the path, when the input is a path);
  • a group token is skipped unless the repo path is ResourcePath or below it.

After GET /projects/:path, require accessLevel() >= Developer (30). Otherwise move to the next candidate. A token that can only read a public project never wins.

ListRepositories already uses membership=true, so it lists only what the token is a member of. No change is needed there.

4. Tighten MintCredential

For AccessWrite, also refuse level 0 (non-member) instead of only 0 < level < Developer.

5. Clear errors

When every candidate is skipped, return CodeForbidden / CodeNotFound with a message that names what each connection covers, for example: "The connected project token covers only acme/ui. Add a connection for acme/api or use a group access token."

Migration

  • Existing identities have no type stored. The migration leaves the columns empty.
  • The provider classifies them lazily, from the stored username, the first time it loads them, and saves the result.
  • No user action is needed.

Tests

  • Classification of each username form.
  • ResolveRepository:
    • a project token skipped for another repo;
    • a group token covering a subgroup;
    • a public repo not bound to a non-member token;
    • the ordering when several candidates qualify.
  • MintCredential refusing a write at level 0.
  • The display name for each kind.
  • These extend spi_fakegitlab_test.go with project_<id>_bot and group_<id>_bot users, /groups/:id, and permissions on /projects/:id.

Open question

Should core show a structured "reach" instead of relying on DisplayName? That would need an optional field on gitprovider.Identity. I'd keep that out of this change.

Activity

  1. pikann commented on Oct 28, 2026

    @pikann

    Hi @gorlix ,

    Thanks for the detailed proposal!

    Would you like to submit a PR for this? If so, please let me know. Otherwise, I’d be happy to jump in and take care of it.

  2. gorlix commented on Oct 28, 2026

    @gorlix
    Author

    hello @pikann
    Absolutely;
    I just wanted to get your confirmation that I’ve understood everything correctly.

  3. gorlix commented on Oct 28, 2026

    @gorlix
    Author

    Hi @pikann,

    Thanks, that's a fair point, and I agree. A task that spans backend and frontend shouldn't be tied to one repo through its ID.
    Keeping PROJ-N as the only identifier is the better model, so I'm withdrawing the repo-key part of the proposal.

    Two smaller things are still worth doing:

    1. Parser fix (small PR). taskRefRE in service/git/service.go reads TRIM-UI-200 as UI-200, because \b matches after the first
      hyphen. If anyone writes a 3-part string in a branch or title (from habit or from another tool's convention), it can link to
      nothing, or to a task in a project whose prefix happens to be UI. The fix: only accept a match that isn't preceded by -, with tests. No schema or API change.
    2. Optional, your call: a per-repo "scope" note. Since agents pick the right repos from the docs, would a short scope description on each linked repository help? It would be set in Project Settings → Git and shown in list_repositories and in the agent prompt. It puts the context where the agent already looks, without changing task IDs. If the docs already cover this well enough, I'll skip it.
  4. pikann commented on Oct 28, 2026

    @pikann

    Yes, it's a good suggestion. A description for the repository will also be helpful for the agent to detect which repository to use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions