Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUD-789 - add test to check password leaks in the logs #1472

Merged
merged 26 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
933a2d7
CLOUD-789 - add test to check password leaks in the logs
ptankov Aug 3, 2023
0275289
fixinf the passwords of monitor user and pmmserver user
ptankov Aug 3, 2023
e39bcf1
Adding password checks in haproxy and pitr tests
ptankov Aug 3, 2023
7c5096f
fixing diff file with 2 new entries
ptankov Aug 4, 2023
681dc6a
trying to be more verbose when a password leak is found
ptankov Aug 4, 2023
d88fea0
previsous fix wasn't correct
ptankov Aug 4, 2023
9ad2b34
Remove bash to lowercase function so it works in older bash
tplavcic Aug 5, 2023
593b6bc
for debugging purposes
ptankov Aug 7, 2023
a4c54b2
for debugging purposes - 2
ptankov Aug 8, 2023
e43d04e
for debugging purposes - 3
ptankov Aug 8, 2023
0af8d71
@ptankov
ptankov Aug 8, 2023
aeb2c16
for debugging purposes - 5
ptankov Aug 8, 2023
fbc305b
Merge branch 'main' into CLOUD-789
tplavcic Aug 29, 2023
4320a5f
Merge branch 'main' into CLOUD-789
ptankov Sep 29, 2023
95d07a9
converting variables in a function to local
ptankov Sep 29, 2023
39eacd3
changing TEMP_DIR to tmp_dir
ptankov Oct 2, 2023
22da5ab
some more local variables declaration
ptankov Oct 2, 2023
56d05fe
- updating the compare yaml file to match new reality
ptankov Oct 5, 2023
2513cc2
monitor and pmmserver users included a new line in their passwords -…
ptankov Oct 11, 2023
c160e11
fixing a broken password
ptankov Oct 16, 2023
96f8d59
pgrep command doesn't exist in the latest pmm docker image - workaround
ptankov Oct 16, 2023
5000515
Merge branch 'main' into CLOUD-789
ptankov Oct 16, 2023
8e40e7f
debugging purposes: 01
ptankov Oct 17, 2023
cb0da76
debugging purposes: 02
ptankov Oct 18, 2023
313fd23
removing the usage of the empty payload.json file
ptankov Oct 18, 2023
31ea845
Merge branch 'main' into CLOUD-789
ptankov Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e-tests/conf/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ type: Opaque
data:
root: cm9vdF9wYXNzd29yZA==
xtrabackup: YmFja3VwX3Bhc3N3b3Jk
monitor: bW9uaXRvcg==
monitor: bW9uaXRvcl9wYXNzd29yZA==
clustercheck: Y2x1c3RlcmNoZWNrcGFzc3dvcmQ=
proxyadmin: YWRtaW5fcGFzc3dvcmQ=
pmmserver: YWRtaW4=
pmmserver: cG1tc2VydmVyX3Bhc3N3b3Jk
operator: b3BlcmF0b3JhZG1pbg==
replication: cmVwbF9wYXNzd29yZA==
---
Expand Down
4 changes: 2 additions & 2 deletions e2e-tests/conf/secrets_without_tls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ type: Opaque
data:
root: cm9vdF9wYXNzd29yZA==
xtrabackup: YmFja3VwX3Bhc3N3b3Jk
monitor: bW9uaXRvcg==
monitor: bW9uaXRvcl9wYXNzd29yZA==
clustercheck: Y2x1c3RlcmNoZWNrcGFzc3dvcmQ=
proxyadmin: YWRtaW5fcGFzc3dvcmQ=
pmmserver: YWRtaW4=
pmmserver: cG1tc2VydmVyX3Bhc3N3b3Jk
operator: b3BlcmF0b3JhZG1pbg==
replication: cmVwbF9wYXNzd29yZA==
54 changes: 54 additions & 0 deletions e2e-tests/functions
Original file line number Diff line number Diff line change
Expand Up @@ -1518,3 +1518,57 @@ function check_backup_deletion() {
((retry += 1))
done
}

