Skip to contentSkip to conversation

95ssh-client: attempt to copy UserKnownHostsFile to kdump's initramfs

PATCH In review Tong Li 4 participants 7 messages Nov 25, 2016 – Dec 2, 2016 6 messages not in the archive

lore
Share & tools
lore

Tong Li

author
#0 lore raw

PATCH 1/1 95ssh-client: attempt to copy UserKnownHostsFile to kdump's initramfs

Bug related to this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1360131
Now dracut only attempts to copy GlobalKnownHostsFile while generating kdump's initramfs. This method will cause kdump's failure if users set customized UserKnownHostsFile in /etc/ssh/ssh_config. This patch simply attempts to copy those files too while going through /etc/ssh/ssh_config. Note that we need to make sure ~/foo will be copied as /root/foo in kdump's initramfs.

---
 modules.d/95ssh-client/module-setup.sh | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
modules.d/95ssh-client/module-setup.sh +12 -5
index 0a0e80c..bebcae5 100755
@@ -45,11 +45,18 @@ inst_sshenv()
         inst_simple /etc/ssh/ssh_config
         sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/' ${initdir}/etc/ssh/ssh_config
         while read key val || [ -n "$key" ]; do
-            [[ $key != "GlobalKnownHostsFile" ]] && continue
-            inst_simple "$val"
-            break
-        done < /etc/ssh/ssh_config
-    fi
+            if [ $key != "GlobalKnownHostsFile" ]; then
+                inst_simple "$val"
+            # Copy customized UserKnowHostsFile
+            elif [ $key != "UserKnownHostsFile" ]; then
+                # Make sure that ~/foo will be copied as /root/foo in kdump's initramfs
+                if str_starts "$val" "~/"; then
+                    val="/root/${val#"~/"}"
+                fi
+                inst_simple "$val"
+            fi
+         done < /etc/ssh/ssh_config
+     fi
 
     return 0
 }
Signature · 1 line
2.7.4

A message that is not in the archive (sent off-list or not yet received): 1480039895-20001-1-git-send-email-tonli-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#3 lore raw
In reply to a message not in the archive
Quoted 17 lines · Tong Li

Bug related to this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1360131
Now dracut only attempts to copy GlobalKnownHostsFile while generating kdump's initramfs. This method will cause kdump's failure if users set customized UserKnownHostsFile in /etc/ssh/ssh_config. This patch simply attempts to copy those files too while going through /etc/ssh/ssh_config. Note that we need to make sure ~/foo will be copied as /root/foo in kdump's initramfs.

---
 modules.d/95ssh-client/module-setup.sh | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
modules.d/95ssh-client/module-setup.sh +0 -0
index 0a0e80c..bebcae5 100755

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 48

Quoted 9 lines
modules.d/95ssh-client/module-setup.sh +1 -5
@@ -45,11 +45,18 @@ inst_sshenv()
         inst_simple /etc/ssh/ssh_config
         sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/' ${initdir}/etc/ssh/ssh_config
         while read key val || [ -n "$key" ]; do
-            [[ $key != "GlobalKnownHostsFile" ]] && continue
-            inst_simple "$val"
-            break
-        done < /etc/ssh/ssh_config
-    fi
+            if [ $key != "GlobalKnownHostsFile" ]; then

Shouldn't it be "$key = "GlobalKnownHostsFile" instead of "!="?

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 51

Quoted 3 lines
modules.d/95ssh-client/module-setup.sh +3 -0
+                inst_simple "$val"
+            # Copy customized UserKnowHostsFile
+            elif [ $key != "UserKnownHostsFile" ]; then

ditto

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 56

Quoted 5 lines
modules.d/95ssh-client/module-setup.sh +5 -0
+                # Make sure that ~/foo will be copied as /root/foo in kdump's initramfs
+                if str_starts "$val" "~/"; then
+                    val="/root/${val#"~/"}"
+                fi
+                inst_simple "$val"

Seems may have "UserKnownHostsFile no", so it will end up with "inst_simple no".

Regards,
Xunlei

Quoted 6 lines
modules.d/95ssh-client/module-setup.sh +3 -0
+            fi
+         done < /etc/ssh/ssh_config
+     fi
 
     return 0
 }

A message that is not in the archive (sent off-list or not yet received): CAOAn1LPhyJ+gG=mAkM3EDZ2FiARG6PxffzKCfDWJigx97Svu1Q@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAOAn1LPhyJ+gG=mAkM3EDZ2FiARG6PxffzKCfDWJigx97Svu1Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw
Quoted 49 lines · Tong Li

Hi,

On Tue, Nov 29, 2016 at 4:40 PM, Xunlei Pang <[email protected] <mailto:[email protected]>> wrote:

    On 2016/11/25 at 10:11, Tong Li wrote:
    > Bug related to this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1360131 <https://bugzilla.redhat.com/show_bug.cgi?id=1360131>
    > Now dracut only attempts to copy GlobalKnownHostsFile while generating kdump's
    > initramfs. This method will cause kdump's failure if users set customized
    > UserKnownHostsFile in /etc/ssh/ssh_config. This patch simply attempts to copy
    > those files too while going through /etc/ssh/ssh_config. Note that we need to
    > make sure ~/foo will be copied as /root/foo in kdump's initramfs.
    >
    > Signed-off-by: Tong Li <[email protected] <mailto:[email protected]>>
    > ---
    >  modules.d/95ssh-client/module-setup.sh | 17 ++++++++++++-----
    >  1 file changed, 12 insertions(+), 5 deletions(-)
    >
    > diff --git a/modules.d/95ssh-client/module-setup.sh b/modules.d/95ssh-client/module-setup.sh
    > index 0a0e80c..bebcae5 100755
    > --- a/modules.d/95ssh-client/module-setup.sh
    > +++ b/modules.d/95ssh-client/module-setup.sh
    > @@ -45,11 +45,18 @@ inst_sshenv()
    >          inst_simple /etc/ssh/ssh_config
    >          sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/' ${initdir}/etc/ssh/ssh_config
    >          while read key val || [ -n "$key" ]; do
    > -            [[ $key != "GlobalKnownHostsFile" ]] && continue
    > -            inst_simple "$val"
    > -            break
    > -        done < /etc/ssh/ssh_config
    > -    fi
    > +            if [ $key != "GlobalKnownHostsFile" ]; then

    Shouldn't it be "$key = "GlobalKnownHostsFile" instead of "!="?

Yes, you are right. That's a mistake made when I send the patch. I will reopen a pull request to correct it.

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 51

Quoted 3 lines
modules.d/95ssh-client/module-setup.sh +3 -0
+                inst_simple "$val"
+            # Copy customized UserKnowHostsFile
+            elif [ $key != "UserKnownHostsFile" ]; then

ditto

> + # Make sure that ~/foo will be copied as /root/foo in kdump's initramfs
> + if str_starts "$val" "~/"; then
> + val="/root/${val#"~/"}"
> + fi
> + inst_simple "$val"

Quoted 3 lines

Seems may have "UserKnownHostsFile no", so it will end up with "inst_simple no".

According to posts I found, it's more common to set UserKnownHostsFile as /dev/null to disable key checking. Is "UserKnownHostsFile no" a correct usage?

I am not sure, but "UserKnownHostsFile /dev/null" sounds more reasonable :-)

Quoted 18 lines

Regards,
Xunlei

> + fi
> + done < /etc/ssh/ssh_config
> + fi
>
> return 0
> }

Regards,

Signature · 1 line
Tong

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw
Quoted 36 lines · Xunlei Pang
Quoted 17 lines · Tong Li

Bug related to this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1360131
Now dracut only attempts to copy GlobalKnownHostsFile while generating kdump's initramfs. This method will cause kdump's failure if users set customized UserKnownHostsFile in /etc/ssh/ssh_config. This patch simply attempts to copy those files too while going through /etc/ssh/ssh_config. Note that we need to make sure ~/foo will be copied as /root/foo in kdump's initramfs.

---
 modules.d/95ssh-client/module-setup.sh | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
modules.d/95ssh-client/module-setup.sh +0 -0
index 0a0e80c..bebcae5 100755

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 48

Quoted 9 lines
modules.d/95ssh-client/module-setup.sh +1 -5
@@ -45,11 +45,18 @@ inst_sshenv()
         inst_simple /etc/ssh/ssh_config
         sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/' ${initdir}/etc/ssh/ssh_config
         while read key val || [ -n "$key" ]; do
-            [[ $key != "GlobalKnownHostsFile" ]] && continue
-            inst_simple "$val"
-            break
-        done < /etc/ssh/ssh_config
-    fi
+            if [ $key != "GlobalKnownHostsFile" ]; then

Shouldn't it be "$key = "GlobalKnownHostsFile" instead of "!="?

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 51

Quoted 3 lines
modules.d/95ssh-client/module-setup.sh +3 -0
+                inst_simple "$val"
+            # Copy customized UserKnowHostsFile
+            elif [ $key != "UserKnownHostsFile" ]; then

ditto

Quoted 7 lines

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 56

Quoted 5 lines
modules.d/95ssh-client/module-setup.sh +5 -0
+                # Make sure that ~/foo will be copied as /root/foo in kdump's initramfs
+                if str_starts "$val" "~/"; then
+                    val="/root/${val#"~/"}"
+                fi
+                inst_simple "$val"

Seems may have "UserKnownHostsFile no", so it will end up with "inst_simple no".

If one use "no" as the filename, we should install it. We do not need to guess the wrong configuration..

Quoted 15 lines

Regards,
Xunlei

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 62

Quoted 6 lines
modules.d/95ssh-client/module-setup.sh +3 -0
+            fi
+         done < /etc/ssh/ssh_config
+     fi
 
     return 0
 }

--
To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw
In reply to a message not in the archive
Quoted 22 lines · Tong Li

Bug related to this issue: https://bugzilla.redhat.com/show_bug.cgi?id=1360131
Now dracut only attempts to copy GlobalKnownHostsFile while generating kdump's initramfs. This method will cause kdump's failure if users set customized UserKnownHostsFile in /etc/ssh/ssh_config. This patch simply attempts to copy those files too while going through /etc/ssh/ssh_config. Note that we need to make sure ~/foo will be copied as /root/foo in kdump's initramfs.

---
 modules.d/95ssh-client/module-setup.sh | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
modules.d/95ssh-client/module-setup.sh +0 -2
index 0a0e80c..bebcae5 100755
@@ -45,11 +45,18 @@ inst_sshenv()
         inst_simple /etc/ssh/ssh_config
         sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/' ${initdir}/etc/ssh/ssh_config
         while read key val || [ -n "$key" ]; do
-            [[ $key != "GlobalKnownHostsFile" ]] && continue
-            inst_simple "$val"

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 54

Quoted 10 lines
modules.d/95ssh-client/module-setup.sh +7 -3
-            break
-        done < /etc/ssh/ssh_config
-    fi
+            if [ $key != "GlobalKnownHostsFile" ]; then
+                inst_simple "$val"
+            # Copy customized UserKnowHostsFile
+            elif [ $key != "UserKnownHostsFile" ]; then
+                # Make sure that ~/foo will be copied as /root/foo in kdump's initramfs
+                if str_starts "$val" "~/"; then
+                    val="/root/${val#"~/"}"

This should be handled by inst_* automaticlly, really should not be here.

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 57

Quoted 3 lines
modules.d/95ssh-client/module-setup.sh +3 -0
+                fi
+                inst_simple "$val"
+            fi

The if/else means we install either Global or User knownhostsfile. Actually both of them can coexist, should install them all if exist.

Quoted 12 lines
modules.d/95ssh-client/module-setup.sh +2 -0
+         done < /etc/ssh/ssh_config
+     fi
 
     return 0
 }
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe initramfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): CAOAn1LMB9i3Sz-1Npgw0cVm1i-n6U0pymathNftMVu89RNt6JA@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAOAn1LMB9i3Sz-1Npgw0cVm1i-n6U0pymathNftMVu89RNt6JA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#12 lore raw
Quoted 57 lines · Tong Li

Hi,

Quoted 45 lines · Dave Young
Quoted 1 line · Tong Li

Bug related to this issue: https://bugzilla.redhat.com/

show_bug.cgi?id=1360131

Quoted 1 line

Now dracut only attempts to copy GlobalKnownHostsFile while generating

kdump's

Quoted 2 lines

initramfs. This method will cause kdump's failure if users set customized UserKnownHostsFile in /etc/ssh/ssh_config. This patch simply attempts to

copy

Quoted 1 line

those files too while going through /etc/ssh/ssh_config. Note that we

need to

Review

Quoted 8 lines

make sure ~/foo will be copied as /root/foo in kdump's initramfs.

---
 modules.d/95ssh-client/module-setup.sh | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
(quoted diff) +0 -0

b/modules.d/95ssh-client/module-setup.sh

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 46

Quoted 6 lines

index 0a0e80c..bebcae5 100755

modules.d/95ssh-client/module-setup.sh +0 -0
@@ -45,11 +45,18 @@ inst_sshenv()
         inst_simple /etc/ssh/ssh_config
         sed -i -e 's/\(^[[:space:]]*\)ProxyCommand/\1# ProxyCommand/'

${initdir}/etc/ssh/ssh_config

modules.d/95ssh-client/module-setup.sh inst_sshenv()

Quoted 11 lines
modules.d/95ssh-client/module-setup.sh +5 -5
         while read key val || [ -n "$key" ]; do
-            [[ $key != "GlobalKnownHostsFile" ]] && continue
-            inst_simple "$val"
-            break
-        done < /etc/ssh/ssh_config
-    fi
+            if [ $key != "GlobalKnownHostsFile" ]; then
+                inst_simple "$val"
+            # Copy customized UserKnowHostsFile
+            elif [ $key != "UserKnownHostsFile" ]; then
+                # Make sure that ~/foo will be copied as /root/foo in

kdump's initramfs

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 54

Quoted 2 lines
modules.d/95ssh-client/module-setup.sh +2 -0
+                if str_starts "$val" "~/"; then
+                    val="/root/${val#"~/"}"

This should be handled by inst_* automaticlly, really should not be here.

Quoted 7 lines

modules.d/95ssh-client/module-setup.sh inst_sshenv() · line 57

Quoted 3 lines
modules.d/95ssh-client/module-setup.sh +3 -0
+                fi
+                inst_simple "$val"
+            fi

The if/else means we install either Global or User knownhostsfile. Actually both of them can coexist, should install them all if exist.

Quoted 6 lines

Both Global and User will be copied, just User may need a little tweak, which is replacing "~" with ${HOME}. I think inst_simple is designed to accept one or two absolute paths as arguments (didn't find comments in code to prove that, just according to my tests). So we should handle the "~" issue inside ssh-client module.

dracut_install supports relative path, so maybe inst_simple should do it as well. If so just add if !globalknownhost or !userknownhost; then continue the loop, otherwise inst the file of "$val" will be enough.

Quoted 21 lines
Quoted 15 lines
Quoted 14 lines
modules.d/95ssh-client/module-setup.sh +2 -1
+         done < /etc/ssh/ssh_config
+     fi
 
     return 0
 }
--

2.7.4

--
To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 2 lines
Regards,
Tong