IBM Cloud Docs
IBM Cloud 用の Code Risk Analyzer プラグイン

IBM Cloud 用の Code Risk Analyzer プラグイン

IBM Cloud® コマンドラインインターフェース(CLI)は、コードリスク分析用のコマンドを提供します。 IBM Cloud CLI を使用して、コードに脆弱性がないか、また特定のルールに準拠しているかどうかを分析できます。 Code Risk Analyzerは、ツールチェーンがサポートされているすべての IBM Cloud 地域でご利用いただけます。

次のタスクを完了するには、CLI を使用します

  • すべてのサード・パーティー OS パッケージおよびアプリケーション・パッケージの依存関係と使用可能なライセンス情報をリストする部品表 (BOM) を生成します。 この出力は、 CycloneDX-specific 形式でも生成できます。
  • 部品表に記載されているパッケージの脆弱性を発見する。 また、 CycloneDX-specific 形式で生成されたレポートを表示することもできます。また、 Node.js、Maven、または Gradle (Groovy)アプリケーションの脆弱性自動修復機能を使用することもできます。
  • 特定のルールに準拠しているかどうか Terraform プランを分析します。
  • Kubernetes ファイルを分析して、特定のルールに準拠しているかどうかを確認します。

2024 年 1 月から、Code Risk Analyzer は、商用企業の Snyk Limited からのデータではなく、 Clair オープン・ソース・プロジェクト によって提供される脆弱性データを取り込みます。 この変更の結果として、お客様の側で具体的なアクションは必要ありません。 ただし、Code Risk Analyzer によって報告される 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 にとって、Code Risk analyzerは修正作業の自動化も可能にします。 インストールされたnpmのバージョンがプロジェクトのnpmのバージョンと一致していることを確認してください。
Python 依存関係は、requirements.txtファイルを使用して計算されます。
Golang go mod および go dep 依存関係の管理をサポートします。 go mod の場合、go.sum ファイルがリポジトリー内に入っている必要があります。 go dep の場合、Gopkg.lock ファイルがリポジトリー内に入っている必要があります。
Dockerfile リポジトリー内の Dockerfile パターンのファイルが対象となります。 コンテナイメージについては、 Debian、 Red Hat Enterprise Linux®、 Alpine、 Ubuntu、 Linux のディストリビューションがサポートされています。
Kubernetes 接尾部が .yaml.yml のファイルが対象となります。 kind の値は、 PodReplicaSetReplicationControllerDeploymentDaemonsetStatefulsetJobCronJobNetworkPolicy、または Ingress に設定する必要があります。
Calico 接尾部が .yaml.yml のファイルが対象となります。 kind 値は、 NetworkPolicyGlobalNetworkPolicyProfileNetworkSetGlobalNetworkSet、または HostEndpoint に設定する必要があります。
Terraform Terraform プラン・ファイルは、Terraform プロバイダーとして IBM Cloud を使用して生成する必要があります。

Code Risk Analyzer は、リポジトリー内のソース・コードとイメージの依存関係に脆弱性がないかどうかを調べます。 以下の表に、さまざまな種類の依存関係について 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 Tracker
npm ( JavaScript )、Maven ( Java )、 PyPI ( Python )、 RubyGems ( Ruby )、Packagist (PHP) ベンダー・セキュリティーをサポートするすべての安定バージョン。 オープン・ソース脆弱性データベース

Code Risk Analyzer に関する既知の問題

Code Risk Analyzer は、バージョン管理スキームを使用しないアプリケーション・パッケージ (major.minor.patchなど) の脆弱性を検出できません。 例えば、リリース前のバージョンや、ビルド・メタデータを含むバージョンはサポートされません。

前提条件

  • IBM Cloud CLI をインストールします。 手順については、IBM Cloud CLI のダウンロードを参照してください。

  • 以下のコマンドを実行して、Code Risk Analyzer CLI プラグインをインストールします。

ibmcloud plugin install cra
  • サポートされているいずれかの地域のツールチェーンにアクセスできることを確認してください。 ツールチェーンにはツールは必要ありません。 ツールチェーンについて詳しくは、アプリからのツールチェーンの作成を参照してください。

  • TOOLCHAIN_ID環境変数を設定して、ツールチェーン ID を指定します。

export TOOLCHAIN_ID=e22195a5-11e3-44ba-9533-e7c18a3a61a7
  • 以下のコマンドを実行して、IBM Cloud の特定のリージョンにログインします。ここで、[region]は、ツールチェーンが作成されたリージョンです。
ibmcloud login -r [region]
  • オプションとして、CLI を使用する際のデータに対する制御とセキュリティを強化するために、 IBM Cloud エンドポイントへのプライベートルートを使用するオプションがあります。 まず、アカウントで仮想ルーティングと転送を有効にしてから、IBM Cloud プライベート・サービス・エンドポイントの使用を有効にする必要があります。 プライベート接続オプションをサポートするためにアカウントをセットアップする方法について詳しくは、VRF エンドポイントおよびサービス・エンドポイントの有効化を参照してください。

次のコマンドを使用して、 [region] がツールチェーンが作成された地域であるプライベートエンドポイントにログインします。

ibmcloud login -a private.cloud.ibm.com -r [region]

CLI の使用方法を示すコマンド

IBM Cloud CLI およびプラグインの更新が使用可能になると、コマンド・ラインで通知を受け取ります。 最新のコマンドを使用できるように、CLI を最新の状態に保つようにしてください。 ibmcloud plugin listコマンドを実行すると、インストールされているすべてのプラグインの現行バージョンを表示できます。

Code Risk Analyzer のヘルプ

以下のコマンドは、Code Risk Analyzer コマンドのリストを表示します。

ibmcloud cra --help

Code Risk Analyzer コマンド・ヘルプ

次のコマンドは、コマンドで使用されるフラグの詳細を表示します。 使用可能なコマンドを表示するには、ibmcloud cra --helpを使用します。

ibmcloud cra <command> --help

部品表 (BOM)

