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

fix(auth): check compute cred type before non-default flag for DP #11255

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
6 changes: 3 additions & 3 deletions auth/grpctransport/directpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func isTokenProviderDirectPathCompatible(tp auth.TokenProvider, o *Options) bool
if tok == nil {
return false
}
if o.InternalOptions != nil && o.InternalOptions.EnableNonDefaultSAForDirectPath {
return true
}
if tok.MetadataString("auth.google.tokenSource") != "compute-metadata" {
return false
}
if o.InternalOptions != nil && o.InternalOptions.EnableNonDefaultSAForDirectPath {
return true
}
if tok.MetadataString("auth.google.serviceAccount") != "default" {
return false
}
Expand Down
16 changes: 15 additions & 1 deletion auth/grpctransport/directpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,28 @@ func TestIsTokenProviderDirectPathCompatible(t *testing.T) {
},
{
name: "EnableNonDefaultSAForDirectPath",
tp: &staticTP{tok: &auth.Token{Value: "fakeToken"}},
tp: &staticTP{
tok: token(map[string]interface{}{
"auth.google.tokenSource": "compute-metadata",
}),
},
opts: &Options{
InternalOptions: &InternalOptions{
EnableNonDefaultSAForDirectPath: true,
},
},
want: true,
},
{
name: "EnableNonDefaultSAForDirectPathButNotCompute",
tp: &staticTP{},
opts: &Options{
InternalOptions: &InternalOptions{
EnableNonDefaultSAForDirectPath: true,
},
},
want: false,
},
{
name: "non-compute token source",
tp: &staticTP{tok: token(map[string]interface{}{"auth.google.tokenSource": "NOT-compute-metadata"})},
Expand Down
Loading