@@ -22,6 +22,7 @@ import (
2222 "github.com/docker/docker/api/types/network"
2323 "github.com/docker/docker/client"
2424 "github.com/pkg/errors"
25+ "github.com/sethvargo/go-password/password"
2526
2627 dblabCfg "gitlab.com/postgres-ai/database-lab/pkg/config"
2728 "gitlab.com/postgres-ai/database-lab/pkg/log"
@@ -245,8 +246,13 @@ func (r *RestoreJob) startContainer(ctx context.Context, containerName string) (
245246 return "" , errors .Wrap (err , "failed to build container host config" )
246247 }
247248
249+ pwd , err := password .Generate (tools .PasswordLength , tools .PasswordMinDigits , tools .PasswordMinSymbols , false , true )
250+ if err != nil {
251+ return "" , errors .Wrap (err , "failed to generate PostgreSQL password" )
252+ }
253+
248254 syncInstance , err := r .dockerClient .ContainerCreate (ctx ,
249- r .buildContainerConfig (),
255+ r .buildContainerConfig (pwd ),
250256 hostConfig ,
251257 & network.NetworkingConfig {},
252258 containerName ,
@@ -345,9 +351,9 @@ func (r *RestoreJob) runSyncInstance(ctx context.Context) error {
345351 return nil
346352}
347353
348- func (r * RestoreJob ) getEnvironmentVariables () []string {
354+ func (r * RestoreJob ) getEnvironmentVariables (password string ) []string {
349355 envVariables := append ([]string {
350- "POSTGRES_HOST_AUTH_METHOD=trust" ,
356+ "POSTGRES_PASSWORD=" + password ,
351357 "PGDATA=" + r .globalCfg .DataDir ,
352358 }, r .restorer .GetEnvVariables ()... )
353359
@@ -358,10 +364,10 @@ func (r *RestoreJob) getEnvironmentVariables() []string {
358364 return envVariables
359365}
360366
361- func (r * RestoreJob ) buildContainerConfig () * container.Config {
367+ func (r * RestoreJob ) buildContainerConfig (password string ) * container.Config {
362368 return & container.Config {
363369 Labels : map [string ]string {"label" : tools .DBLabControlLabel },
364- Env : r .getEnvironmentVariables (),
370+ Env : r .getEnvironmentVariables (password ),
365371 Image : r .DockerImage ,
366372 }
367373}
0 commit comments