Skip to content

Commit 93fe988

Browse files
authored
Added demo script for KubeCon EU 2024 (#25)
Signed-off-by: Toddy Mladenov <[email protected]>
1 parent b5ee99f commit 93fe988

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed
+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/bin/zsh
2+
3+
# This script uses the slow() function from Brandon Mitchell available at
4+
# https://github.com/sudo-bmitch/presentations/blob/main/oci-referrers-2023/demo-script.sh#L23
5+
# to simulate typing the commands
6+
7+
# NOTE: Prep steps and cleanup
8+
# - Notation keys are removed
9+
# - Notation certs are removed
10+
export TRUST_STORE_NAME=docker.io
11+
export TEST_KEY_NAME=wabbit-networks.io
12+
notation key delete $TEST_KEY_NAME
13+
notation key ls
14+
rm /Users/toddysm/Library/Application\ Support/notation/localkeys/wabbit-networks.io.key
15+
rm /Users/toddysm/Library/Application\ Support/notation/localkeys/wabbit-networks.io.crt
16+
notation cert delete --type ca --store $TEST_KEY_NAME --all
17+
notation cert delete --type ca --store $TRUST_STORE_NAME --all
18+
notation cert ls
19+
20+
opt_a=0
21+
opt_s=25
22+
23+
while getopts 'ahs:' option; do
24+
case $option in
25+
a) opt_a=1;;
26+
h) opt_h=1;;
27+
s) opt_s="$OPTARG";;
28+
esac
29+
done
30+
set +e
31+
shift `expr $OPTIND - 1`
32+
33+
if [ $# -gt 0 -o "$opt_h" = "1" ]; then
34+
echo "Usage: $0 [opts]"
35+
echo " -h: this help message"
36+
echo " -s bps: speed (default $opt_s)"
37+
exit 1
38+
fi
39+
40+
slow() {
41+
echo -n "\$ $@" | pv -qL $opt_s
42+
if [ "$opt_a" = "0" ]; then
43+
read lf
44+
else
45+
echo
46+
fi
47+
}
48+
49+
clear
50+
slow
51+
52+
# Set the env variables for the images
53+
slow 'export TEST_REPO='docker.io/toddysm/python'
54+
$ export TEST_IMAGE="${TEST_REPO}:3.12"'
55+
export TEST_REPO='docker.io/toddysm/python'
56+
export TEST_IMAGE="${TEST_REPO}:3.12"
57+
58+
# Show notation version
59+
slow 'notation version'
60+
notation version
61+
62+
# List the tags for the netmonitor image (un-trusted)
63+
# NOTE: Make sure the image is available
64+
slow 'oras repo tags $TEST_IMAGE'
65+
oras repo tags $TEST_REPO
66+
67+
# Show the keys (there shouldn't be any)
68+
slow 'notation key list'
69+
notation key list
70+
71+
slow
72+
clear
73+
74+
echo ' ______________________________ '
75+
echo '| __________________________ |'
76+
echo '| | Signing with test key... | |'
77+
echo '| |__________________________| |'
78+
echo '|______________________________|'
79+
80+
# Set the test key name in env variable
81+
slow 'export TEST_KEY_NAME=wabbit-networks.io'
82+
export TEST_KEY_NAME=wabbit-networks.io
83+
84+
# Set up the TEST_KEY
85+
slow 'notation cert generate-test --default $TEST_KEY_NAME'
86+
notation cert generate-test --default $TEST_KEY_NAME
87+
88+
slow 'notation key list'
89+
notation key list
90+
91+
slow 'notation cert list'
92+
notation cert list
93+
94+
slow
95+
clear
96+
97+
# Sign into Docker Hub
98+
slow 'docker login'
99+
docker login
100+
101+
# Sign the net-monitor image
102+
slow 'notation sign --signature-format cose --key $TEST_KEY_NAME $TEST_IMAGE'
103+
notation sign --signature-format cose --key $TEST_KEY_NAME $TEST_IMAGE
104+
slow 'notation ls $TEST_IMAGE'
105+
notation ls $TEST_IMAGE
106+
107+
slow
108+
clear
109+
110+
echo ' ___________________________________ '
111+
echo '| _______________________________ |'
112+
echo '| | Validating the signature... | |'
113+
echo '| |_______________________________| |'
114+
echo '|___________________________________|'
115+
116+
slow 'export TRUST_POLICY_LOCATION=~/Library/Application\ Support/notation/'
117+
export TRUST_POLICY_LOCATION=~/Library/Application\ Support/notation
118+
119+
slow
120+
slow 'cat <<EOF > ${TRUST_POLICY_LOCATION}/trustpolicy.json
121+
{
122+
"version": "1.0",
123+
"trustPolicies": [
124+
{
125+
"name": "python-images",
126+
"registryScopes": [ "${TEST_REPO}" ],
127+
"signatureVerification": {
128+
"level" : "strict"
129+
},
130+
"trustStores": [ "ca:wabbit-networks.io" ],
131+
"trustedIdentities": [
132+
"*"
133+
]
134+
}
135+
]
136+
}
137+
EOF'
138+
cat <<EOF > ${TRUST_POLICY_LOCATION}/trustpolicy.json
139+
{
140+
"version": "1.0",
141+
"trustPolicies": [
142+
{
143+
"name": "flasksample-application",
144+
"registryScopes": [ "${TEST_REPO}" ],
145+
"signatureVerification": {
146+
"level" : "strict"
147+
},
148+
"trustStores": [ "ca:wabbit-networks.io" ],
149+
"trustedIdentities": [
150+
"*"
151+
]
152+
}
153+
]
154+
}
155+
EOF
156+
157+
slow 'notation verify $TEST_IMAGE'
158+
notation verify $TEST_IMAGE
159+
160+
slow
161+
slow
162+
# The END

0 commit comments

Comments
 (0)