Skip to content

Commit 7969d9b

Browse files
author
Ryan Kohler
committed
google/externalaccount: add support for workforce pool credentials
1 parent 2bc19b1 commit 7969d9b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

google/google.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ type credentialsFile struct {
123123
ServiceAccountImpersonationURL string `json:"service_account_impersonation_url"`
124124
CredentialSource externalaccount.CredentialSource `json:"credential_source"`
125125
QuotaProjectID string `json:"quota_project_id"`
126+
WorkforcePoolUserProject string `json:"workforce_pool_user_project"`
126127
}
127128

128129
func (f *credentialsFile) jwtConfig(scopes []string, subject string) *jwt.Config {
@@ -176,6 +177,7 @@ func (f *credentialsFile) tokenSource(ctx context.Context, params CredentialsPar
176177
CredentialSource: f.CredentialSource,
177178
QuotaProjectID: f.QuotaProjectID,
178179
Scopes: params.Scopes,
180+
WorkforcePoolUserProject: f.WorkforcePoolUserProject,
179181
}
180182
return cfg.TokenSource(ctx)
181183
case "":

google/internal/externalaccount/basecredentials.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ type Config struct {
5353
QuotaProjectID string
5454
// Scopes contains the desired scopes for the returned access token.
5555
Scopes []string
56+
// The optional workforce pool user project number when the credential
57+
// corresponds to a workforce pool and not a workload identity pool.
58+
// The underlying principal must still have serviceusage.services.use IAM
59+
// permission to use the project for billing/quota.
60+
WorkforcePoolUserProject string
5661
}
5762

5863
// Each element consists of a list of patterns. validateURLs checks for matches
@@ -224,7 +229,13 @@ func (ts tokenSource) Token() (*oauth2.Token, error) {
224229
ClientID: conf.ClientID,
225230
ClientSecret: conf.ClientSecret,
226231
}
227-
stsResp, err := exchangeToken(ts.ctx, conf.TokenURL, &stsRequest, clientAuth, header, nil)
232+
var options map[string]string
233+
if (ts.Config.WorkforcePoolUserProject != "") {
234+
options = map[string]string{
235+
"userProject": ts.Config.WorkforcePoolUserProject,
236+
}
237+
}
238+
stsResp, err := exchangeToken(ts.ctx, conf.TokenURL, &stsRequest, clientAuth, header, options)
228239
if err != nil {
229240
return nil, err
230241
}

0 commit comments

Comments
 (0)