Skip to content

Instantly share code, notes, and snippets.

@MegaManSec
Created April 3, 2023 11:24
Show Gist options
  • Save MegaManSec/2e56df412d2c6a4cd0404d69bf6eb095 to your computer and use it in GitHub Desktop.
Save MegaManSec/2e56df412d2c6a4cd0404d69bf6eb095 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get all secrets in all namespaces
secrets=$(kubectl get secrets --all-namespaces -o json)
# Loop over every secret and namespace
for secret in $(echo "${secrets}" | jq -r '.items[] | @base64'); do
secret_data=$(echo ${secret} | base64 --decode | jq -r '.metadata.namespace + "/" + .metadata.name')
namespace=$(echo ${secret_data} | cut -d '/' -f 1)
secret_name=$(echo ${secret_data} | cut -d '/' -f 2)
full_secret_data=$(echo ${secret} | base64 --decode)
mkdir $namespace
echo "$full_secret_data" > $namespace/$secret_name.data
done
find . -type f | while read file; do jq '.data |= with_entries(.value |= @base64d)' "$file" > "$file.tmp"; mv "$file.tmp" "$file"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment