# GCP 서비스 계정 키 없이 쓰기: 가장과 PERMISSION_DENIED 읽기

> 역할 없이 서비스 계정 cr-lab-sa를 만들고 Keys 탭의 키 위험 경고를 읽습니다. 키는 만들지 않고 Storage Object Viewer 역할 하나만 부여합니다. Cloud Shell에서 --impersonate-service-account로 가장을 시도하자 프로젝트 Owner 계정도 roles/iam.serviceAccountTokenCreator 역할이 없어 PERMISSION_DENIED가 났습니다. 가장이 성공하는 것은 확인하지 않았고, 권한을 회수한 뒤 서비스 계정을 지웠습니다.

- 주소: https://copyandrun.com/blog/gcp-service-account-no-key-impersonation/
- 분야: 클라우드
- 발행일: 2026-11-10
- 태그: GCP, Google Cloud, IAM, 서비스 계정, impersonation, 보안 점검

서비스 계정은 사람이 아니라 코드나 시스템이 쓰는 신원입니다. 콘솔의 안내 문구는 서비스 계정을 "a Google Cloud service identity, such as code running on Compute Engine VMs, App Engine apps, or systems running outside Google"이라고 설명합니다. 이 글은 서비스 계정을 만들고, 키 대신 다른 계정이 그 계정을 가장(impersonate)하는 방식을 콘솔과 Cloud Shell에서 시도한 기록입니다.

결과를 먼저 말하면, 가장은 성공하지 않았습니다. 프로젝트 Owner 계정으로 시도했지만 `roles/iam.serviceAccountTokenCreator` 역할이 없어서 PERMISSION_DENIED가 났습니다. 이 글은 그 오류 문구를 읽는 실습입니다. 가장이 되는 상태는 만들지 않았습니다.

## 한 문장 답

IAM & Admin > **Service Accounts** > **Create service account**에서 이름만 넣고 역할 없이 서비스 계정을 만들 수 있습니다. Keys 탭에는 키 위험 경고와 Add key 메뉴가 있지만, 이 글에서는 키를 만들지 않았습니다. 대신 Cloud Shell에서 `--impersonate-service-account`로 가장을 시도했고, 프로젝트 Owner (Legacy) 계정으로도 `iam.serviceAccounts.getAccessToken` 권한 거부(PERMISSION_DENIED)가 났습니다. 가장이 성공하는 것은 확인하지 않았습니다.

## 준비물

| 항목 | 내용 |
| --- | --- |
| 프로젝트 | `copyandrun-net-lab`. 조직이 없어서 조직 정책 화면은 확인하지 않았습니다 |
| 화면 | IAM & Admin > Service Accounts, IAM, Cloud Shell |
| 만든 계정 | `cr-lab-sa`, 이메일 `cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com`, 설명 `Lab service account, no keys` |
| 부여한 역할 | 프로젝트에 Storage Object Viewer (`roles/storage.objectViewer`) 하나. 실습 끝에 회수했습니다 |
| 콘솔 예상 금액 | 화면에 표시가 없었습니다 |

## 입력할 값

| 화면 항목 | 입력하거나 고른 값 |
| --- | --- |
| Service account name | `cr-lab-sa`. Display name for this service account라는 안내가 붙어 있습니다 |
| Service account ID | 이름을 넣으면 `cr-lab-sa`로 자동으로 채워졌습니다 |
| Service account description | `Lab service account, no keys` |
| 2단계 Permissions (optional) | 역할을 고르지 않음 |
| 3단계 Principals with access (optional) | 비워 둠 |

## 1. 역할 없이 서비스 계정 만들기

1. Service accounts 목록을 엽니다. 화면에는 "A service account represents a Google Cloud service identity, such as code running on Compute Engine VMs, App Engine apps, or systems running outside Google."라는 안내가 있습니다. 같은 안내에는 "Organization policies can be used to secure service accounts and block risky service account features, such as automatic IAM Grants, key creation/upload, or the creation of service accounts entirely."라는 문구도 있습니다. 목록의 열은 Email, Status, Name, Description, Key ID, Key creation date, OAuth 2 Client ID, Actions입니다. 처음에는 Compute Engine 기본 서비스 계정 하나만 있었고, 그 행의 Key ID는 "No keys"였습니다.

2. **Create service account**를 누릅니다. 1단계 "Create service account"에서 **Service account name**에 `cr-lab-sa`를 입력합니다. 그러면 **Service account ID**가 `cr-lab-sa`로 자동으로 채워지고, 아래에 "Email address: cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com"이 나타납니다. **Service account description**에 `Lab service account, no keys`를 넣고 **Create and continue**를 누릅니다. 알림 "Service account created"가 뜹니다.

   이 시점에 계정은 이미 만들어집니다. 뒤의 2단계와 3단계에서 Cancel을 눌러도 계정은 남습니다.

   ![서비스 계정 이름을 넣으면 ID와 이메일 주소가 자동으로 채워지는 것을 확인합니다.](https://copyandrun.com/img/gcp-service-account-no-key-impersonation/01-create-sa-form.png)

3. 2단계 "Permissions (optional)"에는 "Grant this service account access to copyandrun-net-lab so that it has permission to complete specific actions on the resources in your project."라는 안내가 있습니다. 역할을 고르지 않고 **Continue**를 누릅니다. 오른쪽 info 패널의 "Permissions"에는 프로젝트에서 상속된 역할 네 개가 보입니다. Compute Engine Service Agent, Editor (Legacy), Instance Group Manager Service Agent, Owner (Legacy)입니다. 이 역할들은 계정에 직접 준 것이 아니라 프로젝트에서 상속된 것입니다.

   ![역할을 고르지 않고 Permissions 단계를 넘긴 것을 확인합니다.](https://copyandrun.com/img/gcp-service-account-no-key-impersonation/02-sa-optional-steps.png)

4. 3단계 "Principals with access (optional)"에는 "Grant access to users or groups that need to perform actions as this service account."라는 안내가 있습니다. 칸은 "Service account users role"과 "Service account admins role"입니다. 두 칸을 비워 두고 **Done**을 누릅니다.

## 2. Keys 탭 읽기 (키는 만들지 않음)

5. 계정 상세 화면의 탭은 Details, Permissions, Keys, Metrics, Logs, Principals with access입니다. Details 탭에는 Email, Unique ID와 함께 상태가 Enabled로 나옵니다. Disable service account 버튼도 있습니다.

6. **Keys** 탭을 엽니다. 노란 경고 문구는 다음과 같습니다. "Service account keys could pose a security risk if compromised. We recommend you avoid downloading service account keys and instead use the Workload Identity Federation. Learn more about the best way to authenticate service accounts on Google Cloud." 파란 안내에는 "Google automatically disables service account keys detected in public repositories. You can customize this behavior by using the 'iam.serviceAccountKeyExposureResponse' organization policy."라는 문구가 있습니다. "Block service account key creation using organization policies." 문구도 보입니다. 키 표의 열은 Type, Status, Key, Creation date, Expiration date이고, 표에는 "No rows to display"가 나옵니다.

   ![Keys 탭에서 키 위험 경고와 키가 하나도 없는 상태를 확인합니다.](https://copyandrun.com/img/gcp-service-account-no-key-impersonation/03-keys-tab-warning.png)

7. **Add key** 메뉴를 열면 Create new key와 Upload existing key가 나옵니다. 이 글에서는 둘 중 어느 것도 누르지 않고 메뉴를 닫았습니다. 이 프로젝트에는 조직이 없었고, 키 생성을 막는 조직 정책 안내나 차단 메시지는 나오지 않았습니다. Add key 메뉴는 그대로 열렸습니다.

   ![Add key 메뉴는 열어 보기만 하고 키를 만들지 않은 것을 확인합니다.](https://copyandrun.com/img/gcp-service-account-no-key-impersonation/04-add-key-menu-not-used.png)

## 3. 프로젝트 역할 하나만 부여하기

8. 계정 상세의 Permissions 탭에는 "Manage service account permissions"라는 제목이 있습니다. 아래 설명은 "You can edit roles assigned to a service account on resources in this project."입니다. **Manage access**를 누르면 'Edit access to "copyandrun-net-lab"' 패널이 열립니다. Principal은 `cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com`입니다. **Add role**에서 Storage Object Viewer를 고르고 **Save**를 누릅니다. 알림은 "Policy updated. It may take a few minutes for these changes to become active."입니다.

9. IAM 목록에 `cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com`, `cr-lab-sa`, Storage Object Viewer 행이 생겼습니다. 이 계정에는 프로젝트 역할이 하나뿐입니다.

   ![서비스 계정에 Storage Object Viewer 역할 하나만 부여된 것을 확인합니다.](https://copyandrun.com/img/gcp-service-account-no-key-impersonation/05-sa-storage-object-viewer.png)

10. 계정 상세의 **Principals with access** 탭을 엽니다. 안내는 "Principals with access to this service account"입니다. 이어서 "Users with the Owner or Editor basic role on the project can already modify service accounts, ..."라는 문구가 나옵니다. 목록에는 상속된 Compute Engine 기본 서비스 계정(Editor (Legacy))과 사용자 계정(Owner (Legacy))이 있고, Inheritance 열은 copyandrun-net-lab입니다. 이 계정에 직접 준 권한이 아니라 프로젝트에서 내려온 권한입니다.

    ![프로젝트 Owner·Editor가 서비스 계정에 상속으로 접근할 수 있게 표시되는 것을 확인합니다.](https://copyandrun.com/img/gcp-service-account-no-key-impersonation/06-principals-with-access.png)

## 4. Cloud Shell에서 가장 시도하고 오류 읽기

11. 콘솔 위의 Cloud Shell 아이콘을 누릅니다. 이번에는 Editor 화면으로 먼저 열렸습니다. "Authorize Cloud Shell" 창이 나왔고, 창에는 "Cloud Shell needs permission to use your credentials to make Google Cloud API calls."라는 문구가 있습니다. **Authorize**를 누른 뒤 위쪽의 **Open Terminal**을 눌러 터미널을 열었습니다.

12. 다음 명령을 실행했습니다. 이 명령은 `cr-lab-sa` 계정을 가장해서 버킷 목록을 읽으려는 것입니다.

    ```bash
    gcloud storage buckets list --impersonate-service-account=cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com
    ```

13. 출력의 요지는 다음과 같습니다. 원문을 줄인 곳은 `...`으로 남겼습니다.

    ```text
    WARNING: This command is using service account impersonation. All API calls will be executed as [cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com].
    ERROR: (gcloud.storage.buckets.list) PERMISSION_DENIED: Failed to impersonate [cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com]. Make sure the account that's trying to impersonate it has access to the service account itself and the "roles/iam.serviceAccountTokenCreator" role. Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist). Remediate access with this Troubleshooter URL ...
    ```

    오류의 메타데이터에는 `permission: iam.serviceAccounts.getAccessToken`, `reason: IAM_PERMISSION_DENIED`, 그리고 `troubleshooter_url`이 있었습니다. Troubleshooter 주소의 `errorId` 값은 이 글에서 줄였습니다.

    ![Token Creator 역할이 없어 가장(impersonation)이 PERMISSION_DENIED로 막힌 것을 확인합니다.](https://copyandrun.com/img/gcp-service-account-no-key-impersonation/07-impersonate-permission-denied.png)

14. 이 결과는 실습의 핵심입니다. 프로젝트 Owner (Legacy) 계정만으로는 `cr-lab-sa`를 가장할 수 없었습니다. 오류 문구가 필요한 조건을 직접 알려 줍니다. 가장하려는 계정이 서비스 계정 자체에 접근 권한이 있어야 하고, `roles/iam.serviceAccountTokenCreator` 역할도 있어야 한다는 내용입니다. 이 글에서는 사용자 계정에 그 역할을 주지 않았습니다. 사용자 계정의 권한은 바꾸지 않았습니다.

## 5. 정리: 권한을 먼저 회수하고 계정 지우기

15. IAM 목록에서 `cr-lab-sa` 행을 체크하고 **Remove access**를 누릅니다. 대화상자 제목은 'Remove cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com'입니다. 본문에는 "They will lose all non-inherited roles on this resource."라는 문구가 있습니다. **Confirm**을 누르자 "Removed cr-lab-sa@copyandrun-net-lab.iam.gserviceaccount.com" 알림이 떴습니다.

16. 서비스 계정 목록에서 `cr-lab-sa` 행의 ⋮ 메뉴를 엽니다. 메뉴는 Manage details, Manage permissions, Manage keys, View metrics, View logs, Disable, Delete입니다. **Delete**를 누르면 'Delete service account "cr-lab-sa"' 대화상자가 나옵니다. 본문은 다음과 같습니다. "Deleting this service account will delete all associated key IDs, and will prevent the account from authenticating to any API." 그리고 "You cannot restore or roll back this change easily. We highly recommend disabling the service account first, testing for any unexpected impact, and only then deleting."입니다. 버튼은 Cancel, Disable, Delete입니다. 이 글에서는 **Delete**를 눌렀습니다. 알림 "Account cr-lab-sa has been deleted."가 떴고, 목록에는 Compute Engine 기본 서비스 계정만 남았습니다. 계정의 Key ID는 처음부터 "No keys"였습니다.

    이 글에서는 역할 부여를 먼저 회수하고 계정을 나중에 지웠습니다. 감사 로그 시각으로는 프로젝트 정책 변경이 21:54:30, 계정 삭제가 21:55:36입니다. 계정을 먼저 지운 순서는 시험하지 않았습니다.

    ![실습 서비스 계정을 지운 뒤 기본 서비스 계정만 남은 것을 확인합니다.](https://copyandrun.com/img/gcp-service-account-no-key-impersonation/08-sa-deleted.png)

## 자주 막히는 곳

| 증상 | 확인할 것 |
| --- | --- |
| 2단계나 3단계에서 Cancel을 눌렀는데 계정이 남아 있음 | 계정은 **Create and continue**를 누르는 순간 만들어집니다. 남은 계정은 목록에서 Delete로 지웁니다 |
| Owner 계정인데 가장이 안 됨 | Owner (Legacy) 계정으로도 가장은 되지 않았습니다. 오류 메시지가 `roles/iam.serviceAccountTokenCreator`와 `iam.serviceAccounts.getAccessToken`을 알려 줍니다 |
| Cloud Shell이 Editor 화면으로 열림 | 위의 **Open Terminal**을 눌러야 터미널이 나왔습니다. 첫 호출 전에는 Authorize Cloud Shell 창이 떴습니다 |
| 계정을 지우기 전에 역할 부여를 회수해야 하는지 헷갈림 | 이 글에서는 역할 회수를 먼저 하고 계정을 지웠습니다. 반대 순서는 시험하지 않았습니다 |
| 조직이 없는 프로젝트에서 키 생성이 막히는지 궁금함 | 이 프로젝트에서는 Add key 메뉴가 그대로 열렸고 차단 안내는 없었습니다 |

## 자주 묻는 질문

### GCP 서비스 계정 가장(impersonation)을 시도하면 어떤 오류가 나오나요?
프로젝트 Owner 계정으로도 Token Creator 역할이 없어서 PERMISSION_DENIED 오류가 났고, 가장이 성공하는 것은 이 글에서 확인하지 않았습니다.

### GCP 서비스 계정은 역할을 주지 않고 만들 수 있나요?
네, 역할을 고르지 않고 넘겨도 되며, 계정은 Create and continue를 누르는 시점에 이미 만들어집니다.

### GCP 서비스 계정 키를 받기 전에 콘솔은 어떤 경고를 보여 주나요?
Keys 탭에는 키가 유출되면 보안 위험이 될 수 있다는 경고와 함께 키를 내려받기보다 Workload Identity Federation을 쓰라는 안내가 나옵니다.

## 확인 범위

- **해 본 것:**
  - 날짜는 2026-11-10이고 콘솔 언어는 English입니다. 프로젝트는 `copyandrun-net-lab`이고 조직이 없습니다.
  - 역할 없이 서비스 계정 `cr-lab-sa`를 만들었습니다.
  - Keys 탭의 경고를 읽고 Add key 메뉴를 열었다가 닫았습니다. 키는 만들지 않았습니다.
  - 프로젝트에 Storage Object Viewer 하나를 부여했고, 상속된 주체 목록을 봤습니다.
  - Cloud Shell에서 `--impersonate-service-account`로 가장을 시도했고, PERMISSION_DENIED 오류를 확인했습니다.
  - Storage Object Viewer 부여를 회수하고 서비스 계정을 지웠습니다.
- **해 보지 않은 것:**
  - 키를 만들거나 다운로드하지 않았습니다.
  - `roles/iam.serviceAccountTokenCreator`를 누구에게도 주지 않았습니다. 그래서 가장이 성공하는지는 확인하지 않았습니다.
  - 조직 정책을 설정하거나 확인하지 않았습니다.
  - Workload Identity Federation을 설정하지 않았습니다.
  - 서비스 계정을 VM에 연결하지 않았습니다.
  - 계정을 먼저 지웠을 때 IAM에 어떤 바인딩이 남는지 확인하지 않았습니다.
  - 사용자 계정의 권한을 바꾸지 않았습니다.
- **읽을 때 주의:** 이 글의 가장 시도는 실패로 끝났습니다. 성공 기록이 아니고, 오류 문구를 읽는 실습입니다.

관련 글: 이전 글 [GCP IAM 역할 점검: 기본 역할과 최소 권한 커스텀 역할 비교](/blog/gcp-iam-role-least-privilege-console/)에서 커스텀 역할을 만들고 지웠습니다. 같은 계정으로 Policy Troubleshooter를 실행한 내용은 [GCP IAM 기본 개념: 역할, 주체, 정책 바인딩 읽는 법](/blog/gcp-iam-basics-role-principal-policy/)에 있습니다. 다음 글 [GCP Secret Manager로 비밀값 저장하고 접근 권한 제한하기](/blog/gcp-secret-manager-store-access-control/)에서는 이 계정에 비밀 하나에만 접근 권한을 줬다가 회수합니다. Cloud Shell 사용법은 [GCP Cloud Shell 사용법: 설치 없이 브라우저에서 gcloud 실행](/blog/gcp-cloud-shell-browser-gcloud/)을 참고하세요.
