서비스 계정 API
GitLab v19.5Offering: GitLab Self-Managed, GitLab Dedicated
요약
이 API를 사용하여 서비스 계정과 상호 작용합니다. 생성할 수 있는 서비스 계정 수는 구독 및 오퍼링에 따라 다릅니다. 사용자 API를 통해서도 서비스 계정과 상호 작용할 수 있습니다. 인스턴스 서비스 계정은 GitLab 인스턴스 전체에서 사용할 수 있지만, 일반 사용자와 마찬가지로 그룹 및 프로젝트에 추가해야 합니다.
히스토리
- GitLab 18.10에서 Free 티어에
service_accounts_available_on_free_or_unlicensed라는 - GitLab 18.11에서 Free 티어에 일반적으로 사용 가능해짐.
이 API를 사용하여 서비스 계정과 상호 작용합니다.
생성할 수 있는 서비스 계정 수는 구독 및 오퍼링에 따라 다릅니다.
- GitLab Premium 및 Ultimate에서는 모든 오퍼링에 대해 서비스 계정을 무제한으로 생성할 수 있습니다.
- GitLab Free에서는 오퍼링에 따라 제한이 다릅니다.
- GitLab.com에서는 최상위 그룹마다 최대 100개의 서비스 계정을 생성할 수 있습니다. 여기에는 하위 그룹이나 프로젝트에서 생성한 서비스 계정도 포함됩니다.
- GitLab Self-Managed에서는 인스턴스 전체에 대해 최대 100개의 서비스 계정을 생성할 수 있습니다. 여기에는 인스턴스, 그룹, 프로젝트 수준에서 생성한 서비스 계정이 포함됩니다.
사용자 API를 통해서도 서비스 계정과 상호 작용할 수 있습니다. 서비스 계정의 SSH 키를 관리하려면 사용자 SSH 및 GPG 키 API를 사용합니다.
인스턴스 서비스 계정#
인스턴스 서비스 계정은 GitLab 인스턴스 전체에서 사용할 수 있지만, 일반 사용자와 마찬가지로 그룹 및 프로젝트에 추가해야 합니다.
인스턴스 서비스 계정의 개인 액세스 토큰을 관리하려면 개인 액세스 토큰 API를 사용합니다.
사전 요구 사항:
- 인스턴스에 대한 관리자 액세스 권한이 있어야 합니다.
모든 인스턴스 서비스 계정 목록 조회#
히스토리
- 모든 서비스 계정 목록 조회가 GitLab 17.1에서 도입됨.
모든 인스턴스 서비스 계정 목록을 조회합니다.
page 및 per_page 페이지네이션 파라미터를 사용하여 결과를 필터링합니다.
GET /service_accounts
지원되는 속성:
| Attribute | Type | Required | Description |
|---|---|---|---|
order_by |
string | no | 결과를 정렬할 속성. 가능한 값: id 또는 username. 기본값: id. |
sort |
string | no | 결과 정렬 방향. 가능한 값: desc 또는 asc. 기본값: desc. |
요청 예시:
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/service_accounts"
응답 예시:
[
{
"id": 114,
"username": "service_account_33",
"public_email": "",
"name": "Service account user",
"email": "service_account_33@noreply.gitlab.example.com"
},
{
"id": 137,
"username": "service_account_34",
"public_email": "",
"name": "john doe",
"email": "service_account_34@noreply.gitlab.example.com"
}
]
인스턴스 서비스 계정 생성#
인스턴스 서비스 계정을 생성합니다.
POST /service_accounts
POST /service_accounts?email=custom_email@gitlab.example.com
지원되는 속성:
| Attribute | Type | Required | Description |
|---|---|---|---|
name |
string | no | 사용자의 이름. 설정하지 않으면 Service account user를 사용합니다. |
username |
string | no | 사용자 계정의 사용자 이름. 정의하지 않으면 service_account_ 접두사가 붙은 이름을 생성합니다. |
email |
string | no | 사용자 계정의 이메일. 지정하지 않으면 service_account_ 접두사가 붙은 이메일을 생성합니다. 커스텀 이메일 주소는 이메일 확인 설정이 꺼져 있지 않으면 확인이 필요합니다. |
external |
boolean | no | 사용자가 외부 사용자인지 여부. 기본값은 true입니다. |
요청 예시:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/service_accounts"
응답 예시:
{
"id": 57,
"username": "service_account_6018816a18e515214e0c34c2b33523fc",
"public_email": "",
"name": "Service account user",
"email": "service_account_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com",
"external": true
}
email 속성에 정의한 이메일 주소를 이미 다른 사용자가 사용 중이면
400 Bad request 오류를 반환합니다.
인스턴스 서비스 계정 업데이트#
지정한 인스턴스 서비스 계정을 업데이트합니다.
PATCH /service_accounts/:id
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer | yes | 서비스 계정의 ID. |
name |
string | no | 사용자의 이름. |
username |
string | no | 사용자 계정의 사용자 이름. |
email |
string | no | 사용자 계정의 이메일. 커스텀 이메일 주소는 이메일 확인 설정이 꺼져 있지 않으면 확인이 필요합니다. |
external |
boolean | no | 사용자가 외부 사용자인지 여부. |
요청 예시:
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/service_accounts/57" \
--data "name=Updated Service Account&email=updated_email@example.com"
응답 예시:
{
"id": 57,
"username": "service_account_6018816a18e515214e0c34c2b33523fc",
"public_email": "",
"name": "Updated Service Account",
"email": "service_account_<random_hash>@noreply.gitlab.example.com",
"external": true,
"unconfirmed_email": "custom_email@example.com"
}
그룹 서비스 계정#
히스토리
- 하위 그룹 서비스 계정이 GitLab 18.10에서
allow_subgroups_to_create_service_accounts라는 기능 플래그와 함께 도입됨. 기본적으로 비활성화됨. - 하위 그룹 서비스 계정이 GitLab 18.11에서 일반적으로 사용 가능해짐. 기능 플래그
allow_subgroups_to_create_service_accounts제거됨.
그룹 서비스 계정은 특정 그룹이 소유하며, 계정을 생성한 그룹이나 그 하위 그룹 또는 프로젝트에 초대할 수 있습니다. 상위 그룹에는 초대할 수 없습니다.
사전 요구 사항:
- GitLab.com에서는 해당 그룹에 대한 Owner 권한이 있어야 합니다.
- GitLab Self-Managed 또는 GitLab Dedicated에서는 다음 중 하나에 해당해야 합니다.
- 인스턴스의 관리자입니다.
- 그룹에서 Owner 권한이 있고 서비스 계정 생성이 허용되어 있습니다.
모든 그룹 서비스 계정 목록 조회#
히스토리
- GitLab 17.1에서 도입됨.
지정한 그룹의 모든 서비스 계정 목록을 조회합니다.
page 및 per_page 페이지네이션 파라미터를 사용하여 결과를 필터링합니다.
GET /groups/:id/service_accounts
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 그룹의 ID 또는 URL 인코딩된 경로. |
order_by |
string | no | username 또는 id로 사용자 목록을 정렬합니다. 기본값은 id 입니다. |
sort |
string | no | asc 또는 desc로 정렬 방향을 지정합니다. 기본값은 desc 입니다. |
요청 예시:
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/345/service_accounts"
응답 예시:
[
{
"id": 57,
"username": "service_account_group_345_<random_hash>",
"public_email": "",
"name": "Service account user",
"email": "service_account_group_345_<random_hash>@noreply.gitlab.example.com"
},
{
"id": 58,
"username": "service_account_group_345_<random_hash>",
"public_email": "",
"name": "Service account user",
"email": "service_account_group_345_<random_hash>@noreply.gitlab.example.com",
"unconfirmed_email": "custom_email@example.com"
}
]
그룹 서비스 계정 조회#
지정한 그룹의 서비스 계정 하나를 조회합니다.
GET /groups/:id/service_accounts/:user_id
지원되는 속성:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 그룹의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
성공하면 200 OK와 다음 응답 속성을 반환합니다.
| Attribute | Type | Description |
|---|---|---|
email |
string | 서비스 계정의 이메일 주소. |
id |
integer | 서비스 계정의 ID. |
name |
string | 서비스 계정의 이름. |
public_email |
string | 서비스 계정의 공개 이메일 주소. |
unconfirmed_email |
string | 확인을 기다리는 이메일 주소. 확인이 보류 중일 때만 반환됩니다. |
username |
string | 서비스 계정의 사용자 이름. |
그룹에 해당 서비스 계정이 없으면 404 Not Found를 반환하고, 사용자가 그룹에 있지만
서비스 계정이 아니면 400 Bad Request를 반환합니다.
요청 예시:
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/345/service_accounts/57"
응답 예시:
{
"id": 57,
"username": "service_account_group_345_6018816a18e515214e0c34c2b33523fc",
"public_email": "",
"name": "Service account user",
"email": "service_account_group_345_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com"
}
그룹 서비스 계정 생성#
히스토리
email속성이 GitLab 17.9에서group_service_account_custom_email이라는 기능 플래그와 함께 추가됨.email속성이 GitLab 17.11에서 일반적으로 사용 가능해짐. 기능 플래그group_service_account_custom_email제거됨.
지정한 그룹에 서비스 계정을 생성합니다.
POST /groups/:id/service_accounts
지원되는 속성:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 그룹의 ID 또는 URL 인코딩된 경로. |
name |
string | no | 사용자 계정 이름. 지정하지 않으면 Service account user를 사용합니다. |
username |
string | no | 사용자 계정 사용자 이름. 지정하지 않으면 service_account_group_ 접두사가 붙은 이름을 생성합니다. |
email |
string | no | 사용자 계정의 이메일. 지정하지 않으면 service_account_group_ 접두사가 붙은 이메일을 생성합니다. 커스텀 이메일 주소는 최상위 그룹에 일치하는 인증된 도메인이 있거나 이메일 확인 설정이 꺼져 있지 않으면 확인이 필요합니다. |
요청 예시:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/345/service_accounts" \
--data "email=custom_email@example.com"
응답 예시:
{
"id": 57,
"username": "service_account_group_345_6018816a18e515214e0c34c2b33523fc",
"public_email": "",
"name": "Service account user",
"email": "custom_email@example.com"
}
그룹 서비스 계정 업데이트#
히스토리
지정한 그룹의 서비스 계정을 업데이트합니다.
- 복합 아이덴티티에 연결된 서비스 계정의 사용자 이름은 업데이트할 수 없습니다.
PATCH /groups/:id/service_accounts/:user_id
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 그룹의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
name |
string | no | 사용자의 이름. |
username |
string | no | 사용자의 사용자 이름. |
email |
string | no | 사용자 계정의 이메일. 커스텀 이메일 주소는 최상위 그룹에 일치하는 인증된 도메인이 있거나 이메일 확인 설정이 꺼져 있지 않으면 확인이 필요합니다. |
요청 예시:
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/345/service_accounts/57" \
--data "name=Updated Service Account&email=updated_email@example.com"
응답 예시:
{
"id": 57,
"username": "service_account_group_345_6018816a18e515214e0c34c2b33523fc",
"public_email": "",
"name": "Updated Service Account",
"email": "service_account_group_345_<random_hash>@noreply.gitlab.example.com",
"unconfirmed_email": "custom_email@example.com"
}
그룹 서비스 계정 삭제#
히스토리
- GitLab 17.1에서 도입됨.
지정한 그룹에서 서비스 계정을 삭제합니다.
DELETE /groups/:id/service_accounts/:user_id
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 그룹의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
hard_delete |
boolean | no | true로 설정하면 일반적으로 ghost 사용자로 이동되는 기여 내용이 삭제되며, 이 서비스 계정이 단독으로 소유한 그룹도 삭제됩니다. |
요청 예시:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/345/service_accounts/181"
그룹 서비스 계정의 모든 개인 액세스 토큰 목록 조회#
지정한 그룹에 있는 서비스 계정의 모든 개인 액세스 토큰 목록을 조회합니다.
GET /groups/:id/service_accounts/:user_id/personal_access_tokens
지원되는 속성:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 그룹의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
created_after |
datetime (ISO 8601) | no | 정의하면 지정한 시각 이후에 생성된 토큰을 반환합니다. |
created_before |
datetime (ISO 8601) | no | 정의하면 지정한 시각 이전에 생성된 토큰을 반환합니다. |
expires_after |
date (ISO 8601) | no | 정의하면 지정한 시각 이후에 만료되는 토큰을 반환합니다. |
expires_before |
date (ISO 8601) | no | 정의하면 지정한 시각 이전에 만료되는 토큰을 반환합니다. |
last_used_after |
datetime (ISO 8601) | no | 정의하면 지정한 시각 이후에 마지막으로 사용된 토큰을 반환합니다. |
last_used_before |
datetime (ISO 8601) | no | 정의하면 지정한 시각 이전에 마지막으로 사용된 토큰을 반환합니다. |
revoked |
boolean | no | true 이면 취소된 토큰만 반환합니다. |
search |
string | no | 정의하면 이름에 지정한 값이 포함된 토큰을 반환합니다. |
sort |
string | no | 정의하면 지정한 값을 기준으로 결과를 정렬합니다. 가능한 값: created_asc, created_desc, expires_asc, expires_desc, last_used_asc, last_used_desc, name_asc, name_desc. |
state |
string | no | 정의하면 지정한 상태의 토큰을 반환합니다. 가능한 값: active 및 inactive. |
요청 예시:
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/187/service_accounts/195/personal_access_tokens?sort=id_desc&search=token2b&created_before=2025-03-27"
응답 예시:
[
{
"id": 187,
"name": "service_accounts_token2b",
"revoked": false,
"created_at": "2025-03-26T14:42:51.084Z",
"description": null,
"scopes": [
"api"
],
"user_id": 195,
"last_used_at": null,
"last_used_ips": [],
"active": true,
"expires_at": null
}
]
실패 응답 예시:
401: Unauthorized404 Group Not Found
그룹 서비스 계정의 개인 액세스 토큰 생성#
히스토리
- 응답의
last_used_ips가 GitLab 19.4에서 도입됨.
지정한 그룹에 있는 기존 서비스 계정의 개인 액세스 토큰을 생성합니다.
POST /groups/:id/service_accounts/:user_id/personal_access_tokens
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 그룹의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
name |
string | yes | 개인 액세스 토큰의 이름. |
description |
string | no | 개인 액세스 토큰의 설명. |
scopes |
array | yes | 승인된 스코프 배열. 가능한 값 목록은 액세스 토큰 스코프를 참고합니다. |
expires_at |
date | no | ISO 형식(YYYY-MM-DD)으로 지정한 액세스 토큰의 만료 날짜. 지정하지 않고 토큰에 만료 날짜가 필요하면 기본값은 허용되는 최대 수명 한도입니다. 필요하지 않으면 토큰에는 만료 날짜가 없습니다. |
요청 예시:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/35/service_accounts/71/personal_access_tokens" \
--data "scopes[]=api,read_user,read_repository" \
--data "name=service_accounts_token"
응답 예시:
{
"id":6,
"name":"service_accounts_token",
"revoked":false,
"created_at":"2023-06-13T07:47:13.900Z",
"scopes":["api"],
"user_id":71,
"last_used_at":null,
"last_used_ips":[],
"active":true,
"expires_at":"2024-06-12",
"token":"<token_value>"
}
그룹 서비스 계정의 개인 액세스 토큰 취소#
히스토리
- GitLab 17.11에서 도입됨
그룹에 있는 기존 서비스 계정의 지정한 개인 액세스 토큰을 취소합니다.
DELETE /groups/:id/service_accounts/:user_id/personal_access_tokens/:token_id
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 그룹의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
token_id |
integer | yes | 토큰의 ID. |
요청 예시:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/35/service_accounts/71/personal_access_tokens/6"
성공하면 204: No Content를 반환합니다.
그 밖에 반환될 수 있는 응답은 다음과 같습니다.
400: Bad Request— 취소에 실패한 경우.401: Unauthorized— 요청이 인증되지 않은 경우.403: Forbidden— 요청이 허용되지 않은 경우.404: Not Found— 액세스 토큰이 존재하지 않는 경우.
그룹 서비스 계정의 개인 액세스 토큰 교체#
지정한 그룹에 있는 기존 서비스 계정의 지정한 개인 액세스 토큰을 교체합니다. 기존 토큰을 취소하고 이름, 설명, 스코프가 동일한 새 토큰을 생성합니다.
POST /groups/:id/service_accounts/:user_id/personal_access_tokens/:token_id/rotate
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 그룹의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
token_id |
integer | yes | 토큰의 ID. |
expires_at |
date | no | ISO 형식(YYYY-MM-DD)으로 지정한 액세스 토큰의 만료 날짜. GitLab 17.9에서 도입됨. 토큰에 만료 날짜가 필요하면 기본값은 1주입니다. 필요하지 않으면 토큰에는 만료 날짜가 없습니다. |
요청 예시:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/groups/35/service_accounts/71/personal_access_tokens/6/rotate"
응답 예시:
{
"id":7,
"name":"service_accounts_token",
"revoked":false,
"created_at":"2023-06-13T07:54:49.962Z",
"scopes":["api"],
"user_id":71,
"last_used_at":null,
"last_used_ips":[],
"active":true,
"expires_at":"2023-06-20",
"token":"<token_value>"
}
세분화된 스코프가 있는 토큰을 교체하면 새 토큰의 granular_scopes 속성으로 해당 스코프가 반환됩니다. 자세한 내용은
모든 개인 액세스 토큰 나열을 참고합니다.
프로젝트 서비스 계정#
히스토리
- GitLab 18.9에서
allow_projects_to_create_service_accounts라는 기능 플래그와 함께 도입됨. 기본적으로 비활성화됨. - 프로젝트 서비스 계정이 GitLab 18.11에서 일반적으로 사용 가능해짐. 기능 플래그
allow_projects_to_create_service_accounts제거됨.
프로젝트 서비스 계정은 특정 프로젝트가 소유하며 해당 프로젝트에서만 사용할 수 있습니다.
사전 요구 사항:
- GitLab.com에서는 해당 프로젝트에 대한 Maintainer 또는 Owner 권한이 있어야 합니다.
- GitLab Self-Managed 또는 GitLab Dedicated에서는 다음 중 하나에 해당해야 합니다.
- 인스턴스의 관리자입니다.
- 프로젝트에서 Maintainer 또는 Owner 권한이 있습니다.
모든 프로젝트 서비스 계정 목록 조회#
지정한 프로젝트의 모든 서비스 계정 목록을 조회합니다.
page 및 per_page 페이지네이션 파라미터를 사용하여 결과를 필터링합니다.
GET /projects/:id/service_accounts
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 프로젝트의 ID 또는 URL 인코딩된 경로. |
order_by |
string | no | username 또는 id로 사용자 목록을 정렬합니다. 기본값은 id 입니다. |
sort |
string | no | asc 또는 desc로 정렬 방향을 지정합니다. 기본값은 desc 입니다. |
요청 예시:
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/345/service_accounts"
응답 예시:
[
{
"id": 57,
"username": "service_account_project_345_<random_hash>",
"public_email": "",
"name": "Service account user",
"email": "service_account_project_345_<random_hash>@noreply.gitlab.example.com"
},
{
"id": 58,
"username": "service_account_project_345_<random_hash>",
"public_email": "",
"name": "Service account user",
"email": "service_account_project_345_<random_hash>@noreply.gitlab.example.com",
"unconfirmed_email": "custom_email@example.com"
}
]
프로젝트 서비스 계정 조회#
지정한 프로젝트의 서비스 계정 하나를 조회합니다.
GET /projects/:id/service_accounts/:user_id
지원되는 속성:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 프로젝트의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
성공하면 200 OK와 다음 응답 속성을 반환합니다.
| Attribute | Type | Description |
|---|---|---|
email |
string | 서비스 계정의 이메일 주소. |
id |
integer | 서비스 계정의 ID. |
name |
string | 서비스 계정의 이름. |
public_email |
string | 서비스 계정의 공개 이메일 주소. |
unconfirmed_email |
string | 확인을 기다리는 이메일 주소. 확인이 보류 중일 때만 반환됩니다. |
username |
string | 서비스 계정의 사용자 이름. |
프로젝트에 해당 서비스 계정이 없으면 404 Not Found를 반환합니다.
요청 예시:
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/345/service_accounts/57"
응답 예시:
{
"id": 57,
"username": "service_account_project_345_6018816a18e515214e0c34c2b33523fc",
"public_email": "",
"name": "Service account user",
"email": "service_account_project_345_6018816a18e515214e0c34c2b33523fc@noreply.gitlab.example.com"
}
프로젝트 서비스 계정 생성#
지정한 프로젝트에 서비스 계정을 생성합니다.
POST /projects/:id/service_accounts
지원되는 속성:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 프로젝트의 ID 또는 URL 인코딩된 경로 |
name |
string | no | 사용자 계정 이름. 지정하지 않으면 Service account user를 사용합니다. |
username |
string | no | 사용자 계정 사용자 이름. 지정하지 않으면 service_account_project_ 접두사가 붙은 이름을 생성합니다. |
email |
string | no | 사용자 계정의 이메일. 지정하지 않으면 service_account_project_ 접두사가 붙은 이메일을 생성합니다. 커스텀 이메일 주소는 최상위 그룹에 일치하는 인증된 도메인이 있거나 이메일 확인 설정이 꺼져 있지 않으면 확인이 필요합니다. |
요청 예시:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/345/service_accounts" \
--data "email=custom_email@example.com"
응답 예시:
{
"id": 57,
"username": "service_account_project_345_6018816a18e515214e0c34c2b33523fc",
"public_email": "",
"name": "Service account user",
"email": "custom_email@example.com"
}
프로젝트 서비스 계정 업데이트#
지정한 프로젝트의 서비스 계정을 업데이트합니다.
PATCH /projects/:id/service_accounts/:user_id
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 프로젝트의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
name |
string | no | 사용자의 이름. |
username |
string | no | 사용자의 사용자 이름. |
email |
string | no | 사용자 계정의 이메일. 커스텀 이메일 주소는 최상위 그룹에 일치하는 인증된 도메인이 있거나 이메일 확인 설정이 꺼져 있지 않으면 확인이 필요합니다. |
요청 예시:
curl --request PATCH \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/345/service_accounts/57" \
--data "name=Updated Service Account&email=updated_email@example.com"
응답 예시:
{
"id": 57,
"username": "service_account_project_345_6018816a18e515214e0c34c2b33523fc",
"public_email": "",
"name": "Updated Service Account",
"email": "service_account_project_345_<random_hash>@noreply.gitlab.example.com",
"unconfirmed_email": "custom_email@example.com"
}
프로젝트 서비스 계정 삭제#
지정한 프로젝트에서 서비스 계정을 삭제합니다.
DELETE /projects/:id/service_accounts/:user_id
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 프로젝트의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
hard_delete |
boolean | no | true로 설정하면 일반적으로 ghost 사용자로 이동되는 기여 내용이 삭제되며, 이 서비스 계정이 단독으로 소유한 그룹도 삭제됩니다. |
요청 예시:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/345/service_accounts/181"
프로젝트 서비스 계정의 모든 개인 액세스 토큰 목록 조회#
히스토리
- 응답의
last_used_ips가 GitLab 19.4에서 도입됨.
프로젝트에 있는 서비스 계정의 모든 개인 액세스 토큰 목록을 조회합니다.
GET /projects/:id/service_accounts/:user_id/personal_access_tokens
지원되는 속성:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 프로젝트의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
created_after |
datetime (ISO 8601) | no | 정의하면 지정한 시각 이후에 생성된 토큰을 반환합니다. |
created_before |
datetime (ISO 8601) | no | 정의하면 지정한 시각 이전에 생성된 토큰을 반환합니다. |
expires_after |
date (ISO 8601) | no | 정의하면 지정한 시각 이후에 만료되는 토큰을 반환합니다. |
expires_before |
date (ISO 8601) | no | 정의하면 지정한 시각 이전에 만료되는 토큰을 반환합니다. |
last_used_after |
datetime (ISO 8601) | no | 정의하면 지정한 시각 이후에 마지막으로 사용된 토큰을 반환합니다. |
last_used_before |
datetime (ISO 8601) | no | 정의하면 지정한 시각 이전에 마지막으로 사용된 토큰을 반환합니다. |
revoked |
boolean | no | true 이면 취소된 토큰만 반환합니다. |
search |
string | no | 정의하면 이름에 지정한 값이 포함된 토큰을 반환합니다. |
sort |
string | no | 정의하면 지정한 값을 기준으로 결과를 정렬합니다. 가능한 값: created_asc, created_desc, expires_asc, expires_desc, last_used_asc, last_used_desc, name_asc, name_desc. |
state |
string | no | 정의하면 지정한 상태의 토큰을 반환합니다. 가능한 값: active 및 inactive. |
요청 예시:
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/187/service_accounts/195/personal_access_tokens?sort=id_desc&search=token2b&created_before=2025-03-27"
응답 예시:
[
{
"id": 187,
"name": "service_accounts_token2b",
"revoked": false,
"created_at": "2025-03-26T14:42:51.084Z",
"description": null,
"scopes": [
"api"
],
"user_id": 195,
"last_used_at": null,
"last_used_ips": [],
"active": true,
"expires_at": null
}
]
실패 응답 예시:
401: Unauthorized404 Project Not Found
프로젝트 서비스 계정의 개인 액세스 토큰 생성#
히스토리
- 응답의
last_used_ips가 GitLab 19.4에서 도입됨.
지정한 프로젝트에 있는 기존 서비스 계정의 개인 액세스 토큰을 생성합니다.
POST /projects/:id/service_accounts/:user_id/personal_access_tokens
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 프로젝트의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
name |
string | yes | 개인 액세스 토큰의 이름. |
description |
string | no | 개인 액세스 토큰의 설명. |
scopes |
array | yes | 승인된 스코프 배열. 가능한 값 목록은 액세스 토큰 스코프를 참고합니다. |
expires_at |
date | no | ISO 형식(YYYY-MM-DD)으로 지정한 액세스 토큰의 만료 날짜. 지정하지 않고 토큰에 만료 날짜가 필요하면 기본값은 허용되는 최대 수명 한도입니다. 필요하지 않으면 토큰에는 만료 날짜가 없습니다. |
요청 예시:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/35/service_accounts/71/personal_access_tokens" \
--data "scopes[]=api,read_user,read_repository" \
--data "name=service_accounts_token"
응답 예시:
{
"id":6,
"name":"service_accounts_token",
"revoked":false,
"created_at":"2023-06-13T07:47:13.900Z",
"scopes":["api"],
"user_id":71,
"last_used_at":null,
"last_used_ips":[],
"active":true,
"expires_at":"2024-06-12",
"token":"<token_value>"
}
프로젝트 서비스 계정의 개인 액세스 토큰 취소#
지정한 프로젝트에 있는 기존 서비스 계정의 개인 액세스 토큰을 취소합니다.
DELETE /projects/:id/service_accounts/:user_id/personal_access_tokens/:token_id
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 프로젝트의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
token_id |
integer | yes | 토큰의 ID. |
요청 예시:
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/35/service_accounts/71/personal_access_tokens/6"
성공하면 204: No Content를 반환합니다.
그 밖에 반환될 수 있는 응답은 다음과 같습니다.
400: Bad Request— 취소에 실패한 경우.401: Unauthorized— 요청이 인증되지 않은 경우.403: Forbidden— 요청이 허용되지 않은 경우.404: Not Found— 액세스 토큰이 존재하지 않는 경우.
프로젝트 서비스 계정의 개인 액세스 토큰 교체#
지정한 프로젝트에 있는 기존 서비스 계정의 개인 액세스 토큰을 교체합니다. 1주 동안 유효한 새 토큰을 생성하고 기존 토큰을 모두 취소합니다.
POST /projects/:id/service_accounts/:user_id/personal_access_tokens/:token_id/rotate
파라미터:
| Attribute | Type | Required | Description |
|---|---|---|---|
id |
integer or string | yes | 타깃 프로젝트의 ID 또는 URL 인코딩된 경로. |
user_id |
integer | yes | 서비스 계정의 ID. |
token_id |
integer | yes | 토큰의 ID. |
expires_at |
date | no | ISO 형식(YYYY-MM-DD)으로 지정한 액세스 토큰의 만료 날짜. GitLab 17.9에서 도입됨. 토큰에 만료 날짜가 필요하면 기본값은 1주입니다. 필요하지 않으면 토큰에는 만료 날짜가 없습니다. |
요청 예시:
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/35/service_accounts/71/personal_access_tokens/6/rotate"
응답 예시:
{
"id":7,
"name":"service_accounts_token",
"revoked":false,
"created_at":"2023-06-13T07:54:49.962Z",
"scopes":["api"],
"user_id":71,
"last_used_at":null,
"last_used_ips":[],
"active":true,
"expires_at":"2023-06-20",
"token":"<token_value>"
}
세분화된 스코프가 있는 토큰을 교체하면 새 토큰의 granular_scopes 속성으로 해당 스코프가 반환됩니다. 자세한 내용은
모든 개인 액세스 토큰 나열을 참고합니다.