Skip to content

Commit 6854a7d

Browse files
authored
Merge branch 'main' into K8SPS-421
2 parents e9470a5 + ad414c4 commit 6854a7d

39 files changed

+134
-67
lines changed

build/orc-entrypoint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ fi
4343

4444
set +o xtrace
4545
temp=$(mktemp)
46-
sed -r "s|^[#]?user=.*$|user=${TOPOLOGY_USER}|" "${ORC_CONF_PATH}/orc-topology.cnf" >"${temp}"
47-
sed -r "s|^[#]?password=.*$|password=${TOPOLOGY_PASSWORD:-$ORC_TOPOLOGY_PASSWORD}|" "${ORC_CONF_PATH}/orc-topology.cnf" >"${temp}"
46+
47+
ESCAPED_PASSWORD=$(printf '%s' "${TOPOLOGY_PASSWORD:-$ORC_TOPOLOGY_PASSWORD}" | sed -e 's/[&"\\]/\\&/g')
48+
ESCAPED_PASSWORD="\"${ESCAPED_PASSWORD}\"" # Wrap in double quotes for .cnf
49+
50+
sed -r \
51+
-e "s|^[#]?user=.*$|user=${TOPOLOGY_USER}|" \
52+
-e "s|^[#]?password=.*$|password=${ESCAPED_PASSWORD}|" \
53+
"${ORC_CONF_PATH}/orc-topology.cnf" > "${temp}"
54+
4855
cat "${temp}" >"${ORC_CONF_PATH}/config/orc-topology.cnf"
4956
rm "${temp}"
5057
set -o xtrace

build/ps-entrypoint.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ ensure_read_only() {
210210
sed -i "/\[mysqld\]/a super_read_only=ON" $CFG
211211
}
212212

213+
escape_special() {
214+
{ set +x; } 2>/dev/null
215+
echo "$1" \
216+
| sed 's/\\/\\\\/g' \
217+
| sed 's/'\''/'\\\\\''/g' \
218+
| sed 's/"/\\\"/g'
219+
}
220+
213221
MYSQL_VERSION=$(mysqld -V | awk '{print $3}' | awk -F'.' '{print $1"."$2}')
214222

