커스텀 역할 생성 및 관리

이 페이지에서는 Identity and Access Management(IAM) 커스텀 역할을 만들고 관리하는 방법을 설명합니다. 역할 관리에는 역할 수정, 사용 중지, 나열, 삭제, 삭제 취소가 포함됩니다.

시작하기 전에

  • Enable the IAM API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  • 인증을 설정합니다.

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

    In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

    C#

    로컬 개발 환경에서 이 페이지의 .NET 샘플을 사용하려면 gcloud CLI를 설치하고 초기화한 후 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정합니다.

      Google Cloud CLI를 설치합니다.

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

      If you're using a local shell, then create local authentication credentials for your user account:

      gcloud auth application-default login

      You don't need to do this if you're using Cloud Shell.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    자세한 내용은 Google Cloud 인증 문서의 로컬 개발 환경의 ADC 설정을 참조하세요.

    C++

    로컬 개발 환경에서 이 페이지의 C++ 샘플을 사용하려면 gcloud CLI를 설치하고 초기화한 후 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정합니다.

      Google Cloud CLI를 설치합니다.

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

      If you're using a local shell, then create local authentication credentials for your user account:

      gcloud auth application-default login

      You don't need to do this if you're using Cloud Shell.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    자세한 내용은 Google Cloud 인증 문서의 로컬 개발 환경의 ADC 설정을 참조하세요.

    Go

    로컬 개발 환경에서 이 페이지의 Go 샘플을 사용하려면 gcloud CLI를 설치하고 초기화한 후 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정합니다.

      Google Cloud CLI를 설치합니다.

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

      If you're using a local shell, then create local authentication credentials for your user account:

      gcloud auth application-default login

      You don't need to do this if you're using Cloud Shell.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    자세한 내용은 Google Cloud 인증 문서의 로컬 개발 환경의 ADC 설정을 참조하세요.

    자바

    로컬 개발 환경에서 이 페이지의 Java 샘플을 사용하려면 gcloud CLI를 설치하고 초기화한 후 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정합니다.

      Google Cloud CLI를 설치합니다.

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

      If you're using a local shell, then create local authentication credentials for your user account:

      gcloud auth application-default login

      You don't need to do this if you're using Cloud Shell.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    자세한 내용은 Google Cloud 인증 문서의 로컬 개발 환경의 ADC 설정을 참조하세요.

    Python

    로컬 개발 환경에서 이 페이지의 Python 샘플을 사용하려면 gcloud CLI를 설치하고 초기화한 후 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정합니다.

      Google Cloud CLI를 설치합니다.

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

      If you're using a local shell, then create local authentication credentials for your user account:

      gcloud auth application-default login

      You don't need to do this if you're using Cloud Shell.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    자세한 내용은 Google Cloud 인증 문서의 로컬 개발 환경의 ADC 설정을 참조하세요.

    REST

    로컬 개발 환경에서 이 페이지의 REST API 샘플을 사용하려면 gcloud CLI에 제공한 사용자 인증 정보를 사용합니다.

      Google Cloud CLI를 설치합니다.

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

    자세한 내용은 Google Cloud 인증 문서의 REST 사용을 위한 인증을 참조하세요.

  • Google Cloud 리소스 계층 구조를 파악합니다.

  • IAM 커스텀 역할 이해를 읽어보세요.

필요한 역할

커스텀 역할을 만들고 관리하는 데 필요한 권한을 얻으려면 관리자에게 다음 IAM 역할을 부여해 달라고 요청하세요.

  • 프로젝트에 대한 역할을 관리하려는 경우: 역할을 관리할 프로젝트에 대한 역할 관리자(roles/iam.roleAdmin)
  • 조직에 대한 역할을 관리하려는 경우: 역할을 관리할 조직에 대한 조직 역할 관리자(roles/iam.organizationRoleAdmin)

역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

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

프로젝트, 폴더, 조직에 사용 가능한 권한 보기

전체 조직이나 해당 조직의 특정 프로젝트에 대한 커스텀 역할을 만들 수 있습니다. 커스텀 역할에 사용할 수 있는 권한은 역할을 만드는 위치에 따라 다릅니다. 예를 들어 권한이 조직 수준에서만 사용될 수 있으면 프로젝트 수준 커스텀 역할에 이 권한을 포함할 수 없습니다.

조직 수준 및 프로젝트 수준 커스텀 역할에 사용할 수 있는 권한을 확인하려면 gcloud CLI나 Identity and Access Management API를 사용하여 특정 조직 또는 프로젝트에서 사용할 수 있는 권한을 나열할 수 있습니다. 예를 들어 프로젝트에서 생성된 커스텀 역할에 사용할 수 있는 모든 권한을 가져올 수 있습니다.

일부 권한이 커스텀 역할에서 지원되더라도 사용자에게 표시되지 않거나 커스텀 역할에서 사용되지 않을 수 있습니다. 예를 들어 서비스에 API를 사용 설정하지 않으면 커스텀 역할에서 사용할 수 있는 권한을 사용하지 못할 수 있습니다.

커스텀 역할에 추가할 수 있는 권한에 대한 자세한 내용은 지원되는 권한을 참조하세요.

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.

  2. 특정 프로젝트나 조직에서 커스텀 역할에 사용할 수 있는 권한의 목록을 가져오려면 gcloud iam list-testable-permissions 명령어를 사용합니다. 응답에는 프로젝트나 조직의 커스텀 역할에 사용할 수 있는 권한이 나열됩니다.

    프로젝트나 조직의 커스텀 역할에서 사용할 수 있는 권한을 나열하려면 다음 명령어를 실행합니다.

    gcloud iam list-testable-permissions FULL_RESOURCE_NAME \
        --filter="customRolesSupportLevel!=NOT_SUPPORTED"

    FULL_RESOURCE_NAME을 다음 값 중 하나로 바꿉니다.

    • 프로젝트: //cloudresourcemanager.googleapis.com/projects/PROJECT_ID(예: //cloudresourcemanager.googleapis.com/projects/my-project)

    • 조직: //cloudresourcemanager.googleapis.com/organizations/NUMERIC_ID(예: //cloudresourcemanager.googleapis.com/organizations/123456789012)

    결과에는 각 권한이 커스텀 역할에서 지원되는지 여부가 표시됩니다. customRolesSupportLevel 필드가 없는 권한은 완전히 지원됩니다.

    list-testable-permissions 명령어는 결과 수백 개를 반환할 수 있습니다. 이 부분 예시에서는 각 결과의 형식을 보여줍니다.

    ---
    name: appengine.applications.create
    stage: GA
    ---
    customRolesSupportLevel: TESTING
    name: appengine.applications.disable
    stage: GA
    ---
    name: appengine.applications.get
    stage: GA
    ---
    name: appengine.applications.update
    stage: GA
    ---
    name: appengine.instances.delete
    stage: GA
    ---
    name: appengine.instances.get
    stage: GA
    ---
    
  3. C++

    IAM용 클라이언트 라이브러리를 설치하고 사용하는 방법은 IAM 클라이언트 라이브러리를 참조하세요. 자세한 내용은 IAM C++ API 참고 문서를 참조하세요.

    IAM에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 시작하기 전에를 참조하세요.

    namespace iam = ::google::cloud::iam_admin_v1;
    [](std::string const& resource) {
      iam::IAMClient client(iam::MakeIAMConnection());
      google::iam::admin::v1::QueryTestablePermissionsRequest request;
      request.set_full_resource_name(resource);
      int count = 0;
      for (auto& permission : client.QueryTestablePermissions(request)) {
        if (!permission) throw std::move(permission).status();
        std::cout << "Permission successfully retrieved: " << permission->name()
                  << "\n";
        ++count;
      }
      if (count == 0) {
        std::cout << "No testable permissions found in resource: " << resource
                  << "\n";
      }
    }

    C#

    IAM용 클라이언트 라이브러리를 설치하고 사용하는 방법은 IAM 클라이언트 라이브러리를 참조하세요. 자세한 내용은 IAM C# API 참고 문서를 참조하세요.

    IAM에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 시작하기 전에를 참조하세요.

    
    using System;
    using System.Collections.Generic;
    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Iam.v1;
    using Google.Apis.Iam.v1.Data;
    
    public partial class CustomRoles
    {
        public static IList<Permission> QueryTestablePermissions(
            string fullResourceName)
        {
            var credential = GoogleCredential.GetApplicationDefault()
                .CreateScoped(IamService.Scope.CloudPlatform);
            var service = new IamService(new IamService.Initializer
            {
                HttpClientInitializer = credential
            });
    
            var request = new QueryTestablePermissionsRequest
            {
                FullResourceName = fullResourceName
            };
            var response = service.Permissions.QueryTestablePermissions(request)
                .Execute();
            foreach (var p in response.Permissions)
            {
                Console.WriteLine(p.Name);
            }
            return response.Permissions;
        }
    }
    

    Go

    IAM용 클라이언트 라이브러리를 설치하고 사용하는 방법은 IAM 클라이언트 라이브러리를 참조하세요. 자세한 내용은 IAM Go API 참고 문서를 참조하세요.

    IAM에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 시작하기 전에를 참조하세요.

    import (
    	"context"
    	"fmt"
    	"io"
    
    	iam "google.golang.org/api/iam/v1"
    )
    
    // queryTestablePermissions lists testable permissions on a resource.
    func queryTestablePermissions(w io.Writer, fullResourceName string) ([]*iam.Permission, error)