Protecting APIs on Azure API Gateway

Instructions on how to protect your APIs deployed behind the Azure API gateway

Prerequisites

  • You have a Microsoft Azure account.
  • You are permitted to access the API Management service and the Function App service in the Microsoft Azure portal.

Select workspace

  1. In your browser, navigate to ACP and log in with your credentials.

  2. In the Workspace Directory view, select a workspace that you want to enter.

Create Azure GW

  1. In the workspace, select APIs from the sidebar.

  2. Select the GATEWAYS tab.

  3. Select ADD GATEWAY.

  4. Select Azure API Management, enter the name and the description for your gateway, and select NEXT.

  5. In the Gateway Management view, go to the QUICK START tab and follow the provided instruction to configure your gateway.

    1. Go to the Microsoft Azure portal to configure ACP Authorizer. See Configure ACP Authorizer for detailed instructions.

    2. Get back to the ACP administrator portal (Gateway Management view > QUICK START tab) and select CONNECT API GROUPS to connect APIs and enable enforcement policies.

    Result

    A set of API groups that you have in the Azure portal has been imported to the ACP administrator portal and displayed in the APIs tab of the Gateway Management view. The API groups are ready to be connected to services.

  6. To access your gateway settings, select the SETTINGS tab.

  7. In the SETTINGS tab, copy values of ACP_CLIENT_ID, ACP_CLIENT_SECRET, and ACP_ISSUER_URL.

    Note

    ACP_CLIENT_ID, ACP_CLIENT_SECRET, and ACP_ISSUER_URL are needed to configure ACP Authorizer in the Microsoft Azure portal (step 2 in Set environment variables).

  8. Select Save.

Configure Azure permissions

To configure the Azure API gateway, you need ACP Authorizer, which uses a specific set of APIs. Your Azure application (OAuth client) needs permissions to access these APIs.

Register an application

  1. Go to the Microsoft Azure portal, create an Azure Active Directory application according to instructions in How to: Use the portal to create an Azure AD application….

    Result

    You can identify AZURE_CLIENT_ID and AZURE_TENANT_ID for your new application.

  2. Select Certificate and secrets from the sidebar and add a new secret for your application.

    Result

    AZURE_CLIENT_SECRET is generated.

Assign roles

  1. Get back to the Microsoft Azure homepage and select Subscriptions from the sidebar.

  2. In the Subscriptions view, select a subscription that you want to configure.

    Result

    An overview of the selected subscription opens and you can identify AZURE_SUBSCRIPTION_ID.

  3. Select Access control from the sidebar and make sure that the Check access tab is open.

  4. Select + Add > Add role assignment.

  5. In the Add role assignment fly-out pane

    1. Enter a name of the role into the Role field.

      Required roles to be assigned

      • API Management Service Contributor
      • Website Contributor
    2. Enter the name of your application into the Select field.

    3. Select Save.

Result

You can check your role assignments in the Role assignments tab by entering the name of a role into the Role field.

Configure ACP Authorizer

Create a function app

  1. In the Microsoft Azure portal, go to All services > Compute > Function App.

  2. Select Add to create a new function.

  3. In the Function App view, go to the Basics tab and provide requested project and instance details.

    • For Subscription, select Pay-As-You-Go.

    • For Resource Group, select an existing group or create a new one.

    • For Function App name, provide a name of your preference.

    • For Publish, select Docker Container.

    • For Region, select a region of your preference from the dropdown list.

  4. Select Next : Hosting > at the bottom of the page.

    Result

    The Hosting tab opens.

  5. In the Hosting tab, provide information on your storage account and the application service plan. Modify the default values if needed.

  6. Select Next : Monitoring > at the bottom of the page.

    Result

    The Monitoring tab opens.

  7. In the Monitoring tab, keep application insights enabled or disable them.

  8. Select Next : Tags > at the bottom of the page.

    Result

    The Tags tab opens.

  9. In the Tags tab, create tags for your resources.

  10. Select Next : Review + create > at the bottom of the page.

    Result

    The provided data gets reviewed and, if verified as correct, the Review + create tab opens.

  11. In the Review + create tab, check all the details on your function app and select Create if they are fine.

    Result

    Your function app is ready.

