---
title: SQL database instances should only use private IP addresses
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > OOTB Rules > SQL database instances should only use
  private IP addresses
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# SQL database instances should only use private IP addresses
 
## Description{% #description %}

This rule evaluates second-generation Cloud SQL primary instances (instance type `CLOUD_SQL_INSTANCE`). An instance passes only when it has a collected `PRIVATE` IP address and no public IP address. An instance with Private Service Connect enabled (`psc_enabled`) also passes without a `PRIVATE` address, because an instance that uses only [Private Service Connect](https://docs.cloud.google.com/sql/docs/mysql/configure-private-service-connect) connects through PSC endpoints and does not list a `PRIVATE` address. The instance has a public IP address when `ipv4_enabled` is `true`, even if no IP address is collected, or when it has an IP address of type `PRIMARY`, or `MIGRATED_1ST_GEN` for an address kept after migration from a first-generation instance. An IP address with a missing or unspecified type also fails, because that address could be public. Private IP addresses lower the attack surface of the database and reduce latency for applications in the same VPC network.

Read replicas and read pools are skipped to match the CIS audit, which treats replica settings as inherited from the primary instance. A read replica can be created with its own public IP address, and this rule does not report that case. Green instances (`GREEN_INSTANCE`) are skipped like read replicas: a green instance is the staging clone in a [blue-green deployment](https://docs.cloud.google.com/sql/docs/mysql/about-blue-green-deployments), functions as a read replica of the primary, and becomes the production instance only at switchover. First-generation instances, instances with backend type `EXTERNAL`, and on-premises instances (instance type `ON_PREMISES_INSTANCE`) are also skipped. Each skip applies regardless of the other type field, so a read replica with no backend type, or an `EXTERNAL` backend with no instance type, is skipped. Any other instance with a missing or unspecified backend type or instance type fails because its scope cannot be determined.

## Remediation{% #remediation %}

1. Remove the public IP address from the flagged instance and assign a private IP address by following [Configure private IP](https://docs.cloud.google.com/sql/docs/mysql/configure-private-ip).
1. To prevent new instances from getting a public IP address, enforce the `constraints/sql.restrictPublicIp` constraint described in [Cloud SQL organization policies](https://docs.cloud.google.com/sql/docs/mysql/org-policy/org-policy).

## References{% #references %}

- [Private IP overview](https://docs.cloud.google.com/sql/docs/mysql/private-ip)
- [CIS Google Cloud Platform Foundation Benchmark](https://www.cisecurity.org/benchmark/google_cloud_computing_platform)
