部署全球性 Google 代管憑證,並透過 DNS 授權

本教學課程說明如何使用 Certificate Manager,部署具備 DNS 授權的全域 Google 代管憑證。

下列全域負載平衡器支援具備 DNS 授權的 Google 代管憑證:

  • 全域外部應用程式負載平衡器
  • 傳統版應用程式負載平衡器
  • 全域外部 Proxy 網路負載平衡器
  • 傳統版 Proxy 網路負載平衡器

如要部署至跨區域負載平衡器或區域性負載平衡器,請參閱下列內容:

目標

本教學課程將說明如何完成下列工作:

  • 使用 Certificate Manager,建立由公開信任憑證授權單位核發、具備 DNS 授權的 Google 代管憑證。
  • 使用目標 HTTPS Proxy,將憑證部署至支援的負載平衡器。

事前準備

  1. 登入 Google Cloud 帳戶。如果您未曾使用過 Google Cloud,歡迎 建立帳戶,親自體驗實際使用我們產品的成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Compute Engine, Certificate Manager APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  5. Install the Google Cloud CLI.

  6. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  7. To initialize the gcloud CLI, run the following command:

    gcloud init
  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. Enable the Compute Engine, Certificate Manager APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  11. Install the Google Cloud CLI.

  12. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  13. To initialize the gcloud CLI, run the following command:

    gcloud init
  14. 建立公開 DNS 區域

必要的角色

請確認您具備下列角色,才能完成本教學課程中的工作:

  • Certificate Manager 擁有者 (roles/certificatemanager.owner)

    建立及管理 Certificate Manager 資源。

  • Compute 負載平衡器管理員 (roles/compute.loadBalancerAdmin) 或 Compute 網路管理員 (roles/compute.networkAdmin)

    必須具備這項權限,才能建立及管理 HTTPS 目標 Proxy。

  • DNS 管理員 (roles/dns.admin)

    如要使用 Cloud DNS 做為 DNS 解決方案,則必須提供這項資訊。

如要瞭解詳情,請參考下列資源:

網域名稱

如要建立憑證,請取得您擁有的網域完整網域名稱 (FQDN)。如果您沒有網域,可以使用 Cloud Domains 註冊網域。

建立負載平衡器

本教學課程假設您已建立並設定負載平衡器的後端、健康狀態檢查、後端服務和網址對應。如果您已建立外部應用程式負載平衡器,請記下網址對應的名稱,因為稍後會用到。

如果您尚未建立負載平衡器,請參閱下列頁面來建立:

建立 Google 代管憑證並設定 DNS 授權

建立憑證前,請先建立公開 DNS 區域。接著,建立 DNS 授權,並將 CNAME 記錄新增至目標 DNS 區域。

建立 DNS 授權

DNS 授權僅涵蓋單一網域名稱。您必須為要與目標憑證搭配使用的每個網域名稱,分別建立 DNS 授權。

如要為萬用字元憑證 (例如 *.myorg.example.com) 建立 DNS 授權,請為上層網域 (例如 myorg.example.com) 設定 DNS 授權。

控制台

建立憑證時,您可以建立 DNS 授權,或附加現有的 DNS 授權。詳情請參閱「建立參照 DNS 授權的 Google 代管憑證」。

gcloud

您可以建立兩種 DNS 授權:FIXED_RECORD 或 PER_PROJECT_RECORD。詳情請參閱「DNS 授權」。

FIXED_RECORD DNS 授權

如要建立 FIXED_RECORD DNS 授權,請使用下列 gcloud certificate-manager dns-authorizations create 指令:

gcloud certificate-manager dns-authorizations create AUTHORIZATION_NAME \
    --domain="DOMAIN_NAME" \
    --type=[FIXED_RECORD]

更改下列內容:

  • AUTHORIZATION_NAME:DNS 授權的名稱。
  • DOMAIN_NAME:您要建立這項 DNS 授權的目標網域名稱。網域名稱必須是完整網域名稱,例如 myorg.example.com。

