Skip to content

Commit 3755d3d

Browse files
committed
fix(cmd): prevent adding connection with invalid identities file
Signed-off-by: axel7083 <[email protected]>
1 parent 06b6842 commit 3755d3d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cmd/podman/system/connection/add.go

+8
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,14 @@ func add(cmd *cobra.Command, args []string) error {
141141

142142
switch uri.Scheme {
143143
case "ssh":
144+
// ensure the Identity provided is a valid file
145+
info, err := os.Stat(entities.Identity)
146+
switch {
147+
case err != nil:
148+
return err
149+
case info.IsDir():
150+
return fmt.Errorf("%q is a directory", entities.Identity)
151+
}
144152
return ssh.Create(entities, sshMode)
145153
case "unix":
146154
if cmd.Flags().Changed("identity") {

test/e2e/system_connection_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ var _ = Describe("podman system connection", func() {
4545
BeforeEach(setupConnectionsConf)
4646

4747
Context("without running API service", func() {
48+
It("adding ssh connection with non-existing identity", func() {
49+
identity := "~/foo/bar.txt"
50+
cmd := []string{"system", "connection", "add",
51+
"--default",
52+
"--identity", identity,
53+
"QA",
54+
"ssh://[email protected]:2222/run/podman/podman.sock",
55+
}
56+
session := podmanTest.Podman(cmd)
57+
session.WaitWithDefaultTimeout()
58+
Expect(session).Should(ExitWithError(125, fmt.Sprintf("Error: stat %s: no such file or directory", identity)))
59+
})
60+
4861
It("add ssh://", func() {
4962
cmd := []string{"system", "connection", "add",
5063
"--default",

0 commit comments

Comments
 (0)