Skip to content

Commit f06f112

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

File tree

1 file changed

+13
-0
lines changed
  • cmd/podman/system/connection

1 file changed

+13
-0
lines changed

cmd/podman/system/connection/add.go

+13
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,19 @@ 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 errors.Is(err, os.ErrNotExist):
148+
logrus.Warnf("%q does not exist", entities.Identity)
149+
case errors.Is(err, os.ErrPermission):
150+
logrus.Warnf("You do not have permission to read %q", entities.Identity)
151+
case err != nil:
152+
return err
153+
case info.IsDir():
154+
return fmt.Errorf("%q is a directory", entities.Identity)
155+
}
156+
144157
return ssh.Create(entities, sshMode)
145158
case "unix":
146159
if cmd.Flags().Changed("identity") {

0 commit comments

Comments
 (0)