-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for remote execution APIs
- Loading branch information
Showing
9 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "remoteapis", | ||
srcs = ["remoteapis.go"], | ||
importpath = "github.com/tweag/credential-helper/authenticate/remoteapis", | ||
visibility = ["//visibility:public"], | ||
deps = ["//api"], | ||
) | ||
|
||
filegroup( | ||
name = "all_files", | ||
srcs = glob(["*"]), | ||
visibility = ["//:__subpackages__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package remoteapis | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/tweag/credential-helper/api" | ||
) | ||
|
||
// well-known grpc names (name of the Java package and the name of the service in the .proto file) | ||
const ( | ||
GOOGLE_BYTESTREAM_BYTESTREAM = "google.bytestream.ByteStream" | ||
REMOTE_ASSET_V1_FETCH = "build.bazel.remote.asset.v1.Fetch" | ||
REMOTE_ASSET_V1_PUSH = "build.bazel.remote.asset.v1.Push" | ||
REMOTE_EXECUTION_V2_ACTIONCACHE = "build.bazel.remote.execution.v2.ActionCache" | ||
REMOTE_EXECUTION_V2_CAPABILITIES = "build.bazel.remote.execution.v2.Capabilities" | ||
REMOTE_EXECUTION_V2_CONTENTADDRESSABLESTORAGE = "build.bazel.remote.execution.v2.ContentAddressableStorage" | ||
REMOTE_EXECUTION_V2_EXECUTION = "build.bazel.remote.execution.v2.Execution" | ||
) | ||
|
||
type RemoteAPIs struct{} | ||
|
||
// CacheKey returns a cache key for the given request. | ||
// For remote apis, the full URI is a good cache key. | ||
func (g *RemoteAPIs) CacheKey(req api.GetCredentialsRequest) string { | ||
return req.URI | ||
} | ||
|
||
func (RemoteAPIs) Resolver(ctx context.Context) (api.Resolver, error) { | ||
return &RemoteAPIs{}, nil | ||
} | ||
|
||
// Get implements the get command of the credential-helper spec: | ||
// | ||
// https://github.com/EngFlow/credential-helper-spec/blob/main/spec.md#get | ||
func (g *RemoteAPIs) Get(ctx context.Context, req api.GetCredentialsRequest) (api.GetCredentialsResponse, error) { | ||
parsedURL, error := url.Parse(req.URI) | ||
if error != nil { | ||
return api.GetCredentialsResponse{}, error | ||
} | ||
|
||
// the scheme for remote APIs appears to be https for all of the following: | ||
// - https:// | ||
// - grpc:// | ||
// - grpcs:// | ||
// | ||
// only unencrypted http:// uses a different scheme | ||
// TOOD: check what we do for different schemes | ||
|
||
// the following only works for grpc (and not HTTP/1.1) | ||
rpcName, hasPrefix := strings.CutPrefix(parsedURL.Path, "/") | ||
if !hasPrefix { | ||
return api.GetCredentialsResponse{}, errors.New("remote execution API path must start with /") | ||
} | ||
switch rpcName { | ||
default: | ||
return api.GetCredentialsResponse{}, errors.New("unknown remote execution API") | ||
case GOOGLE_BYTESTREAM_BYTESTREAM: | ||
case REMOTE_ASSET_V1_FETCH: | ||
case REMOTE_ASSET_V1_PUSH: | ||
case REMOTE_EXECUTION_V2_ACTIONCACHE: | ||
case REMOTE_EXECUTION_V2_CAPABILITIES: | ||
case REMOTE_EXECUTION_V2_CONTENTADDRESSABLESTORAGE: | ||
case REMOTE_EXECUTION_V2_EXECUTION: | ||
} | ||
|
||
// bazel-remote only supports basic auth. | ||
// It tries to read the standard grpc metadata key ":authority" to get the username and password. | ||
// This is special header that the credential helper cannot provide. | ||
// As a fallback for proxies, bazel-remote also reads the grpc metadata key "authorization" to get the username and password encoded as a base64 string. | ||
return api.GetCredentialsResponse{ | ||
// Expires: expires, | ||
Headers: map[string][]string{ | ||
// this doesn't work | ||
// ":authority": {"user:pass"}, | ||
// this does work for bazel-remote | ||
// "authorization": {"Basic dXNlcjpwYXNz"}, | ||
// TODO: read config file to learn secret source (env var, secret store, etc.), and the method (basic auth, auth header, etc.) | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ go_library( | |
"//agent/locate", | ||
"//api", | ||
"//helperfactory/string", | ||
"//logging", | ||
], | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"uri": "https://192.168.178.43:9092/build.bazel.remote.execution.v2.Capabilities"} |