יצירת רשות אישורים (CA) עליונה

בדף הזה מוסבר איך ליצור רשות אישורי בסיס (CA) במאגר CA.

רשות אישורים בסיסית נמצאת בראש ההיררכיה של תשתית מפתח ציבורי (PKI) ואחראית ליצירת עוגן האמון של ה-PKI. כדי להשתתף בצורה תקינה בתשתית מפתח ציבורי (PKI) ולהשתמש באישורים, מכשיר, תוכנה או רכיב צריכים להיות מהימנים ב-PKI. כדי לעשות את זה, צריך להגדיר את המכשיר, התוכנה או הרכיב כך שיתבססו על רשות אישורי הבסיס. כתוצאה מכך, כל האישורים שהונפקו על ידי ה-CA הבסיסי מהימנים.

לפני שמתחילים

יצירת רשות אישורים (CA) עליונה

לרשות אישורי בסיס יש אישור בחתימה עצמית שצריך להפיץ למאגרי האישורים של הלקוחות. האישור של רשות האישורים הבסיסית נמצא בראש שרשרת האישורים. אף רשות אישורים אחרת לא יכולה לבטל את אישור ה-CA. רשימת ה-CRL של רשות האישורים הבסיסית חלה רק על האישורים האחרים שהנפיקה רשות האישורים הבסיסית, ולא על עצמה.

אפשר ליצור רשות אישורים (CA) בסיסית במאגר קיים של רשויות אישורים או במאגר חדש. ההוראות הבאות מתייחסות למאגר קיים.

המסוף

כדי ליצור רשות אישורים (CA) בסיסית במאגר CA קיים:

  1. נכנסים לדף Certificate Authority Service במסוףGoogle Cloud .

    כניסה אל Certificate Authority Service

  2. לוחצים על הכרטיסייה מנהל רשויות אישורים.

  3. לוחצים על החץ להרחבת האפשרות Create CA (יצירת רשות אישורים) ואז בוחרים באפשרות Create CA in an existing CA pool (יצירת רשות אישורים במאגר רשויות אישורים קיים).

בחירת בית ל-CA

בוחרים מאגר אישורים קיים מהרשימה ולוחצים על המשך.

בחירת סוג רשות האישורים

  1. בקטע סוג, בוחרים באפשרות רשות אישורים (CA) עליונה.
  2. בשדה תוקף, מזינים את משך הזמן שבו האישורים שהונפקו על ידי רשות האישורים הבסיסית יהיו תקפים.
  3. בקטע מצב התחלתי, בוחרים את המצב התפעולי שבו רוצים ליצור את רשות האישורים.
  4. לוחצים על Continue.
הגדרה של שם הנושא של CA
  1. בשדה ארגון (O), מזינים את שם החברה.
  2. אופציונלי: בשדה יחידה ארגונית (OU), מזינים את החלוקה המשנית של החברה או את היחידה העסקית.
  3. אופציונלי: בשדה שם המדינה (C), מזינים קוד מדינה בן שתי אותיות.
  4. אופציונלי: בשדה State or province name (שם המדינה או הפרובינציה), מזינים את שם המדינה.
  5. אופציונלי: בשדה שם היישוב, מזינים את שם העיר.
  6. בשדה שם נפוץ (CN) של רשות האישורים, מזינים את שם רשות האישורים.
  7. לוחצים על Continue.
הגדרה של גודל המפתח והאלגוריתם של רשות האישורים
  1. בוחרים את אלגוריתם המפתח שהכי מתאים לצרכים שלכם. פרטים נוספים על אפשרויות מפתחות החתימה זמינים במאמר הגדרת מפתחות חתימה של רשות אישורים.
  2. כדי להשתמש במפתח חתימה בניהול הלקוח, בוחרים באפשרות מפתח בניהול הלקוח ומזינים את הגרסה של המפתח הקריפטוגרפי ב-Cloud Key Management Service.
  3. לוחצים על Continue.
