מחיקת משאבים ב-Cloud KMS

במאמר הזה מוסבר איך למחוק באופן סופי משאבים של Cloud Key Management Service. אפשר למחוק את סוגי המשאבים הבאים של Cloud KMS:

  • אוספי מפתחות
  • מקשים
  • גרסאות של מפתחות

אי אפשר לבטל את הפעולה הזו. בקטע הרלוונטי במסמך הזה מפורטות המגבלות הספציפיות למשאבים.

ב-Cloud KMS, השמדה ומחיקה הן פעולות שונות:

  • השמדה: השבתה של גרסת מפתח באופן סופי, כולל השמדה בלתי הפיכה של חומר המפתח הבסיסי אחרי תקופת ההשמדה שצוינה. אי אפשר להשתמש בגרסת מפתח במצב DESTROYED לפעולות קריפטוגרפיות, והיא לא מחויבת יותר. אתם יכולים להשמיד גרסת מפתח ששימשה להצפנת נתונים כדי לגרוס באופן קריפטוגרפי נתונים שאתם רוצים שלא יהיה אפשר לשחזר אותם באופן סופי. גרסאות מפתח שהושמדו עדיין נכללות ברשימות של משאבי Cloud KMS.

  • מחיקה: הסרה של אוסף מפתחות, מפתח או גרסת מפתח מרשימות המשאבים של Cloud KMS במסוף Google Cloud , ב-Google Cloud CLI, ב-Cloud Key Management Service API ובספריות הלקוח. בפרויקטים עם הרבה אוספי מפתחות, מפתחות או גרסאות של מפתחות שכבר לא פעילים, המחיקה מייעלת את פעולות החיפוש וההצגה ברשימה. כשמוחקים אוסף מפתחות, אפשר להשתמש שוב בשם שלו. עם זאת, אי אפשר להשתמש שוב בשמות של מפתחות CryptoKey שנמחקו. כדי להציג רשימה של שמות של מפתחות CryptoKey שנמחקו ואי אפשר להשתמש בהם שוב, משתמשים ב-method‏ retiredResources.list.

לפני שמתחילים

כדי לקבל את ההרשאות שדרושות למחיקה ולצפייה במשאבים של Cloud KMS, בקשו מהאדמין להקצות לכם את התפקיד אדמין של Cloud KMS (roles/cloudkms.admin) ב-IAM במפתח. כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

זהו תפקיד מוגדר מראש שכולל את ההרשאות שנדרשות כדי למחוק משאבים של Cloud KMS ולצפות בהם. כדי לראות בדיוק אילו הרשאות נדרשות, אפשר להרחיב את הקטע ההרשאות הנדרשות:

ההרשאות הנדרשות

כדי למחוק ולראות משאבים של Cloud KMS, נדרשות ההרשאות הבאות:

  • כדי למחוק גרסת מפתח: cloudkms.cryptoKeyVersions.delete
  • כדי למחוק מפתח: cloudkms.cryptoKeys.delete
  • כדי למחוק אוסף מפתחות: cloudkms.keyRings.delete
  • כדי לראות את המשאבים שנמחקו:
    • cloudkms.retiredResources.get
    • cloudkms.retiredResources.list

יכול להיות שתקבלו את ההרשאות האלה באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש אחרים.

מחיקה של גרסת מפתח

אפשר למחוק גרסת מפתח אם היא במצב DESTROYED, IMPORT_FAILED או GENERATION_FAILED. אם גרסת המפתח יובאה, אפשר למחוק אותה רק אם הייבוא נכשל.

כדי למחוק גרסת מפתח באופן סופי:

המסוף

  1. נכנסים לדף Key Management במסוף Google Cloud .

    כניסה לדף Key Management

  2. לוחצים על השם של אוסף המפתחות שמכיל את המפתח ואת גרסת המפתח שרוצים למחוק.

  3. לוחצים על המפתח שמכיל את גרסת המפתח שרוצים למחוק.

  4. בטבלה Versions, מאתרים את גרסת המפתח שרוצים למחוק ולוחצים על More actions.

  5. בתפריט פעולות נוספות, לוחצים על מחיקה.

  6. בחלון האישור, מזינים את שם המפתח ולוחצים על Delete.

gcloud

כדי למחוק גרסת מפתח, מריצים את הפקודה הבאה:

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

