Skip to content

Commit

Permalink
Fix: Do not redact password for conn pool connection uri while connec…
Browse files Browse the repository at this point in the history
…ting to DB (#2203) (#2208)

Fixing the bug where import data always fails to connect to DB via the connection pool with password authentication as the connection URLs are redacted while passing to the connection pool.
Deep copying the connection params for redacting while logging using the package - https://github.com/tiendc/go-deepcopy.
  • Loading branch information
priyanshi-yb authored Jan 20, 2025
1 parent 4f2a2b7 commit cf0ed15
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/misc-migtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
docker run -d --name yugabytedb-$version \
-p7000:7000 -p9000:9000 -p15433:15433 -p5433:5433 -p9042:9042 \
yugabytedb/yugabyte:$version \
bin/yugabyted start --background=false --ui=false
bin/yugabyted start --tserver_flags="ysql_hba_conf_csv={host all yugabyte all trust,host all all all md5}" --background=false --ui=false
sleep 20
echo "Test YugabyteDB connection"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mysql-migtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
docker run -d --name yugabytedb \
-p7000:7000 -p9000:9000 -p15433:15433 -p5433:5433 -p9042:9042 \
yugabytedb/yugabyte:${{ matrix.version }} \
bin/yugabyted start --background=false --ui=false
bin/yugabyted start --tserver_flags="ysql_hba_conf_csv={host all yugabyte all trust,host all all all md5}" --background=false --ui=false
sleep 20
- name: Test YugabyteDB connection
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pg-13-migtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
docker run -d --name yugabytedb \
-p7000:7000 -p9000:9000 -p15433:15433 -p5433:5433 -p9042:9042 \
yugabytedb/yugabyte:${{ matrix.version }} \
bin/yugabyted start --background=false --ui=false
bin/yugabyted start --tserver_flags="ysql_hba_conf_csv={host all yugabyte all trust,host all all all md5}" --background=false --ui=false
sleep 20
- name: Test YugabyteDB connection
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pg-17-migtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
docker run -d --name yugabytedb \
-p7000:7000 -p9000:9000 -p15433:15433 -p5433:5433 -p9042:9042 \
yugabytedb/yugabyte:${{ matrix.version }} \
bin/yugabyted start --background=false --ui=false
bin/yugabyted start --tserver_flags="ysql_hba_conf_csv={host all yugabyte all trust,host all all all md5}" --background=false --ui=false
sleep 20
- name: Test YugabyteDB connection
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pg-9-migtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
docker run -d --name yugabytedb \
-p7000:7000 -p9000:9000 -p15433:15433 -p5433:5433 -p9042:9042 \
yugabytedb/yugabyte:${{ matrix.version }} \
bin/yugabyted start --background=false --ui=false
bin/yugabyted start --tserver_flags="ysql_hba_conf_csv={host all yugabyte all trust,host all all all md5}" --background=false --ui=false
sleep 20
- name: Test YugabyteDB connection
Expand Down
3 changes: 2 additions & 1 deletion yb-voyager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
github.com/tebeka/atexit v0.3.0
github.com/testcontainers/testcontainers-go v0.34.0
github.com/testcontainers/testcontainers-go/modules/yugabytedb v0.34.0
github.com/tiendc/go-deepcopy v1.2.0
github.com/vbauerster/mpb/v8 v8.4.0
gocloud.dev v0.29.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
Expand Down Expand Up @@ -168,7 +169,7 @@ require (
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/text v0.16.0
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
Expand Down
2 changes: 2 additions & 0 deletions yb-voyager/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,8 @@ github.com/testcontainers/testcontainers-go v0.34.0/go.mod h1:6P/kMkQe8yqPHfPWNu
github.com/testcontainers/testcontainers-go/modules/yugabytedb v0.34.0 h1:9wIqSZJwBr4s8Q7R3S+rhe1J2zqHHxH0S1bN17ld+CI=
github.com/testcontainers/testcontainers-go/modules/yugabytedb v0.34.0/go.mod h1:bgHrbdYjpNPSstf8HfxChUxc6XztBCSoqDR0syb1Oeg=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tiendc/go-deepcopy v1.2.0 h1:6vCCs+qdLQHzFqY1fcPirsAWOmrLbuccilfp8UzD1Qo=
github.com/tiendc/go-deepcopy v1.2.0/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
Expand Down
9 changes: 8 additions & 1 deletion yb-voyager/src/tgtdb/yugabytedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/samber/lo"
log "github.com/sirupsen/logrus"
"github.com/tiendc/go-deepcopy"
"golang.org/x/exp/slices"

"github.com/yugabyte/yb-voyager/yb-voyager/src/callhome"
Expand Down Expand Up @@ -243,7 +244,13 @@ func (yb *TargetYugabyteDB) InitConnPool() error {
SessionInitScript: getYBSessionInitScript(yb.tconf),
}
yb.connPool = NewConnectionPool(params)
redactedParams := params
redactedParams := &ConnectionParams{}
//Whenever adding new fields to CONNECTION PARAMS check if that needs to be redacted while logging
err := deepcopy.Copy(redactedParams, params)
if err!= nil {
log.Errorf("couldn't get the copy of connection params for logging: %v", err)
return nil
}
redactedParams.ConnUriList = utils.GetRedactedURLs(redactedParams.ConnUriList)
log.Info("Initialized connection pool with settings: ", spew.Sdump(redactedParams))
return nil
Expand Down

0 comments on commit cf0ed15

Please sign in to comment.