diff --git a/docs/backends.md b/docs/backends.md index 0380c5c..4ffbeaf 100644 --- a/docs/backends.md +++ b/docs/backends.md @@ -52,15 +52,12 @@ often around 10 GiB, which is why the backend prints how to grow it. **Not every operator is root.** An Incus host is routinely driven by an unprivileged user. That is why `community_scripts_dir()` exists at all, and why -the header cache, logs and defaults all go through it. It also means -`kernel.keys.maxkeys` cannot be written from an unprivileged user namespace, so -that sysctl is set only for privileged containers, and only when the host value -is actually below the target. - -**Optional settings must not brick the container.** A rejected `linux.sysctl.*` -key stops the instance from starting, so they are applied softly and rolled back -on failure — and the rollback confirms the container really is running via -`incus list -c s`, rather than trusting the exit status of a start. +the header cache, logs and defaults all go through it. + +**No per-container `kernel.keys.maxkeys`.** lxc applies `linux.sysctl.*` with +`/proc/sys` already read-only, so that key stopped privileged and unprivileged +containers alike from starting. A failed restart is still recovered by a forced +stop and start, confirmed via `incus list -c s` rather than the exit status. **No pty.** The install runs through `incus exec` *without* `-t`. Allocating one looks harmless and is not: apt's dpkg progress does a `tcsetattr` on stdin, gets diff --git a/incus/backend.func b/incus/backend.func index 8780e78..a41bbfe 100644 --- a/incus/backend.func +++ b/incus/backend.func @@ -84,19 +84,14 @@ _incus_apply_addresses() { return "$changed" } -# Restart the container, tolerating optional boot-time configs (e.g. -# linux.sysctl.kernel.keys.maxkeys) that some hosts/kernels reject for the -# container's privilege level. Such configs pass 'config set' but abort the -# container at *start* time, so a plain restart would leave it stopped. On -# failure, roll those configs back and retry so the container is never left -# dead. Returns non-zero only if it still cannot start. +# Restart the container; when that fails, force a stop and start so it is not +# left dead. Returns non-zero only if it still cannot start. _incus_restart_ct() { local logf="${LOGFILE:-$INCUS_BUILD_LOG}" if incus restart "${CT_NAME}" >>"$logf" 2>&1; then return 0 fi - msg_warn "Container failed to start with current config — rolling back optional sysctls" - _incus_soft incus config unset "${CT_NAME}" linux.sysctl.kernel.keys.maxkeys >>"$logf" 2>&1 + msg_warn "Container restart failed - forcing a stop and start" _incus_soft incus stop -f "${CT_NAME}" >>"$logf" 2>&1 _incus_soft incus start "${CT_NAME}" >>"$logf" 2>&1 # A failed restart leaves incus disagreeing with itself - the same recovery @@ -513,26 +508,6 @@ incus_create_lxc_container() { INCUS_BUILD_OK=0 export INCUS_CT_CREATED INCUS_ORPHAN_HANDLED INCUS_BUILD_OK CT_NAME CTID - # Optional boot-time configs that some hosts/kernels reject for this - # container type. They fail when the container *starts*, not at 'config set' - # (e.g. kernel.keys.maxkeys is not writable from an unprivileged user - # namespace), so a plain set can silently persist a config that aborts the - # next boot. Apply best-effort and verify with a self-healing restart below. - # kernel.keys.maxkeys cannot be written from an unprivileged user namespace - - # lxc aborts the start with "Permission denied - Failed to setup sysctl - # parameters kernel.keys.maxkeys to 2000". This was set for CT_TYPE=1, which - # IS the unprivileged case, so every unprivileged create paid a failed start - # plus a rollback to reach the state it would have had anyway. Privileged - # only, and only when the host default is actually below what we want. - local optional_sysctl_pending=0 - # The sysctl probe reads this machine; against a remote, just try the setting. - if [[ "${CT_TYPE:-1}" == "0" ]] && - { [[ "${INCUS_REMOTE:-local}" != "local" ]] || (($(cat /proc/sys/kernel/keys/maxkeys 2>/dev/null || echo 2000) < 2000)); }; then - if incus config set "${CT_NAME}" linux.sysctl.kernel.keys.maxkeys=2000 >>"$LOGFILE" 2>&1; then - optional_sysctl_pending=1 - fi - fi - msg_ok "Container ${CT_NAME} created" msg_info "Waiting for container to initialize" @@ -582,21 +557,10 @@ incus_create_lxc_container() { _incus_soft incus config set "${CT_NAME}" "user.tags=${TAGS}" >>"$LOGFILE" 2>&1 fi - # Restart when network devices changed, or to verify an optional boot-time - # sysctl we set above (so a rejected one is rolled back now rather than - # bricking a later reboot with boot.autostart=true). - if [[ "$net_reconfigure" -eq 1 || "$optional_sysctl_pending" -eq 1 ]]; then - if [[ "$net_reconfigure" -eq 1 ]]; then - msg_info "Reconfiguring network settings" - else - msg_info "Verifying container configuration" - fi + if [[ "$net_reconfigure" -eq 1 ]]; then + msg_info "Reconfiguring network settings" if _incus_restart_ct; then - if [[ "$net_reconfigure" -eq 1 ]]; then - msg_ok "Network settings applied" - else - msg_ok "Container configuration verified" - fi + msg_ok "Network settings applied" else # Everything past this point needs incus exec. Warning and carrying on # over a stopped container is what turned one failed restart into three @@ -1041,7 +1005,7 @@ http://dl-cdn.alpinelinux.org/alpine/${alpine_rel}/community EOF" if ! incus_ct_exec /bin/sh -c 'getent hosts dl-cdn.alpinelinux.org >/dev/null 2>&1'; then msg_warn "Alpine repository DNS resolution failed in container, injecting public DNS servers" - incus_ct_exec /bin/sh -c 'printf "nameserver 8.8.8.8\nnameserver 1.1.1.1\n" >/etc/resolv.conf' + incus_ct_exec /bin/sh -c 'printf "nameserver 8.8.8.8\nnameserver 1.1.1.1\n" >/etc/resolv.conf' || true fi incus_ct_exec ash -c "apk add bash newt curl openssh nano mc ncurses jq >/dev/null" || msg_warn "Alpine base package install had issues" elif [[ "${var_os:-debian}" =~ ^(debian|ubuntu|devuan)$ ]]; then @@ -1062,7 +1026,7 @@ EOF" if ! incus_ct_exec bash -c "${_ct_env} getent hosts deb.debian.org >/dev/null 2>&1 && getent hosts archive.ubuntu.com >/dev/null 2>&1"; then msg_warn "APT repository DNS resolution failed in container, injecting public DNS servers" - incus_ct_exec bash -c "echo -e 'nameserver 8.8.8.8\nnameserver 1.1.1.1' >/etc/resolv.conf" + incus_ct_exec bash -c "echo -e 'nameserver 8.8.8.8\nnameserver 1.1.1.1' >/etc/resolv.conf" || true fi incus_ct_exec bash -c "${_ct_env} apt-get update >/dev/null 2>&1 && apt-get install -y ${_base_pkgs} >/dev/null 2>&1" || {