IBM Cloud Docs
IBM Cloud 的 Code Risk Analyzer 插件

IBM Cloud 的 Code Risk Analyzer 插件

IBM Cloud® 命令行界面(CLI)提供代码风险分析命令。 您可以使用 IBM Cloud CLI 来分析代码是否存在漏洞以及是否符合特定规则。 在支持工具链的所有 IBM Cloud 区域中都提供了 Code Risk Analyzer。

使用CLI完成以下任务:

  • 生成材料清单 (BOM),列出所有第三方操作系统软件包和应用程序软件包的依赖关系和可用许可证信息。 您也可以生成 CycloneDX-specific 格式的输出。
  • 发现 BOM 中列出的包中的漏洞。 您还可以查看生成的 CycloneDX-specific 格式的报告,或对 Node.js、Maven或 Gradle (Groovy)应用程序使用漏洞自动修复功能。
  • 分析 Terraform 计划以符合某些规则。
  • 分析 Kubernetes 文件以符合某些规则。

从 2024 年 1 月开始,Code Risk Analyzer 使用 Clair 开放式源代码项目 提供的漏洞数据,而不是来自商业公司 Snyk Limited 的数据。 由于此更改,您无需执行任何特定操作。 但是,您可能会观察到代码风险分析器报告的 CVE 的详细信息存在一些差异。

支持的内容

Code Risk Analyzer 支持 Java™,Node.js,Python和 Go 语言。 下表列出并描述了 Code Risk Analyzer 支持的内容。

支持的内容
满足 描述
Java 该仓库需要Maven或 Gradle 才能实现构建自动化。 Maven使用 pom.xml 文件计算依赖关系,而 Gradle 使用 build.gradle(.kts) 文件。 Code Risk Analyzer 可自动修复 Maven 和 Gradle (Groovy) 中的错误。
Node.js package-lock.json 文件计算了相关性。 对于 Node.js,代码风险分析器还可以自动修复。 确保安装的 npm 版本与项目的 npm 版本匹配。
Python 依赖关系是使用 requirements.txt 文件计算的。
Golang 支持 go modgo dep 依赖关系管理。 对于 go modgo.sum 文件必须位于存储库中。 对于 go depGopkg.lock 文件必须位于存储库中。
Dockerfile 将考虑存储库中具有 Dockerfile 模式的文件。 对于容器映像,支持 Debian,Red Hat Enterprise Linux®,Alpine和 Ubuntu Linux distros。
Kubernetes 将考虑以 .yaml.yml 为后缀的文件。 kind 值必须设置为 PodReplicaSetReplicationControllerDeploymentDaemonsetStatefulsetJobCronJobNetworkPolicyIngress
Calico 将考虑以 .yaml.yml 为后缀的文件。 kind 值必须设置为 NetworkPolicyGlobalNetworkPolicyProfileNetworkSetGlobalNetworkSetHostEndpoint
Terraform 必须使用 IBM Cloud 作为 Terraform 提供程序来生成 Terraform 计划文件。

Code Risk Analyzer 会检查存储库中的源代码和映像依赖关系是否存在漏洞。 下表显示了 Code Risk Analyzer 针对不同类型的依赖关系查询的漏洞信息源。

代码风险分析仪检查漏洞时支持的依赖项
依赖关系 受支持的版本 安全通知的源
Alpine 图像 具有供应商安全支持的所有稳定版本。 Alpine SecDB 数据库
Debian 图像 具有供应商安全支持的所有稳定版本。

不会报告与 Debian 源包 linux 关联的二进制包 (例如 linux-libc-dev) 上的 CVE。 这些二进制包中的大多数是内核和内核模块,它们不在容器映像中运行。

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 跟踪程序
Go、npm( JavaScript )、Maven( Java )、PyPI ( Python )、RubyGems ( Ruby )和Packagist(PHP) 具有供应商安全支持的所有稳定版本。 开放式源代码漏洞数据库

