認証局の削除

Certificate Authority Service を使用すると、既存の認証局(CA)を削除できます。CA は、削除プロセスが開始されてから 30 日間の猶予期間が経過すると、完全に削除されます。猶予期間が経過すると、CA Service は CA と、ネストされたすべてのアーティファクト(証明書や証明書失効リスト(CRL)など)を完全に削除します。

削除された CA によって使用されていた顧客管理の Google Cloud リソース(Cloud Storage バケットや Cloud Key Management Service 鍵など)は削除されません。Google マネージド リソースと顧客管理リソースの詳細については、リソースの管理をご覧ください。

削除された CA は、猶予期間中は課金されません。ただし、CA を復元すると、CA が DELETED 状態であった間、CA の課金ティアで課金されます。

準備

  • CA Service オペレーション マネージャー(roles/privateca.caManager)または CA Service 管理者(roles/privateca.admin)の Identity and Access Management(IAM)ロールがあることを確認します。CA Service の事前定義された IAM のロールの詳細については、IAM を使用したアクセス制御をご覧ください。

    IAM ロールの付与については、単一のロールを付与するをご覧ください。

  • CA が次の条件を満たしていることを確認してください。

    • CA が AWAITING_USER_ACTIVATIONDISABLED、または STAGED 状態になっている必要があります。詳しくは、認証局の状態をご覧ください。
    • CA に有効な証明書を含めることはできません。CA を完全に削除する前に、CA によって発行された証明書を取り消すことをおすすめします。CA が完全に削除された後は、有効な証明書を取り消すことはできません。

CA を削除する

CA の削除を開始するには、次の手順を行います。

コンソール

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

    Certificate Authority Service に移動

  2. [CA マネージャー] タブをクリックします。
  3. CA のリストで、削除する CA を選択します。
  4. [無効にする] をクリックします。
  5. 削除する CA を無効にします。
  6. 表示されたダイアログで [登録解除] をクリックします。
  7. [削除] をクリックします。
  8. 表示されたダイアログで [登録解除] をクリックします。

gcloud

  1. CA の状態をチェックして、無効になっていることを確認します。削除できるのは、DISABLED 状態の CA のみです。

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

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

    • CA_ID: CA の一意の識別子。
    • POOL_ID: CA を含む CA プールの名前。

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

  2. CA が無効になっていない場合は、次のコマンドを実行して CA を無効にします。

    gcloud privateca roots disable CA_ID --pool=POOL_ID
    

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

  3. CA を削除します。

    gcloud privateca roots delete CA_ID --pool=POOL_ID
    

    CA に有効な証明書がある場合でも CA を削除するには、gcloud コマンドに --ignore-active-certificates フラグを含めます。

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

  4. プロンプトが表示されたら、CA を削除することを確認します。

    確認後、CA の削除がスケジュール設定され、30 日間の猶予期間が開始されます。このコマンドでは、CA が削除される予定の日時が出力されます。

    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

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

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

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


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

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

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,
        )

削除された CA の有効期限を確認する

CA が完全に削除されるタイミングを確認するには、次の手順を行います。

コンソール

  1. [CA プール マネージャー] タブをクリックします。
  2. 削除した CA を含む CA プールの名前をクリックします。

CA の有効期限は、[CA プール] ページの表で確認できます。

削除された CA の有効期限を確認します。

gcloud

CA の予想される削除時間を確認するには、次のコマンドを実行します。

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

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

  • CA_ID: CA の名前。
  • POOL_ID: CA を含む CA プールの名前。

このコマンドは、CA Service が CA を削除する際に予想される日時を返します。

2020-08-14T19:28:39

CA が完全に削除されたことを確認するには、次のコマンドを実行します。

gcloud privateca roots describe CA_ID --pool=POOL_ID

CA が正常に削除されると、コマンドは次のエラーを返します。

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

次のステップ