Untergeordnete Zertifizierungsstelle erstellen

Auf dieser Seite wird beschrieben, wie Sie untergeordnete Zertifizierungsstellen (CAs) in einem CA-Pool erstellen.

Untergeordnete Zertifizierungsstellen sind für die direkte Ausstellung von Zertifikaten an Endentitäten wie Nutzer, Computer und Geräte verantwortlich. Untergeordnete Zertifizierungsstellen werden kryptografisch von einer übergeordneten Zertifizierungsstelle signiert, die oft die Stammzertifizierungsstelle ist. Daher vertrauen Systeme, die der Root-CA vertrauen, automatisch den untergeordneten CAs und den End-Entity-Zertifikaten, die von den untergeordneten CAs ausgestellt werden.

Hinweis

  • Sie benötigen die IAM-Rolle „CA Service Operation Manager“ (roles/privateca.caManager) oder „CA Service Admin“ (roles/privateca.admin). Weitere Informationen finden Sie unter IAM-Richtlinien konfigurieren.
  • Erstellen Sie einen CA-Pool.
  • Wählen Sie Ihre Stamm-CA aus.
  • Wenn für den CA-Pool, der Ihre ausstellende Root-CA enthält, eine Zertifikatsausstellungsrichtlinie konfiguriert ist, prüfen Sie, ob die baselineValues das Ausstellen von CA-Zertifikaten caOptions.isCa: true, keyUsage.baseKeyUsage.certSign: true und keyUsage.baseKeyUsage.crlSign: true zulassen. Andernfalls schlägt die Aktivierung der untergeordneten Zertifizierungsstelle mit der Fehlermeldung Fields in the CSR were modified or removed in the signed CA certificate fehl.

Untergeordnete Zertifizierungsstelle erstellen

Untergeordnete Zertifizierungsstellen lassen sich einfacher widerrufen und rotieren als Stammzertifizierungsstellen. Wenn Sie mehrere Szenarien für die Zertifikatsausstellung haben, können Sie für jedes dieser Szenarien eine untergeordnete Zertifizierungsstelle erstellen. Wenn Sie einem CA-Pool mehrere untergeordnete Zertifizierungsstellen hinzufügen, können Sie ein besseres Load Balancing von Zertifikatsanfragen und eine höhere effektive Gesamtzahl von Abfragen pro Sekunde erreichen.

So erstellen Sie eine untergeordnete Zertifizierungsstelle:

Console

  1. Rufen Sie in derGoogle Cloud Console die Seite Certificate Authority Service auf.

    Zum Certificate Authority Service

  2. Klicken Sie auf den Tab CA-Manager.

  3. Klicken Sie auf CA erstellen.

    Erstellen Sie eine Zertifizierungsstelle mit der Cloud Console.

CA-Typ auswählen

  1. Klicken Sie auf Untergeordnete Zertifizierungsstelle.
  2. Klicken Sie auf Root CA is in Google Cloud (Stamm-CA befindet sich in Google Cloud).
  3. Geben Sie im Feld Gültig für die Dauer ein, für die das CA-Zertifikat gültig sein soll.
  4. Optional: Wählen Sie die Stufe für die Zertifizierungsstelle aus. Die Standardstufe ist Enterprise. Weitere Informationen finden Sie unter Vorgangsstufen auswählen.
  5. Klicken Sie auf Region, um einen Standort für die Zertifizierungsstelle auszuwählen. Weitere Informationen finden Sie unter Standorte.
  6. Optional: Wählen Sie unter Initialisierter Status den Betriebsstatus aus, in dem die Zertifizierungsstelle erstellt werden soll.
  7. Optional: Klicken Sie unter Ausstellungsszenario einrichten auf Zertifikatsprofil und wählen Sie das Zertifikatsprofil aus, das Ihren Anforderungen am besten entspricht. Weitere Informationen finden Sie unter Zertifikatsprofile.
  8. Klicken Sie auf Weiter.