bom-generateコマンドは、指定されたディレクトリー・パス内の成果物にアクセスし、ディープ・ディスカバリーを実行して、推移的な依存関係を含むすべての依存関係を識別します。 このコマンドは、これらの依存関係が配布されるライセンスも識別します。 すべての依存関係のスナップショットを記録したBOMが作成されます。 BOMは標準フォーマットまたは CycloneDX's SBOMフォーマットで作成できます。

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 ファイルが含まれている場合、コマンドはpipを使用してパッケージの依存関係を生成します。 このシナリオでは、bom-generateコマンドを使用するには、pipコマンドが使用可能になっている必要があります。 Python バージョン 2 と Python バージョン 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 オプション 実行するセキュリティー検査 (アプリ、イメージ、OS、すべて)。 デフォルトでは、このオプションはallに設定されています。 appsオプションは、ディスカバリーをアプリケーション・パッケージに制限するために使用します。 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 の 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 ファイルを使用することで実現できます。これは、Dockerfileのパスを対応するビルドコンテキストにマッピングするJSONファイルです。

プロジェクトディレクトリに .cra/.dockerbuildcontext ファイルが存在する場合、CRAの Docker ビルドコマンドは、このファイル内の指定されたパスを、関連するDockerfileのビルドコンテキストとして使用します。 JSONオブジェクト内のキーはDockerfileへの相対パスを表し、値はそれぞれのビルドコンテキストへの相対パスを指定します。

以下は、複数のDockerfileに対して異なるビルドコンテキストを定義する .dockerbuildcontext ファイルの例です

