Skip to content

Commit 751c4c2

Browse files
committed
Redact plaintext MySQL password from superset entrypoint logs
entrypoint.sh's set -euxo pipefail traced the fully-substituted superset test_db command, including the plaintext mysql_superset_password secret, to stderr. Separately, superset test_db itself prints the full SQLAlchemy connection URI (with password) to stdout. Both ended up in docker logs / docker service logs superset, and persisted indefinitely in the host's json-file log driver. Build the DB URI in a variable with -x off, and pipe test_db's combined output through a literal-string redaction filter before it reaches Docker's log driver. -x tracing resumes for the rest of the script.
1 parent a459eb7 commit 751c4c2

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939

4040
### Fixed
4141

42+
* Redacted MySQL password from `superset` entrypoint's `test_db` output and disabled `-x` tracing around it,
43+
preventing plaintext password exposure in `docker logs`/`docker service logs`.
4244
* Upload `.py` source instead of `.pyc` bytecode to decouple host Python version. (#38, #41)
4345
* Fixed `run_mysql_server()` not instantiating `MySQLServer` class. (#94)
4446
* Disabled MD060 markdownlint rule to fix table column style false positives in documentation. (#94)

services/superset/entrypoint.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
#!/bin/bash
22

3-
set -euxo pipefail
3+
set -euo pipefail
4+
5+
DB_PASSWORD=$(< /run/secrets/mysql_superset_password)
6+
DB_URI="mysql+mysqlconnector://superset:${DB_PASSWORD}@${VIRTUAL_IP_ADDRESS}:6446/superset"
7+
8+
# -x stays off here: tracing this line, or superset test_db's own "SQLAlchemy
9+
# URI" printout, would put the plaintext DB password into docker logs/docker
10+
# service logs. Redact stdout+stderr as a backstop in case anything
11+
# downstream still echoes the URI.
12+
if superset test_db "$DB_URI" --connect-args {} 2>&1 \
13+
| DB_PASSWORD="$DB_PASSWORD" python3 -c '
14+
import os, sys
15+
pw = os.environ["DB_PASSWORD"]
16+
for line in sys.stdin:
17+
sys.stdout.write(line.replace(pw, "<redacted>"))
18+
sys.stdout.flush()
19+
'; then
20+
set -x
421

5-
if superset test_db \
6-
"mysql+mysqlconnector://superset:$(< /run/secrets/mysql_superset_password)@${VIRTUAL_IP_ADDRESS}:6446/superset" \
7-
--connect-args {}; then
8-
922
superset fab create-admin \
1023
--username "superset" \
1124
--firstname "superset" \

0 commit comments

Comments
 (0)