kubeauth

kubeauth is a program to assist usage of kubectl for user/group related operations. It currently provides two commands:
add-usercreates a service account based user, adds the credentials to the selected kubeconfig, and optionally creates bindings to existing roles or cluster roles.ctlwrapskubectlinvocation and validates flags such as--asand--as-group.
add-user
Examples
Create the kubeconfig user "tester" based on service account "default" in the "dev" namespace. Also bind it to a role and cluster role. The --role and --cluster-role flags may be supplied multiple times.
kubeauth add-user -v=1 \
--user tester \
--account default \
--namespace dev \
--role role_name_0:binding_name_0 \
--cluster-role role_name_1:binding_name_1Validation checks
--role: role exists in effective namespace--cluster-role: cluster role exists
ctl
- Invocation format:
ctl [kubectl sub-command] [kubeauth flags] -- [kubectl sub-command flags] ctlflags which are also accepted bykubectlwill be passed to the latter.
Examples
Verify that "tester" exists and run "kubectl auth can-i -v=1 --as tester --list".
kubeauth ctl auth can-i -v=1 \
--as tester \
-- --listVerify that "system:serviceaccount:dev:default" exists and run "kubectl auth can-i -v=1 --as system:serviceaccount:dev:default --list".
kubeauth ctl auth can-i -v=1 \
--as system:serviceaccount:dev:default \
-- --listValidation checks
- effective context exists
- effective namespace exists
--asselection exists--as-groupselection exists- agreement between
--clusterand effective context's cluster
Development
License
Mozilla Public License Version 2.0 (About, FAQ)
add_userwas based on this bash script gist.
Contributing
- Please feel free to submit issues, PRs, questions, and feedback.
- Although this repository consists of snapshots extracted from a private monorepo using transplant, PRs are welcome. Standard GitHub workflows are still used.
Testing
ctl
- Reminders
- "you typically need to include
--as-group=system:authenticatedin order to have permission to run aselfsubjectaccessreviewcheck." (https://github.com/kubernetes/kubernetes/issues/73123#issuecomment-456185028)
- "you typically need to include
FAQ
ctl- Q: When verbose output is enabled with
-v=1and I use--as/--as-groupflags, why do I not always seein namespace Xin the messages describing where the user/group was found?- A: It may be that the
--as/--as-groupidentity was found in a role or cluster-role binding where theSubjectobject contained an emptyNamespacefield. At the time this was written, the empty value is expected forUserandGroupsubjects because those object kinds are considered "non-namespace".
- A: It may be that the
- Q: When verbose output is enabled with