{
  "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に記載されているアプリケーションパッケージおよびOSパッケージの脆弱性を検出します。 Common Vulnerabilities and Exposures (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 オプション マークダウン・レポートが作成されるファイルを指定します。 このコマンドは、 autofix でのみ使用可能です。
-c, --cveignore オプション 無視する CVE のリストが含まれている CVE 無視ファイルのファイル・パス。
-e, --excludedev オプション コマンドが開発の依存関係について CVE を報告しないように指定します。
--force オプション メジャー・バージョンが異なる場合でも、最上位ノード・パッケージの更新を強制します。 このコマンドは、 autofix でのみ使用可能です。
--include-nofix オプション 既知の修復がない CVE のレポートを含めるか、または除外します。 デフォルトでは、このオプションはappに設定されています。 app オプションは、フィックスのないアプリケーション・パッケージ CVE のみを組み込むために使用されます。 os オプションは、フィックスのない OS パッケージ CVE のみを組み込むために使用されます。 all オプションは、アプリケーションと OS パッケージの両方の CVE をフィックスなしで組み込むために使用されます。 none オプションは、フィックスのないアプリ CVE と OS パッケージ CVE の両方を除外するために使用されます。
--path --autofix が有効になっている場合は必須 スキャンするプロジェクト・ディレクトリー・パス。 このコマンドは、 autofix でのみ使用可能です。
--region オプション ツールチェーンの ibmcloud の地域。
-r, --report オプション 生成されたレポートへのパス。
-o, --output オプション CVE レポート・フォーマットを選択します。 フォーマット出力は、標準 CVE フォーマット (standard) または CycloneDX の 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に設定されている場合、修復パスが使用可能になるまで脆弱性は省略されます。 修復が利用可能になると、脆弱性は除外されずにメッセージが表示されます。 このプロパティーは、有効期限日のプロパティー値より優先されます。
  • 有効期限 - このプロパティーがtrueに設定されていて、有効期限に達していない場合、脆弱性は省略されます。 有効期限日に達すると、脆弱性は除外されずにメッセージが表示されます。 このプロパティーを定義するには、RFC3339 時刻形式 (yyyy-MM-ddTHH:mm:ss[+-]Z) を使用します。

Code Risk Analyzer は、これらの定義済みのプロパティーのみを使用します。 プロパティーを追加しても、機能には影響を及ぼしません。 .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 コンテナーのセキュアな構成状況を確立するための規範的なガイダンスを提供します。 Code Risk Analyzer は、これらのセキュリティー構成を参照点として使用し、 Kubernetes アプリケーションのデプロイメント成果物 ( .yaml ファイルなど) をチェックインするためのセキュリティー管理を識別します。 このコマンドは、統制の失敗ごとのリスク評価も提供します。

次の表は、 CIS、 Docker、 1.13.0 から特定された、 DevSecOps, に実装可能なコントロールをリストアップしたものです。 Kubernetes Common Configuration Scoring System(KCCSS)のオープン・ソース参照に基づいて、さらに制御が追加されます。

セキュリティー管理
ID ルール リスク
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-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 を含むファイルを受け入れます。 このフラグを使用するには、 Security and Compliance Center V2 プロファイルを -p フラグとともに指定する必要があります。

以下のコード・スニペットは、terraform-validateコマンドの使用方法を示しています。

ibmcloud cra terraform-validate --tf-plan TFPLANFILE --report REPORT [--policy-file POLICYFILE] [--quiet] [--region REGION] [--strict] [--toolchainid TOOLCHAINID] [--verbose] [--attachment-file ATTACHMENT_FILE]
ibmcloud cra tf -r report-user-profile.json -t ./tfplan.json  -p ./user-profile.json --verbose

terraform-validateコマンドの Terraform プラン・ファイルの例

{
    "format_version": "0.2",
    "terraform_version": "1.0.2",
    "planned_values": {
        "root_module": {
            "child_modules": [
                {
                    "resources": [
                        {
                            "address": "module.instance.ibm_resource_instance.cos_instance",
                            "mode": "managed",
                            "type": "ibm_resource_instance",
                            "name": "cos_instance",
                            "provider_name": "registry.terraform.io/ibm-cloud/ibm",
                            "schema_version": 0,
                            "values": {
                                "location": "global",
                                "parameters": null,
                                "plan": "lite",
                                "service": "cloud-object-storage",
                                "timeouts": null
                            },
                            "sensitive_values": {
                                "extensions": {},
                                "last_operation": {},
                                "plan_history": [],
                                "tags": []
                            }
                        }
                    ],
                    "address": "module.instance"
                },
                {
                    "resources": [
                        {
                            "address": "module.instance_config.ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration[0]",
                            "mode": "managed",
                            "type": "ibm_cos_bucket",
                            "name": "bad_resource_cos_bucket_missing_all_configuration",
                            "index": 0,
                            "provider_name": "registry.terraform.io/ibm-cloud/ibm",
                            "schema_version": 0,
                            "values": {
                                "activity_tracking": [],
                                "allowed_ip": null,
                                "archive_rule": [],
                                "cross_region_location": null,
                                "endpoint_type": "public",
                                "expire_rule": [],
                                "force_delete": true,
                                "key_protect": null,
                                "metrics_monitoring": [],
                                "region_location": "us-south",
                                "retention_rule": [],
                                "single_site_location": null,
                                "storage_class": "standard",
                                "timeouts": null
                            },
                            "sensitive_values": {
                                "activity_tracking": [],
                                "archive_rule": [],
                                "expire_rule": [],
                                "metrics_monitoring": [],
                                "retention_rule": []
                            }
                        },
                        {
                            "address": "module.instance_config.ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration[1]",
                            "mode": "managed",
                            "type": "ibm_cos_bucket",
                            "name": "bad_resource_cos_bucket_missing_all_configuration",
                            "index": 1,
                            "provider_name": "registry.terraform.io/ibm-cloud/ibm",
                            "schema_version": 0,
                            "values": {
                                "activity_tracking": [],
                                "allowed_ip": null,
                                "archive_rule": [],
                                "cross_region_location": null,
                                "endpoint_type": "public",
                                "expire_rule": [],
                                "force_delete": true,
                                "key_protect": null,
                                "metrics_monitoring": [],
                                "region_location": "us-south",
                                "retention_rule": [],
                                "single_site_location": null,
                                "storage_class": "standard",
                                "timeouts": null
                            },
                            "sensitive_values": {
                                "activity_tracking": [],
                                "archive_rule": [],
                                "expire_rule": [],
                                "metrics_monitoring": [],
                                "retention_rule": []
                            }
                        }
                    ],
                    "address": "module.instance_config"
                }
            ]
        }
    },
    "resource_changes": [
        {
            "address": "module.instance.ibm_resource_instance.cos_instance",
            "module_address": "module.instance",
            "mode": "managed",
            "type": "ibm_resource_instance",
            "name": "cos_instance",
            "provider_name": "registry.terraform.io/ibm-cloud/ibm",
            "change": {
                "actions": [
                    "create"
                ],
                "before": null,
                "after": {
                    "location": "global",
                    "parameters": null,
                    "plan": "lite",
                    "service": "cloud-object-storage",
                    "timeouts": null
                },
                "after_unknown": {
                    "account_id": true,
                    "allow_cleanup": true,
                    "created_at": true,
                    "created_by": true,
                    "crn": true,
                    "dashboard_url": true,
                    "deleted_at": true,
                    "deleted_by": true,
                    "extensions": true,
                    "guid": true,
                    "id": true,
                    "last_operation": true,
                    "locked": true,
                    "name": true,
                    "plan_history": true,
                    "resource_aliases_url": true,
                    "resource_bindings_url": true,
                    "resource_controller_url": true,
                    "resource_crn": true,
                    "resource_group_crn": true,
                    "resource_group_id": true,
                    "resource_group_name": true,
                    "resource_id": true,
                    "resource_keys_url": true,
                    "resource_name": true,
                    "resource_plan_id": true,
                    "resource_status": true,
                    "restored_at": true,
                    "restored_by": true,
                    "scheduled_reclaim_at": true,
                    "scheduled_reclaim_by": true,
                    "service_endpoints": true,
                    "state": true,
                    "status": true,
                    "sub_type": true,
                    "tags": true,
                    "target_crn": true,
                    "type": true,
                    "update_at": true,
                    "update_by": true
                },
                "before_sensitive": false,
                "after_sensitive": {
                    "extensions": {},
                    "last_operation": {},
                    "plan_history": [],
                    "tags": []
                }
            }
        },
        {
            "address": "module.instance_config.ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration[0]",
            "module_address": "module.instance_config",
            "mode": "managed",
            "type": "ibm_cos_bucket",
            "name": "bad_resource_cos_bucket_missing_all_configuration",
            "index": 0,
            "provider_name": "registry.terraform.io/ibm-cloud/ibm",
            "change": {
                "actions": [
                    "create"
                ],
                "before": null,
                "after": {
                    "activity_tracking": [],
                    "allowed_ip": null,
                    "archive_rule": [],
                    "cross_region_location": null,
                    "endpoint_type": "public",
                    "expire_rule": [],
                    "force_delete": true,
                    "key_protect": null,
                    "metrics_monitoring": [],
                    "region_location": "us-south",
                    "retention_rule": [],
                    "single_site_location": null,
                    "storage_class": "standard",
                    "timeouts": null
                },
                "after_unknown": {
                    "activity_tracking": [],
                    "archive_rule": [],
                    "bucket_name": true,
                    "crn": true,
                    "expire_rule": [],
                    "id": true,
                    "metrics_monitoring": [],
                    "resource_instance_id": true,
                    "retention_rule": [],
                    "s3_endpoint_private": true,
                    "s3_endpoint_public": true
                },
                "before_sensitive": false,
                "after_sensitive": {
                    "activity_tracking": [],
                    "archive_rule": [],
                    "expire_rule": [],
                    "metrics_monitoring": [],
                    "retention_rule": []
                }
            }
        },
        {
            "address": "module.instance_config.ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration[1]",
            "module_address": "module.instance_config",
            "mode": "managed",
            "type": "ibm_cos_bucket",
            "name": "bad_resource_cos_bucket_missing_all_configuration",
            "index": 1,
            "provider_name": "registry.terraform.io/ibm-cloud/ibm",
            "change": {
                "actions": [
                    "create"
                ],
                "before": null,
                "after": {
                    "activity_tracking": [],
                    "allowed_ip": null,
                    "archive_rule": [],
                    "cross_region_location": null,
                    "endpoint_type": "public",
                    "expire_rule": [],
                    "force_delete": true,
                    "key_protect": null,
                    "metrics_monitoring": [],
                    "region_location": "us-south",
                    "retention_rule": [],
                    "single_site_location": null,
                    "storage_class": "standard",
                    "timeouts": null
                },
                "after_unknown": {
                    "activity_tracking": [],
                    "archive_rule": [],
                    "bucket_name": true,
                    "crn": true,
                    "expire_rule": [],
                    "id": true,
                    "metrics_monitoring": [],
                    "resource_instance_id": true,
                    "retention_rule": [],
                    "s3_endpoint_private": true,
                    "s3_endpoint_public": true
                },
                "before_sensitive": false,
                "after_sensitive": {
                    "activity_tracking": [],
                    "archive_rule": [],
                    "expire_rule": [],
                    "metrics_monitoring": [],
                    "retention_rule": []
                }
            }
        }
    ],
    "configuration": {
        "provider_config": {
            "ibm": {
                "name": "ibm",
                "version_constraint": "1.25.0",
                "expressions": {
                    "ibmcloud_api_key": {
                        "constant_value": "BYwB2M3TJdDMlCpHaxaWilNHVod05TVkqjIbGqrlm9Iz"
                    }
                }
            },
            "module.instance:ibm": {
                "name": "ibm",
                "version_constraint": "1.25.0",
                "module_address": "module.instance",
                "expressions": {
                    "ibmcloud_api_key": {
                        "constant_value": "BYwB2M3TJdDMlCpHaxaWilNHVod05TVkqjIbGqrlm9Iz"
                    }
                }
            },
            "module.instance_config:ibm": {
                "name": "ibm",
                "version_constraint": "1.25.0",
                "module_address": "module.instance_config"
            }
        },
        "root_module": {
            "module_calls": {
                "instance": {
                    "source": "./instance_module",
                    "module": {
                        "outputs": {
                            "cos_instance_id": {
                                "expression": {
                                    "references": [
                                        "ibm_resource_instance.cos_instance.id",
                                        "ibm_resource_instance.cos_instance"
                                    ]
                                }
                            }
                        },
                        "resources": [
                            {
                                "address": "ibm_resource_instance.cos_instance",
                                "mode": "managed",
                                "type": "ibm_resource_instance",
                                "name": "cos_instance",
                                "provider_config_key": "instance:ibm",
                                "expressions": {
                                    "location": {
                                        "constant_value": "global"
                                    },
                                    "name": {},
                                    "plan": {
                                        "constant_value": "lite"
                                    },
                                    "service": {
                                        "constant_value": "cloud-object-storage"
                                    }
                                },
                                "schema_version": 0
                            }
                        ]
                    }
                },
                "instance_config": {
                    "source": "./instance_config_module",
                    "expressions": {
                        "cos_instance_id": {
                            "references": [
                                "module.instance.cos_instance_id",
                                "module.instance"
                            ]
                        }
                    },
                    "module": {
                        "resources": [
                            {
                                "address": "ibm_cos_bucket.bad_resource_cos_bucket_missing_all_configuration",
                                "mode": "managed",
                                "type": "ibm_cos_bucket",
                                "name": "bad_resource_cos_bucket_missing_all_configuration",
                                "provider_config_key": "instance_config:ibm",
                                "expressions": {
                                    "bucket_name": {},
                                    "region_location": {
                                        "constant_value": "us-south"
                                    },
                                    "resource_instance_id": {
                                        "references": [
                                            "var.cos_instance_id"
                                        ]
                                    },
                                    "storage_class": {
                                        "constant_value": "standard"
                                    }
                                },
                                "schema_version": 0,
                                "count_expression": {
                                    "constant_value": 2
                                }
                            }
                        ],
                        "variables": {
                            "cos_instance_id": {
                                "description": "COS Instance ID"
                            }
                        }
                    },
                    "depends_on": [
                        "module.instance"
                    ]
                }
            }
        }
    }
}

terraform-validate コマンドの SCC V2 プロファイル・ファイル・スキーマの例

{
	"title": "User Profile Standard v2 Schema",
	"type": "object",
	"properties": {
		"id": {
			"type": "string"
		},
		"profile_name": {
			"type": "string"
		},
		"profile_version": {
			"type": "string"
		},
		"controls": {
			"type": "array",
			"items": {
				"type": "object",
				"properties": {
					"control_specifications": {
						"type": "array",
						"items": {
							"type": "object",
							"properties": {
								"assessment_count": {
									"type": "number"
								},
								"assessments": {
									"type": "array",
									"items": {
										"type": "object",
										"properties": {
											"assessment_type": {
												"type": "string"
											},
											"assessment_method": {
												"type": "string"
											},
											"assessment_description": {
												"type": "string"
											},
											"assessment_id": {
												"type": "string"
											},
											"parameter_count": {
												"type": "number"
											},
											"parameters": {
												"type": "array",
												"items": {
													"type": "object",
													"properties": {
														"parameter_name": {
															"type": "string"
														},
														"parameter_display_name": {
															"type": "string"
														},
														"parameter_type": {
															"type": "string"
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		},
		"default_parameters": {
			"type": "array",
			"items": {
				"type": "object",
				"properties": {
					"assessment_type":  {
						"type": "string"
					},
					"assessment_id": {
						"type": "string"
					},
					"parameter_name": {
						"type": "string"
					},
					"parameter_default_value": {
						"type": "string"
					},
					"parameter_display_name": {
						"type": "string"
					},
					"parameter_type": {
						"type": "string"
					}
				}
			}
		}
	},
	"required": ["default_parameters", "controls", "profile_name", "profile_version"]

terraform-validate コマンドの SCC V2 クラシック・プロファイル・ファイルの例

ルール ID の前に rule- を付けることができます。

{
  "schema_version": "2.0",
  "scc_rules": [
    {
      "scc_rule_id": "548a3321-6a39-400c-9c2d-0df9a13afd02"
    },
    {
      "scc_rule_id": "726ec899-505e-4de9-ac1b-9578ef62f89f"
    },
    {
      "scc_rule_id": "962e2bde-2a4f-4e07-a352-ce17708b1e85"
    },
    {
      "scc_rule_id": "9653d2c7-6290-4128-a5a3-65487ba40370"
    },
    {
      "scc_rule_id": "d8d13c3e-5ca0-46c5-a055-2475852c4ec6"
    },
    {
      "scc_rule_id": "0f7e7e60-a05c-43a7-be74-70615f14a342"
    },
    {
      "scc_rule_id": "979fd713-d39f-4efe-ba02-bf6fc07e57bb"
    },
    {
      "scc_rule_id": "rule-e76a3a81-b0d0-41fc-947d-13dc9cfff379"
    },
    {
      "scc_rule_id": "caf5e45d-ccc8-4e35-b124-e1b4c8bcab71"
    },
    {
      "scc_rule_id": "rule-1edc74ae-0dad-4ea1-865d-89e3214d240f"
    },
    {
      "scc_rule_id": "064d9004-8728-4988-b19a-1805710466f6"
    },
    {
      "scc_rule_id": "rule-caf5e45d-ccc8-4e35-b124-e1b4c8bcab71"
    }
  ],
  "scc_parameters": {
    "ibm_minimum_password_length": 12,
    "ibm_password_reuse_prevention": 4,
    "allowed_admins_per_account": "10",
    "api_keys_rotated_days": 90,
    "account_owner_last_login_days": 30,
    "no_of_admins_for_iam": 3,
    "no_of_service_id_admins_for_iam": 3,
    "no_of_managers_for_iam": 0,
    "no_of_service_id_managers_for_iam": 0,
    "iam_service_ids_max_count": 3,
    "ssh_port": 25,
    "rdp_port": 3390,
    "no_pre_shared_key_characters": 30,
    "dns_port": 60,
    "vm_nic_count": 1,
    "no_of_admins_for_container_registry ": 3,
    "no_of_service_id_admins_for_container_registry": 3,
    "no_of_managers_for_container_registry": 0,
    "no_of_service_id_managers_for_container_registry": 0,
    "access_tokens_expire": 120
  }
}

Security and Compliance Center ルール

Terraform Analyzerは、次の Security and Compliance Center ルールをサポートしています

rule-f8722625-1968-4d7a-93cb-4b0f8da726da - Check whether IBMid password policy requires at least one uppercase letter
rule-789cb35b-5bdf-46d3-8b59-e1377e3b211c - Check whether IBMid password policy requires at least one lowercase letter
rule-81b36ae4-0f15-41c7-adac-fa9586ff46ab - Check whether IBMid password policy requires at least one number
rule-979fd713-d39f-4efe-ba02-bf6fc07e57bb - Check whether IBMid password policy requires minimum length of 12 characters
rule-e76a3a81-b0d0-41fc-947d-13dc9cfff379 - Check whether IBMid password policy prevents password reuse below the minimum of #
rule-759d504b-9eed-4602-8b5b-7244bf3f5690 - Check whether IBMid password can contain only printable ASCII characters (in the range 33 - 126)
rule-bcbd57e1-3cdc-4b6d-820b-2c63bc777e19 - Check whether IBMid password policy contains spaces or any of the following characters: ;:("?)<>
rule-fa06f6f2-b98e-49ac-aa55-d57de9e320d3 - Check whether IBMid uses a password meter that coaches users to create strong passwords that exceed the minimum requirements
rule-548a3321-6a39-400c-9c2d-0df9a13afd02 - Check whether IAM roles are used to create IAM policies for IBM resources
rule-726ec899-505e-4de9-ac1b-9578ef62f89f - Check whether a support role has been assigned in IAM to manage cases in the IBM Cloud Support Center
rule-962e2bde-2a4f-4e07-a352-ce17708b1e85 - Check whether API keys are not created in IAM during the initial setup of IAM users
rule-61fa114a-2bb9-43fd-8068-b873b48bdf79 - Check whether IAM users are attached to at least one access group
rule-4d86c074-097e-4ff3-a763-ccff128388e2 - Check whether multifactor authentication (MFA) is enabled at the account level
rule-0704e840-e443-4781-b9be-ec57469d09c1 - Check whether permissions for API key creation are limited and configured in IAM settings for the account owner
rule-d61c20c9-c0be-443b-af0c-0d900601e154 - Check whether Cloud Object Storage public access is disabled in IAM settings (not applicable to ACLs managed using S3 APIs)
rule-0244c010-fde6-4db3-95aa-8952bd292ac3 - Check whether permissions for service ID creation are limited and configured in IAM settings for the account owner
rule-ed64fa73-81e5-4920-8519-acfad845dd6c - Check whether Identity and Access Management (IAM) is enabled with audit logging
rule-b2232217-34a6-4fe8-a791-5903f1cc89ca - Check whether Cloud Shell is disabled in account settings
rule-10de7433-19e4-40a7-aebf-eddf1f75a68c - Check whether Cloud Object Storage is enabled with encryption
rule-7c86bb59-d677-422d-875c-0259053fad20 - Check whether Cloud Object Storage is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-222d6531-1fc7-4485-8771-35eb46c78877 - Check whether Cloud Object Storage is accessible only through HTTPS
rule-7c52a1ce-26cd-4cde-baa7-3bfb3703cf74 - Check whether Cloudant is accessible only through HTTPS
rule-f6197ee2-31bf-4d73-aacd-316c41a48df3 - Check whether Cloud Object Storage is accessible only by using private endpoints
rule-8cbd597c-7471-42bd-9c88-36b2696456e9 - Check whether Cloud Object Storage network access is restricted to a specific IP range
rule-c97259ee-336d-4c5f-b436-1868107a9558 - Check whether Cloud Object Storage is enabled with customer-managed encryption and Keep Your Own Key (KYOK)
rule-ef1db4bb-2490-48a9-883c-a20fea3db0e5 - Check whether Databases for MongoDB is enabled with encryption
rule-7f7ca588-9412-40a9-9bd8-0e5d19141e98 - Check whether Databases for MongoDB is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-77b99b6f-51dc-4290-b20c-7003941c7a46 - Check whether Databases for MongoDB is accessible only through HTTPS
rule-7b210b18-f849-4fa8-bd92-8e47921de51d - Check whether Databases for MongoDB is accessible only by using private endpoints
rule-c58bb2b9-7942-45ab-b9d4-e39c8430f570 - Check whether Databases for Redis is enabled with encryption
rule-e3cad136-17a8-4227-b8af-0be609da1da0 - Check whether Databases for Redis is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-90e3908d-27c3-4050-bb12-413dfc606f5c - Check whether Databases for Redis is accessible only through HTTPS
rule-c48dfb73-ede0-4ebf-b912-214379cd4ce7 - Check whether Databases for Redis is accessible only by using private endpoints
rule-ac09e136-8581-416a-a865-e9fc35a758be - Check whether Databases for Elasticsearch is enabled with encryption
rule-871594ca-0a70-492b-8a42-6f9474445f01 - Check whether Databases for Elasticsearch is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-47ca5017-27e9-4b8b-95d3-c2529271fbb1 - Check whether Databases for Elasticsearch is accessible only through HTTPS
rule-026e6d36-6a15-4623-846d-cab6f3b789d9 - Check whether Databases for Elasticsearch is accessible only by using private endpoints
rule-d634caeb-e5a6-467a-a4ac-8da8fd39f9ef - Check whether Databases for etcd is enabled with encryption
rule-42612696-2b8e-4fa7-8c17-78f191d2e1a0 - Check whether Databases for etcd is accessible only through HTTPS
rule-458decc2-a081-4c49-8f31-eeaf4833d8c8 - Check whether Databases for etcd is accessible only by using private endpoints
rule-4d7e56d6-f657-418c-9e49-6d248b2cf5a6 - Check whether Databases for PostgreSQL is enabled with encryption
rule-041ff30b-7167-4411-985d-5ad32ab6f850 - Check whether Databases for PostgreSQL is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-872db4fc-2f7c-4ba0-ace7-dc468f6813c7 - Check whether Databases for PostgreSQL is accessible only through HTTPS
rule-094495cf-c092-4dcb-96b8-3654c4bcf787 - Check whether Databases for PostgreSQL is accessible only by using private endpoints
rule-beb7b289-706b-4dc0-b01d-b1d15d4331e3 - Check whether Databases for MongoDB network access is restricted to a specific IP range
rule-04d856f1-68ce-4cba-b800-ba49f3c4f1a1 - Check whether Databases for Redis network access is restricted to specific IP range
rule-b5c06228-3f38-4d98-837f-2fe10d6ff9d5 - Check whether Databases for Elasticsearch network access is restricted to a specific IP range
rule-18540c4e-b96d-4ab9-a619-d541cc5a2824 - Check whether Databases for etcd network access is restricted to a specific IP range
rule-9b2d8054-bc93-44fd-901b-91f677287e84 - Check whether Databases for PostgreSQL network access is restricted to a specific IP range
rule-f6b7a692-8e48-4e74-b957-f5d591a7a15d - Check whether Key Protect has high availability
rule-d0725d07-27e6-4079-a3bc-746d5ccae00f - Check whether Hyper Protect Crypto Services instance is enabled with a dual authorization deletion policy
rule-da567ec9-8e24-4c65-993b-ad290bfdb855 - Check whether Cloud Object Storage buckets are enabled with IBM Activity Tracker
rule-0fb54bb2-773b-4cec-81b0-1ca7d8049ba0 - Check whether Cloud Object Storage buckets are enabled with IBM Cloud Monitoring
rule-5910ed25-7ad7-42d0-8e42-905df0123346 - Check whether IBM Activity Tracker is provisioned in multiple regions in an account
rule-d592e06a-8756-4efc-a401-1ec215168f48 - Check whether IBM Activity Tracker trails are integrated with LogDNA logs
rule-c98fab05-5119-451a-b100-35df840d2326 - Check whether IBM Activity Tracker logs are encrypted at rest
rule-1cdad315-c39e-4d7e-99ef-8af88ba410c1 - Check whether Cloud Internet Services (CIS) has web application firewall enabled
rule-564ed93b-1927-4562-8a90-fbae173cdee1 - Check whether Cloud Internet Services (CIS) has DDoS protection enabled
rule-7c5f6385-67e4-4edf-bec8-c722558b2dec - Check whether Virtual Private Cloud (VPC) security groups have no inbound rules that specify source IP 0.0.0.0/0 to SSH port
rule-9653d2c7-6290-4128-a5a3-65487ba40370 - Check whether Virtual Private Cloud (VPC) security groups have no inbound rules that specify source IP 0.0.0.0/0 to RDP port
rule-96527f89-1867-4581-b923-1400e04661e0 - Check whether Virtual Private Cloud (VPC) has no rules in the default security group
rule-4f477e09-c9aa-4bfb-a6b1-eaeaca15c06a - Check whether Virtual Private Cloud (VPC) security groups have no inbound ports open to the internet (0.0.0.0/0)
rule-9407e5a8-ec51-4228-a01a-0f32364224a6 - Check whether Virtual Private Cloud (VPC) security groups have no outbound ports open to the internet (0.0.0.0/0)
rule-65f42d91-d537-4532-a2c8-c5cd377500a7 - Check whether all virtual server instances have at least one Virtual Private Cloud (VPC) security group attached
rule-9e16b8a4-1255-474e-a8a3-afed67de2627 - Check whether all network interfaces of a virtual server instance have at least one Virtual Private Cloud (VPC) security group attached
rule-9ecf7e84-aa51-42ad-875e-58e9522a5e65 - Check whether VPN for VPC has Internet Key Exchange (IKE) policy encryption that is not set to "triple_des"
rule-b4c58eff-4d19-4d33-840e-56b2ac76585a - Check whether VPN for VPC has Internet Key Exchange (IKE) policy authentication that is set to minimum "sha256"
rule-a8a69cd6-a902-4144-b652-8be68600a029 - Check whether VPN for VPC has a Diffie-Hellman group set to at least group #
rule-f98453ba-ebb9-4d96-aa13-09ef808fb4ba - Check whether VPN for VPC has IPsec policy encryption that is not set to "triple_des"
rule-09298b01-e2c5-43f1-a1b4-0b413fe4f998 - Check whether VPN for VPC has IPsec policy authentication that is set to minimum "sha256"
rule-115eb377-e256-459d-9e17-a868e128bd0c - Check whether VPN for VPC has an IPsec policy that does not have Perfect Forward Secrecy (PFS) disabled
rule-d8d13c3e-5ca0-46c5-a055-2475852c4ec6 - Check whether VPN for VPC authentication is configured with a strong pre-shared key with at least # characters
rule-53895d42-9190-47d8-9a70-0c1ebea5f7c7 - Check whether VPN for VPC has a Dead Peer Detection policy that is set to "restart"
rule-200dc6e7-96f1-49a9-9999-7e4645dc7ea6 - Check whether Application Load Balancer for VPC has public access disabled
rule-0e5151b1-9caf-433c-b4e5-be3d505e458e - Check whether Application Load Balancer for VPC is configured with multiple members in the pool
rule-bfc9d304-a086-43c0-b3ba-d0f101f616df - Check whether Application Load Balancer for VPC listener is configured with default pool
rule-8c923215-afdc-41b1-886c-64ce78741f8c - Check whether Application Load Balancer for VPC has health check configured when created
rule-d491a44c-e7bc-46bc-af07-231da0bb6501 - Check whether Application Load Balancer for VPC has a health check protocol that is either HTTP or HTTPS
rule-cb1180b7-2f8c-40ba-b2dd-207bee6bc17f - Check whether Application Load Balancer for VPC pool uses the HTTPS protocol for HTTPS listeners
rule-65b61a0f-ffdb-41ba-873d-ad329e7fc0ee - Check whether Application Load Balancer for VPC is configured to convert HTTP client requests to HTTPS
rule-d544f217-3723-4376-b3aa-037c5f201e8d - Check whether Application Load Balancer for VPC uses HTTPS (SSL & TLS) instead of HTTP
rule-773385ab-4654-4088-883d-fe9d58bc4ecb - Check whether Block Storage for VPC is enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-8ffe83cb-0ba1-47d6-a1e0-53e9932a5691 - Check whether Block Storage for VPC is enabled with customer-managed encryption and Keep Your Own Key (KYOK)
rule-f87929f7-0787-4749-a1ce-35c1f2320401 - Check whether data disks are encrypted with customer-managed keys
rule-390aa9af-c497-4ebc-9958-d572a5b7be3d - Check whether unattached disks are encrypted with customer-managed keys
rule-0f7e7e60-a05c-43a7-be74-70615f14a342 - Check whether Security Groups for VPC contains no outbound rules in security groups that specify source IP 8.8.8.8/32 to DNS port
rule-c4d50b06-9331-4f5c-a3f8-9fe8060efc9b - Check whether Security Groups for VPC doesn't allow PING for the default security group
rule-936158a6-40ff-48ca-91a1-f184aa9b0dff - Check whether Virtual Private Cloud (VPC) classic access is disabled
rule-64c0bea0-8760-4a6b-a56c-ee375a48961e - Check whether Virtual Private Cloud (VPC) has no public gateways attached
rule-64e628f7-4f3a-4c0e-85a4-40300bafe856 - Check whether Virtual Private Cloud (VPC) network access control lists don't allow ingress from 0.0.0.0/0 to any port
rule-f9137be8-2490-4afb-8cd5-a201cb167eb2 - Check whether Virtual Private Cloud (VPC) network access control lists don't allow ingress from 0.0.0.0/0 to SSH port
rule-f1e80ee7-88d5-4bf2-b42f-c863bb24601c - Check whether Virtual Private Cloud (VPC) network access control lists don't allow ingress from 0.0.0.0/0 to RDP port
rule-faacfd1f-454f-4e60-95d7-8fe01158840d - Check whether Virtual Private Cloud (VPC) network access control lists don't allow egress from 0.0.0.0/0 to any port
rule-c0314fad-f377-465e-9f16-fa5aa3d5ebbe - Check whether Virtual Servers for VPC instance has the minimum # interfaces
rule-17b54156-373a-48f9-b340-a7e47acd87b6 - Check whether Virtual Servers for VPC instance doesn't have a floating IP
rule-1af31459-ec38-4a58-91b0-956a17a38954 - Check whether Virtual Servers for VPC boot volumes are enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-4aead0cd-fe26-44f1-b552-8ffdbb86422a - Check whether Virtual Servers for VPC boot volumes are enabled with customer-managed encryption and Keep Your Own Key (KYOK)
rule-a99b5f58-98ef-4208-9a23-e4fa25115d79 - Check whether Virtual Servers for VPC data volumes are enabled with customer-managed encryption and Bring Your Own Key (BYOK)
rule-df7323fd-0b20-493c-89fe-c0b287817c99 - Check whether Virtual Servers for VPC data volumes are enabled with customer-managed encryption and Keep Your Own Key (KYOK)
rule-6970e312-329d-44dc-b683-5ab14acd6a42 - Check whether Virtual Servers for VPC is provisioned from an encrypted image
rule-24e259fb-608e-486f-bb9d-99b78ae0383c - Check whether Virtual Servers for VPC instances are identifable by the workload they are running based on the Auto Scale for VPC instance group definition
rule-250a7311-0cfd-4b43-8987-e5629f8d99ae - Check whether Application Load Balancer for VPC has application port of the workload that is identifiable by the Auto Scale for VPC instance group definition
rule-c2dd768e-9a49-4d6d-8ac5-8fcfb233a7b0 - Check whether Virtual Private Cloud (VPC) has no subnet with public gateway attached
rule-24508beb-c00a-4c6b-bd04-d38dd8cb7d71 - Check whether App ID user data is encrypted
rule-65196a37-ddcc-422d-8096-09955c4b4e5d - Check whether Event Streams is accessible through public endpoints
rule-3b2768e5-d783-4b0c-a47f-81479af34689 - Check whether Event Streams is accessible only by using private endpoints
rule-c471b983-9dc5-4659-8fb1-4d20c9d516cc - Check whether App ID redirect URIs are using HTTPS only
rule-f4d30138-01c1-409d-a469-fa99a23f2fbd - Check whether App ID redirect URIs are not using localhost or 127.0.0.1
rule-6e0c618d-523d-4352-a1d1-12bb9905b914 - Check whether App ID redirect URIs are not using wildcards (*)
rule-1d2287c7-954e-4425-897b-351c30be723c - Check whether App ID Cloud Directory users aren't able to update their own accounts
rule-9786160b-ee91-45ab-b84b-9806541e0fc6 - Check whether App ID Cloud Directory users aren't able to self-sign up to applications
rule-d9247d0e-dce5-4854-849a-4a9033c8fe8d - Check whether App ID anonymous authentication is disabled
rule-9246d682-f7c5-4aac-8751-3947e4f27b0b - Check whether App ID password strength regex is configured
rule-168f8081-dbd6-4cbc-bf19-f9934b39d59c - Check whether App ID advanced password policies are enabled
rule-dd1600d2-2e69-4ada-bca5-9e70b76ccd21 - Check whether App ID avoid password reuse policy is enabled
rule-5b662adf-fcac-4081-a10d-1aa7109aba4e - Check whether App ID password expiration policy is enabled
rule-59cb7d09-feab-48fc-b18b-ee581ca1761e - Check whether App ID prevent username in password policy is enabled
rule-0b082506-2481-4212-a150-d198357fcc3a - Check whether App ID multifactor authentication (MFA) is enabled for Cloud Directory users
rule-91734f9f-b8ff-4bfd-afb3-db4f789ac38f - Check whether App ID access tokens are configured to expire within # minutes
rule-ded212fe-7def-44ce-9480-0487067b64c4 - Check whether Kubernetes Service clusters are accessible only by using private endpoints
rule-2325054a-c338-474a-9740-0b7034487e40 - Check whether OpenShift clusters are accessible only by using private endpoints
rule-de84afba-b83a-41d6-8c80-d0b6acafe039 - Check whether OpenShift version is up-to-date

NetworkPolicy 分析

これは評価およびテストを目的として提供されているベータ版機能です。

netpol-analyze コマンドは、 Kubernetes および Calico NetworkPolicy マニフェストに対して構成検査を実行します。

ibmcloud cra netpol-analyze

このコマンドは、 NIST SP 800-53 SC-7(5)制御に照らして Kubernetes アプリケーションの接続構成状況を検査します。 すべてのワークロードの接続が少なくとも 1 つの 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 での Code Risk Analyzer の使用

Code Risk Analyzer は、DevSecOpsで使用できます。 以下の表では、DevSecOps でサポートされる Code Risk Analyzer パラメーターをリストし、説明しています。

bom-generateコマンドを実行するためにパイプライン・イメージが必要とする従属ユーティリティー・コマンドについて詳しくは、BOM 要件を参照してください。 コマンドが欠落している場合は、cra-custom-script-pathパラメーターを使用して、それらのコマンドをインストールするスクリプトを参照できます。

DevSecOps Code Risk Analyzerに基づくパラメータ
名前 タイプ 説明 必須またはオプション
artifactory-dockerconfigjson シークレット artifactory の資格情報を保管する Base64 エンコードの Docker config.json ファイル。 オプション
baseimage-auth-user テキスト Code Risk Analyzer スキャンで必要とされるアプリケーション Dockerfile の基本イメージの資格情報。 オプション
baseimage-auth-email テキスト Code Risk Analyzer スキャンで必要とされるアプリケーション Dockerfile の基本イメージの資格情報。 オプション
baseimage-auth-host テキスト Code Risk Analyzer スキャンで必要とされるアプリケーション Dockerfile の基本イメージの資格情報。 オプション
baseimage-auth-password シークレット Code Risk Analyzer スキャンで必要とされるアプリケーション Dockerfile の基本イメージの資格情報。 オプション
cra-cveignore-path テキスト アプリケーション・リポジトリーのルートを基準とした、cveignoreファイルへの相対パス。 デフォルトのファイル・パスは .cra/.cveignore です。 オプション
cra-custom-script-path テキスト Code Risk Analyzer スキャン前に実行されるカスタム・スクリプトへのパス。 このスクリプトは、Code Risk Analyzer BOM ツールのコンテキストでENV変数を設定するオプションを提供するために提供されています。 オプション
cra-docker-buildflags テキスト ビルド・ステージ・スキャン用のカスタム Docker ビルド・コマンド。 このパラメーターは、デフォルトでは空です。 オプション
cra-docker-build-context テキスト 指定された場合、Code Risk Analyzer は、パス・パラメーター内のディレクトリーを Docker ビルド・コンテキストとして使用します。 オプション
cra-exclude-devdependencies テキスト スキャンから開発依存関係を除外するかどうかを指定します (true または false)。 デフォルト値はfalseです。 オプション
cra-gradle-exclude-configs テキスト スキャンで依存関係を除外する Gradle 構成を指定します。 例えば、runtimeClasspath,testCompileClasspath です。 このパラメーターは、デフォルトでは空です。 オプション
cra-maven-exclude-scopes テキスト スキャンから依存関係を除外する Maven スコープを指定します。 例えば、test,compile です。 このパラメーターは、デフォルトでは空です。 オプション
cra-nodejs-create-package-lock テキスト Code Risk Analyzer ディスカバリーを有効にすると、node.js リポジトリーのpackage-lock.jsonファイルを作成できるようにします。 このパラメーターは、デフォルトではfalseに設定されています。 オプション
ibmcloud-api-key シークレット ibmcloud CLI ツールと対話するための IBM Cloud® API キー。 必須
pipeline-dockerconfigjson シークレット プライベート・レジストリーからイメージをプルするための Base64 エンコードの Docker config.json ファイル。 オプション
onepipeline-dockerconfigjson シークレット 非推奨。 プライベート・レジストリーからイメージをプルするための Base64 エンコードの Docker config.json ファイル。 オプション
pipeline-debug 選択 パイプラインのデバッグ・モードのスイッチ。 オプション
opt-in-cra-auto-修復 テキスト Code Risk Analyzer が cra auto remediation コマンド (true または false) を実行できるようにします。 デフォルト値は falseです。 このコマンドは、継続的コンプライアンス・パイプラインでのみサポートされます。 オプション
opt-in-cra-auto-remediation-enabled-repos テキスト cra auto remediation コマンドで使用可能にするリポジトリー名のコンマ区切りリストを指定します。 このパラメーターは、 opt-in-cra-auto-remediationtrue に設定されている場合にのみ考慮され、継続的コンプライアンス・パイプラインでのみサポートされます。 オプション
opt-in-cra-auto-remediation-force テキスト メジャー・バージョンが現在の脆弱なパッケージ・バージョン (true または false) と異なる場合でも、 cra auto remediation コマンドを強制的にパッケージを更新します。 このパラメーターは、 opt-in-cra-auto-remediationtrue に設定されている場合にのみ考慮され、継続的コンプライアンス・パイプラインでのみサポートされます。 オプション

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)

cra-custom-script-pathパラメーターは、プロジェクトに基づいて、DevSecOps 基本イメージ・ツールのバージョンが古くなっている可能性があるシナリオにも使用できます。 例えば、新しい pip バージョンを必要とする Python パッケージを検出するために、pip/pip3などのコマンドを更新できます。

以下の例は、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 レジストリーのイメージを使用する場合は、cra-custom-script-pathパラメーターを使用して、Code Risk Analyzer を実行する前にプライベート 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 での Code Risk Analyzer のデバッグ

デバッグを支援するために、独自のローカル・マシンで Code Risk Analyzer をコマンド・ライン・インターフェース (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 が必要な場合、ARGS が欠落しているため、ビルド・ステージのdocker buildコマンドはビルドに失敗します。 ARGS を環境変数としてセットアップするには、cra-custom-script-pathが必要です。 カスタム・スクリプトのセットアップについて詳しくは、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 サポートまでご連絡ください。

FAQ

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 は、脆弱性のすべてのソースの計算に基づいて、最適な重大度を判別します。