9.3. イメージレジストリーの設定
image.config.openshift.io/cluster カスタムリソース (CR) を編集してイメージレジストリーの設定を行うことができます。
手順
次のコマンドを実行して、
image.config.openshift.io/clusterCR を編集します。$ oc edit image.config.openshift.io/cluster以下は、
image.config.openshift.io/clusterCR の例になります。apiVersion: config.openshift.io/v1 kind: Image metadata: annotations: release.openshift.io/create-only: "true" creationTimestamp: "2019-05-17T13:44:26Z" generation: 1 name: cluster resourceVersion: "8302" selfLink: /apis/config.openshift.io/v1/images/cluster uid: e34555da-78a9-11e9-b92b-06d6c7da38dc spec: allowedRegistriesForImport: - domainName: quay.io insecure: false additionalTrustedCA: name: myconfigmap registrySources: allowedRegistries: - example.com - quay.io - registry.redhat.io - image-registry.openshift-image-registry.svc:5000 - reg1.io/myrepo/myapp:latest insecureRegistries: - insecure.com status: internalRegistryHostname: image-registry.openshift-image-registry.svc:5000注記allowedRegistries、blockedRegistries、またはinsecureRegistriesパラメーターを使用する場合、レジストリー内に個別のリポジトリーを指定できます。例:reg1.io/myrepo/myapp:latest起こりうるセキュリティーリスクを軽減するために、非セキュアな外部レジストリーの使用を避けてください。
検証
次のコマンドを実行してノードをリスト表示し、変更を確認します。
$ oc get nodes出力例
NAME STATUS ROLES AGE VERSION ip-10-0-137-182.us-east-2.compute.internal Ready,SchedulingDisabled worker 65m v1.33.4 ip-10-0-139-120.us-east-2.compute.internal Ready,SchedulingDisabled control-plane 74m v1.33.4 ip-10-0-176-102.us-east-2.compute.internal Ready control-plane 75m v1.33.4 ip-10-0-188-96.us-east-2.compute.internal Ready worker 65m v1.33.4 ip-10-0-200-59.us-east-2.compute.internal Ready worker 63m v1.33.4 ip-10-0-223-123.us-east-2.compute.internal Ready control-plane 73m v1.33.4
9.3.1. 特定のレジストリーを許可リストに追加する リンクのコピーリンクがクリップボードにコピーされました!
image.config.openshift.io/cluster カスタムリソース (CR) を編集することで、イメージのプルおよびプッシュアクションで許可されるレジストリーのリスト、またはレジストリー内の個々のレポジトリーを追加できます。
OpenShift Container Platform は、この CR への変更をクラスター内のすべてのノードに適用します。
イメージをプルまたはプッシュする場合、コンテナーランタイムは image.config.openshift.io/cluster CR の registrySources パラメーターの下にリスト表示されるレジストリーを検索します。allowedRegistries パラメーターの下にレジストリーのリストを作成している場合、コンテナーランタイムはそれらのレジストリーのみを検索します。許可リストにないレジストリーはブロックされます。
allowedRegistries パラメーターを定義すると、明示的にリストされていない限り、registry.redhat.io、quay.io、およびデフォルトの OpenShift イメージレジストリーを含むすべてのレジストリーがブロックされます。ペイロードイメージに必要なすべてのレジストリーを allowedRegistries リストに追加する必要があります。たとえば、registry.redhat.io、quay.io、および internalRegistryHostname レジストリーをリストに追加します。非接続クラスターの場合は、ミラーレジストリーも追加する必要があります。そうしなければ、Pod で障害が発生する危険があります。
手順
次のコマンドを実行して、
image.config.openshift.io/clusterカスタムリソースを編集します。$ oc edit image.config.openshift.io/cluster以下は、許可リストを含む
image.config.openshift.io/clusterリソースの例になります。apiVersion: config.openshift.io/v1 kind: Image metadata: annotations: release.openshift.io/create-only: "true" creationTimestamp: "2019-05-17T13:44:26Z" generation: 1 name: cluster resourceVersion: "8302" selfLink: /apis/config.openshift.io/v1/images/cluster uid: e34555da-78a9-11e9-b92b-06d6c7da38dc spec: registrySources: allowedRegistries: - example.com - quay.io - registry.redhat.io - reg1.io/myrepo/myapp:latest - image-registry.openshift-image-registry.svc:5000 status: internalRegistryHostname: image-registry.openshift-image-registry.svc:5000設定を更新したら、次のコマンドを実行してノードをリスト表示します。
$ oc get nodes出力例
NAME STATUS ROLES AGE VERSION <node_name> Ready control-plane,master 37m v1.27.8+4fab27b次のコマンドを実行して、ノードでデバッグモードに入ります。
$ oc debug node/<node_name><node_name> はノードの名前に置き換えます。
プロンプトが表示されたら、ターミナルに
chroot /hostを入力します。sh-4.4# chroot /host
検証
次のコマンドを実行して、レジストリーがポリシーファイル内にあることを確認します。
sh-5.1# cat /etc/containers/policy.json | jq '.'以下のポリシーは、
example.com、quay.io、およびregistry.redhat.ioレジストリーのイメージのみがイメージのプルおよびプッシュにアクセスできることを示しています。イメージ署名ポリシーファイルの例
{ "default":[ { "type":"reject" } ], "transports":{ "atomic":{ "example.com":[ { "type":"insecureAcceptAnything" } ], "image-registry.openshift-image-registry.svc:5000":[ { "type":"insecureAcceptAnything" } ], "insecure.com":[ { "type":"insecureAcceptAnything" } ], "quay.io":[ { "type":"insecureAcceptAnything" } ], "reg4.io/myrepo/myapp:latest":[ { "type":"insecureAcceptAnything" } ], "registry.redhat.io":[ { "type":"insecureAcceptAnything" } ] }, "docker":{ "example.com":[ { "type":"insecureAcceptAnything" } ], "image-registry.openshift-image-registry.svc:5000":[ { "type":"insecureAcceptAnything" } ], "insecure.com":[ { "type":"insecureAcceptAnything" } ], "quay.io":[ { "type":"insecureAcceptAnything" } ], "reg4.io/myrepo/myapp:latest":[ { "type":"insecureAcceptAnything" } ], "registry.redhat.io":[ { "type":"insecureAcceptAnything" } ] }, "docker-daemon":{ "":[ { "type":"insecureAcceptAnything" } ] } } }注記クラスターが
registrySources.insecureRegistriesパラメーターを使用する場合、非セキュアなレジストリーが許可リストに含まれることを確認します。以下に例を示します。
spec: registrySources: insecureRegistries: - insecure.com allowedRegistries: - example.com - quay.io - registry.redhat.io - insecure.com - image-registry.openshift-image-registry.svc:5000