Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive mode in interpreter sessions #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
19 changes: 16 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func main() {
Name: "google-project",
Usage: "the google cloud project for secrets without a project prefix",
},
&cli.BoolFlag{
Name: "interactive",
Aliases: []string{"i"},
Usage: "use this flag if the command expects some input from the stdin",
},
},
Commands: []*cli.Command{
{
Expand Down Expand Up @@ -149,7 +154,7 @@ func mainCmd(c *cli.Context) error {

// Launch main command
var childPid int
childPid, err = run(ctx, provider, c.Bool("exit-early"), c.Args().Slice())
childPid, err = run(ctx, provider, c.Bool("exit-early"), c.Bool("interactive"), c.Args().Slice())
if err != nil {
log.WithError(err).Error("failed to run")
os.Exit(1)
Expand Down Expand Up @@ -188,7 +193,7 @@ func removeZombies(childPid int) {
}

// run passed command
func run(ctx context.Context, provider secrets.Provider, exitEarly bool, commandSlice []string) (childPid int, err error) {
func run(ctx context.Context, provider secrets.Provider, exitEarly, interactive bool, commandSlice []string) (childPid int, err error) {
var commandStr string
var argsSlice []string

Expand All @@ -213,7 +218,15 @@ func run(ctx context.Context, provider secrets.Provider, exitEarly bool, command
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// create a dedicated pidgroup used to forward signals to the main process and its children
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
procAttrs := &syscall.SysProcAttr{Setpgid: true}
// rebind stdin if -i flag is set
if interactive {
cmd.Stdin = os.Stdin
// 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
Loading