Skip to content

Commit 1500121

Browse files
committed
Stat Identity file on sys con add
Fixes: #26016 Signed-off-by: Nicola Sella <[email protected]>
1 parent 277530e commit 1500121

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

cmd/podman/system/connection/add.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ func add(cmd *cobra.Command, args []string) error {
141141

142142
switch uri.Scheme {
143143
case "ssh":
144+
if cOpts.Identity != "" {
145+
if _, err := os.Stat(cOpts.Identity); errors.Is(err, os.ErrNotExist) {
146+
return fmt.Errorf("identity file does not exist: %s", cOpts.Identity)
147+
}
148+
}
144149
return ssh.Create(entities, sshMode)
145150
case "unix":
146151
if cmd.Flags().Changed("identity") {

test/system/272-system-connection.bats

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ $c2[ ]\+tcp://localhost:54321[ ]\+true[ ]\+true" \
8888
run_podman context rm $c1
8989
}
9090

91+
# Test system connection add bad identities with ssh/unix/tcp
92+
@test "podman system connection --identity" {
93+
run_podman system connection ls
94+
is "$output" "Name URI Identity Default ReadWrite" \
95+
"system connection ls: no connections"
96+
97+
run_podman system connection add ssh-conn --identity ~/nonexistent ssh://localhost
98+
is "$output" \
99+
"Error: idendity file does not exist: ~/nonexistent"
100+
run_podman system connection add unix-conn --identity ~/identity unix://path
101+
is "$output"\
102+
"Error: --identity option not supported for unix scheme"
103+
run_podman system connection add tcp-conn --identity ~/identity tcp://path
104+
is "$output"\
105+
"Error: --identity option not supported for unix scheme"
106+
107+
# Ensure no connections were added
108+
run_podman system connection ls
109+
is "$output" "Name URI Identity Default ReadWrite" \
110+
"system connection ls: no connections"
111+
}
112+
91113
# Test tcp socket; requires starting a local server
92114
@test "podman system connection - tcp" {
93115
# Start server

0 commit comments

Comments
 (0)