Created
May 15, 2025 11:56
-
-
Save kek-Sec/81805c37bf3b99af2513acfa92fff542 to your computer and use it in GitHub Desktop.
reseal-kubeseal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
OUT_DIR="./resealed" | |
CERT="./sealed-secrets.crt" | |
mkdir -p "$OUT_DIR" | |
kubeseal --controller-name=sealed-secrets \ | |
--controller-namespace=sealed-secrets \ | |
--fetch-cert > "$CERT" | |
find . -type f \( -iname "*.yaml" -o -iname "*.yml" -o -iname "*.json" \) -print0 \ | |
| while IFS= read -r -d '' file; do | |
if ! grep -qE '"kind": ?"SealedSecret"|kind: ?SealedSecret' "$file"; then | |
continue | |
fi | |
name=$(yq e '.metadata.name' "$file" 2>/dev/null || jq -r '.metadata.name' "$file" 2>/dev/null) | |
namespace=$(yq e '.metadata.namespace' "$file" 2>/dev/null || jq -r '.metadata.namespace' "$file" 2>/dev/null) | |
if [[ -z "$name" || -z "$namespace" ]]; then | |
echo "⚠️ Could not parse name/namespace from '$file'. Skipping." | |
continue | |
fi | |
echo "🔍 Processing $name in $namespace from '$file'" | |
if ! kubectl get secret "$name" -n "$namespace" &>/dev/null; then | |
echo "⚠️ Secret $name not found in namespace $namespace. Skipping." | |
continue | |
fi | |
kubectl get secret "$name" -n "$namespace" -o yaml > /tmp/secret.yaml | |
kubeseal \ | |
--cert "$CERT" \ | |
--format yaml \ | |
< /tmp/secret.yaml > "$OUT_DIR/$name.yaml" | |
echo "✅ Resealed: $OUT_DIR/$name.yaml" | |
done | |
echo "🎉 Done. All resealed secrets saved in $OUT_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment