gcp-cloudsql-import-write-data

cloudsql.instances.import can import a SQL dump or CSV from a GCS bucket into a Cloud SQL instance, allowing data modification, schema changes, and stored procedure injection.

derived gcp emits CanWriteData

match (effective permission)

{ "action": "cloudsql.instances.import", "resource_type": "google.sql.Instance" }

where

the principal holds cloudsql.instances.import permission a source SQL dump or CSV file exists in a GCS bucket the principal can write to or control

emit

source typeIdentity
target typeData
source<principal>
target<Cloud SQL Instance node>
permissionscloudsql.instances.import
conditionsiam_permission resource_policy
state logicACTIVE when cloudsql.instances.import is confirmed effective AND the instance is RUNNABLE AND a source file (SQL dump or CSV) is available in a GCS bucket that the principal can write to (or already controls). If no source file is pre-positioned, downgrade to POTENTIAL (attacker CAN create a malicious dump and trigger import). CONDITIONAL(resource_policy) when the source bucket's accessibility cannot be confirmed from the analyzed principal's grants.

Narrative

{principal.name} holds cloudsql.instances.import on {instance.name} and can import a SQL dump or CSV from a GCS bucket into the database, potentially modifying data, injecting stored procedures, or altering the schema.

Raw rule rules/derived/gcp/cloudsql.yaml

id: gcp-cloudsql-import-write-data
emits: CanWriteData
description: cloudsql.instances.import can import a SQL dump or CSV from a GCS bucket into a Cloud SQL
  instance, allowing data modification, schema changes, and stored procedure injection.
match_effective_permission:
  action: cloudsql.instances.import
  resource_type: google.sql.Instance
where:
- the principal holds cloudsql.instances.import permission
- a source SQL dump or CSV file exists in a GCS bucket the principal can write to or control
emit:
  source_type: Identity
  target_type: Data
  source: <principal>
  target: <Cloud SQL Instance node>
  permissions:
  - cloudsql.instances.import
  conditions:
  - iam_permission
  - resource_policy
  state_logic: ACTIVE when cloudsql.instances.import is confirmed effective AND the instance is RUNNABLE
    AND a source file (SQL dump or CSV) is available in a GCS bucket that the principal can write to (or
    already controls). If no source file is pre-positioned, downgrade to POTENTIAL (attacker CAN create
    a malicious dump and trigger import). CONDITIONAL(resource_policy) when the source bucket's accessibility
    cannot be confirmed from the analyzed principal's grants.
  false_positive_note: 'The Cloud SQL service agent (service-PROJECT_NUMBER@gcp-sa-cloud-sql.iam.gserviceaccount.com)
    reads the source file from GCS. The calling principal needs cloudsql.instances.import to trigger the
    import; the service agent needs storage.objects.get on the source GCS file. If the service agent lacks
    that grant, import fails with 403.

    Import can modify data (INSERT/UPDATE/DELETE via SQL statements in the dump) or inject code (stored
    procedures, triggers, views with privileged operations). On MySQL/PostgreSQL, stored procedure triggers
    can execute external commands or access resources; on SQL Server, CLR-based procedures (if enabled)
    offer code execution. This is a CanWriteData edge (data modification), but may also unlock downstream
    escalation via triggered code execution (model in can-execute-as if triggered execution is relevant).

    Unlike export (which is an attacker read of the dump), import is an attacker WRITE (control of dump
    contents) that modifies the live DB. Common attack paths: - Data poisoning: modify application data
    -> application processes malicious data - Stored procedure injection: add procs that run on schedule
    or trigger -> lateral movement - Schema injection: add columns/tables to trigger application logic
    errors

    Require confirmation that a source file is accessible OR model as POTENTIAL (attacker can create malicious
    dump if they have write access to the source bucket).'
  narrative: '{principal.name} holds cloudsql.instances.import on {instance.name} and can import a SQL
    dump or CSV from a GCS bucket into the database, potentially modifying data, injecting stored procedures,
    or altering the schema.'
  derived_from:
  - cloudsql.instances.import effective permission on google.sql.Instance
  - source GCS file is accessible to the principal (write access to bucket)
move · open · esc close