下位認証局の作成

このページでは、CA プールに下位認証局(CA)を作成する方法について説明します。

下位 CA は、ユーザー、コンピュータ、デバイスなどのエンド エンティティに直接証明書を発行します。下位 CA は、親 CA(多くの場合ルート CA)によって暗号で署名されます。その結果、ルート CA を信頼するシステムは、下位 CA と下位 CA が発行するエンド エンティティ証明書を自動的に信頼します。

準備

  • CA Service オペレーション マネージャー(roles/privateca.caManager)または CA Service 管理者(roles/privateca.admin)の IAM ロールがあることを確認します。詳細については、IAM ポリシーの構成をご覧ください。
  • CA プールを作成します
  • ルート CA を選択します。

下位 CA を作成する

下位 CA は、ルート CA よりも取り消しやローテーションが簡単です。証明書の発行シナリオが複数ある場合は、シナリオごとに下位 CA を作成できます。複数の下位 CA を CA プールに追加すると、証明書リクエストのロード バランシングを改善し、有効 QPS の合計をより高い値で達成できます。

下位 CA を作成するには、次の手順を行います。

コンソール

  1. Google Cloud コンソールの [Certificate Authority Service] ページに移動します。

    Certificate Authority Service に移動

  2. [CA マネージャー] タブをクリックします。

  3. [CA を作成] をクリックします。

    Google Cloud コンソールを使用して CA を作成します。

CA タイプの選択

  1. [下位 CA] をクリックします。
  2. [ルート CA は Google Cloud 内] をクリックします。
  3. [有効期間] フィールドに、CA 証明書の有効期間を入力します。
  4. 省略可: CA のティアを選択します。デフォルトのティアは Enterprise です。詳細については、オペレーション階層を選択するをご覧ください。
  5. [リージョン] をクリックして、CA のロケーションを選択します。詳細については、ロケーションをご覧ください。
  6. 省略可: [初期化された状態] で、CA の作成時に設定する必要がある状態を選択します。
  7. 省略可: [発行シナリオの設定] で [証明書プロファイル] をクリックし、要件に最適な証明書プロファイルをリストから選択します。詳細については、証明書プロファイルをご覧ください。
  8. [次へ] をクリックします。
CA サブジェクト名を構成する
  1. [組織(O)] フィールドに、組織の名前を入力します。
  2. 省略可: [組織部門(OU)] フィールドに、会社の部門またはビジネス ユニットを入力します。
  3. 省略可: [国名] フィールドに、2 文字の国コードを入力します。
  4. 省略可: [州または省名] フィールドに、州名を入力します。
  5. 省略可: [地域名] フィールドに、都市の名前を入力します。
  6. [CA 共通名(CN)] フィールドに、CA 名を入力します。
  7. [プール ID] フィールドに、CA プールの名前を入力します。CA の作成後に CA プールを変更することはできません。
  8. [次へ] をクリックします。
CA の鍵サイズとアルゴリズムを構成する
  1. ニーズに最適な鍵アルゴリズムを選択します。適切な鍵アルゴリズムを決定する方法については、鍵アルゴリズムを選択するをご覧ください。
  2. [次へ] をクリックします。
CA アーティファクトを構成する

次の手順は省略可能です。この手順をスキップすると、デフォルト設定が適用されます。

  1. Google 管理またはセルフマネージドの Cloud Storage バケットのどちらを使用するかを選択します。
  2. セルフマネージド Cloud Storage バケットを選択しない場合、CA Service は CA と同じロケーションに Google 管理バケットを作成します。

  3. Cloud Storage バケットへの証明書失効リスト(CRL)と CA 証明書の公開を無効にするかどうかを選択します。
  4. Cloud Storage バケットでの CRL と CA 証明書の公開は、デフォルトで有効になっています。これらの設定を無効にするには、切り替えボタンをクリックします。

  5. [次へ] をクリックします。
ラベルを追加する

次の手順は省略可能です。

