LoginSignup
2
0

Owner権限でも消すことができないGCPプロジェクトを作成する方法

Last updated at Posted at 2023-12-09

組織内のGoogle Cloudプロジェクトのライフサイクルを適切に管理しないと、以下の記事のように「野良」プロジェクトが大量に発生してしまいます。

上記の記事では作成権限を制限しましたが、一方で削除権限も制限したい場合はどうするのがよいでしょうか。プロジェクト管理者にOwner権限を渡している場合は、その人の権限で自由にプロジェクトを削除できてしまうのですが、その権限を剥奪したいです。

解決策: DENYポリシーの活用

DENYポリシーを作成すると、このようなOwner権限でもプロジェクト削除ができないような設定を入れられます。

DENYポリシーはプロジェクト・フォルダ・組織のいずれかにアタッチできますが、プロジェクトにアタッチしてしまうとOwner権限でDENYポリシーを外せてしまうので、フォルダか組織にアタッチする必要があります。ここでは組織にアタッチする場合を例示します。

data "google_organization" "my-org" {
  domain = "Organizationのドメイン"
}

resource "google_iam_deny_policy" "limited-users-can-delete-project" {
  provider = google-beta

  # フォルダにアタッチする場合は以下を参照に書き換え
  # https://cloud.google.com/iam/docs/deny-access#attachment-point
  parent = urlencode("cloudresourcemanager.googleapis.com/organizations/${data.google_organization.my-org.org_id}")
  name   = "limited-users-can-delete-project"

  rules {
    deny_rule {
      denied_principals    = ["principalSet://goog/public:all"]
      exception_principals = ["削除が許可された人"]
      denied_permissions   = ["cloudresourcemanager.googleapis.com/projects.delete"]
    }
  }
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0