CA-Antragstellername konfigurieren
  1. Optional: Geben Sie im Feld Organisation (O) den Namen Ihres Unternehmens ein.
  2. Optional: Geben Sie im Feld Organisationseinheit (OE) die Unternehmensuntergliederung oder Geschäftseinheit ein.
  3. Optional: Geben Sie im Feld Ländername (C) einen zweistelligen Ländercode ein.
  4. Optional: Geben Sie im Feld Bundesland oder Provinz den Namen Ihres Bundeslandes ein.
  5. Optional: Geben Sie im Feld Ortsname den Namen Ihrer Stadt ein.
  6. Geben Sie im Feld Allgemeiner CA-Name (CN) den CA-Namen ein.
  7. Klicken Sie auf Weiter.
CA-Schlüsselgröße und -Algorithmus konfigurieren
  1. Wählen Sie den Schlüsselalgorithmus aus, der Ihren Anforderungen am besten entspricht. Weitere Informationen zu den Optionen für Signaturschlüssel finden Sie unter CA-Signaturschlüssel konfigurieren.
  2. Wenn Sie einen vom Kunden verwalteten Signaturschlüssel verwenden möchten, wählen Sie Vom Kunden verwalteter Schlüssel aus und geben Sie die Version des kryptografischen Schlüssels des Cloud Key Management Service an.
  3. Klicken Sie auf Weiter.
CA-Artefakte konfigurieren
  1. Wählen Sie aus, ob Sie einen von Google verwalteten oder einen vom Kunden verwalteten Cloud Storage-Bucket verwenden möchten.
    1. Für einen von Google verwalteten Cloud Storage-Bucket erstellt CA Service einen von Google verwalteten Bucket am selben Standort wie die Zertifizierungsstelle.
    2. Klicken Sie für einen vom Kunden verwalteten Cloud Storage-Bucket auf „Durchsuchen“ und wählen Sie einen der vorhandenen Cloud Storage-Buckets aus.
  2. Klicken Sie auf Weiter.
Labels hinzufügen

Die folgenden Schritte sind optional.

So fügen Sie der Zertifizierungsstelle Labels hinzu:

  1. Klicken Sie auf Element hinzufügen.
  2. Geben Sie im Feld Schlüssel 1 den Labelschlüssel ein.
  3. Geben Sie im Feld Wert 1 den Labelwert ein.
  4. Wenn Sie ein weiteres Label hinzufügen möchten, klicken Sie auf Element hinzufügen. Fügen Sie dann den Labelschlüssel und den Wert wie in den Schritten 2 und 3 beschrieben hinzu.
  5. Klicken Sie auf Weiter.
Einstellungen überprüfen

Prüfen Sie alle Einstellungen sorgfältig und klicken Sie dann auf Fertig, um die Zertifizierungsstelle zu erstellen.

