Cloud KMS リソースを削除する

このドキュメントでは、Cloud Key Management Service の鍵と鍵バージョンを完全に削除する方法について説明します。この操作は元に戻せません。

Cloud KMS では、破棄と削除は異なるオペレーションです。

  • 破棄: 鍵バージョンを永続的に無効にします。指定された破棄期間の後に、基盤となる鍵マテリアルを不可逆的に破棄します。DESTROYED 状態の鍵バージョンは、暗号オペレーションに使用できず、課金もされなくなります。データの暗号化に使用された鍵バージョンを破棄して、完全に復元できないようにしたいデータを暗号シュレッディングできます。破棄された鍵バージョンは、Cloud KMS リソースのリストに引き続き含まれます。

  • 削除: Google Cloud コンソール、Google Cloud CLI、Cloud Key Management Service API、クライアント ライブラリの Cloud KMS リソースのリストから、キーまたはキー バージョンを削除します。多くの鍵またはアクティブでない鍵バージョンがあるプロジェクトの場合、削除すると検索とリストのオペレーションが効率化されます。削除された CryptoKey 名は再利用できません。再利用できない削除済み CryptoKey 名のリストを表示するには、retiredResources.list メソッドを使用します。

始める前に

Cloud KMS リソースの削除と表示に必要な権限を取得するには、鍵に対する Cloud KMS 管理者 roles/cloudkms.admin)IAM ロールを付与するよう管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織に対するアクセス権の管理をご覧ください。

この事前定義ロールには、Cloud KMS リソースの削除と表示に必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。

必要な権限

Cloud KMS リソースを削除して表示するには、次の権限が必要です。

  • 鍵バージョンを削除するには: cloudkms.cryptoKeyVersions.delete
  • 鍵を削除するには: cloudkms.cryptoKeys.delete
  • 削除されたリソースを表示するには:
    • cloudkms.retiredResources.get
    • cloudkms.retiredResources.list

カスタムロールや他の事前定義ロールを使用して、これらの権限を取得することもできます。

鍵バージョンを削除する

鍵バージョンが DESTROYEDIMPORT_FAILED、または GENERATION_FAILED の状態の場合、その鍵バージョンを削除できます。鍵バージョンがインポートされた場合、インポートが失敗した場合にのみ削除できます。

鍵バージョンを完全に削除する手順は次のとおりです。

コンソール

  1. Google Cloud コンソールで、[鍵管理] ページに移動します。

    [鍵管理] に移動

  2. 削除する鍵と鍵バージョンを含むキーリングの名前をクリックします。

  3. 削除する鍵バージョンを含む鍵をクリックします。

  4. [バージョン] テーブルで、削除する鍵バージョンを見つけて、 [その他の操作] をクリックします。

  5. [その他の操作] メニューで、[削除] をクリックします。

  6. 確認プロンプトで、鍵名を入力して [削除] をクリックします。

gcloud

鍵バージョンを削除するには、次のコマンドを実行します。

gcloud kms keys versions delete KEY_VERSION \
    --location=LOCATION \
    --keyring=KEY_RING \
    --key=KEY_NAME

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

  • KEY_VERSION: 完全に削除する鍵バージョンの番号。指定された鍵バージョンは、DESTROYEDIMPORT_FAILED、または GENERATION_FAILED 状態である必要があります。
  • LOCATION: キーリングの Cloud KMS のロケーション
  • KEY_RING: 鍵を含むキーリングの名前。
  • KEY_NAME: 完全に削除する鍵バージョンを含む鍵の名前。

Go

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

import (
	"context"
	"fmt"
	"io"

	kms "cloud.google.com/go/kms/apiv1"
	"cloud.google.com/go/kms/apiv1/kmspb"
)

// deleteCryptoKeyVersion deletes a crypto key version. This action is permanent and cannot be undone. Once the key version is deleted, it will no longer exist.
func deleteCryptoKeyVersion(w io.Writer, name string) error {
	// name := "projects/my-project/locations/us-east1/keyRings/my-key-ring/cryptoKeys/my-key/cryptoKeyVersions/1"

	// Create the client.
	ctx := context.Background()
	client, err := kms.NewKeyManagementClient(ctx)
	if err != nil {
		return fmt.Errorf("failed to create kms client: %w", err)
	}
	defer client.Close()

	// Build the request.
	req := &kmspb.DeleteCryptoKeyVersionRequest{
		Name: name,
	}

	// Call the API.
	// Warning: This operation is permanent and cannot be undone.
	op, err := client.DeleteCryptoKeyVersion(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to delete crypto key version: %w", err)
	}

	// Wait for the operation to complete.
	if err := op.Wait(ctx); err != nil {
		return fmt.Errorf("failed to wait for delete crypto key version operation: %w", err)
	}

	fmt.Fprintf(w, "Deleted crypto key version: %s\n", req.Name)
	return nil
}

