Skip to content

Commit 73eaa84

Browse files
authored
Merge pull request #44 from razvan-agape/feat/interactive-terminal-session
Interactive mode in interpreter sessions
2 parents fbd5a1e + e858599 commit 73eaa84

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ FROM busybox:1.36
2626
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2727
# copy the binary to the production image from the builder stage.
2828
COPY --from=builder /go/src/app/.bin/secrets-init /secrets-init
29+
RUN adduser -D -u 1000 secrets-init
30+
USER 1000
31+
2932
ENTRYPOINT ["/secrets-init"]
3033
CMD ["--version"]

main.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func main() {
5858
Name: "google-project",
5959
Usage: "the google cloud project for secrets without a project prefix",
6060
},
61+
&cli.BoolFlag{
62+
Name: "interactive",
63+
Aliases: []string{"i"},
64+
Usage: "use this flag if the command expects some input from the stdin",
65+
},
6166
},
6267
Commands: []*cli.Command{
6368
{
@@ -149,7 +154,7 @@ func mainCmd(c *cli.Context) error {
149154

150155
// Launch main command
151156
var childPid int
152-
childPid, err = run(ctx, provider, c.Bool("exit-early"), c.Args().Slice())
157+
childPid, err = run(ctx, provider, c.Bool("exit-early"), c.Bool("interactive"), c.Args().Slice())
153158
if err != nil {
154159
log.WithError(err).Error("failed to run")
155160
os.Exit(1)
@@ -188,7 +193,7 @@ func removeZombies(childPid int) {
188193
}
189194

190195
// run passed command
191-
func run(ctx context.Context, provider secrets.Provider, exitEarly bool, commandSlice []string) (childPid int, err error) {
196+
func run(ctx context.Context, provider secrets.Provider, exitEarly, interactive bool, commandSlice []string) (childPid int, err error) {
192197
var commandStr string
193198
var argsSlice []string
194199

@@ -213,7 +218,15 @@ func run(ctx context.Context, provider secrets.Provider, exitEarly bool, command
213218
cmd.Stdout = os.Stdout
214219
cmd.Stderr = os.Stderr
215220
// create a dedicated pidgroup used to forward signals to the main process and its children
216-
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
221+
procAttrs := &syscall.SysProcAttr{Setpgid: true}
222+
// rebind stdin if -i flag is set
223+
if interactive {
224+
cmd.Stdin = os.Stdin
225+
// setting 'Foreground' to true will bind current TTY to the child process
226+
procAttrs = &syscall.SysProcAttr{Setpgid: true, Foreground: true}
227+
}
228+
// set child process attributes
229+
cmd.SysProcAttr = procAttrs
217230

218231
// set environment variables
219232
if provider != nil {

0 commit comments

Comments
 (0)