Filestore용 맞춤 제약조건 만들기

이 페이지에서는 조직 정책 서비스 커스텀 제약 조건을 사용하여 다음 Google Cloud 리소스에 대한 특정 작업을 제한하는 방법을 보여줍니다.

  • file.googleapis.com/Instance
  • file.googleapis.com/Backup
  • file.googleapis.com/Snapshot

조직 정책에 대한 자세한 내용은 커스텀 조직 정책을 참조하세요.

조직 정책 및 제약조건 정보

Google Cloud 조직 정책 서비스를 사용하면 조직 리소스를 중앙에서 프로그래매틱 방식으로 제어할 수 있습니다. 조직 정책 관리자Google Cloud 리소스 계층 구조에서Google Cloud 리소스 및 이러한 리소스의 하위 요소에 적용되는 제약 조건이라는 제한사항 집합인 조직 정책을 정의할 수 있습니다. 조직, 폴더 또는 프로젝트 수준에서 조직 정책을 적용할 수 있습니다.

조직 정책은 다양한 Google Cloud 서비스에 내장된 관리형 제약 조건을 제공합니다. 그러나 조직 정책에서 제한되는 특정 필드를 보다 세부적으로 맞춤설정 가능한 방식으로 제어하려면 커스텀 제약조건을 만들고 조직 정책에 이러한 커스텀 제약조건을 사용할 수 있습니다.

정책 상속

기본적으로 조직 정책은 정책을 적용하는 리소스의 하위 요소에 상속됩니다. 예를 들어 폴더에 정책을 적용하면 Google Cloud 가 폴더의 모든 프로젝트에 정책을 적용합니다. 이 동작 및 이를 변경하는 방법에 대한 자세한 내용은 계층 구조 평가 규칙을 참조하세요.

시작하기 전에

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Install the Google Cloud CLI.

  5. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  8. Make sure that billing is enabled for your Google Cloud project.

  9. Install the Google Cloud CLI.

  10. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  11. To initialize the gcloud CLI, run the following command:

    gcloud init
  12. 조직 ID를 알고 있어야 합니다.
  13. 필요한 역할

    커스텀 조직 정책을 관리하는 데 필요한 권한을 얻으려면 관리자에게 조직 리소스에 대한 조직 정책 관리자(roles/orgpolicy.policyAdmin) IAM 역할을 부여해 달라고 요청하세요. 역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

    커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.

    커스텀 제약조건 만들기

    커스텀 제약조건은 조직 정책을 적용하는 서비스에서 지원되는 리소스, 메서드, 조건, 작업을 사용하여 YAML 파일에서 정의됩니다. 커스텀 제약조건의 조건은 Common Expression Language(CEL)를 사용하여 정의됩니다. CEL을 사용해서 커스텀 제약 조건에서 조건을 빌드하는 방법은 커스텀 제약 조건 만들기 및 관리의 CEL 섹션을 참조하세요.

    커스텀 제약조건을 만들려면 다음 형식을 사용하여 YAML 파일을 만듭니다.

    name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
    resourceTypes:
    - RESOURCE_NAME
    methodTypes:
    - CREATE
    - UPDATE
    condition: "CONDITION"
    actionType: ACTION
    displayName: DISPLAY_NAME
    description: DESCRIPTION
    

    다음을 바꿉니다.

  • ORGANIZATION_ID: 조직 ID입니다(예: 123456789).

  • CONSTRAINT_NAME: 새 커스텀 제약조건에 사용하려는 이름입니다. 커스텀 제약조건은 custom.으로 시작해야 하며 대문자, 소문자 또는 숫자만 포함할 수 있습니다. 예를 들면 custom.deletionProtectionEnabledEnforcedOnCreate입니다. 이 필드의 최대 길이는 70자입니다.

  • RESOURCE_NAME: 제한하려는 객체 및 필드가 포함된Google Cloud 리소스의 정규화된 이름. 예를 들면 file.googleapis.com/Instance입니다.

  • CONDITION: 지원되는 서비스 리소스의 표현에 대해 작성된 CEL 조건. 이 필드의 최대 길이는 1000자(영문 기준)입니다. 조건을 작성하는 데 사용할 수 있는 리소스에 대한 자세한 내용은 지원되는 리소스를 참조하세요. 예를 들면 "resource.deletionProtectionEnabled == true"입니다.

  • ACTION: condition이 충족될 때 수행할 작업. 가능한 값은 ALLOWDENY입니다.

  • DISPLAY_NAME: 제약조건에 대한 사용자 친화적인 이름. 이 필드의 최대 길이는 200자(영문 기준)입니다.

  • DESCRIPTION: 정책을 위반할 때 오류 메시지로 표시할 제약조건에 대한 사용자 친화적인 설명. 이 필드의 최대 길이는 2,000자(영문 기준)입니다.

