arrow_back

運用 Gemini 做出安全性決策

登录 加入
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

運用 Gemini 做出安全性決策

Lab 45 分钟 universal_currency_alt 1 积分 show_chart 入门级
Test and share your knowledge with our community!
done
Get access to over 700 hands-on labs, skill badges, and courses

總覽

Gemini 版 Google Cloud 是全天候運作的 AI 協作工具,無論使用者的技能程度為何,都能在需要時獲得協助。在本研究室中,您將瞭解如何使用 Security Command Center 的 Gemini 功能,找出及修正 Google Cloud 環境中的安全性設定錯誤。

注意:Duet AI 已更名為 Gemini,這是我們的新一代模型,本研究室的內容也已據此更新。參考研究室指示時,在使用者介面或說明文件中若有任何內容提及 Duet AI,請視為 Gemini。 注意:Gemini 仍處於早期技術階段,因此可能會輸出看似合理卻與事實不符的內容。使用輸出內容前,請先確認內容是否屬實。如要瞭解詳情,請參閱 Gemini 版 Google Cloud 和負責任的 AI 技術

目標

在本研究室中,您將瞭解如何執行下列工作:

  • 在 Google Cloud 專案中啟用 Gemini
  • 將範例工作負載部署至 Google Cloud 環境
  • 利用 Gemini 找出安全性設定錯誤
  • 利用 Gemini 修正安全性設定錯誤

情境

在您監控基礎架構,尋找改進安全防護機制的方法時,Gemini 可協助找出基礎架構或設定相關變更,避免日後發生問題。

在本範例中,您是電子商務公司的資安工程師,該公司會定期部署代管的 Kubernetes 叢集。您需要設法檢查出錯誤設定,同時希望快速取得操作說明,修正雲端環境問題。

設定和需求

在每個研究室中,您都能在固定時間內免付費建立新的 Google Cloud 專案,並使用一組資源。

  1. 請透過無痕式視窗登入 Qwiklabs。

  2. 請記下研究室的存取時間 (例如 1:15:00),並確保自己能在時間限制內完成作業。
    研究室不提供暫停功能。如有需要,您可以重新開始,但原先的進度恕無法保留。

  3. 準備就緒後,請按一下「Start lab」

  4. 請記下研究室憑證 (使用者名稱密碼),這組資訊將用於登入 Google Cloud 控制台。

  5. 按一下「Open Google Console」

  6. 按一下「Use another account」,然後複製這個研究室的憑證,並貼入提示訊息。
    如果使用其他憑證,系統會顯示錯誤或向您收取費用

  7. 接受條款,然後略過資源復原頁面。

工作 1:啟用 Gemini

您將先在 Google Cloud 專案啟用 Gemini,並設定 Google Cloud Qwiklabs 使用者帳戶所需的權限。

  1. 在 Google Cloud 控制台工具列右上角,點選 Cloud Shell 圖示 Cloud Shell 圖示

  2. 執行下列指令,設定專案 ID 和區域環境變數:

PROJECT_ID=$(gcloud config get-value project) REGION={{{project_0.default_region|lab region}}} echo "PROJECT_ID=${PROJECT_ID}" echo "REGION=${REGION}"
  1. 執行下列指令,將已登入的 Google 使用者帳戶儲存在環境變數:
USER=$(gcloud config get-value account 2> /dev/null) echo "USER=${USER}"
  1. 如果出現提示訊息,請按一下「授權」

  2. 為 Gemini 啟用 Cloud AI Companion API:

gcloud services enable cloudaicompanion.googleapis.com --project ${PROJECT_ID}
  1. 為您的 Google Cloud Qwiklabs 使用者帳戶授予必要的 IAM 角色,以便使用 Gemini:
gcloud projects add-iam-policy-binding ${PROJECT_ID} --member user:${USER} --role=roles/cloudaicompanion.user gcloud projects add-iam-policy-binding ${PROJECT_ID} --member user:${USER} --role=roles/serviceusage.serviceUsageViewer

新增角色後,使用者即可透過 Gemini 取得協助。

點選「Check my progress」,確認工作已完成。 啟用 Gemini

工作 2:建立 GKE 叢集並部署網頁應用程式

您將建立 Google Kubernetes Engine (GKE) 叢集,執行多項微服務。

  1. 執行下列指令,建立名為 test 的 GKE 叢集:
gcloud container clusters create test --region={{{project_0.default_region|lab region}}} --num-nodes=1

這項程序應該需要幾分鐘的時間。程序完成後,您應看到類似如下的結果:

Creating cluster test in {{{project_0.default_region|lab region}}}... Cluster is being health-checked (master is healthy)...done. Created [https://container.googleapis.com/v1/projects/agmsb-gke-lab/zones/us-central1/clusters/test]. To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/us-central1/test?project=agmsb-gke-lab kubeconfig entry generated for test. NAME: test LOCATION: {{{project_0.default_region|lab region}}} MASTER_VERSION: 1.27.3-gke.100 MASTER_IP: 34.66.224.143 MACHINE_TYPE: e2-medium NODE_VERSION: 1.27.3-gke.100 NUM_NODES: 3 STATUS: RUNNING
  1. 複製含有網頁應用程式程式碼的存放區:
git clone https://github.com/GoogleCloudPlatform/microservices-demo && cd microservices-demo
  1. 使用 kubectl 將一組微服務部署至 GKE 叢集:
kubectl apply -f ./release/kubernetes-manifests.yaml
  1. 等待幾分鐘,接著執行下列指令,取得公開 IP 位址,以便在瀏覽器中存取網頁應用程式:
kubectl get service frontend-external | awk '{print $4}'
  1. 從上述指令的輸出結果中複製 IP 位址,然後貼上至新的瀏覽器分頁。

網頁應用程式看起來應類似如下:

網頁應用程式

點選「Check my progress」,確認工作已完成。 建立 GKE 叢集並部署網頁應用程式

工作 3:利用 Gemini 找出安全性設定錯誤

您現在已有用來執行電子商務應用程式的 GKE 叢集,接下來要使用 Gemini,找出安全防護機制的可改進之處。

  1. 透過 Google Cloud 控制台返回您的分頁。

  2. 重新整理 Google Cloud 控制台頁面。

  3. 將 Cloud Shell 窗格縮到最小。

  4. 在 Google Cloud 控制台工具列右上角,點選 Gemini 圖示 Gemini 圖示

  5. 按一下「Start Chatting」

  6. 輸入下列提示:

What services in Google Cloud can help me identify areas to improve security for a set of microservices running in a GKE cluster?

Gemini 的回覆應類似如下:

There are a number of services in Google Cloud that can help you identify areas to improve security for a set of microservices running in a GKE cluster. These include:

  • Security Command Center can help you identify and prioritize security risks across your Google Cloud environment, including GKE clusters.
  • Cloud Asset Inventory can help you track and manage your Google Cloud resources, including GKE clusters.
  • Cloud Logging can help you collect and analyze logs from your GKE clusters.
  • Cloud Monitoring can help you monitor the performance and health of your GKE clusters.
These are just a few of the many services in Google Cloud that can help you improve the security of your microservices. By using these services, you can help protect your data from unauthorized access, and you can also help improve your security posture over time.

在這個情境中,您決定要透過 Security Command Center 來處理。

  1. 開啟導覽選單,依序選取「安全性」>「風險總覽」

您看到多張關於安全漏洞的圖表,想讓 Gemini 快速說明在 Security Command Center 中歸類為安全漏洞的情形。

  1. 輸入下列提示:
How does Security Command Center define a vulnerability?

Gemini 的回覆應類似如下:

Security Command Center defines a vulnerability as a flaw or weakness in software programs that an attacker could use to gain access to or otherwise compromise your Google Cloud environment.

Source: https://cloud.google.com/security-command-center/docs/finding-classes
  1. 點選說明文件連結,即可進一步分辨各個發現項目類別。

  2. 閱讀完畢後,請關閉分頁,返回 Google Cloud 控制台。

  3. 按一下 Google Cloud 控制台側欄的「發現項目」

  4. 如要查看 GKE 叢集的發現項目,請找到「快速篩選器」部分,然後選取「資源類型」下方的「Google container cluster」

您應會看到一些嚴重性為「中」的發現項目。

  1. 按一下「叢集 Secret 加密功能已停用」發現項目。

這個發現項目面板的頂端,應會顯示標題為「AI 生成的摘要」的部分,這份摘要是由 Gemini 提供,類似如下:

Security Health Analytics in Security Command Center has identified a MEDIUM severity finding of type CLUSTER_SECRETS_ENCRYPTION_DISABLED in the google.container.Cluster named test...

This finding indicates that the cluster does not have application-layer secrets encryption enabled. This means that sensitive data, such as user-defined secrets and secrets required for the operation of the cluster, such as service account keys, are stored in etcd in plain text. This is a security risk, as an attacker who gains access to etcd could read these secrets.

To fix this finding, you need to enable application-layer secrets encryption for the cluster. You can do this by going to the Google Kubernetes Engine (GKE) console and clicking on the Security tab. Under Application-layer secrets encryption, click on Edit Application-layer Secrets Encryption. Select the Enable Application-layer Secrets Encryption checkbox and choose a database encryption key. Click Save Changes...

Gemini 的這份摘要進一步擴充了發現項目的簡短說明,更詳細地描述以明文儲存 Secret 的問題,並提供一種修正此發現項目的方法和操作說明。

  1. 退出這個資訊面板。

  2. 接著點選「權限過高的帳戶」,並查看 Gemini 提供的摘要,類似如下:

Security Health Analytics in Security Command Center has identified a MEDIUM severity finding of type OVER_PRIVILEGED_ACCOUNT in the google.container.Cluster named test...

The finding is caused by the fact that the GKE node uses the Compute Engine default service account, which has broad access by default and may be over privileged for running your Kubernetes Engine cluster.

This finding poses a risk because the Compute Engine default service account has access to all of the resources in the project, including the GKE cluster. If an attacker were to gain access to the service account, they would be able to access all of the resources in the project...

這份摘要提供了特定 Google 說明文件,指出修正此發現項目的方法,也就是為 GKE 叢集建立最低權限的服務帳戶。

  1. 退出這個資訊面板。

  2. 按一下「Master authorized networks disabled」發現項目。面板應會顯示 Gemini 的回覆,類似如下:

Security Health Analytics in Security Command Center has identified a MEDIUM severity finding of type MASTER_AUTHORIZED_NETWORKS_DISABLED in the google.container.Cluster named test...

Control plane authorized networks improve security for your container cluster by blocking specified IP addresses from accessing your cluster's control plane.

To fix this finding, go to the Kubernetes cluster and click Edit. The edit button might be disabled if the cluster configuration recently changed. If you aren't able to edit the cluster settings, wait a few minutes and try again. On the Control plane authorized networks drop-down list, select Enabled. Click Add authorized network. Specify the authorized networks you want to use. Click Save....
  1. 退出這個資訊面板。

您已瞭解一些錯誤的環境安全性設定,接下來要按照 Gemini 的建議修正錯誤。

工作 4:修正安全性設定錯誤

您已瞭解可從多方面著手提升 GKE 叢集安全性,接下來就能在 Security Command Center,按照 Gemini 摘要中的操作說明,修正「Master authorized networks disabled」發現項目。

  1. 開啟導覽選單,依序選取「Kubernetes Engine」>「叢集」

  2. 按一下稍早建立的叢集名稱,即「test」。

  3. 向下捲動至「網路」部分。

  4. 點選「控制層授權網路」旁的鉛筆圖示

  5. 勾選「啟用控制層授權網路」旁的方塊

  6. 勾選「Allow access through Google Cloud public IP addresses」旁的方塊。

  7. 按一下「儲存變更」

  8. 按一下側欄的「叢集」

系統會開始更新叢集,且「狀態」部分會顯示不停轉動的轉輪圖示。

  1. 在控制層網路政策的更新期間,請從 Google Cloud 控制台工具列開啟 Gemini。

  2. 輸入下列提示:

How do control plane authorized networks work in GKE?

Gemini 的回覆應類似如下:

Control plane authorized networks allow you to restrict access to the control plane of your GKE cluster. By default, the control plane is accessible from any address. However, you can add one or more authorized networks to restrict access to only those networks.

To add an authorized network, go to the Google Kubernetes Engine page in the Google Cloud console. Click the name of the cluster you want to modify. Under Networking, in the Control plane authorized networks field, click edit Edit control plane authorized networks...

更新版控制層政策套用後,可能需要幾分鐘才能生效。

  1. 在叢集旁的「狀態」欄看到綠色勾號,就表示已順利更新叢集設定。

點選「Check my progress」,確認工作已完成。 修正安全性設定錯誤

關閉研究室

如果您已完成研究室,請按一下「End Lab」(關閉研究室)。Qwiklabs 會移除您已用的資源,並清除使用帳戶。

您可以為研究室的使用體驗評分。請選取合適的星級評等並提供意見,然後按一下「Submit」(提交)

星級評等代表您的滿意程度:

  • 1 星 = 非常不滿意
  • 2 星 = 不滿意
  • 3 星 = 普通
  • 4 星 = 滿意
  • 5 星 = 非常滿意

如果不想提供意見回饋,您可以直接關閉對話方塊。

如有任何想法、建議或指教,請透過「Support」(支援) 分頁提交。

Copyright 2024 Google LLC 保留所有權利。Google 和 Google 標誌是 Google LLC 的商標,其他公司和產品名稱則有可能是其關聯公司的商標。