Skip to content

Commit 280fce8

Browse files
Merge pull request #234299 from KarlErickson/karler-108101
edits, fix for MicrosoftDocs/azure-docs#108101
2 parents 50ef07e + 04298d6 commit 280fce8

File tree

1 file changed

+73
-52
lines changed

1 file changed

+73
-52
lines changed

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

Lines changed: 73 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ ms.date: 07/10/2020
1414
> [!NOTE]
1515
> Azure Spring Apps is the new name for the Azure Spring Cloud service. Although the service has a new name, you'll see the old name in some places for a while as we work to update assets such as screenshots, videos, and diagrams.
1616
17-
**This article applies to:** ✔️ Basic/Standard tier ✔️ Enterprise tier
17+
**This article applies to:** ✔️ Basic/Standard ✔️ Enterprise
1818

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

21-
Both Azure Functions and App Services have built in support for Azure Active Directory (Azure AD) authentication. By leveraging 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, 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.
2222

2323
## Prerequisites
2424

2525
* [Sign up for an Azure subscription](https://azure.microsoft.com/free/)
2626
* [Install the Azure CLI version 2.45.0 or higher](/cli/azure/install-azure-cli)
27-
* [Install Maven 3.0 or above](https://maven.apache.org/download.cgi)
27+
* [Install Maven 3.0 or higher](https://maven.apache.org/download.cgi)
2828
* [Install the Azure Functions Core Tools version 3.0.2009 or higher](../azure-functions/functions-run-local.md#install-the-azure-functions-core-tools)
2929

3030
## Create a resource group
@@ -39,43 +39,54 @@ az group create --name myResourceGroup --location eastus
3939

4040
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):
4141

42-
> [!Important]
42+
> [!IMPORTANT]
4343
> 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.
4444
4545
```azurecli
46-
az storage account create --name <your-storageaccount-name> --resource-group myResourceGroup --location eastus --sku Standard_LRS
46+
az storage account create \
47+
--resource-group myResourceGroup \
48+
--name <your-storageaccount-name> \
49+
--location eastus \
50+
--sku Standard_LRS
4751
```
4852

49-
Once the Storage Account has been created, you can create the Function app.
53+
After the Storage Account is created, you can create the Function app.
5054

5155
```azurecli
52-
az functionapp create --name <your-functionapp-name> --resource-group myResourceGroup --consumption-plan-location eastus --os-type windows --runtime node --storage-account <your-storageaccount-name> --functions-version 3
56+
az functionapp create \
57+
--resource-group myResourceGroup \
58+
--name <your-functionapp-name> \
59+
--consumption-plan-location eastus \
60+
--os-type windows \
61+
--runtime node \
62+
--storage-account <your-storageaccount-name> \
63+
--functions-version 3
5364
```
5465

55-
Make a note of the returned **hostNames**, which will be in the format *https://\<your-functionapp-name>.azurewebsites.net*. It will be used in a following step.
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.
5667

5768
## Enable Azure Active Directory Authentication
5869

59-
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 will ensure that all unauthenticated requests are denied (401 response).
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).
6071

61-
![Authentication settings showing Azure Active Directory as the default provider](media/spring-cloud-tutorial-managed-identities-functions/function-auth-config-1.jpg)
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":::
6273

63-
Under Authentication Providers, select Azure Active Directory to configure the application registration. Selecting Express Management Mode will automatically create an application registration in your Azure AD tenant with the correct configuration.
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.
6475

65-
![Azure Active Directory provider set to Express Management Mode](media/spring-cloud-tutorial-managed-identities-functions/function-auth-config-2.jpg)
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":::
6677

67-
Once you save the settings, the function app will restart and all subsequent requests will be 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 the step above). You should be redirected to your organizations Azure AD login screen.
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.
6879

69-
## Create an Http Triggered Function
80+
## Create an HTTP Triggered Function
7081

71-
In an empty local directory, create a new function app and add an Http triggered function.
82+
In an empty local directory, create a new function app and add an HTTP triggered function.
7283

7384
```console
7485
func init --worker-runtime node
7586
func new --template HttpTrigger --name HttpTrigger
7687
```
7788

78-
By default Functions use key-based authentication to secure Http endpoints. Since we'll be 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.
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.
7990

8091
```json
8192
{
@@ -89,7 +100,7 @@ By default Functions use key-based authentication to secure Http endpoints. Sinc
89100
}
90101
```
91102

92-
The app can now be published to the [Function app](#create-a-function-app) instance created in the previous step.
103+
You can now publish the app to the [Function app](#create-a-function-app) instance created in the previous step.
93104

94105
```console
95106
func azure functionapp publish <your-functionapp-name>
@@ -111,64 +122,74 @@ After installing the spring extension, create an Azure Spring Apps instance with
111122

112123
```azurecli
113124
az extension add --upgrade --name spring
114-
az spring create --name mymsispringcloud --resource-group myResourceGroup --location eastus
125+
az spring create \
126+
--resource-group myResourceGroup \
127+
--name mymsispringcloud \
128+
--location eastus
115129
```
116130

117131
The following example creates an app named `msiapp` with a system-assigned managed identity, as requested by the `--assign-identity` parameter.
118132

119133
```azurecli
120-
az spring app create --name "msiapp" --service "mymsispringcloud" --resource-group "myResourceGroup" --assign-endpoint true --assign-identity
134+
az spring app create \
135+
--resource-group "myResourceGroup" \
136+
--service "mymsispringcloud" \
137+
--name "msiapp" \
138+
--assign-endpoint true \
139+
--assign-identity
121140
```
122141

123142
## Build sample Spring Boot app to invoke the Function
124143

125-
This sample will invoke 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.
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.
126145

127146
1. Clone the sample project.
128147

129-
```bash
130-
git clone https://github.com/Azure-Samples/Azure-Spring-Cloud-Samples.git
131-
```
148+
```bash
149+
git clone https://github.com/Azure-Samples/Azure-Spring-Cloud-Samples.git
150+
```
132151

133-
2. Specify your function URI and the trigger name in your app properties.
152+
1. Specify your function URI and the trigger name in your app properties.
134153

135-
```bash
136-
cd Azure-Spring-Cloud-Samples/managed-identity-function
137-
vim src/main/resources/application.properties
138-
```
154+
```bash
155+
cd Azure-Spring-Cloud-Samples/managed-identity-function
156+
vim src/main/resources/application.properties
157+
```
139158

140-
To use managed identity for Azure Spring Apps apps, add properties with the following content to *src/main/resources/application.properties*.
159+
To use managed identity for Azure Spring Apps apps, add properties with the following content to *src/main/resources/application.properties*.
141160

142-
```properties
143-
azure.function.uri=https://<your-functionapp-name>.azurewebsites.net
144-
azure.function.triggerPath=httptrigger
145-
```
161+
```properties
162+
azure.function.uri=https://<your-functionapp-name>.azurewebsites.net
163+
azure.function.triggerPath=httptrigger
164+
```
146165

147-
3. Package your sample app.
166+
1. Package your sample app.
148167

149-
```bash
150-
mvn clean package
151-
```
168+
```bash
169+
mvn clean package
170+
```
152171

153-
4. Now deploy the app to Azure with the Azure CLI command `az spring app deploy`.
172+
1. Now deploy the app to Azure with the Azure CLI command `az spring app deploy`.
154173

155-
```azurecli
156-
az spring app deploy --name "msiapp" --service "mymsispringcloud" --resource-group "myResourceGroup" --jar-path target/sc-managed-identity-function-sample-0.1.0.jar
157-
```
174+
```azurecli
175+
az spring app deploy \
176+
--resource-group "myResourceGroup" \
177+
--service "mymsispringcloud" \
178+
--name "msiapp" \
179+
--jar-path target/sc-managed-identity-function-sample-0.1.0.jar
180+
```
158181

159-
5. Access the public endpoint or test endpoint to test your app.
182+
1. Access the public endpoint or test endpoint to test your app.
160183

161-
```bash
162-
curl https://mymsispringcloud-msiapp.azuremicroservices.io/func/springcloud
163-
```
184+
```bash
185+
curl https://mymsispringcloud-msiapp.azuremicroservices.io/func/springcloud
186+
```
164187

165-
You'll see the following message returned in the response body.
188+
You see the following message returned in the response body.
166189

167-
```output
168-
Function Response: Hello, springcloud. This HTTP triggered function executed successfully.
169-
```
170-
171-
You can try passing different values to the function by changing the path parameter.
190+
```output
191+
Function Response: Hello, springcloud. This HTTP triggered function executed successfully.
192+
```
172193

173194
## Next steps
174195

0 commit comments

Comments
 (0)