控管安全漏洞掃描費用

正式發行版的「容器分析」安全漏洞掃描功能為付費服務,在您啟用掃描 API 後,系統會立即開始計費。

詳情請參閱定價頁面

控管成本的最佳做法

啟用 Container Scanning API 後,系統會自動掃描您推送的每個新映像檔。為降低成本,請將要掃描的容器映像檔分開至其他專案。

  • 設定新的 Google Cloud 專案,並為該專案啟用 Container Scanning API。這個專案會產生 Artifact Registry 和 Container Registry (已淘汰) 的一般帳單費用。將要掃描的圖片推送至這項專案。

  • 在 CI/CD 管道中新增下列步驟:

    1. 新增標記,對應至已啟用容器掃描功能的 Artifact Registry 或 Container Registry 專案。

    2. 將圖片推送至專案。

預估掃描費用

如要計算專案中圖片的預估費用,請估算在特定時間範圍內推送的圖片數量,然後將該數量乘以每次掃描的價格。您可以在 Cloud Shell 中執行 Shell 指令碼,執行這項操作。

  1. 在專案中開啟 Cloud Shell。

    開啟 Cloud Shell

  2. 按一下「Open Editor」圖示,然後建立新檔案 cost-estimation.sh,並加入下列內容:

        #!/bin/bash
    
        # Replace with price from https://cloud.google.com/artifact-analysis/pricing
        PRICE='PRICE'
    
        # Replace with your project data
        GC_PROJECT='PROJECT_REPOSITORY'
        START_DATE='START_DATE'
        END_DATE='END_DATE'
    
        REGION=$(echo $GC_PROJECT | sed -n 's/\/.*//p')
    
        if [ -z "$REGION" ];
        then
            printf "'GC_PROJECT' value must be a valid GCR or AR repository (e.g. gcr.io/corp-staging or us-central1-docker.pkg.dev/myproj/myrepo"
            exit 1
        fi
    
        IFS=$'\n'
        FILTER="timestamp.date('%Y-%m-%d', Z)>'$START_DATE' AND timestamp.date('%Y-%m-%d', Z)<'$END_DATE'"
    
        images=$( gcloud container images list --repository="$GC_PROJECT" | sed -n "/$REGION/p" | sed 's/NAME: //' )
    
        num_images=$(echo $images | wc -w)
    
        printf "Using gcloud to filter $num_images images from $START_DATE to $END_DATE (takes about 1 second per image)\n\n"
    
        total_digests=0
    
        for image in $images; do
        printf "querying $image\n"
        image_digests=$( gcloud container images list-tags --filter="$FILTER" "$image" 2> >(sed "s/Listed 0 items.//" | sed -n "/.\+/p" >&2) | wc -l)
    
        if [[ "$image_digests" -gt 1 ]]; then
            total_digests=$(( total_digests + $image_digests - 1 ))
        fi
        done
    
        total_price=$( python -c "print($total_digests * $PRICE)" )
    
        echo ''
        echo "Number of images: $total_digests"
        echo "Estimated cost: $total_price"
    

    更改下列內容:

    • PRICE:自動安全漏洞掃描的價格,請參閱定價
    • PROJECT_REPOSITORY:您的專案存放區。例如:gcr.io/corp-staging
    • START_DATE:要預估的期間起始日期,格式為 Y-m-d。例如:2020-03-01
    • END_DATE:要預估的期間結束日期,格式為 Y-m-d。例如:2020-03-31
  3. 執行指令碼:

    bash cost-estimation.sh
    

    這份報表會顯示圖片總數和預估總費用:

    Number of images: 53
    Estimated cost: 13.78
    

這只是預估值,實際費用可能因其他因素而異,例如:

  • 將相同圖片推送至同一專案中的不同多區域,不會產生額外費用。

  • 將相同圖片推送至兩個不同專案中的兩個不同存放區,不會產生額外費用。

查看目前的安全漏洞掃描費用

您可以在帳單報表中查看這項資訊。

後續步驟