使用憑證範本要求憑證

本頁說明如何使用憑證範本要求憑證。

憑證範本可讓您對憑證核發作業實作精細的政策控管。舉例來說,您可以使用憑證範本,在貴機構的 CA 集區中,統一核發伺服器 TLS 憑證。您也可以使用憑證範本,在更精細的層級套用政策,例如套用至特定使用者。如果您需要限制不同人員可核發的認證類型,這個做法就非常實用。您也可以重複使用常見核發情境的範本。

事前準備

  1. 準備 CA 服務環境

  2. 如要取得使用憑證範本核發憑證所需的權限,請要求管理員在憑證範本上授予您「CA 服務憑證範本使用者」(roles/privateca.templateUser) IAM 角色。

    如要進一步瞭解 CA 服務的預先定義 IAM 角色,請參閱「使用身分與存取權管理功能控管存取權」一文。

    如要瞭解如何將 IAM 角色授予主體,請參閱「授予單一角色」。

測試憑證核發作業

使用憑證範本要求簽署憑證前,建議您先驗證憑證範本是否能順利產生憑證。如果 CA 集區的核發政策與憑證範本的政策有衝突,憑證核發就會失敗。透過測試核發程序,您可以主動找出並解決這些衝突。請注意,測試憑證並非 PEM 編碼,且未簽署,產生時不會產生任何費用。

如要使用憑證範本測試憑證核發作業,請按照下列步驟操作:

控制台

  1. 前往 Google Cloud 控制台的「憑證授權單位服務」頁面。

    前往憑證授權單位服務

  2. 按一下「範本管理工具」分頁標籤。

  3. 按一下要測試的認證範本。 「範本詳細資料」頁面隨即顯示。

  4. 如要建立測試要求,請按一下「建立憑證」,然後按一下「測試憑證核發」。系統會顯示憑證要求表單。

  5. 指定建立憑證要求時所需的下列詳細資料:

    • 區域:憑證位置。這必須與 CA 集區的位置相同。
    • CA 集區:負責核發憑證的 CA 集區。
    • 憑證範本:您要用於核發憑證的範本。
    • 網域:要使用 SSL 或 TLS 憑證保護的網站網域名稱。
  6. 按一下「產生憑證」

  7. 建立憑證後,請按一下「查看」。測試或樣本認證會顯示在同一頁面的另一個面板中。

  8. 如果因衝突而無法核發憑證,請解決衝突,然後再次提交測試憑證要求。

使用憑證範本核發憑證

如要使用憑證範本核發已簽署的憑證,請按照下列步驟操作:

控制台

  1. 前往 Google Cloud 控制台的「憑證授權單位服務」頁面。

    前往憑證授權單位服務}

  2. 按一下「範本管理工具」分頁標籤。

  3. 在「認證範本」頁面中,按一下要使用的認證範本。 「範本詳細資料」頁面隨即顯示。

  4. 按一下 [建立憑證]

  5. 選取所需區域。這個區域必須與您要使用的 CA 集區區域相同。

  6. 選取 CA 集區。

  7. 如要使用憑證簽署要求 (CSR) 產生憑證,請參閱「使用 CSR 申請憑證」。

  8. 如要使用自動產生的金鑰產生憑證,請參閱「使用自動產生的金鑰申請憑證」。

產生憑證

  1. 按一下「產生憑證」。如果憑證產生成功,系統會顯示訊息。
  2. 如要查看產生的憑證,請按一下「查看憑證」,然後按一下「查看」

選用:下載簽署的憑證

  1. 如要下載 PEM 編碼憑證鏈結,請按一下「下載憑證鏈結」
  2. 如要下載相關聯的 PEM 編碼私密金鑰,請按一下「下載私密金鑰」

gcloud

如要使用憑證範本核發憑證,請在 gcloud privateca certificates create 指令中加入 --template 標記,格式如下:

--template=projects/PROJECT_ID/locations/LOCATION/certificateTemplates/CERTIFICATE_TEMPLATE

CERTIFICATE_TEMPLATE 替換為您要用於核發這項憑證的憑證範本名稱。指定的範本必須與核發 CA 集區位於相同位置。詳情請參閱產生測試 DNS 憑證產生正式版憑證的範例。

