Skip to content

Commit

Permalink
FEATURE/MEDIUM: userList: generate random secure password
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 committed May 7, 2020
1 parent faede19 commit c9cfd4f
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 c9cfd4f

Please sign in to comment.