認証
第1章 ランタイム時の認証について リンクのコピーリンクがクリップボードにコピーされました!
イメージを構築するとき、次のシナリオで認証を定義する必要が生じる場合があります。
- コンテナーレジストリーに対する認証
- Git からのソースコードの取得
認証は、必要な機密データが保存されるシークレットの定義を通じて行われます。
1.1. ビルドシークレットアノテーション リンクのコピーリンクがクリップボードにコピーされました!
アノテーション build.shipwright.io/referenced.secret: "true"
をビルドシークレットに追加できます。このアノテーションに基づいて、ビルドコントローラーは、ビルドシークレットの作成、更新、削除などのイベントがトリガーされたときに調整アクションを実行します。以下の例は、シークレットでのアノテーションの使用方法を示しています。
このアノテーションは、ビルドインスタンスで参照されないシークレットにフィルターを設定します。たとえば、シークレットにこのアノテーションがない場合は、そのシークレットに対してイベントがトリガーされても、ビルドコントローラーによる調整はありません。イベントのトリガーを調整して、ビルドコントローラーがビルド設定の検証を再トリガーできるようになり、依存関係が欠落しているかどうかが理解しやすくなります。
1.2. Git リポジトリーへの認証 リンクのコピーリンクがクリップボードにコピーされました!
Git リポジトリーに対して次のタイプの認証を定義できます。
- Basic 認証
- セキュアシェル (SSH) 認証
Build
CR で両方のタイプの認証を使用して Git シークレットを設定することもできます。
1.2.1. Basic 認証 リンクのコピーリンクがクリップボードにコピーされました!
Basic 認証では、Git リポジトリーのユーザー名とパスワードを設定する必要があります。以下の例は、Git の Basic 認証の使用方法を示しています。
1.2.2. SSH 認証 リンクのコピーリンクがクリップボードにコピーされました!
SSH 認証では、使用する Git リポジトリープロバイダーのホスト名を指定するように Tekton アノテーションを設定する必要があります。たとえば、GitHub の場合は github.com
、GitLab の場合は gitlab.com
です。
以下の例は、Git での SSH 認証の使用方法を示しています。
1.2.3. Git シークレットの使用 リンクのコピーリンクがクリップボードにコピーされました!
関連する namespace でシークレットを作成したら、そのシークレットを Build
カスタムリソース (CR) で参照できます。両方のタイプの認証で Git シークレットを設定できます。
次の例は、SSH 認証タイプでの Git シークレットの使用法を示しています。
以下の例は、Basic 認証タイプでの Git シークレットの使用法を示しています。
1.3. コンテナーレジストリーへの認証 リンクのコピーリンクがクリップボードにコピーされました!
イメージをプライベートコンテナーレジストリーにプッシュするには、それぞれの namespace でシークレットを定義し、Build
カスタムリソース (CR) で参照する必要があります。
手順
以下のコマンドを実行してシークレットを生成します。
oc --namespace <namespace> create secret docker-registry <container_registry_secret_name> \ --docker-server=<registry_host> \ --docker-username=<username> \ --docker-password=<password> \ --docker-email=<email_address>
$ oc --namespace <namespace> create secret docker-registry <container_registry_secret_name> \ --docker-server=<registry_host> \
1 --docker-username=<username> \
2 --docker-password=<password> \
3 --docker-email=<email_address>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 次のコマンドを実行して、シークレットにアノテーションを付けます。
oc --namespace <namespace> annotate secrets <container_registry_secret_name> build.shipwright.io/referenced.secret='true'
$ oc --namespace <namespace> annotate secrets <container_registry_secret_name> build.shipwright.io/referenced.secret='true'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow spec.output.pushSecret
フィールドの値をBuild
CR のシークレット名に設定します。Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.4. ロールベースのアクセス制御 リンクのコピーリンクがクリップボードにコピーされました!
リリースデプロイメント YAML ファイルには、Builds オブジェクトを使用するための 2 つのクラスター全体のロールが含まれています。次のロールがデフォルトでインストールされます。
-
shpwright-build-aggregate-view
:BuildStrategy
、ClusterBuildStrategy
、Build
、BuildRun
などの Build リソースへの読み取りアクセスを許可します。このロールは Kubernetesview
ロールに集約されます。 -
shipwright-build-aggregate-edit
: namespace レベルで設定されたビルドリソースへの書き込みアクセスを許可します。ビルドリソースには、BuildStrategy
、Build
、およびBuildRun
が含まれます。すべてのClusterBuildStrategy
リソースに読み取りアクセスが付与されます。このロールは、Kubernetes のedit
およびadmin
ロールに集約されます。
ClusterBuildStrategy
リソースへの書き込みアクセス権が割り当てられているのはクラスター管理者のみです。この設定を変更するには、これらの権限を持つ別の Kubernetes ClusterRole
ロールを作成し、そのロールを適切なユーザーにバインドします。
Legal Notice
リンクのコピーリンクがクリップボードにコピーされました!
Copyright © 2025 Red Hat
OpenShift documentation is licensed under the Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0).
Modified versions must remove all Red Hat trademarks.
Portions adapted from https://github.com/kubernetes-incubator/service-catalog/ with modifications by Red Hat.
Red Hat, Red Hat Enterprise Linux, the Red Hat logo, the Shadowman logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat Software Collections is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation’s permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.