File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
cmd/podman/system/connection Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import (
16
16
"go.podman.io/common/pkg/completion"
17
17
"go.podman.io/common/pkg/config"
18
18
"go.podman.io/common/pkg/ssh"
19
+ "go.podman.io/storage/pkg/fileutils"
19
20
)
20
21
21
22
var (
@@ -141,6 +142,14 @@ func add(cmd *cobra.Command, args []string) error {
141
142
142
143
switch uri .Scheme {
143
144
case "ssh" :
145
+ if cOpts .Identity != "" {
146
+ if err := fileutils .Exists (cOpts .Identity ); err != nil {
147
+ if errors .Is (err , os .ErrNotExist ) {
148
+ return fmt .Errorf ("identity file does not exist: %w" , err )
149
+ }
150
+ return err
151
+ }
152
+ }
144
153
return ssh .Create (entities , sshMode )
145
154
case "unix" :
146
155
if cmd .Flags ().Changed ("identity" ) {
Original file line number Diff line number Diff line change @@ -88,6 +88,31 @@ $c2[ ]\+tcp://localhost:54321[ ]\+true[ ]\+true" \
88
88
run_podman context rm $c1
89
89
}
90
90
91
+ # Test system connection add bad identities with ssh/unix/tcp
92
+ @test " podman system connection --identity" {
93
+ run_podman system connection ls -q
94
+ assert " $output " == " " " "
95
+
96
+ run_podman 125 system connection add ssh-conn --identity $PODMAN_TMPDIR /nonexistent ssh://localhost
97
+ assert " $output " =~ \
98
+ " Error: failed to validate: failed to read identity *" " "
99
+ run_podman 125 system connection add unix-conn --identity $PODMAN_TMPDIR /identity unix://path
100
+ assert " $output " == \
101
+ " Error: --identity option not supported for unix scheme" " "
102
+ run_podman 125 system connection add tcp-conn --identity $PODMAN_TEMPDIR /identity tcp://path
103
+ assert " $output " =~ \
104
+ " Error: --identity option not supported for tcp scheme" " "
105
+
106
+ run touch $PODMAN_TEMPDIR /badfile
107
+ run chmod -r $PODMAN_TEMPDIR /badfile
108
+ run_podman 125 system connection add bad-conn --identity $PODMAN_TEMPDIR /badfile ssh://localhost
109
+ assert " $output " =~ \
110
+ " Error: failed to validate: failed to read identity*" " "
111
+ # Ensure no connections were added
112
+ run_podman system connection ls -q
113
+ assert " $output " == " " " "
114
+ }
115
+
91
116
# Test tcp socket; requires starting a local server
92
117
@test " podman system connection - tcp" {
93
118
# Start server
You can’t perform that action at this time.
0 commit comments