Java

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

import com.google.cloud.kms.v1.CryptoKeyVersionName;
import com.google.cloud.kms.v1.KeyManagementServiceClient;
import java.io.IOException;

public class DeleteKeyVersion {

  public void deleteKeyVersion() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String locationId = "us-east1";
    String keyRingId = "my-key-ring";
    String keyId = "my-key";
    String keyVersionId = "123";
    deleteKeyVersion(projectId, locationId, keyRingId, keyId, keyVersionId);
  }

  // deleteKeyVersion deletes a key version. This action is permanent and cannot be undone. Once the
  // key version is deleted, it will no longer exist.
  public void deleteKeyVersion(
      String projectId, String locationId, String keyRingId, String keyId, String keyVersionId)
      throws 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 "close" method on the client to
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
      // Build the key version name from the project, location, key ring, key,
      // and key version.
      CryptoKeyVersionName keyVersionName =
          CryptoKeyVersionName.of(projectId, locationId, keyRingId, keyId, keyVersionId);

      // Delete the key version.
      // Warning: This operation is permanent and cannot be undone.
      // Wait for the operation to complete.
      client.deleteCryptoKeyVersionAsync(keyVersionName).get();
      System.out.printf("Deleted key version: %s%n", keyVersionName.toString());
    } catch (Exception e) {
      System.err.printf("Failed to delete key version: %s%n", e.getMessage());
    }
  }
}

Python

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

from google.cloud import kms


def delete_key_version(
    project_id: str, location_id: str, key_ring_id: str, key_id: str, version_id: str
) -> None:
    """
    Delete the given key version. This action is permanent and cannot be undone.
    Once the key version is deleted, it will no longer exist.

    Args:
        project_id (str): Google Cloud project ID (e.g. 'my-project').
        location_id (str): Cloud KMS location (e.g. 'us-east1').
        key_ring_id (str): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
        key_id (str): ID of the key to use (e.g. 'my-key').
        version_id (str): ID of the key version to delete (e.g. '1').

    Returns:
        None

    """

    # Create the client.
    client = kms.KeyManagementServiceClient()

    # Build the key version name.
    key_version_name = client.crypto_key_version_path(
        project_id, location_id, key_ring_id, key_id, version_id
    )

    # Call the API.
    # Note: delete_crypto_key_version returns a long-running operation.
    # Warning: This operation is permanent and cannot be undone.
    operation = client.delete_crypto_key_version(request={"name": key_version_name})

    # Wait for the operation to complete.
    operation.result()

    print(f"Deleted key version: {key_version_name}")

API

  1. 鍵バージョンを削除するには、cryptoKeyVersions.delete メソッドを呼び出します。このメソッドは、キー バージョンが削除されたことを確認するためにポーリングできる長時間実行オペレーションを返します。

    curl "https://cloudkms.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME/cryptoKeyVersions/KEY_VERSION" \
    --request "DELETE" \
    --header "authorization: Bearer TOKEN"
    

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

    • PROJECT_ID: キーリングを含むプロジェクトの ID。
    • LOCATION: キーリングの Cloud KMS のロケーション
    • KEY_RING: 鍵を含むキーリングの名前。
    • KEY_NAME: 完全に削除する鍵バージョンを含む鍵の名前。
    • KEY_VERSION: 完全に削除する鍵バージョンの番号。指定された鍵バージョンは、DESTROYEDIMPORT_FAILED、または GENERATION_FAILED 状態である必要があります。

    コマンドの出力は Operation を返します。次のステップでは、オペレーションの name が必要になります。

  2. 鍵バージョンが削除されたことを確認するには、operations.get メソッドを呼び出します。

    curl "https://cloudkms.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_NAME" \
        --request "GET" \
        --header "authorization: Bearer TOKEN"
    

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

    • PROJECT_ID: キーリングを含むプロジェクトの ID。
    • LOCATION: キーリングの Cloud KMS のロケーション
    • OPERATION_NAME: 前のメソッドから返されたオペレーションの名前。

    このメソッドの出力で donetrue であることが示されたら、オペレーションは完了しています。error が示されていない場合、キー バージョンは完全に削除されています。

キーを削除する

