設定 VPC Service Controls

代管 Airflow (第 3 代) | 代管 Airflow (第 2 代) | 代管 Airflow (舊版第 1 代)

VPC Service Controls 可讓機構在Google Cloud 資源周圍定義安全範圍,降低資料竊取風險。

您可以在服務範圍內部署 Managed Airflow 環境。透過使用 VPC Service Controls 設定環境,您就能在運用 Managed Airflow 的全代管工作流程自動化調度管理功能時,確保機密資料不外洩。

Managed Airflow 支援 VPC Service Controls,代表:

  • 現在可以選取 Managed Airflow,做為 VPC Service Controls 範圍內的受保護服務。
  • Managed Airflow 使用的所有基礎資源都已設定為支援 VPC Service Controls 架構,並遵循相關規則。

使用 VPC Service Controls 部署 Managed Airflow 環境可提供以下優點:

  • 降低資料竊取風險。
  • 防止因存取控管設定錯誤而導致資料暴露。
  • 降低惡意使用者將資料複製到未經授權資源的風險,或外部攻擊者從網際網路存取資源的風險。Google Cloud Google Cloud

Managed Airflow 中的 VPC Service Controls 簡介

關於 VPC Service Controls 中連線至 Google API 和服務

Managed Airflow (第 3 代) 會透過 restricted.googleapis.com 將流量轉送至 Google 服務,以便存取此範圍支援的 Google API、服務和網域。

如要進一步瞭解 restricted.googleapis.com,以及透過 restricted.googleapis.com 存取的服務和網域清單,請參閱虛擬私有雲說明文件中的「網路設定」。

Managed Airflow (第 3 代) 環境會封鎖對 Google API、服務和網域的呼叫,這些項目必須位於必要 API 和服務清單中。如要從 DAG 呼叫 API:

  1. 確認服務支援 VPC Service Controls
  2. 將服務新增至受限制的服務。
  3. 將服務新增至可透過虛擬私有雲存取的服務。

舉例來說,如果您使用 VertexAI Operator,請將 aiplatform.googleapis.com 新增至受限制的服務和可透過虛擬私有雲存取的服務。

如要進一步瞭解如何將服務新增至服務範圍,請參閱 VPC Service Controls 說明文件的「管理服務範圍」一文。

在 Managed Airflow (第 3 代) 中,如果服務不支援 VPC Service Controls,且無法透過 restricted.googleapis.com 存取,就無法從受 VPC Service Controls 保護的環境存取。Managed Airflow (第 3 代) 新增了這項限制,可提升環境安全性。雖然 Managed Airflow (第 2 代) 允許設定存取這類不支援的服務,但我們強烈建議您在受 VPC Service Controls 保護的任何環境中,避免這麼做。

在範圍內建立環境

如要在安全防護範圍內部署 Managed Airflow,請按照下列步驟操作:

  1. 為專案啟用 Access Context Manager APICloud Composer API。如需參考資料,請參閱「啟用 API」。

  2. 請按照 VPC Service Controls 說明文件中的範圍設定說明建立範圍。請確認受限制服務清單中,除了您要限制的其他服務外,也包含 Managed Airflow 使用的所有服務:

    • Cloud Composer API (composer.googleapis.com)
    • Artifact Registry API (artifactregistry.googleapis.com)
    • Compute Engine API (compute.googleapis.com)
    • Kubernetes Engine API (container.googleapis.com)
    • Container File System API (containerfilesystem.googleapis.com)
    • Cloud DNS API (dns.googleapis.com)
    • Service Account Credentials API (iamcredentials.googleapis.com)
    • Cloud Logging API (logging.googleapis.com)
    • Cloud Monitoring API (monitoring.googleapis.com)
    • Cloud Pub/Sub API (pubsub.googleapis.com)
    • Cloud SQL Admin API (sqladmin.googleapis.com)
    • Cloud Storage API (storage.googleapis.com)

    • DAG 使用的所有其他服務:

      1. 將服務新增至受限制的服務。
      2. 將服務新增至可透過虛擬私有雲存取的服務。
  3. 建立新的 Managed Airflow 環境:

    1. 使用 Google Cloud CLI 建立環境。
    2. 使用 --enable-private-environment 引數啟用私人 IP。
    3. 使用 --web-server-allow-all--web-server-allow-ip--web-server-deny-all 引數,指定網路伺服器的存取參數。如要進一步瞭解如何使用這些引數,請參閱「建立環境」。為提升保護力,請只允許特定 IP 範圍存取網路伺服器。
    4. 使用 --enable-private-builds-only 引數,禁止從公開網際網路存放區安裝套件。

      範例:

      gcloud composer environments create example-environment \
        --location us-central1 \
        --enable-private-environment \
        --web-server-allow-all \
        --enable-private-builds-only
      
  4. 根據預設,只有在安全範圍內才能存取 Airflow UI 和 API。如要允許從安全防護範圍外存取,請設定存取層級輸入和輸出規則

將現有環境新增至 perimeter

如果環境使用私人 IP,且已停用從公開存放區安裝 PyPI 套件,您可以將包含環境的專案新增至安全防護範圍。

如要將現有的 Managed Airflow (第 3 代) 環境更新為這項設定,請按照下列步驟操作:

  1. 請確認您已按照上一節的說明建立或設定安全防護範圍。
  2. 使用 Google Cloud CLI 更新環境。
  3. 使用 --enable-private-environment 引數啟用私人 IP。
  4. 使用 --enable-private-builds-only 引數,禁止從公開網際網路存放區安裝套件。
  5. 視需要設定 Airflow 網路伺服器的存取權。為提升保護力,請只允許來自特定 IP 範圍的存取要求。

範例:

gcloud composer environments update example-environment \
  --location us-central1 \
  --enable-private-environment \
  --enable-private-builds-only

在 VPC Service Controls 中安裝 PyPI 套件

在預設的 VPC Service Controls 設定中,Managed Airflow 僅支援從可透過虛擬私有雲網路內部 IP 位址空間存取的私人存放區,安裝 PyPI 套件。

根據預設,VPC Service Controls 邊界內的所有 Managed Airflow 環境都無法存取公開 PyPI 存放區。

從私人存放區安裝

建議設定私人 PyPI 存放區:

  1. 在存放區中填入貴機構使用的經過審查的套件,然後設定 Managed Airflow,從私人存放區安裝 Python 依附元件

從公開存放區安裝

如要從外部存放區安裝 PyPI 套件,請按照下列步驟操作:

  1. 建立 Artifact Registry 遠端存放區
  2. 授予這個存放區上游來源的存取權
  3. 設定 Airflow,從 Artifact Registry 存放區安裝套件

VPC Service Controls 記錄

排解環境建立問題時,您可以分析 VPC Service Controls 產生的稽核記錄。

除了其他記錄訊息,您還可以查看記錄,瞭解設定環境元件的cloud-airflow-prod@system.gserviceaccount.comservice-PROJECT_ID@cloudcomposer-accounts.iam.gserviceaccount.com服務帳戶資訊。

Managed Airflow 服務會使用 cloud-airflow-prod@system.gserviceaccount.com 服務帳戶管理環境的租戶專案元件

service-PROJECT_ID@cloudcomposer-accounts.iam.gserviceaccount.com 服務帳戶 (又稱 Composer 服務代理程式服務帳戶) 會管理服務和主專案中的環境元件。

後續步驟