管理安全資料傳輸層 (SSL)/傳輸層安全標準 (TLS) 憑證
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁說明如何管理用戶端和伺服器 CA 憑證。
管理用戶端憑證
請按照下列程序管理 Cloud SQL 中的用戶端憑證。
擷取用戶端憑證
您可以擷取用戶端憑證的公開金鑰部分,但無法擷取私密金鑰。如果您已遺失私密金鑰,則必須建立新的憑證。
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
選取「安全性」 分頁標籤。
在「管理用戶端憑證」 中,按一下憑證名稱。
「SSL Client Certificate」 頁面會隨即開啟,並顯示用戶端憑證 (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 導覽選單中選取「Connections」 。
選取「安全性」 分頁標籤。
在「管理用戶端憑證」 中,找出要刪除的憑證,然後按一下 。
在「Delete client certificate」 窗格中,按一下「OK」 。
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": "[email protected] ",
"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": "[email protected] ",
"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 驗證 Proxy 連線會在連線時自動收到新的憑證。
控制台
將新的伺服器 CA 憑證下載至本機環境,並以 PEM 檔案格式進行編碼:
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
選取「安全性」 分頁標籤。
按一下「管理憑證」 展開。
選取「Rotate CA certificate」 。
如果沒有符合資格的憑證,就無法使用輪替選項。您必須建立新的伺服器 CA 憑證 。
按一下「下載憑證」 。
將下載的檔案複製到用戶端主機,取代現有的 server-ca.pem
檔案,藉此更新所有 PostgreSQL 用戶端,以便使用新資訊。
當您更新完用戶端之後,完成輪替:
返回「安全性」 分頁。
按一下「管理憑證」 展開。
選取「Rotate CA certificate」 。
確認您的用戶端正確連線。
如果有任何用戶端未使用剛輪替的憑證進行連線,您可以選取「Rollback CA certificate」 來復原 先前的設定。
gcloud
建立伺服器 CA 憑證:
gcloud 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": "[email protected] ",
"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": "[email protected] ",
"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 "
}
如果您在嘗試旋轉標示為 No upcoming/previous Server CA Certificate exists
的憑證時收到錯誤訊息,請確認您是在使用個別例項 CA 階層的例項上執行指令。您可以使用 gcloud sql instances describe
指令,查看 Cloud SQL 執行個體已設定哪些 CA 階層。詳情請參閱「查看執行個體資訊 」。
復原憑證輪替作業
當您完成憑證輪替之後,您的用戶端必須全都使用新憑證來連線至 Cloud SQL 執行個體。如果用戶端未正確更新為使用新憑證資訊,就無法使用 SSL/TLS 連線至您的執行個體。如果發生這種情況,您可以回復先前的憑證設定。
回溯作業會將有效憑證移至「即將推出」的運算單元 (取代任何「即將推出」的憑證)。「上一個」憑證會成為有效憑證,將憑證設定還原為輪替前狀態。
復原至上一個憑證設定:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
選取「安全性」 分頁標籤。
按一下「管理憑證」 展開。
選取「復原 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
欄位。找出 createTime 值比 sha1Fingerprint 值早的版本,並將其顯示為 activeVersion
。
復原旋轉作業:
使用任何要求資料之前,請先替換以下項目:
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": "[email protected] ",
"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
欄位。找出 createTime 值比 sha1Fingerprint 值早的版本,並將其顯示為 activeVersion
。
復原旋轉作業:
使用任何要求資料之前,請先替換以下項目:
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": "[email protected] ",
"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 階層的例項上執行指令。No upcoming/previous Server CA Certificate exists
您可以使用 gcloud sql instances describe
指令,查看 Cloud SQL 執行個體已設定哪些 CA 階層。詳情請參閱「查看執行個體資訊 」。
啟動旋轉
您不必等待 Cloud SQL 傳送的電子郵件,即可開始輪替。您隨時可以開始進行。當您開始輪替時,會建立新憑證,並將它放進「接下來的」運算單元中。如果在您提出要求時,憑證已出現在「即將到期」的時間範圍內,系統就會刪除該憑證。只能有一個即將到期的證照。
開始輪替:
控制台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
選取「安全性」 分頁標籤。
按一下「管理憑證」 展開。
按一下「建立新的 CA 憑證」 。
選取「Rotate CA certificate」 。
如果沒有符合資格的憑證,就無法使用輪替選項。
按照「輪替伺服器 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": "[email protected] ",
"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": "[email protected] ",
"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 導覽選單中選取「Connections」 。
選取「安全性」 分頁標籤。
在「管理伺服器 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 憑證的內容。
執行 sql ssl server-ca-certs list 指令時,您可能會從先前的輪替相關作業取得多個 CA 憑證。
gcloud
請執行下列指令:
gcloud 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 postgres -connect INSTANCE_IP_ADDRESS :5432
將 INSTANCE_IP_ADDRESS 替換為執行個體的 IP 位址。
管理伺服器憑證 (共用 CA)
本節說明如何在使用共用 CA 或客戶管理 CA 的執行個體上管理伺服器憑證。
您可以在建立執行個體 時,為 serverCaMode
設定 (Cloud SQL Admin API) 或 --server-ca-mode
旗標 (gcloud CLI ) 指定 GOOGLE_MANAGED_CAS_CA
,即可選擇使用共用 CA 做為執行個體的伺服器 CA 模式。
如要將客戶管理的 CA 用於執行個體的伺服器 CA 模式,您必須在建立執行個體 時,為 serverCaMode
設定 (Cloud SQL 管理員 API) 指定 CUSTOMER_MANAGED_CAS_CA
,或為 --server-ca-mode
旗標 (gcloud CLI ) 指定 --server-ca-mode
,且必須擁有有效的 CA 集區和 CA。詳情請參閱「使用客戶代管 CA 」。
輪替伺服器憑證
如果您收到伺服器憑證即將到期的通知,或是想要啟動輪替作業,請按照下列步驟完成輪替作業。開始輪替前,您必須為即將輪替的憑證建立新的伺服器憑證。如果已為即將輪替的憑證建立新的伺服器憑證,請略過下列程序的第一個步驟。
如要在執行個體上輪替伺服器憑證,請執行下列步驟:
如果您需要新的伺服器憑證,請建立 。
如果您的用戶端已信任根 CA,則可選擇略過這個步驟。不過,如果您需要更新用戶端的伺服器 CA 資訊,請按照下列步驟操作:
下載最新的伺服器 CA 資訊。
更新用戶端以使用最新的伺服器 CA 資訊。
將有效憑證移至上一個運算單元,並將新憑證更新為有效憑證,即可完成輪替。
控制台
將以 PEM 檔案編碼的伺服器 CA 憑證資訊下載至本機環境:
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
選取「安全性」 分頁標籤。
按一下「管理憑證」 展開。
確認「Rotate server certificate」 選項是否顯示為可用選項,但請勿立即選取。如果沒有符合資格的憑證,就無法使用輪替選項。您必須建立新的伺服器憑證 。
按一下「下載憑證」 。
將下載的檔案複製到用戶端主機,取代現有的 server-ca.pem
檔案,藉此更新所有 PostgreSQL 用戶端,以便使用新資訊。
當您更新完用戶端之後,完成輪替:
返回「安全性」 分頁。
按一下「管理憑證」 展開。
選取「Rotate certificate」(輪替憑證) 。
在「Confirm certificate rotation」 對話方塊中,按一下「Rotate」 。
確認您的用戶端正確連線。
如果有任何用戶端未使用剛輪替的憑證進行連線,您可以選取「Rollback certificate」 來復原 先前的設定。
gcloud
如要建立伺服器憑證,請使用下列指令:
gcloud sql ssl server-certs create \
--instance=INSTANCE
將 INSTANCE 替換為執行個體名稱。請確認您使用的是最新的 CA 套件 。
如果您未使用最新的 CA 套件,請執行下列指令,將執行個體的最新伺服器 CA 資訊下載至本機 PEM 檔案:
gcloud 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 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": "[email protected] ",
"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": "[email protected] ",
"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": "[email protected] ",
"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": "[email protected] ",
"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 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
選取「安全性」 分頁標籤。
按一下「管理憑證」 展開。
選取「復原伺服器憑證」 。
如果沒有符合資格的憑證,就無法使用復原選項。
在「Confirm certificate rollback」 對話方塊中,選取「Rollback」 。
回溯可能需要幾秒鐘才能完成。
gcloud
gcloud 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
欄位。
找出 createTime
值比 sha1Fingerprint
值早出現的版本,該版本會顯示為 activeVersion
。
回復旋轉。
使用任何要求資料之前,請先替換以下項目:
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": "[email protected] ",
"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
欄位。
找出 createTime
值比 sha1Fingerprint
值早出現的版本,該版本會顯示為 activeVersion
。
回復旋轉。
使用任何要求資料之前,請先替換以下項目:
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": "[email protected] ",
"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 憑證的內容。
執行 sql ssl server-certs list 指令時,由於信任鏈結,您一律會取得多個 CA 憑證。您也可能會從先前的輪替相關作業中取得多個 CA 憑證。
gcloud
請執行下列指令:
gcloud 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
公用程式和 sql ssl server-certs list 指令查看伺服器憑證的內容。
執行 gcloud CLI 指令時,由於信任鏈,您一律會取得多個 CA 憑證。您也可能會從先前的旋轉相關作業中取得多個 CA 憑證。
gcloud
只使用 openssl s_client
:
openssl s_client -starttls postgres -connect INSTANCE_IP_ADDRESS :5432
將 INSTANCE_IP_ADDRESS 替換為執行個體的 IP 位址。
使用 gcloud CLI
和 openssl storeutl
:
請執行下列指令:
gcloud 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 憑證組合
如果您使用 Google 代管的共用 CA 設定,可以從下表下載根 CA 和區域 CA 憑證套件。
這些憑證套件不適用於使用個別執行個體或客戶管理的 CA 選項的執行個體。
重設安全資料傳輸層 (SSL)/傳輸層安全標準 (TLS) 設定
您可以完全重設 SSL/TLS 設定。
注意: 執行這項操作之後,您就無法使用 SSL/TLS 連線至執行個體。您必須建立新的用戶端憑證,取代先前使用的憑證,才能使用 SSL/TLS。
主控台
前往 Google Cloud 控制台的「Cloud SQL 執行個體」 頁面。
前往 Cloud SQL 執行個體
如要開啟執行個體的「總覽」 頁面,請按一下執行個體名稱。
在 SQL 導覽選單中選取「Connections」 。
前往「重設安全資料傳輸層 (SSL) 的設定」 部分。
按一下「Reset SSL Configuration」 。
gcloud
重新整理憑證:
gcloud sql instances reset-ssl-config 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": "[email protected] ",
"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 "
}
建立新的用戶端憑證 。
後續步驟