Skip to content

Azure iPaaS 9 – Securing our Solution Implementation

The final step we need to do in our solution is to enable the security where relevant. For that, we can go in different paths depending on the level of security we need and how much we are ready to invest to secure our solution. Azure gives us many options to secure our components such as:

  • Leverage the Azure networking components by creating a Virtual Network and App Service Environments (ASE) encapsulating our components. Then enable external access only through the APIM. This ensures that only APIM can call our internal components. This is the most secure, but also, the most complicated and costly solution. I’ll not use this method in this series
  • Enable IP whitelisting, where applicable. This technique can be used in SQL Service, API apps, Logic Apps, and APIM to enable calls only from specific set of IPs. This would make sense if our Web API is called directly from an APIM API. Then we could have set IP whitelisting on our Web API to allow calls only from the API management IP address. Same applies for Logic Apps, but in our scenario both cases don’t apply as the APIM doesn’t call neither the Web API, nor the Logic App directly. As for the SQL database and APIM, this technique applies and we’ll discuss it shortly.
  • Enable OAuth2 which would require integration with Azure Active Directory to generate tokens and enable only authorized access to our components.
  • Keys and SAS tokens for service bus, storage account access, APIM and Azure functions access

Let’s pass by all of our components and see how there are secured and if not, how to secure them. As a best practice, we want everything to be accessible through the APIM. The client shouldn’t be able to call any component directly without passing through APIM.

  • Service bus is secured by means of SAS tokens. Only by presenting a valid SAS token access to the service bus is granted. For the sake of brevity, I used the default “RootManageSharedAccessKey” policy. For production scenarios, specific policies for send and listen should be created and used in the APIM and logic app.
  • Storage account is also secured using SAS tokens. Also here, when generating the SAS token, make sure you generate it with the least permissions, services, and resource types that you require.
  • The Logic App doesn’t have an Http trigger and hence can’t be called directly. So I’ll implement no security mechanism on it. Would it be called directly, we could have enabled IP whitelisting as well as OAuth2 authorization to allow only authenticated clients to access it, but that’s not necessary on our case.
  • The Azure functions are secured by means of a key. Calling the function directly requires a function key to be sent in the header or in the query string. Is that totally secure? Not much, so Azure also supports OAuth2 authorization for Azure functions, but again, I’ll not implement that here as I’ll implement OAuth2 in securing the Web API, so I don’t want to repeat myself. I’ll leave that as an exercise for you.
  • The SQL database is secured using SQL authentication as well as IP whitelisting. Currently, if you recall, we enabled access from all Azure resources plus my client machine. Nobody else can access the SQL server. As for Azure resources, the SQL credentials will ensure authorized access.
  • The Web API is still not secure. As of now, anybody would be able to call it and insert data to our database. IP whitelisting will not help here as the logic app is calling our API and the logic app doesn’t have a static IP address. So, to secure the API, I’m going to implement OAuth security between the Logic App (acting as the client) and the Web API (acting as the resource) using Azure Active Directory (as the authorization server)
  • API Management is secured using the subscription key which can be sent via the header or the query string. Again, that’s not real security as anybody who gets the key can access our API management API. We have two options here, if we know who will be using our API’s, as in our case (the vendors), we can implement IP whitelisting by means of policies to restrict the callers to certain IP’s. Details how to do that can be found in the following useful article: https://docs.microsoft.com/en-us/azure/api-management/api-management-howto-policies

Second option is to go for a fully-fledged OAuth security implementation by defining clients, scopes, and users in your preferred authorization server, expose the OAuth endpoints via the API management, and let the client log-in, get an access token, then call your exposed API’s sending the access token in the request header. The API management can then validate the token before forwarding the request to the backend service. Since that’s a lot of work, I might keep it for a future article series dedicated to OAuth security on Azure. As of now, I’ll just use the subscription key, and since our callers are known, assume that an ip-filter policy has been set on the “Entities API” “POST Entity” operation.

