このチュートリアルでは、 証明書を要求する Binary Authorization ポリシーの構成とテストの方法を説明します。このタイプのポリシーは、Google Kubernetes Engine(GKE)にコンテナ イメージをデプロイできる対象と、GKE へのデプロイを許可するコンテナ イメージを定義し、コンテナベースのソフトウェア サプライ チェーンを保護します。
デプロイ時に、Binary Authorization は認証者を使用して証明書のデジタル署名を検証します。証明書は、ビルドプロセスの中で署名者によって作成されています。
このチュートリアルでは、GKE クラスタ、証明書、認証者はすべて 1 つのプロジェクトに存在します。単一プロジェクト構成はサービスのテストや試験運用に非常に役立ちます。より現実的な例については、 マルチプロジェクト構成をご覧ください。
以下では、 Google Cloud コンソールから実行するタスクと、
コマンドを使用して実行するタスクについて説明します。gcloudこれらの手順を
gcloudを使用して行うには、Google Cloud CLI の使用を開始するをご覧ください。
目標
このチュートリアルでは、以下の方法について学習します。
- Binary Authorization を有効にした GKE クラスタを作成する
- Binary Authorization 施行者が証明書の署名を検証するために使用する認証者を作成する
- 証明書を要求するポリシーを構成する
- 証明書に署名して後で検証するための暗号鍵ペアを作成する
- 署名を作成してコンテナ イメージ ダイジェストに署名する
- 署名を使用して証明書を作成する
- コンテナ イメージを GKE にデプロイしてポリシーをテストする
費用
このドキュメントでは、課金対象である次のコンポーネントを使用します。 Google Cloud
料金計算ツールを使うと、予想使用量に基づいて費用の見積もりを生成できます。
始める前に
- アカウントにログインします Google Cloud を初めて使用する場合は、 アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。 Google Cloud新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Container Registry, Artifact Analysis and Binary Authorization APIs.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Google Cloud CLI をインストールします。
-
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
-
gcloud CLI を初期化するには、次のコマンドを実行します:
gcloud init -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Container Registry, Artifact Analysis and Binary Authorization APIs.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.-
Google Cloud CLI をインストールします。
-
外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。
-
gcloud CLI を初期化するには、次のコマンドを実行します:
gcloud init kubectlをインストールします。
デフォルト プロジェクトを設定する
その後のコマンドを実行しやすくするため、次のように Google Cloud プロジェクト ID を 環境変数に保存します。
PROJECT_ID=PROJECT_ID
ここで PROJECT_ID はプロジェクトの名前です。
デフォルト プロジェクトが選択されていない場合は、ここで設定します。
gcloud config set project ${PROJECT_ID}
Binary Authorization を有効にしたクラスタを作成する
クラスタを作成する
これで、Binary Authorization を有効にして GKE クラスタを作成できるようになりました。ここでは、GKE ゾーン us-central1-a に test-cluster というクラスタを作成します。
クラスタの作成手順は次のとおりです。