Skip to content

add azure_identity::create_credential(), SpecificAzureCredential, AppServiceManagedIdentityCredential, VirtualMachineManagedIdentityCredential #1532

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

Merged
merged 36 commits into from
Jan 16, 2024

Conversation

cataggar
Copy link
Member

@cataggar cataggar commented Jan 1, 2024

Happy new year 2024!

This adds azure_identity::new_credential(), SpecificAzureCredential, AppServiceManagedIdentityCredential, and VirtualMachineManagedIdentityCredential.

  • Similar to azure_core::new_http_client(), azure_identity::create_credential() is a function that simplifies the most common use cases.
  • SpecificAzureCredential fixes add SpecificAzureCredential #1503. It provides an easy and fast way to specify a specific credential type at runtime using an AZURE_CREDENTIAL_KIND environment variable.
  • AppServiceManagedIdentityCredential and VirtualMachineManagedIdentityCredential are split off of and make use of ImdsManagedIdentityCredential. This fixes split up ImdsManagedIdentityCredential #1495.

Most all of the credentials have something similar to create(options: impl into<TokenCredentialOptions>) -> Result<Self> now. This is similar to how C# has TryCreate shown in #1495. They are able to check environment variables or files to see if they can be created, something milliseconds fast. The main exception is VirtualMachineManagedIdentityCredential, which does not have anything quick to check, so it is disabled by default. This is a breaking behavioral change that allows the default credentials to be faster by default. You can still opt in to using them by setting AZURE_CREDENTIAL_KIND to virtualmachine. You can also include them using the DefaultAzureCredentialBuilder.

Manual functional tests of the AppServiceManagedIdentityCredential and VirtualMachineManagedIdentityCredential was completed.

…viceManagedIdentityCredential, VirtualMachineManagedIdentityCredential
Copy link
Contributor

@demoray demoray left a comment

Choose a reason for hiding this comment

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

In general, this is a significant positive step forward.

ClientCertificateCredential {
tenant_id,
client_id,
client_certificate: client_certificate.into(),
client_certificate_pass: client_certificate_pass.into(),
http_client: new_http_client(),
options,
http_client: options.options().http_client().clone(),
Copy link
Contributor

Choose a reason for hiding this comment

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

options.options feels awkward.

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, a little bit awkward. It still felt better than copying all the members.

Comment on lines +41 to +47
pub fn new(
options: impl Into<TokenCredentialOptions>,
endpoint: Url,
api_version: &str,
secret_header: HeaderName,
secret_env: &str,
id: ImdsId,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you discuss the intent for ImdsManagedIdentityCredential in the future?

If this is intended to be used by consumers of the create, I would expect users to not have to know these things, but it's reasonable enable users to change them as appropriate.

If this is intended to be the implementation wrappers like the app service managed identity & virtual machine managed identity, can the visibility be changed to only internal to the crate?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at both the golang and the dotnet implementations, both appear to allow the user to create a Managed Identity client directly and based on trying to initialize each of them in term, picks the underlying implementation that is appropriate.

In dotnet, this is performed here:

https://github.com/Azure/azure-sdk-for-net/blob/5c9c4b9c69185fd08567c2a78d8d715aeabb6cda/sdk/identity/Azure.Identity/src/ManagedIdentityClient.cs#L80-L91

In golang, this is performed here:
https://github.com/Azure/azure-sdk-for-go/blob/2d7b90ad1183eb96d60458a8cef2afeec66f7c29/sdk/azidentity/managed_identity_client.go#L124-L151

To mirror the other SDKs, we will want a Managed Identity Credential that figures out the underlying implementation at initialization. The user should not need to know the endpoint, api version, environment variables, etc.

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, we could add a ManagedIdentityCredential that contains all of the managed identities, but it is essentially just a subset of DefaultAzureCredential. I'm not sure how useful it is. Same with EnvironmentCredential now. Still, probably good to check off the compatibility box.

I expect ImdsManagedIdentityCredential to primarily be for internal use. Feature like AzureArcManagedIdentity #1503 will build off of it. I left it public, primarily for others to be able to build off of it for features we have not implemented.

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding ManagedIdentityCredential would be useful, as it aligns with the different SDK implementations.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree and I will add it after this merges. I created #1536 to track.

Copy link
Member Author

Choose a reason for hiding this comment

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

👆 Relevant for #1659 @johnbatty.

@cataggar cataggar marked this pull request as draft January 4, 2024 15:59
@cataggar cataggar changed the title add azure_identity::new_credential(), SpecificAzureCredential, AppServiceManagedIdentityCredential, VirtualMachineManagedIdentityCredential add azure_identity::create_credential(), SpecificAzureCredential, AppServiceManagedIdentityCredential, VirtualMachineManagedIdentityCredential Jan 6, 2024
@cataggar
Copy link
Member Author

cataggar commented Jan 12, 2024

Testing on a Azure Virtual Machine is complete. I created a VM, scpd the same get_secret binary and the VirtualMachineManagedIdentityCredential worked with the system assigned identity. Some testing notes:

az vm create -g $vm_name -n $vm_name --image $image --admin-username $env.USER --ssh-key-values $'($env.HOME)/.ssh/id_rsa.pub'

I used the portal to add the identity, but it can be done via the CLI too:
https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/qs-configure-cli-windows-vm

@cataggar cataggar marked this pull request as ready for review January 12, 2024 20:25
@cataggar cataggar requested review from demoray and heaths January 12, 2024 21:36
@cataggar
Copy link
Member Author

As we just discussed, I created #1581 as a placeholder for updating the README. This PR is ready to merge.

@heaths heaths force-pushed the SpecificAzureCredential2 branch from bd1104e to 71fac71 Compare January 16, 2024 22:24
@heaths
Copy link
Member

heaths commented Jan 16, 2024

Opened a couple tracking issues for subsequent discussion / work, but nothing to hold up this PR.

///
/// These sources will be tried in the order provided in the `TokenCredential` authentication flow.
pub fn with_sources(sources: Vec<DefaultAzureCredentialEnum>) -> Self {
fn with_sources(sources: Vec<DefaultAzureCredentialKind>) -> Self {
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed pub here. It could be made public, but I'd like to know the use case.

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.

add SpecificAzureCredential split up ImdsManagedIdentityCredential
5 participants