fix: don't log admin password via slog (closes #26)
Replace slog.Info (which outputs structured JSON in prod and ends up in log aggregation) with a plain fmt.Fprintf to stderr. The password is printed once on first startup in a clearly-delimited banner that won't be parsed as a structured log field.
This commit is contained in:
@@ -3,7 +3,9 @@ package database
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
|
"os"
|
||||||
|
|
||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
"gorm.io/driver/sqlite"
|
"gorm.io/driver/sqlite"
|
||||||
@@ -118,11 +120,18 @@ func (d *Database) migrate() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the password - this will only happen once on first startup
|
// Print the password directly to stderr so it never ends up in
|
||||||
d.log.Info("admin user created",
|
// structured JSON log aggregation. This message is only shown
|
||||||
"username", "admin",
|
// once on first startup.
|
||||||
"password", password,
|
fmt.Fprintf(os.Stderr, "\n"+
|
||||||
"message", "SAVE THIS PASSWORD - it will not be shown again!")
|
"==========================================================\n"+
|
||||||
|
" ADMIN USER CREATED\n"+
|
||||||
|
" Username: admin\n"+
|
||||||
|
" Password: %s\n"+
|
||||||
|
" SAVE THIS PASSWORD — it will not be shown again!\n"+
|
||||||
|
"==========================================================\n\n",
|
||||||
|
password,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
Reference in New Issue
Block a user