已开启
InferNex-Bridge:删除推理实例后遗留 per-model ClusterRole / ClusterRoleBinding 未清理 #174
luochen01创建于  9月29日
luochen01
luochen01
9月29日 创建

问题描述

创建 PD(Prefill-Decode)分离模式的推理实例(LLMInferenceService)时,InferNex-Bridge 会为每个模型派生增强组件(cache-indexer、pd-orchestrator 的 elastic-scaler / rsg / tidal 等),并为这些组件的控制器创建 per-model 的 ClusterRole / ClusterRoleBinding,其 label 为:

  • infernex.io/managed-cluster-rbac=true
  • infernex.io/owner=<model>
  • infernex.io/component=<component>

删除模型后,这些 ClusterRole / ClusterRoleBinding 没有被清理,永久残留。

复现步骤

  1. 创建一个 PD 模型,开启 enableCacheIndexer 与 enablePDOrchestrator。
  2. 删除该模型。
  3. 检查残留:
kubectl get clusterrolebindings -l infernex.io/managed-cluster-rbac=true | grep <model>
kubectl get clusterroles -l infernex.io/managed-cluster-rbac=true | grep <model>

仍能看到 <model>-cache-indexer-controller-rolebinding、<model>-pd-orchestrator-elastic-scaler-controller-rolebinding、<model>-pd-orchestrator-rsg-controller-rolebinding、<model>-pd-orchestrator-tidal-controller-rolebinding 等残留 RBAC(实际数量取决于启用的组件;hermes-router 使用的是 namespaced Role/RoleBinding,带 controller ownerRef,会被 GC 正常清理,不受影响)。

根因

  1. ClusterRole / ClusterRoleBinding 是 cluster-scoped 资源,无法将 namespaced 的 InferNexService 设为 ownerReferences,因此 K8s Garbage Collection(GC)的级联删除对它无效。
  2. 清理逻辑 deleteComponentControllerRBAC 是存在的,但只在正常 reconcile 的 prune 路径被调用(pruneOrphanedComponents → syncComponentControllerRBACCleanup)。
  3. 真正删除时走的 reconcileInferNexServiceDeletion 路径,只清理了 Gateway 路由和 singleton ServiceAccount 的 ownerReferences(releaseSingletonOwnerReferences),没有调用 syncComponentControllerRBACCleanup,导致 cluster-scoped RBAC 泄漏。

影响

  1. RBAC 对象随模型增删持续累积,成为集群垃圾。
  2. 权限回收不及时:cache-indexer-sa、elastic-scaler-sa 等 ServiceAccount 是 namespace 内共享的 singleton。残留的 ClusterRoleBinding 会把这些共享 ServiceAccount 持续绑定到已删除模型的 ClusterRole,导致本应随模型删除而回收的权限未被回收。尤其 pd-orchestrator-elastic-scaler 的 ClusterRole 含 apiGroups: ["*"], resources: ["*"] 的宽泛权限,模型全部删除后该权限仍可能保留,构成潜在安全风险。

建议修复

删除路径 reconcileInferNexServiceDeletion 在移除 finalizer 前本就会调用 releaseSingletonOwnerReferences,但该函数原先只释放共享 singleton ServiceAccount 的 owner refs:

// 修改前
return r.syncSingletonComponentSAOwnerRefsCleanup(ctx, owner, nil)

将其实现改为委托给 syncComponentControllerRBACCleanup,即可在删除时一并显式清理 per-model 的 cluster-scoped RBAC:

// 修改后
return r.syncComponentControllerRBACCleanup(ctx, owner, nil)

syncComponentControllerRBACCleanup(ctx, owner, nil) 传 nil desired 表示所有组件均不再需要,会触发 deleteComponentControllerRBAC 逐个清理 ClusterRole / ClusterRoleBinding(幂等,NotFound 忽略);同时它对共享 singleton ServiceAccount 只做 ownerRef 清理而不直接删除,并一并清理 per-owner 的 leader Role/RoleBinding 与 webhook 证书 Secret。

likedislike
openFuyao-botopenFuyao-bot成员
9月29日 添加了label:sig/sig-ai-inference
openFuyao-bot
openFuyao-bot成员
9月29日 评论:

欢迎来到 openFuyao 社区

Hey @luochen01 , 感谢你对社区的贡献.

机器人使用手册

有关指令的使用,可以点击 此处 查看详情。开发人员可以在每个PR或Issue下方评论特定指令来触发机器人任务。您可以自助配置此仓库的 PR 合并规则,更多详情,请参阅此处。

联系指引

有疑问可以联系 SIG: sig-ai-inference ,
维护者是: @foxbit, @regandy ,
审核者是: @ShiroChen, @piamposer-li, @qinwenzh .

likedislike
luochen01luochen01
9月29日 修改了issue 的描述
luochen01luochen01
9月29日 关联了pull request:fix(controller): cleanup per-model ClusterRole/ClusterRoleBinding on deletion
luochen01luochen01
9月29日 修改了issue 的描述
luochen01luochen01
9月30日 修改了issue 的描述