Skip to content

Commit

Permalink
FAB-5794 Mask credentials in debug messages
Browse files Browse the repository at this point in the history
(backport for 1.0.2)

While this would not normally have been an
issue, there are several cases where 3rd
party operators are hosting/running
fabric-ca.  In those cases, the people
who monitor the service should not be able
to see any credentials in the logs if they
need to turn on debug logging to
troubleshoot.

Change-Id: I51aa67a80094278e53481a91b8a9252655bd603e
Signed-off-by: Gari Singh <[email protected]>
  • Loading branch information
mastersingh24 committed Aug 25, 2017
1 parent 00700da commit 3066136
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"path"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/cloudflare/cfssl/config"
Expand Down Expand Up @@ -485,7 +486,12 @@ func (ca *CA) initDB() error {
}
}

log.Debugf("Initializing '%s' database at '%s'", db.Type, db.Datasource)
// Strip out user:pass from datasource for logging
ds := db.Datasource
dsParts := strings.Split(ds, "@")
if len(dsParts) > 1 {
ds = fmt.Sprintf("*****:*****@%s", dsParts[len(dsParts)-1])
}

switch db.Type {
case defaultDatabaseType:
Expand Down
3 changes: 0 additions & 3 deletions lib/dbutil/dbutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ func NewUserRegistryPostgres(datasource string, clientTLSConfig *tls.ClientTLSCo
connStr = fmt.Sprintf("%s sslcert=%s sslkey=%s", connStr, cert, key)
}

log.Debug("Connection String: ", connStr)

db, err := sqlx.Open("postgres", connStr)
if err != nil {
return nil, false, fmt.Errorf("Failed to open Postgres database: %s", err)
Expand Down Expand Up @@ -221,7 +219,6 @@ func NewUserRegistryMySQL(datasource string, clientTLSConfig *tls.ClientTLSConfi
mysql.RegisterTLSConfig("custom", tlsConfig)
}

log.Debug("Connection String: ", connStr)
db, err := sqlx.Open("mysql", connStr)
if err != nil {
return nil, false, fmt.Errorf("Failed to open MySQL database: %s", err)
Expand Down

0 comments on commit 3066136

Please sign in to comment.