הגדרת ארטיפקטים של CA
  1. בוחרים אם רוצים להשתמש בקטגוריה של Cloud Storage שמנוהלת על ידי Google או בקטגוריה שמנוהלת על ידי הלקוח.
    1. בקטגוריה של Cloud Storage בניהול Google, שירות CA יוצר קטגוריה בניהול Google באותו מיקום שבו נמצא ה-CA.
    2. כדי לבחור קטגוריה של Cloud Storage בניהול הלקוח, לוחצים על Browse ובוחרים אחת מהקטגוריות הקיימות של Cloud Storage.
  2. לוחצים על Continue.
הוספת תוויות

השלבים הבאים הם אופציונליים.

כדי להוסיף תוויות לקהל המקור:

  1. לוחצים על הוספת פריט.
  2. בשדה מפתח 1, מזינים את מפתח התווית.
  3. בשדה ערך 1, מזינים את ערך התווית.
  4. אם רוצים להוסיף עוד תווית, לוחצים על הוספת פריט. לאחר מכן, מוסיפים את המפתח והערך של התווית כמו שצוין בשלבים 2 ו-3.
  5. לוחצים על Continue.
בדיקת ההגדרות

בודקים בקפידה את כל ההגדרות ולוחצים על סיום כדי ליצור את רשות האישורים.

gcloud

  1. כדי ליצור CA חדש ברמה הבסיסית במאגר CA קיים, מריצים את הפקודה הבאה:

    gcloud privateca roots create ROOT_CA_ID \
        --location=LOCATION \
        --pool=POOL_ID \
        --key-algorithm=KEY_ALGORITHM \
        --subject="CN=my-ca, O=Test LLC"
    

    מחליפים את מה שכתוב בשדות הבאים:

    • ROOT_CA_ID: השם של רשות האישורים
    • LOCATION: המיקום של מאגר אישורי ה-CA
    • POOL_ID: השם של מאגר רשות האישורים
    • KEY_ALGORITHM: האלגוריתם שבו יש להשתמש ליצירת מפתח Cloud KMS. הדגל הזה הוא אופציונלי. אם לא תכללו את הדגל הזה, אלגוריתם המפתח יהיה rsa-pkcs1-4096-sha256 כברירת מחדל. מידע נוסף זמין במאמר בנושא הדגל ‎--key-algorithm.

    כברירת מחדל, כלל הקמפיין נוצר במצב STAGED. כדי להפעיל CA כברירת מחדל, צריך לכלול את הדגל --auto-enable.

    אם רוצים להשתמש בקטגוריה של Cloud Storage בניהול הלקוח כדי לפרסם אישורי CA ו-CRL, מוסיפים --bucket bucket-name לפקודה. מחליפים את bucket-name בשם של הקטגוריה של Cloud Storage.

    כדי לציין כתובות URL מותאמות אישית לגישה למידע על רשות (AIA) ולנקודת הפצה של רשימת ביטול אישורים (CRL) ‏(CDP), משתמשים בדגלים --custom-aia-urls ו---custom-cdp-urls. אם מציינים כתובות URL כאלה, הן נכללות בכל האישורים שהונפקו על ידי CA ומחליפות את כתובות ה-URL של הגישה לקטגוריית Cloud Storage שמוגדרות כברירת מחדל.

    כדי ליצור רשות אישורים (CA) בסיסית באמצעות מפתח חתימה בניהול הלקוח, מריצים את הפקודה הבאה:

    gcloud privateca roots create ROOT_CA_ID \
        --location=LOCATION \
        --pool=POOL_ID \
        --kms-key-version=KMS_KEY_VERSION \
        --subject="CN=my-ca, O=Test LLC"
    

    מחליפים את מה שכתוב בשדות הבאים:

    • ROOT_CA_ID: המזהה הייחודי של רשות האישורים (CA) הבסיסית
    • LOCATION: המיקום של מאגר אישורי ה-CA
    • POOL_ID: השם של מאגר רשות האישורים
    • KMS_KEY_VERSION: מזהה המשאב המלא של גרסה של מפתח קריפטוגרפי ב-Cloud KMS בניהול הלקוח, לשימוש כמפתח חתימה

    פרטים נוספים על אפשרויות של מפתחות חתימה ועל הכנת מפתח חתימה בניהול הלקוח מופיעים במאמר בנושא הגדרת מפתחות חתימה של רשות אישורים.

    כדי לראות את הרשימה המלאה של ההגדרות, מריצים את הפקודה הבאה:

    gcloud privateca roots create --help
    

