@@ -12,6 +12,7 @@ import (
12
12
"github.com/buildbuddy-io/buildbuddy/enterprise/server/remote_execution/platform"
13
13
"github.com/buildbuddy-io/buildbuddy/enterprise/server/util/ci_runner_util"
14
14
"github.com/buildbuddy-io/buildbuddy/enterprise/server/workflow/config"
15
+ "github.com/buildbuddy-io/buildbuddy/proto/auditlog"
15
16
"github.com/buildbuddy-io/buildbuddy/server/endpoint_urls/build_buddy_url"
16
17
"github.com/buildbuddy-io/buildbuddy/server/endpoint_urls/cache_api_url"
17
18
"github.com/buildbuddy-io/buildbuddy/server/endpoint_urls/events_api_url"
@@ -30,9 +31,11 @@ import (
30
31
"github.com/google/uuid"
31
32
"google.golang.org/genproto/googleapis/longrunning"
32
33
"google.golang.org/grpc/metadata"
34
+ "google.golang.org/protobuf/encoding/protojson"
33
35
"google.golang.org/protobuf/types/known/durationpb"
34
36
"gopkg.in/yaml.v2"
35
37
38
+ fcpb "github.com/buildbuddy-io/buildbuddy/proto/firecracker"
36
39
repb "github.com/buildbuddy-io/buildbuddy/proto/remote_execution"
37
40
rnpb "github.com/buildbuddy-io/buildbuddy/proto/runner"
38
41
gstatus "google.golang.org/grpc/status"
@@ -420,6 +423,7 @@ func (r *runnerService) Run(ctx context.Context, req *rnpb.RunRequest) (*rnpb.Ru
420
423
return nil , status .WrapError (err , "get credentials" )
421
424
}
422
425
426
+ var hasBESOverride bool
423
427
for _ , h := range req .GetRemoteHeaders () {
424
428
parts := strings .SplitN (h , "=" , 2 )
425
429
if len (parts ) != 2 {
@@ -432,6 +436,10 @@ func (r *runnerService) Run(ctx context.Context, req *rnpb.RunRequest) (*rnpb.Ru
432
436
// to credential-related env overrides that were set above.
433
437
if headerKey == platform .OverrideHeaderPrefix + platform .EnvOverridesPropertyName {
434
438
envOverrides = append (envOverrides , headerVal )
439
+
440
+ if strings .HasPrefix (headerVal , "BUILDBUDDY_BES_API_KEY=" ) {
441
+ hasBESOverride = true
442
+ }
435
443
continue
436
444
}
437
445
@@ -441,6 +449,16 @@ func (r *runnerService) Run(ctx context.Context, req *rnpb.RunRequest) (*rnpb.Ru
441
449
execCtx = platform .WithRemoteHeaderOverride (
442
450
execCtx , platform .EnvOverridesPropertyName , strings .Join (envOverrides , "," ))
443
451
452
+ if hasBESOverride {
453
+ snapshotKeyStr := getExecProperty (req .GetExecProperties (), "snapshot-key-override" )
454
+ snapshotKey := & fcpb.SnapshotKey {}
455
+ if err := protojson .Unmarshal ([]byte (snapshotKeyStr ), snapshotKey ); err != nil {
456
+ return nil , status .WrapError (err , "unmarshal SnapshotKey" )
457
+ }
458
+ // TODO: Make sure this is logging for the correct group
459
+ r .env .GetAuditLogger ().LogForGroup (ctx , req .GetRequestContext ().GetGroupId (), auditlog .Action_IMPERSONATE_REMOTE_RUN , snapshotKey )
460
+ }
461
+
444
462
executionClient := r .env .GetRemoteExecutionClient ()
445
463
if executionClient == nil {
446
464
return nil , status .UnimplementedError ("Missing remote execution client." )
0 commit comments