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: Improve impersonation support. #2394

Merged

Conversation

amanda-tarafa
Copy link
Contributor

No description provided.

@amanda-tarafa amanda-tarafa requested a review from a team as a code owner April 22, 2023 00:37
@amanda-tarafa
Copy link
Contributor Author

@jskeet as always one commit at a time. The first commit is unrelated, but it's something that I caught while running the tests.

Copy link
Collaborator

@jskeet jskeet left a comment

Choose a reason for hiding this comment

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

I suspect this is all fine, but let's chat before merging.

""type"": ""authorized_user""
},
""type"": ""impersonated_service_account""}";
private const string RecursiveImpersonatedServiceAccountCredential = @"{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Possibly add a blank line between each of these service credentials? (Or better yet, maybe now's a good time to move them to resource files that we load? That way we don't need the quote doubling etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving to files on the latest commit.

}

// If source credential is of a credential type that does not support impersonation, attemting to create the
// impersonated credential will faill a few lines after.
Copy link
Collaborator

Choose a reason for hiding this comment

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

faill => fail (and I'd personally use "later" instead of "after" but the meaning is clear)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, both done.

/// <summary>
/// ImpersonatedCredential is created by the GCloud SDK tool when the user runs
/// <a href="https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login">GCloud Auth ADC Login</a>
/// using the <a href="https://cloud.google.com/sdk/gcloud/reference#--impersonate-service-account">--impersonate-service-accont</a>
Copy link
Collaborator

Choose a reason for hiding this comment

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

accont => account (assuming there's no typo in gcloud itself)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Luckily the typo is just mine, changing.

@TimurSadykov
Copy link
Member

passing by comment ) Thanks!

amanda-tarafa added a commit to amanda-tarafa/google-api-dotnet-client that referenced this pull request Apr 24, 2023
Copy link
Contributor Author

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

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

@jskeet the las commit contains the changes to DefaultCredentialProvider tests.

The other couple requests are squashed in their respective commits, they were typos.

""type"": ""authorized_user""
},
""type"": ""impersonated_service_account""}";
private const string RecursiveImpersonatedServiceAccountCredential = @"{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving to files on the latest commit.

}

// If source credential is of a credential type that does not support impersonation, attemting to create the
// impersonated credential will faill a few lines after.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, both done.

/// <summary>
/// ImpersonatedCredential is created by the GCloud SDK tool when the user runs
/// <a href="https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login">GCloud Auth ADC Login</a>
/// using the <a href="https://cloud.google.com/sdk/gcloud/reference#--impersonate-service-account">--impersonate-service-accont</a>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Luckily the typo is just mine, changing.

Copy link
Collaborator

@jskeet jskeet left a comment

Choose a reason for hiding this comment

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

Much nicer :)

@@ -34,6 +35,25 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="OAuth2\DummyCredentialFiles\aws_workforce_external_account_credential.json" />
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason for not just using OAuth2\DummyCredentialFiles\*.json here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just because I marked the files as embeded with right click on VS, but yes, this is better, changing. :)


protected override Stream GetStream(string filePath)
{
if (!fileContents.ContainsKey(filePath))
if (!pathToFileName.TryGetValue(filePath, out var resourcaName))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: resourcaName => resourceName

And maybe just:

var resourceName = pathToFileName.TryGetValue(filePath, out var mappedPath) ? mappedPath : filePath;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, done on both.

Documentation does not specify the exact reason given on each case and this seems to have changed recently.
StatusCode continues to be the same.
See: https://developers.google.com/identity/protocols/oauth2/web-server#httprest_8
- Move all dummy credentials to files that are loaded as resources.
- Use Assert.Throws instead of try ... catch.
Copy link
Contributor Author

@amanda-tarafa amanda-tarafa left a comment

Choose a reason for hiding this comment

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

Both comments addressed.

I'll merge on green, thanks!

@@ -34,6 +35,25 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="OAuth2\DummyCredentialFiles\aws_workforce_external_account_credential.json" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just because I marked the files as embeded with right click on VS, but yes, this is better, changing. :)


protected override Stream GetStream(string filePath)
{
if (!fileContents.ContainsKey(filePath))
if (!pathToFileName.TryGetValue(filePath, out var resourcaName))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, done on both.

@amanda-tarafa amanda-tarafa merged commit 0b8714c into googleapis:main Apr 25, 2023
4 checks passed
@amanda-tarafa amanda-tarafa deleted the impersonation-improvements branch April 25, 2023 08:10
amanda-tarafa added a commit to amanda-tarafa/google-api-dotnet-client that referenced this pull request Jun 14, 2023
Features

- googleapis#2429 Utilities for date/time parsing.
- googleapis#2394 Which improves impersonation support.
- googleapis#2349 and googleapis#2379 Which improve error reported when ADC is not configured.
amanda-tarafa added a commit that referenced this pull request Jun 14, 2023
Features

- #2429 Utilities for date/time parsing.
- #2394 Which improves impersonation support.
- #2349 and #2379 Which improve error reported when ADC is not configured.
amanda-tarafa added a commit to amanda-tarafa/google-api-dotnet-client that referenced this pull request Jun 26, 2023
Updates support version: 1.61.0 - beta02 -> 1.61.0

Features

- Improvements for  date/time parsing.
  - googleapis#2441
  - googleapis#2432
  - googleapis#2429
- googleapis#2435 PKCE support.
- googleapis#2394 Which improves impersonation support.
- googleapis#2349 and googleapis#2379 Which improve error reported when ADC is not configured.
amanda-tarafa added a commit that referenced this pull request Jun 26, 2023
Updates support version: 1.61.0 - beta02 -> 1.61.0

Features

- Improvements for  date/time parsing.
  - #2441
  - #2432
  - #2429
- #2435 PKCE support.
- #2394 Which improves impersonation support.
- #2349 and #2379 Which improve error reported when ADC is not configured.
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.

None yet

3 participants