מחליפים את מה שכתוב בשדות הבאים:

  • ‫KEY_VERSION: מספר גרסת המפתח שרוצים למחוק באופן סופי. גרסת המפתח שצוינה חייבת להיות במצב DESTROYED, IMPORT_FAILED או GENERATION_FAILED.
  • ‫LOCATION: המיקום ב-Cloud KMS שבו נמצא אוסף המפתחות.
  • ‫KEY_RING: השם של אוסף המפתחות שמכיל את המפתח.
  • ‫KEY_NAME: שם המפתח שמכיל את גרסת המפתח שרוצים למחוק באופן סופי.

Go

במאמר ספריות הלקוח של Cloud KMS מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Cloud KMS.

כדי לבצע אימות ב-Cloud KMS, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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. כדי למחוק גרסת מפתח, צריך להפעיל את ה-method‏ 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: מזהה הפרויקט שמכיל את אוסף המפתחות.
    • ‫LOCATION: המיקום ב-Cloud KMS שבו נמצא אוסף המפתחות.
    • ‫KEY_RING: השם של אוסף המפתחות שמכיל את המפתח.
    • ‫KEY_NAME: שם המפתח שמכיל את גרסת המפתח שרוצים למחוק באופן סופי.
    • ‫KEY_VERSION: מספר גרסת המפתח שרוצים למחוק באופן סופי. גרסת המפתח שצוינה חייבת להיות במצב DESTROYED, IMPORT_FAILED או GENERATION_FAILED.

    הפלט של הפקודה מחזיר Operation. תצטרכו את ה-name של הפעולה בשביל השלב הבא.

  2. כדי לוודא שגרסת המפתח נמחקה, אפשר להפעיל את ה-method‏ operations.get:

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

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫PROJECT_ID: מזהה הפרויקט שמכיל את אוסף המפתחות.
    • ‫LOCATION: המיקום ב-Cloud KMS שבו נמצא אוסף המפתחות.
    • ‫OPERATION_NAME: שם הפעולה שהוחזרה על ידי השיטה הקודמת.

    כשהפלט של ה-method הזו מראה שהערך של done הוא true, הפעולה הסתיימה. אם לא מצוין error, גרסת המפתח נמחקה באופן סופי.

מחיקת מפתח

אפשר למחוק מפתח אם הוא עומד בתנאים הבאים:

  • המפתח לא מכיל גרסאות מפתח שעדיין לא נמחקו.
  • לא מתוזמנת רוטציית מפתחות אוטומטית למפתח.
  • המפתח לא נוצר על ידי Cloud KMS Autokey.

כדי למחוק מפתח באופן סופי:

המסוף

  1. נכנסים לדף Key Management במסוף Google Cloud .

    כניסה לדף Key Management

  2. לוחצים על השם של אוסף המפתחות שמכיל את המפתח שרוצים למחוק.

  3. בשורה של המפתח שרוצים למחוק, לוחצים על Key actions ואז על Delete.

  4. בחלון האישור, מזינים את שם המפתח ולוחצים על Delete.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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. כדי למחוק מפתח, צריך לבצע קריאה ל-method‏ cryptoKey.delete. ה-method הזו מחזירה פעולה ממושכת שאפשר לדגום כדי לוודא שהמפתח נמחק.

    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: מזהה הפרויקט שמכיל את אוסף המפתחות.
    • ‫LOCATION: המיקום ב-Cloud KMS שבו נמצא אוסף המפתחות.
    • ‫KEY_RING: השם של אוסף המפתחות שמכיל את המפתח.
    • ‫KEY_NAME: שם המפתח שרוצים למחוק באופן סופי. המפתח לא יכול להכיל גרסאות מפתח שעדיין לא נמחקו, והוא לא יכול להיות מפתח שנוצר על ידי Autokey.

    הפלט של הפקודה מחזיר Operation. תצטרכו את ה-name של הפעולה בשביל השלב הבא.

  2. כדי לוודא שהמפתח נמחק, אפשר להפעיל את ה-method‏ operations.get:

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

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫PROJECT_ID: מזהה הפרויקט שמכיל את אוסף המפתחות.
    • ‫LOCATION: המיקום ב-Cloud KMS שבו נמצא אוסף המפתחות.
    • ‫OPERATION_NAME: שם הפעולה שהוחזר על ידי השיטה הקודמת.

    כשהפלט של השיטה הזו מראה שהערך של done הוא true, הפעולה הסתיימה. אם לא מצוין error, המפתח נמחק באופן סופי.

