Skip to content

Commit 66cf59b

Browse files
authored
fix: Apply environment variables to startup script (#2099)
This was stopping `coder` from being in the path, and allowed applications started in the script to bypass injected environmnet variables like `GIT_SSH_COMMAND`.
1 parent 1a39931 commit 66cf59b

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

agent/agent.go

+4-16
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,10 @@ func (a *agent) run(ctx context.Context) {
155155
}
156156
}
157157

158-
func (*agent) runStartupScript(ctx context.Context, script string) error {
158+
func (a *agent) runStartupScript(ctx context.Context, script string) error {
159159
if script == "" {
160160
return nil
161161
}
162-
currentUser, err := user.Current()
163-
if err != nil {
164-
return xerrors.Errorf("get current user: %w", err)
165-
}
166-
username := currentUser.Username
167-
168-
shell, err := usershell.Get(username)
169-
if err != nil {
170-
return xerrors.Errorf("get user shell: %w", err)
171-
}
172162

173163
writer, err := os.OpenFile(filepath.Join(os.TempDir(), "coder-startup-script.log"), os.O_CREATE|os.O_RDWR, 0600)
174164
if err != nil {
@@ -178,12 +168,10 @@ func (*agent) runStartupScript(ctx context.Context, script string) error {
178168
_ = writer.Close()
179169
}()
180170

181-
caller := "-c"
182-
if runtime.GOOS == "windows" {
183-
caller = "/c"
171+
cmd, err := a.createCommand(ctx, script, nil)
172+
if err != nil {
173+
return xerrors.Errorf("create command: %w", err)
184174
}
185-
186-
cmd := exec.CommandContext(ctx, shell, caller, script)
187175
cmd.Stdout = writer
188176
cmd.Stderr = writer
189177
err = cmd.Run()

0 commit comments

Comments
 (0)