CA にラベルを追加する場合は、次の手順を行います。

  1. [項目を追加] をクリックします。
  2. [キー 1] フィールドにラベルキーを入力します。
  3. [値 1] フィールドにラベルの値を入力します。
  4. 別のラベルを追加する場合は、 [項目を追加] をクリックします。次に、手順 2 と 3 で説明したように、ラベルキーと値を追加します。
  5. [次へ] をクリックします。
設定を確認する

すべての設定をよく確認し、[作成] をクリックして CA を作成します。

gcloud

  1. 下位 CA の CA プールを作成します。

    gcloud privateca pools create SUBORDINATE_POOL_ID
    

    SUBORDINATE_POOL_ID を、CA プールの名前に置き換えます。

    CA プールの作成の詳細については、CA プールの作成をご覧ください。

    gcloud privateca pools create コマンドの詳細については、gcloud privateca pools create をご覧ください。

  2. 作成した CA プールに下位 CA を作成します。

    gcloud privateca subordinates create SUBORDINATE_CA_ID \
      --pool=SUBORDINATE_POOL_ID \
      --issuer-pool=POOL_ID \
      --key-algorithm="ec-p256-sha256" \
      --subject="CN=Example Server TLS CA, O=Example LLC"
    

    下位 CA を作成すると、次のステートメントが返されます。

    Created Certificate Authority [projects/my-project-pki/locations/us-west1/caPools/SUBORDINATE_POOL_ID/certificateAuthorities/SUBORDINATE_CA_ID].
    

    すべてを網羅した設定のリストを表示するには、次の gcloud コマンドを実行します。

    gcloud privateca subordinates create --help
    

    このコマンドは、発行元が CA Service 上に配置されているか、別の場所に配置されている下位 CA を作成する例を返します。

Terraform

resource "google_privateca_certificate_authority" "root_ca" {
  pool                                   = "my-pool"
  certificate_authority_id               = "my-certificate-authority-root"
  location                               = "us-central1"
  deletion_protection                    = false # set to true to prevent destruction of the resource
  ignore_active_certificates_on_deletion = true
  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_authority" "default" {
  // This example assumes this pool already exists.
  // Pools cannot be deleted in normal test circumstances, so we depend on static pools
  pool                     = "my-pool"
  certificate_authority_id = "my-certificate-authority-sub"
  location                 = "us-central1"
  deletion_protection      = false # set to true to prevent destruction of the resource
  subordinate_config {
    certificate_authority = google_privateca_certificate_authority.root_ca.name
  }
  config {
    subject_config {
      subject {
        organization = "HashiCorp"
        common_name  = "my-subordinate-authority"
      }
      subject_alt_name {
        dns_names = ["hashicorp.com"]
      }
    }
    x509_config {
      ca_options {
        is_ca = true
        # Force the sub CA to only issue leaf certs
        max_issuer_path_length = 0
      }
      key_usage {
        base_key_usage {
          digital_signature  = true
          content_commitment = true
          key_encipherment   = false
          data_encipherment  = true
          key_agreement      = true
          cert_sign          = true
          crl_sign           = true
          decipher_only      = true
        }
        extended_key_usage {
          server_auth      = true
          client_auth      = false
          email_protection = true
          code_signing     = true
          time_stamping    = true
        }
      }
    }
  }
  lifetime = "86400s"
  key_spec {
    algorithm = "RSA_PKCS1_4096_SHA256"
  }
  type = "SUBORDINATE"
}

Java

CA Service への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。


