Licensing Automation on Azure
To activate the instances where the MetaDefender products are running, it is needed to activate these products providing the LICENSE_KEY.
There are 2 options to manage the licensing that will automate the activation and deactivation of the products.
Azure Function to handle the VMSS events
Diagram

Solution recommended for production as the activation and deactivation does not depend if the VM is gracefully terminated or not
Pre-requisites
This sections presumed that a VMSS has been created with the Azure VM image generated based on the database mode desired. If not please go to VM Scale Set
Resources Needed
- Azure Function App
- Azure Key Vault
- Azure Event System Topic
- Azure Event Subscription
- Azure Function to run within the Azure Function App
This guidelines are for creating the resources from Azure Portal. To use Terraform please check
Azure Function
Check the Deployment Options for Azure Functions
This function has 2 different tasks.
- Activation: Retrieve the LICENSE_KEY and APIKEY from Azure Secret and activate the VM. Store the deployment ID to Azure Key Vault using VM as key
- Deactivation: Retrieve Deployment ID from Azure Secret and deactivate the deployment.
Steps to create the Azure Function
Create the Azure Function App (Recommended Flex Consumption Plan)
Create Azure Key Vault with the following required keys
- License Key (licenseKey)
- API Key (apiKey)
- Core UI User (coreUser)
- Core UI Password (corePwd)
Create an Access Policy in the Key Vault for the Azure Function to "Get", "Set", "List", "Delete", "Purge" and "Recover"
Set Up as environment variables for the Azure Function App
- SUBSCRIPTION_ID
- KEY_VAULT_NAME
Deploy the Event Licensing Handler Function
Trigger the Azure Function
This Azure Function has to be triggered by an Azure Event Grid System Topic and a Event Grid Subscription to link the topic and trigger the Azure Function based on events that will be specified in the subscription.
Create Event Grid System Topic
This topic will generate events for the resource group linked to it.
How to create it from Azure portal
- Go to Event Grid > Azure Service Event > System Topics
- Create Topic > Select Azure Subscription or Resource Group
- Enable system assigned identity and input all the tags
Create Event Grid Subscription to System Topic and Azure Function
The subscription will link the Azure Event Grid Topic to the Azure Function already created.
How to create the Event Grid Subscription
Go to Event Topic and create Subscription from within it
Indicate name and Event Grid Schema
Under Event Types select only Resource Action Success
Configure the Endpoint to be the Azure function created in previous section
Under filters Enable subject filtering
- Subject Begins With: "/subscriptions/{subscription_id}/resourceGroups/{RG_NAME}/providers/Microsoft.Compute/virtualMachines"
Under Advanced Filters
- Key: data.operationName
- Values:
- "Microsoft.Compute/virtualMachines/start/action"
- "Microsoft.Compute/virtualMachines/deallocate/action"
- "Microsoft.Compute/virtualMachines/powerOff/action"
Setting Up Environment Variables using user-data (Only POC)
Only works with OPSWAT Marketplace Images that are prepared to handle user-data
This option is the default and recommended mechanism to automate the licensing management when using the Azure Marketplace Image, as this is the easiest way to activate and deactivate the product when running a single VM of MetaDefender Core
When passing as environment variables to the user-data the LICENSE_KEY it will set up the automation that will activate the product when the instance is started and will deactivate the product when the instance is terminated or stopped.
It is also recommended to indicate the APIKEY environment variables as this will set up the APIKEY to the admin user to be able to make requests to the MetaDefender Core API. In vm scale set deployment types it will help to manage all the instances with the same APIKEY when hitting the Load Balancer.
Licensing when running in Kubernetes
The licensing automation options when the MetaDefender products are installed in a Kubernetes cluster, are explained in Licensing in K8S