Skip to main content
Deterministically creating service identities for APIs in Google Cloud
  1. Posts/

Deterministically creating service identities for APIs in Google Cloud

·175 words·1 min
Christoph Petersen
Author
Christoph Petersen

Platform services in Google Cloud act in the context of a service account. While these default service identities are mostly generated automatically, it is not always deterministic when they are created. Some are created when the API is enabled, others will only be created on first use of the API. This makes it hard for managing IAM permissions for these identities - especially when employing infrastructure as code like Terraform.

Service Usage API to the rescue
#

Luckily the Service Usage API now features a new method (generateServiceIdentity) in v1beta1 that ensures the service identity is being created and will return its identifier (namely the email address of the service account).

The endpoint is already available in gcloud beta and the following snippit will create the service identity for Cloud Build:

project="<PROJECT ID>"
service="cloudbuild.googleapis.com"

gcloud beta services identity create \
    --project $project \
    --service $service

The google-beta provider for Terraform also makes a resource available for direct use in Terraform:

resource "google_project_service_identity" "cloudbuild" {
  provider = google-beta
  project = "<PROJECT ID>"
  service = "cloudbuild.googleapis.com"
}

Related

Protect disk snapshots against accidental deletion or malicious tampering

·1421 words·7 mins
It could happen. Total mahem. An administrative pricipal for a project was accidentally leaked. An attacker has taken you projects hostage. You need to recover and fast. Restoring project access is the least of your worries your concern is to restore services. Luckily you have all workloads protected with snapshots! All deleted by the attacker! This is an exaggerated and hypothetical scenario but I have seen similar things happening. In this article I’m exploring an approach to protect against such a scenario.

IAP command chaining

·584 words·3 mins
Identity-Aware Proxy (IAP) is a powerful tool in the tool chain of Google Cloud administrators and users. It can be used to control access to cloud-based and on-premises applications and VMs running on Google Cloud.

Fix unspecified errors working with Azure root Management Group

·293 words·2 mins
If you have not been working with Management Groups to manage Azure at scale, I recommend to review the documentation. You should also take a look at the Microsoft Cloud Adoption Framework (which was just recently updated).