gcloud

  1. Erstellen Sie einen CA-Pool für die untergeordnete Zertifizierungsstelle:

    gcloud privateca pools create SUBORDINATE_POOL_ID --location=LOCATION
    

    Ersetzen Sie Folgendes:

    • SUBORDINATE_POOL_ID: der Name des CA-Pools
    • LOCATION: der Standort, an dem Sie den CA-Pool erstellen möchten. Eine vollständige Liste der Standorte finden Sie unter Standorte.

    Weitere Informationen zum Erstellen von CA-Pools finden Sie unter CA-Pool erstellen.

    Weitere Informationen zum Befehl gcloud privateca pools create finden Sie unter gcloud privateca pools create.

  2. Erstellen Sie eine untergeordnete Zertifizierungsstelle im erstellten CA-Pool.

    Achten Sie darauf, dass --issuer-pool die ID des ausstellenden CA-Pools angibt (nicht die Ressourcen-ID der Stamm-CA). Wenn für den ausstellenden CA-Pool eine Ausstellungsrichtlinie konfiguriert ist, muss die zugehörige baselineValues außerdem CA-Zertifikate zulassen:

    baselineValues:
      caOptions:
        isCa: true
      keyUsage:
        baseKeyUsage:
          certSign: true
          crlSign: true
    

    Wenn der ausstellende CA-Pool die Ausstellung auf End-Entity-Zertifikate beschränkt, schlägt die Aktivierung der untergeordneten Zertifizierungsstelle mit der Fehlermeldung Fields in the CSR were modified or removed in the signed CA certificate fehl.

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

    Ersetzen Sie Folgendes:

    • SUBORDINATE_CA_ID: die eindeutige Kennung der untergeordneten Zertifizierungsstelle
    • SUBORDINATE_POOL_ID: der Name des CA-Pools
    • LOCATION: der Standort des CA-Pools
    • ISSUER_POOL_ID: der Name des CA-Pools, der die ausstellende CA enthält
    • ISSUER_LOCATION: der Standort des CA-Pools, der die ausstellende CA enthält

      Das Flag --key-algorithm gibt den kryptografischen Algorithmus an, den Sie zum Erstellen eines verwalteten Cloud HSM-Schlüssels für die Zertifizierungsstelle verwenden möchten.

      Das Flag --subject gibt den X.501-Namen des Zertifikatssubjekts an.

    Führen Sie den folgenden Befehl aus, um eine untergeordnete Zertifizierungsstelle mit einem vom Kunden verwalteten Signaturschlüssel zu erstellen:

    gcloud privateca subordinates create SUBORDINATE_CA_ID \
        --pool=SUBORDINATE_POOL_ID \
        --location=LOCATION \
        --issuer-pool=ISSUER_POOL_ID \
        --issuer-location=ISSUER_LOCATION \
        --kms-key-version=KMS_KEY_VERSION \
        --subject="CN=Example Server TLS CA, O=Example LLC"
    

    Ersetzen Sie Folgendes:

    • SUBORDINATE_POOL_ID: der Name des CA-Pools
    • LOCATION: der Standort des CA-Pools
    • ISSUER_POOL_ID: der Name des CA-Pools, der die ausstellende CA enthält
    • ISSUER_LOCATION: der Standort des CA-Pools, der die ausstellende CA enthält
    • KMS_KEY_VERSION: die vollständige Ressourcen-ID einer vom Kunden verwalteten Cloud KMS-Kryptoschlüsselversion, die als Signaturschlüssel verwendet werden soll

    Weitere Informationen zu den Optionen für Signaturschlüssel und zur Vorbereitung eines vom Kunden verwalteten Signaturschlüssels finden Sie unter CA-Signaturschlüssel konfigurieren.

    Die folgende Anweisung wird zurückgegeben, wenn die untergeordnete Zertifizierungsstelle erstellt wird.

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

    Verwenden Sie die Flags --custom-aia-urls und --custom-cdp-urls, um benutzerdefinierte Zugriffs-URLs für Authority Information Access (AIA) und CRL Distribution Point (CDP) anzugeben. Wenn diese URLs angegeben sind, werden sie in alle von der Zertifizierungsstelle ausgestellten Zertifikate aufgenommen und ersetzen die Standard-Zugriffs-URLs für Cloud Storage-Bucket.

    Führen Sie den folgenden gcloud-Befehl aus, um eine vollständige Liste der Einstellungen aufzurufen:

    gcloud privateca subordinates create --help
    

    Der Befehl gibt Beispiele zum Erstellen einer untergeordneten Zertifizierungsstelle zurück, deren Aussteller sich entweder im CA Service oder an einem anderen Ort befindet.

Terraform

resource "google_privateca_certificate_authority" "root_ca" {
  // 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-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 = "ACME"
        common_name  = "my-certificate-authority"
      }
    }
    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 {
        }
      }
    }
  }
  key_spec {
    algorithm = "RSA_PKCS1_4096_SHA256"
  }
  // valid for 10 years
  lifetime = "${10 * 365 * 24 * 3600}s"
}

resource "google_privateca_certificate_authority" "sub_ca" {
  // This example assumes this pool already exists.
  // Pools cannot be deleted in normal test circumstances, so we depend on static pools
  pool                     = "my-sub-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 = "ACME"
        common_name  = "my-subordinate-authority"
      }
    }
    x509_config {
      ca_options {
        is_ca = true
        # Force the sub CA to only issue leaf certs.
        # Use e.g.
        #    max_issuer_path_length = 1
        # if you need to chain more subordinates.
        zero_max_issuer_path_length = true
      }
      key_usage {
        base_key_usage {
          cert_sign = true
          crl_sign  = true
        }
        extended_key_usage {
        }
      }
    }
  }
  // valid for 5 years
  lifetime = "${5 * 365 * 24 * 3600}s"
  key_spec {
    algorithm = "RSA_PKCS1_2048_SHA256"
  }
  type = "SUBORDINATE"
}

