Repository: bazelbuild/bazel
Issue: Implement the credential helpers proposal
Labels: type: feature request
P2
team-Remote-Exec

### Description of the feature request:


Tracking issue for implementing https://github.com/bazelbuild/proposals/blob/main/designs/2022-06-07-bazel-credential-helpers.md.

### What underlying problem are you trying to solve with this feature?


N/A

### Which operating system are you running Bazel on?


N/A

### What is the output of `bazel info release`?


N/A

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.


N/A

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?


```text
N/A
```


### Have you found anything relevant by searching the web?

_No response_

### Any other information, logs, or outputs that you want to share?

_No response_

Issue comments:
@bazel-io flag
@bazel-io fork 5.3.0
Since this feature is implemented and cherry picked to 5.3.0, should we close this one?
The proposal hasn't been fully implemented yet (e.g. we're missing support for repository fetching).
Marking this as a release blocker since we want the repository fetching support to make it into 6.0.0 if possible.
@tjgq What's the ETA for implementing this? Ideally, we don't want to delay the 6.0 release further more, and since this should be a backwards compatible feature, we can cherry pick it in 6.x releases?
I was planning to get this submitted in time for 6.0.0, but other things got in the way. Let's do it for a 6.x release instead.
This has been fully implemented in 7.x and backported to 6.x.

Pull request review comments:

Patch that resolved the issue:
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
index 9d6919cf83c10d..967ac115f213f5 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
@@ -104,6 +104,7 @@ public class CommandEnvironment {
   private final ImmutableList<Any> commandExtensions;
   private final ImmutableList.Builder<Any> responseExtensions = ImmutableList.builder();
   private final Consumer<String> shutdownReasonConsumer;
+  private final CommandLinePathFactory commandLinePathFactory;
 
   private OutputService outputService;
   private TopDownActionCache topDownActionCache;
@@ -266,6 +267,9 @@ public void exit(AbruptExitException exception) {
         repoEnvFromOptions.put(name, value);
       }
     }
+
+    this.commandLinePathFactory =
+        CommandLinePathFactory.create(runtime.getFileSystem(), directories);
   }
 
   private Path computeWorkingDirectory(CommonCommandOptions commandOptions)
@@ -840,4 +844,8 @@ public ImmutableList<Any> getResponseExtensions() {
   public void addResponseExtensions(Iterable<Any> extensions) {
     responseExtensions.addAll(extensions);
   }
+
+  public CommandLinePathFactory getCommandLinePathFactory() {
+    return commandLinePathFactory;
+  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandLinePathFactory.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandLinePathFactory.java
index e39bf074b2d91c..074bda748af98d 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommandLinePathFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandLinePathFactory.java
@@ -13,10 +13,12 @@
 // limitations under the License.
 package com.google.devtools.build.lib.runtime;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Splitter;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableMap;
+import com.google.devtools.build.lib.analysis.BlazeDirectories;
 import com.google.devtools.build.lib.vfs.FileSystem;
 import com.google.devtools.build.lib.vfs.Path;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -44,11 +46,27 @@ public final class CommandLinePathFactory {
   private final FileSystem fileSystem;
   private final ImmutableMap<String, Path> roots;
 
+  @VisibleForTesting
   public CommandLinePathFactory(FileSystem fileSystem, ImmutableMap<String, Path> roots) {
     this.fileSystem = Preconditions.checkNotNull(fileSystem);
     this.roots = Preconditions.checkNotNull(roots);
   }
 
+  static CommandLinePathFactory create(FileSystem fileSystem, BlazeDirectories directories) {
+    Preconditions.checkNotNull(fileSystem);
+    Preconditions.checkNotNull(directories);
+
+    ImmutableMap.Builder<String, Path> wellKnownRoots = ImmutableMap.builder();
+
+    // This is necessary because some tests don't have a workspace set.
+    Path workspace = directories.getWorkspace();
+    if (workspace != null) {
+      wellKnownRoots.put("workspace", workspace);
+    }
+
+    return new CommandLinePathFactory(fileSystem, wellKnownRoots.build());
+  }
+
   /** Creates a {@link Path}. */
   public Path create(Map<String, String> env, String value) throws IOException {
     Preconditions.checkNotNull(env);


Test patch: