Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 420737 - Add reminder to docs that /etc/env.d is for login shells ONLY(WAS: app-admin/sudo-1.8.5_p2: environment variable in /etc/env.d has no effect)
Summary: Add reminder to docs that /etc/env.d is for login shells ONLY(WAS: app-admin/...
Status: RESOLVED INVALID
Alias: None
Product: [OLD] Docs on www.gentoo.org
Classification: Unclassified
Component: Installation Handbook (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Docs Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-11 21:03 UTC by lsching17
Modified: 2013-05-05 22:25 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lsching17 2012-06-11 21:03:00 UTC
The environment variable defined in /etc/env.d have no effect for sudo, shell script called by sudo cannot access those variables automatically.

emerge --info sudo
Portage 2.1.10.49 (default/linux/amd64/10.0/desktop, gcc-4.6.3, glibc-2.14.1-r3, 3.3.6 x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-3.3.6-x86_64-Intel-R-_Core-TM-_i7-2600_CPU_@_3.40GHz-with-gentoo-2.1
Timestamp of tree: Mon, 11 Jun 2012 00:45:01 +0000
app-shells/bash:          4.2_p20
dev-java/java-config:     2.1.11-r3
dev-lang/python:          2.7.3-r1, 3.2.3
dev-util/cmake:           2.8.7-r5
dev-util/pkgconfig:       0.26
sys-apps/baselayout:      2.1-r1
sys-apps/openrc:          0.9.8.4
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.13, 2.68
sys-devel/automake:       1.11.1
sys-devel/binutils:       2.21.1-r1
sys-devel/gcc:            4.6.3
sys-devel/gcc-config:     1.6
sys-devel/libtool:        2.4-r1
sys-devel/make:           3.82-r1
sys-kernel/linux-headers: 3.3 (virtual/os-headers)
sys-libs/glibc:           2.14.1-r3
Repositories: gentoo
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -fuse-linker-plugin -march=native -ftree-vectorize"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt /var/lib/hsqldb"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -fuse-linker-plugin -march=native -ftree-vectorize"
DISTDIR="/custom/tmp/portage/distfiles"
FEATURES="assume-digests binpkg-logs distlocks ebuild-locks fixlafiles news parallel-fetch parallel-install protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync webrsync-gpg xattr"
FFLAGS=""
GENTOO_MIRRORS="http://gentoo.aditsu.net"
LANG="en_HK.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j8"
PKGDIR="/custom/tmp/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/custom/tmp/portage/tmp"
PORTDIR="/custom/tmp/portage/tree"
PORTDIR_OVERLAY=""
SYNC=""
USE="3dnow 3dnowext X a52 aac acl acpi alsa amd64 berkdb bluetooth branding bzip2 cairo caps cdda cdr cjk cli consolekit cracklib crypt cups custom-optimization cxx dbus dga dri dts dvd dvdr emboss encode exif fam firefox flac fortran gdbm gif gnutls gpm gtk iconv ipv6 jpeg lcms ldap libnotify lzma lzo mad mmx mmxext mng modules mp3 mp4 mpeg mudflap multilib ncurses nls nptl ogg openal opengl openmp pam pango pcre pdf png policykit ppds pppd qt3support qt4 readline sasl sdl session smp spell sse sse2 sse3 ssl ssse3 startup-notification svg tcl tcpd threads tiff truetype udev udisks unicode upower usb vdpau vorbis wifi wxwidgets x264 xattr xcb xft xml xorg xulrunner xv xvid zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" PHP_TARGETS="php5-3" PYTHON_TARGETS="python3_2 python2_7" RUBY_TARGETS="ruby18 ruby19" USERLAND="GNU" VIDEO_CARDS="intel radeon" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON

=================================================================
                        Package Settings
=================================================================

app-admin/sudo-1.8.5_p2 was built with the following:
USE="ldap (multilib) nls pam -offensive (-selinux) -skey"


Reproducible: Always

Steps to Reproduce:
"sudo env"
Actual Results:  
"sudo env" do not list variable defined in /etc/env.d

Expected Results:  
"sudo env" should list variable defined in /etc/env.d, they are global variable
Comment 1 Alex Legler (RETIRED) archtester gentoo-dev Security 2012-06-12 10:52:30 UTC
1) /etc/env.d is by default only loaded for login shells -- `sudo env' doe not spawn a login shell
2) sudo resets the environment for security reasons. See the -E switch and the env_keep/env_reset options (I guess in man sudoers) to configure this behavior.

All in all, not a bug.
Comment 2 lsching17 2012-06-12 13:43:16 UTC
May i ask a question before closing this report?


sudo will load variable from /etc/environment after resetting environment, This kind of "global" environment variables may be needed for scripts to function properly (e.g. path, url). It is normal to expect program which work properly in root login shell will work in sudo too.

The -E option may introduce security risk and is totally 2 different thing.


As the recommend Gentoo way to set environment variable is in /etc/env.d

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=5

If this "way" is limited to login shell only, please consider update the documentation to remind user about this.
Comment 3 Sergey Popov gentoo-dev 2013-01-17 04:39:30 UTC
(In reply to comment #2)
> If this "way" is limited to login shell only, please consider update the
> documentation to remind user about this.

Agreed.
Comment 4 nm (RETIRED) gentoo-dev 2013-01-17 06:48:23 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > If this "way" is limited to login shell only, please consider update the
> > documentation to remind user about this.
> 
> Agreed.

since our docs only cover using "su" and not "sudo" i don't see anything that we need to change. nowhere do we say to run "sudo env" so i don't see this as a valid bug.
Comment 5 SpanKY gentoo-dev 2013-05-05 22:25:34 UTC
(In reply to comment #4)

`su` also doesn't spawn a login shell.  it does a rc shell by default.

this isn't related to sudo or su anything else.  this is generally how things work -- you start with a login shell which seeds things, and then you spawn rc shells after that which inherits the env the login shell started up.