Skip to content

fix(install): recover Portainer Edge env vars stripped by sudo env_reset [KS-65]#161

Merged
yajith merged 3 commits into
developfrom
fix/ks-65/sudo-env-preservation
Jun 18, 2026
Merged

fix(install): recover Portainer Edge env vars stripped by sudo env_reset [KS-65]#161
yajith merged 3 commits into
developfrom
fix/ks-65/sudo-env-preservation

Conversation

@yajith

@yajith yajith commented Jun 12, 2026

Copy link
Copy Markdown
Member
  • On systems where sudo is configured with env_reset, the -E flag is silently ignored, stripping KUBESOLO_* vars before the installer runs
  • Fix reads all KUBESOLO_* vars back from /proc/$PPID/environ (the sudo process's own environment, which retains them even when not passed through to the script)
  • Recovery block is now generic — covers all flags.go Envar() declarations automatically, not just the three PORTAINER_EDGE_* vars
  • Recovery only triggers when running under sudo with PORTAINER_EDGE_KEY missing, and is a no-op on systems without procfs
  • Also fixes PORTAINER_EDGE_ASYNC never being added to CMD_ARGS — the flag was parsed but silently dropped since the first commit, meaning async mode never took effect
  • Wires previously missing flags.go vars into var-init and CMD_ARGS: LOAD_BALANCER, LOCAL_STORAGE_SHARED_PATH, FULL, DB_WAL_REPAIR, DISABLE_IPV6, STARTUP_TIMEOUT
  • Fixes LOCAL_STORAGE default mismatch (was false in installer, true in binary) — now consistently true
  • LOAD_BALANCER and LOCAL_STORAGE CMD_ARGS guards use a disable-only pattern (flag only written when explicitly set to false, since binary defaults both to true)

Ref: KS-65

…set [KS-65]

Some systems configure sudo with env_reset, which causes the -E flag to be
silently ignored. This strips KUBESOLO_PORTAINER_* vars set before the sudo
invocation, leaving the installer without edge credentials.

Fix: after argument parsing, if we are running under sudo (SUDO_USER set) and
PORTAINER_EDGE_KEY is empty, read the vars back from /proc/$PPID/environ —
the sudo process's own environment still holds them even though it did not
pass them through to the script. The guard on /proc/$PPID/environ being
readable makes this a no-op on systems without procfs.

Also fix PORTAINER_EDGE_ASYNC never being added to CMD_ARGS: the flag has
been parsed since the first commit but was silently dropped before being
passed to the kubesolo binary, causing async mode to never take effect when
set via env var or --portainer-edge-async.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yajith yajith requested a review from stevensbkang as a code owner June 12, 2026 05:43
@linear

linear Bot commented Jun 12, 2026

Copy link
Copy Markdown

KS-65

Comment thread install.sh Outdated
…[KS-65]

- Replace narrow 3-var recovery block with a generic loop that recovers
  all KUBESOLO_* vars from /proc/$PPID/environ, covering all flags.go
  Envar() declarations automatically
- Move recovery block before var-init so recovered vars are picked up
  naturally by the existing ${KUBESOLO_X:-default} assignments
- Wire missing flags into var-init and CMD_ARGS: LOAD_BALANCER,
  LOCAL_STORAGE_SHARED_PATH, FULL, DB_WAL_REPAIR, DISABLE_IPV6,
  STARTUP_TIMEOUT
- Fix LOCAL_STORAGE default mismatch (false → true, aligning with
  flags.go and expected behaviour)
- Flip LOCAL_STORAGE and LOAD_BALANCER CMD_ARGS guards to fire on false
  (disable-only pattern, since binary defaults both to true)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yajith yajith merged commit 4c4e33d into develop Jun 18, 2026
7 checks passed
@yajith yajith deleted the fix/ks-65/sudo-env-preservation branch June 18, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants