Skip to content

Commit 3916cd1

Browse files
Merge pull request #234555 from brhamilton529/screens-identities
Screenshot update customer pri: Managed indentity
2 parents 7e5e8a4 + 6004132 commit 3916cd1

File tree

5 files changed

+68
-56
lines changed

5 files changed

+68
-56
lines changed
57.6 KB
Loading
62.4 KB
Loading

articles/spring-apps/tutorial-managed-identities-functions.md

Lines changed: 68 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,75 +18,85 @@ ms.date: 07/10/2020
1818

1919
This article shows you how to create a managed identity for an Azure Spring Apps app and use it to invoke HTTP triggered Functions.
2020

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.
2222

2323
## Prerequisites
2424

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.
2929

3030
## Create a resource group
3131

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.
3333

3434
```azurecli
35-
az group create --name myResourceGroup --location eastus
35+
az group create --name <resource-group-name> --location <location>
3636
```
3737

38-
## Create a Function App
38+
## Create a Function app
3939

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.
4141

4242
> [!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.
4446

4547
```azurecli
4648
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> \
5052
--sku Standard_LRS
5153
```
5254

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.
5456

5557
```azurecli
5658
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> \
6062
--os-type windows \
6163
--runtime node \
62-
--storage-account <your-storageaccount-name> \
64+
--storage-account <storage-account-name> \
6365
--functions-version 3
6466
```
6567

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
6771

68-
## Enable Azure Active Directory Authentication
72+
Use the following steps to enable Azure Active Directory authentication to access your Function app.
6973

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.
7177

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":::
7379

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).
7583

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 provider set 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":::
7785

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**.
7987

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.
8189

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.
8393

8494
```console
8595
func init --worker-runtime node
8696
func new --template HttpTrigger --name HttpTrigger
8797
```
8898

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:
90100

91101
```json
92102
{
@@ -100,99 +110,101 @@ By default, Functions use key-based authentication to secure HTTP endpoints. Sin
100110
}
101111
```
102112

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:
104116

105117
```console
106-
func azure functionapp publish <your-functionapp-name>
118+
func azure functionapp publish <function-app-name>
107119
```
108120

109-
The output from the publish command should list the URL to your newly created function.
121+
The output from the publish command should list the URL to your newly created function, as shown in the following output:
110122

111123
```output
112124
Deployment completed successfully.
113125
Syncing triggers...
114126
Functions in <your-functionapp-name>:
115127
HttpTrigger - [httpTrigger]
116-
Invoke url: https://<your-functionapp-name>.azurewebsites.net/api/httptrigger
128+
Invoke url: https://<function-app-name>.azurewebsites.net/api/httptrigger
117129
```
118130

119-
## Create Azure Spring Apps service and app
131+
## Create an Azure Spring Apps service instance and application
120132

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.
122134

123135
```azurecli
124136
az extension add --upgrade --name spring
125137
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>
129141
```
130142

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.
132144

133145
```azurecli
134146
az spring app create \
135-
--resource-group "myResourceGroup" \
136-
--service "mymsispringcloud" \
147+
--resource-group <resource-group-name> \
148+
--service <Azure-Spring-Apps-instance-name> \
137149
--name "msiapp" \
138150
--assign-endpoint true \
139151
--assign-identity
140152
```
141153

142154
## Build sample Spring Boot app to invoke the Function
143155

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).
145157

146-
1. Clone the sample project.
158+
1. Use the following command clone the sample project.
147159

148160
```bash
149161
git clone https://github.com/Azure-Samples/Azure-Spring-Cloud-Samples.git
150162
```
151163

152-
1. Specify your function URI and the trigger name in your app properties.
164+
1. Use the following command to specify your function URI and the trigger name in your app properties.
153165

154166
```bash
155167
cd Azure-Spring-Cloud-Samples/managed-identity-function
156168
vim src/main/resources/application.properties
157169
```
158170

159-
To use managed identity for Azure Spring Apps apps, add properties with the following content to *src/main/resources/application.properties*.
171+
1. To use managed identity for Azure Spring Apps apps, add the following properties with these values to *src/main/resources/application.properties*.
160172

161-
```properties
162-
azure.function.uri=https://<your-functionapp-name>.azurewebsites.net
173+
```text
174+
azure.function.uri=https://<function-app-name>.azurewebsites.net
163175
azure.function.triggerPath=httptrigger
164176
```
165177

166-
1. Package your sample app.
178+
1. Use the following command to package your sample app.
167179

168180
```bash
169181
mvn clean package
170182
```
171183

172-
1. Now deploy the app to Azure with the Azure CLI command `az spring app deploy`.
184+
1. Use the following command to deploy the app to Azure Spring Apps.
173185

174186
```azurecli
175187
az spring app deploy \
176-
--resource-group "myResourceGroup" \
177-
--service "mymsispringcloud" \
188+
--resource-group <resource-group-name> \
189+
--service <Azure-Spring-Apps-instance-name> \
178190
--name "msiapp" \
179191
--jar-path target/asc-managed-identity-function-sample-0.1.0.jar
180192
```
181193

182-
1. Access the public endpoint or test endpoint to test your app.
194+
1. Use the following command to access the public endpoint or test endpoint to test your app.
183195

184196
```bash
185-
curl https://mymsispringcloud-msiapp.azuremicroservices.io/func/springcloud
197+
curl https://<Azure-Spring-Apps-instance-name>-msiapp.azuremicroservices.io/func/springcloud
186198
```
187199

188-
You see the following message returned in the response body.
200+
The following message is returned in the response body.
189201

190202
```output
191203
Function Response: Hello, springcloud. This HTTP triggered function executed successfully.
192204
```
193205

194206
## Next steps
195207

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

Comments
 (0)