本页面介绍了如何管理客户端和服务器 CA 证书。
管理客户端证书
按照以下过程在 Cloud SQL 中管理客户端证书。
检索客户端证书
您可以检索客户端证书的公钥部分,但不能检索私钥。如果私钥丢失,则必须创建一个新证书。
控制台
在 Google Cloud 控制台中,转到 Cloud SQL 实例 页面。
转到“Cloud SQL 实例”
如需打开实例的概览 页面,请点击实例名称。
从 SQL 导航菜单中选择连接 。
选择安全 标签页。
在管理客户端证书 中,点击证书名称。
系统会打开 SSL 客户端证书 页面,并显示客户端证书 (client-cert.pem
),其中包含下载证书的链接。
gcloud
使用 ssl client-certs describe
命令检索客户端证书公钥:
gcloud sql ssl client-certs describe CERT_NAME \
--instance= INSTANCE_NAME \
--format= "value(cert)" > client-cert.pem
REST v1
列出实例的证书,以获取待检索证书的指纹:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#sslCertsList",
"items": [
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint "
"instance": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint ",
"createTime": "2020-02-13T00:10:20.595Z",
"expirationTime": "2030-02-10T00:11:20.595Z"
}
]
}
记录待检索证书的 sha1Fingerprint
字段。请不要包含英文引号。
检索证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
sha1FingerPrint :证书的 sha1FingerPrint
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint "
"instance": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint ",
"createTime": "2020-02-13T00:10:20.595Z",
"expirationTime": "2030-02-10T00:11:20.595Z"
}
将引号内包含的所有证书数据复制到一个文件中(例如 client-cert.pem
)。请不要复制英文引号本身。
REST v1beta4
列出实例的证书,以获取待检索证书的指纹:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#sslCertsList",
"items": [
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint "
"instance": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint ",
"createTime": "2020-02-13T00:10:20.595Z",
"expirationTime": "2030-02-10T00:11:20.595Z"
}
]
}
记录待检索证书的 sha1Fingerprint
字段。请不要包含英文引号。
检索证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
sha1FingerPrint :证书的 sha1FingerPrint
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint "
"instance": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint ",
"createTime": "2020-02-13T00:10:20.595Z",
"expirationTime": "2030-02-10T00:11:20.595Z"
}
将引号内包含的所有证书数据复制到一个文件中(例如 client-cert.pem
)。请不要复制英文引号本身。
删除客户端证书
删除客户端证书后,数据库服务器将会更新,无需重启。
控制台
在 Google Cloud 控制台中,转到 Cloud SQL 实例 页面。
转到“Cloud SQL 实例”
如需打开实例的概览 页面,请点击实例名称。
从 SQL 导航菜单中选择连接 。
选择安全 标签页。
在管理客户端证书 中,找到您要删除的证书,然后点击 。
在删除客户端证书 窗格中,点击确定 。
gcloud
使用 ssl client-certs delete 命令删除客户端证书:
gcloud sql ssl client-certs delete CERT_NAME \
--instance= INSTANCE_NAME
REST v1
列出实例的证书,以获取要删除的证书的指纹:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#sslCertsList",
"items": [
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint "
"instance": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint ",
"createTime": "2020-02-13T00:10:20.595Z",
"expirationTime": "2030-02-10T00:11:20.595Z"
}
]
}
记录待删除证书的 sha1Fingerprint
字段。请不要包含英文引号。
删除证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
sha1FingerPrint :证书的 sha1FingerPrint
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method DELETE ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
REST v1beta4
列出实例的证书,以获取要删除的证书的指纹:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#sslCertsList",
"items": [
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint "
"instance": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint ",
"createTime": "2020-02-13T00:10:20.595Z",
"expirationTime": "2030-02-10T00:11:20.595Z"
}
]
}
记录待删除证书的 sha1Fingerprint
字段。请不要包含英文引号。
删除证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
sha1FingerPrint :证书的 sha1FingerPrint
HTTP 方法和网址:
DELETE https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X DELETE \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint "
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method DELETE ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /sslCerts/sha1FingerPrint " | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
管理服务器 CA 证书(每个实例 CA)
本部分介绍了如何管理 Cloud SQL 在内部创建的服务器 CA 证书。这是 Cloud SQL 中的默认服务器 CA 模式。在此证书授权机构层次结构中,Cloud SQL 会为每个实例创建一个服务器 CA。
轮替服务器 CA 证书
如果您收到了一封有关证书失效的通知,或者您想要发起轮替,请按照以下步骤操作,以完成轮替。在开始轮替之前,您必须在实例上拥有新的服务器 CA。如果已创建新的服务器 CA,则可以跳过以下过程的第一步。
创建新的服务器 CA。
下载新服务器 CA 证书的信息。
更新客户端以使用新服务器 CA 证书的信息。
完成轮替,以将有效证书转入“上一个”空档,并将新添加的证书更新为有效证书。
轮替 SSL 证书后,App Engine 和 Cloud SQL Auth 代理连接会在连接时自动接收新证书。
控制台
下载新服务器 CA 证书的信息:
在 Google Cloud 控制台中,转到 Cloud SQL 实例 页面。
转到“Cloud SQL 实例”
如需打开实例的概览 页面,请点击实例名称。
从 SQL 导航菜单中选择连接 。
选择安全 标签页。
点击展开管理证书 。
选择轮替 CA 证书 。
如果没有符合条件的证书,则轮替选项不可用。
点击下载证书 。
编码为 PEM 文件的服务器 CA 证书信息会下载到您的本地环境中:
通过将下载的文件复制到客户端主机上并替换现有的 server-ca.pem
文件,将所有 MySQL 客户端更新为使用新信息。
更新客户端后,请完成轮替:
返回安全 标签页。
点击展开管理证书 。
选择轮替 CA 证书 。
确认您的客户端连接正确。
如果有任何客户端未使用新轮替的证书进行连接,您可以选择回滚 CA 证书 以回滚 到先前的配置。
gcloud
创建服务器 CA 证书:
gcloud beta sql ssl server-ca-certs create \
--instance=INSTANCE
将证书信息下载到本地 PEM 文件中:
gcloud sql ssl server-ca-certs list \
--format="value(cert)" \
--instance=INSTANCE_NAME > \
FILE_PATH /FILE_NAME .pem
通过将下载的文件复制到客户端主机上并替换现有的 server-ca.pem 文件,将所有客户端更新为使用新信息。
更新完各客户端后,完成轮替:
gcloud sql ssl server-ca-certs rotate \
--instance=INSTANCE_NAME
确认您的客户端连接正确。
如果有任何客户端未使用新轮替的证书进行连接,您可以回滚 到先前的配置。
REST v1
下载服务器 CA 证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /listServerCas
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /listServerCas"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /listServerCas" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"certs": [
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2020-02-10T17:18:54.935Z",
"expirationTime": "2030-02-07T17:19:54.935Z"
},
{
"kind": "sql#sslCert",
certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2019-11-14T22:43:56.458Z",
"expirationTime": "2029-11-11T22:44:56.458Z"
}
],
"activeVersion": "active-version ",
"kind": "sql#instancesListServerCas"
}
完成轮替:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
REST v1beta4
下载服务器 CA 证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /listServerCas
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /listServerCas"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /listServerCas" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"certs": [
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2020-02-10T17:18:54.935Z",
"expirationTime": "2030-02-07T17:19:54.935Z"
},
{
"kind": "sql#sslCert",
certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2019-11-14T22:43:56.458Z",
"expirationTime": "2029-11-11T22:44:56.458Z"
}
],
"activeVersion": "active-version ",
"kind": "sql#instancesListServerCas"
}
完成轮替:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
回滚证书轮替操作
完成证书轮替之后,您的客户端必须全部使用新证书连接到 Cloud SQL 实例。如果客户端未正确更新为使用新证书的信息,则它们无法使用 SSL/TLS 连接到实例。如果发生这种情况,您可以回滚到先前的证书配置。
回滚操作会将有效证书转入“即将生效”空档(取代任何“即将生效”证书)。“上一个”证书会成为有效证书,证书配置也会恢复到完成轮替之前的状态。
要回滚到先前的证书配置,请按如下所述操作:
控制台
在 Google Cloud 控制台中,转到 Cloud SQL 实例 页面。
转到“Cloud SQL 实例”
如需打开实例的概览 页面,请点击实例名称。
从 SQL 导航菜单中选择连接 。
选择安全 标签页。
点击展开管理证书 。
选择回滚 CA 证书 。如果没有符合条件的证书,则回滚选项不可用。否则,回滚操作会在几秒钟后完成。
gcloud
gcloud sql ssl server-ca-certs rollback \
--instance=INSTANCE_NAME
REST v1
下载服务器 CA 证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /listServerCas
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /listServerCas"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /listServerCas" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"certs": [
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2020-02-10T17:18:54.935Z",
"expirationTime": "2030-02-07T17:19:54.935Z"
},
{
"kind": "sql#sslCert",
certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2019-11-14T22:43:56.458Z",
"expirationTime": "2029-11-11T22:44:56.458Z"
}
],
"activeVersion": "active-version ",
"kind": "sql#instancesListServerCas"
}
复制回滚目标版本的 sha1Fingerprint
字段。
先找出 sha1Fingerprint 值显示为 activeVersion
的版本,然后找到 createTime 值在该版本之前并且间隔最近的那个版本。
按如下方式回滚轮替:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa
请求 JSON 正文:
{
"rotateServerCaContext": {"nextVersion": "sha1Fingerprint "}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
REST v1beta4
下载服务器 CA 证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /listServerCas
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /listServerCas"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /listServerCas" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"certs": [
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2020-02-10T17:18:54.935Z",
"expirationTime": "2030-02-07T17:19:54.935Z"
},
{
"kind": "sql#sslCert",
certSerialNumber": "cert-serial-number ",
"cert": "cert-value ",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2019-11-14T22:43:56.458Z",
"expirationTime": "2029-11-11T22:44:56.458Z"
}
],
"activeVersion": "active-version ",
"kind": "sql#instancesListServerCas"
}
复制回滚目标版本的 sha1Fingerprint
字段。
先找出 sha1Fingerprint 值显示为 activeVersion
的版本,然后找到 createTime 值在该版本之前并且间隔最近的那个版本。
按如下方式回滚轮替:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa
请求 JSON 正文:
{
"rotateServerCaContext": {"nextVersion": "sha1Fingerprint "}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
启动轮替
您无需等收到 Cloud SQL 发来的电子邮件后再启动轮替,而是可以随时启动。启动轮替后,系统会创建一个新证书,并将其置于“即将生效”时隙中。如果在您发出请求时“即将生效”空档中已存在证书,则该证书会被删除。只能有一个即将生效的证书。
如需启动轮替,请执行以下操作:
控制台
在 Google Cloud 控制台中,转到 Cloud SQL 实例 页面。
转到“Cloud SQL 实例”
如需打开实例的概览 页面,请点击实例名称。
从 SQL 导航菜单中选择连接 。
选择安全 标签页。
点击创建新的 CA 证书 。
点击展开管理证书 。
选择轮替 CA 证书 。
如果没有符合条件的证书,则轮替选项不可用。
按照轮替服务器 CA 证书 中所述完成轮替。
gcloud
启动轮替:
gcloud sql ssl server-ca-certs create \
--instance=INSTANCE_NAME
按照轮替服务器 CA 证书 中所述完成轮替。
REST v1
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id /rotateServerCa" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
按照轮替服务器 CA 证书 中所述完成轮替。
REST v1beta4
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /rotateServerCa" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
按照轮替服务器 CA 证书 中所述完成轮替。
获取有关服务器 CA 证书的信息
您可以获取有关服务器 CA 证书的信息,例如,该证书何时失效或者提供何种加密级别。
控制台
在 Google Cloud 控制台中,转到 Cloud SQL 实例 页面。
转到“Cloud SQL 实例”
如需打开实例的概览 页面,请点击实例名称。
从 SQL 导航菜单中选择连接 。
选择安全 标签页。
在管理服务器 CA 证书 中,您可以在表中查看服务器 CA 证书的失效日期。
如需查看证书类型,请使用 gcloud sql ssl server-ca-certs list --instance=INSTANCE_NAME
命令。
gcloud
gcloud sql ssl server-ca-certs list \
--instance= INSTANCE_NAME
REST v1
描述实例时,您可以查看有关服务器 CA 证书的详细信息:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=serverCaCert
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=serverCaCert"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/project-id /instances/instance-id ?fields=serverCaCert" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"serverCaCert":
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value -",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2020-02-10T17:18:54.935Z",
"expirationTime": "2030-02-07T17:19:54.935Z"
}
}
REST v1beta4
描述实例时,您可以查看有关服务器 CA 证书的详细信息:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=serverCaCert
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=serverCaCert"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ?fields=serverCaCert" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"serverCaCert":
{
"kind": "sql#sslCert",
"certSerialNumber": "cert-serial-number ",
"cert": "cert-value -",
"commonName": "ca-server-name ",
"sha1Fingerprint": "sha1Fingerprint ",
"instance": "instance-id ",
"createTime": "2020-02-10T17:18:54.935Z",
"expirationTime": "2030-02-07T17:19:54.935Z"
}
}
查看 CA 证书的内容
您可以使用 openssl storeutl
查看 CA 证书的内容。
运行 beta sql ssl server-ca-certs list 命令时,您可能会从之前的轮替相关操作中获取多个 CA 证书。
gcloud
运行以下命令:
gcloud beta sql ssl server-ca-certs list \
--instance= INSTANCE_NAME \
--format= 'value(cert)' > temp_cert.pem
将 INSTANCE_NAME 替换为实例名称。
使用 openssl
检查 CA 证书的内容。
openssl storeutl -noout -text temp_cert.pem
查看服务器证书的内容
您可以使用
openssl s_client
查看服务器证书的内容。
gcloud
如需查看服务器证书内容,请运行以下命令:
openssl s_client -starttls mysql -connect INSTANCE_IP_ADDRESS :3306
将 INSTANCE_IP_ADDRESS 替换为实例的 IP 地址。
管理服务器证书(共享 CA)
本部分介绍了如何在使用共享 CA 的实例上管理服务器证书。您可以选择将共享 CA 用作实例的服务器 CA 模式,方法是在创建实例 时为 serverCaMode
设置(Cloud SQL Admin API)或 --server-ca-mode
标志(gcloud CLI )指定 GOOGLE_MANAGED_CAS_CA
。
轮替服务器证书
如果您收到了一封有关证书失效的通知,或者您想要发起轮替,请按照以下步骤操作,以完成轮替。在开始轮替之前,必须为即将进行的轮替创建新的服务器证书。如果已为即将进行的轮替创建新的服务器证书,则可以跳过以下过程的第一步。
如需轮替实例上的服务器证书,请执行以下步骤:
如果您需要新的服务器证书,请创建一个。
如果您的客户端已信任根 CA,则此步骤是可选的。但是,如果您需要使用服务器 CA 信息更新客户端,请执行以下操作:
下载最新的服务器 CA 信息。
更新客户端以使用最新的服务器 CA 信息。
完成轮替,方法是将有效证书移至上一个空档,并将新证书更新为有效证书。
控制台
在预览版 期间,您无法使用 Google Cloud 控制台在使用 CA Service 的实例上轮替服务器证书。
请改用 gcloud beta sql ssl server-certs rotate
命令或 Cloud SQL Admin API 命令。
gcloud
如需创建服务器证书,请使用以下命令:
gcloud beta sql ssl server-certs create \
--instance=INSTANCE
将 INSTANCE 替换为实例名称。
确保您使用的是最新的 CA 软件包 。
如果您使用的不是最新的 CA 软件包,请运行以下命令,将实例的最新服务器 CA 信息下载到本地 PEM 文件:
gcloud beta sql ssl server-certs list \
--format="value(ca_cert.cert)" \
--instance=INSTANCE_NAME > \
FILE_PATH /server-ca.pem
或者,从本页上的根 CA 和区域 CA 证书捆绑包表 下载 CA 捆绑包。
然后,通过将下载的文件复制到客户端宿主机上并替换现有的 server-ca.pem
文件,将所有客户端更新为使用新的服务器 CA 信息。
更新完所有客户端(如果需要客户端更新)后,完成轮替:
gcloud beta sql ssl server-certs rotate \
--instance=INSTANCE_NAME
确认您的客户端连接正确。
如果有任何客户端未使用新轮替的服务器证书进行连接,请回滚 到先前的配置。
REST v1
创建服务器证书。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /addServerCertificate
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /addServerCertificate"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /addServerCertificate" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2024-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
如果您需要下载服务器 CA 证书信息,可以使用以下命令。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"caCerts": [
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_CA_CERT_ONE ",
"cert": "CERT_VALUE ",
"commonName": "CA_SERVER_NAME ",
"sha1Fingerprint": "sha1Fingerprint_CA_CERT_ONE ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-07-10T17:18:54.935Z",
"expirationTime": "2034-07-10T17:19:54.935Z"
},
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_CA_CERT_TWO ",
"cert": "CERT_VALUE ",
"commonName": "CA_SERVER_NAME ",
"sha1Fingerprint": "sha1Fingerprint_CA_CERT_TWO ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-07-14T22:43:56.458Z",
"expirationTime": "2034-11-11T22:44:56.458Z"
}
],
"serverCerts": [
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_SERVER_CERT_ONE ",
"cert": "CERT_VALUE "
"commonName": "SUBJECT_VALUE ",
"sha1Fingerprint": "sha1Fingerprint_SERVER_CERT_ONE ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-09-16T18:11:39Z",
"expirationTime": "2025-09-16T18:11:38Z"
},
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_SERVER_CERT_TWO ",
"cert": "CERT_VALUE "
"commonName": "SUBJECT_VALUE ",
"sha1Fingerprint": "sha1Fingerprint_SERVER_CERT_TWO ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-09-10T20:56:06Z",
"expirationTime": "2025-09-10T20:56:05Z"
}
],
"activeVersion": "sha1Fingerprint_SERVER_CERT_TWO ",
"kind": "sql#instancesListServerCertificates"
}
完成轮替。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2024-09-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/operation-id ",
"targetProject": "PROJECT_ID "
}
REST v1beta4
创建服务器证书。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /addServerCertificate
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /addServerCertificate"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /addServerCertificate" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2024-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
如果您需要下载服务器 CA 证书信息,可以使用以下命令。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"caCerts": [
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_CA_CERT_ONE ",
"cert": "CERT_VALUE ",
"commonName": "CA_SERVER_NAME ",
"sha1Fingerprint": "sha1Fingerprint_CA_CERT_ONE ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-07-10T17:18:54.935Z",
"expirationTime": "2034-07-10T17:19:54.935Z"
},
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_CA_CERT_TWO ",
"cert": "CERT_VALUE ",
"commonName": "CA_SERVER_NAME ",
"sha1Fingerprint": "sha1Fingerprint_CA_CERT_TWO ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-07-14T22:43:56.458Z",
"expirationTime": "2034-11-11T22:44:56.458Z"
}
],
"serverCerts": [
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_SERVER_CERT_ONE ",
"cert": "CERT_VALUE "
"commonName": "SUBJECT_VALUE ",
"sha1Fingerprint": "sha1Fingerprint_SERVER_CERT_ONE ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-09-16T18:11:39Z",
"expirationTime": "2025-09-16T18:11:38Z"
},
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_SERVER_CERT_TWO ",
"cert": "CERT_VALUE "
"commonName": "SUBJECT_VALUE ",
"sha1Fingerprint": "sha1Fingerprint_SERVER_CERT_TWO ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-09-10T20:56:06Z",
"expirationTime": "2025-09-10T20:56:05Z"
}
],
"activeVersion": "sha1Fingerprint_SERVER_CERT_TWO ",
"kind": "sql#instancesListServerCertificates"
}
完成轮替。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2024-09-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
回滚证书轮替
完成服务器证书轮替后,您的所有客户端都必须使用新证书连接到 Cloud SQL 实例。如果客户端未正确更新为使用新证书的信息,则它们无法使用 SSL/TLS 连接到实例。如果发生这种情况,您可以回滚到先前的证书配置。
回滚操作会将有效证书转入“即将生效”时隙,该时隙会取代任何“即将生效”证书。“上一个”证书会成为有效证书,证书配置也会恢复到完成轮替之前的状态。
控制台
在预览版 期间,您无法使用 Google Cloud 控制台在使用 CA Service 的实例上回滚服务器证书。请改用 gcloud beta sql ssl server-certs rollback
命令或 Cloud SQL Admin API 命令。
gcloud
gcloud beta sql ssl server-certs rollback \
--instance=INSTANCE_NAME
REST v1
列出您的服务器证书。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"caCerts": [
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_CA_CERT_ONE ",
"cert": "CERT_VALUE ",
"commonName": "CA_SERVER_NAME ",
"sha1Fingerprint": "sha1Fingerprint_CA_CERT_ONE ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-07-10T17:18:54.935Z",
"expirationTime": "2034-07-10T17:19:54.935Z"
},
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_CA_CERT_TWO ",
"cert": "CERT_VALUE ",
"commonName": "CA_SERVER_NAME ",
"sha1Fingerprint": "sha1Fingerprint_CA_CERT_TWO ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-07-14T22:43:56.458Z",
"expirationTime": "2034-11-11T22:44:56.458Z"
}
],
"serverCerts": [
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_SERVER_CERT_ONE ",
"cert": "CERT_VALUE "
"commonName": "SUBJECT_VALUE ",
"sha1Fingerprint": "sha1Fingerprint_SERVER_CERT_ONE ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-09-16T18:11:39Z",
"expirationTime": "2025-09-16T18:11:38Z"
},
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_SERVER_CERT_TWO ",
"cert": "CERT_VALUE "
"commonName": "SUBJECT_VALUE ",
"sha1Fingerprint": "sha1Fingerprint_SERVER_CERT_TWO ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-09-10T20:56:06Z",
"expirationTime": "2025-09-10T20:56:05Z"
}
],
"activeVersion": "sha1Fingerprint_SERVER_CERT_TWO ",
"kind": "sql#instancesListServerCertificates"
}
复制回滚目标版本的 sha1Fingerprint
字段。
先找出 sha1Fingerprint
值显示为 activeVersion
的版本,然后找到 createTime
值在该版本之前并且间隔最近的那个版本。
回滚轮替。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate
请求 JSON 正文:
{
"rotateServerCertificateContext": {"nextVersion": "sha1Fingerprint "}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/v1/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
REST v1beta4
列出您的服务器证书。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
GET https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method GET ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /listServerCertificates" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"caCerts": [
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_CA_CERT_ONE ",
"cert": "CERT_VALUE ",
"commonName": "CA_SERVER_NAME ",
"sha1Fingerprint": "sha1Fingerprint_CA_CERT_ONE ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-07-10T17:18:54.935Z",
"expirationTime": "2034-07-10T17:19:54.935Z"
},
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_CA_CERT_TWO ",
"cert": "CERT_VALUE ",
"commonName": "CA_SERVER_NAME ",
"sha1Fingerprint": "sha1Fingerprint_CA_CERT_TWO ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-07-14T22:43:56.458Z",
"expirationTime": "2034-11-11T22:44:56.458Z"
}
],
"serverCerts": [
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_SERVER_CERT_ONE ",
"cert": "CERT_VALUE "
"commonName": "SUBJECT_VALUE ",
"sha1Fingerprint": "sha1Fingerprint_SERVER_CERT_ONE ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-09-16T18:11:39Z",
"expirationTime": "2025-09-16T18:11:38Z"
},
{
"kind": "sql#sslCert",
"certSerialNumber": "CERT_SERIAL_NUMBER_SERVER_CERT_TWO ",
"cert": "CERT_VALUE "
"commonName": "SUBJECT_VALUE ",
"sha1Fingerprint": "sha1Fingerprint_SERVER_CERT_TWO ",
"instance": "INSTANCE_NAME ",
"createTime": "2024-09-10T20:56:06Z",
"expirationTime": "2025-09-10T20:56:05Z"
}
],
"activeVersion": "sha1Fingerprint_SERVER_CERT_TWO ",
"kind": "sql#instancesListServerCertificates"
}
复制回滚目标版本的 sha1Fingerprint
字段。
先找出 sha1Fingerprint
值显示为 activeVersion
的版本,然后找到 createTime
值在该版本之前并且间隔最近的那个版本。
回滚轮替。
在使用任何请求数据之前,请先进行以下替换:
PROJECT_ID :项目 ID
INSTANCE_ID :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate
请求 JSON 正文:
{
"rotateServerCertificateContext": {"nextVersion": "sha1Fingerprint "}
}
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d @request.json \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate"
PowerShell (Windows)
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -ContentType: "application/json; charset=utf-8" ` -InFile request.json ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID /rotateServerCertificate" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /instances/INSTANCE_ID ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "OPERATION_ID ",
"targetId": "INSTANCE_ID ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/PROJECT_ID /operations/OPERATION_ID ",
"targetProject": "PROJECT_ID "
}
查看 CA 证书的内容
您可以使用 openssl storeutl
实用程序查看 CA 证书的内容。
由于信任链,当您运行 beta sql ssl server-certs list 命令时,始终会获得多个 CA 证书。您还可能会从之前的轮替相关操作中获取多个 CA 证书。
gcloud
运行以下命令:
gcloud beta sql ssl server-certs list \
--instance= INSTANCE_NAME \
--format= 'value(cert)' > temp_cert.pem
将 INSTANCE_NAME 替换为实例名称。
使用 openssl
检查 CA 证书的内容。
openssl storeutl -noout -text temp_cert.pem
查看服务器证书的内容
您可以使用 openssl
实用程序和 beta sql ssl server-certs list 命令查看服务器证书的内容。
由于信任链,您在运行 gcloud CLI 命令时始终会获得多个 CA 证书。您还可能会从之前的轮替相关操作中获取多个 CA 证书。
gcloud
仅使用 openssl s_client
:
openssl s_client -starttls mysql -connect INSTANCE_IP_ADDRESS :3306
将 INSTANCE_IP_ADDRESS 替换为实例的 IP 地址。
使用 gcloud CLI
和 openssl storeutl
:
运行以下命令:
gcloud beta sql ssl server-certs list \
--instance= INSTANCE_NAME \
--format= 'value(ssl_cert.cert)' > temp_cert.pem
将 INSTANCE_NAME 替换为实例名称。
使用 openssl
检查服务器证书的内容。
openssl storeutl -noout -text temp_cert.pem
下载根 CA 和区域性 CA 证书捆绑包
您可以从下表下载根 CA 和区域 CA 证书捆绑包。
重置 SSL/TLS 配置
您可以完全重置 SSL/TLS 配置。
注意 :执行此操作将造成您无法使用 SSL/TLS 连接到实例,除非您创建新的客户端证书来替换以前使用的任何证书。
控制台
在 Google Cloud 控制台中,转到 Cloud SQL 实例 页面。
转到“Cloud SQL 实例”
如需打开实例的概览 页面,请点击实例名称。
从 SQL 导航菜单中选择连接 。
前往重置 SSL 配置 部分。
点击重置 SSL 配置 。
gcloud
刷新证书:
gcloud sql instances reset-ssl-config INSTANCE_NAME
gcloud sql instances restart INSTANCE_NAME
新建客户端证书 。
REST v1beta4
刷新证书:
在使用任何请求数据之前,请先进行以下替换:
project-id :项目 ID
instance-id :实例 ID
HTTP 方法和网址:
POST https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /resetSslConfig
如需发送您的请求,请展开以下选项之一:
curl(Linux、macOS 或 Cloud Shell)
执行以下命令:
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json; charset=utf-8" \ -d "" \ "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /resetSslConfig"
PowerShell (Windows)
执行以下命令:
$cred = gcloud auth print-access-token $headers = @{ "Authorization" = "Bearer $cred" } Invoke-WebRequest ` -Method POST ` -Headers $headers ` -Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id /resetSslConfig" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
响应
{
"kind": "sql#operation",
"targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /instances/instance-id ",
"status": "PENDING",
"user": "user@example.com",
"insertTime": "2020-01-20T21:30:35.667Z",
"operationType": "UPDATE",
"name": "operation-id ",
"targetId": "instance-id ",
"selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id /operations/operation-id ",
"targetProject": "project-id "
}
新建客户端证书 。
后续步骤