|
| 1 | +--- |
| 2 | +title: Use Multiple Certificates in Azure Load Testing |
| 3 | +titleSuffix: Azure Load Testing |
| 4 | +description: Learn how to configure and use multiple certificates securely in Azure Load Testing with a JKS file and Key Vault integration. |
| 5 | +services: load-testing |
| 6 | +ms.service: azure-load-testing |
| 7 | +author: saloniagrawal1997 |
| 8 | +ms.author: salagrawal |
| 9 | +ms.date: 01/24/2025 |
| 10 | +ms.topic: how-to |
| 11 | +--- |
| 12 | + |
| 13 | + |
| 14 | +# Using multiple certificates in Azure Load Testing |
| 15 | + |
| 16 | +Azure Load Testing supports the use of multiple certificates for secure communication during load testing scenarios. This article explains how to consolidate multiple certificates into a Java KeyStore (JKS) file, securely store the keystore password in Azure Key Vault (AKV), and configure Azure Load Testing to use the JKS file. |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | +Before you begin, ensure the following: |
| 20 | +- You have an [Azure Key Vault](https://jmeter-plugins.org/wiki/PluginsManager/) instance set up to store secrets. |
| 21 | +- You have the [Managed Identity (MI)](./how-to-use-a-managed-identity.md) of your Azure Load Testing resource configured. |
| 22 | +- You have created a [Java KeyStore (JKS)](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html) file containing all required certificates. |
| 23 | +- You have stored the JKS password as a secret in Azure Key Vault. |
| 24 | + |
| 25 | +## Steps to configure multiple certificates |
| 26 | + |
| 27 | +### Step 1: Create and secure the JKS file |
| 28 | +1. Use the **keytool utility** to create a JKS file and import all necessary certificates. |
| 29 | + ```Terminal |
| 30 | + keytool -importcert -file <certificate-file> -keystore <keystore-name>.jks -alias <alias-name> |
| 31 | + ``` |
| 32 | +1. Store the JKS file's password as a secret in Azure Key Vault: |
| 33 | + - Open the Azure portal and navigate to your Key Vault. |
| 34 | + - Select **Objects > Secrets > Generate/Import**. |
| 35 | + - Enter a name and the password for the JKS file, then click **Create**. |
| 36 | + |
| 37 | +### Step 2: Assign access to the Azure Load Testing managed identity |
| 38 | +1. In the Azure portal, go to your Azure Key Vault resource and select **Access Policies** from the left pane, then click **+ Create**. |
| 39 | +1. On the Permissions tab: |
| 40 | + - Under **Secret permissions**, select **Get**. |
| 41 | + - Click **Next**. |
| 42 | +1. On the **Principal** tab: |
| 43 | + - Search for and select the managed identity for the load testing resource. |
| 44 | + - Click **Next**. |
| 45 | + - If you're using a system-assigned managed identity, the managed identity name matches that of your Azure Load Testing resource. |
| 46 | +1. Click **Next** again to complete the access policy configuration. |
| 47 | + |
| 48 | +When your test runs, the managed identity associated with your load testing resource can now read the secret for your load test from your Key Vault. |
| 49 | +Now that you've added a secret in Azure Key Vault and configured a secret for your load test, move to use secrets in Apache JMeter. |
| 50 | + |
| 51 | +### Step 3: Use keystore configuration and JSR223 PreProcessor |
| 52 | +**Keystore configuration** |
| 53 | + |
| 54 | +1. In your JMeter script, add the **Keystore Configuration** element to manage SSL certificates. |
| 55 | + - Go to **Test Plan > Add > Config Element > Keystore Configuration**. |
| 56 | + - Set the Alias field to match the certificate alias in your JKS file. |
| 57 | + |
| 58 | +**JSR223 PreProcessor for dynamic SSL configuration** |
| 59 | + |
| 60 | +1. Add a **JSR223 PreProcessor** to dynamically configure the SSL properties at runtime. |
| 61 | + - Go to **Thread Group > Add > PreProcessors > JSR223 PreProcessor**. |
| 62 | + - Set the language to Java. |
| 63 | + - Add the following script: |
| 64 | + ```Terminal |
| 65 | + System.setProperty("javax.net.ssl.keyStoreType", "PKCS12"); |
| 66 | + System.setProperty("javax.net.ssl.keyStore", "<path-to-your-keystore>"); |
| 67 | + System.setProperty("javax.net.ssl.keyStorePassword", "<keystore-password>"); |
| 68 | + ``` |
| 69 | +1. Replace `path-to-your-keystore` and `keystore-password` with your actual keystore file path and password. |
| 70 | + |
| 71 | +### Step 4: Add a CSV data set config to iterate over certificates |
| 72 | +1. In your JMeter script, add a **CSV Data Set Config** element to iterate over the certificates in your JKS file. |
| 73 | + - Go to **Test Plan > Add > Config Element > CSV Data Set Config**. |
| 74 | + - Configure the following fields: |
| 75 | + - Filename: Path to the CSV file containing certificate aliases. |
| 76 | + - Variable Names: Name of the variable (e.g., certificateAlias). |
| 77 | +1. Create a CSV file with a list of certificate aliases from your JKS file. Each alias should be on a new line. |
| 78 | +1. Use the variable (e.g., ${certificateAlias}) in the Keystore Configuration or scripts to dynamically reference the current certificate alias during the test execution. |
| 79 | + |
| 80 | +### Step 5: Upload test files |
| 81 | +1. In the Azure portal, navigate to your Azure Load Testing resource and start a new test creation workflow. |
| 82 | +1. Upload the following files: |
| 83 | + - The JKS file. |
| 84 | + - Your JMeter test script. |
| 85 | + - The CSV file with certificate aliases. |
| 86 | + |
| 87 | +### Step 6: Configure parameters |
| 88 | +1. Go to the **Parameters** tab in the test creation workflow. |
| 89 | +1. Add a secret for the JKS password: |
| 90 | + - Name: The name of the secret in Azure Key Vault. |
| 91 | + - Value: The Key Vault URL (e.g., https://`key-vault-name`.vault.azure.net/secrets/`secret-name`). |
| 92 | +1. Configure the **Key Vault reference identity**, by specifying the Managed Identity of the Azure Load Testing resource that will access the Key Vault secret. |
| 93 | + |
| 94 | +Review all configurations to ensure correctness. Click **Create Test** to finalize and run the test. |
| 95 | + |
| 96 | +## Related content |
| 97 | + |
| 98 | +* [Use a Managed Identity in Azure Load Testing](./how-to-use-a-managed-identity.md) |
| 99 | + |
| 100 | +* [Test secure endpoints in Azure Load Testing](./how-to-test-secured-endpoints.md) |
0 commit comments