建立 FIXED_RECORD DNS 授權後,請使用 gcloud certificate-manager dns-authorizations describe 指令驗證:

gcloud certificate-manager dns-authorizations describe AUTHORIZATION_NAME

輸出結果大致如下。在輸出內容中,尋找 dnsResourceRecord 區段。找出 CNAME 記錄,並將記錄詳細資料 (data、name 和 type) 新增至 DNS 設定。

createTime: '2022-01-14T13:35:00.258409106Z'
dnsResourceRecord:
  data: 0e40fc77-a37d-4eb8-8fe1-eea2e18d12d9.4.authorize.certificatemanager.goog.
  name: _acme-challenge.myorg.example.com.
  type: CNAME
domain: myorg.example.com
name: projects/myProject/locations/global/dnsAuthorizations/myAuthorization
updateTime: '2022-01-14T13:35:01.571086137Z'

PER_PROJECT_RECORD DNS 授權

如要建立 PER_PROJECT_RECORD DNS 授權,請使用下列 gcloud certificate-manager dns-authorizations create 指令:

gcloud certificate-manager dns-authorizations create AUTHORIZATION_NAME \
    --domain="DOMAIN_NAME" \
    --type=PER_PROJECT_RECORD

更改下列內容:

  • AUTHORIZATION_NAME:DNS 授權的名稱。
  • DOMAIN_NAME:您要建立這項 DNS 授權的目標網域名稱。網域名稱必須是完整網域名稱,例如 myorg.example.com。

建立 PER_PROJECT_RECORD DNS 授權後,請使用 gcloud certificate-manager dns-authorizations describe 指令驗證:

gcloud certificate-manager dns-authorizations describe AUTHORIZATION_NAME

輸出結果大致如下。在輸出內容中,尋找 dnsResourceRecord 區段。找出 CNAME 記錄,並將記錄詳細資料 (data、name 和 type) 新增至 DNS 設定。

createTime: '2022-01-14T13:35:00.258409106Z'
dnsResourceRecord:
  data: 0e40fc77-a37d-4eb8-8fe1-eea2e18d12d9.4.authorize.certificatemanager.goog.
  name: _acme-challenge_ujmmovf2vn55tgye.myorg.example.com
  type: CNAME
domain: myorg.example.com
name: projects/myProject/locations/global/dnsAuthorizations/myAuthorization
updateTime: '2022-01-14T13:35:01.571086137Z'

Terraform

如要建立 DNS 授權,您可以使用 google_certificate_manager_dns_authorization 資源。

resource "google_certificate_manager_dns_authorization" "default" {
  name        = "${local.name}-dnsauth-${random_id.tf_prefix.hex}"
  description = "The default dns auth"
  domain      = local.domain
  labels = {
    "terraform" : true
  }
}

如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。

API

如要建立 DNS 授權,請向 dnsAuthorizations.create 方法發出 POST 要求:

POST /v1/projects/PROJECT_ID/locations/global/dnsAuthorizations?dns_authorization_id=AUTHORIZATION_NAME
{
  "domain": "DOMAIN_NAME",
  "type": "PER_PROJECT_RECORD" //optional
}

更改下列內容:

  • PROJECT_ID: Google Cloud 專案 ID。
  • AUTHORIZATION_NAME:DNS 授權的名稱。
  • DOMAIN_NAME:您要建立這項 DNS 授權的目標網域名稱。網域名稱必須是完整網域名稱,例如 myorg.example.com。

建立參照 DNS 授權的 Google 代管憑證

如要建立 Google 代管憑證,並參照您在先前步驟中建立的 DNS 授權,請按照下列步驟操作:

