토큰 해지 API
토큰 해지 API는 GitLab과 통신하여 GitLab Secret Detection이 감지한 API 토큰 및 기타 시크릿을 수신하고 해지하는 외부 배포용 HTTP API입니다. 고수준 아키텍처를 참조하여 Secret Detection 후처리 및 해지 흐름을 이해하세요.
GitLab.com은 시크릿 해지 서비스(팀 멤버 전용)를 Token Revocation API로 사용합니다. GitLab Self-managed의 경우, 직접 API를 생성하고 GitLab을 구성할 수 있습니다.
Self-managed용 토큰 해지 API 구현
해지 기능을 사용하고자 하는 GitLab Self-managed 인스턴스는 다음을 수행해야 합니다:
- 자체 토큰 해지 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.type
과 primary_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
| 해당 공급자가 너무 많은 요청을 받았습니다. 요청을 나중에 다시 시도해야 합니다. |
요청 본문의 예시:
[{
"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을 토큰 해지 API와 연동하도록 구성하기
GitLab 인스턴스에서 다음의 데이터베이스 설정을 구성해야 합니다:
설정 | 유형 | 설명 |
---|---|---|
secret_detection_token_revocation_enabled
| 부울 | 자동 토큰 해지가 활성화되었는지 여부 |
secret_detection_token_revocation_url
| 문자열 | 토큰 해지 API의 /v1/revoke_tokens 엔드포인트로의 완전히 정규화된 URL
|
secret_detection_revocation_token_types_url
| 문자열 | 토큰 해지 API의 /v1/revocable_token_types 엔드포인트로의 완전히 정규화된 URL
|
secret_detection_token_revocation_token
| 문자열 | 토큰 해지 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가 고수준 아키텍처 다이어그램에 따라 호출됩니다.