Skip to content

Commit 56a072b

Browse files
committed
Create containers with a fixed umask, not the operator's
Answers the question in the thread directly: why does the GUI produce a working container from the same template when the script does not? Because pct create extracts the template under the umask of whoever called it. The GUI calls it from pvedaemon, which systemd starts with 022. We are called from the operator's shell, so a hardened 027 there gives /etc 750 -- and apt cannot resolve then, since it fetches as the _apt user. Same template, same pct, different umask. The reporter demonstrated it themselves: prefixing the script with `umask 022` made the network problem go away. That does make it ours to fix, whatever PegaProx does. A container should not come out differently depending on the shell the script was launched from. Scoped to the eight pct create calls rather than set for the whole build, so the operator's umask still governs the logs and temp files we write on the host -- narrowing their hardening beyond the one call that needs it would be presumptuous. The Incus path is deliberately untouched: incus launch hands the work to the daemon, which extracts under its own umask, so the caller's never applied. Wrapper checked for all three properties: 022 during the call, the previous umask restored after, exit code passed through unchanged.
1 parent 9cfeefe commit 56a072b

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

pve/backend.func

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ reclaim_tty() {
128128
' "${pgid:-0}" 2>/dev/null || true
129129
}
130130

131+
# pct create extracts the template under the caller's umask. The GUI calls it
132+
# from pvedaemon, which systemd starts with 022; we run from the operator's
133+
# shell, so a hardened 027 there gave containers /etc at 750 -- and apt cannot
134+
# resolve then, because it fetches as _apt. Same template, same pct, different
135+
# umask. Scoped to the call, so the operator's umask still governs everything
136+
# else we write on the host.
137+
_pct_create() {
138+
local prev rc
139+
prev="$(umask)"
140+
umask 022
141+
pct create "$@"
142+
rc=$?
143+
umask "$prev"
144+
return $rc
145+
}
146+
131147
# ------------------------------------------------------------------------------
132148
# build_container()
133149
#
@@ -2108,7 +2124,7 @@ create_lxc_container() {
21082124
export PCT_OSVERSION
21092125

21102126
msg_info "Retrying container creation with $os_type $fallback_ver"
2111-
if pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >>"$LOGFILE" 2>&1; then
2127+
if _pct_create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >>"$LOGFILE" 2>&1; then
21122128
msg_ok "Container created successfully with $os_type $fallback_ver (fallback from $old_template)."
21132129
return 0
21142130
else
@@ -2253,7 +2269,7 @@ create_lxc_container() {
22532269
fi
22542270
if [[ "$do_retry" == "yes" ]]; then
22552271
msg_info "Retrying container creation after upgrade"
2256-
if pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >>"$LOGFILE" 2>&1; then
2272+
if _pct_create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >>"$LOGFILE" 2>&1; then
22572273
msg_ok "Container created successfully after upgrade."
22582274
return 0
22592275
else
@@ -2909,7 +2925,7 @@ create_lxc_container() {
29092925

29102926
# First attempt (PCT_OPTIONS is a multi-line string, use it directly)
29112927
set -f
2912-
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >"$LOGFILE" 2>&1; then
2928+
if ! _pct_create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >"$LOGFILE" 2>&1; then
29132929
msg_debug "Container creation failed on ${TEMPLATE_STORAGE}. Checking error..."
29142930

29152931
if grep -qiE 'Compilation failed|Bareword.*not allowed' "$LOGFILE"; then
@@ -2928,7 +2944,7 @@ create_lxc_container() {
29282944
export CTID
29292945
msg_warn "Container ID $old_ctid was claimed by another process. Retrying with ID $CTID"
29302946
LOGFILE="/tmp/pct_create_${CTID}_$(date +%Y%m%d_%H%M%S)_${SESSION_ID}.log"
2931-
if pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >"$LOGFILE" 2>&1; then
2947+
if _pct_create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >"$LOGFILE" 2>&1; then
29322948
msg_ok "Container successfully created with new ID $CTID"
29332949
else
29342950
msg_error "Container creation failed even with new ID $CTID. See $LOGFILE"
@@ -2943,7 +2959,7 @@ create_lxc_container() {
29432959
msg_ok "Template re-downloaded"
29442960
fi
29452961

2946-
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >>"$LOGFILE" 2>&1; then
2962+
if ! _pct_create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >>"$LOGFILE" 2>&1; then
29472963
if [[ "$TEMPLATE_STORAGE" != "local" ]]; then
29482964
msg_info "Retrying container creation with fallback to local storage"
29492965
LOCAL_TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE"
@@ -2959,7 +2975,7 @@ create_lxc_container() {
29592975
else
29602976
msg_ok "Trying local storage fallback"
29612977
fi
2962-
if ! pct create "$CTID" "local:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >>"$LOGFILE" 2>&1; then
2978+
if ! _pct_create "$CTID" "local:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} >>"$LOGFILE" 2>&1; then
29632979
if grep -qiE 'unsupported .* version' "$LOGFILE"; then
29642980
msg_warn "pct reported 'unsupported version' – LXC stack might be too old for this template"
29652981
offer_lxc_stack_upgrade_and_maybe_retry "yes"
@@ -2986,7 +3002,7 @@ create_lxc_container() {
29863002
msg_error "Container creation failed. See $LOGFILE"
29873003
if whiptail --yesno "pct create failed.\nDo you want to enable verbose debug mode and view detailed logs?" 12 70; then
29883004
set -x
2989-
pct create "$CTID" "local:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} 2>&1 | tee -a "$LOGFILE"
3005+
_pct_create "$CTID" "local:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} 2>&1 | tee -a "$LOGFILE"
29903006
set +x
29913007
fi
29923008
_flush_pct_log
@@ -3022,7 +3038,7 @@ create_lxc_container() {
30223038
msg_error "Container creation failed. See $LOGFILE"
30233039
if whiptail --yesno "pct create failed.\nDo you want to enable verbose debug mode and view detailed logs?" 12 70; then
30243040
set -x
3025-
pct create "$CTID" "local:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} 2>&1 | tee -a "$LOGFILE"
3041+
_pct_create "$CTID" "local:vztmpl/${TEMPLATE}" $PCT_OPTIONS ${_PW_ARGS[@]+"${_PW_ARGS[@]}"} 2>&1 | tee -a "$LOGFILE"
30263042
set +x
30273043
fi
30283044
_flush_pct_log

0 commit comments

Comments
 (0)