containers: Remove use of sudo with docker and add logging

Logging will hopefully help us debug permissions errors in the future.

BUG=none
TEST=manual build_api call

Change-Id: Ic98c085c730f76d96f88bbb1a527fd9c250203c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/3330019
Tested-by: Sean McAllister <smcallis@google.com>
Auto-Submit: Sean McAllister <smcallis@google.com>
Reviewed-by: Derek Beckett <dbeckett@chromium.org>
Commit-Queue: Sean McAllister <smcallis@google.com>
diff --git a/test/docker/util.sh b/test/docker/util.sh
index ddb01a1..24c139f 100644
--- a/test/docker/util.sh
+++ b/test/docker/util.sh
@@ -120,8 +120,8 @@
 
   # First call sets up default GCR registries, second call sets up
   # Artifact Registry registries.
-  sudo gcloud --quiet --verbosity=error auth configure-docker
-  sudo gcloud --quiet --verbosity=error auth configure-docker us-docker.pkg.dev
+  gcloud --quiet --verbosity=error auth configure-docker
+  gcloud --quiet --verbosity=error auth configure-docker us-docker.pkg.dev
 }
 
 build_image() {
@@ -146,13 +146,22 @@
   done
   args+=("${build_context}")
 
-  echo sudo docker build "${args[@]}"
-  sudo docker build "${args[@]}"
+  echo docker build "${args[@]}"
+  docker build "${args[@]}"
 
-  # Push image to register
+  # Print debugging info
   ensure_gcloud_helpers
-  sudo docker login -u oauth2accesstoken -p "$(gcloud auth print-access-token)" "https://${registry_name}"
-  sudo docker push --all-tags "${image_path}"
+  echo
+  echo "== Gcloud helper configuration"
+  docker-credential-gcloud list
+
+  echo
+  echo "== User Authorization Scopes"
+  curl -H "Authorization: Bearer $(gcloud auth print-access-token)" \
+       https://www.googleapis.com/oauth2/v1/tokeninfo
+
+  # Push image to registry
+  docker push --all-tags "${image_path}"
 
   # write output if requested
   if [[ -n "${output_path}" ]]; then