Menghapus certificate authority

Certificate Authority Service memungkinkan Anda menghapus certificate authority (CA) yang ada. CA akan dihapus secara permanen setelah masa tenggang 30 hari sejak proses penghapusan dimulai. Setelah masa tenggang, Layanan CA akan menghapus CA dan semua artefak bertingkat secara permanen, seperti sertifikat dan daftar pencabutan sertifikat (CRL).

Semua resource Google Cloud yang dikelola pelanggan yang digunakan oleh CA yang dihapus, seperti bucket Cloud Storage atau kunci Cloud Key Management Service, tidak akan dihapus. Untuk mengetahui informasi selengkapnya tentang resource yang dikelola Google dan dikelola pelanggan, lihat Mengelola resource.

CA yang dihapus tidak ditagih selama masa tenggang. Namun, jika Anda memulihkan CA, Anda akan ditagih berdasarkan tingkat penagihan CA selama CA berada dalam status DELETED.

Sebelum memulai

  • Pastikan Anda memiliki peran Identity and Access Management (IAM) CA Service Operation Manager (roles/privateca.caManager) atau CA Service Admin (roles/privateca.admin). Untuk mengetahui informasi selengkapnya tentang peran IAM bawaan untuk Layanan CA, lihat Kontrol akses dengan IAM.

    Untuk mengetahui informasi tentang cara memberikan peran IAM, lihat Memberikan satu peran.

  • Pastikan CA memenuhi kondisi berikut:

    • CA harus dalam status AWAITING_USER_ACTIVATION, DISABLED, atau STAGED. Untuk mengetahui informasi selengkapnya, lihat Status Certificate Authority.
    • CA tidak boleh berisi sertifikat aktif. Sertifikat dianggap aktif jika memenuhi kondisi berikut:

      • Sertifikat memiliki tanggal 'dari' dan 'hingga' yang valid.
      • Sertifikat belum dicabut.
      • Perangkat atau sistem yang menggunakan sertifikat memercayai certificate authority (CA) yang menerbitkan sertifikat.

    Sebelum menghapus CA, pastikan semua sertifikat aktif yang telah dikeluarkan oleh CA dicabut. Anda tidak dapat mencabut sertifikat dari CA yang dihapus.

Menghapus CA

Untuk memulai penghapusan CA, lakukan hal berikut:

Konsol

  1. Buka halaman Certificate authorities di konsol Google Cloud.

    Buka Certificate authorities

  2. Dalam daftar CA, pilih CA yang ingin dihapus.
  3. Klik Delete. Dialog Hapus Certificate Authority akan muncul.
  4. Opsional: Centang salah satu atau kedua kotak centang berikut jika kondisinya berlaku untuk Anda:
    • Hapus CA ini, meskipun ada sertifikat aktif

      Opsi ini memungkinkan Anda menghapus CA dengan sertifikat aktif. Menghapus CA dengan sertifikat aktif dapat menyebabkan situs, aplikasi, atau sistem yang mengandalkan sertifikat tersebut gagal. Sebaiknya cabut semua sertifikat aktif yang dikeluarkan oleh CA sebelum Anda menghapus CA.

    • Lewati masa tenggang 30 hari dan segera hapus CA ini

      Masa tenggang 30 hari memberi Anda waktu untuk mencabut semua sertifikat yang dikeluarkan oleh CA ini dan memverifikasi bahwa tidak ada sistem yang bergantung pada CA ini. Sebaiknya gunakan opsi ini hanya di lingkungan non-produksi atau pengujian untuk mencegah potensi pemadaman dan kehilangan data.

  5. Klik Konfirmasi.