check_passwords_leak() {
local secrets
local passwords
local pods

secrets=$(kubectl_bin 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") or contains("release") or contains("namespace") or contains("AWS_ACCESS_KEY_ID") or contains("AZURE_STORAGE_ACCOUNT_NAME")) | not) | .value')
ptankov marked this conversation as resolved.
Show resolved Hide resolved
echo secrets=$secrets

passwords="$(for i in $secrets; do base64 -d <<< $i; echo; done) $secrets"
ptankov marked this conversation as resolved.
Show resolved Hide resolved
echo passwords=$passwords

pods=$(kubectl_bin get pods -o name | awk -F "/" '{print $2}')
echo pods=$pods

collect_logs() {
local containers
local count

NS=$1
for p in $pods; do
if [[ $p == "monitoring-0" ]]; then
continue
fi
containers=$(kubectl_bin -n "$NS" get pod $p -o jsonpath='{.spec.containers[*].name}')
for c in $containers; do
# temporary, because of: https://jira.percona.com/browse/PMM-8357
if [[ $c =~ "pmm" ]]; then
continue
fi
kubectl_bin -n "$NS" logs $p -c $c > ${tmp_dir}/logs_output-$p-$c.txt
ptankov marked this conversation as resolved.
Show resolved Hide resolved
echo logs saved in: ${tmp_dir}/logs_output-$p-$c.txt
for pass in $passwords; do
echo trying password: $pass
count=$(grep -c --fixed-strings -- "$pass" ${tmp_dir}/logs_output-$p-$c.txt || :)
if [[ $count != 0 ]]; then
echo leaked password $pass is found in log ${tmp_dir}/logs_output-$p-$c.txt
echo the content of file ${tmp_dir}/logs_output-$p-$c.txt is:
echo =========================================================
cat ${tmp_dir}/logs_output-$p-$c.txt
false
fi
done
done
echo
done
}

collect_logs $namespace
if [ -n "$OPERATOR_NS" ]; then
pods=$(kubectl_bin -n "${OPERATOR_NS}" get pods -o name | awk -F "/" '{print $2}')
collect_logs $OPERATOR_NS
fi
}
3 changes: 3 additions & 0 deletions e2e-tests/haproxy/run
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ main() {
wait_for_running "$cluster-pxc" 3
check_haproxy_writer

desc 'check for passwords leak'
check_passwords_leak

desc 'delete active writer and checking all haproxy pods still point to the same writer'
desc 'fail pxc-pod-0 pod for 60s'
fail_pod $cluster-pxc-0
Expand Down
13 changes: 8 additions & 5 deletions e2e-tests/init-deploy/run
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ compare_kubectl pdb/$cluster-proxysql

desc 'check if MySQL users created'
compare_mysql_user "-h $cluster-pxc -uroot -proot_password"
compare_mysql_user "-h $cluster-pxc -umonitor -pmonitor"
compare_mysql_user "-h $cluster-pxc -umonitor -pmonitor_password"
compare_mysql_user "-h $cluster-pxc -uproxyuser -ps3cret"
compare_mysql_user_local "-uxtrabackup -pbackup_password" "$cluster-pxc-0" "" "pxc"
compare_mysql_user_local "-uclustercheck -pclustercheckpassword" "$cluster-pxc-0" "" "pxc"
desc "check that pmm server user don't have access"
compare_mysql_user "-h $cluster-pxc -upmmserver -pmonitor"
compare_mysql_user "-h $cluster-pxc -upmmserver -ppmmserver_password"

desc 'check if ProxySQL users created'
compare_mysql_user "-h $cluster-proxysql -uroot -proot_password"
compare_mysql_user "-h $cluster-proxysql -umonitor -pmonitor"
compare_mysql_user "-h $cluster-proxysql -umonitor -pmonitor_password"
desc "check that pmm server user don't have access"
compare_mysql_user "-h $cluster-proxysql -uproxyuser -ps3cret" "-proxysql"
compare_mysql_user "-h $cluster-proxysql -upmmserver -pmonitor" "-proxysql"
compare_mysql_user "-h $cluster-proxysql -upmmserver -ppmmserver_password" "-proxysql"

desc 'write data directly, read from all'
run_mysql \
Expand Down Expand Up @@ -98,7 +98,10 @@ compare_mysql_cmd "select-1" "SELECT * from myApp.myApp;" "-h $cluster3-pxc-0.$c
compare_mysql_cmd "select-1" "SELECT * from myApp.myApp;" "-h $cluster3-pxc-1.$cluster3-pxc -uroot -proot_password"
compare_mysql_cmd "select-1" "SELECT * from myApp.myApp;" "-h $cluster3-pxc-2.$cluster3-pxc -uroot -proot_password"
compare_mysql_cmd "max_allowed_packet-2" "SELECT @@max_allowed_packet;" "-h $cluster3-pxc-0.$cluster3-pxc -uroot -proot_password"
kubectl_bin delete -f $test_dir/conf/$cluster3.yml

desc 'check for passwords leak'
check_passwords_leak

kubectl_bin delete -f $test_dir/conf/$cluster3.yml
destroy $namespace
desc "test passed"
1 change: 0 additions & 1 deletion e2e-tests/monitoring-2-0/compare/agents-list.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
"service_type": "postgresql",
"database_name": "postgres",
"node_name": "pmm-server",
"cluster": "pmm-server-postgresql",
"address": "127.0.0.1",
"port": 5432,
"agents": [
Expand Down
12 changes: 6 additions & 6 deletions e2e-tests/monitoring-2-0/run
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ get_mgmnt_service_list() {
local api_key=$1
local endpoint=$2
local namespace=$3
cat >${tmp_dir}/payload.json <<EOF
{}
EOF

curl -s -k -H "Authorization: Bearer ${api_key}" -X POST -d @payload.json "https://$endpoint/v1/management/Service/List" \
curl -s -k -H "Authorization: Bearer ${api_key}" -X POST "https://$endpoint/v1/management/Service/List" \
| jq 'walk(if type=="object" then with_entries(select(.key | test("service_id|node_id|agent_id|created_at|updated_at|service_name") | not)) else . end)' \
| jq 'walk(if type == "array" then sort_by(.agent_type) else . end)' \
>${tmp_dir}/active_pmm_agents.json
Expand Down Expand Up @@ -71,8 +68,7 @@ else
helm install monitoring --set imageTag=$IMAGE_PMM_SERVER_TAG --set imageRepo=$IMAGE_PMM_SERVER_REPO --set platform=$platform https://percona-charts.storage.googleapis.com/pmm-server-${PMM_SERVER_VER}.tgz
fi
kubectl_bin wait --for=condition=Ready pod/${cluster}-0 --timeout=120s
SERVICE="postgres"
until kubectl_bin exec monitoring-0 -- bash -c "pgrep -x $SERVICE >/dev/null"; do
until kubectl_bin exec monitoring-0 -- bash -c "ls -l /proc/*/exe 2>/dev/null| grep postgres >/dev/null"; do
echo "Retry $retry"
sleep 5
let retry+=1
Expand Down Expand Up @@ -160,6 +156,10 @@ if [[ -n ${OPENSHIFT} ]]; then
oc delete rolebinding pmm-pxc-operator-namespace-only
fi
fi

desc 'check for passwords leak'
check_passwords_leak

helm uninstall monitoring
destroy $namespace
desc "test passed"
7 changes: 7 additions & 0 deletions e2e-tests/pitr/run
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ main() {

run_backup "$cluster" "on-pitr-minio"

desc 'check for passwords leak'
check_passwords_leak

write_test_data "$cluster"

desc 'show binlog events'
Expand Down Expand Up @@ -134,6 +137,10 @@ main() {

run_recovery_check_pitr "$cluster" "restore-on-pitr-minio-gtid" "on-pitr-minio" "select-2" "" "" "$gtid"
desc "done gtid type"

desc 'check for passwords leak'
check_passwords_leak

sleep 60
if [[ $(kubectl get pxc-backup on-pitr-minio -o jsonpath='{.status.conditions}' | grep -c 'Binlog with GTID set') -eq 1 ]]; then
echo "Binlog gap detected"
Expand Down
Loading