次の条件を満たしている場合は、キーを削除できます。

  • 鍵に、まだ削除されていない鍵バージョンが含まれていません。
  • 鍵の自動ローテーションがスケジュールされていない。
  • 鍵が Cloud KMS Autokey によって作成されていない。

鍵を完全に削除する手順は次のとおりです。

コンソール

  1. Google Cloud コンソールで、[鍵管理] ページに移動します。

    [鍵管理] に移動

  2. 削除する鍵を含むキーリングの名前をクリックします。

  3. 次のいずれかの場所でキーを削除します。

    • キーリスト ページ: [KEY_RING」キーリングのキー] テーブルで、削除するキーを見つけて [キーアクション] をクリックし、[削除] をクリックします。
    • キーの詳細ページ: 削除するキーの名前をクリックして、[キーの詳細] ページを開きます。ページ上部の [削除] をクリックします。
  4. 確認プロンプトで、鍵名を入力して [削除] をクリックします。

gcloud

鍵を削除するには、次のコマンドを実行します。

gcloud kms keys delete KEY_NAME \
    --location=LOCATION \
    --keyring=KEY_RING

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

  • KEY_NAME: 完全に削除するキーの名前。鍵には、まだ削除されていない鍵バージョンが含まれておらず、Autokey によって作成された鍵であってはなりません。
  • LOCATION: キーリングの Cloud KMS のロケーション
  • KEY_RING: 鍵を含むキーリングの名前。

Go

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

import (
	"context"
	"fmt"
	"io"

	kms "cloud.google.com/go/kms/apiv1"
	"cloud.google.com/go/kms/apiv1/kmspb"
)

// deleteCryptoKey deletes a crypto key. This action is permanent and cannot be undone. Once the key is deleted, it will no longer exist.
func deleteCryptoKey(w io.Writer, name string) error {
	// name := "projects/my-project/locations/us-east1/keyRings/my-key-ring/cryptoKeys/my-key"

	// Create the client.
	ctx := context.Background()
	client, err := kms.NewKeyManagementClient(ctx)
	if err != nil {
		return fmt.Errorf("failed to create kms client: %w", err)
	}
	defer client.Close()

	// Build the request.
	req := &kmspb.DeleteCryptoKeyRequest{
		Name: name,
	}

	// Call the API.
	// Warning: This operation is permanent and cannot be undone.
	op, err := client.DeleteCryptoKey(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to delete crypto key: %w", err)
	}

	// Wait for the operation to complete.
	if err := op.Wait(ctx); err != nil {
		return fmt.Errorf("failed to wait for delete crypto key operation: %w", err)
	}

	fmt.Fprintf(w, "Deleted crypto key: %s\n", req.Name)
	return nil
}

Java

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

import com.google.cloud.kms.v1.CryptoKeyName;
import com.google.cloud.kms.v1.DeleteCryptoKeyMetadata;
import com.google.cloud.kms.v1.KeyManagementServiceClient;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

public class DeleteKey {

  public void deleteKey() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String locationId = "us-east1";
    String keyRingId = "my-key-ring";
    String keyId = "my-key";
    deleteKey(projectId, locationId, keyRingId, keyId);
  }

  // deleteKey deletes a crypto key. This action is permanent and cannot be undone. Once the key
  // is deleted, it will no longer exist.
  public void deleteKey(String projectId, String locationId, String keyRingId, String keyId)
      throws 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 "close" method on the client to
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
      // Build the key name from the project, location, key ring, and key.
      CryptoKeyName keyName = CryptoKeyName.of(projectId, locationId, keyRingId, keyId);

      // Delete the key.
      // Warning: This operation is permanent and cannot be undone.
      // Wait for the operation to complete.
      client.deleteCryptoKeyAsync(keyName).get();
      System.out.printf("Deleted key: %s%n", keyName.toString());
    } catch (Exception e) {
      System.err.printf("Failed to delete key: %s%n", e.getMessage());
    }
  }
}

Python

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

from google.cloud import kms


def delete_key(
    project_id: str, location_id: str, key_ring_id: str, key_id: str
) -> None:
    """
    Delete the given key. This action is permanent and cannot be undone. Once the
    key is deleted, it will no longer exist.

    Args:
        project_id (str): Google Cloud project ID (e.g. 'my-project').
        location_id (str): Cloud KMS location (e.g. 'us-east1').
        key_ring_id (str): ID of the Cloud KMS key ring (e.g. 'my-key-ring').
        key_id (str): ID of the key to use (e.g. 'my-key').

    Returns:
        None

    """

    # Create the client.
    client = kms.KeyManagementServiceClient()

    # Build the key name.
    key_name = client.crypto_key_path(project_id, location_id, key_ring_id, key_id)

    # Call the API.
    # Note: delete_crypto_key returns a long-running operation.
    # Warning: This operation is permanent and cannot be undone.
    operation = client.delete_crypto_key(request={"name": key_name})

    # Wait for the operation to complete.
    operation.result()

    print(f"Deleted key: {key_name}")