215223
if [[ "$MYSQL_VERSION" != '8.0' ]] && [[ "${MYSQL_VERSION}" != '8.4' ]]; then
@@ -295,7 +303,7 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
295303
# no, we don't care if read finds a terminating character in this heredoc
296304
# https://unix.stackexchange.com/questions/265149/why-is-set-o-errexit-breaking-this-read-heredoc-expression/265151#265151
297305
read -r -d '' rootCreate <<-EOSQL || true
298-
CREATE USER 'root'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' PASSWORD EXPIRE NEVER;
306+
CREATE USER 'root'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '$(escape_special "${MYSQL_ROOT_PASSWORD}")' PASSWORD EXPIRE NEVER;
299307
GRANT ALL ON *.* TO 'root'@'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ;
300308
EOSQL
301309
fi
@@ -319,38 +327,38 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
319327
SET @@SESSION.SQL_LOG_BIN=0;
320328
321329
DELETE FROM mysql.user WHERE user NOT IN ('mysql.sys', 'mysqlxsys', 'root', 'mysql.infoschema', 'mysql.session') OR host NOT IN ('localhost') ;
322-
ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
330+
ALTER USER 'root'@'localhost' IDENTIFIED BY '$(escape_special "${MYSQL_ROOT_PASSWORD}")' ;
323331
GRANT ALL ON *.* TO 'root'@'localhost' WITH GRANT OPTION ;
324332
${rootCreate}
325333
/*!80016 REVOKE SYSTEM_USER ON *.* FROM root */;
326334
327-
CREATE USER 'operator'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '${OPERATOR_ADMIN_PASSWORD}' PASSWORD EXPIRE NEVER;
335+
CREATE USER 'operator'@'${MYSQL_ROOT_HOST}' IDENTIFIED BY '$(escape_special "${OPERATOR_ADMIN_PASSWORD}")' PASSWORD EXPIRE NEVER;
328336
GRANT ALL ON *.* TO 'operator'@'${MYSQL_ROOT_HOST}' WITH GRANT OPTION ;
329337
330-
CREATE USER 'xtrabackup'@'localhost' IDENTIFIED BY '${XTRABACKUP_PASSWORD}' PASSWORD EXPIRE NEVER;
338+
CREATE USER 'xtrabackup'@'localhost' IDENTIFIED BY '$(escape_special "${XTRABACKUP_PASSWORD}")' PASSWORD EXPIRE NEVER;
331339
GRANT SYSTEM_USER, BACKUP_ADMIN, PROCESS, RELOAD, GROUP_REPLICATION_ADMIN, REPLICATION_SLAVE_ADMIN, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'xtrabackup'@'localhost';
332340
GRANT SELECT ON performance_schema.replication_group_members TO 'xtrabackup'@'localhost';
333341
GRANT SELECT ON performance_schema.log_status TO 'xtrabackup'@'localhost';
334342
GRANT SELECT ON performance_schema.keyring_component_status TO 'xtrabackup'@'localhost';
335343
336-
CREATE USER 'monitor'@'${MONITOR_HOST}' IDENTIFIED BY '${MONITOR_PASSWORD}' WITH MAX_USER_CONNECTIONS 100 PASSWORD EXPIRE NEVER;
344+
CREATE USER 'monitor'@'${MONITOR_HOST}' IDENTIFIED BY '$(escape_special "${MONITOR_PASSWORD}")' WITH MAX_USER_CONNECTIONS 100 PASSWORD EXPIRE NEVER;
337345
GRANT SYSTEM_USER, SELECT, PROCESS, SUPER, REPLICATION CLIENT, RELOAD, BACKUP_ADMIN ON *.* TO 'monitor'@'${MONITOR_HOST}';
338346
GRANT SELECT ON performance_schema.* TO 'monitor'@'${MONITOR_HOST}';
339347
${monitorConnectGrant}
340348
341-
CREATE USER 'replication'@'%' IDENTIFIED BY '${REPLICATION_PASSWORD}' PASSWORD EXPIRE NEVER;
349+
CREATE USER 'replication'@'%' IDENTIFIED BY '$(escape_special "${REPLICATION_PASSWORD}")' PASSWORD EXPIRE NEVER;
342350
GRANT DELETE, INSERT, UPDATE ON mysql.* TO 'replication'@'%' WITH GRANT OPTION;
343351
GRANT SELECT ON performance_schema.threads to 'replication'@'%';
344352
GRANT SYSTEM_USER, REPLICATION SLAVE, BACKUP_ADMIN, GROUP_REPLICATION_STREAM, CLONE_ADMIN, CONNECTION_ADMIN, CREATE USER, EXECUTE, FILE, GROUP_REPLICATION_ADMIN, PERSIST_RO_VARIABLES_ADMIN, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION_APPLIER, REPLICATION_SLAVE_ADMIN, ROLE_ADMIN, SELECT, SHUTDOWN, SYSTEM_VARIABLES_ADMIN ON *.* TO 'replication'@'%' WITH GRANT OPTION;
345353
346-
CREATE USER 'orchestrator'@'%' IDENTIFIED BY '${ORC_TOPOLOGY_PASSWORD}' PASSWORD EXPIRE NEVER;
354+
CREATE USER 'orchestrator'@'%' IDENTIFIED BY '$(escape_special "${ORC_TOPOLOGY_PASSWORD}")' PASSWORD EXPIRE NEVER;
347355
GRANT SYSTEM_USER, SUPER, PROCESS, REPLICATION SLAVE, REPLICATION CLIENT, RELOAD ON *.* TO 'orchestrator'@'%';
348356
GRANT SELECT ON performance_schema.replication_group_members TO 'orchestrator'@'%';
349357
GRANT SELECT ON mysql.slave_master_info TO 'orchestrator'@'%';
350358
GRANT SELECT ON sys_operator.* TO 'orchestrator'@'%';
351359
352360
CREATE DATABASE IF NOT EXISTS sys_operator;
353-
CREATE USER 'heartbeat'@'localhost' IDENTIFIED BY '${HEARTBEAT_PASSWORD}' PASSWORD EXPIRE NEVER;
361+
CREATE USER 'heartbeat'@'localhost' IDENTIFIED BY '$(escape_special "${HEARTBEAT_PASSWORD}")' PASSWORD EXPIRE NEVER;
354362
GRANT SYSTEM_USER, REPLICATION CLIENT ON *.* TO 'heartbeat'@'localhost';
355363
GRANT SELECT, CREATE, DELETE, UPDATE, INSERT ON sys_operator.heartbeat TO 'heartbeat'@'localhost';
356364

