53. 使用 Rancher SSO 访问 NeuVector REST API
NeuVector, Rancher. NeuVector,牧场主。
PURPOSE 目的
This article explains how to securely access NeuVector REST APIs when NeuVector is integrated with Rancher SSO authentication. In standard NeuVector installations, REST APIs can be accessed directly using NeuVector API keys or local user tokens. However, when NeuVector is deployed and accessed through Rancher with SSO enabled, the authentication and API access behavior changes significantly.
本文解释了当 NeuVector 与 Rancher SSO 认证集成时,如何安全访问 NeuVector REST API。在标准的 NeuVector 安装中,REST API 可以通过 NeuVector API 密钥或本地用户令牌直接访问。然而,当 NeuVector 部署并通过启用 SSO 的 Rancher 访问时,认证和 API 访问行为会发生显著变化。
In Rancher-SSO integrated environments:
在 Rancher-SSO 集成环境中:
- NeuVector REST APIs are not exposed by default
NeuVector REST API 默认不会被暴露 - NeuVector API keys do not work for API authentication
NeuVector API 密钥无法用于 API 认证 - All API access must be tied to an active Rancher SSO session
所有 API 访问必须绑定到活跃的 Rancher SSO 会话 - Authentication must be performed using Rancher SSO cookies and NeuVector login tokens
认证必须使用 Rancher SSO cookie 和 NeuVector 登录令牌进行
PREREQUISITES 先决条件
- NeuVector installed in Rancher.
NeuVector 安装在 Rancher 中。 - Rancher SSO enabled. 已启用牧场主单点登录。
- kubectl access to the cluster.
库贝克尔访问集群。 - Browser access to Rancher UI.
浏览器访问 Rancher 界面。
Step 1 – Expose NeuVector Controller REST API
NeuVector REST APIs are served by the controller on port 10443.
NeuVector REST API 由控制器在端口 10443 上提供。
Expose this port using a NodePort service:
使用 NodePort 服务暴露该端口:
apiVersion: v1
kind: Service
metadata:
name: api-controller
namespace: cattle-neuvector-system
spec:
type: NodePort
selector:
app: neuvector-controller-pod
ports:
- name: api
port: 10443
targetPort: 10443
nodePort: 30001 # use any free NodePort
Apply: 申请:
kubectl apply -f api-controller.yaml
Step 2 – Obtain Rancher SSO Cookie
步骤 2 – 获取 Rancher SSO Cookie
Login to Rancher UI.
登录 Rancher UI。
Open Developer Tools → Application → Cookies.
打开开发者工具→应用→Cookies。
Copy the value of the cookie named: "R_SESS = token-xxxxxxxxxxxxxxxx"
复制名为“R_SESS = token-xxxxxxxxxxxxxxxx” 的 cookie 值
Step 3 – Login to NeuVector via Rancher SSO
步骤 3 – 通过 Rancher SSO 登录 NeuVector
RancherCookie="<R_SESS value>"
ControllerIP=<Node IP>
ControllerPORT=30001
curl -k -H "Content-Type: application/json" \
-H "X-R-Sess: $RancherCookie" \
-X POST https://$ControllerIP:$ControllerPORT/v1/auth > token.json
Extract the token: 提取令牌:
TOKEN=`cat token.json | jq -r '.token.token'`
Step 4 – Call NeuVector REST APIs
步骤 4 – 调用 NeuVector REST APIS
System Summary 系统概述
curl -k -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -H "X-R-Sess: $RancherCookie" https://$ControllerIP:$ControllerPORT/v1/system/summary
Exposure & Security Score
曝光与安全评分
curl -k -H "Content-Type: application/json" -H "X-Auth-Token: $TOKEN" -H "X-R-Sess: $RancherCookie" https://$ControllerIP:$ControllerPORT/v1/system/score/metrics
IMPORTANT NOTES 重要注释
| Auth Method 认证方法 | Rancher SSO login Rancher SSO 登录 |
| Controller API Port 控制器 API 端口 | 10443 only 仅限10443 |
| Required Headers 必需头部 | X-R-Sess, X-Auth-TokenX-R-Sess, X-Auth-令牌 |
| UI Port 界面移植 | 8443 (not for APIs) 8443(非用于 API) |
SUMMARY 摘要
NeuVector APIs behind Rancher SSO must always be accessed using:
Rancher SSO 背后的 NeuVector API 必须始终通过以下方式访问:
- Rancher SSO cookie
/v1/authRancher login/v1/认证牧场主登录- Token-based API calls 基于令牌的 API 调用
- Controller REST API port (10443)
Controller REST API 端口(10443)
访问Rancher-K8S解决方案博主 :https://blog.csdn.net/lidw2009
更多推荐




所有评论(0)