Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arize dev/workload identity support #6

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions broker/fragment/store_gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fragment

import (
"context"
"fmt"
"io"
"net/url"
"strings"
Expand All @@ -13,6 +12,7 @@ import (
log "github.com/sirupsen/logrus"
pb "go.gazette.dev/core/broker/protocol"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
)
Expand Down Expand Up @@ -133,6 +133,8 @@ func (s *gcsBackend) Remove(ctx context.Context, fragment pb.Fragment) error {
}

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

if err = parseStoreArgs(ep, &cfg); err != nil {
return
}
Expand All @@ -153,31 +155,43 @@ 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 {
err = fmt.Errorf("use of GCS requires that a service-account private key be supplied with application default credentials")
return
}
conf, err := google.JWTConfigFromJSON(creds.JSON, storage.ScopeFullControl)
if err != nil {
return
}
client, err = storage.NewClient(ctx, option.WithTokenSource(conf.TokenSource(ctx)))
if err != nil {
return
}
opts = storage.SignedURLOptions{
GoogleAccessID: conf.Email,
PrivateKey: conf.PrivateKey,
} else if creds.JSON != nil {
conf, err = google.JWTConfigFromJSON(creds.JSON, storage.ScopeFullControl)
if err != nil {
return
}
client, err = storage.NewClient(ctx, option.WithTokenSource(conf.TokenSource(ctx)))
if err != nil {
return
}
opts = storage.SignedURLOptions{
GoogleAccessID: conf.Email,
PrivateKey: conf.PrivateKey,
}
s.client, s.signedURLOptions = client, opts

log.WithFields(log.Fields{
"ProjectID": creds.ProjectID,
"GoogleAccessID": conf.Email,
"PrivateKeyID": conf.PrivateKeyID,
"Subject": conf.Subject,
"Scopes": conf.Scopes,
}).Info("constructed new GCS client")
} else {
// Possible to use GCS without a service account (e.g. with a GCE instance and workload identity).
client, err = storage.NewClient(ctx, option.WithTokenSource(creds.TokenSource))
if err != nil {
return
}

s.client = client

// Note: SignGet() also works with empty signedURLOptions.

log.WithFields(log.Fields{
"ProjectID": creds.ProjectID,
}).Info("constructed new GCS client without JWT")
}
s.client, s.signedURLOptions = client, opts

log.WithFields(log.Fields{
"ProjectID": creds.ProjectID,
"GoogleAccessID": conf.Email,
"PrivateKeyID": conf.PrivateKeyID,
"Subject": conf.Subject,
"Scopes": conf.Scopes,
}).Info("constructed new GCS client")

return
}
Loading