Google Cloud Storageバケットのインベントリ

バケットの用途とアクセス権限を併せて記録してください。

説明

この項目には Terraform で宣言した Cloud Storage バケットが表示されます。保存されたオブジェクトはデフォルトで暗号化されます。

想定される影響

公開アクセスの防止が適用されていないバケットでは、allUsers に READER ACL を付与すると誰でもオブジェクト名を一覧表示できます。allUsers に roles/storage.admin を付与すると誰でもバケットとデータを変更できます。

対処方法

担当チーム、用途、保持ポリシーを記録します。ACL と IAM を調べ、継承されたものも含めて allUsers や allAuthenticatedUsers への権限付与を確認します。顧客管理の暗号鍵を使う場合は、鍵のロケーションをバケットに合わせ、Cloud Storage サービスエージェントに鍵の使用権限を付与します。

例

最初の例は 2 つのバケットに公開権限を設定します。次の例は均一なバケットレベルのアクセスを使う別のバケットを定義し、運用グループに roles/storage.objectViewer を付与します。参照先の KMS 鍵を指定します。

変更前

hcl
resource "google_storage_bucket_access_control" "public_rule" {
  bucket = google_storage_bucket.bucket.name
  role   = "READER"
  entity = "allUsers"
}

resource "google_storage_bucket" "bucket" {
  name     = "static-content-bucket"
  location = "US"
}

resource "google_storage_bucket_iam_binding" "binding" {
  bucket = google_storage_bucket.bucket2.name
  role   = "roles/storage.admin"
  members = [
    "allUsers",
  ]
}

resource "google_storage_bucket" "bucket2" {
  name     = "static-content-bucket-2"
  location = "US"

  encryption {
    default_kms_key_name = var.bucket_kms_key
  }
}

変更後

hcl
resource "google_storage_bucket" "logs_bucket" {
  name     = "team-app-logs-prod"
  location = "US"

  uniform_bucket_level_access = true

  encryption {
    default_kms_key_name = google_kms_crypto_key.bucket_key.id
  }

  labels = {
    service = "app"
    env     = "prod"
  }
}

resource "google_storage_bucket_iam_member" "ops_reader" {
  bucket = google_storage_bucket.logs_bucket.name
  role   = "roles/storage.objectViewer"
  member = "group:ops@example.com"
}

参考資料