Hanzo
PlatformHanzo KMSPlatformIdentities

Azure Auth

Learn how to authenticate with Hanzo KMS for services on Azure

Azure Auth is an Azure-native authentication method for Azure resources like Azure VMs, Azure App Services, Azure Functions, Azure Kubernetes Service, etc. to access Hanzo KMS.

Diagram

The following sequence diagram illustrates the Azure Auth workflow for authenticating Azure service principals with Hanzo KMS.

sequenceDiagram
  participant Client as Client
  participant Infis as Hanzo KMS
  participant Azure as Azure AD OpenID

  Note over Client,Azure: Step 1: Instance Identity Token Retrieval
  Client->>Azure: Request managed identity access token
  Azure-->>Client: Return managed identity access token

  Note over Client,Infis: Step 2: Identity Token Login Operation
  Client->>Infis: Send managed identity access token to /api/v1/auth/azure-auth/login
  Infis->>Azure: Request public key
  Azure-->>Infis: Return public key

  Note over Infis: Step 3: Identity Token Verification
  Note over Infis: Step 4: Identity Property Validation
  Infis->>Client: Return short-lived access token

  Note over Client,Infis: Step 4: Access Hanzo KMS API with Token
  Client->>Infis: Make authenticated requests using the short-lived access token

Concept

At a high-level, Hanzo KMS authenticates an Azure service by verifying its identity and checking that it meets specific requirements (e.g. it is bound to an allowed service principal) at the /api/v1/auth/azure-auth/login endpoint. If successful, then Hanzo KMS returns a short-lived access token that can be used to make authenticated requests to the Hanzo KMS API.

To be more specific:

  1. The client running on an Azure service obtains an access token that is a JWT token representing the managed identity for the Azure resource such as a Virtual Machine; the managed identity is associated with a service principal in Azure AD.
  2. The client sends the access token to Hanzo KMS.
  3. Hanzo KMS verifies the token against the corresponding public key at the public Azure AD OpenID configuration endpoint.
  4. Hanzo KMS checks if the entity behind the access token is allowed to authenticate with Hanzo KMS based on set criteria such as Allowed Service Principal IDs.
  5. If all is well, Hanzo KMS returns a short-lived access token that the client can use to make authenticated requests to the Hanzo KMS API.

We recommend using one of Hanzo KMS's clients like SDKs or the KMS Agent to authenticate with Hanzo KMS using Azure Auth as they handle the authentication process including generating the client access token for you.

Also, note that Hanzo KMS needs network-level access to send requests to the Google Cloud API as part of the Azure Auth workflow.

Guide

In the following steps, we explore how to create and use identities for your applications in Azure to access the Hanzo KMS API using the Azure Auth authentication method.

To create an identity, head to your Organization Settings > Access Control > Identities and press Create identity.

identities organization

When creating an identity, you specify an organization level role for it to assume; you can configure roles in Organization Settings > Access Control > Organization Roles.

identities organization create

Now input a few details for your new identity. Here's some guidance for each field:

  • Name (required): A friendly name for the identity.
  • Role (required): A role from the Organization Roles tab for the identity to assume. The organization role assigned will determine what organization level resources this identity can have access to.

Once you've created an identity, you'll be redirected to a page where you can manage the identity.

identities page

Since the identity has been configured with Universal Auth by default, you should re-configure it to use Azure Auth instead. To do this, press to edit the Authentication section, remove the existing Universal Auth configuration, and add a new Azure Auth configuration onto the identity.

identities page remove default auth

identities create azure auth method

Here's some more guidance on each field:

  • Tenant ID: The tenant ID for the Azure AD organization.
  • Resource / Audience: The resource URL for the application registered in Azure AD. The value is expected to match the aud claim of the access token JWT later used in the login operation against Hanzo KMS. See the resource parameter for how the audience is set when requesting a JWT access token from the Azure Instance Metadata Service (IMDS) endpoint. In most cases, this value should be https://management.azure.com/ which is the default.
  • Allowed Service Principal IDs: A comma-separated list of Azure AD service principal IDs that are allowed to authenticate with Hanzo KMS.
  • Access Token TTL (default is 2592000 equivalent to 30 days): The lifetime for an acccess token in seconds. This value will be referenced at renewal time.
  • Access Token Max TTL (default is 2592000 equivalent to 30 days): The maximum lifetime for an acccess token in seconds. This value will be referenced at renewal time.
  • Access Token Max Number of Uses (default is 0): The maximum number of times that an access token can be used; a value of 0 implies infinite number of uses.
  • Access Token Trusted IPs: The IPs or CIDR ranges that access tokens can be used from. By default, each token is given the 0.0.0.0/0, allowing usage from any network address.

To enable the identity to access project-level resources such as secrets within a specific project, you should add it to that project.

To do this, head over to the project you want to add the identity to and go to Project Settings > Access Control > Machine Identities and press Add identity.

Next, select the identity you want to add to the project and the project level role you want to allow it to assume. The project role assigned will determine what project level resources this identity can have access to.

identities project

identities project create

To access the Hanzo KMS API as the identity, you need to generate a managed identity access token that is a JWT token representing the managed identity for the Azure resource such as a Virtual Machine. The client token must be sent to the /api/v1/auth/azure-auth/login endpoint in exchange for a separate access token to access the Hanzo KMS API.

We provide a few code examples below of how you can authenticate with Hanzo KMS to access the Hanzo KMS API.

Start by making a request from your Azure client such as Virtual Machine to obtain a managed identity access token.

For more examples of how to obtain the managed identity access token, refer to the official documentation.

Sample request

curl 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fmanagement.azure.com%2F' -H Metadata:true -s

Sample response

{
    "access_token": "eyJ0eXAi...",
    "refresh_token": "",
    "expires_in": "3599",
    "expires_on": "1506484173",
    "not_before": "1506480273",
    "resource": "https://management.azure.com/",
    "token_type": "Bearer"
}

Next use send the obtained managed identity access token (i.e. the token from the access_token field above) to authenticate with Hanzo KMS and obtain a separate access token.

Sample request

curl --location --request POST 'https://app.kms.hanzo.ai/api/v1/auth/gcp-auth/login' \
    --header 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'identityId=...' \
    --data-urlencode 'jwt=...'

Note that you should replace <identityId> with the ID of the identity you created in step 1.

Sample response

{
    "accessToken": "...",
    "expiresIn": 7200,
    "accessTokenMaxTTL": 43244
    "tokenType": "Bearer"
}

Next, you can use this access token to access the Hanzo KMS API

We recommend using one of Hanzo KMS's clients like SDKs or the KMS Agent to authenticate with Hanzo KMS using Azure Auth as they handle the authentication process including retrieving the client access token.

Each identity access token has a time-to-live (TTL) which you can infer from the response of the login operation; the default TTL is 7200 seconds which can be adjusted. If an identity access token expires, it can no longer authenticate with the Hanzo KMS API. In this case, a new access token should be obtained by performing another login operation.

How is this guide?

Last updated on

On this page