Skip to content

Commit 5617ad8

Browse files
committed
fix: Set the universe domain when using an impersonation chain.
This change ensures that the universe domain configuration is correctly passed when setting up an impersonation chain for credentials. It also introduces internal test infrastructure to mock `impersonate.CredentialsTokenSource` and adds a unit test `TestCredentialsOpt` to verify this behavior.
1 parent 5b14b6a commit 5617ad8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

internal/proxy/proxy.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
package proxy
1616

1717
import (
18+
"cloud.google.com/go/cloudsqlconn"
1819
"context"
1920
"fmt"
21+
"github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/cloudsql"
22+
"github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/internal/gcloud"
23+
"golang.org/x/oauth2"
24+
"google.golang.org/api/impersonate"
25+
"google.golang.org/api/option"
26+
"google.golang.org/api/sqladmin/v1"
2027
"io"
2128
"net"
2229
"os"
@@ -26,14 +33,6 @@ import (
2633
"sync"
2734
"sync/atomic"
2835
"time"
29-
30-
"cloud.google.com/go/cloudsqlconn"
31-
"github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/cloudsql"
32-
"github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/internal/gcloud"
33-
"golang.org/x/oauth2"
34-
"google.golang.org/api/impersonate"
35-
"google.golang.org/api/option"
36-
"google.golang.org/api/sqladmin/v1"
3736
)
3837

3938
var (
@@ -342,6 +341,9 @@ func credentialsOpt(c Config, l cloudsql.Logger) (cloudsqlconn.Option, error) {
342341
// credentials token source.
343342
if c.ImpersonationChain != "" {
344343
var iopts []option.ClientOption
344+
if c.UniverseDomain != "" {
345+
iopts = append(iopts, option.WithUniverseDomain(c.UniverseDomain))
346+
}
345347
switch {
346348
case c.Token != "":
347349
l.Infof("Impersonating service account with OAuth2 token")

0 commit comments

Comments
 (0)