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 (
1616 "go.podman.io/common/pkg/completion"
1717 "go.podman.io/common/pkg/config"
1818 "go.podman.io/common/pkg/ssh"
19+ "go.podman.io/storage/pkg/fileutils"
1920)
2021
2122var (
@@ -141,6 +142,14 @@ func add(cmd *cobra.Command, args []string) error {
141142
142143 switch uri .Scheme {
143144 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+ }
144153 return ssh .Create (entities , sshMode )
145154 case "unix" :
146155 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" \
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 -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+
91116# Test tcp socket; requires starting a local server
92117@test " podman system connection - tcp" {
93118 # Start server
You can’t perform that action at this time.
0 commit comments