flatcar-scripts/chroot_version_hooks.d/45_rewrite_sudoers.d
Brian Harring 06d3c2e20b Pass more proxy vars into the chroot, rework sudoers.d maintenance.
In particular, put the sudoers.d setup into one script (making
updates to it easier in the future if necessary), and
centralize the proxied vars into a const in common.sh.

Thanks to Kevin McCray/Josh Triplett/Alexander Kanevsky for
pointing out the missing proxy variables, and fixes/cleanup.

BUG=None
TEST=https_proxy=blah cros_sdk -- bash -c 'echo $https_proxy'
TEST=build_packages behind a proxy.
TEST=cros_sdk --replace && \
     RSYNC_PROXY=blah cros_sdk -- bash -c 'echo $RSYNC_PROXY'

Change-Id: I3165882dfd9c8b52d25c2b26d7ff9242c84c91bd
Reviewed-on: https://gerrit.chromium.org/gerrit/31185
Tested-by: Brian Harring <ferringb@chromium.org>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Josh Triplett <josh@joshtriplett.org>
2012-08-24 13:26:03 -07:00

42 lines
1.1 KiB
Makefile

# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Note that this script is invoked by make_chroot in addition
# to normal upgrade pathways.
if [ "$(id -u)" != 0 ]; then
# Note that since we're screwing w/ sudo variables, this script
# explicitly bounces up to root for everything it does- that way
# if anyone introduces a temp depriving in the sudo setup, it can't break
# mid upgrade.
exec sudo bash -e "${VERSION_HOOKS_DIR}/45_rewrite_sudoers.d" \
/ "${USER}" "${ENVIRONMENT_WHITELIST[@]}"
exit 1
fi
# Reaching here means we're root.
if [ $# -lt 2 ]; then
echo "Invoked with wrong number of args; expected root USER [variables]*"
exit 1
fi
root=$1
username=$2
shift
shift
set -- "${@}" CROS_WORKON_SRCROOT PORTAGE_USERNAME
cat > "${root}/etc/sudoers.d/90_cros" <<EOF
Defaults env_keep += "${*}"
%adm ALL=(ALL) ALL
root ALL=(ALL) ALL
${username} ALL=NOPASSWD: ALL
EOF
chmod 0440 "${root}/etc/sudoers.d/90_cros"
chown root:root "${root}/etc/sudoers.d/90_cros"
exit 0