代码风险分析器的已知问题

Code Risk Analyzer 无法发现不使用版本控制方案 (例如 major.minor.patch) 的应用程序包上的漏洞。 例如,不支持发行前版本或包含构建元数据的版本。

先决条件

  • 安装 IBM Cloud CLI。 请参阅 下载 IBM Cloud CLI 以获取指示信息。

  • 通过运行以下命令安装代码风险分析器CLI插件:

ibmcloud plugin install cra
  • 确保您可以访问其中一个受支持区域中的工具链。 工具链无需具有任何工具。 有关工具链的更多信息,请参阅通过应用程序创建工具链

  • 通过设置 TOOLCHAIN_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,用于捕获所有依赖关系的快照。 您可以生成标准格式或 CycloneDX's SBOM格式的物料清单。

ibmcloud cra bom-generate

BOM 命令需求

bom-generate 命令依赖于某些外部命令:

  • 如果路径包含 Dockerfile,那么此命令会拉低基本映像,并为每个 Dockerfile 中的每个构建阶段构建映像。 在此场景中,bom-generate 命令要求 Docker clitar 命令可用。
  • 如果路径包含 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 V 2 和 Python V 3。

如果您正在使用 Dockerfile,请确保登录到要从中拉取基本映像的容器注册表。

如果 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)。 默认情况下,此选项设置为 allapps 选项用于将发现限制为应用程序包。 image 选项用于将发现限制为 Dockerfile 中使用的基本映像。 os 选项用于将发现限制为仅在 Dockerfile 中构建阶段。 您可以通过使用逗号对值进行定界来指定多个值,例如 -a os,image,apps
-p, --prev-report 可选 使用先前的 BOM 报告来加快该命令的速度。 例如,如果自生成上次报告以来未更新 Dockerfile,那么该命令将跳过从该 Dockerfile 中发现包。 同一方案适用于其他清单文件,例如 package-lock.json 文件。
-c, --dockerbuildcontext 可选 如果指定了此参数,那么 CRA 将在构建阶段扫描期间使用 path 参数中的目录作为 Docker 构建上下文。
-o, --output 可选 选择 BOM 报告格式。 您可以选择标准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 可选 要使用的目标工具链标识。
-v, --verbose 可选 启用详细日志消息。

正在忽略文件

如果路径包含 .cra/.fileignore 文件,那么不会扫描 .fileignore 文件中指定的文件以查找依赖关系。 .fileignore 文件必须遵循 .gitignore 文件的规则。 与 .gitignore 文件类似,.fileignore 文件可以包含注释,要忽略的目录,要忽略的文件以及其他 模式

以下示例 .fileignore 文件显示了如何排除 bash 脚本,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 构建命令将使用该文件中的指定路径作为相关Docker文件的构建上下文。 JSON对象中的键表示Docker文件的相对路径,而值则指定了各自构建环境的相对路径。

下面是一个 .dockerbuildcontext 文件的示例,它为多个Docker文件定义了不同的构建环境:

{
  "Dockerfile": "./",
  "path/to/different/Dockerfile": "./another/Path"
}

示例

以下代码片段显示如何使用 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 中列出的应用程序包和操作系统包中的漏洞。 根据从多个常见漏洞和风险来源 (CVE) 获取的丰富威胁情报,提供有针对性的修订建议。 Code Risk Analyzer 还可以仅对基于 Node.js 的应用程序的易受攻击包执行自动补救。 您也可以生成标准格式或 CycloneDX's 漏洞可利用性交换(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 的报告。 默认情况下,此选项设置为 appapp 选项用于仅包含没有修订的应用程序包 CVE。 os 选项用于仅包含没有修订的操作系统软件包 CVE。 all 选项用于包含没有修订的应用程序和操作系统包 CVE。 none 选项用于排除没有修订的应用程序和操作系统软件包 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 配置为无限期地省略这些 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) 来定义此属性。

代码风险分析器仅使用这些定义的属性。 您可以添加对函数没有影响的属性。 如果未省略 .cveignore 中定义的漏洞,那么将生成说明原因的日志。 如果省略了 .cveignore 文件中定义的漏洞,那么不会显示单独的日志记录。 在完成报告后,将记录省略的漏洞标识的数目以及带有包名的漏洞标识列表。

以下代码片段显示了样本 .cveignore 文件:

[
    {
        "cve": "CVE-2021-27290",
        "alwaysOmit": true
    },
    {
        "cve": "CVE-2020-8244",
        "untilRemediationAvailable": true,
    }
]

示例

以下代码片段显示如何使用 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 容器建立安全配置态势的规范性指导。 代码风险分析器将这些安全配置用作参考点,并标识用于检入 Kubernetes 应用程序的部署工件 (例如 .yaml 文件) 的安全控件。 此命令还提供每个控制故障的风险评估。

下表列出了您可以在 DevSecOps, 中实现的控件,这些控件是从 CIS Docker 1.13.0 中确定的。 根据 Kubernetes 公共配置评分系统(KCCSS)的开放式源代码引用添加了更多控件。

安全控制
标识 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 套接字未安装在任何容器中。
确保容器不允许不安全地分配 CPU 资源。
确保容器不允许特权升级。
确保容器不会公开 /proc 的不安全部件。
确保未通过共享主机端口公开容器。

部署命令选项

下表列出了可用于 deployment-analyze 命令的命令选项。

部署分析的命令选项。
命令选项 必需或可选 描述
--path 必需 要扫描的项目目录路径。
-r, --report 必需 要在其中创建报告的文件名。
-f, --fileignore 可选 .fileignore 文件的文件路径。
-s, --strict 可选 找到部署风险时命令失败 (退出状态 2) 的结果。

示例

以下代码片段显示如何使用 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 分析器

在将 Terraform 计划应用于环境之前,可以使用 terraform-validate 命令来分析 Terraform 计划是否合规。 此命令会分析指定的 Terraform 计划文件以符合 IBM Cloud® Security and Compliance Center中指定的规则。 此命令生成一致性报告。

您可以指定列出要用于验证的规则和参数的策略文件。 如果未指定策略文件,那么此命令会分析缺省规则集的计划。

ibmcloud cra terraform-validate

Terraform 命令选项

下表列出了可用于 terraform-validate 命令的选项。

执行Terraform分析的命令选项
命令选项 必需或可选 描述
-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 概要文件。

示例

以下代码片段显示如何使用 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 经典概要文件示例

您可以使用 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 分析

这是可用于评估和测试目的的 Beta 功能。

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)。

示例

以下样本代码片段显示了如何使用 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 支持的代码风险分析器参数,并进行了说明。

有关管道映像运行 bom-generate 命令所需的从属实用程序命令的更多信息,请参阅 BOM 需求。 如果缺少命令,那么可以使用 cra-custom-script-path 参数来引用脚本以安装这些命令。