커스텀 제약조건을 만드는 방법에 대한 자세한 내용은 커스텀 제약조건 정의를 참조하세요.

커스텀 제약조건 설정

새 커스텀 제약조건의 YAML 파일을 만든 후에는 조직에서 조직 정책에 사용할 수 있도록 설정해야 합니다. 커스텀 제약조건을 설정하려면 gcloud org-policies set-custom-constraint 명령어를 사용합니다.
gcloud org-policies set-custom-constraint CONSTRAINT_PATH
CONSTRAINT_PATH를 커스텀 제약조건 파일의 전체 경로로 바꿉니다. 예를 들면 /home/user/customconstraint.yaml입니다. 완료되면 Google Cloud 조직 정책 목록에서 조직 정책으로 커스텀 제약 조건을 사용할 수 있습니다. 커스텀 제약 조건이 존재하는지 확인하려면 gcloud org-policies list-custom-constraints 명령어를 사용합니다.
gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
ORGANIZATION_ID를 조직 리소스 ID로 바꿉니다. 자세한 내용은 조직 정책 보기를 참조하세요.

커스텀 조직 정책 적용

제약 조건을 참조하는 조직 정책을 만들고 해당 조직 정책을 Google Cloud 리소스에 적용하여 제약 조건을 적용할 수 있습니다.

콘솔

  1. Google Cloud 콘솔에서 조직 정책 페이지로 이동합니다.

    조직 정책으로 이동

  2. 프로젝트 선택 도구에서 조직 정책을 설정할 프로젝트를 선택합니다.
  3. 조직 정책 페이지의 목록에서 제약조건을 선택하여 해당 제약조건의 정책 세부정보 페이지를 봅니다.
  4. 이 리소스의 조직 정책을 구성하려면 정책 관리를 클릭합니다.
  5. 정책 수정 페이지에서 상위 정책 재정의를 선택합니다.
  6. 규칙 추가를 클릭합니다.
  7. 적용 섹션에서 이 조직 정책 적용을 사용 설정할지 여부를 선택합니다.
  8. (선택사항) 태그로 조직 정책을 조건부로 만들려면 조건 추가를 클릭합니다. 조건부 규칙을 조직 정책에 추가하면 비조건부 규칙을 최소 하나 이상 추가해야 합니다. 그렇지 않으면 정책을 저장할 수 없습니다. 자세한 내용은 태그를 사용하여 조직 정책 설정을 참조하세요.
  9. 변경사항 테스트를 클릭하여 조직 정책의 효과를 시뮬레이션합니다. 기존 관리형 제약 조건에는 정책 시뮬레이션을 사용할 수 없습니다. 자세한 내용은 정책 시뮬레이터로 조직 정책 변경사항 테스트를 참조하세요.
  10. 조직 정책을 완료하고 적용하려면 정책 설정을 클릭합니다. 정책이 적용되는 데 최대 15분이 소요됩니다.

gcloud

