Skip to content

Commit

Permalink
Set child process as 'foreground' in interactive mode to correctly bi…
Browse files Browse the repository at this point in the history
…nd stdin

Configure user in Dockerfile
  • Loading branch information
razvan-agape committed Apr 26, 2024
1 parent 4f20265 commit e858599
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ FROM busybox:1.36
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# copy the binary to the production image from the builder stage.
COPY --from=builder /go/src/app/.bin/secrets-init /secrets-init
RUN adduser -D -u 1000 secrets-init
USER 1000

ENTRYPOINT ["/secrets-init"]
CMD ["--version"]
9 changes: 6 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,16 @@ func run(ctx context.Context, provider secrets.Provider, exitEarly, interactive
cmd := exec.Command(commandStr, argsSlice...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// create a dedicated pidgroup used to forward signals to the main process and its children
procAttrs := &syscall.SysProcAttr{Setpgid: true}
// rebind stdin if -i flag is set
if interactive {
cmd.Stdin = os.Stdin
} else {
// create a dedicated pidgroup used to forward signals to the main process and its children
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
// setting 'Foreground' to true will bind current TTY to the child process
procAttrs = &syscall.SysProcAttr{Setpgid: true, Foreground: true}
}
// set child process attributes
cmd.SysProcAttr = procAttrs

// set environment variables
if provider != nil {
Expand Down

0 comments on commit e858599

Please sign in to comment.