Terraform

/**
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

resource "google_privateca_certificate_template" "template" {
  location    = "us-central1"
  name        = "my-certificate-template"
  description = "An updated sample certificate template"

  identity_constraints {
    allow_subject_alt_names_passthrough = true
    allow_subject_passthrough           = true

    cel_expression {
      description = "Always true"
      expression  = "true"
      location    = "any.file.anywhere"
      title       = "Sample expression"
    }
  }

  passthrough_extensions {
    additional_extensions {
      object_id_path = [1, 6]
    }

    known_extensions = ["EXTENDED_KEY_USAGE"]
  }

  predefined_values {
    additional_extensions {
      object_id {
        object_id_path = [1, 6]
      }

      value    = "c3RyaW5nCg=="
      critical = true
    }

    aia_ocsp_servers = ["string"]

    ca_options {
      is_ca                  = false
      max_issuer_path_length = 6
    }

    key_usage {
      base_key_usage {
        cert_sign          = false
        content_commitment = true
        crl_sign           = false
        data_encipherment  = true
        decipher_only      = true
        digital_signature  = true
        encipher_only      = true
        key_agreement      = true
        key_encipherment   = true
      }

      extended_key_usage {
        client_auth      = true
        code_signing     = true
        email_protection = true
        ocsp_signing     = true
        server_auth      = true
        time_stamping    = true
      }

      unknown_extended_key_usages {
        object_id_path = [1, 6]
      }
    }

    policy_ids {
      object_id_path = [1, 6]
    }
  }
}

resource "google_privateca_certificate_authority" "test_ca" {
  pool                     = "my-pool"
  certificate_authority_id = "my-certificate-authority-test-ca"
  location                 = "us-central1"
  deletion_protection      = false # set to true to prevent destruction of the resource
  config {
    subject_config {
      subject {
        organization = "HashiCorp"
        common_name  = "my-certificate-authority"
      }
      subject_alt_name {
        dns_names = ["hashicorp.com"]
      }
    }
    x509_config {
      ca_options {
        # is_ca *MUST* be true for certificate authorities
        is_ca = true
      }
      key_usage {
        base_key_usage {
          # cert_sign and crl_sign *MUST* be true for certificate authorities
          cert_sign = true
          crl_sign  = true
        }
        extended_key_usage {
          server_auth = false
        }
      }
    }
  }
  key_spec {
    algorithm = "RSA_PKCS1_4096_SHA256"
  }
}


resource "google_privateca_certificate" "default" {
  pool                  = "my-pool"
  location              = "us-central1"
  certificate_authority = google_privateca_certificate_authority.test_ca.certificate_authority_id
  lifetime              = "860s"
  name                  = "my-certificate-from-template"
  pem_csr               = tls_cert_request.example.cert_request_pem
  certificate_template  = google_privateca_certificate_template.template.id
}

resource "tls_private_key" "example" {
  algorithm = "RSA"
}

resource "tls_cert_request" "example" {
  private_key_pem = tls_private_key.example.private_key_pem

  subject {
    common_name  = "example.com"
    organization = "ACME Examples, Inc"
  }
}

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

如果系統在 CA 集區的核發政策和憑證範本之間偵測到政策衝突,憑證要求可能會失敗。發生這種情況時,你必須先解決政策衝突,才能再次提交憑證要求。

如要與貴機構的其他使用者共用憑證要求表單連結,讓他們使用相同參數要求憑證,請按照下列步驟操作:

控制台

  1. 前往 Google Cloud 控制台的「CA pool manager」(CA 集區管理員) 分頁,然後按一下「Share request form link」(分享要求表單連結)
  2. 在隨即顯示的「分享要求表單連結」面板中,選取 CA 集區和您選擇用來建立要求的憑證範本。系統會顯示憑證要求連結。
  3. 複製連結並視需要分享。

查看使用範本核發的憑證

如要查看使用憑證範本核發的憑證,請按照下列步驟操作:

控制台

  1. 前往 Google Cloud 控制台的「範本管理工具」分頁。
  2. 按一下您用於核發憑證的憑證範本。
  3. 在「範本詳細資料」頁面中,按一下「憑證」。 系統會顯示使用所選憑證範本核發的憑證清單。

後續步驟