gcloud

  1. Periksa status CA untuk memastikannya dinonaktifkan. Anda hanya dapat menghapus CA yang berada dalam status DISABLED.

    gcloud privateca roots describe CA_ID --pool=POOL_ID \
      --format="value(state)"
    

    Ganti kode berikut:

    • CA_ID: ID unik CA.
    • POOL_ID: Nama kumpulan CA yang berisi CA.

    Untuk informasi selengkapnya tentang perintah gcloud privateca roots describe, lihat gcloud privateca roots describe.

  2. Jika CA tidak dinonaktifkan, jalankan perintah berikut untuk menonaktifkan CA.

    gcloud privateca roots disable CA_ID --pool=POOL_ID
    

    Untuk informasi selengkapnya tentang perintah gcloud privateca roots disable, lihat gcloud privateca roots disable.

  3. Hapus CA.

    gcloud privateca roots delete CA_ID --pool=POOL_ID
    

    Anda dapat menghapus CA meskipun CA memiliki sertifikat aktif dengan menyertakan tanda --ignore-active-certificates dalam perintah gcloud.

    Untuk informasi selengkapnya tentang perintah gcloud privateca roots delete, lihat gcloud privateca roots delete.

  4. Saat diminta, konfirmasi bahwa Anda ingin menghapus CA.

    Setelah mengonfirmasi, CA akan dijadwalkan untuk dihapus dan masa tenggang 30 hari akan dimulai. Perintah ini menghasilkan output tanggal dan waktu yang diperkirakan saat CA akan dihapus.

    Deleted Root CA [projects/PROJECT_ID/locations/us-west1/caPools/POOL_ID/certificateAuthorities/CA_ID] can be undeleted until 2020-08-14T19:28:39Z.
    

Go

Untuk melakukan autentikasi ke Layanan CA, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import (
	"context"
	"fmt"
	"io"

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

// Delete a Certificate Authority from the specified CA pool.
// Before deletion, the CA must be disabled or staged and must not contain any active certificates.
func deleteCa(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 deleted.

	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)

	// Check if the CA is disabled or staged.
	// See https://pkg.go.dev/cloud.google.com/go/security/privateca/apiv1/privatecapb#GetCertificateAuthorityRequest.
	caReq := &privatecapb.GetCertificateAuthorityRequest{Name: fullCaName}
	caResp, err := caClient.GetCertificateAuthority(ctx, caReq)
	if err != nil {
		return fmt.Errorf("GetCertificateAuthority failed: %w", err)
	}

	if caResp.State != privatecapb.CertificateAuthority_DISABLED &&
		caResp.State != privatecapb.CertificateAuthority_STAGED {
		return fmt.Errorf("you can only delete disabled or staged Certificate Authorities. %s is not disabled", caId)
	}

	// Create the DeleteCertificateAuthorityRequest.
	// Setting the IgnoreActiveCertificates to True will delete the CA
	// even if it contains active certificates. Care should be taken to re-anchor
	// the certificates to new CA before deleting.
	// See https://pkg.go.dev/cloud.google.com/go/security/privateca/apiv1/privatecapb#DeleteCertificateAuthorityRequest.
	req := &privatecapb.DeleteCertificateAuthorityRequest{
		Name:                     fullCaName,
		IgnoreActiveCertificates: false,
	}

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

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

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

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

Java

Untuk melakukan autentikasi ke Layanan CA, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.


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.DeleteCertificateAuthorityRequest;
import com.google.longrunning.Operation;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class DeleteCertificateAuthority {

  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 deleted.
    String project = "your-project-id";
    String location = "ca-location";
    String poolId = "ca-pool-id";
    String certificateAuthorityName = "certificate-authority-name";
    deleteCertificateAuthority(project, location, poolId, certificateAuthorityName);
  }

  // Delete the Certificate Authority from the specified CA pool.
  // Before deletion, the CA must be disabled and must not contain any active certificates.
  public static void deleteCertificateAuthority(
      String project, String location, String poolId, String certificateAuthorityName)
      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()) {
      // Create the Certificate Authority Name.
      CertificateAuthorityName certificateAuthorityNameParent =
          CertificateAuthorityName.newBuilder()
              .setProject(project)
              .setLocation(location)
              .setCaPool(poolId)
              .setCertificateAuthority(certificateAuthorityName)
              .build();

      // Check if the CA is enabled.
      State caState =
          certificateAuthorityServiceClient
              .getCertificateAuthority(certificateAuthorityNameParent)
              .getState();
      if (caState == State.ENABLED) {
        System.out.println(
            "Please disable the Certificate Authority before deletion ! Current state: " + caState);
        return;
      }

      // Create the DeleteCertificateAuthorityRequest.
      // Setting the setIgnoreActiveCertificates() to true, will delete the CA
      // even if it contains active certificates. Care should be taken to re-anchor
      // the certificates to new CA before deleting.
      DeleteCertificateAuthorityRequest deleteCertificateAuthorityRequest =
          DeleteCertificateAuthorityRequest.newBuilder()
              .setName(certificateAuthorityNameParent.toString())
              .setIgnoreActiveCertificates(false)
              .build();

      // Delete the Certificate Authority.
      ApiFuture<Operation> futureCall =
          certificateAuthorityServiceClient
              .deleteCertificateAuthorityCallable()
              .futureCall(deleteCertificateAuthorityRequest);
      Operation response = futureCall.get();

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

      // Check if the CA has been deleted.
      caState =
          certificateAuthorityServiceClient
              .getCertificateAuthority(certificateAuthorityNameParent)
              .getState();
      if (caState == State.DELETED) {
        System.out.println(
            "Successfully deleted Certificate Authority : " + certificateAuthorityName);
      } else {
        System.out.println(
            "Unable to delete Certificate Authority. Please try again ! Current state: " + caState);
      }
    }
  }
}