불리언 규칙이 있는 조직 정책을 만들려면 제약 조건을 참조하는 정책 YAML 파일을 만듭니다.

      name: projects/PROJECT_ID/policies/CONSTRAINT_NAME
      spec:
        rules:
        - enforce: true
    

다음을 바꿉니다.

  • PROJECT_ID: 제약조건을 적용할 프로젝트
  • CONSTRAINT_NAME: 커스텀 제약조건에 대해 정의된 이름. 예를 들면 custom.deletionProtectionEnabledEnforcedOnCreate입니다.

제약조건이 포함된 조직 정책을 적용하려면 다음 명령어를 실행합니다.

    gcloud org-policies set-policy POLICY_PATH
    

POLICY_PATH를 조직 정책 YAML 파일의 전체 경로로 바꿉니다. 정책이 적용되는 데 최대 15분이 소요됩니다.

커스텀 조직 정책 테스트

다음 예에서는 deletionProtection 필드가 true로 설정된 경우 사용자가 Filestore 인스턴스를 만들 수 있는 커스텀 제약조건 및 정책을 만듭니다.

시작하기 전에 다음을 준비하세요.

  • 조직 ID
  • 프로젝트 ID

제약조건 만들기

  1. 다음 파일을 constraint-instance.yaml로 저장합니다.

    name: organizations/ORGANIZATION_ID/customConstraints/custom.deletionProtectionEnabledEnforcedOnCreate
    resourceTypes:
    - file.googleapis.com/Instance
    methodTypes:
    - CREATE
    condition: "resource.deletionProtectionEnabled == true"
    actionType: ALLOW
    displayName: Enforce deletion protection
    description: Enforce instance creation with deletion protection.
    

    이는 CREATE 메서드에서 deletionProtection 필드가 true로 설정되어야 하는 제약조건을 정의합니다.

  2. 제약조건을 적용합니다.

    gcloud org-policies set-custom-constraint constraint-instance.yaml
    
  3. 제약조건이 있는지 확인합니다.

    gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
    

    출력은 다음과 비슷합니다.

    CUSTOM_CONSTRAINT                                 ACTION_TYPE  METHOD_TYPES   RESOURCE_TYPES                DISPLAY_NAME
    custom.deletionProtectionEnabledEnforcedOnCreate  ALLOW        CREATE         file.googleapis.com/Instance  Enforce deletion protection
    
    ...
    

정책 만들기

  1. 다음 파일을 policy-instance.yaml로 저장합니다.

    name: projects/PROJECT_ID/policies/custom.deletionProtectionEnabledEnforcedOnCreate
    spec:
      rules:
      - enforce: true
    

    PROJECT_ID를 프로젝트 ID로 바꿉니다.

  2. 정책을 적용합니다.

    gcloud org-policies set-policy policy-instance.yaml
    
  3. 정책이 있는지 확인합니다.

    gcloud org-policies list --project=PROJECT_ID
    

    출력은 다음과 비슷합니다.

    CONSTRAINT                                        LIST_POLICY  BOOLEAN_POLICY  ETAG
    custom.deletionProtectionEnabledEnforcedOnCreate  -            SET             CJqb674GEMiAzGE=-
    

정책을 적용한 후 Google Cloud 가 정책 시행을 시작할 때까지 2분 정도 기다립니다.

정책 테스트

deletionProtectiontrue로 설정하지 않고 인스턴스를 만들어 보세요.

  gcloud filestore instances create test-ins --zone=us-central1 --tier=enterprise --network=name="default" --file-share="capacity=1024,name=test-fs"

출력은 다음과 비슷합니다.

ERROR: (gcloud.filestore.instances.create) FAILED_PRECONDITION: Operation denied by custom org policy on resource 'projects/test-project/locations/us-central1/instances/test-ins': ["customConstraints/custom.deletionProtectionEnabledEnforcedOnCreate": "Enforce instance creation with deletion protection."].
- '@type': type.googleapis.com/google.rpc.DebugInfo
  detail: "generic::failed_precondition: Operation denied by custom org policy on\
    \ resource 'projects/test-project/locations/us-central1/instances/test-ins':\
    \ [\"customConstraints/custom.deletionProtectionEnabledEnforcedOnCreate\": \"\
    Enforce instance creation with deletion protection.\"]."
  .
  .
  .

- '@type': type.googleapis.com/google.rpc.DebugInfo
- '@type': type.googleapis.com/google.rpc.ErrorInfo
  domain: file.googleapis.com
  metadata:
    customConstraints: customConstraints/custom.deletionProtectionEnabledEnforcedOnCreate
    resource: projects/test-project/locations/us-central1/instances/test-ins
  reason: CUSTOM_ORG_POLICY_VIOLATION

일반적인 사용 사례의 커스텀 조직 정책 예시

다음 표에는 유용한 커스텀 조직 정책이 나와 있습니다.

설명 제약조건 구문
제한된 IP 및 역할 목록에 액세스 제어를 설정할 때 관리자 IP를 고유한 IP로 설정할 수 있도록 허용
    name: organizations/ORGANIZATION_ID/customConstraints/custom.filestoreAdminIP
    resourceTypes:
    - file.googleapis.com/Instance
    methodTypes:
    - CREATE
    - UPDATE
    condition: "resource.fileShares.size() > 0 && resource.fileShares[0].nfsExportOptions.size() > 0 && resource.fileShares[0].nfsExportOptions.exists(o, o.squashMode == 'NO_ROOT_SQUASH' && o.accessMode == 'READ_WRITE' && o.ipRanges.exists(i, i != '10.0.0.1'))"
    actionType: ALLOW
    displayName: Access control admin IP
    description: Access control restriction allows setting admin IP exclusively to 10.0.0.1.
용량이 1,024GB를 초과하는 인스턴스 만들기 사용 중지
    name: organizations/ORGANIZATION_ID/customConstraints/custom.disableLargeCapacity
    resourceTypes:
    - file.googleapis.com/Instance
    methodTypes:
    - CREATE
    - UPDATE
    condition: "resource.fileShares.size() > 0 && resource.fileShares[0].capacityGb > 1024"
    actionType: DENY
    displayName: Disable large instance creation
    description: Instance capacity must be up to 1024 GB.
이름에 test라는 단어가 포함된 소스 인스턴스로 백업을 만들지 못하도록 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.denyBackupFromTestInstance
    resourceTypes:
    - file.googleapis.com/Backup
    methodTypes:
    - CREATE
    condition: "resource.sourceInstance.contains('test')"
    actionType: DENY
    displayName: Deny backup of test instance
    description: Don't allow creating a backup if the source instance contains 'test' in its name.

Filestore 지원 리소스

다음 표에는 커스텀 제약조건에서 참조할 수 있는 Filestore 리소스가 나와 있습니다.

리소스 필드
file.googleapis.com/Backup resource.description
resource.kmsKey
resource.sourceFileShare
resource.sourceInstance
file.googleapis.com/Instance resource.deletionProtectionEnabled
resource.deletionProtectionReason
resource.description
resource.fileShares.capacityGb
resource.fileShares.name
resource.fileShares.nfsExportOptions.accessMode
resource.fileShares.nfsExportOptions.anonGid
resource.fileShares.nfsExportOptions.anonUid
resource.fileShares.nfsExportOptions.ipRanges
resource.fileShares.nfsExportOptions.squashMode
resource.fileShares.sourceBackup
resource.kmsKeyName
resource.networks.connectMode
resource.networks.modes
resource.networks.network
resource.networks.reservedIpRange
resource.performanceConfig.fixedIops.maxIops
resource.performanceConfig.iopsPerTb.maxIopsPerTb
resource.protocol
resource.replication.replicas.peerInstance
resource.replication.role
resource.tier
file.googleapis.com/Snapshot resource.description

다음 단계