build/router-entrypoint.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ ROUTER_DIR=${ROUTER_DIR:-/tmp/router}
66
OPERATOR_USER=${OPERATOR_USER:-operator}
77
NAMESPACE=$(</var/run/secrets/kubernetes.io/serviceaccount/namespace)
88

9+
urlencode() {
10+
python3 -c 'import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))' "$1"
11+
}
12+
913
if [ -f "/etc/mysql/mysql-users-secret/${OPERATOR_USER}" ]; then
1014
OPERATOR_PASS=$(<"/etc/mysql/mysql-users-secret/${OPERATOR_USER}")
15+
OPERATOR_PASS_ESCAPED=$(urlencode "$OPERATOR_PASS")
1116
fi
1217

1318
mysqlrouter --force \
14-
--bootstrap "${OPERATOR_USER}:${OPERATOR_PASS}@${MYSQL_SERVICE_NAME}-0.${MYSQL_SERVICE_NAME}.${NAMESPACE}.svc" \
19+
--bootstrap "${OPERATOR_USER}:${OPERATOR_PASS_ESCAPED}@${MYSQL_SERVICE_NAME}-0.${MYSQL_SERVICE_NAME}.${NAMESPACE}.svc" \
1520
--conf-bind-address 0.0.0.0 \
1621
--conf-set-option http_auth_backend:default_auth_backend.backend=file \
1722
--conf-set-option http_auth_backend:default_auth_backend.filename="${ROUTER_DIR}/realm.txt" \
1823
--directory "${ROUTER_DIR}"
1924

20-
echo ${OPERATOR_PASS} | mysqlrouter_passwd set "${ROUTER_DIR}/realm.txt" ${OPERATOR_USER}
25+
echo "${OPERATOR_PASS_ESCAPED}" | mysqlrouter_passwd set "${ROUTER_DIR}/realm.txt" "${OPERATOR_USER}"
2126

2227
sed -i 's/logging_folder=.*/logging_folder=/g' "${ROUTER_DIR}/mysqlrouter.conf"
2328
sed -i "/\[logger\]/a destination=/dev/stdout" "${ROUTER_DIR}/mysqlrouter.conf"

build/router_readiness_check.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
#!/bin/bash
22

3+
urlencode() {
4+
python3 -c 'import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))' "$1"
5+
}
6+
37
OPERATOR_PASS=$(</etc/mysql/mysql-users-secret/operator)
8+
OPERATOR_PASS_ESCAPED=$(urlencode "$OPERATOR_PASS")
49

5-
if ! curl -k -s -u operator:"${OPERATOR_PASS}" https://localhost:8443/api/20190715/routes/bootstrap_rw/health | grep true; then
10+
if ! curl -k -s -u operator:"${OPERATOR_PASS_ESCAPED}" https://localhost:8443/api/20190715/routes/bootstrap_rw/health | grep true; then
611
echo "Read-write route is not healthy"
712
exit 1
813
fi
914

