Manage SSL/TLS certificates

This page describes how to manage your client and server certificate authority (CA) certificates.

Manage client certificates

Use the following procedures to manage client certificates in Cloud SQL.

Retrieve a client certificate

You can retrieve the public key portion of a client certificate. You cannot retrieve the private key, however. If you have lost your private key, you must create a new certificate.

Console

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open the Overview page of an instance, click the instance name.
  3. Select Connections from the SQL navigation menu.
  4. Select the Security tab.
  5. In Manage client certificates, click a certificate name.
  6. The SSL Client Certificate page opens and shows the client certificate (client-cert.pem) with a link to download the certificate.

gcloud

Retrieve the client certificate public key with the ssl client-certs describe command:

gcloud sql ssl client-certs describe CERT_NAME \
--instance=INSTANCE_NAME \
--format="value(cert)" > client-cert.pem

REST v1

  1. List the certificates on the instance to get the fingerprint of the certificate you want to retrieve:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/sslCerts

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

    Record the sha1Fingerprint field for the certificate you want to retrieve. Don't include the quotation marks.

  2. Retrieve the certificate:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID
    • sha1FingerPrint: The cert's sha1FingerPrint

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/sslCerts/sha1FingerPrint

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  3. Copy all of the certificate data contained by the quotation marks to a file, for example client-cert.pem. Don't copy the quotation marks themselves.

REST v1beta4

  1. List the certificates on the instance to get the fingerprint of the certificate you want to retrieve:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/sslCerts

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

    Record the sha1Fingerprint field for the certificate you want to retrieve. Don't include the quotation marks.

  2. Retrieve the certificate:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID
    • sha1FingerPrint: The cert's sha1FingerPrint

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/sslCerts/sha1FingerPrint

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  3. Copy all of the certificate data contained by the quotation marks to a file, for example client-cert.pem. Don't copy the quotation marks themselves.

Delete a client certificate

When you delete a client certificate, the database server is updated and doesn't need to be restarted.

Console

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open the Overview page of an instance, click the instance name.
  3. Select Connections from the SQL navigation menu.
  4. Select the Security tab.
  5. In Manage client certificates, find the certificate you want to delete and click Delete..
  6. In the Delete client certificate pane, click Ok.

gcloud

Delete the client certificate using the ssl client-certs delete command:

gcloud sql ssl client-certs delete CERT_NAME \
--instance=INSTANCE_NAME

REST v1

  1. List the certificates on the instance to get the fingerprint of the certificate you want to delete:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/sslCerts

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

    Record the sha1Fingerprint field for the certificate you want to delete. Don't include the quotation marks.

  2. Delete the certificate:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID
    • sha1FingerPrint: The cert's sha1FingerPrint

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/sslCerts/sha1FingerPrint

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

REST v1beta4

  1. List the certificates on the instance to get the fingerprint of the certificate you want to delete:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/sslCerts

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

    Record the sha1Fingerprint field for the certificate you want to delete. Don't include the quotation marks.

  2. Delete the certificate:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID
    • sha1FingerPrint: The cert's sha1FingerPrint

    HTTP method and URL:

    DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/sslCerts/sha1FingerPrint

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

Manage server CA certificates (per-instance CA)

This section describes how to manage server CA certificates that are created internally by Cloud SQL. This is the default server CA mode in Cloud SQL. In this certificate authority hierarchy, Cloud SQL creates a server CA for each instance.

Rotate server CA certificates

If you've received a notice about your certificates expiring, or you want to initiate a rotation, then take the following steps to complete the rotation. Before you start the rotation, you must have a new server CA on the instance. If a new server CA has already been created, then you can skip the first step in the following procedure.

  1. Create a new server CA.
  2. Download the new server CA certificate information.
  3. Update your clients to use the new server CA certificate information.
  4. Complete the rotation, which moves the active certificate into the "previous" slot and updates the newly added certificate to be the active certificate.

Console

Download the new server CA certificate, encoded as a PEM file, to your local environment:

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open the Overview page of an instance, click the instance name.
  3. Select Connections from the SQL navigation menu.
  4. Select the Security tab.
  5. Click to expand Manage certificates.
  6. Select Rotate CA certificate.

    If there are no eligible certificates, then the rotate option is unavailable. You must create a new server CA certificate.

  7. Click Download Certificates.

Update all of your MySQL clients to use the new information by copying the downloaded file to your client host machines, replacing the existing server-ca.pem file.

After you have updated your clients, complete the rotation:

  1. Return to the Security tab.
  2. Click to expand Manage certificates.
  3. Select Rotate CA certificate.
  4. Confirm that your clients are connecting properly.
  5. If any clients are not connecting using the newly rotated certificate, then you can select Rollback CA certificate to rollback to the previous configuration.

gcloud

  1. Create a server CA certificate:
    gcloud sql ssl server-ca-certs create \
    --instance=INSTANCE
  2. Download the certificate information to a local PEM file:
    gcloud sql ssl server-ca-certs list \
    --format="value(cert)" \
    --instance=INSTANCE_NAME > \
    FILE_PATH/FILE_NAME.pem
  3. Update all of your clients to use the new information by copying the downloaded file to your client host machines, replacing the existing server-ca.pem files.
  4. After you have updated your clients, complete the rotation:
    gcloud sql ssl server-ca-certs rotate \
    --instance=INSTANCE_NAME
          
  5. Confirm that your clients are connecting properly.
  6. If any clients are not connecting using the newly rotated certificate, then you can rollback to the previous configuration.

REST v1

  1. Download your server CA certificates:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/listServerCas

    To send your request, expand one of these options:

    You should receive a JSON response similar to the following:

  2. Complete the rotation:

    Before using any of the request data, make the following replacements:

    • project-id: The project ID
    • instance-id: The instance ID

    HTTP method and URL:

    POST https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/rotateServerCa

    To send your request, expand one of these options: