-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement clean_chroot to avoid host env variables like TMP to leak into the chroot #280
base: master
Are you sure you want to change the base?
Conversation
…nto the chroot Some implementation notes: If we use `env -i`, then we can no longer export shell functions. So export -f "error_handler" had to be removed. `PATH` needs to be set, otherwise `clean_chroot "$MNTPOINT" grub-install` would fail, because grub-install is in /usr/sbin/grub-install in the chroot. http_proxy has to be passed otherwise apt-cacher-ng would be broken by this commit. While at it, I completed it and added https_proxy, and ALL_PROXY there too for completeness sake. Which environment variables are passed into the chroot is currently hardcoded. FTR, I was also wondering if it was better to use a similar mechanism to the one you're using for CHROOT_VARIABLES, but that would not work because only the chroot-script reads those. But we're not only using that but also other calls from grml-debootstrap to chroot (now clean_chroot), so the environment variables need to be set at the grml-debootstrap level. Closes: #232
This is the result of squashing the commits from #267 and extending the commit message accordingly. What I'm not entirely sure about yet is the usage of calls like:
@adrelanos are you sure this behaves as expected? 🤔 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
shellcheck
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1893 in 07a5fe6
cp $VERBOSE "${CHROOT_VARIABLES}" "${MNTPOINT}"/etc/debootstrap/variables |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1895 in 07a5fe6
cp $VERBOSE -a -L "${CONFFILES}"/extrapackages/ "${MNTPOINT}"/etc/debootstrap/ |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1898 in 07a5fe6
[ -f "${MNTPOINT}"/etc/resolv.conf ] || cp $VERBOSE /etc/resolv.conf "${MNTPOINT}"/etc/resolv.conf |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1901 in 07a5fe6
[ -n "$LOCALES" ] && cp $VERBOSE "${CONFFILES}"/locale.gen "${MNTPOINT}"/etc/locale.gen |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1904 in 07a5fe6
[ -d "${CONFFILES}"/bin ] && cp $VERBOSE -a -L "${CONFFILES}"/bin/* "${MNTPOINT}"/bin/ |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1905 in 07a5fe6
[ -d "${CONFFILES}"/boot ] && cp $VERBOSE -a -L "${CONFFILES}"/boot/* "${MNTPOINT}"/boot/ |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1906 in 07a5fe6
[ -d "${CONFFILES}"/etc ] && cp $VERBOSE -a -L "${CONFFILES}"/etc/* "${MNTPOINT}"/etc/ |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1907 in 07a5fe6
[ -d "${CONFFILES}"/sbin ] && cp $VERBOSE -a -L "${CONFFILES}"/sbin/* "${MNTPOINT}"/sbin/ |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1908 in 07a5fe6
[ -d "${CONFFILES}"/share ] && cp $VERBOSE -a -L "${CONFFILES}"/share/* "${MNTPOINT}"/share/ |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1909 in 07a5fe6
[ -d "${CONFFILES}"/usr ] && cp $VERBOSE -a -L "${CONFFILES}"/usr/* "${MNTPOINT}"/usr/ |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1910 in 07a5fe6
[ -d "${CONFFILES}"/var ] && cp $VERBOSE -a -L "${CONFFILES}"/var/* "${MNTPOINT}"/var/ |
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1965 in 07a5fe6
cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces" |
fi | ||
done | ||
|
||
[ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a >/dev/null 2>&1 || true | ||
[ -x "$MNTPOINT"/bin/umount ] && clean_chroot "$MNTPOINT" umount -a >/dev/null 2>&1 || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
# ugly, but make sure we really don't leave anything (/proc /proc and | ||
# /dev /dev are intended, trying to work around timing issues, see #657023) | ||
for ARG in /run/udev /sys /proc /proc /dev/pts /dev/pts /dev /dev ; do | ||
[ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true | ||
[ -x "$MNTPOINT"/bin/umount ] && clean_chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Possible misspelling: PACKAGES may not be assigned. Did you mean KPACKAGE? SC2153
grml-debootstrap/chroot-script
Line 272 in 07a5fe6
if [ "$PACKAGES" = 'yes' ] ; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 817 in 07a5fe6
RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 869 in 07a5fe6
CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 879 in 07a5fe6
0 0 $MIRROR)" || bailout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 885 in 07a5fe6
0 0 $ISO)" || bailout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1852 in 07a5fe6
cp $VERBOSE "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1857 in 07a5fe6
cp $VERBOSE "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1876 in 07a5fe6
cp $VERBOSE "${_opt_packages:-$CONFFILES/$PACKAGES_FILE}" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1883 in 07a5fe6
cp $VERBOSE "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086
grml-debootstrap/grml-debootstrap
Line 1889 in 07a5fe6
cp -a $VERBOSE "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
shellcheck (suggestion)
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1895 in 07a5fe6
cp $VERBOSE -a -L "${CONFFILES}"/extrapackages/ "${MNTPOINT}"/etc/debootstrap/ |
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1898 in 07a5fe6
[ -f "${MNTPOINT}"/etc/resolv.conf ] || cp $VERBOSE /etc/resolv.conf "${MNTPOINT}"/etc/resolv.conf |
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1901 in 07a5fe6
[ -n "$LOCALES" ] && cp $VERBOSE "${CONFFILES}"/locale.gen "${MNTPOINT}"/etc/locale.gen |
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Lines 1904 to 1910 in 07a5fe6
[ -d "${CONFFILES}"/bin ] && cp $VERBOSE -a -L "${CONFFILES}"/bin/* "${MNTPOINT}"/bin/ | |
[ -d "${CONFFILES}"/boot ] && cp $VERBOSE -a -L "${CONFFILES}"/boot/* "${MNTPOINT}"/boot/ | |
[ -d "${CONFFILES}"/etc ] && cp $VERBOSE -a -L "${CONFFILES}"/etc/* "${MNTPOINT}"/etc/ | |
[ -d "${CONFFILES}"/sbin ] && cp $VERBOSE -a -L "${CONFFILES}"/sbin/* "${MNTPOINT}"/sbin/ | |
[ -d "${CONFFILES}"/share ] && cp $VERBOSE -a -L "${CONFFILES}"/share/* "${MNTPOINT}"/share/ | |
[ -d "${CONFFILES}"/usr ] && cp $VERBOSE -a -L "${CONFFILES}"/usr/* "${MNTPOINT}"/usr/ | |
[ -d "${CONFFILES}"/var ] && cp $VERBOSE -a -L "${CONFFILES}"/var/* "${MNTPOINT}"/var/ |
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1965 in 07a5fe6
cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 817 in 07a5fe6
RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 869 in 07a5fe6
CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 879 in 07a5fe6
0 0 $MIRROR)" || bailout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 885 in 07a5fe6
0 0 $ISO)" || bailout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1852 in 07a5fe6
cp $VERBOSE "${CONFFILES}"/chroot-script "${MNTPOINT}"/bin/chroot-script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1857 in 07a5fe6
cp $VERBOSE "${CONFFILES}/config" "${MNTPOINT}"/etc/debootstrap/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1876 in 07a5fe6
cp $VERBOSE "${_opt_packages:-$CONFFILES/$PACKAGES_FILE}" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1883 in 07a5fe6
cp $VERBOSE "${_opt_debconf}" "${MNTPOINT}"/etc/debootstrap/debconf-selections |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1889 in 07a5fe6
cp -a $VERBOSE "${_opt_chroot_scripts}"/* "${MNTPOINT}"/etc/debootstrap/chroot-scripts/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[shellcheck (suggestion)] reported by reviewdog 🐶
grml-debootstrap/grml-debootstrap
Line 1893 in 07a5fe6
cp $VERBOSE "${CHROOT_VARIABLES}" "${MNTPOINT}"/etc/debootstrap/variables |
Thank you!
I've built several releases using that line. It is functional because we are using
It would make sense but I did not include it to keep this PR smaller. It wasn't strictly required, I thought. And it made the diff look simpler. I could be done in a follow-up. |
Ahhhh right, now I see the magic in
Ok :) |
Some implementation notes:
If we use
env -i
, then we can no longer export shell functions. So export -f "error_handler" had to be removed.PATH
needs to be set, otherwiseclean_chroot "$MNTPOINT" grub-install
would fail, because grub-install is in /usr/sbin/grub-install in the chroot.http_proxy has to be passed otherwise apt-cacher-ng would be broken by this commit. While at it, I completed it and added https_proxy, and ALL_PROXY there too for completeness sake.
Which environment variables are passed into the chroot is currently hardcoded.
FTR, I was also wondering if it was better to use a similar mechanism to the one you're using for CHROOT_VARIABLES, but that would not work because only the chroot-script reads those. But we're not only using that but also other calls from grml-debootstrap to chroot (now clean_chroot), so the environment variables need to be set at the grml-debootstrap level.
Closes: #232