Helm impersonations with kubie

16 October 2022

In a previous post I discussed a convenient shell alias for elevating kubectl command privileges. Below is a similar alias to do the same, but for helm commands.

The alias relies on using kubie, a tool I highly recommend for your day-to-day Kubernetes interactions. It has some excellent features that simplify a lot of the repetition around the kubectl command. Another dependency is yq for parsing a YAML file.

# Impersonate -admin in current kubie namespace
kubieHelmAsAdmin() {
  KUBENS=$(cat $KUBIE_KUBECONFIG | yq '.contexts[0].context.namespace')
  helm --kube-as-user $KUBENS-admin $(echo "$@")
}
alias helma='kubieHelmAsAdmin'

Now it’s a matter of using helma <command> to run commands as the elevated user.

[my-context|my-ns] ➜  ~ helma list
NAME                          	NAMESPACE 	REVISION	UPDATED                                	STATUS  	CHART                             	APP VERSION
some-running-service          	my-ns       25      	2022-11-10 21:20:00.235553093 +0000 UTC	deployed	some-running-service-0.1.3        	0.2.3
devops-tool-box               	my-ns     	2       	2022-11-03 19:10:58.21162 -0400 -0400  	deployed	devops-toolbox-0.1.5
...

comments powered by Disqus