IT/Infra&Cloud

[gcp] Cloud ID로 조직 생성&테라폼 배포

Hayley Shim 2023. 10. 30. 00:06

안녕하세요. Google Workspace의 다양한 서비스 중에서도 계정 관리를 위해 별도로 만들어진 서비스인 Cloud ID로 조직을 생성하고 테라폼으로 배포해보겠습니다.

Cloud ID는아래와 같은 기능을 지원합니다.

  • 직원의 사용자 계정 및 그룹 관리
  • 조직 구조를 만들고 조직의 모든 프로젝트 및 리소스를 중앙에서 제어
  • 보안 가드레일 구성

사전 단계

1. Google Cloud 콘솔 내 ID 및 조직 접속

우선 Google Cloud 콘솔에서 아래 [IAM 및 관리자 — ID 및 조직]에 접속합니다.

2. 조직 계정 생성

접속 후 admin.google.com 콘솔에서 조직을 위한 계정을 생성해줍니다.

3. Cloud ID용 도메인 확인 후 등록

아래 자료를 참고해서 가지고 있는 도메인 호스팅 영역에 Cloud ID 서비스를 위한 DNS 레코드를 추가해줍니다.

  • Cloud ID용 도메인 확인 : 참고
  • AWS 도메인 확인 : 참고
  • AWS 퍼블릭 호스팅 : 참고

주의 : 등록한 도메인에 네임서버와 호스팅 영역의 네임서버(NS) 값이 일치하는지 확인합니다. 현재 도메인의 DNS를 조회하기 위해 아래 사이트에서 쿼리 응답이 제대로 오는지 확인할 수 있습니다.(Dig(DNS) 조회: 참고)

Cloud ID를 위한 도메인이 확인되었다면 아래와 같이 DNS 조회 시 정상 응답이 오는 것을 확인할 수 있습니다.

Dig(DNS 조회) 화면

Cloud ID에 도메인 등록 화면

실습 단계

1. 조직 만들기

위에서 보호 설정한 도메인을 가지고 Google Cloud 조직을 만들어보겠습니다.

2. 사용자 및 그룹 만들기

1) Google Cloud 기초 설정을 위한 관리 그룹 만들기

아래와 같이 조직의 핵심 기능을 관리할 사용자 그룹을 만듭니다. 후반부 태스크에서 역할 기반 IAM 권한을 부여하려면 이 태스크에서 만든 그룹이 반드시 필요합니다.

테스트를 위해 우선 모든 그룹을 만들어줬습니다.

2) Google 관리 콘솔에서 관리 권한 사용자 만들기

그룹 내 지정할 사용자를 추가해줍니다.

아래와 같이 security 담당 사용자를 추가해주었습니다.

추가한 사용자에 그룹을 매핑합니다.

gcp-security-admins@wellbeconnected.com 그룹에 추가해주었습니다.

 

 

3. 관리 액세스

아래와 같이 그룹별 IAM 기본 역할이 지정되어있고 해당 그룹별로 역할을 수정할 수 있습니다.

우선 기본 역할로 두었습니다.

4. 결제

아래와 같이 IAM 역할 중 결제 계정 생성자 역할을 부여하면 결제 계정을 연결할 수 있습니다.

아래 사용자에게 결제 계정 생성자 역할을 부여하고 결제 계정을 연결했습니다.

5. 계층 구조 및 액세스

아래와 같이 리소스 계층 구조를 설정합니다.

Google Cloud 리소스 계층 구조의 가장 완벽한 형태에는 조직 리소스, 폴더 , 프로젝트 가 포함됩니다. 이를 통해 회사에서 조직을 Google Cloud로 매핑하고 액세스 관리 정책(IAM) 및 조직 정책에 대한 논리적 연결 지점을 제공할 수 있습니다. 조직의 니즈에 맞는 리소스 계층 구조 모델을 선택합니다.

리소스 계층 구조 모델 선택

아래와 같이 비지니스 단위 중심의 계층 구조를 통해 사업부/팀/환경/프로젝트별로 구성해주었습니다.

권장 계층 구조 구성

서비스 프로젝트에 필수 프로젝트로 host/logging/monitoring 등의 프로젝트를 설정해주었습니다.

IAM 정책을 설정하여 액세스 권한을 할당해줍니다.

6. 네트워킹

공유 VPC 네트워크 개요

VPC 네트워크는 Google Cloud 내에서 가상화된다는 점을 제외하면 물리적 네트워크와 유사하며, 리전별 서브네트워크(서브넷) 목록으로 구성된 전역 리소스입니다. 공유 VPC 는 프로젝트 하나를 호스트 프로젝트 로 지정하고 하나 이상의 다른 서비스 프로젝트 를 여기에 연결할 수 있게 해 주는 VPC 유형입니다. 호스트 프로젝트를 사용하면 경로, 방화벽, VPN 연결, 서브넷을 중앙에서 관리할 수 있을 뿐 아니라 보조 범위를 포함하여 선택한 서브넷을 서비스 프로젝트와 공유할 수 있습니다. 서비스 프로젝트는 호스트 프로젝트에 연결된 모든 프로젝트입니다.

