forked from kubewarden/verify-image-signatures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe2e.bats
157 lines (135 loc) · 7.35 KB
/
e2e.bats
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
#!/usr/bin/env bats
@test "Accept a valid signature" {
run kwctl run --request-path test_data/pod_creation_signed.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ]
}
@test "Reject invalid signature" {
run kwctl run --request-path test_data/pod_creation_unsigned.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*"message":"Pod invalid-pod-name is not accepted: verification of image ghcr.io/kubewarden/test-verify-image-signatures:unsigned failed.*') -ne 0 ]
}
@test "Mutate Pod definition" {
# Need to run the command inside of `bash -c` because of a bats
# limitation: https://bats-core.readthedocs.io/en/stable/gotchas.html?highlight=pipe#my-piped-command-does-not-work-under-run
run bash -c 'kwctl run \
--request-path test_data/pod_creation_signed.json \
--settings-path test_data/settings-mutation-enabled.yaml \
annotated-policy.wasm | jq -r ".patch | @base64d"'
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*ghcr.io/kubewarden/test-verify-image-signatures:signed@sha256:1d9d3da4c60d27b77bb96bba738319c1c4424853fdd10f65982f9f2ca2422a72.*') -ne 0 ]
}
@test "Do not mutate Pod definition" {
# Need to run the command inside of `bash -c` because of a bats
# limitation: https://bats-core.readthedocs.io/en/stable/gotchas.html?highlight=pipe#my-piped-command-does-not-work-under-run
run bash -c 'kwctl run \
--request-path test_data/pod_creation_signed.json \
--settings-path test_data/settings-mutation-disabled.yaml \
annotated-policy.wasm | jq -r ".patch"'
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : 'null') -ne 0 ]
}
@test "Accept a valid signature in a Deployment" {
run kwctl run --request-path test_data/deployment_creation_signed.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ]
}
@test "Reject invalid signature in a Deployment" {
run kwctl run --request-path test_data/deployment_creation_unsigned.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*is not accepted: verification of image ghcr.io/kubewarden/test-verify-image-signatures:unsigned failed.*') -ne 0 ]
}
@test "Accept a valid signature in a StatefulSet" {
run kwctl run --request-path test_data/statefulset_creation_signed.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ]
}
@test "Reject invalid signature in a StatefulSet" {
run kwctl run --request-path test_data/statefulset_creation_unsigned.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*is not accepted: verification of image ghcr.io/kubewarden/test-verify-image-signatures:unsigned failed.*') -ne 0 ]
}
@test "Accept a valid signature in a ReplicaSet" {
run kwctl run --request-path test_data/replicaset_creation_signed.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ]
}
@test "Reject invalid signature in a ReplicaSet" {
run kwctl run --request-path test_data/replicaset_creation_unsigned.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*is not accepted: verification of image ghcr.io/kubewarden/test-verify-image-signatures:unsigned failed.*') -ne 0 ]
}
@test "Accept a valid signature in a ReplicationController" {
run kwctl run --request-path test_data/replicationcontroller_creation_signed.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ]
}
@test "Reject invalid signature in a ReplicationController" {
run kwctl run --request-path test_data/replicationcontroller_creation_unsigned.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*is not accepted: verification of image ghcr.io/kubewarden/test-verify-image-signatures:unsigned failed.*') -ne 0 ]
}
@test "Accept a valid signature in a Job" {
run kwctl run --request-path test_data/job_creation_signed.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ]
}
@test "Reject invalid signature in a Job" {
run kwctl run --request-path test_data/job_creation_unsigned.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*is not accepted: verification of image ghcr.io/kubewarden/test-verify-image-signatures:unsigned failed.*') -ne 0 ]
}
@test "Accept a valid signature in a CronJob" {
run kwctl run --request-path test_data/cronjob_creation_signed.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":true.*') -ne 0 ]
}
@test "Reject invalid signature in a CronJob" {
run kwctl run --request-path test_data/cronjob_creation_unsigned.json --settings-path test_data/settings-mutation-enabled.yaml annotated-policy.wasm
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*"allowed":false.*') -ne 0 ]
[ $(expr "$output" : '.*is not accepted: verification of image ghcr.io/kubewarden/test-verify-image-signatures:unsigned failed.*') -ne 0 ]
}
@test "Certificate verification with Rekor enabled" {
# Need to run the command inside of `bash -c` because of a bats
# limitation: https://bats-core.readthedocs.io/en/stable/gotchas.html?highlight=pipe#my-piped-command-does-not-work-under-run
run bash -c 'kwctl run \
--request-path test_data/pod_creation_signed_with_certificate.json \
--settings-path test_data/settings-pod_signed_with_cert_and_rekor.yaml \
annotated-policy.wasm | jq -r ".patch | @base64d"'
[ "$status" -eq 0 ]
echo "$output"
[ $(expr "$output" : '.*ghcr.io/kubewarden/tests/pod-privileged:v0.2.1@sha256:db48aecd83c2826eba154a84c4fbabe0977f96b3360b4c6098578eae5c2d2882.*') -ne 0 ]
}
@test "Certificate verification with a wrong certificate chain" {
run kwctl run \
--request-path test_data/pod_creation_signed_with_certificate.json \
--settings-path test_data/settings-cert-verification-wrong-cert-chain.yaml \
annotated-policy.wasm
[ "$status" -eq 1 ]
echo "$output"
[ $(expr "$output" : '.*Provided settings are not valid.*') -ne 0 ]
[ $(expr "$output" : '.*Certificate not trusted: Certificate is not trusted by the provided cert chain.*') -ne 0 ]
}