Skip to content

Conversation

@enocom
Copy link
Member

@enocom enocom commented Oct 7, 2022

Note: the CLI flag matches the gcloud UI.

Fixes #417

@enocom enocom requested a review from a team October 7, 2022 18:15
@enocom
Copy link
Member Author

enocom commented Oct 7, 2022

~361 lines of this PR are just cleaning up our e2e authentication tests to be table tests, and adding a matching impersonation test for each authentication type.

@enocom
Copy link
Member Author

enocom commented Oct 7, 2022

Also, I've updated our CI pipeline to support impersonation as well.

Copy link
Collaborator

@hessjcg hessjcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

TargetPrincipal: c.ImpersonateTarget,
Delegates: c.ImpersonateDelegates,
Scopes: []string{
sqladmin.CloudPlatformScope,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need CloudPlatform here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check on that -- we did for the e2e tests using the token.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it here. It's the token source that gets the impersonated token that needs this scope. Removed it here, and removed the SQL Admin scope from the token source in the tests.

func (c *Config) DialerOptions(l cloudsql.Logger) ([]cloudsqlconn.Option, error) {
opts := []cloudsqlconn.Option{
cloudsqlconn.WithUserAgent(c.UserAgent),
func (c *Config) credentialsOpt(l cloudsql.Logger) (cloudsqlconn.Option, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like it modifies c in anyway. Would it be better to take c as an arg instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm in favor of that idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, I see we're reading a bunch of data from c. So even though we're not modifying it, it's still common to define c as a receiver. Passing it as an argument would basically be a de-sugared version of the same code here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

downgrade to nit: but it does seem like a receiver indicates we are doing something to c, where a read only parameter makes clear in the intent is only to create something from c.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me try that in a separate PR and we can apply the pattern across the board if we like it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enocom
Copy link
Member Author

enocom commented Oct 12, 2022

I need to verify the delegation logic here. I've matched gcloud's behavior, but need to check if the Go library does the same (back to front).

func (c *Config) DialerOptions(l cloudsql.Logger) ([]cloudsqlconn.Option, error) {
opts := []cloudsqlconn.Option{
cloudsqlconn.WithUserAgent(c.UserAgent),
func (c *Config) credentialsOpt(l cloudsql.Logger) (cloudsqlconn.Option, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

downgrade to nit: but it does seem like a receiver indicates we are doing something to c, where a read only parameter makes clear in the intent is only to create something from c.

func removeAuthEnvVar(t *testing.T) (*oauth2.Token, string, func()) {
ts, err := google.DefaultTokenSource(context.Background(), sqladmin.SqlserviceAdminScope)
ts, err := google.DefaultTokenSource(context.Background(),
"https://www.googleapis.com/auth/cloud-platform",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need cloud-platform here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short answer: the impersonation fails without this scope. Longer answer: let me figure out if we can limit this scope still further.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enocom enocom merged commit d0f8e55 into main Oct 14, 2022
@enocom enocom deleted the impersonation branch October 14, 2022 18:45
enocom added a commit to GoogleCloudPlatform/alloydb-auth-proxy that referenced this pull request Dec 7, 2022
enocom added a commit to GoogleCloudPlatform/alloydb-auth-proxy that referenced this pull request Dec 7, 2022
enocom added a commit to GoogleCloudPlatform/alloydb-auth-proxy that referenced this pull request Dec 7, 2022
enocom added a commit to GoogleCloudPlatform/alloydb-auth-proxy that referenced this pull request Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for --impersonate-service-account

3 participants