LoginSignup
2
0

GCP OrganizationレベルでGoogle Cloud Storageの公開を禁止する

Last updated at Posted at 2023-12-15

Google Cloud Storage(GCS)やAmazon S3などのクラウドストレージは便利ですが、簡単にデータをパプリック公開できるためにうっかり公開してしまうことによる事故のリスクもあります。

そのため、以下のようにGCSにはバケット単位でパブリックアクセスを禁止する設定もあります。
しかし、この設定はバケット単位でしか効果がないので、この設定をせずにバケットを作成してしまった場合には、リスクは依然として存在し続けます。

resource "google_storage_bucket" "bucket" {
  name     = "バケット名"
  location = "リージョン"

  uniform_bucket_level_access = true
  public_access_prevention    = "enforced" # パブリックアクセス禁止
}

そのため、プロジェクトレベル・フォルダレベルOrganizationレベルでパブリックアクセスを禁止したいです。
Organization Policyを活用して禁止設定を入れてみます。

data "google_organization" "org" {
  domain = "ドメイン"
}

resource "google_organization_policy" "storage_public_access_prevention" {
  org_id     = data.google_organization.org.org_id
  constraint = "storage.publicAccessPrevention"

  boolean_policy {
    enforced = true
  }
}

これによってOrganization内のすべてのプロジェクトに対して、GCSのパブリックアクセスが禁止に設定されます。

参考:

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