מחיקה של אוסף מפתחות

אפשר למחוק אוסף מפתחות אם הוא עומד בתנאים הבאים:

  • צריך למחוק את כל המפתחות באוסף המפתחות.
  • כל משימות הייבוא באוסף המפתחות צריכות להיות בתוקף.

כשמוחקים אוסף מפתחות, השם שלו הופך לזמין לשימוש חוזר תוך כ-5 עד 10 דקות.

כדי למחוק לצמיתות אוסף מפתחות:

המסוף

  1. נכנסים לדף Key Management במסוף Google Cloud .

    כניסה לדף Key Management

  2. בשורה של אוסף המפתחות שרוצים למחוק, לוחצים על Key ring actions ואז על Delete.

  3. בחלון האישור, מזינים את שם אוסף המפתחות ולוחצים על Delete.

gcloud

כדי למחוק אוסף מפתחות, מריצים את הפקודה הבאה:

gcloud kms keyrings delete KEY_RING \
    --location=LOCATION \

מחליפים את מה שכתוב בשדות הבאים:

  • ‫KEY_RING: השם של אוסף המפתחות שרוצים למחוק באופן סופי. אוסף המפתחות לא יכול להכיל מפתחות או משימות ייבוא במצב ACTIVE.
  • ‫LOCATION: המיקום ב-Cloud KMS שבו נמצא אוסף המפתחות.

API

  1. כדי למחוק אוסף מפתחות, צריך לבצע קריאה ל-method‏ keyRings.delete. ה-method הזו מחזירה פעולה ממושכת שאפשר לדגום כדי לוודא שאוסף המפתחות נמחק.

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

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫PROJECT_ID: מזהה הפרויקט שמכיל את אוסף המפתחות.
    • ‫LOCATION: המיקום ב-Cloud KMS שבו נמצא אוסף המפתחות.
    • ‫KEY_RING: השם של אוסף המפתחות שרוצים למחוק באופן סופי. אוסף המפתחות לא יכול להכיל מפתחות או משימות ייבוא במצב ACTIVE.

    הפלט של הפקודה מחזיר Operation. תצטרכו את ה-name של הפעולה בשביל השלב הבא.

  2. כדי לוודא שאוסף המפתחות נמחק, אפשר להפעיל את ה-method‏ operations.get:

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

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫PROJECT_ID: מזהה הפרויקט שמכיל את אוסף המפתחות.
    • ‫LOCATION: המיקום ב-Cloud KMS שבו נמצא אוסף המפתחות.
    • ‫OPERATION_NAME: שם הפעולה שהוחזר על ידי השיטה הקודמת.

    כשהפלט של השיטה הזו מראה שהערך של done הוא true, הפעולה הסתיימה. אם לא מצוין error, אוסף המפתחות נמחק באופן סופי.

הצגת השמות של משאבים שהוצאו משימוש

אי אפשר להשתמש שוב בשמות של מפתחות שנמחקו באותו פרויקט ב-Google Cloud . כך נמנע מצב שבו לשני מפתחות שונים יש את אותו מזהה משאב. השמות של המפתחות שנמחקו מאוחסנים באובייקטים של retiredResources. אפשר לשלוח שאילתה ל-retiredResources כדי לראות שמות שאי אפשר להשתמש בהם שוב למשאבים חדשים של Cloud KMS.

כדי לראות רשימה של כל המשאבים שהוצאו משימוש:

gcloud

מריצים את הפקודה הבאה:

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

מחליפים את מה שכתוב בשדות הבאים:

  • ‫LOCATION: המיקום שבו רוצים לראות את המשאבים שהוצאו משימוש.

Go

במאמר ספריות הלקוח של Cloud KMS מוסבר איך להתקין את ספריית הלקוח ולהשתמש בה ב-Cloud KMS.

כדי לבצע אימות ב-Cloud KMS, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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

משתמשים ב-method‏ 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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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, אתם צריכים להגדיר את Application Default Credentials. למידע נוסף, ראו הגדרת אימות לסביבת פיתוח מקומית.

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

משתמשים ב-method‏ 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: שם המשאב שרוצים לראות.

הפלט של השיטה כולל את resourceType, את deleteTime ואת מזהה המשאב המלא של המשאב שנמחק.

המאמרים הבאים