shared vpc

서브넷과 방화벽 규칙을 포함하여 프로덕션 및 비프로덕션 호스트 프로젝트 모두를 위한 공유 VPC 네트워크를 구성합니다.

서브넷 설정

방화벽 설정

아래와 같이 공유 vpc 네트워크가 설정되었습니다.

아래와 같이 공유 vpc 네트워크에 서비스 프로젝트를 연결해줍니다.

 

 

7. 로깅 중앙화

이제 로깅 중앙화를 통해 로그를 쌓을 버킷을 생성해줍니다.

모든 프로젝트의 로그를 쉽게 검색하고 분석할 수 있도록 로깅 데이터를 보관하는 기본 컨테이너인 중앙 Logging 로그 버킷에 모든 로그를 라우팅하는 것이 좋습니다. 이 로그 버킷은 사용자 또는 조직의 관리자가 5단계: 리소스 계층 구조 및 액세스에서 만든 중앙 로깅 프로젝트에 저장됩니다.

아래와 같이 로깅을 구성합니다.

구성 배포

앞서 구성한 리소스 계층 구조, 네트워킹, 로깅을 테라폼으로 배포합니다.

아래와 같이 각 인프라별로 코드가 생성되었습니다.

terraform init

Cloud shell 환경 내 테라폼 환경을 초기화해줍니다.

cloud shell terraform init

terraform plan

plan 도중 아래와 같은 에러가 발생했습니다.