Terraform

כדי ליצור רשות אישורי בסיס באמצעות מפתח הצפנה שבבעלות ובניהול של Google , משתמשים בהגדרת הדוגמה הבאה:

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

כדי ליצור CA בסיסי באמצעות מפתח בניהול עצמי, משתמשים בהגדרת הדוגמה הבאה:

resource "google_project_service_identity" "privateca_sa" {
  provider = google-beta
  service  = "privateca.googleapis.com"
}

resource "google_kms_crypto_key_iam_binding" "privateca_sa_keyuser_signerverifier" {
  crypto_key_id = "projects/keys-project/locations/us-central1/keyRings/key-ring/cryptoKeys/crypto-key"
  role          = "roles/cloudkms.signerVerifier"

  members = [
    "serviceAccount:${google_project_service_identity.privateca_sa.email}",
  ]
}

resource "google_kms_crypto_key_iam_binding" "privateca_sa_keyuser_viewer" {
  crypto_key_id = "projects/keys-project/locations/us-central1/keyRings/key-ring/cryptoKeys/crypto-key"
  role          = "roles/viewer"
  members = [
    "serviceAccount:${google_project_service_identity.privateca_sa.email}",
  ]
}

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                     = "ca-pool"
  certificate_authority_id = "my-certificate-authority"
  location                 = "us-central1"
  deletion_protection      = false # set to true to prevent destruction of the resource
  key_spec {
    cloud_kms_key_version = "projects/keys-project/locations/us-central1/keyRings/key-ring/cryptoKeys/crypto-key/cryptoKeyVersions/1"
  }

  config {
    subject_config {
      subject {
        organization = "Example, Org."
        common_name  = "Example Authority"
      }
    }
    x509_config {
      ca_options {
        # is_ca *MUST* be true for certificate authorities
        is_ca                  = true
        max_issuer_path_length = 10
      }
      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
        }
      }
    }
  }

  depends_on = [
    google_kms_crypto_key_iam_binding.privateca_sa_keyuser_signerverifier,
    google_kms_crypto_key_iam_binding.privateca_sa_keyuser_viewer,
  ]
}

המשך

כדי לבצע אימות ב-CA Service, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"

	privateca "cloud.google.com/go/security/privateca/apiv1"
	"cloud.google.com/go/security/privateca/apiv1/privatecapb"
	"google.golang.org/protobuf/types/known/durationpb"
)

