Skip to content

Commit 7b1bbac

Browse files
stefanhaRHstefanha
authored andcommitted
image-builder: require root earlier for better error messages
The image_builder.sh script must be run as root. The following check is performed before the script checks for root: [ "${AGENT_INIT}" == "yes" ] || [ -x "${ROOTFS}/usr/bin/${AGENT_BIN}" ] || \ die "/usr/bin/${AGENT_BIN} is not installed in ${ROOTFS} use AGENT_BIN env variable to change the expected agent binary name" The -x test is "True if the file is executable by you". It may evaluate to true as root and false as non-root, depending on the file permissions. The permissions for kata-agent given in the Developer Guide are 0550 (https://github.com/kata-containers/documentation/blob/master/Developer-Guide.md#add-a-custom-agent-to-the-image---optional). Therefore image_builder.sh fails with "/usr/bin/${AGENT_BIN} is not installed" when run as non-root. This is confusing since the agent binary is really installed! Move the root check to the beginning of the script. This solves the confusing error and prevents similar problems where the script doesn't take into account that the user may be non-root. Fixes: kata-containers#127 Signed-off-by: Stefan Hajnoczi <[email protected]>
1 parent ac0c290 commit 7b1bbac

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

image-builder/image_builder.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ script_dir="$(dirname $(readlink -f $0))"
1414
lib_file="${script_dir}/../scripts/lib.sh"
1515
source "$lib_file"
1616

17+
[ "$(id -u)" -eq 0 ] || die "$0: must be run as root"
18+
1719
IMAGE="${IMAGE:-kata-containers.img}"
1820
AGENT_BIN=${AGENT_BIN:-kata-agent}
1921
AGENT_INIT=${AGENT_INIT:-no}
@@ -131,7 +133,6 @@ fi
131133
die "/usr/bin/${AGENT_BIN} is not installed in ${ROOTFS}
132134
use AGENT_BIN env variable to change the expected agent binary name"
133135
OK "Agent installed"
134-
[ "$(id -u)" -eq 0 ] || die "$0: must be run as root"
135136

136137
ROOTFS_SIZE=$(du -B 1MB -s "${ROOTFS}" | awk '{print $1}')
137138
BLOCK_SIZE=${BLOCK_SIZE:-4096}

0 commit comments

Comments
 (0)