DevSecOps 基于代码风险分析器的参数
名称 Type 描述 必需或可选
artifactory-dockerconfigjson Secret base64-encoded Docker config.json 文件,用于存储 Artifactory的凭证信息。 可选
baseimage-auth-user 文本 代码风险分析器扫描所需的应用程序 Dockerfile 基本映像的凭证。 可选
baseimage-auth-电子邮件 文本 代码风险分析器扫描所需的应用程序 Dockerfile 基本映像的凭证。 可选
baseimage-auth-host 文本 代码风险分析器扫描所需的应用程序 Dockerfile 基本映像的凭证。 可选
baseimage-auth-password Secret 代码风险分析器扫描所需的应用程序 Dockerfile 基本映像的凭证。 可选
拉卡-cveignore-path 文本 相对于应用程序存储库的根目录的 cveignore 文件的路径。 默认文件路径为 .cra/.cveignore 可选
CR-custom-script-path 文本 在 Code Risk Analyzer 扫描之前运行的定制脚本的路径。 此脚本的来源是提供用于在 Code Risk Analyzer BOM 工具的上下文中设置 ENV 变量的选项。 可选
拉卡-Docker-buildflags 文本 用于构建阶段扫描的定制 Docker 构建命令。 此参数默认值为空。 可选
拉卡-Docker-build-context 文本 如果指定了此参数,那么 Code Risk Analyzer 将路径参数中的目录用作 Docker 构建上下文。 可选
拉卡-排除-开发依赖关系 文本 指定是否从扫描中排除开发依赖关系 (truefalse)。 缺省值为 false 可选
卡-格拉德勒-排除-配置 文本 指定要在扫描中排除依赖关系的 Gradle 配置。 例如,runtimeClasspath,testCompileClasspath。 此参数默认值为空。 可选
拉卡-马文-排除作用域 文本 指定要在扫描中排除依赖关系的 Maven 作用域。 例如,test,compile。 此参数默认值为空。 可选
卡-nodejs-create-package-lock 文本 启用 Code Risk Analyzer 发现以构建 node.js 存储库的 package-lock.json 文件。 默认情况下,此参数设置为 false 可选
ibmcloud-api-key Secret ibmcloud CLI 工具交互的 IBM Cloud® API 密钥。 必需
管道-dockerconfigjson Secret 用于从专用注册表拉取映像的 base64-encoded Docker config.json 文件。 可选
onepipeln-dockerconfigjson Secret 不推荐使用。 用于从专用注册表拉取映像的 base64-encoded Docker config.json 文件。 可选
管道调试 选择 管道调试方式开关。 可选
选择性加入-自动补救 文本 启用 Code Risk Analyzer 以运行 cra auto remediation 命令 (truefalse)。 缺省值为 false。 此命令仅在 Continuous Compliance Pipeline 中受支持。 可选
opt-in-cra-auto-修复-enabled-repos 文本 指定要对 cra auto remediation 命令启用的以逗号分隔的存储库名称的列表。 仅当 opt-in-cra-auto-remediation 设置为 true 并且仅在 Continuous Compliance Pipeline 中受支持时,才会考虑此参数。 可选
选择性加入-自动补救-强制 文本 强制 cra auto remediation 命令更新软件包,即使主版本与当前易受攻击的软件包版本 (truefalse) 不同也是如此。 仅当 opt-in-cra-auto-remediation 设置为 true 并且仅在 Continuous Compliance Pipeline 中受支持时,才会考虑此参数。 可选

示例自定义脚本 DevSecOps

如果 Dockerfile 需要 ARGS,那么在运行该命令之前,可以使用 cra-custom-script-path 参数将单个 ARG 设置为环境变量。 定制脚本路径是驻留在用户项目中的脚本的路径。 例如,如果 Dockerfile 使用 IAM_USER ARG,请在名为 IAM_USER: export IAM_USER='value' 的脚本中导出环境变量。 如果将 Dockerfile 所需的 ARG 设置为工具链中的环境属性,那么可以使用 get_env 来获取值。 在此实例中,可以在 IAM_USER: export IAM_USER=$(get_env iam_user_environment_property_name) 脚本中导出环境变量。 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-scriptibmcloud 容器注册表进行认证:

#!/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 之前运行的定制脚本的路径,以向专用注册表进行认证。

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 从此上下文构建 Dockerfile。

除去存储的 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 持续合规(CC)流程生成的旧SBOM导致的误报问题。

为什么报告或问题的严重性与关联漏洞链接的严重性不同?

由于我们的漏洞信息源最近已更改,因此您可能会看到与特定漏洞关联的严重性已更改。 Code Risk Analyzer 将根据所有漏洞源的计算来确定最佳严重性。