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?
Your ClusterRole should be:
A Deployment would have some
apiVersion: apps/v1
. Which belongs to apiGroupsapps
. Wherehas pods, secrets or services would have theirs set tov1
, thus in appGroups""
.