Home > Enterprise >  Not able to get deployments as ServiceAccount
Not able to get deployments as ServiceAccount

Time:07-31

I'm trying to access deployments in another namespace, and have the following ServiceAccount, ClusterRole, and ClusterRoleBinding

apiVersion: v1
kind: ServiceAccount
metadata:
  name: tekton-triggers-example-sa
  namespace: tekton-pipelines
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
    name: tekton-pipeline-sa
rules:
    - apiGroups: [""]
      resources: ["secrets", "services", "deployments", "pods"]
      verbs: ["get", "watch", "list", "create", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
    name: tekton-pipeline-permissions
    namespace: tekton-pipelines
subjects:
    - kind: ServiceAccount
      name: tekton-triggers-example-sa
      namespace: tekton-pipelines
roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole
    name: tekton-pipeline-sa

With that I can get everything but deployments

kubectl auth can-i get secrets --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes
kubectl auth can-i get services --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes
kubectl auth can-i get deployments --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get pods --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes

If I delete the binding I can't get anything, which makes sense

kubectl delete -f rbac/binding.yaml 
clusterrolebinding.rbac.authorization.k8s.io "tekton-pipeline-permissions" deleted

kubectl auth can-i get secrets --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get services --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get deployments --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get pods --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no

If I apply it again, I get access to everything but deployments

kubectl apply -f rbac/binding.yaml 
clusterrolebinding.rbac.authorization.k8s.io/tekton-pipeline-permissions created
kubectl auth can-i get secrets --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes
kubectl auth can-i get services --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes
kubectl auth can-i get deployments --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
no
kubectl auth can-i get pods --as=system:serviceaccount:tekton-pipelines:tekton-triggers-example-sa -n anxiety-app 
yes

So that seems to me like that bindings is working for all the resources except deployments.

Anyone know what I've got wrong, why I can't access deployments?

CodePudding user response:

Your ClusterRole should be:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: tekton-pipeline-sa
rules:
- apiGroups: [""]
  resources: ["secrets", "services", "pods"]
  verbs: ["get", "watch", "list", "create", "delete"]
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get", "watch", "list", "create", "delete"]

A Deployment would have some apiVersion: apps/v1. Which belongs to apiGroups apps. Wherehas pods, secrets or services would have theirs set to v1, thus in appGroups "".

  • Related