Skip to content

Commit 32025ca

Browse files
chore: addressed comments
1 parent 1430a65 commit 32025ca

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

packages/cmd/pam.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var pamSshAccessCmd = &cobra.Command{
110110
Use: "access",
111111
Short: "Start interactive SSH session to PAM account",
112112
Long: "Start an interactive SSH session to a PAM-managed SSH account. This command automatically launches an SSH client connected through the Infisical Gateway.",
113-
Example: "infisical pam ssh access --resource prod-servers --account root --duration 1h",
113+
Example: "infisical pam ssh access --resource prod-servers --account root --project-id <project-uuid> --duration 1h",
114114
DisableFlagsInUseLine: true,
115115
Args: cobra.NoArgs,
116116
Run: func(cmd *cobra.Command, args []string) {
@@ -124,10 +124,10 @@ var pamSshExecCmd = &cobra.Command{
124124
Long: `Execute a single command on a PAM-managed SSH account and return the output.
125125
This is useful for CI/CD pipelines and scripting where interactive sessions are not needed.`,
126126
Example: ` # Run a command and get output
127-
infisical pam ssh exec "ls -la /var/log" --resource prod-servers --account root
127+
infisical pam ssh exec "ls -la /var/log" --resource prod-servers --account root --project-id <project-uuid>
128128
129129
# Use in a script
130-
OUTPUT=$(infisical pam ssh exec "cat /etc/hostname" --resource prod-servers --account root)`,
130+
OUTPUT=$(infisical pam ssh exec "cat /etc/hostname" --resource prod-servers --account root --project-id <project-uuid>)`,
131131
DisableFlagsInUseLine: true,
132132
Args: cobra.ExactArgs(1),
133133
Run: func(cmd *cobra.Command, args []string) {
@@ -144,7 +144,7 @@ var pamSshProxyCmd = &cobra.Command{
144144
This is useful for file transfers using SCP, SFTP, rsync, or other SSH-based tools.
145145
The proxy prints connection details and waits until terminated with Ctrl+C.`,
146146
Example: ` # Start the proxy
147-
infisical pam ssh proxy --resource prod-servers --account root
147+
infisical pam ssh proxy --resource prod-servers --account root --project-id <project-uuid>
148148
149149
# Then in another terminal, use SCP:
150150
scp -P <port> -o StrictHostKeyChecking=no local-file.txt root@127.0.0.1:/remote/path/

packages/pam/local/ssh-proxy.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type SSHProxyServer struct {
2525
port int
2626
sshProcess *exec.Cmd
2727
options SSHAccessOptions
28+
sshExitCode int // Exit code from SSH process (for exec mode)
2829
}
2930

3031
// SSHAccessOptions configures SSH access behavior
@@ -227,11 +228,14 @@ func (p *SSHProxyServer) waitForSSHCompletion() {
227228
err := p.sshProcess.Wait()
228229
if err != nil {
229230
if exitErr, ok := err.(*exec.ExitError); ok {
230-
log.Debug().Msgf("SSH client exited with code: %d", exitErr.ExitCode())
231+
p.sshExitCode = exitErr.ExitCode()
232+
log.Debug().Msgf("SSH client exited with code: %d", p.sshExitCode)
231233
} else {
232234
log.Error().Err(err).Msg("Error waiting for SSH client")
235+
p.sshExitCode = 1
233236
}
234237
} else {
238+
p.sshExitCode = 0
235239
log.Debug().Msg("SSH client exited successfully")
236240
}
237241
}
@@ -264,7 +268,8 @@ func (p *SSHProxyServer) gracefulShutdown() {
264268
p.WaitForConnectionsWithTimeout(10 * time.Second)
265269

266270
log.Debug().Msg("SSH proxy shutdown complete")
267-
os.Exit(0)
271+
272+
os.Exit(p.sshExitCode)
268273
})
269274
}
270275

0 commit comments

Comments
 (0)