Skip to content

Commit 0e3a296

Browse files
committed
MINOR: added comand line options to set uid and gid
1 parent 1da3dfd commit 0e3a296

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

cmd/dataplaneapi/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"os"
2121
"path"
22+
"syscall"
2223

2324
loads "github.com/go-openapi/loads"
2425
"github.com/go-openapi/runtime"
@@ -119,6 +120,19 @@ func startServer(cfg *configuration.Configuration) (reload configuration.AtomicB
119120
if err != nil {
120121
log.Fatalln(err)
121122
}
123+
124+
if cfg.HAProxy.UID != 0 {
125+
if err = syscall.Setuid(cfg.HAProxy.UID); err != nil {
126+
log.Fatalln("set uid:", err)
127+
}
128+
}
129+
130+
if cfg.HAProxy.GID != 0 {
131+
if err = syscall.Setgid(cfg.HAProxy.GID); err != nil {
132+
log.Fatalln("set gid:", err)
133+
}
134+
}
135+
122136
// incorporate changes from file to global settings
123137
dataplaneapi.SyncWithFileSettings(server, cfg)
124138
err = cfg.LoadRuntimeVars(dataplaneapi.SwaggerJSON, server.Host, server.Port)

configuration/configuration.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ type HAProxyConfiguration struct {
6363
ValidateCmd string `long:"validate-cmd" description:"Executes a custom command to perform the HAProxy configuration check" group:"reload"`
6464
DisableInotify bool `long:"disable-inotify" description:"Disables inotify watcher watcher for the configuration file" group:"dataplaneapi"`
6565
PIDFile string `long:"pid-file" description:"Path to file that will dataplaneapi use to write its pid" group:"dataplaneapi" example:"/tmp/dataplane.pid"`
66+
UID int `long:"uid" description:"User id value to set on start" group:"dataplaneapi"`
67+
GID int `long:"gid" description:"Group id value to set on start" group:"dataplaneapi"`
6668
}
6769

6870
type User struct {

configuration/configuration_generated.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)