GCP KMS Bulk Encryption by GCS Service Account
Description
Detects bulk KMS encryption operations performed by the GCS service account. This pattern is indicative of a ransomware attack where an adversary directly calls the KMS Encrypt API using the GCS service account identity to encrypt data at scale, effectively holding data hostage. The threshold of 10+ encryption operations suggests automated bulk encryption rather than normal application behavior.
Query · python
def rule(event):
method_name = event.deep_get("protoPayload", "methodName")
service_name = event.deep_get("protoPayload", "serviceName")
principal = event.deep_get(
"protoPayload", "authenticationInfo", "principalEmail", default="<UNKNOWN_PRINCIPAL>"
)
severity = event.get("severity")
return all(
[
method_name == "Encrypt",
service_name == "cloudkms.googleapis.com",
"gs-project-accounts.iam.gserviceaccount.com" in principal,
severity != "ERROR", # Operation succeeded
]
)
def title(event):
key = event.deep_get("resource", "labels", "crypto_key_id", default="Unknown")
return f"GCS service account performing bulk KMS encryption with key [{key}]"
def alert_context(event):
return {
"principal": event.deep_get("protoPayload", "authenticationInfo", "principalEmail"),
"kms_key": event.deep_get("protoPayload", "resourceName"),
"key_ring": event.deep_get("resource", "labels", "key_ring_id"),
"crypto_key": event.deep_get("resource", "labels", "crypto_key_id"),
"project": event.deep_get("resource", "labels", "project_id"),
"status": event.deep_get("protoPayload", "status"),
"location": event.deep_get("resource", "labels", "location"),
}
Analyst notes
- Query GCP Audit logs for all KMS Encrypt API calls by the GCS service account in the 1 hour window around this alert
- Identify the total number of encryption operations and the rate of operations per minute
- Check if KMS IAM policies were recently modified to grant the GCS service account encryption permissions
- Investigate the source of these encryption calls and what data is being encrypted
- Search for related GCS operations (object rewrite, copy, bucket updates) in the same time window
- Look for other ransomware indicators (disabled KMS keys, bucket configuration changes) from this project in the past 24 hours