// Create Certificate Authority which is the root CA in the given CA Pool. This CA will be
// responsible for signing certificates within this pool.
func createCa(
	w io.Writer,
	projectId string,
	location string,
	caPoolId string,
	caId string,
	caCommonName string,
	org string,
	caDuration int64) error {
	// projectId := "your_project_id"
	// location := "us-central1"		// For a list of locations, see: https://cloud.google.com/certificate-authority-service/docs/locations.
	// caPoolId := "ca-pool-id"			// The CA Pool id under which the CA should be created.
	// caId := "ca-id"					// A unique id/name for the ca.
	// caCommonName := "ca-name"		// A common name for your certificate authority.
	// org := "ca-org"					// The name of your company for your certificate authority.
	// ca_duration := int64(31536000)	// The validity of the certificate authority in seconds.

	ctx := context.Background()
	caClient, err := privateca.NewCertificateAuthorityClient(ctx)
	if err != nil {
		return fmt.Errorf("NewCertificateAuthorityClient creation failed: %w", err)
	}
	defer caClient.Close()

	// Set the types of Algorithm used to create a cloud KMS key.
	keySpec := &privatecapb.CertificateAuthority_KeyVersionSpec{
		KeyVersion: &privatecapb.CertificateAuthority_KeyVersionSpec_Algorithm{
			Algorithm: privatecapb.CertificateAuthority_RSA_PKCS1_2048_SHA256,
		},
	}

	// Set CA subject config.
	subjectConfig := &privatecapb.CertificateConfig_SubjectConfig{
		Subject: &privatecapb.Subject{
			CommonName:   caCommonName,
			Organization: org,
		},
	}

	// Set the key usage options for X.509 fields.
	isCa := true
	x509Parameters := &privatecapb.X509Parameters{
		KeyUsage: &privatecapb.KeyUsage{
			BaseKeyUsage: &privatecapb.KeyUsage_KeyUsageOptions{
				CrlSign:  true,
				CertSign: true,
			},
		},
		CaOptions: &privatecapb.X509Parameters_CaOptions{
			IsCa: &isCa,
		},
	}

	// Set certificate authority settings.
	// Type: SELF_SIGNED denotes that this CA is a root CA.
	ca := &privatecapb.CertificateAuthority{
		Type:    privatecapb.CertificateAuthority_SELF_SIGNED,
		KeySpec: keySpec,
		Config: &privatecapb.CertificateConfig{
			SubjectConfig: subjectConfig,
			X509Config:    x509Parameters,
		},
		Lifetime: &durationpb.Duration{
			Seconds: caDuration,
		},
	}

	fullCaPoolName := fmt.Sprintf("projects/%s/locations/%s/caPools/%s", projectId, location, caPoolId)

	// Create the CreateCertificateAuthorityRequest.
	// See https://pkg.go.dev/cloud.google.com/go/security/privateca/apiv1/privatecapb#CreateCertificateAuthorityRequest.
	req := &privatecapb.CreateCertificateAuthorityRequest{
		Parent:                 fullCaPoolName,
		CertificateAuthorityId: caId,
		CertificateAuthority:   ca,
	}

	op, err := caClient.CreateCertificateAuthority(ctx, req)
	if err != nil {
		return fmt.Errorf("CreateCertificateAuthority failed: %w", err)
	}

	if _, err = op.Wait(ctx); err != nil {
		return fmt.Errorf("CreateCertificateAuthority failed during wait: %w", err)
	}

	fmt.Fprintf(w, "CA %s created", caId)

	return nil
}

Java

כדי לבצע אימות ב-CA Service, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


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.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 CreateCertificateAuthority {

  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.
    // certificateAuthorityName: Unique name for the CA.
    String project = "your-project-id";
    String location = "ca-location";
    String poolId = "ca-pool-id";
    String certificateAuthorityName = "certificate-authority-name";
    createCertificateAuthority(project, location, poolId, certificateAuthorityName);
  }

  // Create Certificate Authority which is the root CA in the given CA Pool.
  public static void createCertificateAuthority(
      String project, String location, String poolId, String certificateAuthorityName)
      throws InterruptedException, ExecutionException, 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()) {

      String commonName = "common-name";
      String orgName = "org-name";
      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())
              .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 certificateAuthority =
          CertificateAuthority.newBuilder()
              // CertificateAuthority.Type.SELF_SIGNED denotes that this CA is a root CA.
              .setType(CertificateAuthority.Type.SELF_SIGNED)
              .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 certificateAuthorityRequest =
          CreateCertificateAuthorityRequest.newBuilder()
              .setParent(CaPoolName.of(project, location, poolId).toString())
              .setCertificateAuthorityId(certificateAuthorityName)
              .setCertificateAuthority(certificateAuthority)
              .build();

      // Create Certificate Authority.
      ApiFuture<Operation> futureCall =
          certificateAuthorityServiceClient
              .createCertificateAuthorityCallable()
              .futureCall(certificateAuthorityRequest);
      Operation response = futureCall.get();

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

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

Python

כדי לבצע אימות ב-CA Service, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

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


