Add the raw-token validity checks domain module

Problem

Internal scanners such as Tokinator find raw token values outside GitLab and have no way to ask GitLab whether they are still live. Finding verification only runs when a security report is ingested, and asynchronously. The spike in https://gitlab.com/gitlab-org/gitlab/-/work_items/632986 settled on a synchronous REST endpoint in the monolith. This MR adds the domain module behind that endpoint. The route follows in !268618 (merged).

Changes

I added the Security::SecretDetection::ValidityChecks namespace. VerifyRawTokensService is its only public entry point; every other class is private to it.

  • VerifyRawTokensService takes the caller, the project the caller acts for, the tokens and the caller's organization id. It checks the verify_secret_detection_raw_token ability from !268663 (merged) on the project, then returns one result per caller-chosen id, or :not_found for every denial so the endpoint stays invisible to callers it is not for. Nothing else in the module sees a User or Project.
  • RawTokenBatch groups the request by token type and maps results back by id. Raw values never appear in results.
  • GitlabTokenVerifier answers GitLab-issued tokens from the instance's own records through the existing TokenLookupService. Any other token type returns unsupported_token_type; partner tokens come in https://gitlab.com/gitlab-org/gitlab/-/work_items/637861.

Design decisions:

  • Lookups are instance-wide, because a leaked token can belong to anyone. The project only authorizes the call.
  • GitlabTokenVerifier takes an organization_id that nothing reads yet, so narrowing lookups in https://gitlab.com/gitlab-org/gitlab/-/work_items/637863 is a deliberate parameter change. The route passes the caller's current organization.
  • The module makes no authorization decision of its own. Role and licence come from the project policy, and the paid-plan rule is added to that policy in !268618 (merged) alongside the route.
  • Nothing is persisted. Raw tokens have no finding.

Nothing calls the module yet. The route, its wip feature flag and the policy rule come in !268618 (merged). This is the second of four MRs for https://gitlab.com/gitlab-org/gitlab/-/work_items/637856.

Reviewer focus

VerifyRawTokensService#authorized? is the only place the module checks an ability, and it delegates to the project policy.

Validation

The module specs pass locally on the rebased branch (15 examples, 0 failures). RuboCop reports no offenses on the changed files. Pipeline: https://gitlab.com/gitlab-org/gitlab/-/pipelines/3051978989.

Re: https://gitlab.com/gitlab-org/gitlab/-/work_items/637856+

Edited by Jennifer Li

Merge request reports

Loading
Loading