Skip to content

Commit

Permalink
FEATURE/MEDIUM: userList: generate random secure password (#47)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amelhusic authored May 11, 2020
1 parent 4d39796 commit f8963ae
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion haproxy/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package haproxy

import (
"crypto/rand"
"encoding/base64"
"io/ioutil"
"os"
"path"
Expand All @@ -14,9 +16,10 @@ import (

const (
dataplaneUser = "haproxy"
dataplanePass = "pass"
)

var dataplanePass string

var baseCfgTmpl = `
global
master-worker
Expand Down Expand Up @@ -105,6 +108,8 @@ func newHaConfig(baseDir string, sd *lib.Shutdown) (*haConfig, error) {
}
defer cfgFile.Close()

dataplanePass = createRandomString()

err = tmpl.Execute(cfgFile, baseParams{
NbThread: runtime.GOMAXPROCS(0),
SocketPath: cfg.StatsSock,
Expand All @@ -131,3 +136,9 @@ func newHaConfig(baseDir string, sd *lib.Shutdown) (*haConfig, error) {

return cfg, nil
}

func createRandomString() string {
randBytes := make([]byte, 32)
_, _ = rand.Read(randBytes)
return base64.URLEncoding.EncodeToString(randBytes)
}

0 comments on commit f8963ae

Please sign in to comment.