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

feat: service sccount to service account impersonation to support universe domain #1528

Merged
merged 25 commits into from
Oct 18, 2024

Conversation

zhumin8
Copy link
Contributor

@zhumin8 zhumin8 commented Oct 4, 2024

for context: b/340602527

Changes in this pr:

Not in this pr:

  • idtoken and signBlob endpoint changes are out-of-scope for this pr, will raise separate pr for it.

sa-to-sa impersonation is successfully E2E tested for TPC usage according to go/prptst-testing-service-account-impersonation.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Oct 4, 2024
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Oct 10, 2024
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Oct 10, 2024
@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Oct 11, 2024
@zhumin8 zhumin8 changed the title Service Account-to-Service Account Impersonation to support universe domain feat: service sccount to service account impersonation to support universe domain Oct 11, 2024
@zhumin8 zhumin8 marked this pull request as ready for review October 11, 2024 18:49
@zhumin8 zhumin8 requested review from a team as code owners October 11, 2024 18:49
} catch (IOException e) {
throw new IOException("Unable to refresh sourceCredentials", e);
// skip for nonGDU because it uses self-signed JWT
// and will get refreshed at initialize request step
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not sure why this call is required for GDU but not required for nonGDU, is there any feature that is only supported in GDU?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am convinced that this is not needed for nonGDU, reasons in description above.
For GDU, I am not 100% convinced that this is required before initialize step. But out of precautious, I do not want to change the flow for GDU in this pr. I will raise a separate issue to investigate for GDU flow.

Copy link
Contributor

Choose a reason for hiding this comment

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

to answer Blake's question - GDU has token endpoint, nonGDU does not :)

SSJ is a primary flow is GDU now as well. This should be a fallback scenario if SSJ is disabled, execute conditionally if SSJ flag is disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated condition to also skip for GDU SSJ flow.

@@ -724,6 +787,12 @@ public Calendar getCalendar() {
return this.calendar;
}

@Override
public Builder setUniverseDomain(String universeDomain) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we have to override this method as it is already public in the parent. I noticed that it seems we are overriding the builder methods in other subclasses of the builder, but I think that was a mistake.

Copy link
Contributor Author

@zhumin8 zhumin8 Oct 11, 2024

Choose a reason for hiding this comment

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

I debated this in my mind. One benefit I see overriding the setter allows for a fluent builder API where method calls can be chained without requiring explicit casting to ImpersonatedCredentials. In this case, I feel it provides a slightly better experience for users setting explicit UD
So user can do

        ImpersonatedCredentials.newBuilder()
            .setUniverseDomain("explicit.domain.com");

instead of casting:

        (ImpersonatedCredentials) ImpersonatedCredentials.newBuilder()
            .setUniverseDomain("explicit.domain.com");

While generally it's best to avoid overriding public methods if possible, override setters in Builders is kind of a special case and more acceptable. .e.g. overriding Builder setters seems to be a pattern in other libraries like Guava (example)

One other concern is removing other overrides in other credential classes will be breaking change to customers code.
That said, I don't feel too strongly about this, and I believe exposing this setter is not a hard requirement for now. If you have any other concerns, I can remove this for now. What do you think?

Copy link
Contributor

@blakeli0 blakeli0 Oct 14, 2024

Choose a reason for hiding this comment

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

I don't think customers have to cast the credential to ImpersonatedCredentials to setUniverseDomain(), I verified in my local that it works. Can you please double check it?
For the Guava example, yes they are doing it because there are some additional logics, but we are not doing anything special other than calling super.setUniverseDomain(). So I think we can delete it at this moment and add it later if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Confirming that explicit overrides were added to avoid casting.

Copy link
Contributor

@blakeli0 blakeli0 Oct 15, 2024

Choose a reason for hiding this comment

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

Min and I confirmed that we do need explicit casting right now. However, the problem is that the parent builder's setters should return the child types. I created a demo PR for a potential fix. Also see how protobuf's GeneratedMessageV3 does it.

That being said, this should be separate problem to solve, so it's OK to override the parent's setters right now.

super.getRequestMetadata(uri, executor, callback);
}
} catch (IOException e) {
// Wrap it here to avoid breaking change.
Copy link
Contributor

Choose a reason for hiding this comment

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

What would be a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added to comment, to throw IOException would be breaking.

@@ -266,8 +266,8 @@ protected boolean isExplicitUniverseDomain() {
* @return true if universeDomain equals to {@link Credentials#GOOGLE_DEFAULT_UNIVERSE}, false
Copy link
Contributor

Choose a reason for hiding this comment

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

update docs?

Copy link
Contributor

@TimurSadykov TimurSadykov left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@TimurSadykov TimurSadykov left a comment

Choose a reason for hiding this comment

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

Overall looks good, there is a pending discussion on explicit UD

@zhumin8
Copy link
Contributor Author

zhumin8 commented Oct 17, 2024

@blakeli0 @TimurSadykov Can you please take another look? Changes since you last reviewed:
Updated with changes to reflect internal discussion to throw for explicit set universe domain not matching source credential's ud.
Also updated condition to skip refreshIfExpired() to include gdu w/ ssj flow.
Added tests for these changes.

note: kokoro tests are failing because trampoline is disabled at the moment.

Copy link

Copy link
Contributor

@TimurSadykov TimurSadykov left a comment

Choose a reason for hiding this comment

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

LGTM

@zhumin8 zhumin8 merged commit c498ccf into main Oct 18, 2024
18 checks passed
@zhumin8 zhumin8 deleted the sa-2-sa branch October 18, 2024 19:44
@lsirac lsirac requested a review from aeitzman October 31, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants