リソースへのアクセスを拒否する

このページでは、プリンシパルが特定の Identity and Access Management(IAM)権限を使用できないようにする方法で、プリンシパルのアクセスを拒否する方法について説明します。

IAM では、拒否ポリシーを使用してアクセスを拒否します。拒否ポリシーは Google Cloud の組織、フォルダ、プロジェクトに関連付けられます。拒否ポリシーには拒否ルールが含まれています。このルールには、プリンシパルと、そのプリンシパルが使用できない権限のリストが記述されています。

拒否ポリシーは、IAM ポリシーとも呼ばれる許可ポリシーとは別のものです。許可ポリシーは、プリンシパルに IAM ロールを付与することで、リソースへのアクセスを許可します。

拒否ポリシーは、 Google Cloud コンソール、Google Cloud CLI または IAM v2 REST API を使用して管理できます。

始める前に

  • 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.

    Terraform

    ローカル開発環境でこのページの Terraform サンプルを使用するには、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

    ローカル開発環境でこのページの 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 の設定をご覧ください。

    Node.js

    ローカル開発環境でこのページの Node.js サンプルを使用するには、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 を使用して認証するをご覧ください。

  • 拒否ポリシーの概要を確認します。

必要なロール

拒否ポリシーの管理に必要な権限を取得するには、組織に対する次の IAM ロールを付与するよう管理者に依頼してください。

  • 拒否ポリシーを表示する: 拒否審査担当者roles/iam.denyReviewer
  • 拒否ポリシーを表示、作成、更新、削除する: 拒否管理者roles/iam.denyAdmin

ロールの付与については、プロジェクト、フォルダ、組織へのアクセスを管理するをご覧ください。

これらの事前定義ロールには、拒否ポリシーの管理に必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。

必要な権限

拒否ポリシーを管理するには、次の権限が必要です。

  • 拒否ポリシーを表示する:
    • iam.denypolicies.get
    • iam.denypolicies.list
  • 拒否ポリシーを作成、更新、削除する:
    • iam.denypolicies.create
    • iam.denypolicies.delete
    • iam.denypolicies.get
    • iam.denypolicies.update

カスタムロールや他の事前定義ロールを使用して、これらの権限を取得することもできます。

拒否する権限を特定する

拒否ポリシーを作成する前に、拒否する権限と、これらの権限を拒否するプリンシパルを決定する必要があります。

拒否できるのは一部の権限です。拒否できる権限のリストについては、拒否ポリシーでサポートされる権限をご覧ください。

権限グループを使用して権限のセットを拒否できる場合もあります。詳しくは、権限グループをご覧ください。

拒否ポリシーは、v2 REST API で管理します。この REST API では、権限名に特別な形式が必要です。たとえば、IAM カスタムロールを作成する権限名は次のように指定します。

  • v1 API: iam.roles.create
  • v2 API: iam.googleapis.com/roles.create

拒否ポリシーを作成する

組織、フォルダ、プロジェクトに拒否ポリシーを追加できます。各リソースには、最大 500 個の拒否ポリシーを設定できます。

拒否ポリシーには、次の項目を指定する拒否ルールが含まれています。

  • 拒否する権限。
  • これらの権限を拒否するプリンシパル。
  • 省略可: 権限拒否が免除されるプリンシパル。

    たとえば、グループに対する権限を拒否し、そのグループに属する特定のユーザーを除外できます。

  • 省略可: プリンシパルが権限を使用できないタイミングを指定する条件式。拒否ポリシーの条件式ではリソースタグの関数のみを使用できます。他の関数と演算子はサポートされていません。

各リソースには、接続されている拒否ポリシー全体で最大 500 個の拒否ルールを設定できます。

拒否ポリシーはリソース階層から継承されます。たとえば、組織レベルで権限を拒否すると、その権限は組織内のフォルダとプロジェクト、および各プロジェクト内のサービス固有のリソースに対しても拒否されます。

拒否ポリシーは許可ポリシーをオーバーライドします。特定の権限を含むロールがプリンシパルに付与されていても、拒否ポリシーでプリンシパルがその権限を使用できないと示されている場合、プリンシパルは権限を使用できません。

コンソール

  1. Google Cloud コンソールで、[IAM] ページの [拒否] タブに移動します。

    [IAM] に移動

  2. プロジェクト、フォルダ、または組織を選択します。

  3. [