13.7. ユーザーエージェントによる CLI バージョンの不一致の防止
OpenShift Container Platform は、アプリケーション開発者の CLI が OpenShift Container Platform API にアクセスできないように、ユーザーエージェントを実装しています。
OpenShift Container Platform CLI のユーザーエージェントは、OpenShift Container Platform 内の値のセットで設定されています。
<command>/<version>+<git_commit> (<platform>/<architecture>) <client>/<git_commit>
たとえば、以下の場合を考慮しましょう。
-
<command> =
oc -
<version> = クライアントのバージョン。たとえば、
v3.3.0。/apiで Kubernetes API に対して行われる要求が Kubernetes のバージョンを受信し、/oapiで OpenShift Container Platform API に対して行われる要求が OpenShift Container Platform のバージョン (oc versionによって指定される) を受信します。 -
<platform> =
linux -
<architecture> =
amd64 -
<client> =
openshiftまたはkubernetes。 要求が/apiで Kubernetes API に対して行われるか、/oapiで OpenShift Container Platform API に対して行われるかによって決まります。 -
<git_commit> = クライアントバージョンの Git コミット (例:
f034127)
上記の場合、ユーザーエージェントは以下のようになります。
oc/v3.3.0+f034127 (linux/amd64) openshift/f034127
ユーザーエージェントはマスター設定ファイル /etc/origin/master/master-config.yaml で設定する必要があります。設定を適用するには、API サーバーを再起動します。
$ /usr/local/bin/master-restart api
OpenShift Container Platform 管理者として、マスター設定の userAgentMatching 設定を使用してクライアントが API にアクセスできないようにすることができます。そのため、クライアントが特定のライブラリーまたはバイナリーを使用している場合、クライアントは API にアクセスできなくなります。
以下のユーザーエージェントの例は、Kubernetes 1.2 クライアントバイナリー、OpenShift Origin 1.1.3 バイナリー、POST および PUT httpVerbs を拒否します。
policyConfig:
userAgentMatchingConfig:
defaultRejectionMessage: "Your client is too old. Go to https://example.org to update it."
deniedClients:
- regex: '\w+/v(?:(?:1\.1\.1)|(?:1\.0\.1)) \(.+/.+\) openshift/\w{7}'
- regex: '\w+/v(?:1\.1\.3) \(.+/.+\) openshift/\w{7}'
httpVerbs:
- POST
- PUT
- regex: '\w+/v1\.2\.0 \(.+/.+\) kubernetes/\w{7}'
httpVerbs:
- POST
- PUT
requiredClients: null
管理者は、予想されるクライアントに正確に一致しないクライアントを拒否することもできます。
policyConfig:
userAgentMatchingConfig:
defaultRejectionMessage: "Your client is too old. Go to https://example.org to update it."
deniedClients: []
requiredClients:
- regex: '\w+/v1\.1\.3 \(.+/.+\) openshift/\w{7}'
- regex: '\w+/v1\.2\.0 \(.+/.+\) kubernetes/\w{7}'
httpVerbs:
- POST
- PUT
許可クライアントのセットに含まれるクライアントを拒否するには、deniedClients と requiredClients の値を一緒に使用します。以下の例では、1.13 以外のすべての 1.X クライアントバイナリーを許可します。
policyConfig:
userAgentMatchingConfig:
defaultRejectionMessage: "Your client is too old. Go to https://example.org to update it."
deniedClients:
- regex: '\w+/v1\.13.0\+\w{7} \(.+/.+\) openshift/\w{7}'
- regex: '\w+/v1\.13.0\+\w{7} \(.+/.+\) kubernetes/\w{7}'
requiredClients:
- regex: '\w+/v1\.[1-9][1-9].[0-9]\+\w{7} \(.+/.+\) openshift/\w{7}'
- regex: '\w+/v1\.[1-9][1-9].[0-9]\+\w{7} \(.+/.+\) kubernetes/\w{7}'
クライアントのユーザーエージェントが設定と一致しない場合にエラーが発生します。変更する要求が一致するように、ホワイトリストを実施します。ルールは特定の verb にマップされるので、変化する要求を禁止し、変化しない要求を許可することができます。