Set environment variables

  1. Go to an overview of your new function app by selecting Go to resources.

  2. To access environment variables, select Configuration from the sidebar and go to the Application settings tab.

    Result

    The application settings list opens and shows multiple variables with no values set.

  3. By selecting + New application setting, add three ACP variables: ACP_CLIENT_ID, ACP_CLIENT_SECRET, and ACP_ISSUER_URL.

  4. Enter values for the new variables.

    Note

    For ACP_CLIENT_ID, ACP_CLIENT_SECRET, and ACP_ISSUER_URL, paste the values generated for your new gateway in the ACP administrator portal (step 8 in Create Azure GW.

    Result

    The new ACP variables are visible on the Application settings list.

  5. Similarly as for the ACP variables, add Azure variables and specify their values.

    • Mandatory settings

    • Optional settings

      • CONFIG_SYNC_INTERVAL defines the frequency of scanning Azure APIs and injecting the authorizer into the policy (by default equals 60 seconds).

      • CONFIG_REFRESH_INTERVAL defines the frequency of loading the configuration from ACP by the authorizer.

      • AZURE_STATIC_AUTHORIZER_URL is to be used if you deploy the authorizer with a custom domain (by default the authorizer URL used in the policy is discovered automatically).

      • DISABLE_ANALYTICS can be changed from its default value (false) to true to turn off the analytics.

      • LOGGING_LEVEL

    Result

    The new Azure variables are visible on the Application settings list.

  6. Select Save to apply the changes.

Result

By configuring all required environment variables, you’ve enabled ACP Authorizer to call APIs and modify policies.

Deploy the function app

  1. To deploy your Docker instance, select Container settings from the sidebar.

  2. In the Container settings view

    • Select Docker Hub as an image source.

    • Enter Full Image Name and Tag, for example cloudentity/azure-authorizer:1.16.1.

    • Select Save and, next, Refresh.

    Result

    The Docker image gets downloaded. Check the logs and make sure that Settings updated successfully is displayed.

Connect a service

There are two ways to connect API groups to ACP services: starting from the gateway to be connected or starting from the service that you want to connect.

From the gateway

  1. From the list of available gateways, select your newly-created Azure gateway.

  2. In the Gateway Management view, select the APIs tab.

    Result

    A list of imported API groups opens.

  3. From the list of API groups available, select an API group and, from its drop-down menu, pick a service to which you’d like to connect the API group.

Note

You can connect an API group to an existing service or a new one you create, both options available from the same service drop-down menu.

From the service

  1. Select APIs from the left sidebar and go to the AUTHORIZATION tab.

  2. Pick a service that you want to connect and select ADD GATEWAY API for the selected service.

  3. In the Add Gateway API Group popup window, highlight an API group that you want to add and select CONNECT.

Result

In the APIs tab of the Gateway Management view, you can see specific API groups integrated to services.

Apply a sample policy

  1. Create a policy.

  2. Select APIs from the left sidebar and go to the AUTHORIZATION tab.

  3. Select a service protected by Azure to preview all the available APIs (1) and click any API with authorization status None to open it for editing (2).

  4. In the Edit API popup window, select Policy from the dropdown list and click UPDATE.

Result

You’ve successfully applied a policy to the selected API.

Check if it works

Call one of the APIs that your Azure API gateway hosts and note down the system’s response.

Note

For URL to perform your call to, navigate to Microsoft Azure > API Management services. Preview your service and copy Gateway URL.

Example

Visit https://acp-test.azure-api.net in your browser.

  • If the policy applied in ACP to the called API allows the access, you receive a response from a target service.

  • If your policy restricts the access, you receive a 403 error message.