10-
if ! curl -k -s -u operator:"${OPERATOR_PASS}" https://localhost:8443/api/20190715/routes/bootstrap_ro/health | grep true; then
15+
if ! curl -k -s -u operator:"${OPERATOR_PASS_ESCAPED}" https://localhost:8443/api/20190715/routes/bootstrap_ro/health | grep true; then
1116
echo "Read-only route is not healthy"
1217
exit 1
1318
fi
1419

15-
exit 0
20+
exit 0

build/router_startup_check.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
#!/bin/bash
22

3+
urlencode() {
4+
python3 -c 'import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))' "$1"
5+
}
6+
37
OPERATOR_PASS=$(</etc/mysql/mysql-users-secret/operator)
8+
OPERATOR_PASS_ESCAPED=$(urlencode "$OPERATOR_PASS")
49

5-
if [[ $(curl -k -s -u operator:"${OPERATOR_PASS}" -o /dev/null -w %{http_code} https://localhost:8443/api/20190715/router/status) != 200 ]]; then
10+
if [[ $(curl -k -s -u operator:"${OPERATOR_PASS_ESCAPED}" -o /dev/null -w %{http_code} https://localhost:8443/api/20190715/router/status) != 200 ]]; then
611
echo "Router is not ready"
7-
fi
12+
fi

cmd/bootstrap/group_replication.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"log"
10+
"net/url"
1011
"os"
1112
"os/exec"
1213
"regexp"
@@ -54,8 +55,9 @@ func (m *mysqlsh) getURI() string {
5455
if err != nil {
5556
return ""
5657
}
58+
escapedPass := url.QueryEscape(operatorPass)
5759

58-
return fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, operatorPass, m.host)
60+
return fmt.Sprintf("%s:%s@%s", apiv1alpha1.UserOperator, escapedPass, m.host)
5961
}
6062

6163
func (m *mysqlsh) run(ctx context.Context, cmd string) (bytes.Buffer, bytes.Buffer, error) {

e2e-tests/conf/secrets.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ stringData:
77
root: root_password
88
xtrabackup: backup_password
99
monitor: monitor_password
10-
proxyadmin: admin_password
1110
operator: operator_password
1211
replication: replication_password
1312
orchestrator: orchestrator_password

e2e-tests/functions

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,11 @@ deploy_cmctl() {
12591259
kubectl apply -n "${NAMESPACE}" -f "${TESTS_CONFIG_DIR}/cmctl.yml"
12601260
}
12611261

1262+
get_user_pass() {
1263+
local user="${1:-root}"
1264+
kubectl -n "${NAMESPACE}" get secret test-secrets -o jsonpath="{.data.${user}}" | base64 --decode
1265+
}
1266+
12621267
get_operator_version() {
12631268
kubectl get crd -n "$NAMESPACE" perconaservermysqls.ps.percona.com -o jsonpath='{.metadata.labels.app\.kubernetes\.io/version}'
12641269
}

e2e-tests/tests/demand-backup/01-deploy-operator.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ commands:
1010
1111
apply_s3_storage_secrets
1212
deploy_operator
13-
deploy_non_tls_cluster_secrets
1413
deploy_tls_cluster_secrets
1514
deploy_client
1615
deploy_minio

e2e-tests/tests/demand-backup/03-write-data.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ commands:
66
set -o xtrace
77
88
source ../../functions
9-
9+
password=$(get_user_pass root)
1010
run_mysql \
1111
"CREATE DATABASE IF NOT EXISTS myDB; CREATE TABLE IF NOT EXISTS myDB.myTable (id int PRIMARY KEY)" \
12-
"-h $(get_haproxy_svc $(get_cluster_name)) -uroot -proot_password"
12+
"-h $(get_haproxy_svc $(get_cluster_name)) -uroot -p'$password'"
1313
1414
run_mysql \
1515
"INSERT myDB.myTable (id) VALUES (100500)" \
16-
"-h $(get_haproxy_svc $(get_cluster_name)) -uroot -proot_password"
16+
"-h $(get_haproxy_svc $(get_cluster_name)) -uroot -p'$password'"

0 commit comments

Comments
 (0)