Skip to content

Commit 121e937

Browse files
fix patch functions and add troubleshooting doc (IBM#259)
* fix patch functions and add troubleshooting doc * fix scripts and some parts in doc
1 parent 0ef8683 commit 121e937

File tree

15 files changed

+608
-105
lines changed

15 files changed

+608
-105
lines changed
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
# Check and Troubleshooting
2+
3+
## How to check Integrity Shield working
4+
5+
### Check Installation
6+
7+
To check if Integrity Shield is correctly deployed, you can check Pod status and webhook existence like the following.
8+
9+
If `integrity-shield-server` Pod is Running and a WebhookConfiguration is there, Integrity Shield is installed and working.
10+
11+
12+
```
13+
$ oc get pod -n integrity-shield-operator-system
14+
NAME READY STATUS RESTARTS AGE
15+
integrity-shield-operator-controller-manager-7df9cfffd-tzq2f 1/1 Running 0 23m
16+
integrity-shield-server-8469845dd-98bld 2/2 Running 0 22m
17+
18+
$ oc get mutatingwebhookconfiguration
19+
NAME WEBHOOKS AGE
20+
ishield-webhook-config 1 22m
21+
```
22+
23+
### Check Integrity Shield Events
24+
25+
Integrity Shield reports all events that were denied by Integrity Shield itself.
26+
27+
You can see all denied requests as Kubernetes Event like below.
28+
29+
```
30+
$ oc get event -n secure-ns --field-selector type=IntegrityShield
31+
32+
LAST SEEN TYPE REASON OBJECT MESSAGE
33+
27s IntegrityShield no-signature configmap/test-cm [IntegrityShieldEvent] Result: deny, Reason: "Signature verification is required for this request, but no signature is found. Please attach a valid signature to the annotation or by a ResourceSignature.", Request: {"kind":"ConfigMap","name":"test-cm","namespace":"secure-ns","operation":"CREATE","request.uid":"cfea7d34-0bf0-4e6a-9b59-e53290e02e67","scope":"Namespaced","userName":"kubernetes-admin"}
34+
```
35+
36+
This is an example of ConfigMap request, so the event is reported in the same namespace as ConfigMap namespace.
37+
38+
If a request of Cluster-scoped resource such as ClusterRole is denied by Integrity Shield, the event will be created in the same namespace as Integrity Shield.
39+
40+
To check all denied events in your cluster, simply you can run the command below.
41+
42+
```
43+
$ oc get event --all-namespaces --field-selector type=IntegrityShield
44+
```
45+
46+
If you want to check not only denied events but also allowed events, they are logged in container log. Please see the next section.
47+
48+
49+
### Check RSP status
50+
51+
Resource Signing Profile (RSP) defines what resource should be protected by Integrity Shield, so RSP status shows corresponding denied events if exist.
52+
53+
You can check RSP status like the following.
54+
55+
```
56+
$ oc describe rsp -n secure-ns sample-rsp
57+
58+
...
59+
60+
Status:
61+
Deny Count: 1
62+
Deny Summary:
63+
Count: 1
64+
Group Version Kind: /v1, Kind=ConfigMap
65+
Latest Denied Events:
66+
Request:
67+
API Version: v1
68+
Kind: ConfigMap
69+
Name: sample-cm
70+
Namespace: secure-ns
71+
Operation: CREATE
72+
User Name: kubernetes-admin
73+
Result:
74+
Message: Signature verification is required for this request, but no signature is found. Please attach a valid signature to the annotation or by a ResourceSignature.
75+
Timestamp: 2021-01-13 07:34:21
76+
77+
```
78+
79+
### Check Integrity Verified Resources
80+
81+
When you want to check what resources are verified with their signatures, you can use a script named [`list_signed_resources.sh `](../scripts/list_signed_resources.sh).
82+
83+
This script shows you a list of resources that are verified by Integrity Shield, and you can use a short name for a kind argument like below.
84+
85+
```
86+
$ ./scripts/list_signed_resources.sh deployment
87+
--- Deployment ---
88+
NAMESPACE NAME SIGNER LAST_VERIFIED RSIG_UID
89+
secure-ns sample-deployment [email protected] 2021-01-20T07:28:09Z 2de4ea9e-7bfb-45fd-a730-ab866cfd4332
90+
91+
$ ./scripts/list_signed_resources.sh cm
92+
--- ConfigMap ---
93+
NAMESPACE NAME SIGNER LAST_VERIFIED RSIG_UID
94+
secure-ns sample-cm [email protected] 2021-01-20T07:27:59Z ac31dd59-6f73-4958-a21a-df337fbf5d07
95+
secure-ns sample-cm-2 [email protected] 2021-01-20T07:43:38Z 08dbcb7d-3055-4a84-8246-302510d9b76c
96+
```
97+
98+
Also, you can specify `all` as kind argument, but please note that this queries `kubectl get` API for all valid resource kinds. The output will be like following.
99+
```
100+
$ ./scripts/list_signed_resources.sh all
101+
--- ConfigMap ---
102+
NAMESPACE NAME SIGNER LAST_VERIFIED RSIG_UID
103+
secure-ns sample-cm [email protected] 2021-01-20T07:27:59Z ac31dd59-6f73-4958-a21a-df337fbf5d07
104+
secure-ns sample-cm-2 [email protected] 2021-01-20T07:43:38Z 08dbcb7d-3055-4a84-8246-302510d9b76c
105+
106+
--- Service ---
107+
NAMESPACE NAME SIGNER LAST_VERIFIED RSIG_UID
108+
secure-ns test-service [email protected] 2021-01-20T07:27:20Z null
109+
110+
--- Deployment ---
111+
NAMESPACE NAME SIGNER LAST_VERIFIED RSIG_UID
112+
secure-ns sample-deployment [email protected] 2021-01-20T07:28:09Z 2de4ea9e-7bfb-45fd-a730-ab866cfd4332
113+
114+
--- ClusterRole ---
115+
NAMESPACE NAME SIGNER LAST_VERIFIED RSIG_UID
116+
- sample-sa-role [email protected] 2021-01-20T07:48:41Z aa63307a-a938-4efd-8d98-dd1f8b0442eb
117+
```
118+
119+
120+
## Troubleshooting
121+
122+
### Install issue
123+
124+
If only operator Pod (`integrity-shield-operator-controller-xxxx-xxxx` by default) is running and there is no `integrity-shield-server-xxxx-xxxx` Pod, please check operator container log.
125+
126+
If you see the log message like below, some required verification key secret are not ready. Once you deployed the secret there, installation will be started by operator.
127+
128+
```
129+
$ oc get pod -n integrity-shield-operator-system
130+
NAME READY STATUS RESTARTS AGE
131+
integrity-shield-operator-controller-manager-7df9cfffd-tzq2f 1/1 Running 0 2m
132+
133+
134+
$ oc logs deployment.apps/integrity-shield-operator-controller-manager
135+
136+
...
137+
138+
2021-01-13T09:06:15.279Z INFO controllers.IntegrityShield KeyRing secret "keyring-secret" does not exist. Skip reconciling. {"Request.Namespace": "integrity-shield-operator-system", "Request.Name": "integrity-shield-server"}
139+
2021-01-13T09:06:15.286Z INFO controllers.IntegrityShield KeyRing secret "keyring-secret" does not exist. Skip reconciling. {"Request.Namespace": "integrity-shield-operator-system", "Request.Name": "integrity-shield-server"}
140+
2021-01-13T09:06:15.299Z INFO controllers.IntegrityShield KeyRing secret "keyring-secret" does not exist. Skip reconciling. {"Request.Namespace": "integrity-shield-operator-system", "Request.Name": "integrity-shield-server"}
141+
```
142+
143+
144+
### Uninstall issue
145+
146+
Integrity Shield protects Integirty Shield itself, so uninstalling it should be done by some correct steps.
147+
148+
Documents and some scripts in this repository provide automated ways to uninstall Integrity Shield, so basically you don't need to know the actual steps.
149+
150+
But sometimes you might face a issue around uninstall due to some reasons, and you might not be able to uninstall it.
151+
152+
In such a case, deleting `MutatingWebhookConfiguration` of IntegrityShield could solve the situation.
153+
154+
Here is example steps of manual uninstall for Integrity Shield.
155+
156+
```
157+
$ oc delete mutatingwebhookconfiguration ishield-webhook-config
158+
mutatingwebhookconfiguration.admissionregistration.k8s.io "ishield-webhook-config" deleted
159+
160+
$ oc delete integrityshield integrity-shield-server -n integrity-shield-operator-system
161+
integrityshield.apis.integrityshield.io "integrity-shield-server" deleted
162+
163+
$ oc get pod -n integrity-shield-operator-system
164+
NAME READY STATUS RESTARTS AGE
165+
integrity-shield-operator-controller-manager-7df9cfffd-tzq2f 1/1 Running 0 23m
166+
```
167+
168+
After deleting IntegrityShield CR, the server Pod will be deleted (because CR is the owner).
169+
170+
Once you successfully deleted server Pod, no blocking functions are working anymore, so you can delete all other resources if you want.
171+
172+
### Unexpected Deny
173+
174+
If your request has been denied in spite of non-protected resource, please check RSPs in the cluster.
175+
176+
Basically, RSPs in a certain namespace can be used only for protection of resources in the namespace.
177+
178+
However, RSPs in Integrity Shield namespace (`integrity-shield-operator-system` by default) can be used as something like global configuration, so it can define any namespace rule.
179+
180+
To see all RSPs in your cluster, you can use a [list_rsp.sh ](../scripts/list_rsp.sh) (Use `jq` and `column` in the script)
181+
182+
```
183+
$ ./scripts/list_rsp.sh
184+
NAMESPACE NAME RULES TARGET_NAMESPACE
185+
integrity-shield-operator-system global-rsp {"protectRules":[{"match":[{"kind":"Service"}]}]} {"exclude":["kube-*"],"include":["*"]}
186+
secure-ns sample-rsp {"protectRules":[[{"match":[{"kind":"Pod"},{"kind":"ConfigMap"},{"kind":"Deployment"}]}]} secure-ns
187+
test-ns sample-clusterrole-rsp {"protectRules":[[{"match":[{"kind":"ClusterRole"}]}]} test-ns
188+
```
189+
190+
Additionally, if you are using ResourceSignature instead of annotation signature, you can list all ResourceSignatures in your cluster by a script [list_rsig.sh ](../scripts/list_rsig.sh) .
191+
192+
This might be useful to solve some issues caused by mis-configured ResourceSignature.
193+
194+
```
195+
$ ./scripts/list_rsig.sh
196+
NAMESPACE NAME SIGNED_OBJECT SIGNED_TIME(UTC)
197+
secure-ns rsig-configmap-sample-cm kind=ConfigMap,name=sample-cm 2021-01-13T10:52:38Z
198+
test-ns rsig-deployment-sample-deployment kind=Deployment,name=sample-deployment 2021-01-13T10:53:27Z
199+
```
200+
201+
202+
### Unexpected Allow
203+
204+
If your request has been allowed unexpectedly, please check if Integrity Shield is correctly working in the cluster first.
205+
You can check it following [this](#check-installtion) .
206+
207+
Also, mis-configured RSP might cause unexpected allow, so the script above ([list_rsp.sh](../scripts/list-rsp.sh)) might be useful to check RSP configurations.
208+
209+
If Integirty Shield and RSPs are correctly set up in the cluster, server container of integrity-shield-server Pod might log unexpected error, this should not be happened though.
210+
211+
In this case, reporting issue with your log will be great help for us to improve Integrity Shield even more. We would really appreciate you if you could report any issue.
212+

docs/README_QUICK.md

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ run the command below for trying to create the configmap in `secure-ns` namespac
200200

201201
```
202202
$ oc apply -f /tmp/test-cm.yaml -n secure-ns
203-
Error from server: error when creating "test-cm.yaml": admission webhook "ac-server.integrity-shield-operator-system.svc" denied the request: No signature found
203+
Error from server: error when creating "test-cm.yaml": admission webhook "ac-server.integrity-shield-operator-system.svc" denied the request: Signature verification is required for this request, but no signature is found. Please attach a valid signature to the annotation or by a ResourceSignature, Request: {"kind":"ConfigMap","name":"test-cm","namespace":"secure-ns","operation":"CREATE","request.uid":"cfea7d34-0bf0-4e6a-9b59-e53290e02e67","scope":"Namespaced","userName":"kubernetes-admin"}
204204
```
205205

206206

@@ -247,64 +247,13 @@ configmap/test-cm created
247247
```
248248

249249

250-
Integrity Shield generates logs while processing admission requests in a cluster. Two types of logs are available. You can see Integrity Shield server processing logs by a script called [`log_server.sh `](../scripts/log_server.sh). This includes when requests come and go, as well as errors which occured during processing.
251-
252-
If you want to see the result of admission check, you can see the detail by using a script called [`log_logging.sh `](../scripts/log_logging.sh).
253-
```json
254-
{
255-
"abortReason": "",
256-
"aborted": false,
257-
"allowed": false,
258-
"apiGroup": "",
259-
"apiVersion": "v1",
260-
"breakglass": false,
261-
"claim.ownerApiVersion": "",
262-
"claim.ownerKind": "",
263-
"claim.ownerName": "",
264-
"claim.ownerNamespace": "secure-ns",
265-
"creator": "",
266-
"detectOnly": false,
267-
"iShieldResource": false,
268-
"ignoreSA": false,
269-
"kind": "ConfigMap",
270-
"ma.checked": "false",
271-
"ma.diff": "",
272-
"ma.errOccured": false,
273-
"ma.filtered": "",
274-
"ma.mutated": "false",
275-
"maIntegrity.serviceAccount": "",
276-
"maIntegrity.signature": "",
277-
"msg": "Failed to verify signature; Signature is invalid",
278-
"name": "test-cm",
279-
"namespace": "secure-ns",
280-
"objLabels": "",
281-
"objMetaName": "test-cm",
282-
"operation": "CREATE",
283-
"org.ownerApiVersion": "",
284-
"org.ownerKind": "",
285-
"org.ownerName": "",
286-
"org.ownerNamespace": "secure-ns",
287-
"own.errOccured": false,
288-
"own.owners": "null",
289-
"own.verified": false,
290-
"protected": true,
291-
"reasonCode": "invalid-signature",
292-
"request.dump": "",
293-
"request.objectHash": "",
294-
"request.objectHashType": "",
295-
"request.uid": "bdb62f22-22f8-4a4d-9ead-cc034e4ce07b",
296-
"requestScope": "Namespaced",
297-
"sessionTrace": "time=2020-09-23T02:45:19Z level=trace msg=New Admission Request Sent aborted=false allowed=true apiVersion=apis.integrityshield.io/v1alpha1 kind=ResourceSigningProfile name=sample-rsp namespace=secure-ns operation=UPDATE\n",
298-
"sig.allow": false,
299-
"sig.errMsg": "",
300-
"sig.errOccured": true,
301-
"sig.errReason": "Failed to verify signature; Signature is invalid",
302-
"timestamp": "2020-09-23T02:45:19.728Z",
303-
"type": "",
304-
"userInfo": "{\"username\":\"IAM#[email protected]\",\"groups\":[\"admin\",\"ishield-group\",\"system:authenticated\"]}",
305-
"userName": "IAM#[email protected]",
306-
"verified": false
307-
}
250+
You can see all denied requests as Kubernetes Event like below.
251+
252+
```
253+
$ oc get event -n secure-ns --field-selector type=IntegrityShield
254+
255+
LAST SEEN TYPE REASON OBJECT MESSAGE
256+
27s IntegrityShield no-signature configmap/test-cm [IntegrityShieldEvent] Result: deny, Reason: "Signature verification is required for this request, but no signature is found. Please attach a valid signature to the annotation or by a ResourceSignature.", Request: {"kind":"ConfigMap","name":"test-cm","namespace":"secure-ns","operation":"CREATE","request.uid":"cfea7d34-0bf0-4e6a-9b59-e53290e02e67","scope":"Namespaced","userName":"kubernetes-admin"}
308257
```
309258

310259
### Clean up Integrity Shield from the cluster

scripts/list_rsig.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
if ! [ -x "$(command -v kubectl)" ]; then
4+
echo 'Error: kubectl is not installed.' >&2
5+
exit 1
6+
fi
7+
8+
if ! [ -x "$(command -v jq)" ]; then
9+
echo 'Error: jq is not installed.' >&2
10+
exit 1
11+
fi
12+
13+
if ! [ -x "$(command -v column)" ]; then
14+
echo 'Error: column is not installed.' >&2
15+
exit 1
16+
fi
17+
18+
if [ -z "$ISHIELD_NS" ]; then
19+
echo "ISHIELD_NS is empty. Please set namespace name for integrity-shield."
20+
exit 1
21+
fi
22+
23+
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
24+
date='date -u -d @'
25+
elif [[ "$OSTYPE" == "darwin"* ]]; then
26+
date='date -u -r '
27+
fi
28+
29+
rsiglist=$(kubectl get rsig --all-namespaces -o json)
30+
# echo -e "${rsigdata}"
31+
len=$(echo -e "$rsiglist" | jq .items | jq length)
32+
if [[ $len != "0" ]]; then
33+
result=$(echo NAMESPACE NAME SIGNED_OBJECT SIGNED_TIME\(UTC\))
34+
for i in $( seq 0 $(($len - 1)) ); do
35+
rsig=$(echo -e "$rsiglist" | jq .items[$i] | jq -c .)
36+
ns=$(echo -e "$rsig" | jq -r .metadata.namespace)
37+
name=$(echo -e "$rsig" | jq -r .metadata.name)
38+
msg=$(echo -e "$rsig" | jq -r '.spec.data[0].message' | base64 -D | gzip -d)
39+
# echo -e "$msg"
40+
kind=$(echo -e "$msg" | yq r - -j | jq -r .kind)
41+
obj_name=$(echo -e "$msg" | yq r - -j | jq -r .metadata.name)
42+
sigtime=$(echo -e "$rsig" | jq -r '.metadata.labels."integrityshield.io/sigtime"')
43+
sigtime_date=$(${date}${sigtime} +'%Y-%m-%dT%H:%M:%SZ')
44+
result=$(echo -e "${result}\n${ns} ${name} kind=${kind},name=${obj_name} ${sigtime_date}")
45+
done
46+
47+
echo -e "$result" | column -t
48+
fi

scripts/list_rsp.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
if ! [ -x "$(command -v kubectl)" ]; then
4+
echo 'Error: kubectl is not installed.' >&2
5+
exit 1
6+
fi
7+
8+
if ! [ -x "$(command -v jq)" ]; then
9+
echo 'Error: jq is not installed.' >&2
10+
exit 1
11+
fi
12+
13+
if ! [ -x "$(command -v column)" ]; then
14+
echo 'Error: column is not installed.' >&2
15+
exit 1
16+
fi
17+
18+
if [ -z "$ISHIELD_NS" ]; then
19+
echo "ISHIELD_NS is empty. Please set namespace name for integrity-shield."
20+
exit 1
21+
fi
22+
23+
rsplist=$(kubectl get rsp --all-namespaces -o json)
24+
# echo -e "${rspdata}"
25+
len=$(echo -e "$rsplist" | jq .items | jq length)
26+
if [[ $len != "0" ]]; then
27+
result=$(echo NAMESPACE NAME RULES TARGET_NAMESPACE)
28+
for i in $( seq 0 $(($len - 1)) ); do
29+
rsp=$(echo -e "$rsplist" | jq .items[$i] | jq -c .)
30+
ns=$(echo -e "$rsp" | jq -r .metadata.namespace)
31+
t_ns=$(echo -e "$rsp" | jq .spec.targetNamespaceSelector | jq -c .)
32+
if [[ $t_ns == "null" ]]; then
33+
t_ns=$ns
34+
fi
35+
name=$(echo -e "$rsp" | jq -r .metadata.name)
36+
rule=$(echo -e "$rsp" | jq -c '{"protectRules":.spec.protectRules,"ignoreRules":.spec.ignoreRules,"forceCheckRules":.spec.forceCheckRules} | with_entries( select( .value != null ) )' | jq -c .)
37+
result=$(echo -e "${result}\n${ns} ${name} ${rule} ${t_ns}")
38+
done
39+
echo -e "$result" | column -t
40+
fi
41+

0 commit comments

Comments
 (0)