def create_certificate_authority(
    project_id: str,
    location: str,
    ca_pool_name: str,
    ca_name: str,
    common_name: str,
    organization: str,
    ca_duration: int,
) -> None:
    """
    Create Certificate Authority which is the root CA in the given CA Pool. This CA will be
    responsible for signing certificates within this 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.
        ca_name: unique name for the CA.
        common_name: a title for your certificate authority.
        organization: the name of your company for your certificate authority.
        ca_duration: the validity of the certificate authority in seconds.
    """

    caServiceClient = privateca_v1.CertificateAuthorityServiceClient()

    # Set the types of Algorithm used to create a cloud KMS key.
    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 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(
        # CertificateAuthority.Type.SELF_SIGNED denotes that this CA is a root CA.
        type_=privateca_v1.CertificateAuthority.Type.SELF_SIGNED,
        key_spec=key_version_spec,
        config=privateca_v1.CertificateConfig(
            subject_config=subject_config,
            x509_config=x509_parameters,
        ),
        lifetime=duration_pb2.Duration(seconds=ca_duration),
    )

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

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

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

    print("Operation result:", result)

‫API בארכיטקטורת REST

  1. יוצרים רשות אישורים (CA) עליונה.

    כדי להשתמש במפתח חתימה בניהול הלקוח, מציינים את cloud_kms_key_version בשדה key_spec במקום algorithm.

    פרטים נוספים על אפשרויות של מפתחות חתימה ועל הכנת מפתח חתימה בניהול הלקוח מופיעים במאמר בנושא הגדרת מפתחות חתימה של רשות אישורים.

    ה-method של ה-HTTP וכתובת ה-URL:

    POST https://privateca.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/caPools/POOL_ID/certificateAuthorities?certificate_authority_id=ROOT_CA_ID

    תוכן בקשת JSON:

    {
    "type": "SELF_SIGNED",
    "lifetime": {
      "seconds": 315576000,
      "nanos": 0
    },
    "config": {
      "subject_config": {
        "subject": {
          "organization": "ORGANIZATION_NAME",
          "common_name": "COMMON_NAME"
        }
      },
      "x509_config":{
        "ca_options":{
          "is_ca":true
        },
        "key_usage":{
          "base_key_usage":{
            "cert_sign":true,
            "crl_sign":true
          }
        }
      }
    },
    "key_spec":{
      "algorithm":"RSA_PKCS1_4096_SHA256"
    }
    }
    

    כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

    אתם אמורים לקבל תגובת JSON שדומה לזו:

    {
      "name": "projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID",
      "metadata": {...},
      "done": false
    }
    

  2. מבצעים שאילתות לגבי הפעולה עד שהיא מסתיימת.

    ה-method של ה-HTTP וכתובת ה-URL:

    GET https://privateca.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID

    כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

    אתם אמורים לקבל תגובת JSON שדומה לזו:

    {
     "name": "projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID",
     "metadata": {...},
     "done": true,
     "response": {
       "@type": "type.googleapis.com/google.cloud.security.privateca.v1.CertificateAuthority",
       "name": "...",
     }
    }
    

אחרי שמוודאים ש-CA פועל כצפוי, אפשר להפעיל אותו כדי להתחיל להנפיק אישורים מאוזני עומס למאגר CA.

הפעלת רשות אישורים (CA) בסיסית

gcloud

כדי להפעיל רשות אישורים (CA) בסיסית, מריצים את הפקודה gcloud הבאה:

gcloud privateca roots enable ROOT_CA_ID --location=LOCATION --pool=POOL_ID

מחליפים את מה שכתוב בשדות הבאים:

  • ROOT_CA_ID: השם של רשות האישורים
  • LOCATION: המיקום של מאגר אישורי ה-CA. כאן מפורטת רשימת המיקומים המלאה.
  • POOL_ID: השם של מאגר רשות האישורים

Terraform

אם משתמשים ב-Terraform כדי ליצור רשות אישורי בסיס, היא מופעלת בזמן היצירה. כדי ליצור רשות אישורים בסיסית במצב STAGED, מגדירים את השדה desired_state לערך STAGED כשיוצרים את רשות האישורים.

אפשר להגדיר את השדה desired_state לערך ENABLED או DISABLED אחרי יצירת CA.

המשך

כדי לבצע אימות ב-CA Service, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"

	privateca "cloud.google.com/go/security/privateca/apiv1"
	"cloud.google.com/go/security/privateca/apiv1/privatecapb"
)

// Enable the Certificate Authority present in the given ca pool.
// CA cannot be enabled if it has been already deleted.
func enableCa(w io.Writer, projectId string, location string, caPoolId string, caId string) error {
	// projectId := "your_project_id"
	// location := "us-central1"	// For a list of locations, see: https://cloud.google.com/certificate-authority-service/docs/locations.
	// caPoolId := "ca-pool-id"		// The id of the CA pool under which the CA is present.
	// caId := "ca-id"				// The id of the CA to be enabled.

	ctx := context.Background()
	caClient, err := privateca.NewCertificateAuthorityClient(ctx)
	if err != nil {
		return fmt.Errorf("NewCertificateAuthorityClient creation failed: %w", err)
	}
	defer caClient.Close()

	fullCaName := fmt.Sprintf("projects/%s/locations/%s/caPools/%s/certificateAuthorities/%s",
		projectId, location, caPoolId, caId)

	// Create the EnableCertificateAuthorityRequest.
	// See https://pkg.go.dev/cloud.google.com/go/security/privateca/apiv1/privatecapb#EnableCertificateAuthorityRequest.
	req := &privatecapb.EnableCertificateAuthorityRequest{Name: fullCaName}

	op, err := caClient.EnableCertificateAuthority(ctx, req)
	if err != nil {
		return fmt.Errorf("EnableCertificateAuthority failed: %w", err)
	}

	var caResp *privatecapb.CertificateAuthority
	if caResp, err = op.Wait(ctx); err != nil {
		return fmt.Errorf("EnableCertificateAuthority failed during wait: %w", err)
	}

	if caResp.State != privatecapb.CertificateAuthority_ENABLED {
		return fmt.Errorf("unable to enable Certificate Authority. Current state: %s", caResp.State.String())
	}

	fmt.Fprintf(w, "Successfully enabled Certificate Authority: %s.", caId)
	return nil
}

Java

כדי לבצע אימות ב-CA Service, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.


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

כדי לבצע אימות ב-CA Service, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

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)

‫API בארכיטקטורת REST

  1. מאפשרים לרשות האישורים להנפיק אישורים ממאגר רשויות האישורים.

    ה-method של ה-HTTP וכתובת ה-URL:

    POST https://privateca.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/caPools/POOL_ID/certificateAuthorities/ROOT_CA_ID:enable

    כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

    אתם אמורים לקבל תגובת JSON שדומה לזו:

    {
        "name": "projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID",
        "metadata": {...},
        "done": false
    }
    

  2. מבצעים שאילתות לגבי הפעולה עד שהיא מסתיימת.

    ה-method של ה-HTTP וכתובת ה-URL:

    GET https://privateca.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID

    כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

    אתם אמורים לקבל תגובת JSON שדומה לזו:

    {
        "name": "projects/PROJECT_ID/locations/LOCATION/operations/operation-UUID",
        "metadata": {...},
        "done": true,
        "response": {
          "@type": "type.googleapis.com/google.cloud.security.privateca.v1.CertificateAuthority",
          "name": "...",
        }
    }
    

בדיקת רשות אישורים

כדי לוודא שרשות אישורים (CA) יכולה להנפיק אישורים, צריך לבקש אישור ממאגר ה-CA המשויך ולציין במפורש את שם ה-CA שרוצים לבדוק באמצעות הדגל --ca.

אפשר להשתמש בשיטות הבאות כדי לבקש אישור ממאגר רשויות אישורים:

  1. מבקשים משירות רשות האישורים ליצור בשבילכם מפתח פרטי או ציבורי.
  2. יוצרים מפתח פרטי או ציבורי משלכם ושולחים בקשה לחתימת אישור (CSR).

