토큰 폐기 API
토큰 폐기 API는 GitLab과 통합되어 API 토큰 및 GitLab Secret Detection에서 감지된 기타 시크릿을 수신하고 폐기하는 외부 배포형 HTTP API입니다. 고수준 아키텍처를 참조하여 Secret Detection 후처리 및 폐기 흐름을 이해할 수 있습니다.
GitLab.com은 내부 유지보수되는 Secret Revocation Service (팀 멤버 전용)를 Token Revocation API로 사용합니다. GitLab Self-Managed의 경우, 고유한 API를 생성하고 GitLab에서 이를 구성할 수 있습니다.
자체 관리용 토큰 폐기 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
값 반환합니다.
참고:
이러한 값은 the ‘secrets’ analyzer’s의 기본 식별자인
primary identifier의 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)
이러한 값을 구성한 후에는 고수준 아키텍처 다이어그램에 따라 토큰 폐기 API가 호출됩니다.