具有资源名称和列表对象的 Kubernetes RBAC 角色

kgu*_*kar 2 kubernetes

apiVersion: rbac.authorization.k8s.io/v1                                                                                                                    
kind: Role                                                                                                                                                  
metadata:                                                                                                                                                   
  name: p-viewer-role                                                                                                                  
  namespace: pepsi                                                                                                                                  
rules:                                                                                                                                                      
- apiGroups:                                                                                                                                                
  - ""                                                                                                                                    
  resourceNames:                                                                                                                                            
  - p83                                                                                                                                                     
  resources:                                                                                                                                                
  - pods                                                                                                                                                
  verbs:                                                                                                                                                    
  - list                                                                                                                                                    
  - get                                                                                                                                                     
  - watch   
Run Code Online (Sandbox Code Playgroud)

当我们在角色中使用 resourceNames 时,以下命令有效

kubectl get pods -n pepsi p83
Run Code Online (Sandbox Code Playgroud)

返回一个适当的值。然而,

kubectl get pods -n pepsi 
Run Code Online (Sandbox Code Playgroud)

禁止退货。为什么不列出 p83

角色绑定

apiVersion: rbac.authorization.k8s.io/v1                                                                                                                    
kind: RoleBinding                                                                                                                                           
metadata:                                                                                                                                                   
  name: p-viewer-rolebinding                                                                                                          
  namespace: pepsi                                                                                                                                  
roleRef:                                                                                                                                                    
  apiGroup: rbac.authorization.k8s.io                                                                                                                       
  kind: Role                                                                                                                                                
  name: p-viewer-role                                                                                                                  
subjects:                                                                                                                                                   
- apiGroup: rbac.authorization.k8s.io                                                                                                                       
  kind: Group                                                                                                                                               
  name: pepsi-project-viewer                                                                                                                    
  namespace: project                                                                                                                      
Run Code Online (Sandbox Code Playgroud)

Arg*_*dhu 6

这是预期的行为。您已经定义了一个role范围为namespace百事可乐 to pod resourceswith specific resourceName p83.

要使kubectl get pods -n peps命令起作用,您需要resourceNames p83Role

这种高级验证最好由OPA处理,您可以在其中定义细粒度策略。