控制台

  1. 前往 Google Cloud 控制台的「Certificate Manager」頁面。

    前往「Certificate Manager」

  2. 在「憑證」分頁中,按一下「新增憑證」。

  3. 在「Certificate name」(憑證名稱) 欄位中,輸入憑證的專屬名稱。

  4. 選用:在「Description」(說明) 欄位中輸入憑證說明。說明可用於識別憑證。

  5. 在「位置」部分,選取「全域」。

  6. 在「Scope」(範圍) 中選取「Default」(預設值)。

  7. 在「Certificate type」(憑證類型) 部分,選取「Create Google-managed certificate」(建立 Google 代管的憑證)。

  8. 在「Certificate Authority type」(憑證授權單位類型) 部分,選取「Public」(公開)。

  9. 在「Domain Names」(網域名稱) 欄位中,指定憑證的網域名稱清單,並以半形逗號分隔。每個網域名稱都必須是完整網域名稱,例如 myorg.example.com。網域名稱也可以是萬用字元網域名稱,例如 *.example.com。

  10. 在「Authorization type」(授權類型) 部分,選取「DNS authorization」(DNS 授權)。

    頁面會列出網域名稱的 DNS 授權。如果網域名稱沒有相關聯的 DNS 授權,請按照下列步驟建立:

    1. 按一下「Create missing DNS authorization」(建立缺少的 DNS 授權)。
    2. 在「DNS authorization name」(DNS 授權名稱) 欄位中,指定 DNS 授權的名稱。預設 DNS 授權類型為 FIXED_RECORD。如要獨立管理多項專案的憑證,請勾選「Per project authorization」(依專案授權) 核取方塊。
    3. 按一下「Create DNS authorization」(建立 DNS 授權)。
  11. 在「Labels」(標籤) 欄位中,指定要與憑證建立關聯的標籤。如要新增標籤,請按一下 「Add label」(新增標籤),然後指定標籤的鍵和值。

  12. 點選「建立」。

    新的憑證會顯示在憑證清單中。

gcloud

如要建立具備 DNS 授權的全域 Google 代管憑證,請執行 certificate-manager certificates create 指令並加上 dns-authorizations 旗標:

gcloud certificate-manager certificates create CERTIFICATE_NAME \
    --domains="DOMAIN_NAME,*.DOMAIN_NAME" \
    --dns-authorizations="AUTHORIZATION_NAMES"

更改下列內容:

  • CERTIFICATE_NAME:憑證名稱。
  • DOMAIN_NAME:目標網域的名稱。網域名稱必須是完整網域名稱 (例如 myorg.example.com) 或萬用字元網域 (例如 *.myorg.example.com)。星號點前置字元 (*.) 代表萬用字元憑證。
  • AUTHORIZATION_NAMES:以半形逗號分隔的清單,列出您為憑證建立的 DNS 授權名稱。

Terraform

使用 google_certificate_manager_certificate 資源。

resource "google_certificate_manager_certificate" "root_cert" {
  name        = "${local.name}-rootcert-${random_id.tf_prefix.hex}"
  description = "The wildcard cert"
  managed {
    domains = [local.domain, "*.${local.domain}"]
    dns_authorizations = [
      google_certificate_manager_dns_authorization.default.id
    ]
  }
  labels = {
    "terraform" : true
  }
}

API

如要建立憑證,請向 certificates.create 方法發出 POST 要求,如下所示:

POST /v1/projects/PROJECT_ID/locations/global/certificates?certificate_id=CERTIFICATE_NAME
{
 "managed": {
  "domains": ["DOMAIN_NAME"],
  "dnsAuthorizations": [
   "projects/PROJECT_ID/locations/global/dnsAuthorizations/AUTHORIZATION_NAME",
  ],
 }
}

更改下列內容:

  • PROJECT_ID: Google Cloud 專案 ID。
  • CERTIFICATE_NAME:憑證名稱。
  • DOMAIN_NAME:目標網域的名稱。網域名稱必須是完整網域名稱 (例如 myorg.example.com) 或萬用字元網域 (例如 *.myorg.example.com)。星號點前置字元 (*.) 代表萬用字元憑證。
  • AUTHORIZATION_NAMES:以半形逗號分隔的 DNS 授權名稱清單。

在 DNS 設定中新增 CNAME 記錄

如果您使用第三方 DNS 解決方案管理 DNS,請參閱相關說明文件,瞭解如何將 CNAME 記錄新增至 DNS 設定。如果您使用Google Cloud 管理 DNS,請完成本節中的步驟。

