Skip to content

fix(cmd): prevent adding connection with invalid identities file #26042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/podman/system/connection/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ func add(cmd *cobra.Command, args []string) error {

switch uri.Scheme {
case "ssh":
// ensure the Identity provided is a valid file
if cmd.Flags().Changed("identity") {
info, err := os.Stat(entities.Identity)
switch {
case err != nil:
return err
case info.IsDir():
return fmt.Errorf("%q is a directory", entities.Identity)
}
}
return ssh.Create(entities, sshMode)
case "unix":
if cmd.Flags().Changed("identity") {
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/system_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ var _ = Describe("podman system connection", func() {
BeforeEach(setupConnectionsConf)

Context("without running API service", func() {
It("adding ssh connection with non-existing identity", func() {
identity := "~/foo/bar.txt"
cmd := []string{"system", "connection", "add",
"--default",
"--identity", identity,
"QA",
"ssh://[email protected]:2222/run/podman/podman.sock",
}
session := podmanTest.Podman(cmd)
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitWithError(125, fmt.Sprintf("Error: stat %s: no such file or directory", identity)))
})

It("add ssh://", func() {
cmd := []string{"system", "connection", "add",
"--default",
Expand Down