Merge pull request #2460 from weaveworks/issues/2427-detect-peerid-clashes

Detect and report peer name collisions
This commit is contained in:
Bryan Boreham authored and GitHub committed 2016-08-12 16:52:56 +01:00
commit c79b6a8bd7
3 files changed
+34 -16

No files matched your search

+6 -2
View File
@@ -49,10 +49,14 @@ When the router is launched on a host, it derives its peer name in order of pref
* From the command line, where the user is responsible for uniqueness and * From the command line, where the user is responsible for uniqueness and
stability stability
* From the BIOS product UUID, which is generally stable across * From the concatenated result of any of the following:
* The unique machine ID, which is generated either by [systemd](https://www.freedesktop.org/software/systemd/man/machine-id.html)
or [D-Bus](https://dbus.freedesktop.org/doc/dbus-uuidgen.1.html) and is
practically stable across restarts unless a user re-generates it.
* The BIOS product UUID, which is generally stable across
restarts and unique across different physical hardware and certain restarts and unique across different physical hardware and certain
cloned VMs cloned VMs
* From the hypervisor UUID, which is generally stable across restarts * The hypervisor UUID, which is generally stable across restarts
and unique across VMs which do not provide access to a BIOS product and unique across VMs which do not provide access to a BIOS product
UUID UUID
* From a random value, practically unique across different physical * From a random value, practically unique across different physical
+27 -13
View File
@@ -143,12 +143,22 @@ launch_router_options() {
[ "$1" = "launch" -o "$1" = "launch-router" ] && echo -v /:/host -e HOST_ROOT=/host [ "$1" = "launch" -o "$1" = "launch-router" ] && echo -v /:/host -e HOST_ROOT=/host
} }
exec_options() {
case "$1" in
# Required by create_bridge which might need machine-id
launch|launch-router|create-bridge|attach-router|run|start|attach|restart|expose|hide)
echo -v /etc:/host/etc -v /var/lib/dbus:/host/var/lib/dbus -e HOST_ROOT=/host
;;
esac
}
exec_remote() { exec_remote() {
docker $DOCKER_CLIENT_ARGS run --rm \ docker $DOCKER_CLIENT_ARGS run --rm \
$(docker_run_options) \ $(docker_run_options) \
--pid=host \ --pid=host \
$(cni_volume_options "$@") \ $(cni_volume_options "$@") \
$(launch_router_options "$@") \ $(launch_router_options "$@") \
$(exec_options "$@") \
-e DOCKERHUB_USER="$DOCKERHUB_USER" \ -e DOCKERHUB_USER="$DOCKERHUB_USER" \
-e WEAVE_VERSION \ -e WEAVE_VERSION \
-e WEAVE_DEBUG \ -e WEAVE_DEBUG \
@@ -451,12 +461,11 @@ mac_from_hex() {
read a b c d e f && printf "%02x:$b:$c:$d:$e:$f" $((0x$a & ~1 | 2)) read a b c d e f && printf "%02x:$b:$c:$d:$e:$f" $((0x$a & ~1 | 2))
} }
mac_from_file() { mac_from_uid() {
UUID=$(cat $1 2>/dev/null) || return 1
# We salt the input just as a precaution to avoid clashes with # We salt the input just as a precaution to avoid clashes with
# other applications who might have had the bright idea of # other applications who might have had the bright idea of
# generating MACs in the same way. # generating MACs in the same way.
echo "9oBJ0Jmip-$UUID" | sha256sum | sed 's/\(..\)/\1 /g' | cut -c1-17 | mac_from_hex echo "9oBJ0Jmip-$1" | sha256sum | sed 's/\(..\)/\1 /g' | cut -c1-17 | mac_from_hex
} }
# Generate a random MAC value # Generate a random MAC value
@@ -464,6 +473,11 @@ random_mac() {
od -txC -An -N6 /dev/urandom | mac_from_hex od -txC -An -N6 /dev/urandom | mac_from_hex
} }
machineid() {
cat "$HOST_ROOT/etc/machine-id" 2>/dev/null && return 0 || true
cat "$HOST_ROOT/var/lib/dbus/machine-id" 2>/dev/null && return 0 || true
}
###################################################################### ######################################################################
# weave and docker specific helpers # weave and docker specific helpers
###################################################################### ######################################################################
@@ -696,16 +710,16 @@ init_bridge() {
ip link add name $BRIDGE type bridge ip link add name $BRIDGE type bridge
# Derive the bridge MAC from the system (aka bios) UUID, or, # Derive the bridge MAC from concatenated machine-id (either systemd or
# failing that, the hypervisor UUID. Elsewhere we in turn derive # dbus), the system (aka bios) UUID and the hypervisor UUID. If we cannot
# the peer name from that, which we want to be stable across # determine all of them we just generate a random MAC.
# reboots but otherwise unique. The system/hypervisor UUID fits # Elsewhere we in turn derive the peer name from the bridge MAC, which we
# that bill, unlike, say, /etc/machine-id, which is often # want to be stable across reboots but otherwise unique.
# identical on VMs created from cloned filesystems. If we cannot
# determine the system/hypervisor UUID we just generate a random MAC. uid="$(machineid)"
MAC=$(mac_from_file /sys/class/dmi/id/product_uuid) || \ uid="$uid#$(cat /sys/class/dmi/id/product_uuid 2>/dev/null || echo '')"
MAC=$(mac_from_file /sys/hypervisor/uuid) || \ uid="$uid#$(cat /sys/hypervisor/uuid 2>/dev/null || echo '')"
MAC=$(random_mac) [ "$uid" != "##" ] && MAC=$(mac_from_uid "$uid") || MAC=$(random_mac)
ip link set dev $BRIDGE address $MAC ip link set dev $BRIDGE address $MAC