יותר קל להשתמש במפתח פרטי או במפתח ציבורי שנוצרו באופן אוטומטי כדי לבקש אישור מ-CA במאגר CA. בקטע הזה מוסבר איך לבדוק רשות אישורים באמצעות השיטה הזו.

כדי להשתמש במפתח פרטי או במפתח ציבורי שנוצרו באופן אוטומטי כדי לבקש אישור מ-CA במאגר CA, מריצים את gcloudהפקודה הבאה:

gcloud privateca certificates create \
    --issuer-pool=POOL_ID \
    --issuer-location=ISSUER_LOCATION \
    --ca=ROOT_CA_ID \
    --generate-key \
    --key-output-file=KEY_FILENAME \
    --cert-output-file=CERT_FILENAME \
    --dns-san=DNS_NAME

מחליפים את מה שכתוב בשדות הבאים:

  • POOL_ID: השם של מאגר רשות האישורים
  • ISSUER_LOCATION: המיקום של רשות האישורים (CA) שהנפיקה את האישור הדיגיטלי
  • ROOT_CA_ID: המזהה הייחודי של רשות האישורים שרוצים לבדוק
  • KEY_FILENAME: הקובץ שבו המפתח שנוצר נכתב בפורמט PEM
  • CERT_FILENAME: הקובץ שאליו נכתב קובץ שרשרת האישורים שנוצר בהצפנת PEM. הסדר של שרשרת האישורים הוא מאישור הקצה לאישור הבסיס.
  • DNS_NAME: שמות חלופיים (SAN) של נושא DNS, מופרדים בפסיקים (לפחות אחד)

    הדגל --generate-key יוצר מפתח פרטי חדש מסוג RSA-2048 במחשב.

כדי להשתמש בבקשת חתימה על אישור (CSR) כדי לבקש אישור מ-CA במאגר CA, או כדי לקבל מידע נוסף על בקשת אישורים, ראו בקשת אישור והצגת אישורים שהונפקו.

שכפול רשויות אישורים

כדי לשכפל רשות אישורים קיימת כדי לחדש אותה, או כדי ליצור רשות אישורים חדשה עם אותה תצורה, מריצים את הפקודה הבאה:

gcloud privateca roots create NEW_CA_ID \
    --location=LOCATION \
    --pool=POOL_ID \
    --from-ca=EXISTING_CA_ID \
    --key-algorithm "ec-p384-sha384"

מחליפים את מה שכתוב בשדות הבאים:

  • NEW_CA_ID: המזהה הייחודי של רשות האישורים החדשה
  • LOCATION: המיקום של מאגר אישורי ה-CA
  • POOL_ID: השם של מאגר רשויות האישורים שבו רוצים ליצור את רשות האישורים החדשה
  • EXISTING_CA_ID: המזהה של ה-CA של המקור או מזהה מוגדר במלואו של ה-CA של המקור

הסימון הבוליאני --from-ca נתמך ביצירת רשויות אישורים בסיסיות ומשניות. ה-CA הקיים צריך להיות באותו מאגר CA כמו ה-CA החדש.

הדגל --key-algorithm מעתיק את כל הגדרות ה-CA מ-CA קיים (מלבד גרסת המפתח של Cloud KMS והקטגוריה של Cloud Storage). עם זאת, עדיין אפשר לשנות כל אחד מערכי ההגדרה ב-CA החדש על ידי ציון הדגל המתאים. לדוגמה, עדיין אפשר לציין את האפשרות ‎`--subject SUBJECT כדי להשתמש בנושא חדש.

אם לא מציינים את הדגל --key-algorithm, ברירת המחדל של האלגוריתם היא:

  • rsa-pkcs1-4096-sha256 לרשויות אישורי בסיס.
  • rsa-pkcs1-2048-sha256 עבור רשויות אישורים משניות.

מידע נוסף על הפקודה gcloud מופיע במאמר gcloud privateca roots create.

המאמרים הבאים