証明書を取り消す

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

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 日間有効です。新しい CRL は、新しい証明書失効から 15 分以内に公開されます。

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

コンソール

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

    Certificate Authority Service

  2. 変更する CA プールの CA の名前をクリックします。

  3. [認証局] ページで、[ポリシーを編集] をクリックします。

  4. 表示される左パネルで、[公開オプション] の下にある [発行済み証明書の証明書失効リストのアクセス URL を公開する] をクリックします。

gcloud

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

gcloud privateca pools update POOL_ID \
  --publish-crl

POOL_ID は、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 \
      --reason REVOCATION_REASON
    

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

    • CERT_ID: 取り消す証明書の一意の識別子。
    • POOL_ID: 証明書を発行した 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 \
      --reason REVOCATION_REASON
    

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

    • SERIAL_NUMBER: 証明書のシリアル番号。
    • POOL_ID: 証明書を発行した 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)

次のステップ