Detection rules › YARA-L

Google Cloud Service Account Key Created or Uploaded

Severity
medium
Type
alert
Time window
30m
Match by
sa_key_id
Author
Google Cloud Security
Source
github.com/chronicle/detection-rules

Detects when a service account key is created in or uploaded to a monitored Google Cloud project.

MITRE ATT&CK coverage

References

Event coverage

ProviderEventTitle
GCP-iam.googleapis.comgoogle-iam-admin-CreateServiceAccountKeyCreate service account key
GCP-iam.googleapis.comgoogle-iam-admin-UploadServiceAccountKeyUpload service account key

Rules detecting the same action

Other rules on this platform that filter on the same API call or operation.

Rule body yaral

/*
 * Copyright 2024 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
rule google_cloud_service_account_key_created_or_uploaded {

  meta:
    author = "Google Cloud Security"
    description = "Detects when a service account key is created in or uploaded to a monitored Google Cloud project."
    rule_id = "mr_751d64b3-2aef-4c5b-bf39-abc6577f6ce8"
    rule_name = "Google Cloud Service Account Key Created or Uploaded"
    assumption = "Google SecOps is ingesting Google Cloud logs. Reference: https://cloud.google.com/chronicle/docs/ingestion/cloud/ingest-gcp-logs"
    type = "alert"
    severity = "Medium"
    priority = "Medium"
    platform = "Google Cloud"
    data_source = "GCP Cloud Audit"
    mitre_attack_tactic = "Persistence"
    mitre_attack_technique = "Account Manipulation: Additional Cloud Credentials"
    mitre_attack_url = "https://attack.mitre.org/techniques/T1098/001/"
    mitre_attack_version = "v15"
    reference = "https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys"

  events:
    $gc.metadata.log_type = "GCP_CLOUDAUDIT"
    $gc.metadata.product_name = "Google Cloud IAM"
    (
        $gc.metadata.product_event_type = "google.iam.admin.v1.CreateServiceAccountKey" or
        $gc.metadata.product_event_type = "google.iam.admin.v1.UploadServiceAccountKey"
    )
    $gc.security_result.action = "ALLOW"
    $gc.security_result.detection_fields["key_id"] = $sa_key_id

  match:
    $sa_key_id over 30m

  outcome:
    $risk_score = max(65)
    $mitre_attack_tactic = "Persistence"
    $mitre_attack_technique = "Account Manipulation: Additional Cloud Credentials"
    $mitre_attack_technique_id = "T1098.001"
    $event_count = count_distinct($gc.metadata.id)
    $principal_ip = array_distinct($gc.principal.ip)
    $principal_user_userid = array_distinct($gc.principal.user.userid)
    $principal_ip_country = array_distinct($gc.principal.ip_geo_artifact.location.country_or_region)
    $principal_ip_state = array_distinct($gc.principal.ip_geo_artifact.location.state)
    $principal_ip_city = array_distinct($gc.principal.location.city)
    $security_result_summary = array_distinct($gc.security_result.summary)
    $sa_key_expiry_date = array_distinct(timestamp.get_date(cast.as_int($gc.about.labels["res_valid_before_time"])))

  condition:
    $gc
}

Detection logic

Fires when at least one $gc event in the 30m window.

Events

$gc

  • metadata.log_type = "GCP_CLOUDAUDIT"
  • metadata.product_event_type = "google.iam.admin.v1.CreateServiceAccountKey" or "google.iam.admin.v1.UploadServiceAccountKey"
  • security_result.action = "ALLOW"

Correlation

Match key
$sa_key_id (security_result.detection_fields["key_id"])
Within
30m

Outcome

Fields the detection emits on a match. $risk_score drives alerting; Chronicle surfaces the rest on the detection.

FieldExpression
risk_scoremax(65)
event_countcount_distinct($gc.metadata.id)
principal_iparray_distinct($gc.principal.ip)
principal_user_useridarray_distinct($gc.principal.user.userid)
principal_ip_countryarray_distinct($gc.principal.ip_geo_artifact.location.country_or_region)
principal_ip_statearray_distinct($gc.principal.ip_geo_artifact.location.state)
principal_ip_cityarray_distinct($gc.principal.location.city)
security_result_summaryarray_distinct($gc.security_result.summary)
sa_key_expiry_datearray_distinct(timestamp.get_date(cast.as_int($gc.about.labels["res_valid_before_time"])))