Confidential Space イメージは、Confidential VM インスタンスで実行される単一目的の最小限の OS です。永続ストレージを使用せずに、単一のワークロードを 1 回だけ実行するように設計されています。このワークロードは、Docker を使用して Confidential Space イメージの上にレイヤ化されます。
Confidential Space イメージは、Container-Optimized OS の既存のセキュリティ強化機能に基づいて構築され、次のメリットが追加されています。
整合性保護により暗号化されたディスク パーティション
認証済みの暗号化されたネットワーク接続
さまざまなブート測定
リモート アクセスとクラウド固有のツールの無効化
イメージの種類
Confidential Space イメージは、次の 2 つのバリアントで利用可能です。
本番環境: 本番環境イメージは、実際の本番環境データを使用して実際の本番環境ワークロードを実行するために使用されます。ワークロード オペレーターが処理されたデータにアクセスできないようにロックされています。詳細については、Confidential Space のセキュリティの概要をご覧ください。
デバッグ: デバッグ イメージは、非本番環境データでワークロードをテストするために使用されます。デバッグ イメージで SSH が有効になっており、オペレーターはワークロードを実行する VM への root アクセス権を持っています。デバッグ イメージを実行している VM は、ワークロードの完了後に停止しません。
使用するイメージタイプは、ワークロードをデプロイするときに設定できます。
Confidential Space イメージを表示する
利用可能な Confidential Space イメージを表示するには、次の gcloud コマンドを使用します。
gcloud compute images list \
--project=confidential-space-images \
--no-standard-images
次のフラグを使用すると、結果で返される画像を変更できます。
本番環境のイメージを表示するには、
--filter="family~'confidential-space$'"フラグを追加します。--filter="family~'confidential-space-debug$'"フラグを追加して、デバッグ画像を表示します。
非推奨のイメージを表示する
次のコマンドを実行して、非推奨のイメージを結果に含めます。また、意思決定に役立つ追加のフィールドも表示します。
gcloud compute images list \
--project=confidential-space-images \
--no-standard-images \
--show-deprecated \
--filter="name ~ '^confidential-space-[0-9]{6}$'" \
--format="table(
name,
creationTimestamp.date('%Y-%m-%d'):label=CREATION_DATE,
status,
description.sub('.*COS: ', '').sub(',.*', ''):label=COS_VERSION,
deprecated.state:label=STATE,
deprecated.deprecated:label=DEPRECATE_ON,
deprecated.obsolete:label=OBSOLETE_ON,
deprecated.replacement
)"
成功したときのレスポンスは次のようになります。
NAME CREATION_DATE STATUS COS_VERSION STATE DEPRECATE_ON OBSOLETE_ON REPLACEMENT
confidential-space-230600 2023-06-09 READY cos-dev-109-17637-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-230901
confidential-space-230900 2023-09-17 READY cos-dev-109-17637-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-230600
confidential-space-230901 2023-10-02 READY cos-dev-113-17877-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-231001
confidential-space-231001 2023-11-01 READY cos-dev-113-17965-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-231100
confidential-space-231100 2023-11-17 READY cos-dev-113-18026-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-231200
confidential-space-231200 2023-12-04 READY cos-dev-113-18054-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-231201
confidential-space-231201 2023-12-15 READY cos-dev-113-18059-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-240200
confidential-space-240200 2024-02-28 READY cos-dev-113-18146-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-240402
confidential-space-240402 2024-04-22 READY cos-dev-117-18342-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-240500
confidential-space-240500 2024-05-30 READY cos-dev-117-18374-0-0 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-240700
confidential-space-240700 2024-07-30 READY cos-113-18244-85-54 DEPRECATED https://www.googleapis.com/compute/v1/projects/confidential-space-images/global/images/confidential-space-240800
confidential-space-240800 2024-09-03 READY cos-113-18244-151-14
confidential-space-240900 2024-10-01 READY cos-113-18244-151-80
confidential-space-241000 2024-10-18 READY cos-113-18244-151-96
...
Confidential Space イメージのライフサイクル
Confidential Space イメージ ファミリーを使用して Confidential VM を作成すると、最新バージョンの Confidential Space イメージが使用されます。ワークロードの完了時に常に Confidential VMs を削除し、ワークロードを実行するたびに新しい VM を作成すると、イメージを確実に最新の状態にすることができます。
ただし、長時間実行されるワークロードや、過去に作成された VM で実行されるワークロードでは、Confidential Space イメージの古いバージョンが使用されるリスクがあり、セキュリティの脆弱性が生じる可能性があります。
これを軽減するために、データ共同編集者はサポート属性を使用して、VM で実行されている本番環境の Confidential Space イメージ バージョンが最新かどうかを確認し、合格しない場合はデータへのアクセスを拒否できます。Confidential Space のデバッグ イメージにはサポート属性が設定されていません。
次の表に、本番環境の Confidential Space イメージに存在するサポート属性を示します。
| サポート属性 | 説明 |
|---|---|
|
|
イメージの有効期間: 約 1 か月。この後、 これは最新バージョンの Confidential Space イメージであり、脆弱性をサポートし、モニタリングします。
長時間実行されるワークロードの場合、証明書ポリシーの一部として |
|
|
イメージの有効期間: 約 6 か月。2027 年 4 月 1 日以降、イメージの有効期間が終了すると、
まれに、通常の 6 か月のサポート期間中に |
USABLE |
gcloud compute images describe confidential-space-240800 \ --format=json \ --project=confidential-space-images |
EXPERIMENTAL |
この属性のみを持つイメージは、プレビュー機能を使用します。
|
Confidential Space イメージは最新の状態に保つことをおすすめします。Confidential Space イメージを更新する方法については、 Confidential Space イメージを更新するをご覧ください。
非推奨のイメージをモニタリングする
非推奨または非推奨予定の Confidential Space イメージを実行している VM インスタンスをモニタリングするには、Cloud Scheduler ジョブで定期的に実行される Cloud Run functions の関数をデプロイします。その後、イメージが非推奨になったときにアラートを送信するように Cloud Logging 通知を設定できます。
Cloud Run 関数をデプロイして非推奨のイメージを確認する
Cloud Run functions の関数を設定するには、次の操作を行います。
Cloud Run で、[サービス] ページに移動します。
[関数を作成] をクリックします。
[サービス名] ボックスに、関数の名前を入力します。
関数を実行するリージョンを選択します。
[ランタイム] を最新バージョンの Go に設定します。
[認証] を [認証が必要] に設定します。
[Ingress] を [Internal] に設定します。
[コンテナ、ネットワーキング、セキュリティ] セクションを開きます。
[コンテナ] タブで、[メモリ] を [128 MiB] に設定します。
[セキュリティ] タブで、[サービス アカウント] ボックスをクリックします。
[サービス アカウントを新規作成] をクリックします。
[サービス アカウント名] ボックスに名前を入力します。
[作成] をクリックします。
Compute 閲覧者ロールを追加し、[完了] をクリックします。
[作成] をクリックします。
関数が読み込まれたら、[ソース] タブで [関数のエントリ ポイント] を
DeprecationCheckに設定します。function.goの内容を次のコードで上書きします。// Package imagechecker provides a function to check for deprecated CS images. package imagechecker import ( "context" "encoding/json" "fmt" "log" "log/slog" "net/http" "regexp" "strings" "time" "cloud.google.com/go/compute/metadata" "google.golang.org/api/compute/v1" "github.com/GoogleCloudPlatform/functions-framework-go/functions" ) const ( sourceImageProject = "confidential-space-images" deprecationValueFmt = "2006-01-02" ) // CS Images have the format confidential-space-.*. var prodImageNameRegex = regexp.MustCompile(`^confidential-space-.*`) // VMInfo represents the information logged about an VM instance of note. type VMInfo struct { Name string `json:"instance_name"` Zone string `json:"instance_zone"` ImageName string `json:"image_name"` DeprecationDate string `json:"image_deprecation_date,omitempty"` ObsoleteDate string `json:"image_obsolete_date,omitempty"` } // VMList represents a list of notable VMs and their relevance. type VMList struct { Description string `json:"description"` Instances []VMInfo `json:"instances"` } // LogPayload is the payload for Cloud Logs written by this job. type LogPayload struct { Message string `json:"message"` Obsolete *VMList `json:"vms_obsolete"` ObsoleteWarning *VMList `json:"vms_obsolete_warning"` Deprecated *VMList `json:"vms_deprecated"` DeprecationWarning *VMList `json:"vms_deprecation_warning"` } // LogEntry represents a Cloud Logging entry. type LogEntry struct { Message string `json:"message"` Severity string `json:"severity"` // Special field for Cloud Logging. Payload *LogPayload `json:"payload,omitempty"` ProjectID string `json:"projectId"` } func init() { log.SetFlags(0) functions.HTTP("DeprecationCheck", checkForDeprecations) } func checkForDeprecations(w http.ResponseWriter, r *http.Request) { ctx := context.Background() // Retrieve project ID. projectID, err := metadata.ProjectIDWithContext(ctx) if err != nil { errMsg := fmt.Sprintf("Failed to get project ID from metadata server: %v", err) logError(projectID, errMsg) http.Error(w, errMsg, http.StatusInternalServerError) return } slog.Info(fmt.Sprintf("Checking for project: %s", projectID)) // Configure compute service. computeService, err := compute.NewService(ctx) if err != nil { msg := fmt.Sprintf("Failed to create compute service: %v", err) logError(projectID, msg) http.Error(w, msg, http.StatusInternalServerError) return } var obsoleteVMs []VMInfo // Will contain VMs whose images are obsolete. var obsoleteWarningVMs []VMInfo // Will contain VMs using an image that will be obsolete within a month. var deprecatedVMs []VMInfo // Will contain VMs whose images are deprecated. var deprecationWarningVMs []VMInfo // Will contain VMs using an image that will be deprecated within a month. now := time.Now() pageFunc := instancesPageFunc(ctx, projectID, &obsoleteVMs, &obsoleteWarningVMs, &deprecatedVMs, &deprecationWarningVMs, now, computeService) if err = computeService.Instances.AggregatedList(projectID).Pages(ctx, pageFunc); err != nil { msg := fmt.Sprintf("Failed to list instances: %v", err) logError(projectID, msg) http.Error(w, msg, http.StatusInternalServerError) return } if len(obsoleteVMs) == 0 && len(obsoleteWarningVMs) == 0 && len(deprecatedVMs) == 0 && len(deprecationWarningVMs) == 0 { returnmsg := "No VMs using obsolete or deprecated images found." logEntry := LogEntry{ Message: "Confidential Space Image Deprecation Alert - No Issues Detected", Severity: "INFO", ProjectID: projectID, Payload: &LogPayload{Message: returnmsg}, } writeLog(logEntry) w.WriteHeader(http.StatusOK) _, err := w.Write([]byte(returnmsg)) if err != nil { http.Error(w, fmt.Sprintf("Failed to write HTTP response: %v", err), http.StatusInternalServerError) } return } respPayload := &LogPayload{ Message: "The following instances are using Confidential Space images that are obsolete, deprecated, or will be obsolete/deprecated soon. Obsolete and deprecated images are no longer maintained and scanned for vulnerabilities. Please review these instances and update their boot images as needed.", } if len(obsoleteVMs) > 0 { respPayload.Obsolete = &VMList{ Description: "Instances using CS images that are obsolete.", Instances: obsoleteVMs, } } if len(obsoleteWarningVMs) > 0 { respPayload.ObsoleteWarning = &VMList{ Description: "Instances using CS images that will be obsolete within a month.", Instances: obsoleteWarningVMs, } } if len(deprecatedVMs) > 0 { respPayload.Deprecated = &VMList{ Description: "Instances using CS images that are deprecated.", Instances: deprecatedVMs, } } if len(deprecationWarningVMs) > 0 { respPayload.DeprecationWarning = &VMList{ Description: "Instances using CS images that will be deprecated within a month.", Instances: deprecationWarningVMs, } } entry := LogEntry{ Message: "Confidential Space Image Deprecation Alert", Severity: "WARNING", ProjectID: projectID, Payload: respPayload, } writeLog(entry) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) err = json.NewEncoder(w).Encode(respPayload) if err != nil { http.Error(w, fmt.Sprintf("Failed to write HTTP response: %v", err), http.StatusInternalServerError) return } } func instancesPageFunc(ctx context.Context, projectID string, obsoleteVMs *[]VMInfo, obsoleteWarningVMs *[]VMInfo, deprecatedVMs *[]VMInfo, deprecationWarningVMs *[]VMInfo, now time.Time, computeService *compute.Service) func(list *compute.InstanceAggregatedList) error { return func(list *compute.InstanceAggregatedList) error { for _, instanceList := range list.Items { for _, instances := range instanceList.Instances { sourceImage, err := getSourceImage(ctx, projectID, instances, computeService) if err != nil { slog.Warn(fmt.Sprintf("Failed to get source image for instance %s: %v", instances.Name, err)) continue } // Skip instance if not using a CS prod image. imageProject, imageName := parseImage(sourceImage) if imageProject != sourceImageProject || !prodImageNameRegex.MatchString(imageName) { continue } // Get deprecation status ("deprecate-on" / "obsolete-on" / state settings). depStatus, err := getDeprecationStatus(ctx, imageProject, imageName, computeService) if err != nil { slog.Error(fmt.Sprintf("Failed to get deprecation status for image %s in project %s: %v", imageName, imageProject, err)) continue } if depStatus == nil { continue } vm := VMInfo{ Name: instances.Name, Zone: getResourceName(instances.Zone), ImageName: imageName, } var depTime, obsTime time.Time if depStatus.Deprecated != "" { depTime, err = parseDeprecationDate(depStatus.Deprecated) if err != nil { slog.Error(fmt.Sprintf("Failed to parse deprecation date %s for image %s in project %s: %v", depStatus.Deprecated, imageName, imageProject, err)) continue } vm.DeprecationDate = depTime.Format(deprecationValueFmt) } if depStatus.Obsolete != "" { obsTime, err = parseDeprecationDate(depStatus.Obsolete) if err != nil { slog.Error(fmt.Sprintf("Failed to parse obsolete date %s for image %s in project %s: %v", depStatus.Obsolete, imageName, imageProject, err)) continue } vm.ObsoleteDate = obsTime.Format(deprecationValueFmt) } // Determine whether instance image is obsolete, upcoming obsolete, deprecated, or upcoming deprecated. if depStatus.State == "OBSOLETE" || (!obsTime.IsZero() && isPast(obsTime, now)) { *obsoleteVMs = append(*obsoleteVMs, vm) } else if !obsTime.IsZero() && isWarning(obsTime, now) { *obsoleteWarningVMs = append(*obsoleteWarningVMs, vm) } else if depStatus.State == "DEPRECATED" || (!depTime.IsZero() && isPast(depTime, now)) { *deprecatedVMs = append(*deprecatedVMs, vm) } else if !depTime.IsZero() && isWarning(depTime, now) { *deprecationWarningVMs = append(*deprecationWarningVMs, vm) } } } return nil } } func getSourceImage(ctx context.Context, projectID string, instance *compute.Instance, service *compute.Service) (string, error) { for _, disk := range instance.Disks { // Only check boot disk. if disk.Boot { // Retrieve source image for disk. diskName := getResourceName(disk.Source) zone := getResourceName(instance.Zone) d, err := service.Disks.Get(projectID, zone, diskName).Context(ctx).Do() if err != nil { slog.Warn(fmt.Sprintf("Failed to get details for disk %s in zone %s: %v", diskName, zone, err)) continue } if d.SourceImage != "" { return d.SourceImage, nil } } } return "", fmt.Errorf("no suitable source image name found for instance %s", instance.Name) } func getDeprecationStatus(ctx context.Context, imageProject, imageName string, service *compute.Service) (*compute.DeprecationStatus, error) { image, err := service.Images.Get(imageProject, imageName).Context(ctx).Do() if err != nil { slog.Warn(fmt.Sprintf("Failed to get details for image %s in project %s: %v", imageName, imageProject, err)) return nil, err } if image.Deprecated == nil || (image.Deprecated.Deprecated == "" && image.Deprecated.Obsolete == "" && image.Deprecated.State == "") { // Skip if no deprecation/obsolete setting. slog.Warn(fmt.Sprintf("Image %s in project %s has no deprecate-on or obsolete-on setting", imageName, imageProject)) return nil, nil } return image.Deprecated, nil } func parseDeprecationDate(dateStr string) (time.Time, error) { formats := []string{ time.RFC3339, time.RFC3339Nano, "2006-01-02T15:04:05", "2006-01-02", "2006-01", } for _, format := range formats { if t, err := time.Parse(format, dateStr); err == nil { return t, nil } } return time.Time{}, fmt.Errorf("unable to parse %q as a valid deprecation date", dateStr) } func isPast(obsTime time.Time, now time.Time) bool { return !obsTime.After(now) } func isWarning(targetTime time.Time, now time.Time) bool { warningWindowEnd := now.AddDate(0, 1, 0) return targetTime.After(now) && !targetTime.After(warningWindowEnd) } func parseImage(image string) (string, string) { parts := strings.Split(image, "/") var project, imageName string for i, part := range parts { if part == "projects" && i+1 < len(parts) { project = parts[i+1] } else if part == "images" && i+1 < len(parts) { imageName = parts[i+1] } } slog.Info(fmt.Sprintf("Source image project: %s, name: %s", project, imageName)) return project, imageName } // getResourceName extracts the last part of a GCP resource URL. func getResourceName(url string) string { parts := strings.Split(url, "/") return parts[len(parts)-1] } func writeLog(entry LogEntry) { jsonData, err := json.Marshal(entry) if err != nil { slog.Warn(fmt.Sprintf("Error marshaling final log: %v", err)) slog.Warn(fmt.Sprintf("Log contents: %v", entry)) return } fmt.Println(string(jsonData)) } func logError(projectID, errMsg string) { entry := LogEntry{ Message: "Confidential Space Image Deprecation Alert - Job Failed", Severity: "ERROR", ProjectID: projectID, Payload: &LogPayload{ Message: errMsg, }, } writeLog(entry) }go.modの内容を次のコードで上書きします。module example.com/imagechecker require ( cloud.google.com/go/compute/metadata v0.5.0 github.com/GoogleCloudPlatform/functions-framework-go v1.9.0 google.golang.org/api v0.264.0 )[保存して再デプロイ] をクリックします。
サービスが正常にデプロイされたら、後で使用するために、関数名の近くにある URL をメモします。
Cloud Scheduler ジョブの設定
Cloud Run functions の関数を実行する Cloud Scheduler ジョブを設定するには、次の操作を行います。
まず、スケジュールされたジョブを実行するサービス アカウントを作成します。これを行うには、[サービス アカウントの作成] ページに移動します。
[サービス アカウント名] ボックスに、サービス アカウント名を追加します。
後で使用できるように、サービス アカウント ID をメモしておきます。
[作成して続行] をクリックします。
Cloud Run 起動元ロールを追加します。
[完了] をクリックします。
まだ有効にしていない場合は、Cloud Scheduler API を有効にします。
Cloud Scheduler で、[ジョブ] ページに移動します。
[ジョブを作成] をクリックします。
[名前] フィールドに、ジョブの名前を入力します。
スケジュールされたジョブを実行するリージョンを選択します。
[頻度] フィールドに cron スケジュールを追加します。たとえば、
0 9 1 * *は毎月 1 日の午前 9 時にジョブを実行します。スケジュールのタイムゾーンを設定します。
[続行] をクリックします。
[ターゲット タイプ] を [HTTP] に設定します。
[URL] を、作成した Cloud Run 関数の URL に設定します。
[Auth ヘッダー] ボックスで、[OIDC トークンを追加] を選択します。
[サービス アカウント] ボックスをクリックし、先ほど作成したサービス アカウントの ID を入力します。
オーディエンスを、作成した Cloud Run functions の関数の URL に設定します。
[作成] をクリックします。
ジョブをテストするには、 [アクション] をクリックし、[強制実行] をクリックします。
ログベースのアラートを設定する
非推奨のイメージに関するログベースのアラートを設定するには、次の操作を行います。
[ログ エクスプローラ] ページに移動
[クエリを表示] を有効にします。
クエリボックスに、次のいずれかの Logging Query Language クエリを入力します。
サポート終了予定の VM が見つかりました。
resource.type="cloud_run_revision" severity="WARNING" jsonPayload.message="Confidential Space Image Deprecation Alert"非推奨チェックの失敗:
resource.type="cloud_run_revision" severity="ERROR" jsonPayload.message="Confidential Space Image Deprecation Alert - Job Failed"VM フリートで非推奨のイメージが検出されませんでした。
resource.type="cloud_run_revision" severity="INFO" jsonPayload.message="Confidential Space Image Deprecation Alert - No Issues Detected"
[クエリを実行] をクリックします。
結果の近くにある [アクション] をクリックします。
[ログアラートを作成] をクリックし、入力したクエリに基づいてアラート ポリシーを作成するプロセスを完了します。
Confidential Space イメージを更新する
Confidential Space イメージを最新の状態に保ち、中断を回避するには、Confidential Space ワークロードを起動するたびに新しい Confidential VM インスタンスを作成することをおすすめします。Confidential Space イメージに基づいて新しいインスタンスを作成するたびに、最新の Confidential Space イメージがプロビジョニングされます。
Confidential Space ワークロードの実行ごとに新しい Confidential VMs インスタンスを作成できない場合は、証明書利用者によって構成された構成証明ポリシーのサポート属性に基づいて、Confidential VMs インスタンスを再作成するメンテナンスの時間枠を定義することをおすすめします。
LATESTサポート属性を必要とする証明書ポリシーを設定している場合は、Confidential Space イメージを少なくとも毎月更新する必要があります。STABLEサポート属性を必要とする証明書ポリシーを設定している場合は、少なくとも 6 か月ごとに Confidential Space イメージを更新する必要があります。
次のいずれかを使用すると、VM の再作成を簡単に行うことができます。
これらの機能を設定する方法については、自動スケーリング、自動修復、イメージ更新を使用して MIG で Confidential Space ワークロードをデプロイするをご覧ください。
長時間実行されるワークロード
長時間実行されるワークロード中に、Confidential Space イメージが非推奨になるか、取り消される可能性があります。STABLE Confidential Space サポート属性を要求するように証明書ポリシーを設定し、ワークロードで使用している Confidential Space イメージが非推奨または取り消されている場合、ワークロードを実行している Confidential VM インスタンスは証明書を渡しません。中断を回避するには、長時間実行されるワークロードを、再開を念頭に置いて設計し、状態を安全に管理する必要があります。