Python

Untuk melakukan autentikasi ke Layanan CA, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, lihat Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import google.cloud.security.privateca_v1 as privateca_v1


def delete_certificate_authority(
    project_id: str, location: str, ca_pool_name: str, ca_name: str
) -> None:
    """
    Delete the Certificate Authority from the specified CA pool.
    Before deletion, the CA must be disabled and must not contain any active 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: the name of the CA pool under which the CA is present.
        ca_name: the name of the CA to be deleted.
    """

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

    # Check if the CA is enabled.
    ca_state = caServiceClient.get_certificate_authority(name=ca_path).state
    if ca_state != privateca_v1.CertificateAuthority.State.DISABLED:
        print(
            "Please disable the Certificate Authority before deletion ! Current state:",
            ca_state,
        )
        raise RuntimeError(
            f"You can only delete disabled Certificate Authorities. "
            f"{ca_name} is not disabled!"
        )

    # Create the DeleteCertificateAuthorityRequest.
    # Setting the ignore_active_certificates to True will delete the CA
    # even if it contains active certificates. Care should be taken to re-anchor
    # the certificates to new CA before deleting.
    request = privateca_v1.DeleteCertificateAuthorityRequest(
        name=ca_path, ignore_active_certificates=False
    )

    # Delete the Certificate Authority.
    operation = caServiceClient.delete_certificate_authority(request=request)
    result = operation.result()

    print("Operation result", result)

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

    # Check if the CA has been deleted.
    if ca_state == privateca_v1.CertificateAuthority.State.DELETED:
        print("Successfully deleted Certificate Authority:", ca_name)
    else:
        print(
            "Unable to delete Certificate Authority. Please try again ! Current state:",
            ca_state,
        )

Memeriksa tanggal habis masa berlaku CA yang dihapus

Untuk melihat kapan CA akan dihapus secara permanen, lakukan tindakan berikut:

Konsol

  1. Klik tab CA pool manager.
  2. Klik nama kumpulan CA yang berisi CA yang Anda hapus.

Anda dapat melihat tanggal habis masa berlaku CA dalam tabel di halaman kumpulan CA.

Melihat tanggal habis masa berlaku CA yang dihapus.

gcloud

Untuk memeriksa waktu penghapusan yang diharapkan untuk CA, jalankan perintah berikut:

gcloud privateca roots describe CA_ID \
  --pool=POOL_ID \
  --format="value(expireTime.date())"

Ganti kode berikut:

  • CA_ID: Nama CA.
  • POOL_ID: Nama kumpulan CA yang berisi CA.

Perintah ini menampilkan tanggal dan waktu yang diharapkan saat Layanan CA menghapus CA.

2020-08-14T19:28:39

Untuk memverifikasi bahwa CA telah dihapus secara permanen, jalankan perintah berikut:

gcloud privateca roots describe CA_ID --pool=POOL_ID

Jika CA berhasil dihapus, perintah akan menampilkan error berikut.

ERROR: (gcloud.privateca.roots.describe) NOT_FOUND: Resource 'projects/PROJECT_ID/locations/LOCATION/caPools/POOL_ID/certificateAuthorities/CA_ID' was not found

Langkah selanjutnya