Java

Richten Sie zur Authentifizierung beim CA-Dienst die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.


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

Richten Sie zur Authentifizierung bei CA Service die Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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}")

Untergeordnete Zertifizierungsstelle aktivieren

So aktivieren Sie eine untergeordnete Zertifizierungsstelle:

Console

  1. Rufen Sie in derGoogle Cloud Console die Seite Certificate Authority Service auf.

    Zum Certificate Authority Service

  2. Klicken Sie auf den Tab CA-Manager.

  3. Wählen Sie unter Zertifizierungsstellen die Zertifizierungsstelle aus, die Sie aktivieren möchten.

  4. Klicken Sie auf play_circleAktivieren.

gcloud

Führen Sie den folgenden Befehl aus, um eine neu erstellte untergeordnete Zertifizierungsstelle zu aktivieren:

gcloud privateca subordinates enable SUBORDINATE_CA_ID \
--pool=SUBORDINATE_POOL_ID \
--location=LOCATION

Ersetzen Sie Folgendes:

  • SUBORDINATE_CA_ID: die eindeutige Kennung der untergeordneten Zertifizierungsstelle
  • SUBORDINATE_POOL_ID: der Name des CA-Pools, der die untergeordnete Zertifizierungsstelle enthält
  • LOCATION: der Standort des CA-Pools. Eine vollständige Liste der Standorte finden Sie unter Standorte.

Weitere Informationen zum Befehl gcloud privateca subordinates enable finden Sie unter gcloud privateca subordinates enable.

Terraform

Setzen Sie das Feld desired_state für die untergeordnete Zertifizierungsstelle auf ENABLED und führen Sie terraform apply aus.

Java

Rufen Sie den RPC ActivateCertificateAuthority auf, um die untergeordnete Zertifizierungsstelle mit einem signierten Zertifikat zu aktivieren:


import com.google.api.core.ApiFuture;
import com.google.cloud.security.privateca.v1.ActivateCertificateAuthorityRequest;
import com.google.cloud.security.privateca.v1.CertificateAuthorityName;
import com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient;
import com.google.cloud.security.privateca.v1.SubordinateConfig;
import com.google.longrunning.Operation;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class ActivateSubordinateCa {

  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 a unique id for the CA pool.
    // subordinateCaName: The CA to be activated.
    // pemCaCertificate: The signed certificate, obtained by signing the CSR.
    String project = "your-project-id";
    String location = "ca-location";
    String poolId = "ca-pool-id";
    String subordinateCaName = "subordinate-certificate-authority-name";
    String pemCaCertificate =
        "-----BEGIN CERTIFICATE-----\n" + "sample-pem-certificate\n" + "-----END CERTIFICATE-----";

    // certificateAuthorityName: The name of the certificate authority which signed the CSR.
    // If an external CA (CA not present in Google Cloud) was used for signing,
    // then use the CA's issuerCertificateChain.
    String certificateAuthorityName = "certificate-authority-name";

    activateSubordinateCa(
        project, location, poolId, certificateAuthorityName, subordinateCaName, pemCaCertificate);
  }

  // Activate a subordinate CA.
  // *Prerequisite*: Get the CSR of the subordinate CA signed by another CA. Pass in the signed
  // certificate and (issuer CA's name or the issuer CA's Certificate chain).
  // *Post*: After activating the subordinate CA, it should be enabled before issuing certificates.
  public static void activateSubordinateCa(
      String project,
      String location,
      String poolId,
      String certificateAuthorityName,
      String subordinateCaName,
      String pemCaCertificate)
      throws ExecutionException, InterruptedException, IOException {
    // 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()) {
      // Subordinate CA parent.
      String subordinateCaParent =
          CertificateAuthorityName.of(project, location, poolId, subordinateCaName).toString();

      // Construct the "Activate CA Request".
      ActivateCertificateAuthorityRequest activateCertificateAuthorityRequest =
          ActivateCertificateAuthorityRequest.newBuilder()
              .setName(subordinateCaParent)
              // The signed certificate.
              .setPemCaCertificate(pemCaCertificate)
              .setSubordinateConfig(
                  SubordinateConfig.newBuilder()
                      // Follow one of the below methods:

                      // Method 1: If issuer CA is in Google Cloud, set the Certificate Authority
                      // Name.
                      .setCertificateAuthority(
                          CertificateAuthorityName.of(
                                  project, location, poolId, certificateAuthorityName)
                              .toString())

                      // Method 2: If issuer CA is external to Google Cloud, set the issuer's
                      // certificate chain.
                      // The certificate chain of the CA (which signed the CSR) from leaf to root.
                      // .setPemIssuerChain(
                      //     SubordinateConfigChain.newBuilder()
                      //         .addAllPemCertificates(issuerCertificateChain)
                      //         .build())

                      .build())
              .build();

      // Activate the CA.
      ApiFuture<Operation> futureCall =
          certificateAuthorityServiceClient
              .activateCertificateAuthorityCallable()
              .futureCall(activateCertificateAuthorityRequest);

      Operation response = futureCall.get();

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

      System.out.println(
          "Subordinate Certificate Authority activated successfully ! !" + subordinateCaName);
      TimeUnit.SECONDS.sleep(3);
      // The current state will be STAGED.
      // The Subordinate CA has to be ENABLED before issuing certificates.
      System.out.println(
          "Current State: "
              + certificateAuthorityServiceClient
              .getCertificateAuthority(subordinateCaParent)
              .getState());
    }
  }
}

