証明書を取り消す

このページでは、証明書を取り消す方法について説明します。

Certificate Authority Service は、証明書失効リスト(CRL)を定期的に公開することで、証明書の取り消しをサポートしています。取り消すことができるのは、Enterprise ティアの CA プールによって発行された証明書のみです。

準備

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

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

CRL 公開を有効にする

CA プールによって発行された証明書を取り消すには、CA プールで CRL 公開を有効にする必要があります。CA プールの作成時に CRL 公開を有効にできます。最初に無効にした場合は、後で CRL 公開を有効にできます。

CRL 公開を有効にすると、新しい CRL が毎日公開され、7 日間有効になります。新しい証明書の取り消しから 15 分以内に、新しい CRL も公開されます。

証明書には、証明書の CRL 情報の場所を指定する CRL 配布ポイント(CDP)拡張機能が含まれています。デフォルトでは、CRL 公開を有効にすると、CA Service は、CA が使用する Cloud Storage の公開場所を使用して、CA によって発行されたすべての証明書の CDP 拡張機能を設定します。この証明書拡張機能に独自のリンクを表示するには、UserDefinedAccessUrls を設定します。デフォルトの Cloud Storage パブリッシュ ロケーションのリンクを保持し、独自のリンクも追加するには、指定するリンクのリストに Cloud Storage リンクを追加します。

CA プールで CRL 公開を有効にするには、次の手順を行います。

コンソール

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

    Certificate Authority Service

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

  3. 編集する CA プールをクリックするか、編集する CA が含まれている CA プールをクリックします。

  4. [CA プール] ページで、[] をクリックします。

    編集

  5. [パブリッシュ オプションを設定する] セクションが表示されるまで [次へ] をクリックします。

  6. [このプール内の CA の CRL を GCS バケットに公開する] の切り替えボタンをクリックします。

gcloud

次のコマンドを実行します。

gcloud privateca pools update POOL_ID --location LOCATION --publish-crl

以下を置き換えます。

  • POOL_ID: CA プールの名前。
  • LOCATION: CA プールのロケーション。ロケーションの完全なリストについては、ロケーションをご覧ください。

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

CA Service では、CRL ごとに期限切れになっていない取り消し済みの証明書数の上限が 500,000 に制限されています。

証明書を取り消す

CA Service では、シリアル番号またはリソース名で証明書を取り消すことができます。また、任意の理由も受け入れます。証明書が取り消されると、そのシリアル番号と取り消し理由が、証明書の有効期限が切れるまで、以降のすべての CRL に表示されます。取り消しから 15 分以内に帯域外 CRL も生成されます。

証明書を取り消すには、次の手順を行います。

コンソール

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

    Certificate Authority Service に移動

  2. [プライベート証明書マネージャー] タブをクリックします。
  3. 証明書のリストで、削除する証明書の行にある [さらに表示] をクリックします。
  4. [取り消し] をクリックします。
  5. 表示されたダイアログで [登録解除] をクリックします。

gcloud

  • リソース名を使用して証明書を取り消すには、次のコマンドを実行します。

    gcloud privateca certificates revoke \
        --certificate CERT_ID \
        --issuer-pool POOL_ID \
        --issuer-location ISSUER_LOCATION \
        --reason REVOCATION_REASON
    

    以下を置き換えます。

    • CERT_ID: 取り消す証明書の固有識別子。
    • POOL_ID: 証明書を発行した CA プールの名前。
    • ISSUER_LOCATION: 発行 CA プールのロケーション。
    • REVOCATION_REASON: 証明書を取り消す理由。

    --reason フラグは省略可能です。このフラグの詳細については、--reason をご覧になるか、--help フラグを指定して次の gcloud コマンドを使用してください。

    gcloud privateca certificates revoke --help
    

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

  • シリアル番号を使用して証明書を取り消すには、次のコマンドを実行します。

    gcloud privateca certificates revoke \
        --serial-number SERIAL_NUMBER \
        --issuer-pool POOL_ID \
        --issuer-location ISSUER_LOCATION \
        --reason REVOCATION_REASON
    

    以下を置き換えます。

    • SERIAL_NUMBER: 証明書のシリアル番号。
    • POOL_ID: 証明書を発行した CA プールの名前。
    • ISSUER_LOCATION: 発行 CA プールのロケーション。
    • REVOCATION_REASON: 証明書を取り消す理由。

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

    確認のメッセージが表示されたら、「Y」と入力して確認します。

    You are about to revoke Certificate [projects/PROJECT_ID/locations/CA_POOL_REGION/caPools/POOL_ID/certificates/CERT_ID]
    
    Do you want to continue? (Y/n) Y
    Revoked certificate [projects/PROJECT_ID/locations/CA_POOL_REGION/caPools/POOL_ID/certificates/CERT_ID] at DATE_TIME.
    
    

