Let's connect
Let's connect

Cloud security policies in GCP: How to set them up using Terraform

Picture of Mateusz Borowski, Cloud Security Engineer

Mateusz Borowski

Cloud Security Engineer

10 minutes read

policy-concepts

TODO policy-concepts Source: https://cloud.google.com/resource-manager/img/org-policy-concepts.svg

bash

module "disableGlobalSerialPortAccess" {
  source        	= "terraform-google-modules/org-policy/google"
  version       	= "~> 5.2.2"
  policy_for    	= "project"
  project_id    	= "XXXXXXXXX"
  constraint    	= "constraints/compute.disableGlobalSerialPortAccess"
  policy_type   	= "boolean"
  organisation_id   = "XXXXXXXXX"
  enforce       	= true
}

bash

module "restrictTLSVersion" {
  source        	= "terraform-google-modules/org-policy/google"
  version       	= "~> 5.2.2"
  policy_for    	= "project"
  project_id    	= "XXXXXXXXX"
  constraint    	= "constraints/gcp.restrictTLSVersion"
  policy_type   	= "list"
  organisation_id   = "XXXXXXXXX"
  deny         	= ["TLS_VERSION_1", "TLS_VERSION_1_1"]
  deny_list_length = 2
}

bash

module "publicAccessPrevention" {
  source        	= "terraform-google-modules/org-policy/google"
  version       	= "~> 5.2.2"
  policy_for    	= "project"
  project_id    	= "XXXXXXXXX"
  constraint    	= "constraints/storage.publicAccessPrevention"
  policy_type   	= "boolean"
  organisation_id   = "XXXXXXXXX"
  enforce       	= true
}

bash

module "shieldedvm" {
  source        	= "terraform-google-modules/org-policy/google"
  version       	= "~> 5.2.2"
  policy_for    	= "project"
  project_id    	= "XXXXXXXXX"
  constraint     	= "constraints/compute.requireShieldedVm"
  policy_type   	= "boolean"
  organisation_id   = "XXXXXXXXX"
  enforce       	= true
}

bash

module "serviceaccountskeyrotation"{
  source        	= "terraform-google-modules/org-policy/google"
  version       	= "~> 5.2.2"
  policy_for    	= "project"
  project_id    	= "XXXXXXXXX"
  constraint    	= "constraints/iam.serviceAccountKeyExpiryHours"
  policy_type   	= "list"
  organisation_id   = "XXXXXXXXX"
  allow        	= ["2160h"] // 90 days
  allow_list_length = 1
}

bash

# Enable the organisation Policy API
resource "google_project_service" "orgpolicy_api" {
  service = "orgpolicy.googleapis.com"
  project = "XXXXXXXXX"
}

Curated by

Sebastian Synowiec

Liked the article?

Share it with others!

explore more on

Take the first step to a sustained competitive edge for your business

Get your free consultation

VirtusLab's work has met the mark several times over, and their latest project is no exception. The team is efficient, hard-working, and trustworthy. Customers can expect a proactive team that drives results.

Stephen Rooke
Stephen RookeDirector of Software Development @ Extreme Reach

VirtusLab's engineers are truly Strapi extensions experts. Their knowledge and expertise in the area of Strapi plugins gave us the opportunity to lift our multi-brand CMS implementation to a different level.

facile logo
Leonardo PoddaEngineering Manager @ Facile.it

VirtusLab has been an incredible partner since the early development of Scala 3, essential to a mature and stable Scala 3 ecosystem.

Martin_Odersky
Martin OderskyHead of Programming Research Group @ EPFL

The VirtusLab team's in-depth knowledge, understanding, and experience of technology have been invaluable to us in developing our product. The team is professional and delivers on time – we greatly appreciated this efficiency when working with them.

Michael_Grant
Michael GrantDirector of Development @ Cyber Sec Company