Skip to content

Commit e59aa6a

Browse files
auth-subject
Sumary: - Support for `sub` field in auth context, denoting subject. - Motivating use case is email address based impersonation of google users by service account principals.
1 parent 5b7fb04 commit e59aa6a

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/spf13/cobra v1.4.0
2222
github.com/spf13/pflag v1.0.5
2323
github.com/spf13/viper v1.10.1
24-
github.com/stackql/any-sdk v0.0.3-beta09
24+
github.com/stackql/any-sdk v0.0.3-beta11
2525
github.com/stackql/go-suffix-map v0.0.1-alpha01
2626
github.com/stackql/psql-wire v0.1.1-alpha07
2727
github.com/stackql/stackql-parser v0.0.14-alpha04

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
471471
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
472472
github.com/spf13/viper v1.10.1 h1:nuJZuYpG7gTj/XqiUwg8bA0cp1+M2mC3J4g5luUYBKk=
473473
github.com/spf13/viper v1.10.1/go.mod h1:IGlFPqhNAPKRxohIzWpI5QEy4kuI7tcl5WvR+8qy1rU=
474-
github.com/stackql/any-sdk v0.0.3-beta09 h1:1Ddl3cpkaLC+3XXkEyAkKeunhMbYwRkWE4iPnTr+TfE=
475-
github.com/stackql/any-sdk v0.0.3-beta09/go.mod h1:CIMFo3fC2ScpqzkzeCkzUQQuzYA1VuqpG0p1EZXN+wY=
474+
github.com/stackql/any-sdk v0.0.3-beta11 h1:9cqA3Rzwkkwb4kupO95sa0FK5pBvRWJW4AbqFK7u2Xk=
475+
github.com/stackql/any-sdk v0.0.3-beta11/go.mod h1:CIMFo3fC2ScpqzkzeCkzUQQuzYA1VuqpG0p1EZXN+wY=
476476
github.com/stackql/go-suffix-map v0.0.1-alpha01 h1:TDUDS8bySu41Oo9p0eniUeCm43mnRM6zFEd6j6VUaz8=
477477
github.com/stackql/go-suffix-map v0.0.1-alpha01/go.mod h1:QAi+SKukOyf4dBtWy8UMy+hsXXV+yyEE4vmBkji2V7g=
478478
github.com/stackql/psql-wire v0.1.1-alpha07 h1:LQWVUlx4Bougk6dztDNG5tmXxpIVeeTSsInTj801xCs=

internal/stackql/dto/auth_ctx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type AuthCtx struct {
2828
EnvVarPassword string `json:"password_var" yaml:"password_var"`
2929
EncodedBasicCredentials string `json:"-" yaml:"-"`
3030
Successor *AuthCtx `json:"successor" yaml:"successor"`
31+
Subject string `json:"sub" yaml:"sub"`
3132
Active bool `json:"-" yaml:"-"`
3233
Location string `json:"location" yaml:"location"`
3334
Name string `json:"name" yaml:"name"`

internal/stackql/handler/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ func GetHandlerCtx(
521521
func transformOpenapiStackqlAuthToLocal(authDTO anysdk.AuthDTO) *dto.AuthCtx {
522522
rv := &dto.AuthCtx{
523523
Scopes: authDTO.GetScopes(),
524+
Subject: authDTO.GetSubject(),
524525
Type: authDTO.GetType(),
525526
ValuePrefix: authDTO.GetValuePrefix(),
526527
KeyID: authDTO.GetKeyID(),

internal/stackql/provider/auth_util.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,19 @@ func parseServiceAccountFile(ac *dto.AuthCtx) (serviceAccount, error) {
161161
return c, json.Unmarshal(b, &c)
162162
}
163163

164-
func getJWTConfig(provider string, credentialsBytes []byte, scopes []string) (*jwt.Config, error) {
164+
func getJWTConfig(provider string, credentialsBytes []byte, scopes []string, subject string) (*jwt.Config, error) {
165165
switch provider {
166166
case "google", "googleads", "googleanalytics",
167167
"googledevelopers", "googlemybusiness", "googleworkspace",
168168
"youtube", "googleadmin":
169-
return google.JWTConfigFromJSON(credentialsBytes, scopes...)
169+
rv, err := google.JWTConfigFromJSON(credentialsBytes, scopes...)
170+
if err != nil {
171+
return nil, err
172+
}
173+
if subject != "" {
174+
rv.Subject = subject
175+
}
176+
return rv, nil
170177
default:
171178
return nil, fmt.Errorf("service account auth for provider = '%s' currently not supported", provider)
172179
}
@@ -182,7 +189,7 @@ func oauthServiceAccount(
182189
if err != nil {
183190
return nil, fmt.Errorf("service account credentials error: %w", err)
184191
}
185-
config, errToken := getJWTConfig(provider, b, scopes)
192+
config, errToken := getJWTConfig(provider, b, scopes, authCtx.Subject)
186193
if errToken != nil {
187194
return nil, errToken
188195
}

0 commit comments

Comments
 (0)