Rufen Sie den RPC EnableCertificateAuthority auf, um die untergeordnete Zertifizierungsstelle zu aktivieren, damit sie Zertifikate ausstellen kann:


import com.google.api.core.ApiFuture;
import com.google.cloud.security.privateca.v1.CertificateAuthority.State;
import com.google.cloud.security.privateca.v1.CertificateAuthorityName;
import com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient;
import com.google.cloud.security.privateca.v1.EnableCertificateAuthorityRequest;
import com.google.longrunning.Operation;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class EnableCertificateAuthority {

  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: The id of the CA pool under which the CA is present.
    // certificateAuthorityName: The name of the CA to be enabled.
    String project = "your-project-id";
    String location = "ca-location";
    String poolId = "ca-pool-id";
    String certificateAuthorityName = "certificate-authority-name";
    enableCertificateAuthority(project, location, poolId, certificateAuthorityName);
  }

  // Enable the Certificate Authority present in the given ca pool.
  // CA cannot be enabled if it has been already deleted.
  public static void enableCertificateAuthority(
      String project, String location, String poolId, String certificateAuthorityName)
      throws IOException, ExecutionException, InterruptedException {
    try (CertificateAuthorityServiceClient certificateAuthorityServiceClient =
        CertificateAuthorityServiceClient.create()) {
      // Create the Certificate Authority Name.
      CertificateAuthorityName certificateAuthorityParent =
          CertificateAuthorityName.newBuilder()
              .setProject(project)
              .setLocation(location)
              .setCaPool(poolId)
              .setCertificateAuthority(certificateAuthorityName)
              .build();

      // Create the Enable Certificate Authority Request.
      EnableCertificateAuthorityRequest enableCertificateAuthorityRequest =
          EnableCertificateAuthorityRequest.newBuilder()
              .setName(certificateAuthorityParent.toString())
              .build();

      // Enable the Certificate Authority.
      ApiFuture<Operation> futureCall =
          certificateAuthorityServiceClient
              .enableCertificateAuthorityCallable()
              .futureCall(enableCertificateAuthorityRequest);
      Operation response = futureCall.get();

      if (response.hasError()) {
        System.out.println("Error while enabling Certificate Authority !" + response.getError());
        return;
      }

      // Get the current CA state.
      State caState =
          certificateAuthorityServiceClient
              .getCertificateAuthority(certificateAuthorityParent)
              .getState();

      // Check if the CA is enabled.
      if (caState == State.ENABLED) {
        System.out.println("Enabled Certificate Authority : " + certificateAuthorityName);
      } else {
        System.out.println(
            "Cannot enable the Certificate Authority ! Current CA State: " + caState);
      }
    }
  }
}

