Skip to content

Latest commit

 

History

History
178 lines (108 loc) · 7.51 KB

APPROOV_TOKEN_QUICKSTART.md

File metadata and controls

178 lines (108 loc) · 7.51 KB

Approov Token Quickstart

This quickstart is for developers familiar with Azure who are looking for a quick intro into how they can add Approov into an existing project. Therefore this will guide you through the necessary steps for adding Approov to an existing Azure API management platform.

TOC - Table of Contents

Why?

To lock down your API server to your mobile app. Please read the brief summary in the README at the root of this repo or visit our website for more details.

TOC

How it works?

For more background, see the overview in the README at the root of this repo.

TOC

Requirements

To complete this quickstart you will need to already have an Azure API management platform created, and the Approov CLI tool installed.

TOC

Approov Setup

To use Approov with the Azure API management platform we need a small amount of configuration. First, Approov needs to know the API domain that will be protected. Second, the Azure API management platform needs the Approov Base64 encoded secret that will be used to verify the tokens generated by the Approov cloud service.

Configure API Domain

Approov needs to know the domain name of the API for which it will issue tokens.

Add it with:

approov api -add your.azure-api.domain.com

NOTE: By default a symmetric key (HS256) is used to sign the Approov token on a valid attestation of the mobile app for each API domain it's added with the Approov CLI, so that all APIs will share the same secret and the backend needs to take care to keep this secret secure.

A more secure alternative is to use asymmetric keys (RS256 or others) that allows for a different keyset to be used on each API domain and for the Approov token to be verified with a public key that can only verify, but not sign, Approov tokens.

To implement the asymmetric key you need to change from using the symmetric HS256 algorithm to an asymmetric algorithm, for example RS256, that requires you to first add a new key, and then specify it when adding each API domain. Please visit Managing Key Sets on the Approov documentation for more details.

Adding the API domain also configures the dynamic certificate pinning setup, out of the box.

NOTE: By default the pin is extracted from the public key of the leaf certificate served by the domain, as visible to the box issuing the Approov CLI command and the Approov servers.

Approov Secret

Approov tokens are signed with a symmetric secret. To verify tokens, we need to grab the secret using the Approov secret command and plug it into the Azure API management platform environment to check the signatures of the Approov Tokens that it processes.

To retrieved the Approov secret you need to enable your admin role with:

eval `approov role admin`

Retrieve the Approov secret with:

approov secret -get base64

Set the Approov Secret

The Approov secret MUST be a named value, and we recommend to use approov-base64-secret as its name. Never use it directly in the policy statement.

The named value for the Approov secret MUST be created using the type secret to guarantee that is stored encrypted. You can also create it using the type key vault, that will retrieve it from the Azure Key Vault, therefore you must have already created it there.

IMPORTANT: Never add the Approov Secret with the type plain text for the named value.

TOC

Approov Token Check

To check the Approov token in any existing Azure API management platform project we just need to add an inbound processing policy to the API we want to protect with Approov.

We will use the validate-jwt policy with this policy statement:

<policies>
    <inbound>
        <base />
        <validate-jwt header-name="Approov-Token" failed-validation-httpcode="401" failed-validation-error-message="Unauthorized" require-expiration-time="true" require-signed-tokens="true">
            <issuer-signing-keys>
                <!-- Replace approov-base64-secret with whatever you have used to add the Approov Secret as a named value. -->
                <key>{{approov-base64-secret}}</key>
            </issuer-signing-keys>
        </validate-jwt>
    </inbound>
</policies>

NOTE: When the Approov token validation fails we return a 401 with no further details in the message, because we don't want to give the specifics to an attacker about the reason the request failed, and you can go even further by returning a 400.

TOC

Test your Approov Integration

The following examples below use cURL, but you can also use the Postman Collection to make the API requests. Just remember that you need to adjust the urls and tokens defined in the collection to match your deployment. Alternatively, the README for the Postman Collection also contains instructions for using the preset dummy secret to test your Approov integration.

With Valid Approov Tokens

Generate a valid token example from the Approov Cloud service:

approov token -genExample your.azure-api.domain.com

Then make the request with the generated token:

curl -i --request GET 'https://your.azure-api.domain.com' \
  --header 'Ocp-Apim-Subscription-Key: ___AZURE_SUBSCRIPTION_KEY_HERE___' \
  --header 'Approov-Token: ___APPROOV_TOKEN_EXAMPLE_HERE___'

The request should be accepted. For example:

HTTP/1.1 200 OK

...

{"key": "The response from your backend API"}

With Invalid Approov Tokens

Generate an invalid token example from the Approov Cloud service:

approov token -type invalid -genExample your.azure-api.domain.com

Then make the request with the generated token:

curl -i --request GET 'https://your.azure-api.domain.com' \
  --header 'Ocp-Apim-Subscription-Key: ___AZURE_SUBSCRIPTION_KEY_HERE___' \
  --header 'Approov-Token: ___APPROOV_INVALID_TOKEN_EXAMPLE_HERE___'

The above request should fail with an Unauthorized error. For example:

HTTP/1.1 401 Unauthorized

...
{
    "statusCode": 401,
    "message": "Unauthorized"
}

TOC