Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

8.4. 为路由和入口对象禁用主机名集合

在 OpenShift Container Platform 中,路由和入口对象的主机名冲突攻击会被默认启用。这意味着没有 cluster-admin 角色的用户只能在创建时在路由或入口对象中设置主机名,之后无法更改它。但是,您可以为部分或所有用户放松对路由和入口对象的限制。

警告

由于 OpenShift Container Platform 使用对象创建时间戳来确定给定主机名的最旧的路由或入口对象,如果旧的路由更改了主机名,或者使用了 ingress 对象,则路由或入口对象可能会劫持较新路由的主机名。

作为 OpenShift Container Platform 集群管理员,您可以在创建后编辑路由中的主机名。您还可以创建一个角色来允许特定用户这样做:

$ oc create clusterrole route-editor --verb=update --resource=routes.route.openshift.io/custom-host

然后您可以将新角色绑定到用户:

$ oc adm policy add-cluster-role-to-user route-editor user

您还可以对入口对象禁用主机名冲突检测。这样,没有 cluster-admin 角色的用户可在创建后编辑 ingress 对象的主机名。这对依赖于 Kubernetes 行为的 OpenShift Container Platform 安装很有用,包括允许编辑 ingress 对象中的主机名。

  1. 将以下内容添加到 master.yaml 文件中:

    admissionConfig:
      pluginConfig:
        openshift.io/IngressAdmission:
          configuration:
            apiVersion: v1
            allowHostnameChanges: true
            kind: IngressAdmissionConfig
          location: ""
  2. 重启 master 服务以使更改生效:

    $ master-restart api
    $ master-restart controllers