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
Copy file name to clipboardExpand all lines: articles/spring-apps/tutorial-managed-identities-functions.md
+68-56Lines changed: 68 additions & 56 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,75 +18,85 @@ ms.date: 07/10/2020
18
18
19
19
This article shows you how to create a managed identity for an Azure Spring Apps app and use it to invoke HTTP triggered Functions.
20
20
21
-
Both Azure Functions and App Services have built in support for Azure Active Directory (Azure AD) authentication. By using this built-in authentication capability along with Managed Identities for Azure Spring Apps, we can invoke RESTful services using modern OAuth semantics. This method doesn't require storing secrets in code and provides more granular controls for controlling access to external resources.
21
+
Both Azure Functions and App Services have built in support for Azure Active Directory (Azure AD) authentication. By using this built-in authentication capability along with Managed Identities for Azure Spring Apps, you can invoke RESTful services using modern OAuth semantics. This method doesn't require storing secrets in code and provides more granular controls for controlling access to external resources.
22
22
23
23
## Prerequisites
24
24
25
-
*[Sign up for an Azure subscription](https://azure.microsoft.com/free/)
26
-
*[Install the Azure CLI version 2.45.0 or higher](/cli/azure/install-azure-cli)
27
-
*[Install Maven 3.0 or higher](https://maven.apache.org/download.cgi)
28
-
*[Install the Azure Functions Core Tools version 3.0.2009 or higher](../azure-functions/functions-run-local.md#install-the-azure-functions-core-tools)
25
+
- An Azure subscription. If you don't have a subscription, create a [free account](https://azure.microsoft.com/free/) before you begin.
26
+
-[Azure CLI](/cli/azure/install-azure-cli) version 2.45.0 or higher.
27
+
-[Apache Maven](https://maven.apache.org/download.cgi) version 3.0 or higher.
28
+
-[Install the Azure Functions Core Tools](../azure-functions/functions-run-local.md#install-the-azure-functions-core-tools) version 3.0.2009 or higher.
29
29
30
30
## Create a resource group
31
31
32
-
A resource group is a logical container into which Azure resources are deployed and managed. Create a resource group to contain both the Function app and Spring Cloud using the command [az group create](/cli/azure/group#az-group-create):
32
+
A resource group is a logical container into which Azure resources are deployed and managed. Use the following command to create a resource group to contain a Function app. For more information, see the [az group create](/cli/azure/group#az-group-create) command.
33
33
34
34
```azurecli
35
-
az group create --name myResourceGroup --location eastus
35
+
az group create --name <resource-group-name> --location <location>
36
36
```
37
37
38
-
## Create a Function App
38
+
## Create a Function app
39
39
40
-
To create a Function app you must first create a backing storage account, use the command [az storage account create](/cli/azure/storage/account#az-storage-account-create):
40
+
To create a Function app, you must first create a backing storage account. You can use the [az storage account create](/cli/azure/storage/account#az-storage-account-create) command.
41
41
42
42
> [!IMPORTANT]
43
-
> Each Function app and Storage Account must have a unique name. Replace *\<your-functionapp-name>* with the name of your Function app and *\<your-storageaccount-name>* with the name of your Storage Account in the following examples.
43
+
> Each Function app and storage account must have a unique name.
44
+
45
+
Use the following command to create the storage account. Replace *\<function-app-name>* with the name of your Function app and *\<storage-account-name>* with the name of your storage account.
44
46
45
47
```azurecli
46
48
az storage account create \
47
-
--resource-group myResourceGroup \
48
-
--name <your-storageaccount-name> \
49
-
--location eastus \
49
+
--resource-group <resource-group-name> \
50
+
--name <storage-account-name> \
51
+
--location <location> \
50
52
--sku Standard_LRS
51
53
```
52
54
53
-
After the Storage Account is created, you can create the Function app.
55
+
After the storage account is created, use the following command to create the Function app.
54
56
55
57
```azurecli
56
58
az functionapp create \
57
-
--resource-group myResourceGroup \
58
-
--name <your-functionapp-name> \
59
-
--consumption-plan-location eastus \
59
+
--resource-group <resource-group-name> \
60
+
--name <function-app-name> \
61
+
--consumption-plan-location <location> \
60
62
--os-type windows \
61
63
--runtime node \
62
-
--storage-account <your-storageaccount-name> \
64
+
--storage-account <storage-account-name> \
63
65
--functions-version 3
64
66
```
65
67
66
-
Make a note of the returned `hostNames` value, which is in the format *https://\<your-functionapp-name>.azurewebsites.net*. You use this value in a following step.
68
+
Make a note of the returned `hostNames` value, which is in the format *https://\<your-functionapp-name>.azurewebsites.net*. Use this value in the Function app's root URL for testing the Function app.
69
+
70
+
## Enable Azure Active Directory authentication
67
71
68
-
## Enable Azure Active Directory Authentication
72
+
Use the following steps to enable Azure Active Directory authentication to access your Function app.
69
73
70
-
Access the newly created Function app from the [Azure portal](https://portal.azure.com) and select **Authentication / Authorization** from the settings menu. Enable App Service Authentication and set the **Action to take when request is not authenticated** to **Log in with Azure Active Directory**. This setting ensures that all unauthenticated requests are denied (401 response).
74
+
1. In the Azure portal, navigate to your resource group and then open the Function app you created.
75
+
1. In the navigation pane, select **Authentication** and then select **Add identity provider** on the main pane.
76
+
1. On the **Add an identity provider** page, select **Microsoft** from the **Identity provider** dropdown menu.
71
77
72
-
:::image type="content" source="media/spring-cloud-tutorial-managed-identities-functions/function-auth-config-1.jpg" alt-text="Screenshot of the Azure portal showing Authentication / Authorization page with Azure Active Directory set as the default provider." lightbox="media/spring-cloud-tutorial-managed-identities-functions/function-auth-config-1.jpg":::
78
+
:::image type="content" source="media/spring-cloud-tutorial-managed-identities-functions/add-identity-provider.png" alt-text="Screenshot of the Azure portal showing the Add an identity provider page with Microsoft highlighted in the identity provider dropdown menu." lightbox="media/spring-cloud-tutorial-managed-identities-functions/add-identity-provider.png":::
73
79
74
-
Under **Authentication Providers**, select **Azure Active Directory** to configure the application registration. Selecting **Express Management Mode** automatically creates an application registration in your Azure AD tenant with the correct configuration.
80
+
1. Select **Add**.
81
+
1. For the **Basics** settings on the **Add an identity provider** page, set **Supported account types** to **Any Azure AD directory - Multi-tenant**.
82
+
1. Set **Unauthenticated requests** to **HTTP 401 Unauthorized: recommended for APIs**. This setting ensures that all unauthenticated requests are denied (401 response).
75
83
76
-
:::image type="content" source="media/spring-cloud-tutorial-managed-identities-functions/function-auth-config-2.jpg" alt-text="Screenshot of the Azure portal showing the Azure Active Directory providerset to Express Management Mode." lightbox="media/spring-cloud-tutorial-managed-identities-functions/function-auth-config-2.jpg":::
84
+
:::image type="content" source="media/spring-cloud-tutorial-managed-identities-functions/identity-provider-settings.png" alt-text="Screenshot of the Azure portal showing the settings page for adding an identity provider. This page highlights the 'supported account types' setting set to the 'Any Azure AD directory Multi tenant' option and also highlights the 'Unauthenticated requests' setting set to the 'HTTP 401 Unauthorized recommended for APIs' option." lightbox="media/spring-cloud-tutorial-managed-identities-functions/identity-provider-settings.png":::
77
85
78
-
After you save the settings, the function app restarts and all subsequent requests are prompted to log in via Azure AD. You can test that unauthenticated requests are now being rejected by navigating to the function apps root URL (returned in the `hostNames` output in a previous step). You should be redirected to your organizations Azure AD login screen.
86
+
1. Select **Add**.
79
87
80
-
## Create an HTTP Triggered Function
88
+
After you add the settings, the Function app restarts and all subsequent requests are prompted to sign in through Azure AD. You can test that unauthenticated requests are currently being rejected with the Function app's root URL (returned in the `hostNames` output of the `az functionapp create` command). You should then be redirected to your organization's Azure Active Directory sign-in screen.
81
89
82
-
In an empty local directory, create a new function app and add an HTTP triggered function.
90
+
## Create an HTTP triggered function
91
+
92
+
In an empty local directory, use the following commands to create a new function app and add an HTTP triggered function.
83
93
84
94
```console
85
95
func init --worker-runtime node
86
96
func new --template HttpTrigger --name HttpTrigger
87
97
```
88
98
89
-
By default, Functions use key-based authentication to secure HTTP endpoints. Since we're enabling Azure AD authentication to secure access to the Functions, we want to [set the function auth level to anonymous](../azure-functions/functions-bindings-http-webhook-trigger.md#secure-an-http-endpoint-in-production) in the *function.json* file.
99
+
By default, functions use key-based authentication to secure HTTP endpoints. To enable Azure AD authentication to secure access to the functions, set the `authLevel` key to `anonymous` in the *function.json* file, as shown in the following example:
90
100
91
101
```json
92
102
{
@@ -100,99 +110,101 @@ By default, Functions use key-based authentication to secure HTTP endpoints. Sin
100
110
}
101
111
```
102
112
103
-
You can now publish the app to the [Function app](#create-a-function-app) instance created in the previous step.
113
+
For more information, see the [Secure an HTTP endpoint in production](../azure-functions/functions-bindings-http-webhook-trigger.md#secure-an-http-endpoint-in-production) section of [Azure Functions HTTP trigger](../azure-functions/functions-bindings-http-webhook-trigger.md).
114
+
115
+
Use the following command to publish the app to the instance created in the previous step:
## Create an Azure Spring Apps service instance and application
120
132
121
-
After installing the spring extension, create an Azure Spring Apps instance with the Azure CLI command `az spring create`.
133
+
Use the following commands to add the spring extension and to create a new instance of Azure Spring Apps.
122
134
123
135
```azurecli
124
136
az extension add --upgrade --name spring
125
137
az spring create \
126
-
--resource-group myResourceGroup \
127
-
--name mymsispringcloud \
128
-
--location eastus
138
+
--resource-group <resource-group-name> \
139
+
--name <Azure-Spring-Apps-instance-name> \
140
+
--location <location>
129
141
```
130
142
131
-
The following example creates an app named `msiapp` with a system-assigned managed identity, as requested by the `--assign-identity` parameter.
143
+
Use the following command to create an application named `msiapp` with a system-assigned managed identity, as requested by the `--assign-identity` parameter.
132
144
133
145
```azurecli
134
146
az spring app create \
135
-
--resource-group "myResourceGroup" \
136
-
--service "mymsispringcloud" \
147
+
--resource-group <resource-group-name> \
148
+
--service <Azure-Spring-Apps-instance-name> \
137
149
--name "msiapp" \
138
150
--assign-endpoint true \
139
151
--assign-identity
140
152
```
141
153
142
154
## Build sample Spring Boot app to invoke the Function
143
155
144
-
This sample invokes the HTTP triggered function by first requesting an access token from the [MSI endpoint](../active-directory/managed-identities-azure-resources/how-to-use-vm-token.md#get-a-token-using-http)and using that token to authenticate the Function http request.
156
+
This sample invokes the HTTP triggered function by first requesting an access token from the MSI endpoint and using that token to authenticate the function HTTP request. For more information, see the [Get a token using HTTP](../active-directory/managed-identities-azure-resources/how-to-use-vm-token.md#get-a-token-using-http)section of [How to use managed identities for Azure resources on an Azure VM to acquire an access token](../active-directory/managed-identities-azure-resources/how-to-use-vm-token.md).
145
157
146
-
1.Clone the sample project.
158
+
1.Use the following command clone the sample project.
You see the following message returned in the response body.
200
+
The following message is returned in the response body.
189
201
190
202
```output
191
203
Function Response: Hello, springcloud. This HTTP triggered function executed successfully.
192
204
```
193
205
194
206
## Next steps
195
207
196
-
*[How to enable system-assigned managed identity for applications in Azure Spring Apps](./how-to-enable-system-assigned-managed-identity.md)
197
-
*[Learn more about managed identities for Azure resources](../active-directory/managed-identities-azure-resources/overview.md)
198
-
*[Configure client apps to access your App Service](../app-service/configure-authentication-provider-aad.md#configure-client-apps-to-access-your-app-service)
208
+
-[How to enable system-assigned managed identity for applications in Azure Spring Apps](./how-to-enable-system-assigned-managed-identity.md)
209
+
-[Learn more about managed identities for Azure resources](../active-directory/managed-identities-azure-resources/overview.md)
210
+
-[Configure client apps to access your App Service](../app-service/configure-authentication-provider-aad.md#configure-client-apps-to-access-your-app-service)
0 commit comments