-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Who can use podsecuritypolicy #63
Comments
Resolves: #63 Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
Thank you for reporting this @schnatterer The fix was released in v0.1.0. You can get it with |
@danielpacak Thank you so much for fixing this. I can confirm that the error message is gone. However, I don't seem to get subjects authorize via RoleBinding. Steps to reproduce:
cat <<EOF | kubectl apply -f -
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: database-psp
namespace: default
spec:
# The rest fills in some required fields.
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
runAsUser:
rule: RunAsAny
fsGroup:
rule: RunAsAny
volumes:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: podsecuritypolicy:databases
namespace: default
rules:
- apiGroups: ['policy']
resources: ['podsecuritypolicies']
verbs: ['use']
resourceNames:
- database-psp
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: databases
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: podsecuritypolicy:databases
namespace: default
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: podsecuritypolicy:databases
subjects:
- kind: ServiceAccount
name: databases
namespace: default
EOF
kubectl auth can-i use psp/database-psp --as=system:serviceaccount:default:databases
# yes
kubectl who-can use psp/database-psp --all-namespaces
# No subjects found with permissions to use psp/database-psp assigned through RoleBindings |
I'll check it on my end @schnatterer and come back to you |
@schnatterer According to the docs https://kubernetes.io/docs/concepts/policy/pod-security-policy/#authorizing-policies if a RoleBinding (not a ClusterRoleBinding) is used, it will only grant usage for pods being run in the same namespace as the binding (the That said, in your example, you're checking whether the ServiceAccount named
On the other hand, the
If you specify the namespace with the
|
If your intention was to authorize the
Then the output of
|
I did check all that without enabling PodSecurityPolicy admission controller in my cluster. @schnatterer Would you mind validating it on the cluster with enabled admission controller and confirm it. Otherwise, I'll do it anyway before closing this issue. |
@danielpacak I was then wondering why I got Unfortunately, enabling the PSP Admission Controller on local clusters such as KIND seems to be not straightforward. That is, I also tested it without admission controller. But does this matter for our use case? We're only testing RBAC features here. |
Your config is fine. But when you query permissions you should not use the
or
but not with the
You cannot authorize SA to PSP with RoleBindings and that's why you get empty result. |
@danielpacak 🙈 I got the But yeah it makes perfect sense that the question answered by Thanks very much for taking your time to explain! Closing this. Slightly offtopic as Post Scriptum:
Don't know if I got you wrong, but I do authorize PSPs to certain SAs using RoleBindings in practice and it works. A PSP might be non-namespaced but SAs and RoleBindings are. So I can authorize a single SA to use a certain PSP. And it's only valid within a certain namespace. |
I know that sometimes this flag can be confusing and we actually thought about renaming it to
Yup, you're right!
❤️ I'm glad that you found it useful and actually contributed to make sure that we handle PSP properly.
I agree with you. I meant that you cannot authorize SA to PSP in any namespece / all namespaces with RoleBindings. For a certain namespace, as you said, it works. |
What would you like to be added
k who-can use psp
Current Behavior:
Error: resolving resource: the "podsecuritypolicies" resource does not support the "use" verb, only [create delete deletecollection get list patch update watch]
Desired Behavior:
Return a list of Subjects that are authorized to use PSP.
Why is this needed
For debugging PSPs and getting an overview of Pods authorized to use a certain PSP.
The text was updated successfully, but these errors were encountered: