You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 13, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: azure-go-sdk-conceptual/azure-sdk-go-auth-aad-samples.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: Selected samples for working with Azure Active Directory (AAD) and
4
4
author: sptramer
5
5
ms.author: sttramer
6
6
manager: carmonm
7
-
ms.date: 03/21/2018
7
+
ms.date: 09/05/2018
8
8
ms.topic: sample
9
9
ms.prod: azure
10
10
ms.technology: azure-sdk-go
@@ -13,7 +13,7 @@ ms.devlang: go
13
13
---
14
14
# Azure SDK for Go samples for authentication and AAD
15
15
16
-
The following table links to selected samples of Go source code that you can use to authenticate with the Azure SDK for Go and work with Azure Active Directory (AAD) services.
16
+
The following table links to selected samples that demonstrate authentication and use of Azure Active Directory from the Azure SDK for Go.
17
17
18
18
All samples for the Azure SDK for Go are available on [GitHub](https://github.com/Azure-Samples/azure-sdk-for-go-samples).
Copy file name to clipboardExpand all lines: azure-go-sdk-conceptual/azure-sdk-go-authorization.md
+34-17Lines changed: 34 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ services: azure
5
5
author: sptramer
6
6
ms.author: sttramer
7
7
manager: carmonm
8
-
ms.date: 04/03/2018
8
+
ms.date: 09/05/2018
9
9
ms.topic: conceptual
10
10
ms.prod: azure
11
11
ms.technology: azure-sdk-go
@@ -15,19 +15,19 @@ ms.component: authentication
15
15
---
16
16
# Authentication methods in the Azure SDK for Go
17
17
18
-
The Azure SDK for Go offers a variety of authentication types and methods that your application can use. Supported authentication methods range from pulling information from environment variables to interactive web-based authentication. This article introduces you to the available types of authentication in the SDK, and the methods for using them. You'll also learn best practices for selecting which authentication type is right for your application.
18
+
The Azure SDK for Go offers multiple ways to authenticate with Azure. These authentication _types_ are invoked through different authentication_methods_. This article covers the available types, methods, and how to choose which are best for your application.
19
19
20
20
## Available authentication types and methods
21
21
22
-
The Azure SDK for Go offers several different types of authentication, using different credentials sets. Each of these authentication types are available through different authentication methods, which are how the SDK takes these credentials as input. The following table describes the available types of authentication and situations in which they're recommended for use by your application.
22
+
The Azure SDK for Go offers several different types of authentication, using different credentials sets. Each authentication type is available through different authentication methods, which are how the SDK takes these credentials as input. The following table describes the available types of authentication and situations in which they're recommended for use by your application.
23
23
24
24
| Authentication type | Recommended when... |
25
25
|---------------------|---------------------|
26
26
| Certificate-based authentication | You have an X509 certificate that was configured for an Azure Active Directory (AAD) user or service principal. To learn more, see [Get started with certificate-based authentication in Azure Active Directory]. |
27
27
| Client credentials | You have a configured service principal that is set up for this application or a class of applications it belongs to. To learn more, see [Create a service principal with Azure CLI]. |
28
28
| Managed Service Identity (MSI) | Your application is running on an Azure resource that has been configured with Managed Service Identity (MSI). To learn more, see [Managed Service Identity (MSI) for Azure resources]. |
29
-
| Device token | Your application is meant to be used interactively __only__ and will have a variety of users, potentially from multiple AAD tenants. Users have access to a web browser to sign in. For more information, see [Use device token authentication](#use-device-token-authentication).|
30
-
| Username/password | You have an interactive application that cannot use any other authentication method. Your users do not have multi-factor authentication enabled for their AAD signin. |
29
+
| Device token | Your application is meant to be used interactively __only__. Users may have multi-factor authentication enabled. Users have access to a web browser to sign in. For more information, see [Use device token authentication](#use-device-token-authentication).|
30
+
| Username/password | You have an interactive application that can't use any other authentication method. Your users don't have multi-factor authentication enabled for their AAD sign-in. |
31
31
32
32
> [!IMPORTANT]
33
33
> If you use an authentication type other than client credentials, your application must be registered in Azure Active Directory. To learn how,
@@ -40,7 +40,12 @@ The Azure SDK for Go offers several different types of authentication, using dif
40
40
[Create a service principal with Azure CLI]: /cli/azure/create-an-azure-service-principal-azure-cli
41
41
[Managed Service Identity (MSI) for Azure resources]: /azure/active-directory/managed-service-identity/overview
42
42
43
-
These authentication types are available through different methods. [_Environment-based authentication_](#use-environment-based-authentication) reads credentials directly from the program's environment. [_File-based authentication_](#use-file-based-authentication) loads a file containing service principal credentials. [_Client-based authentication_](#use-an-authentication-client) uses an object in Go code and makes you responsible for providing the credentials during program execution. Finally, [_Device token authentication_](#use-device-token-authentication) requires users to sign in interactively through a web browser with a token, and cannot be used with environment- or file-based authentication.
43
+
These authentication types are available through different methods.
44
+
45
+
*[_Environment-based authentication_](#use-environment-based-authentication) reads credentials directly from the program's environment.
46
+
*[_File-based authentication_](#use-file-based-authentication) loads a file containing service principal credentials.
47
+
*[_Client-based authentication_](#use-an-authentication-client) uses an object in code and makes you responsible for providing the credentials during program execution.
48
+
*[_Device token authentication_](#use-device-token-authentication) requires users to sign in interactively through a web browser with a token.
44
49
45
50
All authentication functions and types are available in the `github.com/Azure/go-autorest/autorest/azure/auth` package.
46
51
@@ -49,9 +54,17 @@ All authentication functions and types are available in the `github.com/Azure/go
49
54
50
55
## Use environment-based authentication
51
56
52
-
If you're running your application in a tightly controlled environment such as in a container, environment-based authentication is a natural choice. You configure the shell environment before running your application and the Go SDK reads these environment variables at runtime to authenticate with Azure.
57
+
If you're running your application in a controlled setting, environment-based authentication is a natural choice. With this authentication method, you configure the shell environment before running your application. At runtime, the Go SDK reads these environment variables to authenticate with Azure.
58
+
59
+
Environment-based authentication has support for all authentication methods except device tokens, evaluated in the following order:
53
60
54
-
Environment-based authentication has support for all authentication methods except device tokens, evaluated in the following order: Client credentials, certificates, username/password, and Managed Service Identity (MSI). If a required environment variable is unset or the SDK gets a refusal from the authentication service, the next authentication type is tried. If the SDK cannot authenticate from the environment, it returns an error.
61
+
* Client credentials
62
+
* X509 certificates
63
+
* Username/password
64
+
* Managed Service Identity (MSI)
65
+
66
+
If an authentication type has unset values or is refused, the SDK automatically tries the next authentication type. When no more types are available to try,
67
+
the SDK returns an error.
55
68
56
69
The following table details the environment variables that need to be set for each authentication type supported by environment-based authentication.
57
70
@@ -68,14 +81,14 @@ The following table details the environment variables that need to be set for ea
68
81
||`AZURE_CLIENT_ID`| The application client ID. |
69
82
||`AZURE_USERNAME`| The username to sign in with. |
70
83
||`AZURE_PASSWORD`| The password to sign in with. |
71
-
|__MSI__||MSI does not require any credentials to be set. The application must be running on an Azure resource configured to use MSI. For details, see [Managed Service Identity (MSI) for Azure resources]. |
84
+
|__MSI__||No credentials are needed for MSI authentication. The application must be running on an Azure resource configured to use MSI. For details, see [Managed Service Identity (MSI) for Azure resources]. |
72
85
73
-
If you need to connect to a cloud or management endpoint other than the default Azure public cloud, you can also set the following environment variables. The most common reasons to set them are if you use Azure Stack, a cloud in a different geographic region, or the Azure Classic deployment model.
86
+
To connect to a cloud or management endpoint other than the default Azure public cloud, set the following environment variables. The most common reasons are if you use Azure Stack, a cloud in a different geographic region, or the classic deployment model.
74
87
75
88
| Environment variable | Description |
76
89
|----------------------|--------------|
77
90
|`AZURE_ENVIRONMENT`| The name of the cloud environment to connect to. |
78
-
|`AZURE_AD_RESOURCE`| The Active Directory resource ID to use when connecting. This should be a URI pointing to your management endpoint. |
91
+
|`AZURE_AD_RESOURCE`| The Active Directory resource ID to use when connecting, as a URI to your management endpoint. |
79
92
80
93
When using environment-based authentication, call the [NewAuthorizerFromEnvironment](https://godoc.org/github.com/Azure/go-autorest/autorest/azure/auth#NewAuthorizerFromEnvironment) function to get your authorizer object. This object is then set
81
94
on the `Authorizer` property of clients to allow them access to Azure.
@@ -96,18 +109,18 @@ To authenticate on Azure Stack, you need to set the following variables:
96
109
97
110
These variables can be retrieved from Azure Stack metadata information. To retrieve the metadata, open a web browser in your Azure Stack environment and use the url: `(ResourceManagerURL)/metadata/endpoints?api-version=1.0`
98
111
99
-
The `ResourceManagerURL` varies based on the region name, machine name and external fully qualified domain name (FQDN) of your Azure Stack deployment:
112
+
The `ResourceManagerURL` varies based on the region name, machine name, and external fully qualified domain name (FQDN) of your Azure Stack deployment:
100
113
101
114
| Environment | ResourceManagerURL |
102
115
|----------------------|--------------|
103
116
| Development Kit |`https://management.local.azurestack.external/`|
104
117
| Integrated Systems |`https://management.(region).ext-(machine-name).(FQDN)`|
105
118
106
-
For more details on how to use Azure SDK for Go on Azure Stack see [Use API version profiles with Go in Azure Stack](https://docs.microsoft.com/azure/azure-stack/user/azure-stack-version-profiles-go)
119
+
For more information on how to use the Azure SDK for Go on Azure Stack, see [Use API version profiles with Go in Azure Stack](https://docs.microsoft.com/azure/azure-stack/user/azure-stack-version-profiles-go)
107
120
108
121
## Use file-based authentication
109
122
110
-
File-based authentication only works with client credentials when they are stored in a local file format generated by [the Azure CLI](/cli/azure). You can easily create this file when creating a new service principal with the `--sdk-auth` parameter. If you plan on using file-based authentication, make sure that this argument is provided when creating a service principal. Since the CLI prints output to `stdout`, redirect output to a file.
123
+
File-based authentication uses a file format generated by [the Azure CLI](/cli/azure). You can easily create this file when creating a new service principal with the `--sdk-auth` parameter. If you plan on using file-based authentication, make sure that this argument is provided when creating a service principal. Since the CLI prints output to `stdout`, redirect output to a file.
111
124
112
125
```azurecli
113
126
az ad sp create-for-rbac --sdk-auth > azure.auth
@@ -126,7 +139,7 @@ For more on using service principals and managing their access permissions, see
126
139
127
140
## Use device token authentication
128
141
129
-
If you want users to sign in interactively, the best way to offer that capability is through device token authentication. This authentication flow passes the user a token to paste into a Microsoft sign-in site, where they then authenticate with an Azure Active Directory (AAD) account. This authentication method supports accounts that have multi-factor authentication enabled, unlike standard username/password authentication.
142
+
If you want users to sign in interactively, the best way is through device token authentication. This authentication flow passes the user a token to paste into a Microsoft sign-in site, where they then authenticate with an Azure Active Directory (AAD) account. This authentication method supports accounts that have multi-factor authentication enabled, unlike standard username/password authentication.
130
143
131
144
To use device token authentication, create a [DeviceFlowConfig](https://godoc.org/github.com/Azure/go-autorest/autorest/azure/auth#DeviceFlowConfig) authorizer with the [NewDeviceFlowConfig](https://godoc.org/github.com/Azure/go-autorest/autorest/azure/auth#NewDeviceFlowConfig) function. Call [Authorizer](https://godoc.org/github.com/Azure/go-autorest/autorest/azure/auth#DeviceFlowConfig.Authorizer) on the resulting object to start the authentication process. Device flow authentication blocks program execution until the whole authentication flow is complete.
If you require a specific type of authentication and are willing to have your program do the work to load authentication information from the user, you can use any client that conforms to the [auth.AuthorizerConfig](https://godoc.org/github.com/Azure/go-autorest/autorest/azure/auth#AuthorizerConfig) interface. Use a type that implements this interface when you want an interactive program, use specialized configuration files, or have a requirement that prevents you from using another authentication method.
154
+
If you require a specific type of authentication and are willing to have your program do the work to load authentication information from the user, you can use any client that conforms to the [auth.AuthorizerConfig](https://godoc.org/github.com/Azure/go-autorest/autorest/azure/auth#AuthorizerConfig) interface. Use a type that implements this interface when you:
155
+
156
+
* Write an interactive program
157
+
* Use specialized configuration files
158
+
* Have a requirement that prevents using a built-in authentication method
142
159
143
160
> [!WARNING]
144
161
> Never hard-code Azure credentials into an application. Putting secrets into an application binary makes it easier for an attacker to
@@ -159,7 +176,7 @@ The following table lists the types in the SDK that conform to the `AuthorizerCo
Create an authenticator with its associated `New` function, and then call `Authorize` on the resulting object to perform authentication. For example, to use certificate-based authentication:
179
+
Create an authenticator with its associated `New` function, and then call `Authorize` on the resulting object to authenticate. For example, to use certificate-based authentication:
Copy file name to clipboardExpand all lines: azure-go-sdk-conceptual/azure-sdk-go-compute-networking-samples.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: Selected samples for working with compute resources like VMs and vi
4
4
author: sptramer
5
5
ms.author: sttramer
6
6
manager: carmonm
7
-
ms.date: 03/21/2018
7
+
ms.date: 09/05/2018
8
8
ms.topic: sample
9
9
ms.prod: azure
10
10
ms.technology: azure-sdk-go
@@ -14,14 +14,14 @@ ms.devlang: go
14
14
15
15
# Azure SDK for Go samples for compute and networking
16
16
17
-
The following table links to selected samples of Go source code that you can use to manage VMs, virtual networks, and subnets in Azure.
17
+
The following table links to selected samples that demonstrate the management of compute and virtual network resources in the Azure SDK for Go.
18
18
19
19
All samples for the Azure SDK for Go are available on [GitHub](https://github.com/Azure-Samples/azure-sdk-for-go-samples).
20
20
21
21
| Name | Description |
22
22
|------|-------------|
23
23
|[network/network](https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/master/network/network.go)| Create, update, delete, and query network resources including virtual networks, subnets, and network security groups. |
24
-
|[compute/vm_disk](https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/master/compute/vm_disk.go)| Create, attach, detatch, update, and encrypt data disks for a VM. |
24
+
|[compute/vm_disk](https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/master/compute/vm_disk.go)| Create, attach, detach, update, and encrypt data disks for a VM. |
25
25
|[compute/vm](https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/master/compute/vm.go)| Create, update, deactivate, and manage VMs. |
26
26
|[compute/vm_with_availabilityset](https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/master/compute/vm_with_availabilityset.go)| Create availability sets and load balancers for VMs. |
27
27
|[compute/vm_with_identity](https://github.com/Azure-Samples/azure-sdk-for-go-samples/blob/master/compute/vm_with_identity.go)| Create and manage Managed Service Identities (MSIs) for VMs. |
Copy file name to clipboardExpand all lines: azure-go-sdk-conceptual/azure-sdk-go-containers-samples.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: Selected samples for working with ACI and AKS from the Azure SDK fo
4
4
author: sptramer
5
5
ms.author: sttramer
6
6
manager: carmonm
7
-
ms.date: 03/21/2018
7
+
ms.date: 09/05/2018
8
8
ms.topic: sample
9
9
ms.prod: azure
10
10
ms.technology: azure-sdk-go
@@ -14,7 +14,7 @@ ms.devlang: go
14
14
15
15
# Azure SDK for Go samples for containers
16
16
17
-
The following table links to selected samples of Go source code that you can use to work with containers on Azure via Azure Container Instances (ACI) or Azure Kubernetes Service (AKS).
17
+
The following table links to selected samples that demonstrate the management of Azure Container Instances (ACI) and Azure Kubernetes Service (AKS) from the Azure SDK for Go.
18
18
19
19
All samples for the Azure SDK for Go are available on [GitHub](https://github.com/Azure-Samples/azure-sdk-for-go-samples).
0 commit comments