-
<namespace_route>
指的是命名空间路由。可以通过运行以下命令找到:$ oc get route oauth-openshift -n openshift-authentication -o json | jq .spec.host
OpenShift Container Platform 默认创建了多个 OAuth 客户端。您也可以注册和配置额外的 OAuth 客户端。
启动 OpenShift Container Platform API 时会自动创建以下 OAuth 客户端
OAuth 客户端 | 用途 |
---|---|
|
使用能够处理交互式登录的用户代理,在 |
|
使用能够处理 |
|
使用本地 HTTP 服务器获取授权码授权来请求令牌。 |
<namespace_route>
指的是命名空间路由。可以通过运行以下命令找到:
$ oc get route oauth-openshift -n openshift-authentication -o json | jq .spec.host
如果您需要额外的 OAuth 客户端来管理 OpenShift Container Platform 集群的身份验证,您可以注册一个。
注册额外的 OAuth 客户端:
$ oc create -f <(echo '
kind: OAuthClient
apiVersion: oauth.openshift.io/v1
metadata:
name: demo (1)
secret: "..." (2)
redirectURIs:
- "http://www.example.com/" (3)
grantMethod: prompt (4)
')
1 | OAuth 客户端的name 在向<namespace_route>/oauth/authorize 和<namespace_route>/oauth/token 发出请求时用作client_id 参数。 |
2 | secret 在向<namespace_route>/oauth/token 发出请求时用作client_secret 参数。 |
3 | 向<namespace_route>/oauth/authorize 和<namespace_route>/oauth/token 发出的请求中指定的redirect_uri 参数必须等于或以redirectURIs 参数值中列出的 URI 之一来作为前缀。 |
4 | grantMethod 用于确定当此客户端请求令牌且尚未获得用户的访问权限时要采取的操作。指定auto 自动批准授权并重试请求,或指定prompt 提示用户批准或拒绝授权。 |
您可以配置 OAuth 客户端,使其在设定的非活动时间段后令牌过期。默认情况下,不会设置令牌非活动超时。
如果在内部 OAuth 服务器配置中也配置了令牌非活动超时,则 OAuth 客户端中设置的超时将覆盖该值。 |
您可以作为具有cluster-admin
角色的用户访问集群。
您已配置身份提供商 (IDP)。
更新OAuthClient
配置以设置令牌非活动超时。
编辑OAuthClient
对象
$ oc edit oauthclient <oauth_client> (1)
1 | 将<oauth_client> 替换为要配置的 OAuth 客户端,例如console 。 |
添加accessTokenInactivityTimeoutSeconds
字段并设置您的超时值
apiVersion: oauth.openshift.io/v1
grantMethod: auto
kind: OAuthClient
metadata:
...
accessTokenInactivityTimeoutSeconds: 600 (1)
1 | 允许的最小超时值(以秒为单位)是300 。 |
保存文件以应用更改。
使用来自您的 IDP 的身份登录到集群。请务必使用您刚刚配置的 OAuth 客户端。
执行操作并验证其是否成功。
在不使用该身份的情况下等待超过配置的超时时间。在此步骤的示例中,等待超过 600 秒。
尝试从同一身份的会话执行操作。
此尝试应失败,因为由于非活动时间超过配置的超时时间,令牌应已过期。