Skip to content

Add support for service account impersonation #336

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
29 changes: 22 additions & 7 deletions pkg/bigquery/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,35 @@ func getMiddleware(settings types.BigQuerySettings, routePath string) (httpclien
var provider tokenprovider.TokenProvider
switch settings.AuthenticationType {
case "gce":
provider = tokenprovider.NewGceAccessTokenProvider(providerConfig)
if settings.UsingImpersonation {
providerConfig.TargetPrincipal = settings.ServiceAccountToImpersonate
provider = tokenprovider.NewImpersonatedGceAccessTokenProvider(providerConfig)
} else {
provider = tokenprovider.NewGceAccessTokenProvider(providerConfig)
}

case "jwt":
err := validateDataSourceSettings(settings)

if err != nil {
return nil, err
}

providerConfig.JwtTokenConfig = &tokenprovider.JwtTokenConfig{
Email: settings.ClientEmail,
URI: settings.TokenUri,
PrivateKey: []byte(settings.PrivateKey),
if settings.UsingImpersonation {
providerConfig.TargetPrincipal = settings.ServiceAccountToImpersonate
providerConfig.JwtTokenConfig = &tokenprovider.JwtTokenConfig{
Email: settings.ClientEmail,
URI: settings.TokenUri,
PrivateKey: []byte(settings.PrivateKey),
}
provider = tokenprovider.NewImpersonatedJwtAccessTokenProvider(providerConfig)
} else {
providerConfig.JwtTokenConfig = &tokenprovider.JwtTokenConfig{
Email: settings.ClientEmail,
URI: settings.TokenUri,
PrivateKey: []byte(settings.PrivateKey),
}
provider = tokenprovider.NewJwtAccessTokenProvider(providerConfig)
}
provider = tokenprovider.NewJwtAccessTokenProvider(providerConfig)
}

return tokenprovider.AuthMiddleware(provider), nil
Expand Down
26 changes: 14 additions & 12 deletions pkg/bigquery/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import (
)

type BigQuerySettings struct {
DatasourceId int64 `json:"datasourceId"`
ClientEmail string `json:"clientEmail"`
DefaultProject string `json:"defaultProject"`
FlatRateProject string `json:"flatRateProject"`
TokenUri string `json:"tokenUri"`
QueryPriority string `json:"queryPriority"`
ProcessingLocation string `json:"processingLocation"`
MaxBytesBilled int64 `json:"MaxBytesBilled,omitempty"`
Updated time.Time
AuthenticationType string `json:"authenticationType"`
PrivateKeyPath string `json:"privateKeyPath"`
ServiceEndpoint string `json:"serviceEndpoint"`
DatasourceId int64 `json:"datasourceId"`
ClientEmail string `json:"clientEmail"`
DefaultProject string `json:"defaultProject"`
FlatRateProject string `json:"flatRateProject"`
TokenUri string `json:"tokenUri"`
QueryPriority string `json:"queryPriority"`
ProcessingLocation string `json:"processingLocation"`
MaxBytesBilled int64 `json:"MaxBytesBilled,omitempty"`
Updated time.Time
AuthenticationType string `json:"authenticationType"`
PrivateKeyPath string `json:"privateKeyPath"`
ServiceEndpoint string `json:"serviceEndpoint"`
UsingImpersonation bool `json:"usingImpersonation"`
ServiceAccountToImpersonate string `json:"serviceAccountToImpersonate"`

// Saved in secure JSON
PrivateKey string `json:"-"`
Expand Down
Loading