From 9fa72e56bf2e860ff38be417fafd621c437cca86 Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Mon, 15 Oct 2018 10:48:01 -0700 Subject: [PATCH 1/4] Fork multiarch/qemu-user-static registration scripts These files were downloaded from https://github.com/multiarch/qemu-user-static/tree/22b0013668d2aed4a2cfd21650e85c664b1f21c6. --- .../multiarch/qemu-user-static/LICENSE | 21 + .../qemu-user-static/README.kubernetes | 1 + .../register/qemu-binfmt-conf.sh | 367 ++++++++++++++++++ .../qemu-user-static/register/register.sh | 31 ++ 4 files changed, 420 insertions(+) create mode 100644 third_party/multiarch/qemu-user-static/LICENSE create mode 100644 third_party/multiarch/qemu-user-static/README.kubernetes create mode 100755 third_party/multiarch/qemu-user-static/register/qemu-binfmt-conf.sh create mode 100755 third_party/multiarch/qemu-user-static/register/register.sh diff --git a/third_party/multiarch/qemu-user-static/LICENSE b/third_party/multiarch/qemu-user-static/LICENSE new file mode 100644 index 0000000000..e9658e820b --- /dev/null +++ b/third_party/multiarch/qemu-user-static/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015-2016 Manfred Touron + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/third_party/multiarch/qemu-user-static/README.kubernetes b/third_party/multiarch/qemu-user-static/README.kubernetes new file mode 100644 index 0000000000..4e046fe6a0 --- /dev/null +++ b/third_party/multiarch/qemu-user-static/README.kubernetes @@ -0,0 +1 @@ +Files copied from https://github.com/multiarch/qemu-user-static at commit 22b0013668d2aed4a2cfd21650e85c664b1f21c6. diff --git a/third_party/multiarch/qemu-user-static/register/qemu-binfmt-conf.sh b/third_party/multiarch/qemu-user-static/register/qemu-binfmt-conf.sh new file mode 100755 index 0000000000..f21f146602 --- /dev/null +++ b/third_party/multiarch/qemu-user-static/register/qemu-binfmt-conf.sh @@ -0,0 +1,367 @@ +#!/bin/sh +# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390/HPPA/Xtensa/microblaze +# program execution by the kernel +# +# downloaded from https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-binfmt-conf.sh + +qemu_target_list="i386 i486 alpha arm armeb sparc32plus ppc ppc64 ppc64le m68k \ +mips mipsel mipsn32 mipsn32el mips64 mips64el \ +sh4 sh4eb s390x aarch64 aarch64_be hppa riscv32 riscv64 xtensa xtensaeb microblaze microblazeel" + +i386_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00' +i386_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +i386_family=i386 + +i486_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00' +i486_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +i486_family=i386 + +alpha_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90' +alpha_mask='\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +alpha_family=alpha + +arm_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00' +arm_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +arm_family=arm + +armeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28' +armeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +armeb_family=armeb + +sparc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02' +sparc_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +sparc_family=sparc + +sparc32plus_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12' +sparc32plus_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +sparc32plus_family=sparc + +ppc_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14' +ppc_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +ppc_family=ppc + +ppc64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15' +ppc64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +ppc64_family=ppc + +ppc64le_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00' +ppc64le_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00' +ppc64le_family=ppcle + +m68k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x04' +m68k_mask='\xff\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +m68k_family=m68k + +# FIXME: We could use the other endianness on a MIPS host. + +mips_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' +mips_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips_family=mips + +mipsel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' +mipsel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsel_family=mips + +mipsn32_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' +mipsn32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mipsn32_family=mips + +mipsn32el_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' +mipsn32el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mipsn32el_family=mips + +mips64_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08' +mips64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +mips64_family=mips + +mips64el_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00' +mips64el_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +mips64el_family=mips + +sh4_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00' +sh4_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +sh4_family=sh4 + +sh4eb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a' +sh4eb_mask='\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +sh4eb_family=sh4 + +s390x_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16' +s390x_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +s390x_family=s390x + +aarch64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00' +aarch64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +aarch64_family=arm + +aarch64_be_magic='\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7' +aarch64_be_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +aarch64_be_family=armeb + +hppa_magic='\x7f\x45\x4c\x46\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x0f' +hppa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +hppa_family=hppa + +riscv32_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' +riscv32_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +riscv32_family=riscv + +riscv64_magic='\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00' +riscv64_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +riscv64_family=riscv + +xtensa_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e\x00' +xtensa_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +xtensa_family=xtensa + +xtensaeb_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x5e' +xtensaeb_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' +xtensaeb_family=xtensaeb + +microblaze_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xba\xab' +microblaze_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +microblaze_family=microblaze + +microblazeel_magic='\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xab\xba' +microblazeel_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff' +microblazeel_family=microblazeel + +qemu_get_family() { + cpu=${HOST_ARCH:-$(uname -m)} + case "$cpu" in + amd64|i386|i486|i586|i686|i86pc|BePC|x86_64) + echo "i386" + ;; + mips*) + echo "mips" + ;; + "Power Macintosh"|ppc64|powerpc|ppc) + echo "ppc" + ;; + ppc64el|ppc64le) + echo "ppcle" + ;; + arm|armel|armhf|arm64|armv[4-9]*l|aarch64) + echo "arm" + ;; + armeb|armv[4-9]*b|aarch64_be) + echo "armeb" + ;; + sparc*) + echo "sparc" + ;; + riscv*) + echo "riscv" + ;; + *) + echo "$cpu" + ;; + esac +} + +usage() { + cat <&2 + exit 1 + fi +} + +qemu_check_bintfmt_misc() { + # load the binfmt_misc module + if [ ! -d /proc/sys/fs/binfmt_misc ]; then + if ! /sbin/modprobe binfmt_misc ; then + exit 1 + fi + fi + if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then + if ! mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc ; then + exit 1 + fi + fi + + qemu_check_access /proc/sys/fs/binfmt_misc/register +} + +installed_dpkg() { + dpkg --status "$1" > /dev/null 2>&1 +} + +qemu_check_debian() { + if [ ! -e /etc/debian_version ] ; then + echo "WARNING: your system is not a Debian based distro" 1>&2 + elif ! installed_dpkg binfmt-support ; then + echo "WARNING: package binfmt-support is needed" 1>&2 + fi + qemu_check_access "$EXPORTDIR" +} + +qemu_check_systemd() { + if ! systemctl -q is-enabled systemd-binfmt.service ; then + echo "WARNING: systemd-binfmt.service is missing or disabled" 1>&2 + fi + qemu_check_access "$EXPORTDIR" +} + +qemu_generate_register() { + echo ":qemu-$cpu:M::$magic:$mask:$qemu:$FLAGS" +} + +qemu_register_interpreter() { + echo "Setting $qemu as binfmt interpreter for $cpu" + qemu_generate_register > /proc/sys/fs/binfmt_misc/register +} + +qemu_generate_systemd() { + echo "Setting $qemu as binfmt interpreter for $cpu for systemd-binfmt.service" + qemu_generate_register > "$EXPORTDIR/qemu-$cpu.conf" +} + +qemu_generate_debian() { + cat > "$EXPORTDIR/qemu-$cpu" <> "$EXPORTDIR/qemu-$cpu" + fi +} + +qemu_set_binfmts() { + # probe cpu type + host_family=$(qemu_get_family) + + # register the interpreter for each cpu except for the native one + + for cpu in ${qemu_target_list} ; do + magic=$(eval echo \$${cpu}_magic) + mask=$(eval echo \$${cpu}_mask) + family=$(eval echo \$${cpu}_family) + + if [ "$magic" = "" ] || [ "$mask" = "" ] || [ "$family" = "" ] ; then + echo "INTERNAL ERROR: unknown cpu $cpu" 1>&2 + continue + fi + + qemu="$QEMU_PATH/qemu-$cpu-static" + if [ "$cpu" = "i486" ] ; then + qemu="$QEMU_PATH/qemu-i386-static" + fi + + if [ "$host_family" != "$family" ] ; then + $BINFMT_SET + fi + done +} + +CHECK=qemu_check_bintfmt_misc +BINFMT_SET=qemu_register_interpreter + +SYSTEMDDIR="/etc/binfmt.d" +DEBIANDIR="/usr/share/binfmts" + +QEMU_PATH=/usr/local/bin +FLAGS="" + +options=$(getopt -o ds:Q:e:hc: -l debian,systemd:,qemu-path:,exportdir:,help,credential: -- "$@") +eval set -- "$options" + +while true ; do + case "$1" in + -d|--debian) + CHECK=qemu_check_debian + BINFMT_SET=qemu_generate_debian + EXPORTDIR=${EXPORTDIR:-$DEBIANDIR} + ;; + -s|--systemd) + CHECK=qemu_check_systemd + BINFMT_SET=qemu_generate_systemd + EXPORTDIR=${EXPORTDIR:-$SYSTEMDDIR} + shift + # check given cpu is in the supported CPU list + if [ "$1" != "ALL" ] ; then + for cpu in ${qemu_target_list} ; do + if [ "$cpu" = "$1" ] ; then + break + fi + done + + if [ "$cpu" = "$1" ] ; then + qemu_target_list="$1" + else + echo "ERROR: unknown CPU \"$1\"" 1>&2 + usage + exit 1 + fi + fi + ;; + -Q|--qemu-path) + shift + QEMU_PATH="$1" + ;; + -e|--exportdir) + shift + EXPORTDIR="$1" + ;; + -h|--help) + usage + exit 1 + ;; + -c|--credential) + shift + if [ "$1" = "yes" ] ; then + FLAGS="OC" + else + FLAGS="" + fi + ;; + *) + break + ;; + esac + shift +done + +$CHECK +qemu_set_binfmts diff --git a/third_party/multiarch/qemu-user-static/register/register.sh b/third_party/multiarch/qemu-user-static/register/register.sh new file mode 100755 index 0000000000..8e3dab5da5 --- /dev/null +++ b/third_party/multiarch/qemu-user-static/register/register.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +QEMU_BIN_DIR=${QEMU_BIN_DIR:-/usr/bin} + + +if [ ! -d /proc/sys/fs/binfmt_misc ]; then + echo "No binfmt support in the kernel." + echo " Try: '/sbin/modprobe binfmt_misc' from the host" + exit 1 +fi + + +if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then + mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc +fi + +entries="aarch64 aarch64_be alpha arm armeb hppa m68k microblaze microblazeel mips mips64 mips64el mipsel mipsn32 mipsn32el ppc ppc64 ppc64le riscv32 riscv64 s390x sh4 sh4eb sparc sparc32plus sparc64 xtensa xtensaeb" + +if [ "${1}" = "--reset" ]; then + shift + ( + cd /proc/sys/fs/binfmt_misc + for file in $entries; do + if [ -f qemu-${file} ]; then + echo -1 > qemu-${file} + fi + done + ) +fi + +exec /qemu-binfmt-conf.sh --qemu-path="${QEMU_BIN_DIR}" $@ From bb9efbba256fd5c6ef4664aa59b6e68dbf0d6106 Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Mon, 15 Oct 2018 10:52:23 -0700 Subject: [PATCH 2/4] Fix path to qemu-binfmt-conf.sh --- third_party/multiarch/qemu-user-static/register/register.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/multiarch/qemu-user-static/register/register.sh b/third_party/multiarch/qemu-user-static/register/register.sh index 8e3dab5da5..55eafdd428 100755 --- a/third_party/multiarch/qemu-user-static/register/register.sh +++ b/third_party/multiarch/qemu-user-static/register/register.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash QEMU_BIN_DIR=${QEMU_BIN_DIR:-/usr/bin} @@ -28,4 +28,4 @@ if [ "${1}" = "--reset" ]; then ) fi -exec /qemu-binfmt-conf.sh --qemu-path="${QEMU_BIN_DIR}" $@ +exec $(dirname "${BASH_SOURCE}")/qemu-binfmt-conf.sh --qemu-path="${QEMU_BIN_DIR}" $@ From 9e4fa1493d1b30567d91191497ca10fa0e426ffc Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Mon, 15 Oct 2018 11:02:56 -0700 Subject: [PATCH 3/4] Use our forked qemu-static-register scripts instead of a privileged container --- build/debian-base/Makefile | 2 +- build/debian-hyperkube-base/Makefile | 2 +- build/debian-iptables/Makefile | 2 +- test/images/image-util.sh | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/build/debian-base/Makefile b/build/debian-base/Makefile index 379fa49196..d9f0ac5a0c 100755 --- a/build/debian-base/Makefile +++ b/build/debian-base/Makefile @@ -80,7 +80,7 @@ ifeq ($(ARCH),amd64) else # When cross-building, only the placeholder "CROSS_BUILD_" should be removed # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - docker run --rm --privileged multiarch/qemu-user-static:register --reset + sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR) # Ensure we don't get surprised by umask settings chmod 0755 $(TEMP_DIR)/qemu-$(QEMUARCH)-static diff --git a/build/debian-hyperkube-base/Makefile b/build/debian-hyperkube-base/Makefile index d9c0d87a00..53d7aa35a2 100644 --- a/build/debian-hyperkube-base/Makefile +++ b/build/debian-hyperkube-base/Makefile @@ -74,7 +74,7 @@ endif ifneq ($(ARCH),amd64) # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - docker run --rm --privileged multiarch/qemu-user-static:register --reset + sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset endif docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR) rm -rf $(TEMP_DIR) diff --git a/build/debian-iptables/Makefile b/build/debian-iptables/Makefile index 8c793db5aa..56a55ebaf3 100644 --- a/build/debian-iptables/Makefile +++ b/build/debian-iptables/Makefile @@ -32,7 +32,7 @@ build: ifneq ($(ARCH),amd64) # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - docker run --rm --privileged multiarch/qemu-user-static:register --reset + sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset endif docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR) diff --git a/test/images/image-util.sh b/test/images/image-util.sh index dcfd361963..555fd821c1 100755 --- a/test/images/image-util.sh +++ b/test/images/image-util.sh @@ -83,7 +83,8 @@ build() { else ${SED} -i "s|QEMUARCH|${QEMUARCHS[$arch]}|g" Dockerfile # Register qemu-*-static for all supported processors except the current one - docker run --rm --privileged multiarch/qemu-user-static:register --reset + echo "Registering qemu-*-static binaries in the kernel" + sudo "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/${QEMUVERSION}/x86_64_qemu-${QEMUARCHS[$arch]}-static.tar.gz | tar -xz -C ${temp_dir} # Ensure we don't get surprised by umask settings chmod 0755 "${temp_dir}/qemu-${QEMUARCHS[$arch]}-static" From a88244598a121ead3e56dedbb381c99880723b23 Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Mon, 15 Oct 2018 12:42:08 -0700 Subject: [PATCH 4/4] Use sudo only when not already root --- build/debian-base/Makefile | 4 +++- build/debian-hyperkube-base/Makefile | 4 +++- build/debian-iptables/Makefile | 4 +++- test/images/image-util.sh | 6 +++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/build/debian-base/Makefile b/build/debian-base/Makefile index d9f0ac5a0c..7ab9ac5bfc 100755 --- a/build/debian-base/Makefile +++ b/build/debian-base/Makefile @@ -27,6 +27,8 @@ ALL_ARCH = amd64 arm arm64 ppc64le s390x TEMP_DIR:=$(shell mktemp -d) QEMUVERSION=v2.9.1 +SUDO=$(if $(filter 0,$(shell id -u)),,sudo) + # This option is for running docker manifest command export DOCKER_CLI_EXPERIMENTAL := enabled @@ -80,7 +82,7 @@ ifeq ($(ARCH),amd64) else # When cross-building, only the placeholder "CROSS_BUILD_" should be removed # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset + $(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR) # Ensure we don't get surprised by umask settings chmod 0755 $(TEMP_DIR)/qemu-$(QEMUARCH)-static diff --git a/build/debian-hyperkube-base/Makefile b/build/debian-hyperkube-base/Makefile index 53d7aa35a2..71dbd8bfca 100644 --- a/build/debian-hyperkube-base/Makefile +++ b/build/debian-hyperkube-base/Makefile @@ -33,6 +33,8 @@ CNI_TARBALL=cni-plugins-$(ARCH)-$(CNI_VERSION).tgz # This option is for running docker manifest command export DOCKER_CLI_EXPERIMENTAL := enabled +SUDO=$(if $(filter 0,$(shell id -u)),,sudo) + .PHONY: all build push clean all-build all-push-images all-push push-manifest all: all-push @@ -74,7 +76,7 @@ endif ifneq ($(ARCH),amd64) # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset + $(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset endif docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR) rm -rf $(TEMP_DIR) diff --git a/build/debian-iptables/Makefile b/build/debian-iptables/Makefile index 56a55ebaf3..6d0438ffef 100644 --- a/build/debian-iptables/Makefile +++ b/build/debian-iptables/Makefile @@ -26,13 +26,15 @@ BASEIMAGE?=k8s.gcr.io/debian-base-$(ARCH):0.3.2 # This option is for running docker manifest command export DOCKER_CLI_EXPERIMENTAL := enabled +SUDO=$(if $(filter 0,$(shell id -u)),,sudo) + build: cp ./* $(TEMP_DIR) cd $(TEMP_DIR) && sed -i "s|BASEIMAGE|$(BASEIMAGE)|g" Dockerfile ifneq ($(ARCH),amd64) # Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel - sudo ../../third_party/multiarch/qemu-user-static/register/register.sh --reset + $(SUDO) ../../third_party/multiarch/qemu-user-static/register/register.sh --reset endif docker build --pull -t $(IMAGE)-$(ARCH):$(TAG) $(TEMP_DIR) diff --git a/test/images/image-util.sh b/test/images/image-util.sh index 555fd821c1..61a57e844f 100755 --- a/test/images/image-util.sh +++ b/test/images/image-util.sh @@ -84,7 +84,11 @@ build() { ${SED} -i "s|QEMUARCH|${QEMUARCHS[$arch]}|g" Dockerfile # Register qemu-*-static for all supported processors except the current one echo "Registering qemu-*-static binaries in the kernel" - sudo "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset + local sudo="" + if [[ $(id -u) != 0 ]]; then + sudo=sudo + fi + "${sudo}" "${KUBE_ROOT}/third_party/multiarch/qemu-user-static/register/register.sh" --reset curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/${QEMUVERSION}/x86_64_qemu-${QEMUARCHS[$arch]}-static.tar.gz | tar -xz -C ${temp_dir} # Ensure we don't get surprised by umask settings chmod 0755 "${temp_dir}/qemu-${QEMUARCHS[$arch]}-static"