控制台

如要建立記錄集,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「DNS zones」(DNS 區域) 頁面。

    前往 Cloud DNS 區域

  2. 按一下要新增記錄的 DNS 區域名稱。

  3. 在「Zone details」(區域詳細資料) 頁面中,按一下「Add standard」(新增標準)。

  4. 在「Create record set」(建立記錄集) 頁面的「DNS Name」(DNS 名稱) 欄位中,輸入 DNS 區域的子網域。

    輸入子網域名稱時,請確認子網域名稱 (包括「DNS name」(DNS 名稱) 欄位中顯示的灰色文字) 與gcloud certificate-manager dns-authorizations describe 指令輸出中顯示的 dnsResourceRecord.name 欄位完整值相符。

    請參閱以下例子:

    • 如果 dnsResourceRecord.name 欄位值為 _acme-challenge.myorg.example.com.,且「DNS name」(DNS 名稱) 欄位中的灰色文字為 .example.com.,請輸入 _acme-challenge.myorg。

    • 如果 dnsResourceRecord.name 欄位值為 _acme-challenge.myorg.example.com.,且「DNS name」(DNS 名稱) 欄位中的灰色文字為 .myorg.example.com.,請輸入 _acme-challenge。

    • 如果 dnsResourceRecord.name 欄位的值為 _acme-challenge_ujmmovf2vn55tgye.myorg.example.com.,且「DNS name」(DNS 名稱) 欄位中的灰色文字為 .myorg.example.com.,請輸入 _acme-challenge_ujmmovf2vn55tgye。

  5. 在「Resource record type」(資源記錄類型) 欄位中,選取「CNAME」。

  6. 在「TTL」(存留時間)TTL 欄位中,輸入資源記錄存留時間的正數值,也就是記錄可快取的時間。

  7. 從「TTL unit」(存留時間單位) 清單中選取時間單位,例如 30 minutes。

  8. 在「Canonical name」(標準名稱) 欄位中,輸入 dnsResourceRecord.data 欄位的完整值,如 gcloud certificate-manager dns-authorizations describe 指令的輸出內容所示。

  9. 如要輸入其他資訊,請按一下「Add item」(新增項目)。

  10. 點按「Create」(建立)。

gcloud

建立 DNS 授權時,gcloud CLI 指令會傳回對應的 CNAME 記錄。如要在目標網域的 DNS 區域中,將 CNAME 記錄新增至 DNS 設定,請按照下列步驟操作:

  1. 啟動 DNS 記錄交易:

    gcloud dns record-sets transaction start --zone="DNS_ZONE_NAME"
    

    將 DNS_ZONE_NAME 替換為目標 DNS 區域名稱。

  2. 將 CNAME 記錄新增至目標 DNS 區域:

    gcloud dns record-sets transaction add CNAME_RECORD \
        --name="VALIDATION_SUBDOMAIN_NAME.DOMAIN_NAME." \
        --ttl="30" \
        --type="CNAME" \
        --zone="DNS_ZONE_NAME"
    

    更改下列內容:

    • CNAME_RECORD:Google Cloud CLI 指令傳回的 CNAME 記錄完整資料值,該指令建立了對應的 DNS 授權。
    • VALIDATION_SUBDOMAIN_NAME:DNS 區域的前置字元子網域,例如 _acme-challenge。您可以從 gcloud certificate-manager dns-authorizations describe 指令記錄複製名稱,詳情請參閱「建立 DNS 授權」。
    • DOMAIN_NAME:目標網域的名稱。網域名稱必須是完整網域名稱,例如 myorg.example.com。目標網域名稱後方也必須加上半形句號。
    • DNS_ZONE_NAME:目標 DNS 區域的名稱。

    如要進一步瞭解 FIXED_RECORD 和 PER_PROJECT_RECORD DNS 授權之間的差異,請參閱下列範例。這兩個範例唯一的差異在於 --name 旗標的值。

    FIXED_RECORD DNS 授權

    gcloud dns record-sets transaction add 0e40fc77-a37d-4eb8-8fe1-eea2e18d12d9.4.authorize.certificatemanager.goog. \
        --name="_acme-challenge.myorg.example.com." \
        --ttl="30" \
        --type="CNAME" \
        --zone="myorg-example-com"
    

    PER_PROJECT_RECORD DNS 授權

    gcloud dns record-sets transaction add 0e40fc77-a37d-4eb8-8fe1-eea2e18d12d9.4.authorize.certificatemanager.goog. \
        --name="_acme-challenge_ujmmovf2vn55tgye.myorg.example.com." \
        --ttl="30" \
        --type="CNAME" \
        --zone="myorg-example-com"
    
  3. 執行 DNS 記錄交易,儲存變更:

    gcloud dns record-sets transaction execute --zone="DNS_ZONE_NAME"
    

    將 DNS_ZONE_NAME 替換為目標 DNS 區域名稱。

