Commit 681c2050 authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Allow runner to execute builds as different user

parent 0787543c
......@@ -29,6 +29,7 @@ type MultiRunner struct {
config *common.Config
configFile string
workingDirectory string
user string
builds []*common.Build
buildsLock sync.RWMutex
healthy map[string]*RunnerHealth
......@@ -228,6 +229,11 @@ func (mr *MultiRunner) loadConfig() error {
return err
}
// pass user to execute scripts as specific user
if mr.user != "" {
newConfig.User = &mr.user
}
mr.healthy = nil
mr.config = newConfig
return nil
......@@ -379,6 +385,7 @@ func CreateService(c *cli.Context) service.Service {
mr := &MultiRunner{
configFile: c.String("config"),
workingDirectory: c.String("working-directory"),
user: c.String("user"),
}
s, err := service.New(mr, svcConfig)
......
......@@ -60,6 +60,7 @@ type RunnerConfig struct {
type BaseConfig struct {
Concurrent int `toml:"concurrent" json:"concurrent"`
User *string `toml:"user" json:"user"`
Runners []*RunnerConfig `toml:"runners" json:"runners"`
}
......
......@@ -51,6 +51,7 @@ type ShellScriptInfo struct {
Shell string
Build *Build
Type ShellType
User *string
}
type Shell interface {
......
......@@ -20,6 +20,10 @@ type ShellExecutor struct {
}
func (s *ShellExecutor) Prepare(globalConfig *common.Config, config *common.RunnerConfig, build *common.Build) error {
if globalConfig != nil {
s.Shell.User = globalConfig.User
}
err := s.AbstractExecutor.Prepare(globalConfig, config, build)
if err != nil {
return err
......
......@@ -95,11 +95,21 @@ func (b *BashShell) GenerateScript(info common.ShellScriptInfo) (*common.ShellSc
script := common.ShellScript{
Environment: b.GetVariables(build, projectDir),
Script: buffer.String(),
Command: "bash",
}
if info.Type == common.LoginShell {
script.Arguments = []string{"--login"}
// su
if info.User != nil {
script.Command = "su"
if info.Type == common.LoginShell {
script.Arguments = []string{"--shell", "/bin/bash", "--login", *info.User}
} else {
script.Arguments = []string{"--shell", "/bin/bash", *info.User}
}
} else {
script.Command = "bash"
if info.Type == common.LoginShell {
script.Arguments = []string{"--login"}
}
}
return &script, nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment