CLOUD-DATABASE-ENGINEER practice question 22 of 25

You are writing an application that will run on Cloud Run and require a database running in the Cloud SQL managed service. You want to secure this instance so that it only receives connections from applications running in your VPC environment in Google Cloud. What should you do?

Full set: 141 questions
Answer options
A: 1. Create your instance with a specified external (public) IP address. 2. Choose the VPC and create firewall rules to allow only connections from Cloud Run into your instance. 3. Use Cloud SQL Auth proxy to connect to the instance.
B: 1. Create your instance with a specified external (public) IP address. 2. Choose the VPC and create firewall rules to allow only connections from Cloud Run into your instance. 3. Connect to the instance using a connection pool to best manage connections to the instance.
C: 1. Create your instance with a specified internal (private) IP address. 2. Choose the VPC with private service connection configured. 3. Configure the Serverless VPC Access connector in the same VPC network as your Cloud SQL instance. 4. Use Cloud SQL Auth proxy to connect to the instance.
D: 1. Create your instance with a specified internal (private) IP address. 2. Choose the VPC with private service connection configured. 3. Configure the Serverless VPC Access connector in the same VPC network as your Cloud SQL instance. 4. Connect to the instance using a connection pool to best manage connections to the instance. Correct answer
Correct Answer:
D. 1. Create your instance with a specified internal (private) IP address. 2. Choose the VPC with private service connection configured. 3. Configure the Serverless VPC Access connector in the same VPC network as your Cloud SQL instance. 4. Connect to the instance using a connection pool to best manage connections to the instance.
Explanation

To securely connect a Cloud Run application to a Cloud SQL instance exclusively within a VPC, you must prevent any public internet exposure. This is achieved by assigning a private (internal) IP address to the Cloud SQL instance. This requires configuring a private services access connection between your VPC and the Google-managed services. Because Cloud Run services operate in a serverless environment outside your specific VPC, a Serverless VPC Access connector is necessary to bridge the gap and route traffic from Cloud Run into your VPC. Finally, serverless applications like Cloud Run can scale rapidly, potentially creating many new connections and exhausting the database's connection limit. Using a connection pool is a critical best practice to manage and reuse connections efficiently, ensuring application stability and performance.

Why Incorrect

A: Using a public IP address exposes the database to the public internet, which contradicts the requirement to only allow connections from the VPC environment. B: This option also uses a public IP address, which is less secure than a private IP and does not meet the core security requirement of the question. C: While the networking setup is correct, using the Cloud SQL Auth proxy is not the most critical final step. Connection pooling is more important for managing connections from a scalable service like Cloud Run.

References

1. Google Cloud Documentation - Connecting from Cloud Run (private IP): "To connect to a Cloud SQL instance from a Cloud Run service... using a private IP address, you need to use a Serverless VPC Access connector." This document also explicitly recommends connection pooling: "To prevent exceeding the connection limit, we recommend that you use a connection pooler." (Source: Google Cloud, Cloud SQL for MySQL Documentation, "Connecting from Cloud Run", Section: "Connecting using private IP").

2. Google Cloud Documentation - Configuring private IP: "Configuring a Cloud SQL instance to use private IP requires private services access. Private services access enables you to create private connections between your VPC network and the Google Cloud VPC network where your Cloud SQL instance resides." (Source: Google Cloud, Cloud SQL for MySQL Documentation, "Configuring private IP", Section: "About private services access").

3. Google Cloud Documentation - Serverless VPC Access: "Serverless VPC Access enables you to connect directly to your VPC network from serverless environments such as Cloud Run, App Engine, or Cloud Functions. Configuring Serverless VPC Access allows your serverless environment to send requests to your VPC network by using internal DNS and internal IP addresses..." (Source: Google Cloud, VPC Documentation, "Serverless VPC Access overview").

4. Google Cloud Documentation - Managing database connections: "We recommend using a connection pooler to manage your connections... Applications in serverless environments (such as Cloud Functions, Cloud Run, and App Engine) can create a large number of connections to your database." (Source: Google Cloud, Cloud SQL for MySQL Documentation, "Managing database connections", Section: "Connection pooling").

Scroll to Top