Go

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

import (
	"context"
	"fmt"
	"io"

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

// Revoke an issued certificate. Once revoked, the certificate will become invalid
// and will expire post its lifetime.
func revokeCertificate(
	w io.Writer,
	projectId string,
	location string,
	caPoolId string,
	certId 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 CA Pool id in which the certificate exists.
	// certId := "certificate"			// A unique name for the certificate.

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

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

	// Create the RevokeCertificateRequest and specify the appropriate revocation reason.
	// See https://pkg.go.dev/cloud.google.com/go/security/privateca/apiv1/privatecapb#RevokeCertificateRequest.
	req := &privatecapb.RevokeCertificateRequest{
		Name:   fullCertName,
		Reason: privatecapb.RevocationReason_PRIVILEGE_WITHDRAWN,
	}

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

	fmt.Fprintf(w, "Certificate %s revoked", certId)

	return nil
}

Java

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


import com.google.api.core.ApiFuture;
import com.google.cloud.security.privateca.v1.Certificate;
import com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient;
import com.google.cloud.security.privateca.v1.CertificateName;
import com.google.cloud.security.privateca.v1.RevocationReason;
import com.google.cloud.security.privateca.v1.RevokeCertificateRequest;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class RevokeCertificate {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException {
    // 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: Id for the CA pool which contains the certificate.
    // certificateName: Name of the certificate to be revoked.
    String project = "your-project-id";
    String location = "ca-location";
    String poolId = "ca-pool-id";
    String certificateName = "certificate-name";
    revokeCertificate(project, location, poolId, certificateName);
  }

  // Revoke an issued certificate. Once revoked, the certificate will become invalid and will expire
  // post its lifetime.
  public static void revokeCertificate(
      String project, String location, String poolId, String certificateName)
      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 Certificate Name.
      CertificateName certificateNameParent =
          CertificateName.newBuilder()
              .setProject(project)
              .setLocation(location)
              .setCaPool(poolId)
              .setCertificate(certificateName)
              .build();

      // Create Revoke Certificate Request and specify the appropriate revocation reason.
      RevokeCertificateRequest revokeCertificateRequest =
          RevokeCertificateRequest.newBuilder()
              .setName(certificateNameParent.toString())
              .setReason(RevocationReason.PRIVILEGE_WITHDRAWN)
              .build();

      // Revoke certificate.
      ApiFuture<Certificate> response =
          certificateAuthorityServiceClient
              .revokeCertificateCallable()
              .futureCall(revokeCertificateRequest);
      Certificate certificateResponse = response.get();

      System.out.println("Certificate Revoked: " + certificateResponse.getName());
    }
  }
}

Python

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


import google.cloud.security.privateca_v1 as privateca_v1


def revoke_certificate(
    project_id: str,
    location: str,
    ca_pool_name: str,
    certificate_name: str,
) -> None:
    """
    Revoke an issued certificate. Once revoked, the certificate will become invalid and will expire post its lifetime.

    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: name for the CA pool which contains the certificate.
        certificate_name: name of the certificate to be revoked.
    """

    caServiceClient = privateca_v1.CertificateAuthorityServiceClient()

    # Create Certificate Path.
    certificate_path = caServiceClient.certificate_path(
        project_id, location, ca_pool_name, certificate_name
    )

    # Create Revoke Certificate Request and specify the appropriate revocation reason.
    request = privateca_v1.RevokeCertificateRequest(
        name=certificate_path, reason=privateca_v1.RevocationReason.PRIVILEGE_WITHDRAWN
    )
    result = caServiceClient.revoke_certificate(request=request)

    print("Certificate revoke result:", result)

次のステップ