@@ -22,6 +22,7 @@ import (
22
22
"github.com/docker/docker/api/types/network"
23
23
"github.com/docker/docker/client"
24
24
"github.com/pkg/errors"
25
+ "github.com/sethvargo/go-password/password"
25
26
26
27
dblabCfg "gitlab.com/postgres-ai/database-lab/pkg/config"
27
28
"gitlab.com/postgres-ai/database-lab/pkg/log"
@@ -245,8 +246,13 @@ func (r *RestoreJob) startContainer(ctx context.Context, containerName string) (
245
246
return "" , errors .Wrap (err , "failed to build container host config" )
246
247
}
247
248
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
+
248
254
syncInstance , err := r .dockerClient .ContainerCreate (ctx ,
249
- r .buildContainerConfig (),
255
+ r .buildContainerConfig (pwd ),
250
256
hostConfig ,
251
257
& network.NetworkingConfig {},
252
258
containerName ,
@@ -345,9 +351,9 @@ func (r *RestoreJob) runSyncInstance(ctx context.Context) error {
345
351
return nil
346
352
}
347
353
348
- func (r * RestoreJob ) getEnvironmentVariables () []string {
354
+ func (r * RestoreJob ) getEnvironmentVariables (password string ) []string {
349
355
envVariables := append ([]string {
350
- "POSTGRES_HOST_AUTH_METHOD=trust" ,
356
+ "POSTGRES_PASSWORD=" + password ,
351
357
"PGDATA=" + r .globalCfg .DataDir ,
352
358
}, r .restorer .GetEnvVariables ()... )
353
359
@@ -358,10 +364,10 @@ func (r *RestoreJob) getEnvironmentVariables() []string {
358
364
return envVariables
359
365
}
360
366
361
- func (r * RestoreJob ) buildContainerConfig () * container.Config {
367
+ func (r * RestoreJob ) buildContainerConfig (password string ) * container.Config {
362
368
return & container.Config {
363
369
Labels : map [string ]string {"label" : tools .DBLabControlLabel },
364
- Env : r .getEnvironmentVariables (),
370
+ Env : r .getEnvironmentVariables (password ),
365
371
Image : r .DockerImage ,
366
372
}
367
373
}
0 commit comments