-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkeybase.sh
executable file
·199 lines (165 loc) · 3.32 KB
/
keybase.sh
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
set -eu
usage() {
cat << EOF
Keybase integration with Helm.
This provides tools for working with the Keybase.io secure tool suite.
Available Commands:
push Push a chart (repository) to a Keybase signed directory
sign Sign a chart archive (tgz file) with a Keybase key
verify Verify a chart archive (tgz + tgz.prov) with a Keybase key
EOF
}
push_usage() {
cat << EOF
Push a chart to a Keybase repo.
Example:
$ helm keybase push foo-0.1.0.tgz
EOF
}
sign_usage() {
cat << EOF
Sign a chart using Keybase credentials.
This is an alternative to 'helm sign'. It uses your keybase credentials
to sign a chart.
Example:
$ helm keybase sign foo-0.1.0.tgz
EOF
}
verify_usage() {
cat << EOF
Verify a chart
This is an alternative to 'helm verify'. It uses your keybase credentials
to verify a chart.
Example:
$ helm keybase verify foo-0.1.0.tgz
Signature verified. Signed by technosophos 1 day ago (2016-11-28 17:07:21 -0700 MST).
PGP Fingerprint: aba2529598f6626c420d335b62f49e747d911b60.
Chart SHA verified. sha256:62728732cc113510637a6ba4c318bc27e56cbb1d01166f5be03329e547d640c4
In typical usage, use 'helm fetch --prov' to fetch a chart:
$ helm fetch --prov upstream/wordpress
$ helm keybase verify wordpress-1.2.3.tgz
$ helm install ./wordpress-1.2.3.tgz
EOF
}
is_help() {
case "$1" in
"-h")
return 0
;;
"--help")
return 0
;;
"help")
return 0
;;
*)
return 1
;;
esac
}
push() {
if is_help $1 ; then
push_usage
return
fi
u=$(kuser)
chart=$1
repo=/keybase/public/${u}/charts
dest="https://${u}.keybase.pub/charts/"
echo "Copying $chart to $repo"
cp $chart $repo
cp ${chart}.prov $repo
helm repo index $repo --url $dest
echo "Successfully pushed $1 to $dest"
}
sign() {
if is_help $1 ; then
sign_usage
return
fi
chart=$1
echo "Signing $chart"
shasum=$(openssl sha -sha256 $chart| awk '{ print $2 }')
chartyaml=$(tar -zxf $chart --exclude 'charts/' -O '*/Chart.yaml')
c=$(cat << EOF
$chartyaml
...
files:
$chart: sha256:$shasum
EOF
)
keybase pgp sign -c -o "$chart.prov" -m "$c"
}
verify() {
if is_help $1 ; then
verify_usage
return
fi
chart=$1
keybase pgp verify -i ${chart}.prov
# verify checksum
sha=$(shasum $chart)
set +e
grep "$chart: sha256:$sha" ${chart}.prov > /dev/null
if [ $? -ne 0 ]; then
echo "ERROR SHA verify error: sha256:$sha does not match ${chart}.prov"
return 3
fi
set -e
echo "Chart SHA verified. sha256:$sha"
}
shasum() {
openssl sha -sha256 "$1" | awk '{ print $2 }'
}
kuser() {
keybase status | grep "Username: " | awk '{ print $2 }'
}
if [[ $# < 1 ]]; then
usage
exit 1
fi
if ! type "keybase" > /dev/null; then
echo "Command like 'keybase' client must be installed"
exit 1
fi
case "${1:-"help"}" in
"push")
if [[ $# < 2 ]]; then
push_usage
echo "Error: Chart package required."
exit 1
fi
push $2
;;
"sign"):
if [[ $# < 2 ]]; then
push_usage
echo "Error: Chart package required."
exit 1
fi
sign $2
;;
"verify"):
if [[ $# < 2 ]]; then
verify_usage
echo "Error: Chart package required."
exit 1
fi
verify $2
;;
"help")
usage
;;
"--help")
usage
;;
"-h")
usage
;;
*)
usage
exit 1
;;
esac
exit 0