API

  1. キーを削除するには、cryptoKey.delete メソッドを呼び出します。このメソッドは、キーが削除されたことを確認するためにポーリングできる長時間実行オペレーションを返します。

    curl "https://cloudkms.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/KEY_NAME" \
    --request "DELETE" \
    --header "authorization: Bearer TOKEN"
    

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

    • PROJECT_ID: キーリングを含むプロジェクトの ID。
    • LOCATION: キーリングの Cloud KMS のロケーション
    • KEY_RING: 鍵を含むキーリングの名前。
    • KEY_NAME: 完全に削除するキーの名前。鍵には、まだ削除されていない鍵バージョンが含まれておらず、Autokey によって作成された鍵であってはなりません。

    コマンドの出力は Operation を返します。次のステップでは、オペレーションの name が必要になります。

  2. キーが削除されたことを確認するには、operations.get メソッドを呼び出します。

    curl "https://cloudkms.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_NAME" \
        --request "GET" \
        --header "authorization: Bearer TOKEN"
    

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

    • PROJECT_ID: キーリングを含むプロジェクトの ID。
    • LOCATION: キーリングの Cloud KMS のロケーション
    • OPERATION_NAME: 前のメソッドで返されたオペレーションの名前。

    このメソッドの出力で donetrue と表示されたら、オペレーションは完了しています。error が示されていない場合、キーは完全に削除されています。

廃止されたリソースの名前を表示する

削除されたキーの名前は、同じGoogle Cloud プロジェクトで再利用できません。これにより、2 つの異なるキーが同じリソース識別子を持つことを防ぎます。削除された鍵の名前は retiredResources オブジェクトに保存されます。retiredResources をクエリして、新しい Cloud KMS リソースに再利用できない名前を表示できます。

廃止されたすべてのリソースのリストを表示する手順は次のとおりです。

gcloud

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

gcloud kms retired-resources list \
    --location=LOCATION

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

  • LOCATION: 廃止されたリソースを表示するロケーション。

Go

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

import (
	"context"
	"fmt"
	"io"

	kms "cloud.google.com/go/kms/apiv1"
	kmspb "cloud.google.com/go/kms/apiv1/kmspb"
	"google.golang.org/api/iterator"
)

// listRetiredResources lists retired resources.
func listRetiredResources(w io.Writer, parent string) error {
	// parent := "projects/my-project/locations/us-east1"

	ctx := context.Background()
	client, err := kms.NewKeyManagementClient(ctx)
	if err != nil {
		return fmt.Errorf("failed to create kms client: %w", err)
	}
	defer client.Close()

	// Build the request.
	req := &kmspb.ListRetiredResourcesRequest{
		Parent: parent,
	}

	// Call the API.
	it := client.ListRetiredResources(ctx, req)

	// Iterate over the results.
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("failed to list retired resources: %w", err)
		}

		fmt.Fprintf(w, "Retired resource: %s\n", resp.Name)
	}
	return nil
}

Java

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

import com.google.cloud.kms.v1.KeyManagementServiceClient;
import com.google.cloud.kms.v1.LocationName;
import com.google.cloud.kms.v1.RetiredResource;
import java.io.IOException;

public class ListRetiredResources {

  public void listRetiredResources() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String locationId = "us-east1";
    listRetiredResources(projectId, locationId);
  }

  // List retired resources in a specific project and location.
  public void listRetiredResources(String projectId, String locationId)
      throws 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 "close" method on the client to
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
      // Build the location name from the project and location.
      LocationName locationName = LocationName.of(projectId, locationId);

      // List the retired resources.
      for (RetiredResource resource : client.listRetiredResources(locationName).iterateAll()) {
        System.out.printf("Retired resource: %s%n", resource.getName());
      }
    }
  }
}

Python

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

from typing import List

from google.cloud import kms


def list_retired_resources(project_id: str, location_id: str) -> List[kms.RetiredResource]:
    """
    List the retired resources in a location.

    Args:
        project_id (str): Google Cloud project ID (e.g. 'my-project').
        location_id (str): Cloud KMS location (e.g. 'us-east1').

    Returns:
        list[kms.RetiredResource]: The list of retired resources.
    """

    # Create the client.
    client = kms.KeyManagementServiceClient()

    # Build the parent location name.
    parent = client.common_location_path(project_id, location_id)

    # Call the API.
    # The API paginates, but the Python client library handles that for us.
    resources_list = list(client.list_retired_resources(request={"parent": parent}))

    # Iterate over the resources and print them.
    for resource in resources_list:
        print(f"Retired resource: {resource.name}")

    return resources_list

API

retiredResources.list メソッドを使用します。

curl "https://cloudkms.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/retiredResources/" \
    --request "GET" \
    --header "authorization: Bearer TOKEN"

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

  • PROJECT_ID: 廃止されたリソースを表示するプロジェクトの識別子。
  • LOCATION: 廃止されたリソースを表示するロケーション。

個々の廃止されたリソースのメタデータを表示する手順は次のとおりです。

gcloud

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

gcloud kms retired-resources describe RETIRED_RESOURCE \
    --location=LOCATION

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

  • RETIRED_RESOURCE: 表示するリソースの名前。
  • LOCATION: 廃止されたリソースを表示するロケーション。

Go

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

import (
	"context"
	"fmt"
	"io"

	kms "cloud.google.com/go/kms/apiv1"
	kmspb "cloud.google.com/go/kms/apiv1/kmspb"
)

// getRetiredResource gets a retired resource.
func getRetiredResource(w io.Writer, name string) error {
	// name := "projects/my-project/locations/us-east1/retiredResources/my-retired-resource"

	ctx := context.Background()
	client, err := kms.NewKeyManagementClient(ctx)
	if err != nil {
		return fmt.Errorf("failed to create kms client: %w", err)
	}
	defer client.Close()

	// Build the request.
	req := &kmspb.GetRetiredResourceRequest{
		Name: name,
	}

	// Call the API.
	result, err := client.GetRetiredResource(ctx, req)
	if err != nil {
		return fmt.Errorf("failed to get retired resource: %w", err)
	}

	fmt.Fprintf(w, "Got retired resource: %s\n", result.Name)
	return nil
}

Java

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

import com.google.cloud.kms.v1.KeyManagementServiceClient;
import com.google.cloud.kms.v1.RetiredResource;
import com.google.cloud.kms.v1.RetiredResourceName;
import java.io.IOException;

public class GetRetiredResource {

  public void getRetiredResource() throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String locationId = "us-east1";
    String retiredResourceId = "my-retired-resource-id";
    getRetiredResource(projectId, locationId, retiredResourceId);
  }

  // Get the retired resource.
  public void getRetiredResource(
      String projectId, String locationId, String retiredResourceId)
      throws 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 "close" method on the client to
    // safely clean up any remaining background resources.
    try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
      // Build the retired resource name from the project, location, and retired resource id.
      RetiredResourceName name = RetiredResourceName.of(projectId, locationId, retiredResourceId);

      // Get the retired resource.
      RetiredResource response = client.getRetiredResource(name);
      System.out.printf("Retired resource: %s%n", response.getName());
    }
  }
}

Python

Cloud KMS 用のクライアント ライブラリをインストールして使用する方法については、Cloud KMS クライアント ライブラリをご覧ください。

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

from google.cloud import kms


def get_retired_resource(
    project_id: str, location_id: str, retired_resource_id: str
) -> kms.RetiredResource:
    """
    Get the details of a retired resource.

    Args:
        project_id (str): Google Cloud project ID (e.g. 'my-project').
        location_id (str): Cloud KMS location (e.g. 'us-east1').
        resource_id (str): ID of the retired resource to get.

    Returns:
        kms.RetiredResource: The requested retired resource.

    """

    # Create the client.
    client = kms.KeyManagementServiceClient()

    # Build the retired resource name.
    # Note: Retired resources are tied to a Location, not a KeyRing.
    # The name is like projects/{project}/locations/{location}/retiredResources/{id}
    name = client.retired_resource_path(project_id, location_id, retired_resource_id)

    # Call the API.
    response = client.get_retired_resource(request={"name": name})

    print(f"Got retired resource: {response.name}")
    return response

API

retiredResources.get メソッドを使用します。

curl "https://cloudkms.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/retiredResources/RETIRED_RESOURCE" \
    --request "GET" \
    --header "authorization: Bearer TOKEN"

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

  • PROJECT_ID: 廃止されたリソースを表示するプロジェクトの識別子。
  • LOCATION: 廃止されたリソースを表示するロケーション。
  • RETIRED_RESOURCE: 表示するリソースの名前。

メソッドの出力には、resourceTypedeleteTime、削除されたリソースの完全なリソース識別子が含まれます。

次のステップ