-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsign-plugin.sh
More file actions
executable file
·141 lines (114 loc) · 3.83 KB
/
sign-plugin.sh
File metadata and controls
executable file
·141 lines (114 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# Script to sign Helm plugin tarballs for Helm v4 verification
# This creates .prov (provenance) files using GPG signing
set -euo pipefail
PLUGIN_NAME="helm-schema"
VERSION="${1:-}"
TARBALL="${2:-}"
GPG_KEY="${GPG_SIGNING_KEY:-}"
KEYRING="${GPG_KEYRING:-$HOME/.gnupg/pubring.gpg}"
usage() {
cat <<EOF
Usage: $0 <version> <tarball> [gpg-key]
Signs a Helm plugin tarball with GPG to create a provenance file (.prov)
for Helm v4 plugin verification.
Arguments:
version Plugin version (e.g., 1.0.0)
tarball Path to the plugin tarball to sign
gpg-key GPG key name or email (optional, uses GPG_SIGNING_KEY env var)
Environment Variables:
GPG_SIGNING_KEY GPG key to use for signing
GPG_KEYRING Path to GPG keyring (default: ~/.gnupg/pubring.gpg)
GPG_PASSPHRASE GPG key passphrase (if needed)
Example:
$0 1.0.0 dist/helm-schema_1.0.0_Linux_x86_64.tar.gz "John Doe <john@example.com>"
EOF
exit 1
}
if [ -z "$VERSION" ] || [ -z "$TARBALL" ]; then
usage
fi
if [ ! -f "$TARBALL" ]; then
echo "Error: Tarball not found: $TARBALL"
exit 1
fi
# If GPG key not provided as argument, try environment variable
if [ $# -ge 3 ]; then
GPG_KEY="$3"
fi
if [ -z "$GPG_KEY" ]; then
echo "Error: GPG signing key not specified"
echo "Provide it as third argument or set GPG_SIGNING_KEY environment variable"
exit 1
fi
echo "Signing plugin tarball with GPG..."
echo " Tarball: $TARBALL"
echo " Version: $VERSION"
echo " GPG Key: $GPG_KEY"
echo " Keyring: $KEYRING"
# Export keys to legacy format if needed (for GnuPG v2)
if ! [ -f "$KEYRING" ]; then
echo "Exporting GPG keys to legacy format..."
mkdir -p "$(dirname "$KEYRING")"
gpg --export > "$KEYRING" 2>/dev/null || true
fi
# Create a temporary directory for signing
TEMP_DIR=$(mktemp -d)
trap 'rm -rf "$TEMP_DIR"' EXIT
# Save the original directory and convert tarball path to absolute
ORIG_DIR="$(pwd)"
TARBALL_DIR="$(cd "$(dirname "$TARBALL")" && pwd)"
TARBALL_NAME=$(basename "$TARBALL")
# Copy tarball to temp directory
cp "$TARBALL" "$TEMP_DIR/"
cd "$TEMP_DIR"
# Create the provenance file
# The provenance file contains:
# 1. The plugin metadata (from plugin.yaml)
# 2. SHA256 hash of the tarball
# 3. GPG signature of the above
echo "Creating provenance file..."
# Extract plugin.yaml from tarball to include in provenance
tar -xzf "$TARBALL_NAME" plugin.yaml 2>/dev/null || tar -xzf "$TARBALL_NAME" */plugin.yaml 2>/dev/null || true
# Calculate SHA256 hash
HASH=$(sha256sum "$TARBALL_NAME" | awk '{print $1}')
# Create provenance content
cat > "${TARBALL_NAME}.prov.tmp" <<EOF
name: $PLUGIN_NAME
version: $VERSION
description: Generate jsonschemas for your helm charts
home: https://github.com/dadav/helm-schema
...
files:
$TARBALL_NAME: sha256:$HASH
EOF
# If plugin.yaml was extracted, append it
if [ -f plugin.yaml ]; then
echo "" >> "${TARBALL_NAME}.prov.tmp"
echo "plugin.yaml: |" >> "${TARBALL_NAME}.prov.tmp"
sed 's/^/ /' plugin.yaml >> "${TARBALL_NAME}.prov.tmp"
fi
# Sign the provenance file
if [ -n "${GPG_PASSPHRASE:-}" ]; then
# Use passphrase from environment if available
echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 \
--clearsign \
--local-user "$GPG_KEY" \
--output "${TARBALL_NAME}.prov" \
"${TARBALL_NAME}.prov.tmp"
else
# Interactive passphrase prompt
gpg --clearsign \
--local-user "$GPG_KEY" \
--output "${TARBALL_NAME}.prov" \
"${TARBALL_NAME}.prov.tmp"
fi
# Copy back to original location
cp "${TARBALL_NAME}.prov" "$TARBALL_DIR/"
echo "✓ Successfully created provenance file: ${TARBALL_DIR}/${TARBALL_NAME}.prov"
echo ""
echo "To verify the signature:"
echo " helm plugin verify $(basename "$TARBALL")"
echo ""
echo "To install with verification:"
echo " helm plugin install $(basename "$TARBALL") --verify"