IBM Cloud 的 Code Risk Analyzer 外掛程式
IBM Cloud® 指令行介面 (CLI) 提供程式碼風險分析的指令。 您可以使用 IBM Cloud CLI 來分析程式碼是否有漏洞及符合特定規則。 Code Risk Analyzer 可在所有支援工具鏈的 IBM Cloud 地區中使用。
使用 CLI 完成下列任務:
- 產生資料清單 (BOM),其中列出所有協力廠商 OS 套件及應用程式套件的相依關係及可用的授權資訊。 您也可以以 CycloneDX-specific 格式產生此輸出。
- 探索 BOM 中所列出套件的漏洞。 您也可以檢視 CycloneDX-specific 格式的已產生報告,或使用 Node.js、Maven 或 Gradle (Groovy) 應用程式的弱點自動修復功能。
- 分析 Terraform 方案是否符合特定規則。
- 分析 Kubernetes 檔案是否符合特定規則。
從 2024 年 1 月開始,Code Risk Analyzer 會耗用 Clair 開放程式碼專案 所提供的漏洞資料,而不是來自商業公司 Snyk Limited 的資料。 由於此變更,您不需要採取任何特定動作。 不過,您可能會觀察到 Code Risk Analyzer 所報告 CVE 的細節有一些差異。
支援的內容
Code Risk Analyzer 支援 Java™、Node.js、Python及 Go 語言。 下表列出並說明 Code Risk Analyzer 支援的內容。
内容 | 說明 |
---|---|
Java | 此 repo 需要使用 Maven 或 Gradle 進行自動化建置。 Maven 使用 pom.xml 檔案計算相依性,而 Gradle 則使用 build.gradle(.kts) 檔案。 Code Risk Analyzer 可以自動針對 Maven 和 Gradle (Groovy) 進行修復。 |
Node.js | package-lock.json 檔案會計算相依性。 對於 Node.js,Code Risk analyzer 也可以自動進行修復。 確保安裝的 npm 版本與專案的 npm 版本相符。 |
Python | 相依關係是使用 requirements.txt 檔案來計算。 |
Golang | 支援 go mod 和 go dep 相依關係管理。 對於 go mod ,go.sum 檔案必須位於儲存庫中。 對於 go dep ,Gopkg.lock 檔案必須位於儲存庫中。 |
Dockerfiles | 會考量儲存庫中具有 Dockerfile 型樣的檔案。 對於容器映像檔,支援 Debian、Red Hat Enterprise Linux®、Alpine及 Ubuntu Linux distros。 |
Kubernetes | 會考量以 .yaml 和 .yml 作為字尾的檔案。 kind 值必須設為 Pod 、ReplicaSet 、ReplicationController 、Deployment 、Daemonset 、Statefulset 、Job 、CronJob 、NetworkPolicy 或 Ingress 。 |
Calico | 會考量以 .yaml 和 .yml 作為字尾的檔案。 kind 值必須設為 NetworkPolicy 、GlobalNetworkPolicy 、Profile 、NetworkSet 、GlobalNetworkSet 或 HostEndpoint 。 |
Terraform | 必須使用 IBM Cloud 作為 Terraform 提供者來產生 Terraform 計劃檔案。 |
Code Risk Analyzer 會檢查儲存庫中的原始碼及映像檔相依關係是否有漏洞。 下表顯示 Code Risk Analyzer 針對不同類型的相依關係所諮詢的漏洞資訊來源。
相依關係 | 支援的版本 | 安全注意事項的來源 |
---|---|---|
Alpine 影像 | 具有供應商安全支援的所有穩定版本。 | Alpine SecDB 資料庫。 |
Debian 映像檔 | 具有供應商安全支援的所有穩定版本。
不會報告與 Debian 來源套件 |
Debian Security bug Tracker。 |
GoogleContainerTools 無散熱影像 | 具有供應商安全支援的所有穩定版本。 | GoogleContainerTools 無電源 |
Red Hat® Enterprise Linux® (RHEL) 映像 | RHEL 6、RHEL/UBI 7、RHEL/UBI 8 及 RHEL/UBI 9 | Red Hat 安全資料 API。 |
Ubuntu 映像檔 | 具有供應商安全支援的所有穩定版本。 | Ubuntu CVE Tracker。 |
Go、npm ( JavaScript )、Maven ( Java )、PyPI ( Python )、RubyGems ( Ruby ) 和 Packagist (PHP) | 具有供應商安全支援的所有穩定版本。 | 開放程式碼漏洞資料庫。 |
Code Risk Analyzer 的已知問題
Code Risk Analyzer 無法在未使用版本化架構 (例如 major.minor.patch
) 的應用程式套件上探索漏洞。 例如,不支援預先發行版本或包含建置 meta 資料的版本。
必要條件
-
安裝 IBM Cloud CLI。 如需指示,請參閱 下載 IBM Cloud CLI。
-
執行下列指令,安裝 Code Risk Analyzer CLI 外掛程式:
ibmcloud plugin install cra
-
請確定您可以存取其中一個受支援地區中的工具鏈。 工具鏈不需要有任何工具。 如需工具鏈的相關資訊,請參閱從應用程式建立工具鏈。
-
透過設定
TOOLCHAIN_ID
環境變數來指定工具鏈 ID:
export TOOLCHAIN_ID=e22195a5-11e3-44ba-9533-e7c18a3a61a7
- 執行下列指令,以登入 IBM Cloud 的特定地區,其中
[region]
是建立工具鏈的地區。
ibmcloud login -r [region]
- 選擇性地,為了在使用 CLI 時加強對資料的控制和安全性,您可以選擇使用專用路由到 IBM Cloud 端點。 您必須先在帳戶中啟用虛擬路由和轉發,然後才可以啟用 IBM Cloud 私人服務端點的使用。 如需有關設定帳戶以支援專用連線選項的詳細資訊,請參閱 啟用 VRF 和服務端點。
使用下列指令登入私人端點,其中 [region]
是建立工具鏈的區域。
ibmcloud login -a private.cloud.ibm.com -r [region]
CLI 使用指令
當 IBM Cloud CLI 及外掛程式的更新可用時,您會在指令行收到通知。 請確定您保持 CLI 最新,以便您可以使用最新指令。 您可以執行 ibmcloud plugin list
指令來檢視所有已安裝外掛程式的現行版本。
Code Risk Analyzer 說明
下列指令會顯示 Code Risk Analyzer 指令的清單:
ibmcloud cra --help
Code Risk Analyzer 指令說明
以下指令會顯示與指令搭配使用的旗標的詳細資訊。 使用 ibmcloud cra --help
來顯示可用的指令。
ibmcloud cra <command> --help
物料清單 (BOM)
bom-generate
指令會存取指定目錄路徑中的構件,並執行深度探索來識別所有相依關係,包括可轉移的相依關係。 此指令也會識別配送這些相依關係的授權。 會建立 BOM 來擷取所有相依關係的 Snapshot。 您可以以標準格式或 CycloneDX's SBOM 格式產生 BOM。
ibmcloud cra bom-generate
BOM 指令需求
bom-generate
指令取決於某些外部指令:
- 如果路徑包含 Dockerfiles,這個指令會針對每一個 Dockerfile 中的每一個建置階段下拉基本映像檔及建置映像檔。 在此實務範例中,
bom-generate
指令需要Docker cli
及tar
指令可用。 - 如果路徑包含 Maven 檔案,此指令會使用
mvn
來建置相依關係清單。 在此實務範例中,bom-generate
指令需要mvn
指令可用。 - 如果路徑包含 Gradle 檔案,則此指令會使用
gradle
來建置相依關係清單。 在此實務範例中,bom-generate
指令需要gradle
指令可用。 - 如果路徑包含 Node.js
package-json
檔,且這個指令用來產生對應的package-lock.json
檔,則bom-generate
指令會使用npm
來建置 package-lock.json 檔。 在此實務範例中,指令需要npm
指令可用。 - 如果路徑包含 Python requirements.txt 檔案,則指令會使用
pip
來產生套件相依關係。 在此實務範例中,bom-generate
指令需要pip
指令可用。 同時支援 Python 第 2 版和 Python 第 3 版。
如果您使用 Dockerfiles,請確保登入要從中取回基本映像檔的容器登錄。
如果您的 Dockerfile 需要 ARGS,在執行指令之前,請將個別 ARG 設為環境變數。 例如,如果 Dockerfile 使用 IAM_USER
ARG,請匯出名為 IAM_USER
: export IAM_USER='value'
的環境變數。 CLI 會自動將這些環境變數傳遞至 docker build
指令。
您也可以明確指定 DOCKERBUILDFLAGS
旗標。 若要使用 ARGS Docker 旗標來匯出 DOCKERBUILDFLAGS
,請鍵入下列指令:
export DOCKERBUILDFLAGS="--build-arg IAM_USER --build-arg API_KEY"
BOM 指令選項
下表列出您可以使用 bom-generate
指令來產生 BOM 的指令選項。
指令選項 | 必要或選用 | 說明 |
---|---|---|
--path |
必要 | 要掃描的專案目錄路徑。 |
-r , --report |
必要 | 用來儲存 BOM 報告的檔名。 |
-a , --asset-type |
選用 | 要執行的安全檢查 (apps、image、os、all)。 預設情況下,此選項設定為 all 。 apps 選項用來將探索限制為應用程式套件。 image 選項用來將探索限制為 Dockerfiles 中使用的基本映像檔。 os 選項用來將探索限制為僅在 Dockerfile 中建置階段。 您可以使用逗點來區隔值,例如 -a os,image,apps ,以指定多個值。 |
-p , --prev-report |
選用 | 請使用先前的 BOM 報告來加速指令。 例如,如果自前次產生報告以來未更新 Dockerfile,則指令會跳過從該 Dockerfile 探索套件。 相同的實務適用於其他資訊清單檔,例如 package-lock.json 檔。 |
-c , --dockerbuildcontext |
選用 | 如果指定的話,在建置階段掃描期間,CRA 會使用路徑參數中的目錄作為 Docker 建置環境定義。 |
-o , --output |
選用 | 選取 BOM 報告格式。 您可以以 Standard BOM 格式 (standard ) 或 CycloneDX's SBOM 格式 (cyclonedx ) 產生格式輸出。預設值為 standard 。 您可以輸入以逗點區隔且不含空格的每一種格式,來儲存這兩種格式。 |
-f , --dockerbuildflags |
選用 | 自訂 Docker 建置指令,以進行建置階段掃描。 您可以在名為 DOCKERBUILDFLAGS 的環境變數中指定值,而不使用此指令行旗標。 預設情況下,此指令選項設定為 '' 。 如果您使用此選項,請確定它是提供給指令的最後一個旗標。 |
-d , --dockerfilepattern |
選用 | 用來識別儲存庫中 Dockerfile 的型樣。 |
-g , --gradle.excludeconfigurations |
選用 | 排除 Gradle 配置,例如: runtimeClasspath,testCompileClasspath 。 預設情況下,此指令選項設定為 '' 。 |
-l , --gradleprops |
選用 | 使用 Gradle 相依關係掃描的內容來自訂 Gradle 指令。 |
-m , --maven.excludescopes |
選用 | 排除 Maven 範圍,例如: test,compile 。 範例: 'test,compile '。 預設情況下,此指令選項設定為 '' 。 |
-n , --nodejs.createpackagelock |
選用 | 啟用作業來建置 node.js 專案的 package-lock.json 檔。 |
--region |
選用 | 工具鏈所在的 ibmcloud 地區。 |
--toolchainid |
選用 | 要使用的目標工具鏈 ID。 |
-v , --verbose |
選用 | 啟用詳細日誌訊息。 |
忽略檔案
如果路徑包含 .cra/.fileignore
檔案,則不會掃描 .fileignore
檔案中指定的檔案是否有相依關係。 .fileignore
檔案必須遵循 .gitignore
檔案的規則。 類似於 .gitignore
檔,.fileignore
檔可以包含註解、要忽略的目錄、要忽略的檔案,以及其他 型樣。
下列範例 .fileignore
檔案顯示如何排除 Bash Script、node_modules 及 Dockerfile。
# Ignore nested functional_tests directory
**/functional_tests
# Ignore bash scripts
**/*.sh
# This should allow this one file
!test/gatling_tests/loginTobx.sh
# Ignore node_modules
node_modules
# Exclude the dockerfile from scanning
Dockerfile
設定多個 Docker 建立情境
在單一專案中使用多個 Dockerfile 時,您可能想要為每個 Dockerfile 定義獨立的建立上下文。 這可以透過使用 .cra/.dockerbuildcontext
檔案來實現,這是一個 JSON 檔案,將 Dockerfile 路徑對應到其對應的建立上下文。
如果專案目錄中存在 .cra/.dockerbuildcontext
檔案,CRA Docker 建立指令會使用此檔案中的指定路徑作為相關 Dockerfile 的建立上下文。 JSON 物件中的鍵代表 Dockerfile 的相對路徑,而值則指定各自建立上下文的相對路徑。
以下是 .dockerbuildcontext
檔案的範例,它為多個 Dockerfile 定義了不同的建立上下文:
{
"Dockerfile": "./",
"path/to/different/Dockerfile": "./another/Path"
}
範例
下列程式碼 Snippet 顯示如何使用 bom-generate
指令:
ibmcloud cra bom-generate --path PATH --report REPORT [--asset-type ASSET-TYPE] [--dockerbuildcontext] [--dockerbuildflags DOCKERBUILDFLAGS] [--dockerfilepattern DOCKERFILEPATTERN] [--gradle.excludeconfigurations GRADLE.EXCLUDECONFIGURATIONS] [--maven.excludescopes MAVEN.EXCLUDESCOPES] [--nodejs.createpackagelock] [--prev-report PREV-REPORT] [--region REGION] [--toolchainid TOOLCHAINID] [--verbose]
ibmcloud cra bom --path . --report bomreport.json
漏洞掃描
vulnerability-scan
指令預期以 standard
格式的 BOM 作為輸入,並偵測 BOM 中列出的應用程式套件和 OS 套件中的漏洞。 根據從多個「常見漏洞及風險暴露 (CVE)」來源取得的豐富威脅情報,提供有針對性的修正建議。 Code Risk Analyzer 也只能對 Node.js 型應用程式的有漏洞套件執行自動補救。 您也可以以標準格式或 CycloneDX's Vulnerability Exploitability
Exchange (VEX) 格式產生此報告。
ibmcloud cra vulnerability-scan
漏洞掃描指令選項
下表列出使用 vulnerability-scan
指令的選項。
指令選項 | 必要或選用 | 說明 |
---|---|---|
-b , --bom |
必要 | 使用 bom-generate 指令所產生 BOM 的檔案路徑。 這個 BOM 必須採用 standard 格式。 |
-a , --autofix |
選用 | 修正特定類型的應用程式漏洞。 此選項僅適用於 Node.js、Maven 及 Gradle 應用程式。 |
-f , --commentfile |
選用 | 指定建立 Markdown 報告的檔案。 此指令僅適用於 autofix 。 |
-c , --cveignore |
選用 | 包含要忽略的 CVE 清單之「CVE 忽略」檔案的檔案路徑。 |
-e , --excludedev |
選用 | 指定您不想要指令報告開發相依關係的 CVE。 |
--force |
選用 | 即使主要版本不同,也會強制更新最上層節點套件。 此指令僅適用於 autofix 。 |
--include-nofix |
選用 | 包括或排除報告沒有已知補救的 CVE。 預設情況下,此選項設定為 app 。 app 選項用來僅包含沒有修正程式的應用程式套件 CVE。 os 選項用來只包含沒有修正程式的 OS 套件 CVE。 all 選項用來同時包含沒有修正程式的應用程式及 OS 套件 CVE。 none 選項用來排除沒有修正程式的應用程式及 OS 套件 CVE。 |
--path |
如果已啟用 --autofix ,則為必要 |
要掃描的專案目錄路徑。 此指令僅適用於 autofix 。 |
--region |
選用 | 工具鏈的 ibmcloud 地區。 |
-r , --report |
選用 | 所產生報告的路徑。 |
-o , --output |
選用 | 選取 CVE 報告格式。 您可以以標準 CVE 格式 (standard ) 或 CycloneDX's VEX 格式 (cyclonedx ) 產生格式輸出。預設值為 standard 。 |
-s , --strict |
選用 | 當發現漏洞時,會導致指令失敗 (結束狀態 2)。 |
--toolchainid |
選用 | 目標工具鏈的 ID。 |
忽略漏洞
如果指定 -c
或 --cveignore
參數,指令會尋找該檔案,且不會報告檔案中指定的 CVE。 您可以將 CVE 配置成無限期地省略它們,直到有補救可用或直到指定的到期日為止。
下列範例顯示 .cveignore
檔的 JSON 綱目:
[
{
"cve": "string",
"alwaysOmit": "bool",
"untilRemediationAvailable": "bool",
"expiration": "string"
}
]
.cveignore
檔中的每一個項目都支援下列內容:
- cve-要省略的漏洞。 此內容的值是 CVE ID。
- alwaysOmit-如果此內容設為
true
,則在變更之前會省略漏洞。 此內容優先於其他內容值。 - untilRemediationAvailable- 如果此屬性設定為
true
,漏洞會被省略,直到有補救途徑為止。 如果補救變成可用,則不會省略漏洞並顯示訊息。 此內容優先於到期內容值。 - expiration-如果此內容設為
true
,且未達到到期日,則會省略漏洞。 如果達到到期日,則不會省略漏洞,且會顯示一則訊息。 使用 RFC3339 時間格式 (yyyy-MM-ddTHH:mm:ss[+-]Z
) 來定義此內容。
Code Risk Analyzer 只會使用這些已定義的內容。 您可以新增對函數沒有影響的內容。 如果未省略 .cveignore
中定義的漏洞,則會產生日誌來說明原因。 如果省略 .cveignore
檔案中定義的漏洞,則不會顯示個別記載。 在報告完成之後,會記載省略的省略數目及具有套件名稱的漏洞 ID 清單。
下列程式碼 Snippet 顯示 .cveignore
範例檔:
[
{
"cve": "CVE-2021-27290",
"alwaysOmit": true
},
{
"cve": "CVE-2020-8244",
"untilRemediationAvailable": true,
}
]
範例
下列程式碼 Snippet 顯示如何使用 vulnerability-scan
指令:
ibmcloud cra vulnerability-scan --bom BOM [--cveignore CVEIGNORE] [--report REPORT] [--excludedev] [--include-nofix app,os,all,none] [--region REGION] [--strict] [--toolchainid TOOLCHAINID] [--output OUTPUTFILE]
ibmcloud cra cve --bom ./bom-file.json --cveignore ./cveignore-example.json --report ./output-vulnerability-report.json --excludedev --include-nofix all --strict
部署
deployment-analyze
指令會對 Kubernetes 部署資訊清單執行配置檢查。
ibmcloud cra deployment-analyze
這個指令提供指導來建立 Docker 儲存器的安全配置狀態。 Code Risk Analyzer 使用這些安全配置作為參照點,並識別安全控制項來移入 Kubernetes 應用程式的部署構件 (例如 .yaml
檔案)。 這個指令也會提供每一個控制失敗的風險評量。
下表列出了您可以在 DevSecOps, 中執行的控制,這些控制來自 CIS Docker 1.13.0。 根據 Kubernetes Common Configuration Scoring System(KCCSS)的開放程式碼參照來新增更多控制項。
ID | rule | 風險 |
---|---|---|
5.3 | 確保儲存器沒有 CAP_SYS_ADMIN 功能。 |
高 |
5.3 | 確保儲存器沒有 CAP_NET_RAW 功能。 |
高 |
5.4 | 確保未使用特許儲存器。 | 高 |
5.5 | 請確定機密主機系統目錄未裝載在儲存器上。 | 中 |
5.7 | 請確定未在儲存器內對映特許埠。 | 低 |
5.9 | 請確定主機的網路名稱空間未共用。 | 中 |
5.10 | 請確定儲存器的記憶體用量受到限制。 | 中 |
5.11 | 請確定已在儲存器上設定適當的 CPU 優先順序。 | 中 |
5.12 | 請確定儲存器的根檔案系統已裝載為唯讀。 | 中 |
5.15 | 請確定主機的程序名稱空間未共用。 | 中 |
5.16 | 請確定主機的 IPC 名稱空間未共用。 | 中 |
5.31 | 確保 Docker Socket 未裝載在任何儲存器內。 | 高 |
|
請確定儲存器不容許不安全的 CPU 資源配置。 | 中 |
|
請確定儲存器不容許專用權升級。 | 中 |
|
確保儲存器不會暴露 /proc 的不安全組件。 |
中 |
|
確保儲存器未透過共用主機埠公開。 | 中 |
部署指令選項
下表列出您可以用於 deployment-analyze
指令的指令選項。
指令選項 | 必要或選用 | 說明 |
---|---|---|
--path |
必要 | 要掃描的專案目錄路徑。 |
-r , --report |
必要 | 要在其中建立報告的檔名。 |
-f , --fileignore |
選用 | .fileignore 檔案的檔案路徑。 |
-s , --strict |
選用 | 發現部署風險時指令失敗 (結束狀態 2) 的結果。 |
範例
下列程式碼 Snippet 顯示如何使用 deployment-analyze
指令:
ibmcloud cra deployment-analyze --path PATH --report REPORT [--fileignore FILE_IGNORE] [--strict]
ibmcloud cra depl --path ./sampleDir --report deployment-report.json --strict
Terraform Analyzer
在將方案套用至環境之前,您可以使用 terraform-validate
指令來分析 Terraform 方案的相符性。 此指令會分析指定的 Terraform 計劃檔是否符合 IBM Cloud® Security and Compliance Center中指定的規則。 此指令會產生相符性報告。
您可以指定原則檔,其中列出用於驗證的規則和參數。 如果未指定原則檔,則此指令會分析計劃是否有預設規則集。
ibmcloud cra terraform-validate
Terraform 指令選項
下表列出您可以用於 terraform-validate
指令的選項。
指令選項 | 必要或選用 | 說明 |
---|---|---|
-r , --report |
必要 | 所產生報告的路徑。 |
-t , --tf-plan |
必要 | 輸入 Terraform 計劃檔的路徑。 |
-p , --policy-file |
選用 | 原則設定檔的檔案路徑。 此旗標可以接受 Security and Compliance Center V2 設定檔或具有一組 Security and Compliance Center 規則的自訂 JSON 檔案。 |
-q , --quiet |
選用 | 僅顯示彙總資訊。 |
-s , --strict |
選用 | 如果原則失敗,則會導致指令失敗 (結束狀態 2)。 |
-v , --verbose |
選用 | 顯示在失敗規則清單之後傳遞 Security and Compliance Center 規則的清單。 |
-a , --attachment-file |
選用 | 此旗標接受具有 Security and Compliance Center V2 附件的 JSON 檔案。 若要使用此旗標,必須使用 -p 旗標來指定 Security and Compliance Center V2 設定檔。 |
範例
下列程式碼 Snippet 顯示如何使用 terraform-validate
指令:
ibmcloud cra terraform-validate --tf-plan TFPLANFILE --report REPORT [--policy-file POLICYFILE] [--quiet] [--region REGION] [--strict] [--toolchainid TOOLCHAINID] [--verbose] [--attachment-file ATTACHMENT_FILE]
ibmcloud cra tf -r report-user-profile.json -t ./tfplan.json -p ./user-profile.json --verbose
terraform-validate
指令的 Terraform 計劃檔範例
{
"format_version": "0.2",
"terraform_version": "1.0.2",
"planned_values": {
"root_module": {
"child_modules": [
{
"resources": [
{
"address": "module.instance.ibm_resource_instance.cos_instance",
"mode": "managed",
"type": "ibm_resource_instance",
"name": "cos_instance",
"provider_name": "registry.terraform.io/ibm-cloud/ibm",
"schema_version": 0,
"values": {
"location": "global",
"parameters": null,
"plan": "lite",
"service": "cloud-object-storage",
"timeouts": null
},
"sensitive_values": {
"extensions": {},
"last_operation": {},
"plan_history": [],
"tags": []
}
}
],
"address": "module.instance"
},
{
"resources": [
{
"address": "module.instance_config.ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration[0]",
"mode": "managed",
"type": "ibm_cos_bucket",
"name": "bad_resource_cos_bucket_missing_all_configuration",
"index": 0,
"provider_name": "registry.terraform.io/ibm-cloud/ibm",
"schema_version": 0,
"values": {
"activity_tracking": [],
"allowed_ip": null,
"archive_rule": [],
"cross_region_location": null,
"endpoint_type": "public",
"expire_rule": [],
"force_delete": true,
"key_protect": null,
"metrics_monitoring": [],
"region_location": "us-south",
"retention_rule": [],
"single_site_location": null,
"storage_class": "standard",
"timeouts": null
},
"sensitive_values": {
"activity_tracking": [],
"archive_rule": [],
"expire_rule": [],
"metrics_monitoring": [],
"retention_rule": []
}
},
{
"address": "module.instance_config.ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration[1]",
"mode": "managed",
"type": "ibm_cos_bucket",
"name": "bad_resource_cos_bucket_missing_all_configuration",
"index": 1,
"provider_name": "registry.terraform.io/ibm-cloud/ibm",
"schema_version": 0,
"values": {
"activity_tracking": [],
"allowed_ip": null,
"archive_rule": [],
"cross_region_location": null,
"endpoint_type": "public",
"expire_rule": [],
"force_delete": true,
"key_protect": null,
"metrics_monitoring": [],
"region_location": "us-south",
"retention_rule": [],
"single_site_location": null,
"storage_class": "standard",
"timeouts": null
},
"sensitive_values": {
"activity_tracking": [],
"archive_rule": [],
"expire_rule": [],
"metrics_monitoring": [],
"retention_rule": []
}
}
],
"address": "module.instance_config"
}
]
}
},
"resource_changes": [
{
"address": "module.instance.ibm_resource_instance.cos_instance",
"module_address": "module.instance",
"mode": "managed",
"type": "ibm_resource_instance",
"name": "cos_instance",
"provider_name": "registry.terraform.io/ibm-cloud/ibm",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"location": "global",
"parameters": null,
"plan": "lite",
"service": "cloud-object-storage",
"timeouts": null
},
"after_unknown": {
"account_id": true,
"allow_cleanup": true,
"created_at": true,
"created_by": true,
"crn": true,
"dashboard_url": true,
"deleted_at": true,
"deleted_by": true,
"extensions": true,
"guid": true,
"id": true,
"last_operation": true,
"locked": true,
"name": true,
"plan_history": true,
"resource_aliases_url": true,
"resource_bindings_url": true,
"resource_controller_url": true,
"resource_crn": true,
"resource_group_crn": true,
"resource_group_id": true,
"resource_group_name": true,
"resource_id": true,
"resource_keys_url": true,
"resource_name": true,
"resource_plan_id": true,
"resource_status": true,
"restored_at": true,
"restored_by": true,
"scheduled_reclaim_at": true,
"scheduled_reclaim_by": true,
"service_endpoints": true,
"state": true,
"status": true,
"sub_type": true,
"tags": true,
"target_crn": true,
"type": true,
"update_at": true,
"update_by": true
},
"before_sensitive": false,
"after_sensitive": {
"extensions": {},
"last_operation": {},
"plan_history": [],
"tags": []
}
}
},
{
"address": "module.instance_config.ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration[0]",
"module_address": "module.instance_config",
"mode": "managed",
"type": "ibm_cos_bucket",
"name": "bad_resource_cos_bucket_missing_all_configuration",
"index": 0,
"provider_name": "registry.terraform.io/ibm-cloud/ibm",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"activity_tracking": [],
"allowed_ip": null,
"archive_rule": [],
"cross_region_location": null,
"endpoint_type": "public",
"expire_rule": [],
"force_delete": true,
"key_protect": null,
"metrics_monitoring": [],
"region_location": "us-south",
"retention_rule": [],
"single_site_location": null,
"storage_class": "standard",
"timeouts": null
},
"after_unknown": {
"activity_tracking": [],
"archive_rule": [],
"bucket_name": true,
"crn": true,
"expire_rule": [],
"id": true,
"metrics_monitoring": [],
"resource_instance_id": true,
"retention_rule": [],
"s3_endpoint_private": true,
"s3_endpoint_public": true
},
"before_sensitive": false,
"after_sensitive": {
"activity_tracking": [],
"archive_rule": [],
"expire_rule": [],
"metrics_monitoring": [],
"retention_rule": []
}
}
},
{
"address": "module.instance_config.ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration[1]",
"module_address": "module.instance_config",
"mode": "managed",
"type": "ibm_cos_bucket",
"name": "bad_resource_cos_bucket_missing_all_configuration",
"index": 1,
"provider_name": "registry.terraform.io/ibm-cloud/ibm",
"change": {
"actions": [
"create"
],
"before": null,
"after": {
"activity_tracking": [],
"allowed_ip": null,
"archive_rule": [],
"cross_region_location": null,
"endpoint_type": "public",
"expire_rule": [],
"force_delete": true,
"key_protect": null,
"metrics_monitoring": [],
"region_location": "us-south",
"retention_rule": [],
"single_site_location": null,
"storage_class": "standard",
"timeouts": null
},
"after_unknown": {
"activity_tracking": [],
"archive_rule": [],
"bucket_name": true,
"crn": true,
"expire_rule": [],
"id": true,
"metrics_monitoring": [],
"resource_instance_id": true,
"retention_rule": [],
"s3_endpoint_private": true,
"s3_endpoint_public": true
},
"before_sensitive": false,
"after_sensitive": {
"activity_tracking": [],
"archive_rule": [],
"expire_rule": [],
"metrics_monitoring": [],
"retention_rule": []
}
}
}
],
"configuration": {
"provider_config": {
"ibm": {
"name": "ibm",
"version_constraint": "1.25.0",
"expressions": {
"ibmcloud_api_key": {
"constant_value": "BYwB2M3TJdDMlCpHaxaWilNHVod05TVkqjIbGqrlm9Iz"
}
}
},
"module.instance:ibm": {
"name": "ibm",
"version_constraint": "1.25.0",
"module_address": "module.instance",
"expressions": {
"ibmcloud_api_key": {
"constant_value": "BYwB2M3TJdDMlCpHaxaWilNHVod05TVkqjIbGqrlm9Iz"
}
}
},
"module.instance_config:ibm": {
"name": "ibm",
"version_constraint": "1.25.0",
"module_address": "module.instance_config"
}
},
"root_module": {
"module_calls": {
"instance": {
"source": "./instance_module",
"module": {
"outputs": {
"cos_instance_id": {
"expression": {
"references": [
"ibm_resource_instance.cos_instance.id",
"ibm_resource_instance.cos_instance"
]
}
}
},
"resources": [
{
"address": "ibm_resource_instance.cos_instance",
"mode": "managed",
"type": "ibm_resource_instance",
"name": "cos_instance",
"provider_config_key": "instance:ibm",
"expressions": {
"location": {
"constant_value": "global"
},
"name": {},
"plan": {
"constant_value": "lite"
},
"service": {
"constant_value": "cloud-object-storage"
}
},
"schema_version": 0
}
]
}
},
"instance_config": {
"source": "./instance_config_module",
"expressions": {
"cos_instance_id": {
"references": [
"module.instance.cos_instance_id",
"module.instance"
]
}
},
"module": {
"resources": [
{
"address": "ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration",
"mode": "managed",
"type": "ibm_cos_bucket",
"name": "bad_resource_cos_bucket_missing_all_configuration",
"provider_config_key": "instance_config:ibm",
"expressions": {
"bucket_name": {},
"region_location": {
"constant_value": "us-south"
},
"resource_instance_id": {
"references": [
"var.cos_instance_id"
]
},
"storage_class": {
"constant_value": "standard"
}
},
"schema_version": 0,
"count_expression": {
"constant_value": 2
}
}
],
"variables": {
"cos_instance_id": {
"description": "COS Instance ID"
}
}
},
"depends_on": [
"module.instance"
]
}
}
}
}
}
terraform-validate
指令的 SCC V2 設定檔綱目範例
{
"title": "User Profile Standard v2 Schema",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"profile_name": {
"type": "string"
},
"profile_version": {
"type": "string"
},
"controls": {
"type": "array",
"items": {
"type": "object",
"properties": {
"control_specifications": {
"type": "array",
"items": {
"type": "object",
"properties": {
"assessment_count": {
"type": "number"
},
"assessments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"assessment_type": {
"type": "string"
},
"assessment_method": {
"type": "string"
},
"assessment_description": {
"type": "string"
},
"assessment_id": {
"type": "string"
},
"parameter_count": {
"type": "number"
},
"parameters": {
"type": "array",
"items": {
"type": "object",
"properties": {
"parameter_name": {
"type": "string"
},
"parameter_display_name": {
"type": "string"
},
"parameter_type": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
},
"default_parameters": {
"type": "array",
"items": {
"type": "object",
"properties": {
"assessment_type": {
"type": "string"
},
"assessment_id": {
"type": "string"
},
"parameter_name": {
"type": "string"
},
"parameter_default_value": {
"type": "string"
},
"parameter_display_name": {
"type": "string"
},
"parameter_type": {
"type": "string"
}
}
}
}
},
"required": ["default_parameters", "controls", "profile_name", "profile_version"]
terraform-validate
指令的 SCC V2 標準設定檔範例
您可以在規則 ID 前面加上 rule-
作為字首。
{
"schema_version": "2.0",
"scc_rules": [
{
"scc_rule_id": "548a3321-6a39-400c-9c2d-0df9a13afd02"
},
{
"scc_rule_id": "726ec899-505e-4de9-ac1b-9578ef62f89f"
},
{
"scc_rule_id": "962e2bde-2a4f-4e07-a352-ce17708b1e85"
},
{
"scc_rule_id": "9653d2c7-6290-4128-a5a3-65487ba40370"
},
{
"scc_rule_id": "d8d13c3e-5ca0-46c5-a055-2475852c4ec6"
},
{
"scc_rule_id": "0f7e7e60-a05c-43a7-be74-70615f14a342"
},
{
"scc_rule_id": "979fd713-d39f-4efe-ba02-bf6fc07e57bb"
},
{
"scc_rule_id": "rule-e76a3a81-b0d0-41fc-947d-13dc9cfff379"
},
{
"scc_rule_id": "caf5e45d-ccc8-4e35-b124-e1b4c8bcab71"
},
{
"scc_rule_id": "rule-1edc74ae-0dad-4ea1-865d-89e3214d240f"
},
{
"scc_rule_id": "064d9004-8728-4988-b19a-1805710466f6"
},
{
"scc_rule_id": "rule-caf5e45d-ccc8-4e35-b124-e1b4c8bcab71"
}
],
"scc_parameters": {
"ibm_minimum_password_length": 12,
"ibm_password_reuse_prevention": 4,
"allowed_admins_per_account": "10",
"api_keys_rotated_days": 90,
"account_owner_last_login_days": 30,
"no_of_admins_for_iam": 3,
"no_of_service_id_admins_for_iam": 3,
"no_of_managers_for_iam": 0,
"no_of_service_id_managers_for_iam": 0,
"iam_service_ids_max_count": 3,
"ssh_port": 25,
"rdp_port": 3390,
"no_pre_shared_key_characters": 30,
"dns_port": 60,
"vm_nic_count": 1,
"no_of_admins_for_container_registry ": 3,
"no_of_service_id_admins_for_container_registry": 3,
"no_of_managers_for_container_registry": 0,
"no_of_service_id_managers_for_container_registry": 0,
"access_tokens_expire": 120
}
}
Security and Compliance Center 規則
Terraform Analyzer 支援下列 Security and Compliance Center 規則:
rule-f8722625-1968-4d7a-93cb-4b0f8da726da - Check whether IBMid password policy requires at least one uppercase letter
rule-789cb35b-5bdf-46d3-8b59-e1377e3b211c - Check whether IBMid password policy requires at least one lowercase letter
rule-81b36ae4-0f15-41c7-adac-fa9586ff46ab - Check whether IBMid password policy requires at least one number
rule-979fd713-d39f-4efe-ba02-bf6fc07e57bb - Check whether IBMid password policy requires minimum length of 12 characters
rule-e76a3a81-b0d0-41fc-947d-13dc9cfff379 - Check whether IBMid password policy prevents password reuse below the minimum of #
rule-759d504b-9eed-4602-8b5b-7244bf3f5690 - Check whether IBMid password can contain only printable ASCII characters (in the range 33 - 126)
rule-bcbd57e1-3cdc-4b6d-820b-2c63bc777e19 - Check whether IBMid password policy contains spaces or any of the following characters: ;:("?)<>
rule-fa06f6f2-b98e-49ac-aa55-d57de9e320d3 - Check whether IBMid uses a password meter that coaches users to create strong passwords that exceed the minimum requirements
rule-548a3321-6a39-400c-9c2d-0df9a13afd02 - Check whether IAM roles are used to create IAM policies for IBM resources
rule-726ec899-505e-4de9-ac1b-9578ef62f89f - Check whether a support role has been assigned in IAM to manage cases in the IBM Cloud Support Center
rule-962e2bde-2a4f-4e07-a352-ce17708b1e85 - Check whether API keys are not created in IAM during the initial setup of IAM users
rule-61fa114a-2bb9-43fd-8068-b873b48bdf79 - Check whether IAM users are attached to at least one access group
rule-4d86c074-097e-4ff3-a763-ccff128388e2 - Check whether multifactor authentication (MFA) is enabled at the account level
rule-0704e840-e443-4781-b9be-ec57469d09c1 - Check whether permissions for API key creation are limited and configured in IAM settings for the account owner
rule-d61c20c9-c0be-443b-af0c-0d900601e154 - Check whether Cloud Object Storage public access is disabled in IAM settings (not applicable to ACLs managed using S3 APIs)
rule-0244c010-fde6-4db3-95aa-8952bd292ac3 - Check whether permissions for service ID creation are limited and configured in IAM settings for the account owner
rule-ed64fa73-81e5-4920-8519-acfad845dd6c - Check whether Identity and Access Management (IAM) is enabled with audit logging
rule-b2232217-34a6-4fe8-a791-5903f1cc89ca - Check whether Cloud Shell is disabled in account settings
rule-10de7433-19e4-40a7-aebf-eddf1f75a68c - Check whether Cloud Object Storage is enabled with encryption
rule-7c86bb59-d677-422d-875c-0259053fad20 - Check whether Cloud Object Storage is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-222d6531-1fc7-4485-8771-35eb46c78877 - Check whether Cloud Object Storage is accessible only through HTTPS
rule-7c52a1ce-26cd-4cde-baa7-3bfb3703cf74 - Check whether Cloudant is accessible only through HTTPS
rule-f6197ee2-31bf-4d73-aacd-316c41a48df3 - Check whether Cloud Object Storage is accessible only by using private endpoints
rule-8cbd597c-7471-42bd-9c88-36b2696456e9 - Check whether Cloud Object Storage network access is restricted to a specific IP range
rule-c97259ee-336d-4c5f-b436-1868107a9558 - Check whether Cloud Object Storage is enabled with customer-managed encryption and Keep Your Own Key (KYOK)
rule-ef1db4bb-2490-48a9-883c-a20fea3db0e5 - Check whether Databases for MongoDB is enabled with encryption
rule-7f7ca588-9412-40a9-9bd8-0e5d19141e98 - Check whether Databases for MongoDB is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-77b99b6f-51dc-4290-b20c-7003941c7a46 - Check whether Databases for MongoDB is accessible only through HTTPS
rule-7b210b18-f849-4fa8-bd92-8e47921de51d - Check whether Databases for MongoDB is accessible only by using private endpoints
rule-c58bb2b9-7942-45ab-b9d4-e39c8430f570 - Check whether Databases for Redis is enabled with encryption
rule-e3cad136-17a8-4227-b8af-0be609da1da0 - Check whether Databases for Redis is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-90e3908d-27c3-4050-bb12-413dfc606f5c - Check whether Databases for Redis is accessible only through HTTPS
rule-c48dfb73-ede0-4ebf-b912-214379cd4ce7 - Check whether Databases for Redis is accessible only by using private endpoints
rule-ac09e136-8581-416a-a865-e9fc35a758be - Check whether Databases for Elasticsearch is enabled with encryption
rule-871594ca-0a70-492b-8a42-6f9474445f01 - Check whether Databases for Elasticsearch is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-47ca5017-27e9-4b8b-95d3-c2529271fbb1 - Check whether Databases for Elasticsearch is accessible only through HTTPS
rule-026e6d36-6a15-4623-846d-cab6f3b789d9 - Check whether Databases for Elasticsearch is accessible only by using private endpoints
rule-d634caeb-e5a6-467a-a4ac-8da8fd39f9ef - Check whether Databases for etcd is enabled with encryption
rule-42612696-2b8e-4fa7-8c17-78f191d2e1a0 - Check whether Databases for etcd is accessible only through HTTPS
rule-458decc2-a081-4c49-8f31-eeaf4833d8c8 - Check whether Databases for etcd is accessible only by using private endpoints
rule-4d7e56d6-f657-418c-9e49-6d248b2cf5a6 - Check whether Databases for PostgreSQL is enabled with encryption
rule-041ff30b-7167-4411-985d-5ad32ab6f850 - Check whether Databases for PostgreSQL is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-872db4fc-2f7c-4ba0-ace7-dc468f6813c7 - Check whether Databases for PostgreSQL is accessible only through HTTPS
rule-094495cf-c092-4dcb-96b8-3654c4bcf787 - Check whether Databases for PostgreSQL is accessible only by using private endpoints
rule-beb7b289-706b-4dc0-b01d-b1d15d4331e3 - Check whether Databases for MongoDB network access is restricted to a specific IP range
rule-04d856f1-68ce-4cba-b800-ba49f3c4f1a1 - Check whether Databases for Redis network access is restricted to specific IP range
rule-b5c06228-3f38-4d98-837f-2fe10d6ff9d5 - Check whether Databases for Elasticsearch network access is restricted to a specific IP range
rule-18540c4e-b96d-4ab9-a619-d541cc5a2824 - Check whether Databases for etcd network access is restricted to a specific IP range
rule-9b2d8054-bc93-44fd-901b-91f677287e84 - Check whether Databases for PostgreSQL network access is restricted to a specific IP range
rule-f6b7a692-8e48-4e74-b957-f5d591a7a15d - Check whether Key Protect has high availability
rule-d0725d07-27e6-4079-a3bc-746d5ccae00f - Check whether Hyper Protect Crypto Services instance is enabled with a dual authorization deletion policy
rule-da567ec9-8e24-4c65-993b-ad290bfdb855 - Check whether Cloud Object Storage buckets are enabled with IBM Activity Tracker
rule-0fb54bb2-773b-4cec-81b0-1ca7d8049ba0 - Check whether Cloud Object Storage buckets are enabled with IBM Cloud Monitoring
rule-5910ed25-7ad7-42d0-8e42-905df0123346 - Check whether IBM Activity Tracker is provisioned in multiple regions in an account
rule-d592e06a-8756-4efc-a401-1ec215168f48 - Check whether IBM Activity Tracker trails are integrated with LogDNA logs
rule-c98fab05-5119-451a-b100-35df840d2326 - Check whether IBM Activity Tracker logs are encrypted at rest
rule-1cdad315-c39e-4d7e-99ef-8af88ba410c1 - Check whether Cloud Internet Services (CIS) has web application firewall enabled
rule-564ed93b-1927-4562-8a90-fbae173cdee1 - Check whether Cloud Internet Services (CIS) has DDoS protection enabled
rule-7c5f6385-67e4-4edf-bec8-c722558b2dec - Check whether Virtual Private Cloud (VPC) security groups have no inbound rules that specify source IP 0.0.0.0/0 to SSH port
rule-9653d2c7-6290-4128-a5a3-65487ba40370 - Check whether Virtual Private Cloud (VPC) security groups have no inbound rules that specify source IP 0.0.0.0/0 to RDP port
rule-96527f89-1867-4581-b923-1400e04661e0 - Check whether Virtual Private Cloud (VPC) has no rules in the default security group
rule-4f477e09-c9aa-4bfb-a6b1-eaeaca15c06a - Check whether Virtual Private Cloud (VPC) security groups have no inbound ports open to the internet (0.0.0.0/0)
rule-9407e5a8-ec51-4228-a01a-0f32364224a6 - Check whether Virtual Private Cloud (VPC) security groups have no outbound ports open to the internet (0.0.0.0/0)
rule-65f42d91-d537-4532-a2c8-c5cd377500a7 - Check whether all virtual server instances have at least one Virtual Private Cloud (VPC) security group attached
rule-9e16b8a4-1255-474e-a8a3-afed67de2627 - Check whether all network interfaces of a virtual server instance have at least one Virtual Private Cloud (VPC) security group attached
rule-9ecf7e84-aa51-42ad-875e-58e9522a5e65 - Check whether VPN for VPC has Internet Key Exchange (IKE) policy encryption that is not set to "triple_des"
rule-b4c58eff-4d19-4d33-840e-56b2ac76585a - Check whether VPN for VPC has Internet Key Exchange (IKE) policy authentication that is set to minimum "sha256"
rule-a8a69cd6-a902-4144-b652-8be68600a029 - Check whether VPN for VPC has a Diffie-Hellman group set to at least group #
rule-f98453ba-ebb9-4d96-aa13-09ef808fb4ba - Check whether VPN for VPC has IPsec policy encryption that is not set to "triple_des"
rule-09298b01-e2c5-43f1-a1b4-0b413fe4f998 - Check whether VPN for VPC has IPsec policy authentication that is set to minimum "sha256"
rule-115eb377-e256-459d-9e17-a868e128bd0c - Check whether VPN for VPC has an IPsec policy that does not have Perfect Forward Secrecy (PFS) disabled
rule-d8d13c3e-5ca0-46c5-a055-2475852c4ec6 - Check whether VPN for VPC authentication is configured with a strong pre-shared key with at least # characters
rule-53895d42-9190-47d8-9a70-0c1ebea5f7c7 - Check whether VPN for VPC has a Dead Peer Detection policy that is set to "restart"
rule-200dc6e7-96f1-49a9-9999-7e4645dc7ea6 - Check whether Application Load Balancer for VPC has public access disabled
rule-0e5151b1-9caf-433c-b4e5-be3d505e458e - Check whether Application Load Balancer for VPC is configured with multiple members in the pool
rule-bfc9d304-a086-43c0-b3ba-d0f101f616df - Check whether Application Load Balancer for VPC listener is configured with default pool
rule-8c923215-afdc-41b1-886c-64ce78741f8c - Check whether Application Load Balancer for VPC has health check configured when created
rule-d491a44c-e7bc-46bc-af07-231da0bb6501 - Check whether Application Load Balancer for VPC has a health check protocol that is either HTTP or HTTPS
rule-cb1180b7-2f8c-40ba-b2dd-207bee6bc17f - Check whether Application Load Balancer for VPC pool uses the HTTPS protocol for HTTPS listeners
rule-65b61a0f-ffdb-41ba-873d-ad329e7fc0ee - Check whether Application Load Balancer for VPC is configured to convert HTTP client requests to HTTPS
rule-d544f217-3723-4376-b3aa-037c5f201e8d - Check whether Application Load Balancer for VPC uses HTTPS (SSL & TLS) instead of HTTP
rule-773385ab-4654-4088-883d-fe9d58bc4ecb - Check whether Block Storage for VPC is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-8ffe83cb-0ba1-47d6-a1e0-53e9932a5691 - Check whether Block Storage for VPC is enabled with customer-managed encryption and Keep Your Own Key (KYOK)
rule-f87929f7-0787-4749-a1ce-35c1f2320401 - Check whether data disks are encrypted with customer-managed keys
rule-390aa9af-c497-4ebc-9958-d572a5b7be3d - Check whether unattached disks are encrypted with customer-managed keys
rule-0f7e7e60-a05c-43a7-be74-70615f14a342 - Check whether Security Groups for VPC contains no outbound rules in security groups that specify source IP 8.8.8.8/32 to DNS port
rule-c4d50b06-9331-4f5c-a3f8-9fe8060efc9b - Check whether Security Groups for VPC doesn't allow PING for the default security group
rule-936158a6-40ff-48ca-91a1-f184aa9b0dff - Check whether Virtual Private Cloud (VPC) classic access is disabled
rule-64c0bea0-8760-4a6b-a56c-ee375a48961e - Check whether Virtual Private Cloud (VPC) has no public gateways attached
rule-64e628f7-4f3a-4c0e-85a4-40300bafe856 - Check whether Virtual Private Cloud (VPC) network access control lists don't allow ingress from 0.0.0.0/0 to any port
rule-f9137be8-2490-4afb-8cd5-a201cb167eb2 - Check whether Virtual Private Cloud (VPC) network access control lists don't allow ingress from 0.0.0.0/0 to SSH port
rule-f1e80ee7-88d5-4bf2-b42f-c863bb24601c - Check whether Virtual Private Cloud (VPC) network access control lists don't allow ingress from 0.0.0.0/0 to RDP port
rule-faacfd1f-454f-4e60-95d7-8fe01158840d - Check whether Virtual Private Cloud (VPC) network access control lists don't allow egress from 0.0.0.0/0 to any port
rule-c0314fad-f377-465e-9f16-fa5aa3d5ebbe - Check whether Virtual Servers for VPC instance has the minimum # interfaces
rule-17b54156-373a-48f9-b340-a7e47acd87b6 - Check whether Virtual Servers for VPC instance doesn't have a floating IP
rule-1af31459-ec38-4a58-91b0-956a17a38954 - Check whether Virtual Servers for VPC boot volumes are enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-4aead0cd-fe26-44f1-b552-8ffdbb86422a - Check whether Virtual Servers for VPC boot volumes are enabled with customer-managed encryption and Keep Your Own Key (KYOK)
rule-a99b5f58-98ef-4208-9a23-e4fa25115d79 - Check whether Virtual Servers for VPC data volumes are enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-df7323fd-0b20-493c-89fe-c0b287817c99 - Check whether Virtual Servers for VPC data volumes are enabled with customer-managed encryption and Keep Your Own Key (KYOK)
rule-6970e312-329d-44dc-b683-5ab14acd6a42 - Check whether Virtual Servers for VPC is provisioned from an encrypted image
rule-24e259fb-608e-486f-bb9d-99b78ae0383c - Check whether Virtual Servers for VPC instances are identifable by the workload they are running based on the Auto Scale for VPC instance group definition
rule-250a7311-0cfd-4b43-8987-e5629f8d99ae - Check whether Application Load Balancer for VPC has application port of the workload that is identifiable by the Auto Scale for VPC instance group definition
rule-c2dd768e-9a49-4d6d-8ac5-8fcfb233a7b0 - Check whether Virtual Private Cloud (VPC) has no subnet with public gateway attached
rule-24508beb-c00a-4c6b-bd04-d38dd8cb7d71 - Check whether App ID user data is encrypted
rule-65196a37-ddcc-422d-8096-09955c4b4e5d - Check whether Event Streams is accessible through public endpoints
rule-3b2768e5-d783-4b0c-a47f-81479af34689 - Check whether Event Streams is accessible only by using private endpoints
rule-c471b983-9dc5-4659-8fb1-4d20c9d516cc - Check whether App ID redirect URIs are using HTTPS only
rule-f4d30138-01c1-409d-a469-fa99a23f2fbd - Check whether App ID redirect URIs are not using localhost or 127.0.0.1
rule-6e0c618d-523d-4352-a1d1-12bb9905b914 - Check whether App ID redirect URIs are not using wildcards (*)
rule-1d2287c7-954e-4425-897b-351c30be723c - Check whether App ID Cloud Directory users aren't able to update their own accounts
rule-9786160b-ee91-45ab-b84b-9806541e0fc6 - Check whether App ID Cloud Directory users aren't able to self-sign up to applications
rule-d9247d0e-dce5-4854-849a-4a9033c8fe8d - Check whether App ID anonymous authentication is disabled
rule-9246d682-f7c5-4aac-8751-3947e4f27b0b - Check whether App ID password strength regex is configured
rule-168f8081-dbd6-4cbc-bf19-f9934b39d59c - Check whether App ID advanced password policies are enabled
rule-dd1600d2-2e69-4ada-bca5-9e70b76ccd21 - Check whether App ID avoid password reuse policy is enabled
rule-5b662adf-fcac-4081-a10d-1aa7109aba4e - Check whether App ID password expiration policy is enabled
rule-59cb7d09-feab-48fc-b18b-ee581ca1761e - Check whether App ID prevent username in password policy is enabled
rule-0b082506-2481-4212-a150-d198357fcc3a - Check whether App ID multifactor authentication (MFA) is enabled for Cloud Directory users
rule-91734f9f-b8ff-4bfd-afb3-db4f789ac38f - Check whether App ID access tokens are configured to expire within # minutes
rule-ded212fe-7def-44ce-9480-0487067b64c4 - Check whether Kubernetes Service clusters are accessible only by using private endpoints
rule-2325054a-c338-474a-9740-0b7034487e40 - Check whether OpenShift clusters are accessible only by using private endpoints
rule-de84afba-b83a-41d6-8c80-d0b6acafe039 - Check whether OpenShift version is up-to-date
NetworkPolicy 分析
這是可用於評估及測試目的的測試版特性。
netpol-analyze
指令會對 Kubernetes 及 Calico NetworkPolicy 資訊清單執行配置檢查。
ibmcloud cra netpol-analyze
此指令會根據 NIST SP 800-53 SC-7(5)控制項來檢查 Kubernetes 應用程式的連線功能配置狀態。 它會驗證每一個工作量的連線功能是否至少由一個 NetworkPolicy 資源所控制,以及是否同時針對入口和出口封鎖未受保護的埠。
netpol-analyze
指令也可以提供所掃描應用程式的連線功能報告,其中顯示應用程式工作量之間所有容許的連線。 您可以使用此報告作為相符性證明,或協助對連線功能問題進行除錯。 您也可以使用此指令來提供已掃描網路原則的 lint 結果,然後使用這些結果來改善網路原則效率及可讀性。 在某些情況下,lint 結果也可能指向網路原則定義中的錯誤。
NetworkPolicy 分析指令選項
下表列出您可以用於 netpol-analyze
指令的指令選項。
指令選項 | 必要或選用 | 說明 |
---|---|---|
--path |
必要 | 要掃描的專案目錄路徑。 |
-r , --report |
必要 | 要在其中建立相符性報告的檔名。 |
-c , --connectivity |
選用 | 要在其中建立連線功能報告的檔名。 |
-l , --lint |
選用 | 要在其中建立 lint 報告的檔名。 |
-s , --strict |
選用 | 當發現連線功能風險時,會導致指令失敗 (結束狀態 2)。 |
範例
下列範例程式碼 Snippet 顯示如何使用 netpol-analyze
指令:
ibmcloud cra netpol-analyze --path PATH --report REPORT [--connectivity CONNFILE] [--lint LINTFILE] [--strict]
ibmcloud cra np --path ./sampleDir --report netpol-report.json --strict
網路配置分析器影像
netpol-analyze
指令在 IBM的 Network Config Analyzer(NCA)中執行。 因為此指令會將 NCA 作為 Docker 映像檔執行,所以您必須在電腦上安裝 Docker。
網路政策分析器的映像 URL 是 icr.io/continuous-delivery/cra/nca
。
如果分析器映像檔尚未在本端登錄中,則 netpol-analyze
指令會從廣域 IBM Cloud® Container Registry取回最新分析器映像檔 (包括任何漏洞的修正程式)。
在 Tekton 管線中使用 Code Risk Analyzer
您可以在 Tekton 管線中使用 task-cra
作業。 當您建立取回要求、手動觸發程式或發出確定時,請使用 Tekton 管線定義。 您也可以建立自己的 Tekton 作業,並從那些作業執行 Code Risk Analyzer。
使用程式碼風險分析器 DevSecOps
您可以在 DevSecOps. 下表列出並說明 DevSecOps 支援的 Code Risk Analyzer 參數。
如需管線映像檔執行 bom-generate
指令所需之相依公用程式指令的相關資訊,請參閱 BOM 需求。 如果遺漏指令,您可以使用 cra-custom-script-path
參數來參照 Script,以安裝那些指令。
名稱 | 類型 | 說明 | 必要或選用 |
---|---|---|---|
artifactory-dockerconfigjson | 密鑰 | base64-encoded Docker config.json 檔案,用於儲存 Artifactory的認證資訊。 |
選用 |
baseimage-auth-user | 文字 | Code Risk Analyzer 掃描所需之應用程式 Dockerfile 基本映像檔的認證。 | 選用 |
baseimage-auth-email | 文字 | Code Risk Analyzer 掃描所需之應用程式 Dockerfile 基本映像檔的認證。 | 選用 |
baseimage-auth-host | 文字 | Code Risk Analyzer 掃描所需之應用程式 Dockerfile 基本映像檔的認證。 | 選用 |
baseimage-auth-password | 密鑰 | Code Risk Analyzer 掃描所需之應用程式 Dockerfile 基本映像檔的認證。 | 選用 |
cra-cveignore-path | 文字 | 相對於應用程式儲存庫根目錄的 cveignore 檔案路徑。 預設檔案路徑為 .cra/.cveignore 。 |
選用 |
cra-custom-script-path | 文字 | 在 Code Risk Analyzer 掃描之前執行的自訂 Script 路徑。 這個 Script 是用來提供選項,以便在 Code Risk Analyzer BOM 工具的環境定義中設定 ENV 變數。 |
選用 |
cra-docker-buildflags | 文字 | 用於建置階段掃描的自訂 Docker 建置指令。 此參數預設為空。 | 選用 |
cra-docker-build-context | 文字 | 如果指定的話,Code Risk Analyzer 會使用路徑參數中的目錄作為 Docker 建置環境定義。 | 選用 |
cra-exclude-devdependencies | 文字 | 指定是否要從掃描中排除 dev 相依關係 (true 或 false )。 預設值為 false 。 |
選用 |
Cra-gradle-exclude-configs | 文字 | 指定掃描中要排除相依關係的 Gradle 配置。 例如,runtimeClasspath,testCompileClasspath 。 此參數預設為空。 |
選用 |
cra-maven-exclude-scopes | 文字 | 指定掃描中要排除相依關係的 Maven 範圍。 例如,test,compile 。 此參數預設為空。 |
選用 |
cra-nodejs-create-package-lock | 文字 | 啟用 Code Risk Analyzer 探索,以建置 node.js 儲存庫的 package-lock.json 檔案。 此參數預設為 false 。 |
選用 |
ibmcloud-api-key | 密鑰 | 與 ibmcloud CLI 工具互動的 IBM Cloud® API 金鑰。 |
必要 |
pipeline-dockerconfigjson | 密鑰 | base64-encoded Docker config.json 檔案會從專用登錄取回映像檔。 |
選用 |
onepepelin-dockerconfigjson | 密鑰 | 已淘汰。 base64-encoded Docker config.json 檔案會從專用登錄取回映像檔。 |
選用 |
pipeline-debug | 選取 | 管線除錯模式開關。 | 選用 |
opt-in-cra-auto-remediation | 文字 | 啟用 Code Risk Analyzer 來執行 cra auto remediation 指令 (true 或 false )。 預設值為 false 。 此指令僅在 Continuous Compliance Pipeline 中受支援。 |
選用 |
opt-in-cra-auto-remediation-enabled-repos | 文字 | 指定要針對 cra auto remediation 指令啟用的儲存庫名稱清單 (以逗點區隔)。 僅當 opt-in-cra-auto-remediation 設定為 true 且僅在 Continuous Compliance Pipeline 中受支援時,才會考量此參數。 |
選用 |
opt-in-cra-auto-remediation-force | 文字 | 強制 cra auto remediation 指令更新套件,即使主要版本與現行有漏洞的套件版本 (true 或 false ) 不同。 僅當 opt-in-cra-auto-remediation 設定為 true 且僅在 Continuous Compliance Pipeline 中受支援時,才會考量此參數。 |
選用 |
自訂指令碼範例 DevSecOps
如果您的 Dockerfile 需要 ARGS,在執行指令之前,您可以使用 cra-custom-script-path
參數,將個別 ARG 設為環境變數。 自訂 Script 路徑是位於使用者專案中的 Script 路徑。 例如,如果 Dockerfile 使用 IAM_USER ARG
,請在名稱為 IAM_USER: export IAM_USER='value'
的 Script 內匯出環境變數。
如果 Dockerfile 所需的 ARG 設為工具鏈內的環境內容,您可以使用 get_env
來取得值。 在此實例中,您可以在 IAM_USER: export IAM_USER=$(get_env iam_user_environment_property_name)
Script 內匯出環境變數。 run-cra
作業會自動挑選這些環境變數,並將它們傳遞至 Docker 建置指令。
下列範例顯示如何使用 cra-custom-script
來匯出 ENV
變數:
#!/usr/bin/env bash
if [[ "${PIPELINE_DEBUG:-0}" == 1 ]]; then
trap env EXIT
env | sort
set -x
fi
export IAM_USER=$(get_env iam_user_environment_property_name)
您也可以根據專案,針對 DevSecOps 基本映像工具版本可能過時的情況,使用 cra-custom-script-path
參數。 例如,您可以更新指令 (例如 pip/pip3
),以探索需要更新 pip 版本的 Python 套件。
下列範例顯示如何使用 cra-custom-script
來更新 pip 版本:
#!/usr/bin/env bash
if [[ "${PIPELINE_DEBUG:-0}" == 1 ]]; then
trap env EXIT
env | sort
set -x
fi
python3 -m pip install --upgrade pip
如果您的 Dockerfile 使用專用 Docker 登錄中的映像檔,您可以在執行 Code Risk Analyzer 之前,使用 cra-custom-script-path
參數向專用 Docker 登錄進行鑑別,並容許 Code Risk Analyzer 取回此映像檔進行掃描。
下列範例顯示如何使用 cra-custom-script
向 ibmcloud
儲存器登錄進行鑑別:
#!/usr/bin/env bash
if [[ "${PIPELINE_DEBUG:-0}" == 1 ]]; then
trap env EXIT
env | sort
set -x
fi
ibmcloud cr login
調試程式碼風險分析器中的 DevSecOps
為了協助除錯,您可以在自己的本端機器上,以指令行介面 (CLI) 方式在本端執行 Code Risk Analyzer。 如需執行 ibmcloud cra bom-generate
指令來產生 BOM 的相關資訊,請參閱 資料清單(BOM)。 產生 BOM 之後,請使用 ibmcloud cra cve
指令來列出任何漏洞。 如需執行 ibmcloud cra cve
指令的相關資訊,請參閱 漏洞掃描。
請確定 run-cra
作業未包含任何錯誤。 如果任務包含錯誤,請檢查您的管道是否使用目前版本的 DevSecOps。 如果檢查 DevSecOps, 的版本仍無法解決問題,以下範例提供一些常見錯誤和建議的解決方案。
FAILED
Error executing docker pull cmd: [docker pull us.icr.io/opentoolchain/ibmnode:14ubisecure]
您可以驗證您具有專用登錄的存取權。 如果您沒有存取權,則可以使用 cra-custom-script-path
參數,並指定在 Code Risk Analyzer 向專用登錄進行鑑別之前執行的自訂 Script 路徑。
FAILED
Error executing docker build cmd for stage-0: exit status 1
如果您的 Dockerfile 需要 ARGS,則建置階段的 docker build
指令無法建置,因為遺漏 ARGS。 需要 cra-custom-script-path
才能將 ARGS 設定為環境變數。 有關設定自訂指令碼的詳細資訊,請參閱 DevSecOps 的自訂指令碼範例。
FAILED
Error executing docker build cmd for stage-0: exit status 1
...
COPY file-to-copy.js file-to-copy.js:
------
failed to compute cache key: "/file-to-copy.js" not found: not found
依預設,Code Risk Analyzer bom-generate
指令會從 Dockerfile 本身位置的環境定義建置 Dockerfile。 如果您想要從根專案目錄的環境定義建置 Dockerfile,請使用 cra-docker-build-context
參數,以容許 Code Risk Analyzer 從此環境定義建置 Dockerfiles。
移除儲存的 Code Risk Analyzer 資料
Code Risk Analyzer 外掛程式不會將任何用戶端資料儲存在其資料庫中。 不過,舊版 Code Risk Analyzer Tekton 作業會安全地將漏洞掃描結果儲存在其資料庫中。
若要要求移除可能儲存在 Code Risk Analyzer 中的任何用戶端資料,請聯絡 IBM 支援中心。
常見問題
取得有關使用 Code Risk Analyzer CLI 的常見問題解答。
如何判斷 CLI 失敗的原因?
在呼叫 Code Risk Analyzer CLI 之前,請將 IBMCLOUD_TRACE
環境變數設為 true,以開啟除錯日誌。
export IBMCLOUD_TRACE=true
請觀察日誌中顯示的 API 呼叫和回應,以判斷失敗的確切原因。
如何對無法從專用登錄取回基本映像檔的 BOM 指令進行除錯。
請確定您已使用 ibmcloud cr login
指令或 docker login
指令,向基本映像檔所在的登錄進行鑑別。
如何對無法分析 Dockerfile 的 BOM 指令進行除錯?
- 執行
docker build
指令並確定它已通過,以驗證 Dockerfile 沒有任何問題。 - 如果您的 Dockerfile 需要傳遞 ARG,請確定 ARG 設為環境變數。 您也可以使用
DOCKERBUILDFLAG
環境變數。 - 向包含基本映像檔的登錄進行鑑別。
我看到非預期的誤判結果。 我應該怎麼辦?
執行 DevSecOps 持續部署 (CD) 管道,在證據櫃中製作更新的 SBOM。 這可能會解決因 DevSecOps Continuous Compliance (CC) pipeline 所產生的舊版 SBOM 而導致誤判的潛在原因。
為何報告或問題的嚴重性與其中一個相關聯的漏洞鏈結不同?
由於我們的漏洞資訊來源最近已變更,您可能會看到與特定漏洞相關聯的嚴重性已變更。 Code Risk Analyzer 將根據所有漏洞來源的計算來判定最佳嚴重性。