Error: Error when reading or editing Organization Not Found : organizations/43289124806: googleapi: Error 403: Cloud Resource Manager API has not been used in project titanium-gamma-400407 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=titanium-gamma-400407 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.Help",
│     "links": [
│       {
│         "description": "Google developers console API activation",
│         "url": "https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=titanium-gamma-400407"
│       }
│     ]
│   },
│   {
│     "@type": "type.googleapis.com/google.rpc.ErrorInfo",
│     "domain": "googleapis.com",
│     "metadata": {
│       "consumer": "projects/titanium-gamma-400407",
│       "service": "cloudresourcemanager.googleapis.com"
│     },
│     "reason": "SERVICE_DISABLED"
│   }
│ ]
│ , accessNotConfigured
│ 
│   with data.google_organization.org,
│   on data.tf line 1, in data "google_organization" "org":
│    1: data "google_organization" "org" {

terraform plan을 실행하는 도중 발생한 아래 에러들을 해결해줍니다.

  1. Resource Manager API 활성화

Error: Error when reading or editing Organization Not Found : organizations/43289124806: googleapi: Error 403: Cloud Resource Manager API has not been used in project titanium-gamma-400407 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=titanium-gamma-400407 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

해당 계정에 누락된 권한을 부여합니다.(resourcemanager.projects.get)

해당 권한을 가진 predefined role 중에서 프로젝트 IAM 관리자 역할을 부여해주었습니다.

아래와 같이 Cloud Resource Manager API 사용을 enable로 바꿔줍니다.

위 API를 통해 다음의 기능을 할 수 있습니다.

  • Creates, reads, and updates metadata for Google Cloud Platform resource containers.

이제 terraform plan을 실행하면 정상적으로 동작하는 것을 볼 수 있습니다.

 # 아래와 같이 205개의 리소스가 생성되었습니다. 

  # module.cs-svc-depart-team-2-nonprod-svc-79od.module.project-factory.module.project_services.google_project_service.project_services["compute.googleapis.com"] will be created
  + resource "google_project_service" "project_services" {
      + disable_dependent_services = true
      + disable_on_destroy         = true
      + id                         = (known after apply)
      + project                    = "depart-team-2-nonprod-svc-79od"
      + service                    = "compute.googleapis.com"
    }

  # module.cs-svc-depart-team-2-prod-svc-79od.module.project-factory.module.project_services.google_project_service.project_services["compute.googleapis.com"] will be created
  + resource "google_project_service" "project_services" {
      + disable_dependent_services = true
      + disable_on_destroy         = true
      + id                         = (known after apply)
      + project                    = "depart-team-2-prod-svc-79od"
      + service                    = "compute.googleapis.com"
    }

  # module.cs-vpc-host-nonprod-ag807-ms700.module.project-factory.module.project_services.google_project_service.project_services["compute.googleapis.com"] will be created
  + resource "google_project_service" "project_services" {
      + disable_dependent_services = true
      + disable_on_destroy         = true
      + id                         = (known after apply)
      + project                    = "vpc-host-nonprod-ag807-ms700"
      + service                    = "compute.googleapis.com"
    }

  # module.cs-vpc-host-prod-ag807-ms700.module.project-factory.module.project_services.google_project_service.project_services["compute.googleapis.com"] will be created
  + resource "google_project_service" "project_services" {
      + disable_dependent_services = true
      + disable_on_destroy         = true
      + id                         = (known after apply)
      + project                    = "vpc-host-prod-ag807-ms700"
      + service                    = "compute.googleapis.com"
    }

Plan: 205 to add, 0 to change, 0 to destroy.

terraform apply를 실행하는 도중 발생한 아래 에러들을 해결해줍니다.

  1. billing API 활성화

아래와 같은 이유로 billing API를 활성화해줍니다.

Error: failed pre-requisites: failed to check permissions on billing account “billingAccounts/01B2F3–6B9ED1-D870E8”: googleapi: Error 403: Cloud Billing API has not been used in project titanium-gamma-400407 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=titanium-gamma-400407 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
│ Details:

2. identity API 활성화

아래와 같은 이유로 Cloud identity API를 활성화해줍니다.

Error: Error creating Group: googleapi: Error 403: Cloud Identity API has not been used in project titanium-gamma-400407 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudidentity.googleapis.com/overview?project=titanium-gamma-400407 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

3. IAM API 활성화

Error: error creating project logging-ag807-ms700 (logging): googleapi: Error 409: Requested entity already exists, alreadyExists. If you received a 403 error, make sure you have the `roles/resourcemanager.projectCreator` permission

4. 조직에서 roles/resourcemanager.projectCreator` permission 할당

Error: error creating project logging-ag807-ms700 (logging): googleapi: Error 409: Requested entity already exists, alreadyExists. If you received a 403 error, make sure you have the `roles/resourcemanager.projectCreator` permission

참고 : https://stackoverflow.com/questions/69912853/google-cloud-platform-terraform-terragrunt-googleapi-error-409-requested-entit

조직에서 해당 계정에 프로젝트 생성자 권한을 줍니다.

 Error: error creating project logging-ag807-ms700 (logging): googleapi: Error 409: Requested entity already exists, alreadyExists. If you received a 403 error, make sure you have the `roles/resourcemanager.projectCreator` permission
│ 
│   with module.cs-logging-ag807-ms700.module.project-factory.google_project.main,
│   on .terraform/modules/cs-logging-ag807-ms700/modules/core_project_factory/main.tf line 73, in resource "google_project" "main":
│   73: resource "google_project" "main" {
│ 

8. 모니터링

아래와 같이 개별 프로젝트에 대해 추가 구성할 필요 없이 Google이 조직에 Cloud Monitoring을 자동으로 설정합니다. Google의 무료 시스템 측정항목, 대시보드, 알림, 업타임 체크를 사용하여 인프라 상태를 분석하고 문제를 해결할 수 있습니다.

9. 보안

아래 목록에는 Google에서 대부분의 기업 고객에게 권장하는 정책 집합이 나와 있습니다. 조직에 추가 비용이 발생하지 않으며 나중에 언제든지 변경할 수 있습니다.[조직 정책 알아보기]

아래와 같이 조직 정책을 선택할 수 있습니다.

참고: 이러한 정책은 조직 수준에서 설정됩니다. 조직에 속한 모든 폴더 또는 프로젝트에 자동으로 상속됩니다.

적용된 조직 정책은 Security Command Center(SCC)에서 확인가능합니다.

위와 같이 Google Cloud의 리소스 계층 구조 또한 테라폼으로 배포가 가능합니다. Google Cloud에는 Terraform managed service인 Infra Manager가 있습니다. [docs:infra manager]

Infra Manager를 사용하면 코드형 인프라(IaC) 원칙을 쉽게 시작하여 Terraform을 사용하여 Google Cloud 인프라 및 리소스를 프로비저닝할 수 있습니다.[참고 : Introducing Infrastructure Manager: Provision Google Cloud resources with HashiCorp Terraform]

 

 

blog migration project

written in 2023.10.14

https://medium.com/techblog-hayleyshim/gcp-cloud-id%EB%A1%9C-%EC%A1%B0%EC%A7%81-%EC%83%9D%EC%84%B1-%ED%85%8C%EB%9D%BC%ED%8F%BC-%EB%B0%B0%ED%8F%AC-3a2f11f3cbb9

'IT > Infra&Cloud' 카테고리의 다른 글

[aws] Service Catalog - cloudformation  (0) 2023.11.03
[aws] Service Catalog - Terraform Engine  (0) 2023.10.30
[aws] Control Tower  (0) 2023.10.30
[aws] EKS Automation  (0) 2023.10.30
[aws] EKS Security  (0) 2023.10.30