토큰 폐기 API

토큰 폐기 API는 GitLab과 인터페이스하는 외부 배포 HTTP API로, GitLab 비밀 탐지에 의해 탐지된 API 토큰 및 기타 비밀을 수신하고 폐기합니다.

비밀 탐지 후처리 및 폐기 흐름을 이해하려면 고급 아키텍처를 참조하세요.

GitLab.com은 내부에서 유지 관리되는 비밀 폐기 서비스 (팀원 전용)를 토큰 폐기 API로 사용합니다. GitLab을 자체 관리하는 경우, 자신의 API를 만들어 GitLab이 이를 사용하도록 구성할 수 있습니다.

자체 관리용 토큰 폐기 API 구현

폐기 기능 사용에 관심이 있는 GitLab 자체 관리 인스턴스는 다음을 수행해야 합니다:

  • 자신의 토큰 폐기 API를 구현하고 배포합니다.
  • GitLab 인스턴스를 구성하여 토큰 폐기 API를 사용합니다.

귀하의 서비스는 다음과 같아야 합니다:

  • 아래 API 사양에 맞아야 합니다.
  • 두 개의 엔드포인트를 제공해야 합니다:
    • 폐기할 수 있는 토큰 유형 가져오기.
    • 누출된 토큰 폐기.
  • 속도 제한이 있으며, 멱등적이어야 합니다.

문서화된 엔드포인트에 대한 요청은 Authorization 헤더에 전달된 API 토큰을 사용하여 인증됩니다. 요청 및 응답 본문이 있는 경우, 내용 유형은 application/json이어야 합니다.

모든 엔드포인트는 다음과 같은 응답을 반환할 수 있습니다:

  • 401 Unauthorized
  • 405 Method Not Allowed
  • 500 Internal Server Error

GET /v1/revocable_token_types

revoke_tokens 엔드포인트에서 사용할 수 있는 유효한 type 값들을 반환합니다.

참고: 이 값들은 비밀 분석기의 주 식별자를 통해 primary_identifier.typeprimary_identifier.value를 연결한 결과와 일치합니다. 예를 들어, 값 gitleaks_rule_id_gitlab_personal_access_token은 다음과 같은 발견 식별자와 일치합니다:

{"type": "gitleaks_rule_id", "name": "Gitleaks rule ID GitLab Personal Access Token", "value": "GitLab Personal Access Token"}
상태 코드 설명
200 응답 본문에 유효한 토큰 type 값이 포함되어 있습니다.

예시 응답 본문:

{
    "types": ["gitleaks_rule_id_gitlab_personal_access_token"]
}

POST /v1/revoke_tokens

적절한 제공업체에 의해 폐기될 토큰 목록을 수락합니다. 귀하의 서비스는 각 제공업체와 통신하여 토큰을 폐기할 책임이 있습니다.

상태 코드 설명
204 제출된 모든 토큰이 최종 폐기를 위해 수락되었습니다.
400 요청 본문이 유효하지 않거나 제출된 토큰 유형 중 하나가 지원되지 않습니다. 요청을 다시 시도하지 않아야 합니다.
429 제공업체가 너무 많은 요청을 받았습니다. 나중에 요청을 다시 시도해야 합니다.

예시 요청 본문 (비밀 탐지 경고를 방지하기 위해 token 값에 공백 문자를 추가했습니다):

[{
    "type": "gitleaks_rule_id_gitlab_personal_access_token",
    "token": "glpat - 8GMtG8Mf4EnMJzmAWDU",
    "location": "https://example.com/some-repo/blob/abcdefghijklmnop/compromisedfile1.java"
},
{
    "type": "gitleaks_rule_id_gitlab_personal_access_token",
    "token": "glpat - tG84EGK33nMLLDE70zU",
    "location": "https://example.com/some-repo/blob/abcdefghijklmnop/compromisedfile2.java"
}]

GitLab을 Token Revocation API와 인터페이스하도록 구성하기

GitLab 인스턴스에서 다음 데이터베이스 설정을 구성해야 합니다:

설정 유형 설명
secret_detection_token_revocation_enabled Boolean 자동 토큰 회수가 활성화되었는지 여부
secret_detection_token_revocation_url String Token Revocation API의 /v1/revoke_tokens 엔드포인트에 대한 완전한 URL
secret_detection_revocation_token_types_url String Token Revocation API의 /v1/revocable_token_types 엔드포인트에 대한 완전한 URL
secret_detection_token_revocation_token String Token Revocation API에 대한 요청을 인증하는 사전 공유된 토큰

예를 들어, 이러한 값을 Rails 콘솔에서 구성하려면:

::Gitlab::CurrentSettings.update!(secret_detection_token_revocation_token: 'MYSECRETTOKEN')

::Gitlab::CurrentSettings.update!(secret_detection_token_revocation_url: 'https://gitlab.example.com/revocation_service/v1/revoke_tokens')

::Gitlab::CurrentSettings.update!(secret_detection_revocation_token_types_url: 'https://gitlab.example.com/revocation_service/v1/revocable_token_types')

::Gitlab::CurrentSettings.update!(secret_detection_token_revocation_enabled: true)

이 값을 구성한 후, 고수준 아키텍처 다이어그램에 따라 Token Revocation API가 호출됩니다.