Skip to content

Commit f8963ae

Browse files
authored
FEATURE/MEDIUM: userList: generate random secure password (#47)
This change previously hard coded password usage and instead use generated password. So, on every start up a random password is generated and saved to HAProxy conf.
1 parent 4d39796 commit f8963ae

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

haproxy/config.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package haproxy
22

33
import (
4+
"crypto/rand"
5+
"encoding/base64"
46
"io/ioutil"
57
"os"
68
"path"
@@ -14,9 +16,10 @@ import (
1416

1517
const (
1618
dataplaneUser = "haproxy"
17-
dataplanePass = "pass"
1819
)
1920

21+
var dataplanePass string
22+
2023
var baseCfgTmpl = `
2124
global
2225
master-worker
@@ -105,6 +108,8 @@ func newHaConfig(baseDir string, sd *lib.Shutdown) (*haConfig, error) {
105108
}
106109
defer cfgFile.Close()
107110

111+
dataplanePass = createRandomString()
112+
108113
err = tmpl.Execute(cfgFile, baseParams{
109114
NbThread: runtime.GOMAXPROCS(0),
110115
SocketPath: cfg.StatsSock,
@@ -131,3 +136,9 @@ func newHaConfig(baseDir string, sd *lib.Shutdown) (*haConfig, error) {
131136

132137
return cfg, nil
133138
}
139+
140+
func createRandomString() string {
141+
randBytes := make([]byte, 32)
142+
_, _ = rand.Read(randBytes)
143+
return base64.URLEncoding.EncodeToString(randBytes)
144+
}

0 commit comments

Comments
 (0)