Python

Rufen Sie den RPC ActivateCertificateAuthority auf, um die untergeordnete Zertifizierungsstelle mit einem signierten Zertifikat zu aktivieren:

import google.cloud.security.privateca_v1 as privateca_v1


def activate_subordinate_ca(
    project_id: str,
    location: str,
    ca_pool_name: str,
    subordinate_ca_name: str,
    pem_ca_certificate: str,
    ca_name: str,
) -> None:
    """
    Activate a subordinate Certificate Authority (CA).
    *Prerequisite*: Get the Certificate Signing Resource (CSR) of the subordinate CA signed by another CA. Pass in the signed
    certificate and (issuer CA's name or the issuer CA's Certificate chain).
    *Post*: After activating the subordinate CA, it should be enabled before issuing certificates.
    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.
        pem_ca_certificate: the signed certificate, obtained by signing the CSR.
        subordinate_ca_name: the CA to be activated.
        ca_name: The name of the certificate authority which signed the CSR.
            If an external CA (CA not present in Google Cloud) was used for signing,
            then use the CA's issuerCertificateChain.
    """

    ca_service_client = privateca_v1.CertificateAuthorityServiceClient()

    subordinate_ca_path = ca_service_client.certificate_authority_path(
        project_id, location, ca_pool_name, subordinate_ca_name
    )
    ca_path = ca_service_client.certificate_authority_path(
        project_id, location, ca_pool_name, ca_name
    )

    # Set CA subordinate config.
    subordinate_config = privateca_v1.SubordinateConfig(
        # Follow one of the below methods:
        # Method 1: If issuer CA is in Google Cloud, set the Certificate Authority Name.
        certificate_authority=ca_path,
        # Method 2: If issuer CA is external to Google Cloud, set the issuer's certificate chain.
        # The certificate chain of the CA (which signed the CSR) from leaf to root.
        # pem_issuer_chain=privateca_v1.SubordinateConfig.SubordinateConfigChain(
        #     pem_certificates=issuer_certificate_chain,
        # )
    )

    # Construct the "Activate CA Request".
    request = privateca_v1.ActivateCertificateAuthorityRequest(
        name=subordinate_ca_path,
        # The signed certificate.
        pem_ca_certificate=pem_ca_certificate,
        subordinate_config=subordinate_config,
    )

    # Activate the CA
    operation = ca_service_client.activate_certificate_authority(request=request)
    result = operation.result()

    print("Operation result:", result)

    # The current state will be STAGED.
    # The Subordinate CA has to be ENABLED before issuing certificates.
    print(
        f"Current state: {ca_service_client.get_certificate_authority(name=subordinate_ca_path).state}"
    )

Rufen Sie den RPC EnableCertificateAuthority auf, um die untergeordnete Zertifizierungsstelle zu aktivieren, damit sie Zertifikate ausstellen kann:

import google.cloud.security.privateca_v1 as privateca_v1


def enable_certificate_authority(
    project_id: str, location: str, ca_pool_name: str, ca_name: str
) -> None:
    """
    Enable the Certificate Authority present in the given ca pool.
    CA cannot be enabled if it has been already deleted.

    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: the name of the CA pool under which the CA is present.
        ca_name: the name of the CA to be enabled.
    """

    caServiceClient = privateca_v1.CertificateAuthorityServiceClient()
    ca_path = caServiceClient.certificate_authority_path(
        project_id, location, ca_pool_name, ca_name
    )

    # Create the Enable Certificate Authority Request.
    request = privateca_v1.EnableCertificateAuthorityRequest(
        name=ca_path,
    )

    # Enable the Certificate Authority.
    operation = caServiceClient.enable_certificate_authority(request=request)
    operation.result()

    # Get the current CA state.
    ca_state = caServiceClient.get_certificate_authority(name=ca_path).state

    # Check if the CA is enabled.
    if ca_state == privateca_v1.CertificateAuthority.State.ENABLED:
        print("Enabled Certificate Authority:", ca_name)
    else:
        print("Cannot enable the Certificate Authority ! Current CA State:", ca_state)

Nächste Schritte