Skip to content

Commit 7e774de

Browse files
Identity docs (#14520)
* Add images to be referenced in docs * update azidentity readme * update armresources refs * format fixes * update header
1 parent b539535 commit 7e774de

File tree

5 files changed

+86
-13
lines changed

5 files changed

+86
-13
lines changed

sdk/azidentity/README.md

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,91 @@ Directory (AAD). It offers a variety of credential types capable of acquiring
6262
an AAD access token. See [Credential Types](#credential-types "Credential Types") below for a list of this module's credential types.
6363

6464
### DefaultAzureCredential
65+
The `DefaultAzureCredential` is appropriate for most scenarios where the application is ultimately intended to run in Azure Cloud. This is because `DefaultAzureCredential` combines credentials commonly used to authenticate when deployed, with credentials used to authenticate in a development environment.
6566

66-
`DefaultAzureCredential` is appropriate for most applications which will run in
67-
the Azure Cloud because it combines common production credentials with
68-
development credentials. `DefaultAzureCredential` attempts to authenticate via
69-
the following mechanisms in this order, stopping when one succeeds:
67+
> Note: `DefaultAzureCredential` is intended to simplify getting started with the SDK by handling common scenarios with reasonable default behaviors. Developers who want more control or whose scenario isn't served by the default settings should use other credential types.
7068
69+
The `DefaultAzureCredential` will attempt to authenticate via the following mechanisms in order.
70+
7171
![DefaultAzureCredential authentication flow](img/DAC_flow.PNG)
7272

73-
- Environment - `DefaultAzureCredential` will read account information specified
74-
via [environment variables](#environment-variables "environment variables")
75-
and use it to authenticate.
76-
- Managed Identity - if the application is deployed to an Azure host with
77-
Managed Identity enabled, `DefaultAzureCredential` will authenticate with it.
78-
- Azure CLI - If a user has signed in via the Azure CLI `az login` command,
79-
`DefaultAzureCredential` will authenticate as that user.
73+
- Environment - The `DefaultAzureCredential` will read account information specified via [environment variables](#environment-variables) and use it to authenticate.
74+
- Managed Identity - If the application is deployed to an Azure host with Managed Identity enabled, the `DefaultAzureCredential` will authenticate with that account.
75+
- Azure CLI - If the developer has authenticated an account via the Azure CLI `az login` command, the `DefaultAzureCredential` will authenticate with that account.
76+
77+
78+
## Examples
79+
You can find more examples of using various credentials in [Azure Identity Examples Wiki page](https://github.com/Azure/azure-sdk-for-go/wiki/Azure-Identity-Examples).
80+
81+
### Authenticating with `DefaultAzureCredential`
82+
This example demonstrates authenticating the `ResourcesClient` from the [armresources][armresources_library] module using `DefaultAzureCredential`.
83+
84+
```go
85+
// The default credential checks environment variables for configuration.
86+
cred, err := azidentity.NewDefaultAzureCredential(nil)
87+
if err != nil {
88+
// handle error
89+
}
90+
91+
// Azure SDK Azure Resource Management clients accept the credential as a parameter
92+
client := armresources.NewResourcesClient(armcore.NewDefaultConnection(cred, nil), "<subscription ID>")
93+
```
94+
95+
See more how to configure the `DefaultAzureCredential` on your workstation or Azure in [Configure DefaultAzureCredential](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication#configure-defaultazurecredential).
96+
97+
### Authenticating a user assigned managed identity with `DefaultAzureCredential`
98+
This example demonstrates authenticating the `ResourcesClient` from the [armresources][armresources_library] module using the `DefaultAzureCredential`, deployed to an Azure resource with a user assigned managed identity configured.
99+
100+
See more about how to configure a user assigned managed identity for an Azure resource in [Enable managed identity for Azure resources](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication#enable-managed-identity-for-azure-resources).
101+
102+
```go
103+
// The default credential will use the user assigned managed identity with the specified client ID.
104+
// The client_ID for the user assigned is set through an environment variable.
105+
cred, err := azidentity.NewDefaultAzureCredential(nil)
106+
if err != nil {
107+
// handle error
108+
}
109+
110+
// Azure SDK Azure Resource Management clients accept the credential as a parameter
111+
client := armresources.NewResourcesClient(armcore.NewDefaultConnection(cred, nil), "<subscription ID>")
112+
```
113+
114+
## Managed Identity Support
115+
The [Managed identity authentication](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview) is supported via either the `DefaultAzureCredential` or the `ManagedIdentityCredential` directly for the following Azure Services:
116+
* [Azure Virtual Machines](https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-token)
117+
* [Azure App Service](https://docs.microsoft.com/azure/app-service/overview-managed-identity?tabs=dotnet)
118+
* [Azure Kubernetes Service](https://docs.microsoft.com/azure/aks/use-managed-identity)
119+
* [Azure Cloud Shell](https://docs.microsoft.com/azure/cloud-shell/msi-authorization)
120+
* [Azure Arc](https://docs.microsoft.com/azure/azure-arc/servers/managed-identity-authentication)
121+
* [Azure Service Fabric](https://docs.microsoft.com/azure/service-fabric/concepts-managed-identity)
122+
123+
### Examples
124+
#### Authenticating in Azure with Managed Identity
125+
This examples demonstrates authenticating the `ResourcesClient` from the [armresources][armresources_library] module using `ManagedIdentityCredential` in a virtual machine, app service, function app, cloud shell, or AKS environment on Azure, with system assigned, or user assigned managed identity enabled.
126+
127+
See more about how to configure your Azure resource for managed identity in [Enable managed identity for Azure resources](https://github.com/Azure/azure-sdk-for-go/wiki/Set-up-Your-Environment-for-Authentication#enable-managed-identity-for-azure-resources)
128+
129+
```go
130+
// Authenticate with a User Assigned Managed Identity.
131+
cred, err := azidentity.NewManagedIdentityCredential("<USER ASSIGNED MANAGED IDENTITY CLIENT ID>", nil) // specify a client_ID for the user assigned identity
132+
if err != nil {
133+
// handle error
134+
}
135+
136+
// Azure SDK Azure Resource Management clients accept the credential as a parameter
137+
client := armresources.NewResourcesClient(armcore.NewDefaultConnection(cred, nil), "<subscription ID>")
138+
```
139+
140+
```go
141+
// Authenticate with a System Assigned Managed Identity.
142+
cred, err := azidentity.NewManagedIdentityCredential("", nil) // do not specify a client_ID to use the system assigned identity
143+
if err != nil {
144+
// handle error
145+
}
146+
147+
// Azure SDK Azure Resource Management clients accept the credential as a parameter
148+
client := armresources.NewResourcesClient(armcore.NewDefaultConnection(cred, nil), "<subscription ID>")
149+
```
80150

81151
## Credential Types
82152

@@ -179,14 +249,16 @@ azcore.Log().SetClassifications(azidentity.LogCredential)
179249
> CAUTION: logs from credentials contain sensitive information.
180250
> These logs must be protected to avoid compromising account security.
181251
182-
# Next steps
252+
## Next steps
253+
254+
The Go client libraries listed [here](https://azure.github.io/azure-sdk/releases/latest/go.html) support authenticating with `TokenCredential` and the Azure Identity library. You can learn more about their use, and find additional documentation on use of these client libraries along samples with can be found in the links mentioned [here](https://azure.github.io/azure-sdk/releases/latest/go.html).
183255

184256
## Provide Feedback
185257

186258
If you encounter bugs or have suggestions, please
187259
[open an issue](https://github.com/Azure/azure-sdk-for-go/issues) and assign the `Azure.Identity` label.
188260

189-
# Contributing
261+
## Contributing
190262

191263
This project welcomes contributions and suggestions. Most contributions require
192264
you to agree to a Contributor License Agreement (CLA) declaring that you have
@@ -206,6 +278,7 @@ or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any
206278
additional questions or comments.
207279

208280
[azure_cli]: https://docs.microsoft.com/cli/azure
281+
[armresources_library]: https://github.com/Azure/azure-sdk-for-go/tree/master/sdk/arm/resources
209282
[azblob]: https://github.com/Azure/azure-sdk-for-go/tree/master/sdk
210283

211284
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-go%2Fsdk%2Fidentity%2Fazure-identity%2FREADME.png)
79.2 KB
Loading
54.2 KB
Loading
54.1 KB
Loading
26.8 KB
Loading

0 commit comments

Comments
 (0)