Skip to content

Instantly share code, notes, and snippets.

@nasermirzaei89
Last active April 27, 2023 03:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasermirzaei89/27cab414ed6f2c2aa35688a653e399a9 to your computer and use it in GitHub Desktop.
Save nasermirzaei89/27cab414ed6f2c2aa35688a653e399a9 to your computer and use it in GitHub Desktop.
Get decoded secret as yaml
#!/bin/bash
set -e
NAMESPACE=$1
SECRET_NAME=$2
CONTENT=$(kubectl get secret -n "$NAMESPACE" "$SECRET_NAME" -o json)
KEYS=$(echo "${CONTENT}" | jq '.data' | jq 'keys[]')
for KEY in $KEYS
do
DECODED=$(echo "$CONTENT" | jq -r ".data.${KEY}" | base64 -d)
CONTENT=$(echo "$CONTENT" | jq ".stringData.${KEY} = \"${DECODED}\"")
done
echo "${CONTENT}" | jq 'del(.data)' | yq eval -P
@nasermirzaei89
Copy link
Author

nasermirzaei89 commented Apr 27, 2023

Prerequisites

  • kubectl
  • jq
  • yq

Usage

./nonsecret.sh namespace1 secret1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment