Unique bug in ceph start script
Hallo,
I think I have found a bug in the ceph-0.56.4 start script concerning the following code section in src/init-ceph.in:
212 if [ "$host" = "$hostname" ]; then
213 cur_conf=$conf
214 else
215 unique=dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'
216 if echo $pushed_to | grep -v -q " $host "; then
217 scp -q $conf $host:/tmp/ceph.conf.$unique 218 trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT 219 pushed_to="$pushed_to $host "
220 fi
221 cur_conf="/tmp/ceph.conf.$unique"
222 fi
223 cmd="$cmd -c $cur_conf"
Explanation:
If there are more than one OSD instances configured for remote host "abc", the ceph configuration with a random file name will be copied to host "abc" and the pushed_to variable will be set.
Next time, if there is another OSD instance for remote host "abc", the pushed_to variable is already set and therefore _no_ new ceph configuration file will be copied to host "abc". That's OK but nevertheless a new random file name will be created in line 215/221 and will be used in line 223. This leads to an error because the new configuration file name is unknown on host "abc".
The appended patch fixes this misbehavior.
With best regards,
Andreas Friedrich
----------------------------------------------------------------------
FUJITSU
Fujitsu Technology Solutions GmbH
Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany
Tel: +49 (5251) 525-1512
Fax: +49 (5251) 525-321512
Email: [email protected]
Web: ts.fujitsu.com
Company details: de.ts.fujitsu.com/imprint
----------------------------------------------------------------------
src/init-ceph.in +1 -1
@@ -212,8 +212,8 @@ if [ "$host" = "$hostname" ]; then cur_conf=$conf else - unique=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'` if echo $pushed_to | grep -v -q " $host "; then + unique=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'` scp -q $conf $host:/tmp/ceph.conf.$unique trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT pushed_to="$pushed_to $host "
Hi Andreas,
Quoted 23 lines · Andreas Friedrich
Hallo,
I think I have found a bug in the ceph-0.56.4 start script concerning the following code section in src/init-ceph.in:
212 if [ "$host" = "$hostname" ]; then
213 cur_conf=$conf
214 else
215 unique=dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'
216 if echo $pushed_to | grep -v -q " $host "; then217 scp -q $conf $host:/tmp/ceph.conf.$unique 218 trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT 219 pushed_to="$pushed_to $host "220 fi
221 cur_conf="/tmp/ceph.conf.$unique"
222 fi
223 cmd="$cmd -c $cur_conf"Explanation:
If there are more than one OSD instances configured for remote host "abc", the ceph configuration with a random file name will be copied to host "abc" and thepushed_tovariable will be set.
Quoted 6 lines
Next time, if there is another OSD instance for remote host "abc", the
pushed_tovariable is already set and therefore _no_ new ceph configuration file will be copied to host "abc". That's OK but nevertheless a new random file name will be created in line 215/221 and will be used in line 223. This leads to an error because the new configuration file name is unknown on host "abc".
Thanks for the report! I think this doesn't quite solve the problem, though. If all the items for a given target are processed in order, then $unique will be correct, but if you get hosta, hostb, hosta then it will be wrong.
The simplist fix is probably to use a single $unique for the lifetime of the script, but this makes the filename predictable to a certain class of resourceful malicious users. Alternatively, we chould only put a single remote target in $pushed_to and re-push the conf to a new temp file if we get the same host again out of order.
sage
On Mo, Apr 22, 2013 at 08:39:03 -0700, Sage Weil wrote:
Hi Sage,
...
Quoted 4 lines
Thanks for the report! I think this doesn't quite solve the problem, though. If all the items for a given target are processed in order, then $unique will be correct, but if you get hosta, hostb, hosta then it will be wrong.
...
sorry, but I don't recognize why it would be wrong:
Applying my patch the code would do the following:
1. hosta:
Create ceph.conf.uniq1, copy it to hosta and use ceph.conf.uniq1.
2. hostb:
Create ceph.conf.uniq2, copy it to hostb and use ceph.conf.uniq2.
3. hosta:
Create ceph.conf.uniq3, copy it to hosta and use ceph.conf.uniq3.
So in this example two config files with different names but the same content would be copied to hosta. This is not very pretty but it should work without error.
Andreas
Quoted 23 lines · Andreas Friedrich
On Mo, Apr 22, 2013 at 08:39:03 -0700, Sage Weil wrote:
Hi Sage,
...
Quoted 4 lines
Thanks for the report! I think this doesn't quite solve the problem, though. If all the items for a given target are processed in order, then $unique will be correct, but if you get hosta, hostb, hosta then it will be wrong.
...
sorry, but I don't recognize why it would be wrong:
Applying my patch the code would do the following:
1. hosta:
Create ceph.conf.uniq1, copy it to hosta and use ceph.conf.uniq1.2. hostb:
Create ceph.conf.uniq2, copy it to hostb and use ceph.conf.uniq2.
Quoted 7 lines
3. hosta:
Create ceph.conf.uniq3, copy it to hosta and use ceph.conf.uniq3.So in this example two config files with different names but the same content would be copied to hosta. This is not very pretty but it should work without error.
It's because of the $pushed_to list.. for #3 it wouldn't re-push ceph.conf. I pushed a patch that just skips that optimization entirely:
https://github.com/ceph/ceph/commit/ccbc4dbc6edf09626459ca52a53a72682f541e86
Look okay to you?
Thanks!
sage
On Di, Apr 23, 2013 at 10:01:53 -0700, Sage Weil wrote:
...
Quoted 10 lines
Quoted 3 lines
So in this example two config files with different names but the same content would be copied to hosta. This is not very pretty but it should work without error.
It's because of the $pushed_to list.. for #3 it wouldn't re-push ceph.conf. I pushed a patch that just skips that optimization entirely:
https://github.com/ceph/ceph/commit/ccbc4dbc6edf09626459ca52a53a72682f541e86
Look okay to you?
Yes, but I'm not happy with the trap instruction:
trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT
If the start script exits with or without error, the remote config file will be removed from <remote-host>:/tmp - but only for the last host (the former trap calls will be overwritten by the last trap call)! This makes no sense to me.
Best regards
Andreas
Quoted 13 lines · Andreas Friedrich
On Di, Apr 23, 2013 at 10:01:53 -0700, Sage Weil wrote:
...Quoted 10 lines
Quoted 3 lines
So in this example two config files with different names but the same content would be copied to hosta. This is not very pretty but it should work without error.
It's because of the $pushed_to list.. for #3 it wouldn't re-push ceph.conf. I pushed a patch that just skips that optimization entirely:
https://github.com/ceph/ceph/commit/ccbc4dbc6edf09626459ca52a53a72682f541e86
Look okay to you?
Quoted 8 lines
Yes, but I'm not happy with the trap instruction:
trap "ssh $host rm
/tmp/ceph.conf.$unique" EXITIf the start script exits with or without error, the remote config file will be removed from <remote-host>:/tmp - but only for the last host (the former trap calls will be overwritten by the last trap call)! This makes no sense to me.
Bah.. I was thinking they would stack. How about
src/init-ceph.in +4 -1
@@ -218,8 +218,11 @@ for name in $what; do else unique=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'` scp -q $conf $host:/tmp/ceph.conf.$unique - trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT cur_conf="/tmp/ceph.conf.$unique" + + # clean up on exit + remote_configs="$host:/tmp/ceph.conf.$unique $remote_configs" + trap 'for f in '$remote_configs' ; do ssh ${f%:*} rm ${f#*:} ; done' EXIT fi cmd="$cmd -c $cur_conf"
??
On Mi, Apr 24, 2013 at 11:04:56 -0700, Sage Weil wrote:
Hello Sage,
...
Quoted 13 lines
Quoted 4 lines
If the start script exits with or without error, the remote config file will be removed from <remote-host>:/tmp - but only for the last host (the former trap calls will be overwritten by the last trap call)! This makes no sense to me.
Bah.. I was thinking they would stack. How about
src/init-ceph.in +0
-0@@ -218,8 +218,11 @@ for name in $what; do else
src/init-ceph.in for name in $what; do · line 227
Quoted 10 lines
src/init-ceph.in +4
-1unique=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'` scp -q $conf $host:/tmp/ceph.conf.$unique - trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT cur_conf="/tmp/ceph.conf.$unique" + + # clean up on exit + remote_configs="$host:/tmp/ceph.conf.$unique $remote_configs" + trap 'for f in '$remote_configs' ; do ssh ${f%:*} rm ${f#*:} ; done' EXIT fi cmd="$cmd -c $cur_conf"
yes, this looks fine but I have a question:
I don't know the background for copying the config files to <remote-host>:/tmp. Why don't use all the daemons their local config /etc/ceph/ceph.conf?
May be you want to ensure that the remote daemons will use the same config as exists on the host from which the cluster was started. But if the configs on the remote hosts differ from the config of the "cluster-start-host", then we still might have a problem when a remote host is booting: In this case '/etc/init.d/ceph start' is called and the remote host will use its local (different) config.
I think a clear strategy would be:
- All daemons always use their local config (no copying to /tmp).
- If a cluster-start is initiated (/etc/init.d/ceph -a start) the script first checks if the configs on all cluster hosts are equal (maybe we need a content check here - not a literal check).
- If the configs are not equal, the cluster-start command aborts with an error message.
What do you think about that?
Best regards
Andreas
Quoted 50 lines · Andreas Friedrich
On Mi, Apr 24, 2013 at 11:04:56 -0700, Sage Weil wrote:
Hello Sage,
...
Quoted 13 lines
Quoted 4 lines
If the start script exits with or without error, the remote config file will be removed from <remote-host>:/tmp - but only for the last host (the former trap calls will be overwritten by the last trap call)! This makes no sense to me.
Bah.. I was thinking they would stack. How about
src/init-ceph.in +0
-0@@ -218,8 +218,11 @@ for name in $what; do elsesrc/init-ceph.in for name in $what; do · line 227
Quoted 10 lines
src/init-ceph.in +4
-1unique=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'` scp -q $conf $host:/tmp/ceph.conf.$unique - trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT cur_conf="/tmp/ceph.conf.$unique" + + # clean up on exit + remote_configs="$host:/tmp/ceph.conf.$unique $remote_configs" + trap 'for f in '$remote_configs' ; do ssh ${f%:*} rm ${f#*:} ; done' EXIT fi cmd="$cmd -c $cur_conf"yes, this looks fine but I have a question:
I don't know the background for copying the config files to <remote-host>:/tmp. Why don't use all the daemons their local config
/etc/ceph/ceph.conf?May be you want to ensure that the remote daemons will use the same config as exists on the host from which the cluster was started. But if the configs on the remote hosts differ from the config of the "cluster-start-host", then we still might have a problem when a remote host is booting: In this case '
/etc/init.d/cephstart' is called and the remote host will use its local (different) config.I think a clear strategy would be:
- All daemons always use their local config (no copying to /tmp).
- If a cluster-start is initiated (/etc/init.d/ceph-a start) the script first checks if the configs on all cluster hosts are equal (maybe we need a content check here - not a literal check).
- If the configs are not equal, the cluster-start command aborts with an error message.
Quoted 1 line
What do you think about that?
That makes a lot more sense, although I would suggest a warning instead of an error. For cuttlefish, I'm hesitant to change behavior in the 11th hour, but we should make this change going forward.
Care to send a patch? :)
sage
Quoted 51 lines · Sage Weil
Quoted 50 lines · Andreas Friedrich
On Mi, Apr 24, 2013 at 11:04:56 -0700, Sage Weil wrote:
Hello Sage,
...
Quoted 13 lines
Quoted 4 lines
If the start script exits with or without error, the remote config file will be removed from <remote-host>:/tmp - but only for the last host (the former trap calls will be overwritten by the last trap call)! This makes no sense to me.
Bah.. I was thinking they would stack. How about
src/init-ceph.in +0
-0@@ -218,8 +218,11 @@ for name in $what; do elsesrc/init-ceph.in for name in $what; do · line 227
Quoted 10 lines
src/init-ceph.in +4
-1unique=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'` scp -q $conf $host:/tmp/ceph.conf.$unique - trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT cur_conf="/tmp/ceph.conf.$unique" + + # clean up on exit + remote_configs="$host:/tmp/ceph.conf.$unique $remote_configs" + trap 'for f in '$remote_configs' ; do ssh ${f%:*} rm ${f#*:} ; done' EXIT fi cmd="$cmd -c $cur_conf"yes, this looks fine but I have a question:
I don't know the background for copying the config files to <remote-host>:/tmp. Why don't use all the daemons their local config
/etc/ceph/ceph.conf?May be you want to ensure that the remote daemons will use the same config as exists on the host from which the cluster was started. But if the configs on the remote hosts differ from the config of the "cluster-start-host", then we still might have a problem when a remote host is booting: In this case '
/etc/init.d/cephstart' is called and the remote host will use its local (different) config.I think a clear strategy would be:
- All daemons always use their local config (no copying to /tmp).
- If a cluster-start is initiated (/etc/init.d/ceph-a start) the script first checks if the configs on all cluster hosts are equal (maybe we need a content check here - not a literal check).
- If the configs are not equal, the cluster-start command aborts with an error message.
Quoted 7 lines
Quoted 1 line
What do you think about that?
That makes a lot more sense, although I would suggest a warning instead of an error. For cuttlefish, I'm hesitant to change behavior in the 11th hour, but we should make this change going forward.
Care to send a patch? :)
On second thought, I think we should just rip out the config pushign entirely. This will break
service ceph -a -c /some/local/config start ...
(unless /some/local/config is present on all nodes) but I don't think that is a use case any normal person would need...
sge
Quoted 60 lines · Sage Weil
Quoted 51 lines · Sage Weil
Quoted 50 lines · Andreas Friedrich
On Mi, Apr 24, 2013 at 11:04:56 -0700, Sage Weil wrote:
Hello Sage,
...
Quoted 13 lines
Quoted 4 lines
If the start script exits with or without error, the remote config file will be removed from <remote-host>:/tmp - but only for the last host (the former trap calls will be overwritten by the last trap call)! This makes no sense to me.
Bah.. I was thinking they would stack. How about
src/init-ceph.in +0
-0@@ -218,8 +218,11 @@ for name in $what; do elsesrc/init-ceph.in for name in $what; do · line 227
Quoted 10 lines
src/init-ceph.in +4
-1unique=`dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | awk '{print $1}'` scp -q $conf $host:/tmp/ceph.conf.$unique - trap "ssh $host rm /tmp/ceph.conf.$unique" EXIT cur_conf="/tmp/ceph.conf.$unique" + + # clean up on exit + remote_configs="$host:/tmp/ceph.conf.$unique $remote_configs" + trap 'for f in '$remote_configs' ; do ssh ${f%:*} rm ${f#*:} ; done' EXIT fi cmd="$cmd -c $cur_conf"yes, this looks fine but I have a question:
I don't know the background for copying the config files to <remote-host>:/tmp. Why don't use all the daemons their local config
/etc/ceph/ceph.conf?May be you want to ensure that the remote daemons will use the same config as exists on the host from which the cluster was started. But if the configs on the remote hosts differ from the config of the "cluster-start-host", then we still might have a problem when a remote host is booting: In this case '
/etc/init.d/cephstart' is called and the remote host will use its local (different) config.I think a clear strategy would be:
- All daemons always use their local config (no copying to /tmp).
- If a cluster-start is initiated (/etc/init.d/ceph-a start) the script first checks if the configs on all cluster hosts are equal (maybe we need a content check here - not a literal check).
- If the configs are not equal, the cluster-start command aborts with an error message.Quoted 7 lines
Quoted 1 line
What do you think about that?
That makes a lot more sense, although I would suggest a warning instead of an error. For cuttlefish, I'm hesitant to change behavior in the 11th hour, but we should make this change going forward.
Care to send a patch? :)
Quoted 7 lines
On second thought, I think we should just rip out the config pushign entirely. This will break
service ceph -a -c /some/local/config start ...
(unless /some/local/config is present on all nodes) but I don't think that is a use case any normal person would need...
cd7e52cc76878eed0f084f7b9a6cf7c792b716c6
sage