-
Notifications
You must be signed in to change notification settings - Fork 497
/
Copy pathrotation_test.sh
executable file
·65 lines (53 loc) · 1.39 KB
/
rotation_test.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
#!/bin/bash
#
# This script implements a simple rotation test. It takes exactly one argument, the number of
# seconds to run. The default is 600.
#
# It works by registering a short-lived entry (60s), and repeatedly hitting the workload API.
# The retrieved SVID is then tested for validity against the received bundle. The test will
# end early if an invalid SVID or bundle is encountered.
#
# It may be desirable to run this test with a low UpstreamCA TTL setting.
#
TIMEOUT=${1:-600}
START=`date +%s`
END=$(($START + $TIMEOUT))
set -e
rm -f .data/datastore.sqlite3
./cmd/spire-server/spire-server run &
sleep 2
./cmd/spire-server/spire-server entry create \
-spiffeID spiffe://example.org/test \
-parentID spiffe://example.org/agent \
-selector unix:uid:$(id -u) \
-ttl 60
TOKEN=$(./cmd/spire-server/spire-server token generate -spiffeID spiffe://example.org/agent | awk '{print $2}')
./cmd/spire-agent/spire-agent run -joinToken $TOKEN &
set +e
function finish ()
{
kill %2
kill %1
wait
rm bundle.0.pem
rm svid.0.pem
rm svid.0.key
}
while [ $? == 0 ]; do
if [ $END -lt $(date +%s) ]; then
finish
echo
echo
echo "Test done."
exit 0
fi
sleep 5
./cmd/spire-agent/spire-agent api fetch -write .
RESULT=$(openssl verify -partial_chain -CAfile bundle.0.pem svid.0.pem)
done
finish
echo
echo
echo $RESULT
echo
echo "Test failed."