Skip to content

Fix reuse detection and revocation query

What does this MR do and why?

Fix reuse detection and revocation query to avoid ignoring the recursive CTE.

Related to #418566 (closed) and #418629 (closed).

Database queries

Query 1:

Line: https://gitlab.com/gitlab-org/gitlab/-/blob/166c7f03bd5e45a97b193fb6532130d574a2de73/app/services/personal_access_tokens/revoke_token_family_service.rb#L14

Query:

WITH RECURSIVE "personal_access_tokens_cte" AS (
(
    SELECT
      "personal_access_tokens"."id",
      "personal_access_tokens"."revoked",
      "personal_access_tokens"."expires_at"
    FROM
      "personal_access_tokens"
    WHERE
      "personal_access_tokens"."previous_personal_access_token_id" = 6357994)
  UNION (
    SELECT
      "personal_access_tokens"."id",
      "personal_access_tokens"."revoked",
      "personal_access_tokens"."expires_at"
    FROM
      "personal_access_tokens",
      "personal_access_tokens_cte"
    WHERE
      "personal_access_tokens"."previous_personal_access_token_id" = "personal_access_tokens_cte"."id"))
SELECT
  id
FROM
  "personal_access_tokens_cte" AS "personal_access_tokens"
WHERE ("personal_access_tokens"."revoked" = FALSE
  OR "personal_access_tokens"."revoked" IS NULL)
AND ("personal_access_tokens"."expires_at" > '2023-07-19'
  OR "personal_access_tokens"."expires_at" IS NULL)

Plan: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/20496/commands/67132

Query 2:

Line: https://gitlab.com/gitlab-org/gitlab/-/blob/166c7f03bd5e45a97b193fb6532130d574a2de73/app/services/personal_access_tokens/revoke_token_family_service.rb#L20

Query:

UPDATE
  "personal_access_tokens"
SET
  "revoked" = TRUE
WHERE
  "personal_access_tokens"."id" = 6622434

Plan: https://postgres.ai/console/gitlab/gitlab-production-tunnel-pg12/sessions/20496/commands/67133

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Prabakaran Murugesan

Merge request reports

Loading