Skip to content

feat(integrations): agents act as the user on GitLab - #749

Merged
NOX73 merged 13 commits into
developfrom
feature/gitlab-user-token
Nov 14, 2026
Merged

NOX73 merged 13 commits into
developfrom
feature/gitlab-user-token

Conversation

@NOX73

@NOX73 NOX73 commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Agents can act as the user on GitLab, as #214 does for GitHub (task #238, design docs/design/gitlab-user-identity.md, PR #744).

  • Connection. A gitlab entry on the unified OAuth engine over the deployment's existing GitLab OAuth app. Endpoints and issuer follow GITLAB_ENDPOINT (a resolver on the registry entry); the client id/secret use the app's own setting names; the operator's host is trusted for the token exchange and refresh for gitlab only (a literal IP stays refused). Credentials on another host are invisible (gitlab_connections_of filters on the issuer).
  • Consent. act_as_consents.provider accepts gitlab (no migration).
  • Tools. gitlab_user_token and gitlab_user_token_for. The nine shared steps move to InternalTools::Concerns::UserTokenContext; GitHub and GitLab each supply their part. GitHub messages are unchanged and its tests pass untouched. GitLab hands out the stored token, refreshed when under 30 minutes remain, reports expires_at 10 minutes early, and checks Developer access per repository (falling back to the project member list for access that comes through a shared group); repositories the person cannot push to land in skipped.
  • Profile. Connected accounts shows both providers; page props are now keyed by provider.
  • Docs. GitLab user guide ("Acting as yourself", the extra redirect URI, plainly that the token is not limited to the session's repositories), GitHub guide pointer, CHANGELOG, design status.

Not limited to the session's repositories: GitLab cannot narrow an OAuth token (design §2.1, decision D1 accepted).

Related issues

Task #238 (builds on #214).

Type of change

  • New feature

How was this tested?

On a Coder workspace at the pushed head:

  • Rails: the full suite plus targeted runs of the new adapter contract tests (Gitlab::UserTokenService), engine (providers, callback, private-host refresh), both tools, profile request tests, models; the GitHub tool tests pass unchanged.
  • Frontend: yarn tsc, yarn lint, yarn fsd, and the Connections page Vitest.
  • rubocop, rails zeitwerk:check.

Staging QA still to do (needs the redirect URI https://staging.flow.aixle.com/oauth/callback on the staging GitLab OAuth app): connect, push and merge request as the user, a user whose access to a repository comes only through a shared group, spike R2 (does a refresh revoke the previous access token).

Checklist

  • I read CONTRIBUTING.md.
  • All my commits are signed off for the DCO (git commit -s).
  • I added/updated tests where it makes sense.
  • I updated documentation where it makes sense.
  • User-visible changes have an entry under [Unreleased] in CHANGELOG.md.
  • My commits use clear, descriptive messages.

Adds a gitlab provider to the unified OAuth engine over the deployment's GitLab OAuth app, act-as consent for gitlab, and the gitlab_user_token and gitlab_user_token_for tools sharing one concern with the GitHub pair. The profile's Connected accounts page shows both providers.

Signed-off-by: Alex <[email protected]>
Comment thread app/services/gitlab/user_connection.rb Resolved
Comment thread app/services/user_connections.rb Resolved
Comment thread app/controllers/web/oauth_controller.rb Resolved

@aixle-com aixle-com Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One [Must] (GitLab disconnect sends other-host tokens to the current host) plus recommendations; see inline comments.

Comment thread docs/user-guide/gitlab.md Resolved
Comment thread app/models/oauth_credential.rb Resolved
Comment thread app/services/oauth/providers.rb Resolved
Revoke only current-host grants on disconnect, leave old-host grants to lapse,
dispatch the latest connection through PROVIDERS, move identity onto
OauthCredential, name the OAuth app and endpoints explicitly, stop refreshing
early (R2), name the provider in accessible names, warn at the GitLab consent
switches, and fix the GitLab guide.

Signed-off-by: Alex <[email protected]>
Comment thread app/models/oauth_credential.rb Resolved
…ta key

Github/Gitlab::UserConnection read the key from OauthCredential::IDENTITY_FIELDS; move this PR's changelog entry to Unreleased.

Signed-off-by: Alex <[email protected]>

@aixle-com aixle-com Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 4 (head 4a5569d): the delta since 3fb59af matches Alex's decisions. Gitlab::UserTokenService now uses the gitlab gem, with the Bearer header covered by a test and gem errors mapped to the service's errors. Revocation moved into Oauth::TokenService.revoke!, which takes its endpoint from the registry and uses SafeHttp with the trusted host. No remarks.

@NOX73
NOX73 merged commit 506b708 into develop Nov 14, 2026
17 checks passed
@NOX73
NOX73 deleted the feature/gitlab-user-token branch November 14, 2026 14:56
aixle-com Bot pushed a commit that referenced this pull request Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant