cros_sdk: preserve PATH across self re-exec

Bots set up newer python3 via a custom $PATH which works when we go
to run cros_sdk.  But when it re-execs itself using sudo, the new
PATH has been sanitized and loses all those tweaks which means we
fallback to using python3 from the system.  Make sure we keep the
PATH setting when running ourselves through sudo to avoid that.

This doesn't impact the PATH value inside the SDK -- our tooling
still initializes that to the right value as makes sense.  This
only impacts programs run by cros_sdk before we actually chroot.

BUG=b:149182563
TEST=CQ passes

Change-Id: I406f61922bf47cc358b54569c53fccfac827063d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2056044
Reviewed-by: Simon Que <sque@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/scripts/cros_sdk.py b/scripts/cros_sdk.py
index fb0b88d..2065b5b 100644
--- a/scripts/cros_sdk.py
+++ b/scripts/cros_sdk.py
@@ -463,9 +463,13 @@
   """Get the 'sudo' command, along with all needed environment variables."""
 
   # Pass in the ENVIRONMENT_WHITELIST and ENV_PASSTHRU variables so that
-  # scripts in the chroot know what variables to pass through.
+  # scripts in the chroot know what variables to pass through.  We keep PATH
+  # not for the chroot but for the re-exec & for programs we might run before
+  # we chroot into the SDK.  The process that enters the SDK itself will take
+  # care of initializing PATH to the right value then.
   cmd = ['sudo']
-  for key in constants.CHROOT_ENVIRONMENT_WHITELIST + constants.ENV_PASSTHRU:
+  for key in (constants.CHROOT_ENVIRONMENT_WHITELIST + constants.ENV_PASSTHRU +
+              ('PATH',)):
     value = os.environ.get(key)
     if value is not None:
       cmd += ['%s=%s' % (key, value)]