File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
cmd/podman/system/connection Expand file tree Collapse file tree 2 files changed +35
-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,32 @@ $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
+ is " $output " " "
95
+
96
+ run_podman system connection add ssh-conn --identity ~ /nonexistent ssh://localhost
97
+ is " $output " \
98
+ " Error: identity file does not exist: faccessat /home/nsella/nonexistent: no such file or directory"
99
+ run_podman system connection add unix-conn --identity ~ /identity unix://path
100
+ is " $output " \
101
+ " Error: --identity option not supported for unix scheme"
102
+ run_podman system connection add tcp-conn --identity ~ /identity tcp://path
103
+ is " $output " \
104
+ " Error: --identity option not supported for unix scheme"
105
+
106
+ run touch ~ /badfile
107
+ run chmod -r ~ /badfile
108
+ run_podman system connection add bad-conn --identity ~ /badfile ssh://localhost
109
+ is " $output " \
110
+ " Error: failed to validate: failed to read identity*"
111
+ run rm ~ /badfile
112
+ # Ensure no connections were added
113
+ run_podman system connection ls -q
114
+ is " $output " " "
115
+ }
116
+
91
117
# Test tcp socket; requires starting a local server
92
118
@test " podman system connection - tcp" {
93
119
# Start server
You can’t perform that action at this time.
0 commit comments