Before going to the actual implementation, i need to mention that you need to have a good idea about how OAuth security works to understand what are you doing and why.

Ok, so what we want to do here is to secure our entities Web API. First thing we need to do is to create two applications in Azure Active Directory (AAD). One for the Logic App (the Client), and one for the Web API (the resource). Then, we need to associate the Web API with its created application, then send the logic app application client id, client secret, and Web API client id from the Logic App call to the API App. Let’s do that step-by-step.

Creating the AAD Applications

As mentioned, the first step is to create two AAD applications. Open the “classic” azure management portal, as of now, it’s still easier to manage “AAD” from there: https://manage.windowsazure.com

After logging in, click on the “Active Directory” link on the left menu. Click your AD tenant, then “Applications” from the top menu.9-1

Click on the “ADD” action at the bottom of the screen, then “Add an application my organization is developing”. Enter the name of your application and click the “Right” arrow to move into the next stage

9-2

Enter any sign-on URL and App ID, then click the check button.

9-3

Click the “Configure” tab, scroll down and copy the “Client ID” Guid value. Put it in a text document as we’ll need it later. Scroll to the “Keys” section, select a duration, then click “Save” from the bottom menu to generate a secret. Copy the secret and store it in the text file also as we’ll need it later

Go back to the “Application” page and click “ADD” again. Select “Add an application my organization is developing”. Name the application and click forward.

9-4

Enter the API APP URL this time in the sign-on URL and APP ID fields, then finish.

9-5

Click the “Configure” tab, scroll down, copy the “Client ID” GUID value and save it also in the text file.

Scroll down to the Reply URL field, append the value by “/.auth/login/aad/callback”. It will be:
https://devipaasentitiesapi.azurewebsites.net/.auth/login/aad/callback

Click “Save” to save your changes.

Protect the API App with the AAD Identity

Now that we have created the needed AAD applications, let’s secure our Web Api using the second application created. Go back to the azure portal and open the API App blade. Click on “Authentication / Authorization” item in the left menu, then set the “App Service Authentication” to “On”. Also, in the “Action to take when request is not authenticated”, select “Log in with Azure Active Directory”

9-6

Under “Authentication Providers”, select “Azure Active Directory”. In the “Active Directory Settings” blade, select “Express” management mode, then “Select an Existing AD App” as we have previously created the app. Click the “AD Azure App” link and select the “Dev Entities API Application”, then click “Ok”

9-7

Click “Ok” then “Save” to apply your changes.

9-8

Try calling the entities api again, you should not be able to do so.

Send the Authorization Information in the Logic App Call to the API App

In order to call the API successfully, we have now to provide a bearer token in the Authorization header. We can call the AAD token endpoint to generate an access token, but luckily, Logic Apps provides us with an easier way. Open the Logic App and click on the “Call Entities Service” step to expand it, then click “Show advanced options”. Notice that we have an “Authentication” option which is set to “None”. Select “Active Directory OAuth” and notice the fields presented. If we have those information, the logic app will use them to generate an access token and send it to the Api App rather than we doing the “hard” work.

So, let’s go on and fill those information as follows:

  • Tenant: The subscription id you are using. You can grab it immediately from the URL after the “/subscriptions/” portion of the opened URL.
  • Audience: The target application client id. In this case, the client id of the “Dev Entities API Application” which we have previously copied.
  • Client ID: The client id of the caller, which is the client id of the “Logic App Application” which we have previously copied.
  • Client Secret: The client secret of the caller, which is the client secret of the “Logic App Application” which we have previously copied.

Our step should look like:

9-9

Call the API again through the APIM API, I’ll use Postman this time for a change

9-10

Open the Logic App previous runs and check your instance, your call should be successful now.

9-11

This shall conclude our “functional” part of the series. In the next articles, I’ll focus on the automation and continuous integration-continuous deployment (CICD) part.

Leave a Reply