Terraform

如要將 CNAME 記錄新增至 DNS 設定,您可以使用 google_dns_record_set 資源。

resource "google_dns_record_set" "cname" {
  name         = google_certificate_manager_dns_authorization.default.dns_resource_record[0].name
  managed_zone = google_dns_managed_zone.default.name
  type         = google_certificate_manager_dns_authorization.default.dns_resource_record[0].type
  ttl          = 300
  rrdatas      = [google_certificate_manager_dns_authorization.default.dns_resource_record[0].data]
}

驗證憑證狀態

將憑證部署至負載平衡器之前,請先確認憑證已啟用。憑證狀態可能需要幾分鐘才會變更為 ACTIVE。

控制台

  1. 前往 Google Cloud 控制台的「Certificate Manager」頁面。

    前往「Certificate Manager」

  2. 在「Certificates」(憑證) 分頁中,查看憑證的「Status」(狀態) 欄。

gcloud

如要確認憑證狀態,請執行下列指令:

gcloud certificate-manager certificates describe CERTIFICATE_NAME

將 CERTIFICATE_NAME 替換為目標 Google 代管憑證的名稱。

輸出結果會與下列內容相似:

createTime: '2021-10-20T12:19:53.370778666Z'
expireTime: '2022-05-07T05:03:49Z'
managed:
  authorizationAttemptInfo:
  - domain: myorg.example.com
    state: AUTHORIZED
  dnsAuthorizations:
    - projects/myProject/locations/global/dnsAuthorizations/myCert
  domains:
  - myorg.example.com
  state: ACTIVE
name: projects/myProject/locations/global/certificates/myCert
pemCertificate: |
  -----BEGIN CERTIFICATE-----
  [...]
  -----END CERTIFICATE-----
sanDnsnames:
  -   myorg.example.com
updateTime: '2021-10-20T12:19:55.083385630Z'

如果憑證狀態在幾小時後仍未變成 ACTIVE,請確認您已正確將 CNAME 記錄新增至 DNS 設定。

如需更多疑難排解步驟,請參閱「排解 Certificate Manager 問題」。

將憑證部署至負載平衡器

如要部署全域 Google 代管憑證,請使用憑證對應組合部署憑證。

建立憑證對應組合

建立憑證對應組合,參照與憑證相關聯的憑證對應關係項目:

gcloud

如要建立憑證對應組合,請使用 gcloud certificate-manager maps create 指令:

gcloud certificate-manager maps create CERTIFICATE_MAP_NAME

將 CERTIFICATE_MAP_NAME 替換為目標憑證對應組合的名稱。

Terraform

如要建立憑證對應組合,可以使用 google_certificate_manager_certificate_map 資源。

resource "google_certificate_manager_certificate_map" "certificate_map" {
  name        = "${local.name}-certmap-${random_id.tf_prefix.hex}"
  description = "${local.domain} certificate map"
  labels = {
    "terraform" : true
  }
}

建立憑證對應關係

建立憑證對應關係,並與憑證和憑證對應組合建立關聯:

