talos
talos copied to clipboard
State directory is wrongly created at /root/.talos when using sudo as non-root user
Bug Report
Description
State directory is wrongly created at /root/.talos when executing with sudo -E as non-root user.
Logs
creating state directory in "/root/.talos/clusters/talos-qemu"
Environment
talosctl version
Client:
Tag: v1.0.3
SHA: 689c6e54
Built:
Go version: go1.17.7
OS/Arch: linux/amd64
what does this return sudo -E bash -c "echo \$HOME", i wonder if it's not properly passing down env vars
tested from both zsh and bash shells
sudo -E bash -c "echo \$HOME"
/root
Also ran a printenv and found most of my env vars are correctly inherited but the $HOME env var seems to be off limits to over-writing with the -E flag.
When printing env, the only other var I found that we could leverage was SUDO_USER. From that I can get my home correctly with:
sudo -E bash -c "eval echo ~\${SUDO_USER}"
I wonder if it's a os thing, on my debian derivate i see this:
❯ sudo -E bash -c "echo \$HOME"
/home/frezbo
❯
I checked on Fedora 35 and Fedora 36, the behavior is the same on both:
$ cat /etc/os-release
NAME="Fedora Linux"
VERSION="36 (Thirty Six)"
ID=fedora
VERSION_ID=36
VERSION_CODENAME=""
PLATFORM_ID="platform:f36"
PRETTY_NAME="Fedora Linux 36 (Thirty Six)"
There is a sudo direktive that is not set on every OS
see: Defaults env_keep
# Run X applications through sudo; HOME is used to find the
# .Xauthority file. Note that other programs use HOME to find
# configuration files and this may lead to privilege escalation!
Defaults env_keep += "DISPLAY HOME"
and obsolate always_set_home
I have the same problem on openSUSE Tumbleweed .
$ sudo -E talosctl cluster create --provisioner=qemu --with-uefi=false
validating CIDR and reserving IPs
generating PKI and tokens
creating state directory in "/root/.talos/clusters/talos-default"
@ohauer, do you have a workaround for this problem?
Talos Version:
$ talosctl version
Client:
Tag: v1.0.5
SHA: 9f2bfac2
Built:
Go version: go1.17.10
OS/Arch: linux/amd64
sudo --preserve-env=HOME talosctl cluster create --provisioner=qemu worked for me to keep $HOME