Skip to content

Commit 035d023

Browse files
ptankovtplavcic
andauthored
Cloud-789: add test to check password leaks in the logs (#418)
Co-authored-by: Tomislav Plavcic <[email protected]>
1 parent e447204 commit 035d023

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+337
-232
lines changed

e2e-tests/functions

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,3 +460,40 @@ verify_certificate_sans() {
460460

461461
diff "${have}" "${want}"
462462
}
463+
464+
check_passwords_leak() {
465+
466+
secrets=$(kubectl get secrets -o json | jq -r '.items[].data | to_entries | .[] | select(.key | (endswith(".crt") or endswith(".key") or endswith(".pub") or endswith(".pem") or endswith(".p12")) | not) | .value')
467+
468+
passwords="$(for i in $secrets; do base64 -d <<< $i; echo; done) $secrets"
469+
pods=$(kubectl -n "${NAMESPACE}" get pods -o name | awk -F "/" '{print $2}')
470+
471+
collect_logs() {
472+
NS=$1
473+
for p in $pods; do
474+
containers=$(kubectl -n "$NS" get pod $p -o jsonpath='{.spec.containers[*].name}')
475+
for c in $containers; do
476+
# temporary, because of: https://jira.percona.com/browse/PMM-8357
477+
if [[ ${c,,} =~ "pmm" ]]; then
478+
continue
479+
fi
480+
kubectl -n "$NS" logs $p -c $c > ${TEMP_DIR}/logs_output-$p-$c.txt
481+
echo logs saved in: ${TEMP_DIR}/logs_output-$p-$c.txt
482+
for pass in $passwords; do
483+
count=$(grep -c --fixed-strings -- "$pass" ${TEMP_DIR}/logs_output-$p-$c.txt || :)
484+
if [[ $count != 0 ]]; then
485+
echo leaked passwords are found in log ${TEMP_DIR}/logs_output-$p-$c.txt
486+
false
487+
fi
488+
done
489+
done
490+
echo
491+
done
492+
}
493+
494+
collect_logs $NAMESPACE
495+
if [ -n "$OPERATOR_NS" ]; then
496+
pods=$(kubectl -n "${OPERATOR_NS}" get pods -o name | awk -F "/" '{print $2}')
497+
collect_logs $OPERATOR_NS
498+
fi
499+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: |-
5+
set -o errexit
6+
set -o xtrace
7+
8+
source ../../functions
9+
10+
check_passwords_leak
Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
3-
timeout: 400
3+
timeout: 30
44
---
5-
apiVersion: ps.percona.com/v1alpha1
6-
kind: PerconaServerMySQL
5+
kind: ConfigMap
6+
apiVersion: v1
77
metadata:
8-
name: demand-backup
9-
finalizers:
10-
- delete-mysql-pods-in-order
11-
status:
12-
haproxy:
13-
ready: 3
14-
size: 3
15-
state: ready
16-
mysql:
17-
ready: 3
18-
size: 3
19-
state: ready
20-
orchestrator:
21-
ready: 3
22-
size: 3
23-
state: ready
24-
state: ready
8+
name: 04-delete-data-minio-0
9+
data:
10+
data: ""
2511
---
26-
kind: PerconaServerMySQLRestore
27-
apiVersion: ps.percona.com/v1alpha1
12+
kind: ConfigMap
13+
apiVersion: v1
2814
metadata:
29-
name: demand-backup-restore-minio
30-
status:
31-
state: Succeeded
15+
name: 04-delete-data-minio-1
16+
data:
17+
data: ""
18+
---
19+
kind: ConfigMap
20+
apiVersion: v1
21+
metadata:
22+
name: 04-delete-data-minio-2
23+
data:
24+
data: ""
Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
3-
timeout: 30
3+
timeout: 400
44
---
5-
kind: ConfigMap
6-
apiVersion: v1
5+
apiVersion: ps.percona.com/v1alpha1
6+
kind: PerconaServerMySQL
77
metadata:
8-
name: 06-read-data-minio-0
9-
data:
10-
data: "100500"
8+
name: demand-backup
9+
finalizers:
10+
- delete-mysql-pods-in-order
11+
status:
12+
haproxy:
13+
ready: 3
14+
size: 3
15+
state: ready
16+
mysql:
17+
ready: 3
18+
size: 3
19+
state: ready
20+
orchestrator:
21+
ready: 3
22+
size: 3
23+
state: ready
24+
state: ready
1125
---
12-
kind: ConfigMap
13-
apiVersion: v1
26+
kind: PerconaServerMySQLRestore
27+
apiVersion: ps.percona.com/v1alpha1
1428
metadata:
15-
name: 06-read-data-minio-1
16-
data:
17-
data: "100500"
18-
---
19-
kind: ConfigMap
20-
apiVersion: v1
21-
metadata:
22-
name: 06-read-data-minio-2
23-
data:
24-
data: "100500"
29+
name: demand-backup-restore-minio
30+
status:
31+
state: Succeeded

e2e-tests/tests/demand-backup/09-assert.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
commands:
4+
- script: |-
5+
set -o errexit
6+
set -o xtrace
7+
8+
source ../../functions
9+
10+
check_passwords_leak
Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
apiVersion: kuttl.dev/v1beta1
22
kind: TestAssert
3-
timeout: 400
3+
timeout: 30
44
---
5-
apiVersion: ps.percona.com/v1alpha1
6-
kind: PerconaServerMySQL
5+
kind: ConfigMap
6+
apiVersion: v1
77
metadata:
8-
name: demand-backup
9-
finalizers:
10-
- delete-mysql-pods-in-order
11-
status:
12-
haproxy:
13-
ready: 3
14-
size: 3
15-
state: ready
16-
mysql:
17-
ready: 3
18-
size: 3
19-
state: ready
20-
orchestrator:
21-
ready: 3
22-
size: 3
23-
state: ready
24-
state: ready
8+
name: 06-read-data-minio-0
9+
data:
10+
data: "100500"
2511
---
26-
kind: PerconaServerMySQLRestore
27-
apiVersion: ps.percona.com/v1alpha1
12+
kind: ConfigMap
13+
apiVersion: v1
2814
metadata:
29-
name: demand-backup-restore-minio-backup-source
30-
status:
31-
state: Succeeded
15+
name: 06-read-data-minio-1
16+
data:
17+
data: "100500"
18+
---
19+
kind: ConfigMap
20+
apiVersion: v1
21+
metadata:
22+
name: 06-read-data-minio-2
23+
data:
24+
data: "100500"

0 commit comments

Comments
 (0)