gcloud

如要建立憑證對應關係,請使用 gcloud certificate-manager maps entries create 指令:

gcloud certificate-manager maps entries create CERTIFICATE_MAP_ENTRY_NAME \
    --map="CERTIFICATE_MAP_NAME" \
    --certificates="CERTIFICATE_NAME" \
    --hostname="HOSTNAME"

更改下列內容:

  • CERTIFICATE_MAP_ENTRY_NAME:憑證對應項目名稱。
  • CERTIFICATE_MAP_NAME:與憑證對應關係相關聯的憑證對應組合名稱。
  • CERTIFICATE_NAME:要與憑證對應關係建立關聯的憑證名稱。
  • HOSTNAME:要與憑證對應關係建立關聯的主機名稱。

    如要建立涵蓋萬用字元網域和根網域的憑證,請指定含有根網域和萬用字元的主機名稱,例如 example.com 和 *.example.com。此外,您必須指定兩個憑證對應關係,一個用於 example.com,另一個用於 *.example.com。

Terraform

如要建立具有根網域的憑證對應關係,請使用 google_certificate_manager_certificate_map_entry 資源。

resource "google_certificate_manager_certificate_map_entry" "first_entry" {
  name        = "${local.name}-first-entry-${random_id.tf_prefix.hex}"
  description = "example certificate map entry"
  map         = google_certificate_manager_certificate_map.certificate_map.name
  labels = {
    "terraform" : true
  }
  certificates = [google_certificate_manager_certificate.root_cert.id]
  hostname     = local.domain
}

如要建立含有萬用字元網域的憑證對應關係,請使用 google_certificate_manager_certificate_map_entry 資源。

resource "google_certificate_manager_certificate_map_entry" "second_entry" {
  name        = "${local.name}-second-entity-${random_id.tf_prefix.hex}"
  description = "example certificate map entry"
  map         = google_certificate_manager_certificate_map.certificate_map.name
  labels = {
    "terraform" : true
  }
  certificates = [google_certificate_manager_certificate.root_cert.id]
  hostname     = "*.${local.domain}"
}

確認憑證對應關係已啟用

將對應的憑證對應組合附加至目標 Proxy 之前,請先確認憑證對應關係已啟用。

如要驗證憑證對應關係,請使用 gcloud certificate-manager maps entries describe 指令:

gcloud certificate-manager maps entries describe CERTIFICATE_MAP_ENTRY_NAME \
    --map="CERTIFICATE_MAP_NAME"

更改下列內容:

  • CERTIFICATE_MAP_ENTRY_NAME:憑證對應項目名稱。
  • CERTIFICATE_NAME:要與憑證對應關係建立關聯的憑證名稱。

輸出結果會與下列內容相似:

certificates:
createTime: '2021-09-06T10:01:56.229472109Z'
hostname: example.com
name: projects/my-project/locations/global/certificateMaps/myCertMap/certificateMapEntries/myCertMapEntry
state: ACTIVE
updateTime: '2021-09-06T10:01:58.277031787Z'

將憑證對應組合附加至目標 Proxy

您可以將憑證對應組合附加至新的或現有的目標 Proxy。

控制台

如果目標 Proxy 屬於現有負載平衡器,您可以編輯負載平衡器的前端設定,附加憑證對應組合。

  1. 前往 Google Cloud 控制台的「Load balancing」(負載平衡) 頁面。

    前往「Load balancing」(負載平衡)

  2. 按一下要更新的負載平衡器名稱,然後點選「Edit」(編輯)。

  3. 按一下「Frontend configuration」(前端設定),然後選取要編輯的前端 IP 位址和通訊埠設定。

  4. 如果畫面上顯示「Choose certificate repository」(選擇憑證存放區),請選取「Use certificate map」(使用憑證對應關係)。

  5. 在「Select a certificate map」(選取憑證對應組合) 清單中,選取憑證對應組合。

  6. 按一下「Done」(完成),然後按一下「Update」(更新)。

gcloud

