VM 기본 서비스 계정의 권한 검토

VM의 용도에 맞는 서비스 계정과 최소 권한을 구성하세요.

설명

Compute Engine VM에는 워크로드에 필요한 IAM 역할만 가진 전용 서비스 계정을 연결하세요.

잠재적 영향

기본 계정을 여러 VM이 공유하면 한 VM의 권한을 줄일 때 같은 계정을 쓰는 다른 VM의 작업도 중단될 수 있습니다.

해결 방법

준비한 계정의 이메일을 service_accounts의 email에 지정하세요. 기존 VM은 중지한 뒤 계정을 변경하고 다시 시작해 필요한 작업을 확인하세요. auth_kind는 Ansible 자체의 인증 설정입니다.

예시

변경 후 예제는 새 이름 test-object로 VM을 정의합니다. 기존 test-object1과 test-object4의 계정을 바꾸려면 각 VM에 변경을 적용해야 합니다. 새 VM을 만들 때는 부팅 디스크도 지정하세요.

변경 전

yaml
- name: test-object1 VM 생성
  google.cloud.gcp_compute_instance:
    name: test-object1
    machine_type: n1-standard-1
    zone: us-central1-a
    project: "{{ gcp_project_id }}"
    auth_kind: serviceaccount
    state: present

- name: test-object4 VM 생성
  google.cloud.gcp_compute_instance:
    name: test-object4
    machine_type: n1-standard-1
    zone: us-central1-a
    project: "{{ gcp_project_id }}"
    auth_kind: serviceaccount
    service_accounts:
      - email: "{{ project_number }}-compute@developer.gserviceaccount.com"
    state: present

변경 후

yaml
- name: VM 생성
  google.cloud.gcp_compute_instance:
    name: test-object
    machine_type: n1-standard-1
    zone: us-central1-a
    project: "{{ gcp_project_id }}"
    auth_kind: serviceaccount
    service_accounts:
      - email: "{{ vm_service_account_email }}"
        scopes:
          - https://www.googleapis.com/auth/cloud-platform
    state: present

참조