Compare commits

...

5 Commits
v0.1.0 ... main

3 changed files with 30 additions and 9 deletions

View File

@ -3,16 +3,28 @@
kubers is a super simple tool that reveals k8s secrets using kubectl and yq
The tool requires `yq` and `kubectl`
Usage:
kubers [-V | --version] [-h | --help] [-n | --namespace <namespace>] [-c <name>=<value>]
<secret_name> [<entry_name>]
Examples:
If you want to reveal all entries in the current k8s namespace
$ kubers
```
$ kubers $SECRET_NAME
```
If you want to reveal only one entry from the secret in the current namepspace
$ kubers
```
$ kubers $SECRET_NAME $SECRET_ENTRY
```
If you want to reveal a secret from another namespace
$ kubers -n
```
$ kubers -n $SECRET_NAME
```

View File

@ -20,6 +20,7 @@ funcion _kubers() {
_values compadd $(kubectl get namespaces --no-headers -o custom-columns=":metadata.name")
;;
secret)
NAMESPACE=$(kubectl config view --minify -o jsonpath='{..namespace}')
for (( i = 1; i <= $#words - 1; i++ )); do
if [[ $words[$i] == -n || $words[$i] == --namespace ]]; then
NAMESPACE=$words[$((i+1))]
@ -40,4 +41,4 @@ funcion _kubers() {
_values compadd $(for KEY in $(kubectl --namespace $NAMESPACE get secret $SECRET_NAME -o yaml | yq '.data | keys' | sed -e "s/- //"); do echo $KEY; done)
;;
esac
}
}

16
kubers
View File

@ -11,13 +11,21 @@ KUBERS_VERSION=0.1.0
function append_to_secret() {
SECRET=$1
KEY=$2
QUIET=$3
VALUE=$(kubectl -n $NAMESPACE get secret $SECRET -o yaml| yq ".data.\"$KEY\"" | base64 -d)
SECRET_DATA="test"
if (( $(grep -c . <<<"$VALUE") > 1 )); then
SECRET="$KEY: |-\n$(echo $VALUE| sed -e 's/^/ /')"
SECRET_DATA="|-\n$(echo $VALUE| sed -e 's/^/ /')"
SECRET="$KEY: $SECRET_DATA"
else
SECRET="$KEY: $VALUE"
SECRET_DATA="$VALUE"
SECRET="$KEY: $SECRET_DATA"
fi
if [[ $QUIET != "" ]]; then
printf "$VALUE"
else
printf "$SECRET"
fi
printf "$SECRET"
}
function show_help() {
@ -104,7 +112,7 @@ fi
SECRET=()
if [[ $SECRET_ENTRY != "" ]]; then
SECRET+=$(append_to_secret $SECRET_NAME $SECRET_ENTRY)
SECRET+=$(append_to_secret $SECRET_NAME $SECRET_ENTRY 1)
else
for SECRET_ENTRY in $(kubectl -n $NAMESPACE get secret $SECRET_NAME -o yaml | yq '.data | keys' | sed -e "s/- //"); do
SECRET+=("$(append_to_secret $SECRET_NAME $SECRET_ENTRY)");