import com.google.api.core.ApiFuture;
import com.google.cloud.security.privateca.v1.CaPoolName;
import com.google.cloud.security.privateca.v1.CertificateAuthority;
import com.google.cloud.security.privateca.v1.CertificateAuthority.KeyVersionSpec;
import com.google.cloud.security.privateca.v1.CertificateAuthority.SignHashAlgorithm;
import com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient;
import com.google.cloud.security.privateca.v1.CertificateConfig;
import com.google.cloud.security.privateca.v1.CertificateConfig.SubjectConfig;
import com.google.cloud.security.privateca.v1.CreateCertificateAuthorityRequest;
import com.google.cloud.security.privateca.v1.KeyUsage;
import com.google.cloud.security.privateca.v1.KeyUsage.KeyUsageOptions;
import com.google.cloud.security.privateca.v1.Subject;
import com.google.cloud.security.privateca.v1.SubjectAltNames;
import com.google.cloud.security.privateca.v1.X509Parameters;
import com.google.cloud.security.privateca.v1.X509Parameters.CaOptions;
import com.google.longrunning.Operation;
import com.google.protobuf.Duration;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class CreateSubordinateCa {

  public static void main(String[] args)
      throws InterruptedException, ExecutionException, IOException {
    // TODO(developer): Replace these variables before running the sample.
    // location: For a list of locations, see:
    // https://cloud.google.com/certificate-authority-service/docs/locations
    // poolId: Set it to the CA Pool under which the CA should be created.
    // subordinateCaName: Unique name for the Subordinate CA.
    String project = "your-project-id";
    String location = "ca-location";
    String poolId = "ca-pool-id";
    String subordinateCaName = "subordinate-certificate-authority-name";

    createSubordinateCertificateAuthority(project, location, poolId, subordinateCaName);
  }

  public static void createSubordinateCertificateAuthority(
      String project, String location, String poolId, String subordinateCaName)
      throws IOException, ExecutionException, InterruptedException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `certificateAuthorityServiceClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient =
        CertificateAuthorityServiceClient.create()) {

      String commonName = "commonname";
      String orgName = "csr-org-name";
      String domainName = "dns.example.com";
      int caDuration = 100000; // Validity of this CA in seconds.

      // Set the type of Algorithm.
      KeyVersionSpec keyVersionSpec =
          KeyVersionSpec.newBuilder().setAlgorithm(SignHashAlgorithm.RSA_PKCS1_4096_SHA256).build();

      // Set CA subject config.
      SubjectConfig subjectConfig =
          SubjectConfig.newBuilder()
              .setSubject(
                  Subject.newBuilder().setCommonName(commonName).setOrganization(orgName).build())
              // Set the fully qualified domain name.
              .setSubjectAltName(SubjectAltNames.newBuilder().addDnsNames(domainName).build())
              .build();

      //  Set the key usage options for X.509 fields.
      X509Parameters x509Parameters =
          X509Parameters.newBuilder()
              .setKeyUsage(
                  KeyUsage.newBuilder()
                      .setBaseKeyUsage(
                          KeyUsageOptions.newBuilder().setCrlSign(true).setCertSign(true).build())
                      .build())
              .setCaOptions(CaOptions.newBuilder().setIsCa(true).build())
              .build();

      // Set certificate authority settings.
      CertificateAuthority subCertificateAuthority =
          CertificateAuthority.newBuilder()
              .setType(CertificateAuthority.Type.SUBORDINATE)
              .setKeySpec(keyVersionSpec)
              .setConfig(
                  CertificateConfig.newBuilder()
                      .setSubjectConfig(subjectConfig)
                      .setX509Config(x509Parameters)
                      .build())
              // Set the CA validity duration.
              .setLifetime(Duration.newBuilder().setSeconds(caDuration).build())
              .build();

      // Create the CertificateAuthorityRequest.
      CreateCertificateAuthorityRequest subCertificateAuthorityRequest =
          CreateCertificateAuthorityRequest.newBuilder()
              .setParent(CaPoolName.of(project, location, poolId).toString())
              .setCertificateAuthorityId(subordinateCaName)
              .setCertificateAuthority(subCertificateAuthority)
              .build();

      // Create Subordinate CA.
      ApiFuture<Operation> futureCall =
          certificateAuthorityServiceClient
              .createCertificateAuthorityCallable()
              .futureCall(subCertificateAuthorityRequest);

      Operation response = futureCall.get();

      if (response.hasError()) {
        System.out.println("Error while creating Subordinate CA !" + response.getError());
        return;
      }

      System.out.println(
          "Subordinate Certificate Authority created successfully : " + subordinateCaName);
    }
  }
}

Python

CA Service への認証を行うには、アプリケーションのデフォルト認証情報を設定します。 詳細については、ローカル開発環境の認証の設定をご覧ください。

import google.cloud.security.privateca_v1 as privateca_v1
from google.protobuf import duration_pb2

def create_subordinate_ca(
    project_id: str,
    location: str,
    ca_pool_name: str,
    subordinate_ca_name: str,
    common_name: str,
    organization: str,
    domain: str,
    ca_duration: int,
) -> None:
    """
    Create Certificate Authority (CA) which is the subordinate CA in the given CA Pool.
    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        location: location you want to use. For a list of locations, see: https://cloud.google.com/certificate-authority-service/docs/locations.
        ca_pool_name: set it to the CA Pool under which the CA should be created.
        subordinate_ca_name: unique name for the Subordinate CA.
        common_name: a title for your certificate authority.
        organization: the name of your company for your certificate authority.
        domain: the name of your company for your certificate authority.
        ca_duration: the validity of the certificate authority in seconds.
    """

    ca_service_client = privateca_v1.CertificateAuthorityServiceClient()

    # Set the type of Algorithm
    key_version_spec = privateca_v1.CertificateAuthority.KeyVersionSpec(
        algorithm=privateca_v1.CertificateAuthority.SignHashAlgorithm.RSA_PKCS1_4096_SHA256
    )

    # Set CA subject config.
    subject_config = privateca_v1.CertificateConfig.SubjectConfig(
        subject=privateca_v1.Subject(
            common_name=common_name, organization=organization
        ),
        # Set the fully qualified domain name.
        subject_alt_name=privateca_v1.SubjectAltNames(dns_names=[domain]),
    )

    # Set the key usage options for X.509 fields.
    x509_parameters = privateca_v1.X509Parameters(
        key_usage=privateca_v1.KeyUsage(
            base_key_usage=privateca_v1.KeyUsage.KeyUsageOptions(
                crl_sign=True,
                cert_sign=True,
            )
        ),
        ca_options=privateca_v1.X509Parameters.CaOptions(
            is_ca=True,
        ),
    )

    # Set certificate authority settings.
    certificate_authority = privateca_v1.CertificateAuthority(
        type_=privateca_v1.CertificateAuthority.Type.SUBORDINATE,
        key_spec=key_version_spec,
        config=privateca_v1.CertificateConfig(
            subject_config=subject_config,
            x509_config=x509_parameters,
        ),
        # Set the CA validity duration.
        lifetime=duration_pb2.Duration(seconds=ca_duration),
    )

    ca_pool_path = ca_service_client.ca_pool_path(project_id, location, ca_pool_name)

    # Create the CertificateAuthorityRequest.
    request = privateca_v1.CreateCertificateAuthorityRequest(
        parent=ca_pool_path,
        certificate_authority_id=subordinate_ca_name,
        certificate_authority=certificate_authority,
    )

    operation = ca_service_client.create_certificate_authority(request=request)
    result = operation.result()

    print(f"Operation result: {result}")

下位 CA を有効にする

下位 CA を有効にするには、次の手順を行います。

コンソール

  1. Google Cloud コンソールの [Certificate Authority Service] ページに移動します。

    Certificate Authority Service に移動

  2. [CA マネージャー] タブをクリックします。

  3. [認証局] で、有効にする CA を選択します。

  4. [有効にする] をクリックします。

  5. 表示されたダイアログで [CSR をダウンロード] をクリックして、発行 CA が署名できる PEM でエンコードされた CSR ファイルをダウンロードします。

  6. [次へ] をクリックします。

  7. [証明書チェーンをアップロード] フィールドで、[ブラウジング] をクリックします。

  8. 拡張子が .crt の署名付き証明書ファイルをアップロードします。

  9. [Activate] をクリックします。

gcloud

新しく作成した下位 CA を有効にするには、次のコマンドを実行します。

gcloud privateca subordinates enable SUBORDINATE_CA_ID --pool=SUBORDINATE_POOL_ID

次のように置き換えます。

  • SUBORDINATE_CA_ID: 下位 CA の一意の識別子。
  • SUBORDINATE_POOL_ID: 下位 CA を含む CA プールの名前。

gcloud privateca subordinates enable コマンドの詳細については、gcloud privateca subordinates enable をご覧ください。

Terraform

下位 CA の desired_state フィールドを ENABLED に設定し、terraform apply を実行します。

次のステップ