|
| 1 | +--- |
| 2 | +title: Remote-write in Azure Monitor Managed Service for Prometheus using Azure Active Directory (preview) |
| 3 | +description: Describes how to configure remote-write to send data from self-managed Prometheus running in your Kubernetes cluster running on-premises or in another cloud using Azure Active Directory authentication. |
| 4 | +author: bwren |
| 5 | +ms.topic: conceptual |
| 6 | +ms.date: 11/01/2022 |
| 7 | +--- |
| 8 | + |
| 9 | +# Configure remote write for Azure Monitor managed service for Prometheus using Azure Active Directory authentication (preview) |
| 10 | +This article describes how to configure [remote-write](prometheus-remote-write.md) to send data from self-managed Prometheus running in your AKS cluster or Azure Arc-enabled Kubernetes cluster using Azure Active Directory authentication. |
| 11 | + |
| 12 | +## Cluster configurations |
| 13 | +This article applies to the following cluster configurations: |
| 14 | + |
| 15 | +- Azure Kubernetes service (AKS) |
| 16 | +- Azure Arc-enabled Kubernetes cluster |
| 17 | +- Kubernetes cluster running in another cloud or on-premises |
| 18 | + |
| 19 | +> [!NOTE] |
| 20 | +> For Azure Kubernetes service (AKS) or Azure Arc-enabled Kubernetes cluster, managed identify authentication is recommended. See [Azure Monitor managed service for Prometheus remote write - managed identity (preview)](prometheus-remote-write-managed-identity.md). |
| 21 | +
|
| 22 | +## Prerequisites |
| 23 | +See prerequisites at [Azure Monitor managed service for Prometheus remote write (preview)](prometheus-remote-write.md#prerequisites). |
| 24 | + |
| 25 | +## Create Azure Active Directory application |
| 26 | +Follow the procedure at [Register an application with Azure AD and create a service principal](../../active-directory/develop/howto-create-service-principal-portal.md#register-an-application-with-azure-ad-and-create-a-service-principal) to register an application for Prometheus remote-write and create a service principal. |
| 27 | + |
| 28 | + |
| 29 | +## Get the client ID of the Azure Active Directory application. |
| 30 | + |
| 31 | +1. From the **Azure Active Directory** menu in Azure Portal, select **App registrations**. |
| 32 | +2. Locate your application and note the client ID. |
| 33 | + |
| 34 | + :::image type="content" source="media/prometheus-remote-write-active-directory/application-client-id.png" alt-text="Screenshot showing client ID of Azure Active Directory application." lightbox="media/prometheus-remote-write-active-directory/application-client-id.png"::: |
| 35 | + |
| 36 | +## Assign Monitoring Metrics Publisher role on the data collection rule to the application |
| 37 | +The application requires the *Monitoring Metrics Publisher* role on the data collection rule associated with your Azure Monitor workspace. |
| 38 | + |
| 39 | +1. From the menu of your Azure Monitor Workspace account, click the **Data collection rule** to open the **Overview** page for the data collection rule. |
| 40 | + |
| 41 | + :::image type="content" source="media/prometheus-remote-write-managed-identity/azure-monitor-account-data-collection-rule.png" alt-text="Screenshot showing data collection rule used by Azure Monitor workspace." lightbox="media/prometheus-remote-write-managed-identity/azure-monitor-account-data-collection-rule.png"::: |
| 42 | + |
| 43 | +2. Click on **Access control (IAM)** in the **Overview** page for the data collection rule. |
| 44 | + |
| 45 | + :::image type="content" source="media/prometheus-remote-write-managed-identity/azure-monitor-account-access-control.png" alt-text="Screenshot showing Access control (IAM) menu item on the data collection rule Overview page." lightbox="media/prometheus-remote-write-managed-identity/azure-monitor-account-access-control.png"::: |
| 46 | + |
| 47 | +3. Click **Add** and then **Add role assignment**. |
| 48 | + |
| 49 | + :::image type="content" source="media/prometheus-remote-write-managed-identity/data-collection-rule-add-role-assignment.png" alt-text="Screenshot showing adding a role assignment on Access control pages." lightbox="media/prometheus-remote-write-managed-identity/data-collection-rule-add-role-assignment.png"::: |
| 50 | + |
| 51 | +4. Select **Monitoring Metrics Publisher** role and click **Next**. |
| 52 | + |
| 53 | + :::image type="content" source="media/prometheus-remote-write-managed-identity/add-role-assignment.png" alt-text="Screenshot showing list of role assignments." lightbox="media/prometheus-remote-write-managed-identity/add-role-assignment.png"::: |
| 54 | + |
| 55 | +5. Select **User, group, or service principal** and then click **Select members**. Select the application that you created and click **Select**. |
| 56 | + |
| 57 | + :::image type="content" source="media/prometheus-remote-write-active-directory/select-application.png" alt-text="Screenshot showing selection of application." lightbox="media/prometheus-remote-write-active-directory/select-application.png"::: |
| 58 | + |
| 59 | +6. Click **Review + assign** to complete the role assignment. |
| 60 | + |
| 61 | + |
| 62 | +## Create an Azure key vault and generate certificate |
| 63 | + |
| 64 | +1. If you don't already have an Azure key vault, then create a new one using the guidance at [Create a vault](../../key-vault/general/quick-create-portal.md#create-a-vault). |
| 65 | +2. Create a certificate using the guidance at [Add a certificate to Key Vault](../../key-vault/certificates/quick-create-portal.md#add-a-certificate-to-key-vault). |
| 66 | +3. Download the newly generated certificate in CER format using the guidance at [Export certificate from Key Vault](../../key-vault/certificates/quick-create-portal.md#export-certificate-from-key-vault). |
| 67 | + |
| 68 | +## Add certificate to the Azure Active Directory application |
| 69 | + |
| 70 | +1. From the menu for your Azure Active Directory application, select **Certificates & secrets**. |
| 71 | +2. Click **Upload certificate** and select the certificate that you downloaded. |
| 72 | + |
| 73 | + :::image type="content" source="media/prometheus-remote-write-active-directory/upload-certificate.png" alt-text="Screenshot showing upload of certificate for Azure Active Directory application." lightbox="media/prometheus-remote-write-active-directory/upload-certificate.png"::: |
| 74 | + |
| 75 | +> [!WARNING] |
| 76 | +> Certificates have an expiration date, and it's the responsibility of the user to keep these certificates valid. |
| 77 | +
|
| 78 | +## Add CSI driver and storage for cluster |
| 79 | + |
| 80 | +> [!NOTE] |
| 81 | +> Azure Key Vault CSI driver configuration is just one of the ways to get certificate mounted on the pod. The remote write container only needs a local path to a certificate in the pod for the setting `AZURE_CLIENT_CERTIFICATE_PATH` value in the [Deploy Side car and configure remote write on the Prometheus server](#deploy-side-car-and-configure-remote-write-on-the-prometheus-server) step below. |
| 82 | +
|
| 83 | +This step is only required if you didn't enable Azure Key Vault Provider for Secrets Store CSI Driver when you created your cluster. |
| 84 | + |
| 85 | +1. Run the following Azure CLI command to enable Azure Key Vault Provider for Secrets Store CSI Driver for your cluster. |
| 86 | + |
| 87 | + ```azurecli |
| 88 | + az aks enable-addons --addons azure-keyvault-secrets-provider --name <aks-cluster-name> --resource-group <resource-group-name> |
| 89 | + ``` |
| 90 | +
|
| 91 | +2. Run the following commands to give the identity access to the key vault. |
| 92 | +
|
| 93 | + ```azurecli |
| 94 | + # show client id of the managed identity of the cluster |
| 95 | + az aks show -g <resource-group> -n <cluster-name> --query addonProfiles.azureKeyvaultSecretsProvider.identity.clientId -o tsv |
| 96 | +
|
| 97 | + # set policy to access keys in your key vault |
| 98 | + az keyvault set-policy -n <keyvault-name> --key-permissions get --spn <identity-client-id> |
| 99 | +
|
| 100 | + # set policy to access secrets in your key vault |
| 101 | + az keyvault set-policy -n <keyvault-name> --secret-permissions get --spn <identity-client-id> |
| 102 | + |
| 103 | + # set policy to access certs in your key vault |
| 104 | + az keyvault set-policy -n <keyvault-name> --certificate-permissions get --spn <identity-client-id> |
| 105 | + ``` |
| 106 | +
|
| 107 | +3. Create a *SecretProviderClass* by saving the following YAML to a file named *secretproviderclass.yml*. Replace the values for `userAssignedIdentityID`, `keyvaultName`, `tenantId` and the objects to retrieve from your key vault. See [Provide an identity to access the Azure Key Vault Provider for Secrets Store CSI Driver](../../aks/csi-secrets-store-identity-access.md) for details on values to use. |
| 108 | +
|
| 109 | + ```yml |
| 110 | + # This is a SecretProviderClass example using user-assigned identity to access your key vault |
| 111 | + apiVersion: secrets-store.csi.x-k8s.io/v1 |
| 112 | + kind: SecretProviderClass |
| 113 | + metadata: |
| 114 | + name: azure-kvname-user-msi |
| 115 | + spec: |
| 116 | + provider: azure |
| 117 | + parameters: |
| 118 | + usePodIdentity: "false" |
| 119 | + useVMManagedIdentity: "true" # Set to true for using managed identity |
| 120 | + userAssignedIdentityID: <client-id> # Set the clientID of the user-assigned managed identity to use |
| 121 | + keyvaultName: <key-vault-name> # Set to the name of your key vault |
| 122 | + cloudName: "" # [OPTIONAL for Azure] if not provided, the Azure environment defaults to AzurePublicCloud |
| 123 | + objects: | |
| 124 | + array: |
| 125 | + - | |
| 126 | + objectName: <name-of-cert> |
| 127 | + objectType: secret # object types: secret, key, or cert |
| 128 | + objectFormat: pfx |
| 129 | + objectEncoding: base64 |
| 130 | + objectVersion: "" |
| 131 | + tenantId: <tenant-id> # The tenant ID of the key vault |
| 132 | + ``` |
| 133 | +
|
| 134 | +4. Apply the *SecretProviderClass* by running the following command on your cluster. |
| 135 | +
|
| 136 | + ``` |
| 137 | + kubectl apply -f secretproviderclass.yml |
| 138 | + ``` |
| 139 | +
|
| 140 | +## Deploy Side car and configure remote write on the Prometheus server |
| 141 | +
|
| 142 | +1. Copy the YAML below and save to a file. This YAML assumes you're using 8081 as your listening port. Modify that value if you use a different port. |
| 143 | +
|
| 144 | +
|
| 145 | + ```yml |
| 146 | + prometheus: |
| 147 | + prometheusSpec: |
| 148 | + cluster: <CLUSTER-NAME> |
| 149 | +
|
| 150 | + ## https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write |
| 151 | + remoteWrite: |
| 152 | + - url: 'http://localhost:8081/api/v1/write' |
| 153 | + |
| 154 | + # Additional volumes on the output StatefulSet definition. |
| 155 | + # Required only for AAD based auth |
| 156 | + volumes: |
| 157 | + - name: secrets-store-inline |
| 158 | + csi: |
| 159 | + driver: secrets-store.csi.k8s.io |
| 160 | + readOnly: true |
| 161 | + volumeAttributes: |
| 162 | + secretProviderClass: azure-kvname-user-msi |
| 163 | + containers: |
| 164 | + - name: prom-remotewrite |
| 165 | + image: <CONTAINER-IMAGE-VERSION> |
| 166 | + imagePullPolicy: Always |
| 167 | +
|
| 168 | + # Required only for AAD based auth |
| 169 | + volumeMounts: |
| 170 | + - name: secrets-store-inline |
| 171 | + mountPath: /mnt/secrets-store |
| 172 | + readOnly: true |
| 173 | + ports: |
| 174 | + - name: rw-port |
| 175 | + containerPort: 8081 |
| 176 | + livenessProbe: |
| 177 | + httpGet: |
| 178 | + path: /health |
| 179 | + port: rw-port |
| 180 | + initialDelaySeconds: 10 |
| 181 | + timeoutSeconds: 10 |
| 182 | + readinessProbe: |
| 183 | + httpGet: |
| 184 | + path: /ready |
| 185 | + port: rw-port |
| 186 | + initialDelaySeconds: 10 |
| 187 | + timeoutSeconds: 10 |
| 188 | + env: |
| 189 | + - name: INGESTION_URL |
| 190 | + value: '<INGESTION_URL>' |
| 191 | + - name: LISTENING_PORT |
| 192 | + value: '8081' |
| 193 | + - name: IDENTITY_TYPE |
| 194 | + value: aadApplication |
| 195 | + - name: AZURE_CLIENT_ID |
| 196 | + value: '<APP-REGISTRATION-CLIENT-ID>' |
| 197 | + - name: AZURE_TENANT_ID |
| 198 | + value: '<TENANT-ID>' |
| 199 | + - name: AZURE_CLIENT_CERTIFICATE_PATH |
| 200 | + value: /mnt/secrets-store/<CERT-NAME> |
| 201 | + - name: CLUSTER |
| 202 | + value: '<CLUSTER-NAME>' |
| 203 | + ``` |
| 204 | +
|
| 205 | +
|
| 206 | +2. Replace the following values in the YAML. |
| 207 | +
|
| 208 | + | Value | Description | |
| 209 | + |:---|:---| |
| 210 | + | `<CLUSTER-NAME>` | Name of your AKS cluster | |
| 211 | + | `<CONTAINER-IMAGE-VERSION>` | `mcr.microsoft.com/azuremonitor/prometheus/promdev/prom-remotewrite:prom-remotewrite-20221102.1`<br>This is the remote write container image version. | |
| 212 | + | `<INGESTION-URL>` | **Metrics ingestion endpoint** from the **Overview** page for the Azure Monitor workspace | |
| 213 | + | `<APP-REGISTRATION -CLIENT-ID> ` | Client ID of your application | |
| 214 | + | `<TENANT-ID> ` | Tenant ID of the Azure Active Directory application | |
| 215 | + | `<CERT-NAME>` | Name of the certificate | |
| 216 | + | `<CLUSTER-NAME>` | Name of the cluster Prometheus is running on | |
| 217 | +
|
| 218 | + |
| 219 | +
|
| 220 | +
|
| 221 | +
|
| 222 | +3. Open Azure Cloud Shell and upload the YAML file. |
| 223 | +4. Use helm to apply the YAML file to update your Prometheus configuration with the following CLI commands. |
| 224 | +
|
| 225 | + ```azurecli |
| 226 | + # set context to your cluster |
| 227 | + az aks get-credentials -g <aks-rg-name> -n <aks-cluster-name> |
| 228 | + |
| 229 | + # use helm to update your remote write config |
| 230 | + helm upgrade -f <YAML-FILENAME>.yml prometheus prometheus-community/kube-prometheus-stack -namespace <namespace where Prometheus pod resides> |
| 231 | + ``` |
| 232 | +
|
| 233 | +## Verification and troubleshooting |
| 234 | +See [Azure Monitor managed service for Prometheus remote write (preview)](prometheus-remote-write.md#verify-remote-write-is-working-correctly). |
| 235 | +
|
| 236 | +## Next steps |
| 237 | +
|
| 238 | += [Setup Grafana to use Managed Prometheus as a data source](prometheus-grafana.md). |
| 239 | +- [Learn more about Azure Monitor managed service for Prometheus](prometheus-metrics-overview.md). |
0 commit comments