如要將憑證對應組合附加至新的目標 Proxy,請使用 gcloud compute target-https-proxies create 指令:

gcloud compute target-https-proxies create PROXY_NAME \
    --certificate-map="CERTIFICATE_MAP_NAME" \
    --url-map="URL_MAP" \
    --global

更改下列內容:

  • PROXY_NAME:目標 Proxy 的名稱。
  • CERTIFICATE_MAP_NAME:參照憑證對應關係和相關聯憑證的憑證對應組合名稱。
  • URL_MAP:網址對應的名稱

如要將憑證對應組合附加至現有的目標 HTTPS Proxy,請使用 gcloud compute target-https-proxies update 指令。如果您不知道現有目標 Proxy 的名稱,請前往「Target proxies」(目標 Proxy) 頁面,記下目標 Proxy 的名稱。

gcloud compute target-https-proxies update PROXY_NAME \
    --certificate-map="CERTIFICATE_MAP_NAME" \
    --global

建立或更新目標 Proxy 後,請執行下列指令進行驗證:

gcloud compute target-https-proxies list

Terraform

如要將憑證對應組合附加至目標 Proxy,可以使用 google_compute_target_https_proxy 資源。

設定目標 Proxy 時,如果您直接附加 TLS (SSL) 憑證,同時也透過憑證對應組合附加,Proxy 會使用憑證對應組合參照的憑證,並忽略直接附加的 TLS (SSL) 憑證。

清除所用資源

如要避免系統向您的 Google Cloud 帳戶收取這個教學課程所用資源的費用,請刪除這些資源。

  1. 刪除負載平衡器及其資源。

    請參閱「清除負載平衡設定」。

  2. 刪除憑證對應組合,或將其與 Proxy 卸離。

    如要刪除憑證對應組合,請執行下列指令:

    gcloud compute target-https-proxies delete PROXY_NAME
    

    如要保留目標 HTTPS Proxy,請將憑證對應組合與 Proxy 卸離。

    • 如果 Proxy 直接附加任何 TLS (SSL) 憑證,則卸載憑證對應組合會導致 Proxy 繼續使用這些直接附加的 TLS (SSL) 憑證。
    • 如果沒有直接附加至 Proxy 的 TLS (SSL) 憑證,就無法從 Proxy 卸載憑證對應組合。您必須先將至少一個 TLS (SSL) 憑證直接附加至 Proxy,才能卸載憑證對應組合。

    如要卸載憑證對應組合,請執行下列指令:

    gcloud compute target-https-proxies update PROXY_NAME \
        --clear-certificate-map
    

    將 PROXY_NAME 替換為目標 Proxy 的名稱。

  3. 從憑證對應組合中刪除憑證對應關係:

    gcloud certificate-manager maps entries delete CERTIFICATE_MAP_ENTRY_NAME \
        --map="CERTIFICATE_MAP_NAME"
    

    更改下列內容:

    • CERTIFICATE_MAP_ENTRY_NAME:憑證對應項目名稱。
    • CERTIFICATE_MAP_NAME:憑證對應組合的名稱。
  4. 刪除憑證對應組合:

    gcloud certificate-manager maps delete CERTIFICATE_MAP_NAME
    

    將 CERTIFICATE_MAP_NAME 替換為憑證對應組合的名稱。

  5. 刪除 Google 代管的憑證:

    控制台

    1. 前往 Google Cloud 控制台的「Certificate Manager」頁面。

      前往「Certificate Manager」

    2. 在「憑證」分頁中,勾選憑證的核取方塊。

    3. 點選「刪除」。

    4. 在出現的對話方塊中,按一下 [Delete] (刪除) 以進行確認。

    gcloud

    gcloud certificate-manager certificates delete CERTIFICATE_NAME
    

    將 CERTIFICATE_NAME 替換為目標憑證名稱。

  6. 刪除 DNS 授權:

    gcloud certificate-manager dns-authorizations delete AUTHORIZATION_NAME
    

    將 AUTHORIZATION_NAME 替換為 DNS 授權名稱。

後續步驟