代码风险分析器插件 IBM Cloud
IBM Cloud® 命令行界面(CLI)提供代码风险分析命令。 您可以使用 IBM Cloud CLI 分析代码是否存在漏洞以及是否符合某些规则。 代码风险分析器可在支持工具链的所有 IBM Cloud 地区使用。
使用 CLI 完成以下任务:
- 生成物料清单(BOM),列出所有第三方操作系统软件包和应用程序软件包的依赖关系和可用许可信息。 您还可以以 CycloneDX-specific 格式生成该输出。
- 发现 BOM 中列出的软件包中的漏洞。 您还可以查看 CycloneDX-specific 格式的生成报告,或对 Node.js、Maven 或 Gradle (Groovy) 应用程序使用漏洞自动修复功能。
- 分析 Terraform 计划是否符合某些规则。
- 分析 Kubernetes 文件是否符合某些规则。
从 2024 年 1 月开始,代码风险分析器将使用 Clair 开源项目提供的漏洞数据,而不是商业公司 Snyk Limited 提供的数据。 您无需为此采取任何具体行动。 不过,您可能会发现 Code Risk Analyzer 报告的 CVE 在细节上存在一些差异。
支持的内容
代码风险分析器支持 Java™、Node.js、Python 和 Go 语言。 下表列出并描述了代码风险分析仪支持的内容。
满足 | 描述 |
---|---|
Java | 该 repo 需要使用 Maven 或 Gradle 进行自动化构建。 Maven 使用 pom.xml 文件计算依赖关系,而 Gradle 则使用 build.gradle(.kts) 文件。 代码风险分析器可以自动修复 Maven 和 Gradle (Groovy)。 |
Node.js | package-lock.json 文件计算依赖关系。 对于 Node.js,代码风险分析器还可以自动进行修复。 确保安装的 npm 版本与项目的 npm 版本一致。 |
Python | 依赖关系是通过 requirements.txt 和 pyproject.toml 文件计算出来的。 |
Golang | 支持 go mod 和 go dep 依赖关系管理。 对于 go mod ,go.sum 文件必须在 repo 中。 对于 go dep ,Gopkg.lock 文件必须在 repo 中。 |
Dockerfiles | 版本库中具有 Dockerfile 模式的文件会被考虑在内。 对于容器镜像,支持 Debian, Red Hat Enterprise Linux®, Alpine 和 Ubuntu Linux 发行版。 |
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 | Terraform 计划文件必须使用 IBM Cloud 作为 Terraform 提供程序生成。 |
代码风险分析器可检查源代码和软件仓库中的图像依赖关系,查找漏洞。 下表列出了 Code Risk Analyzer 针对不同类型的依赖关系所查询的漏洞信息来源。
依赖关系 | 受支持的版本 | 安全通知的源 |
---|---|---|
Alpine 图像 | 所有稳定版本都有供应商安全支持。 | Alpine SecDB 数据库 |
Debian 图像 | 所有稳定版本都有供应商安全支持。
与 Debian 源软件包 |
Debian 安全漏洞跟踪。 |
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) | 所有稳定版本都有供应商安全支持。 | 开放源代码漏洞数据库。 |
代码风险分析器的已知问题
代码风险分析器无法发现不使用版本计划的应用程序软件包上的漏洞,如 major.minor.patch
。 例如,不支持预发布版本或包含构建元数据的版本。
先决条件
-
安装 IBM Cloud CLI。 有关说明,请参阅 下载 IBM Cloud CLI。
-
运行以下命令安装代码风险分析 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
命令可查看所有已安装插件的当前版本。
代码风险分析器帮助
以下命令显示代码风险分析器命令列表:
ibmcloud cra --help
代码风险分析器命令帮助
以下命令显示命令中使用的标记的详细信息。 使用 ibmcloud cra --help
显示可用命令。
ibmcloud cra <command> --help
物料清单(BOM)
bom-generate
命令会访问指定目录路径下的工件,并执行深度发现以识别所有依赖关系,包括传递依赖关系。 该命令还能识别这些依赖项的发布许可。 创建一个 BOM,捕捉所有依赖关系的快照。 您可以按标准格式或 CycloneDX's SBOM 格式生成 BOM。
ibmcloud cra bom-generate
BOM 命令要求
bom-generate
命令依赖于某些外部命令:
- 如果路径中包含 Dockerfile,该命令会为每个 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
或pyproject.toml
文件,命令会使用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 |
可选 | 要运行的安全检查(应用程序、图像、操作系统,全部)。 默认情况下,该选项设置为 all 。 apps 选项用于限制对应用软件包的发现。 image 选项用于限制发现 Dockerfile 中使用的基本映像。 os 选项用于限制只发现 Dockerfile 中的构建阶段。 您可以使用逗号分隔多个值,如 -a os,image,apps 。 |
-p , --prev-report |
可选 | 使用之前的 BOM 报告可加快命令执行速度。 例如,如果某个 Dockerfile 在上次报告生成后没有更新,该命令就会跳过从该 Dockerfile 中发现软件包的过程。 同样的情况也适用于其他清单文件,如 package-lock.json 文件。 |
-c , --dockerbuildcontext |
可选 | 如果指定,CRA 将在构建阶段扫描时使用路径参数中的目录作为 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 |
可选 | 要使用的目标工具链 ID。 |
-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 构建命令将使用该文件中的指定路径作为相关 Dockerfile 的构建上下文。 JSON 对象中的键代表 Dockerfile 的相对路径,而值则指定各自构建上下文的相对路径。
下面是 .dockerbuildcontext
文件的一个示例,它为多个 Dockerfile 定义了不同的构建上下文:
{
"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 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 |
可选 | 指定创建标记符报告的文件。 该命令仅适用于 autofix 。 |
-c , --cveignore |
可选 | 忽略 CVE 文件的文件路径,该文件包含要忽略的 CVE 列表。 |
-e , --excludedev |
可选 | 指定不希望命令报告开发依赖项的 CVE。 |
--force |
可选 | 强制更新顶层节点软件包,即使主要版本不同。 该命令仅适用于 autofix 。 |
--include-nofix |
可选 | 包括或不包括报告没有已知补救措施的 CVE。 默认情况下,该选项设置为 app 。 app 选项用于只包含没有修复的应用程序软件包 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 进行配置,无限期地忽略它们,直到有补救措施为止,或直到指定的过期日期为止。
下面的示例显示了 .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
文件中定义的漏洞,则不会显示单个日志。 报告完成后,会记录漏报的数量和带有软件包名称的漏洞 ID 列表。
下面的代码片段显示了一个 .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 Common Configuration Scoring System(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 计划文件,看是否符合 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 |
可选 | 该标记接受一个包含 JSON 的文件,用于 Security and Compliance Center V2 附件。 要使用该标志,必须使用 -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 经典配置文件示例
您可以在规则 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 分析器支持以下 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 |
可选 | 创建检查报告的文件名。 |
-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网络配置分析器(NCA) 的一部分运行。 由于该命令以 Docker 映像运行 NCA,因此必须在计算机上安装 Docker 在您的计算机上安装。
网络策略分析器的图像 URL 是 icr.io/continuous-delivery/cra/nca
。
如果本地注册表中还没有分析器映像,netpol-analyze
命令会从全局 IBM Cloud® Container Registry 中提取最新的分析器映像(包括对任何漏洞的修复)。
在 Tekton 管道中使用代码风险分析器
您可以在 Tekton 管道中使用 task-cra
任务。 在创建拉取请求、手动触发或发布提交时,请使用 Tekton 管道定义。 您还可以创建自己的 Tekton 任务,并通过这些任务运行代码风险分析器。
使用代码风险分析器 DevSecOps
您可以在 DevSecOps. 下表列出并说明了 DevSecOps 支持的代码风险分析器参数。
有关管道映像运行 bom-generate
命令所需的从属实用程序命令的更多信息,请参阅 BOM 要求。 如果缺少命令,可以使用 cra-custom-script-path
参数引用脚本来安装这些命令。
名称 | 类型 | 描述 | 必需或可选 |
---|---|---|---|
artifactory-dockerconfigjson | Secret | base64-encoded Docker config.json 文件存储 Artifactory 的凭证信息。 |
可选 |
baseimage-auth-user | 文本 | 代码风险分析器扫描所需的应用程序 Dockerfile 基本映像的凭证。 | 可选 |
baseimage-auth-email | 文本 | 代码风险分析器扫描所需的应用程序 Dockerfile 基本映像的凭证。 | 可选 |
baseimage-auth-host | 文本 | 代码风险分析器扫描所需的应用程序 Dockerfile 基本映像的凭证。 | 可选 |
baseimage-auth-password | Secret | 代码风险分析器扫描所需的应用程序 Dockerfile 基本映像的凭证。 | 可选 |
cra-cveignore-path | 文本 | cveignore 文件的路径,该路径相对于应用程序 repo 的根目录。 默认文件路径为 .cra/.cveignore 。 |
可选 |
cra-custom-script-path | 文本 | 代码风险分析器扫描前运行的自定义脚本的路径。 该脚本的来源是在 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 | 文本 | 启用代码风险分析器发现功能,为 node.js repos 构建 package-lock.json 文件。 该参数默认设置为 false 。 |
可选 |
ibmcloud-api-key | Secret | 与 ibmcloud CLI 工具交互的 IBM Cloud® API 密钥。 |
必需 |
pipeline-dockerconfigjson | Secret | base64-encoded Docker config.json 从私人注册表中提取图像的文件。 |
可选 |
oneipeline-dockerconfigjson | Secret | 不推荐使用。 base64-encoded Docker config.json 从私人注册表中提取图像的文件。 |
可选 |
管道调试 | 选择 | 管道调试模式开关。 | 可选 |
选择自动修复 | 文本 | 启用代码风险分析器运行 cra auto remediation 命令 (true 或 false )。 缺省值为 false 。 此命令仅在持续合规管道中支持。 |
可选 |
选择加入 CRA-auto-remediation-enabled-repos | 文本 | 指定要为 cra auto remediation 命令启用的以逗号分隔的版本库名称列表。 只有当 opt-in-cra-auto-remediation 设置为 true 时,才会考虑该参数,并且仅在持续合规管道中支持该参数。 |
可选 |
选择加入战争遗留爆炸物自动修复部队 | 文本 | 强制 cra auto remediation 命令更新软件包,即使主要版本与当前易受攻击的软件包版本(true 或 false )不同。 只有当 opt-in-cra-auto-remediation 设置为 true 时,才会考虑该参数,并且仅在持续合规管道中支持该参数。 |
可选 |
自定义脚本示例 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-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) 的方式运行代码风险分析器。 有关运行 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
参数允许代码风险分析器从该上下文构建 Dockerfile。
删除已存储的代码风险分析器数据
代码风险分析器插件不会在其数据库中存储任何客户数据。 不过,早期版本的代码风险分析仪 Tekton 任务会将漏洞扫描结果安全地存储在数据库中。
如需删除代码风险分析器中可能存储的任何客户数据,请联系 IBM 支持部门。
常见问题
获取有关使用代码风险分析器 CLI 的常见问题答案。
如何确定 CLI 失败的原因?
在调用 Code Risk Analyzer CLI 之前,请将 IBMCLOUD_TRACE
环境变量设置为 true,以打开调试日志。
export IBMCLOUD_TRACE=true
观察 API 调用和日志中显示的响应,以确定失败的确切原因。
如何调试无法从专用注册表中提取基本映像的 BOM 命令?
使用 ibmcloud cr login
命令或 docker login
命令,确保已通过基本映像所在注册表的身份验证。
如何调试无法分析 Docker 文件的 BOM 命令?
- 运行
docker build
命令并确保其通过,以验证 Dockerfile 没有任何问题。 - 如果 Dockerfile 要求传递 ARG,请确保将 ARG 设置为环境变量。 您也可以使用
DOCKERBUILDFLAG
环境变量。 - 使用包含基础映像的注册表进行验证。
我看到了意想不到的假阳性结果。 我该怎么做?
运行 DevSecOps Continuous Deployment (CD) 管道,在证据柜中生成更新的 SBOM。 这可能会解决因 DevSecOps Continuous Compliance (CC) 管道生成的旧 SBOM 的存在而导致误报的潜在原因。
为什么报告或问题的严重性与相关漏洞链接的严重性不同?
由于我们的漏洞信息来源最近发生了变化,您可能会看到与特定漏洞相关的严重性发生了变化。 代码风险分析器将根据对所有漏洞来源的计算结果,确定最佳严重程度。