In case the user uses a strict umask that results in the KAS_WORK_DIR
not being traversable by others, building currently fails. The reason is
a requirement of mmdebstrap with unshare backend that requires all
parent dirs of the TMPDIR to be world executable.
We fix this by bind-mounting kas-container managed subdirectories of
KAS_WORK_DIR in case KAS_WORK_DIR is not traversable by others. This is
in general a good idea to get standard umasks / file permissions on the
build environment. As these dirs are potentially created by
kas-container outside the container (e.g. KAS_BUILD_DIR is created if not
present), we set a suitable and stable umask. This also ensures that the
change only affects dirs we create - but not ones which have been
created externally by the user.
As the condition to mount a directory now depends not only on the path,
we must use the raw, expanded value (varval) as the host side of the
mount flag. Otherwise a relative path not starting with ./ would be
mounted as volume belonging to root inside the container (podman only).
Changes since v2:
- ensure the bind mounts are always absolute, to enforce that these
are mounted as bind-mounts instead of volumes on podman
Changes since v1:
- set a umask to let kas-container create the dirs with correct permissions
- reword variable name, invert logic, initialize it
- avoid not needed change (reduce diff)
kas-container | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/kas-container b/kas-container
index caaff0429..597bc4cc8 100755
--- a/kas-container
+++ b/kas-container
@@ -238,8 +238,19 @@ check_and_expand()
# shellcheck disable=2034
setup_kas_dirs()
{
+ # Use a stable umask for directories created by kas-container, without
+ # affecting permissions on user-provided directories.
+ umask 0022
+ KAS_WORK_DIR_HAS_S_IXOTH=1
KAS_WORK_DIR="${KAS_WORK_DIR:-$(pwd)}"
KAS_WORK_DIR="$(check_and_expand KAS_WORK_DIR required)"
+ # If KAS_WORK_DIR is not traversable by other users (e.g. chmod 700),
+ # the build user inside the container cannot reach directories located
+ # below it via /work. Force such directories into dedicated mounts.
+ if [ -z "$(find "${KAS_WORK_DIR}" -maxdepth 0 -perm -0001 2>/dev/null)" ]; then
+ KAS_WORK_DIR_HAS_S_IXOTH=0
+ KAS_BUILD_DIR=${KAS_BUILD_DIR:-${KAS_WORK_DIR}/build}
+ fi
KAS_BUILD_DIR="$(check_and_expand KAS_BUILD_DIR create)"
KAS_REPO_REF_DIR="$(check_and_expand KAS_REPO_REF_DIR required)"
DL_DIR="$(check_and_expand DL_DIR createrec)"
@@ -291,8 +302,9 @@ forward_dir()
eval _varval=\"\$"$1"\"
[ -z "$_varval" ] && return
FW_DIR_REL=$(realpath -q --relative-base="${KAS_WORK_DIR}" "$_varval")
- if [ "${FW_DIR_REL}" = "$_varval" ]; then
- KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} -v ${FW_DIR_REL}:$2:$3 -e $1=$2"
+ if [ "${FW_DIR_REL}" = "$_varval" ] || [ "${KAS_WORK_DIR_HAS_S_IXOTH}" = "0" ]; then
+ # varval always contains an absolute path, which ensures podman uses a bind-mount
+ KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} -v ${_varval}:$2:$3 -e $1=$2"
else
KAS_RUNTIME_ARGS="${KAS_RUNTIME_ARGS} -e $1=/work/${FW_DIR_REL}"
fi
--
2.55.0