Skip to content

Commit

Permalink
add support for external_account in another location
Browse files Browse the repository at this point in the history
  • Loading branch information
ddowker committed Sep 17, 2024
1 parent 564fc53 commit 6a6de9d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion broker/client/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"bufio"
"context"
"encoding/json"
"crypto/tls"
"errors"
"fmt"
Expand Down Expand Up @@ -500,6 +501,11 @@ func (s *gcsBackend) open(ctx context.Context, ep *url.URL, fragment pb.Fragment
return gClient.Bucket(cfg.bucket).Object(cfg.rewritePath(cfg.prefix, fragment.ContentPath())).NewReader(ctx)
}

/ to help identify when JSON credentials are an external account used by workload identity
type credentialsFile struct {
Type string `json:"type"`
}

func (s *gcsBackend) gcsClient(ep *url.URL) (cfg GSStoreConfig, client *storage.Client, err error) {
var conf *jwt.Config

Expand All @@ -522,7 +528,18 @@ func (s *gcsBackend) gcsClient(ep *url.URL) (cfg GSStoreConfig, client *storage.
creds, err := google.FindDefaultCredentials(ctx, storage.ScopeFullControl)
if err != nil {
return
} else if creds.JSON != nil {
}

// best effort to determine if JWT credentials are for external account
externalAccount := false
if creds.JSON != nil {
var f credentialsFile
if err := json.Unmarshal(creds.JSON, &f); err == nil {
externalAccount = f.Type == "external_account"
}
}

if creds.JSON != nil && !externalAccount {
conf, err = google.JWTConfigFromJSON(creds.JSON, storage.ScopeFullControl)
if err != nil {
return
Expand Down

0 comments on commit 6a6de9d

Please sign in to comment.