> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/microsoft-azure-manual-onboarding/azure-manual-onboarding-guide/azure-manual-onboarding-subscription-scope/phase-4-audit-logs.md).

# Phase 4: Audit Logs

Module: AUDIT\_LOGS

The Audit Logs pipeline routes the subscription Activity Log to an Azure Event Hub. The Cortex Collector authenticates as a per-customer User-Assigned Managed Identity (UAMI) via workload identity federation, and uses an Azure Storage Account to checkpoint Event Hub partition offsets.

Note: The namespace and Event Hub must belong to the specific Azure subscription being onboarded. Cross-subscription or centralized logging is not currently supported.

### 4.1 Create the user-assigned managed identity (UAMI)

The UAMI is the workload identity assumed by the Cortex Collector. Because authentication relies on workload identity federation, there are no secrets to rotate.

```shell
az identity create \
    --resource-group "<RG_NAME>" \
    --name "<AUDIT_UAMI_NAME>" \
    --location "<LOCATION>" \
    --tags managed_by=paloaltonetworks

# Capture the two identifiers needed below
export AUDIT_UAMI_CLIENT_ID=$(az identity show \
    --resource-group "<RG_NAME>" \
    --name "<AUDIT_UAMI_NAME>" --query clientId -o tsv)
export AUDIT_UAMI_PRINCIPAL_ID=$(az identity show \
    --resource-group "<RG_NAME>" \
    --name "<AUDIT_UAMI_NAME>" --query principalId -o tsv)

echo "AUDIT_UAMI_CLIENT_ID=${AUDIT_UAMI_CLIENT_ID}"
echo "AUDIT_UAMI_PRINCIPAL_ID=${AUDIT_UAMI_PRINCIPAL_ID}"
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<AUDIT_UAMI_NAME>` is your chosen UAMI name (e.g., cortex-audit-uami).
* `<LOCATION>` is the Azure region where you want to create your User-Assigned Managed Identity (UAMI) (e.g. eastus)

Note:

* The clientId is the application ID used by Cortex to authenticate via workload identity federation
* The principalId is the unique object ID used to bind Azure RBAC role assignments

This command will output a value for AUDIT\_UAMI\_CLIENT\_ID and AUDIT\_UAMI\_PRINCIPAL\_ID. You will need to provide these values in the coming phases.

### 4.2 Configure workload identity federation for the UAMI

Configure workload identity federation to allow the Cortex Collector's Google Service Account to authenticate as the UAMI:

```shell
az identity federated-credential create \
    --resource-group "<RG_NAME>" \
    --identity-name "<AUDIT_UAMI_NAME>" \
    --name "cortex-audit-federated-cred" \
    --issuer "https://accounts.google.com" \
    --subject "<COLLECTOR_SA_UNIQUE_ID>" \
    --audiences "<AUDIENCE>"
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<AUDIT_UAMI_NAME>` is your chosen UAMI name (e.g., cortex-audit-uami).
* `<COLLECTOR_SA_UNIQUE_ID>` is the unique ID of the Cortex Collector's Google service account, obtained from the identifiers file
* `<AUDIENCE>` is the value obtained from the identifiers file (always api://AzureADTokenExchange for commercial Azure)

### 4.3 Create the storage account

The Cortex Collector uses a dedicated storage account to manage Event Hub checkpoints and maintain data continuity during restarts.

```shell
az storage account create \
    --resource-group "<RG_NAME>" \
    --name "<STORAGE_ACCOUNT_NAME>" \
    --location "<LOCATION>" \
    --sku Standard_LRS \
    --kind StorageV2 \
    --https-only true \
    --min-tls-version TLS1_2 \
    --allow-blob-public-access false \
    --allow-cross-tenant-replication false \
    --default-action Deny \
    --bypass AzureServices \
    --assign-identity \
    --tags managed_by=paloaltonetworks

# Allow-list the Cortex Collector egress IPs (one call per IP)
for ip in $(echo "<COLLECTOR_ALLOWED_IPS>" | tr ',' ' '); do
  az storage account network-rule add \
    --resource-group "<RG_NAME>" \
    --account-name "<STORAGE_ACCOUNT_NAME>" \
    --ip-address "$ip"
done

# Apply blob-service properties (versioning, retention, change-feed)
az storage account blob-service-properties update \
    --resource-group "<RG_NAME>" \
    --account-name "<STORAGE_ACCOUNT_NAME>" \
    --enable-delete-retention true \
    --delete-retention-days 7 \
    --enable-change-feed true \
    --enable-versioning true
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<STORAGE_ACCOUNT_NAME>` is your chosen name for the storage account
* `<LOCATION>` is the Azure region where you want to create your storage account (e.g. eastus)
* `<COLLECTOR_ALLOWED_IPS>` is comma-separated list of Cortex Collector egress IPs, obtained from the identifiers file

### 4.4 Grant the UAMI Storage Blob Data Contributor role on the storage account

```shell
STORAGE_ACCOUNT_ID=$(az storage account show \
    --resource-group "<RG_NAME>" \
    --name "<STORAGE_ACCOUNT_NAME>" --query id -o tsv)

az role assignment create \
    --role "Storage Blob Data Contributor" \
    --assignee-object-id "${AUDIT_UAMI_PRINCIPAL_ID}" \
    --assignee-principal-type ServicePrincipal \
    --scope "${STORAGE_ACCOUNT_ID}"
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<STORAGE_ACCOUNT_NAME>` is your chosen name for the storage account

### 4.5 Create and secure the Event Hubs namespace

```shell
az eventhubs namespace create \
    --resource-group "<RG_NAME>" \
    --name "<EH_NAMESPACE>" \
    --location "<LOCATION>" \
    --sku Standard \
    --capacity 1 \
    --enable-auto-inflate true \
    --maximum-throughput-units 20 \
    --tags managed_by=paloaltonetworks

# Allow-list the Cortex Collector egress IPs
for ip in $(echo "<COLLECTOR_ALLOWED_IPS>" | tr ',' ' '); do
  az eventhubs namespace network-rule-set ip-rule add \
    --resource-group "<RG_NAME>" \
    --namespace-name "<EH_NAMESPACE>" \
    --ip-rule ip-address="$ip" action=Allow
done

# Lock the namespace down to Cortex Collector IPs + trusted Azure services
az eventhubs namespace network-rule-set update \
    --resource-group "<RG_NAME>" \
    --namespace-name "<EH_NAMESPACE>" \
    --default-action Deny \
    --enable-trusted-service-access true
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<EH_NAMESPACE>` is your chosen namespace name
* `<LOCATION>` is the Azure region where you want to create your namespace (e.g. eastus)
* `<COLLECTOR_ALLOWED_IPS>` is comma-separated list of Cortex Collector egress IPs, obtained from the identifiers file

### 4.6 Create the Event Hub

```shell
az eventhubs eventhub create \
    --resource-group "<RG_NAME>" \
    --namespace-name "<EH_NAMESPACE>" \
    --name "<EH_NAME>" \
    --partition-count 20 \
    --cleanup-policy Delete \
    --retention-time-in-hours 168
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<EH_NAMESPACE>` is your chosen namespace name
* `<EH_NAME>` is your chosen Event Hub name (e.g., cortex-activity-logs).

### 4.7 Create an authorization rule on the namespace

```shell
az eventhubs namespace authorization-rule create \
    --resource-group "<RG_NAME>" \
    --namespace-name "<EH_NAMESPACE>" \
    --name "<EH_NAMESPACE_AUTH_RULE>" \
    --rights Listen Send
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<EH_NAMESPACE>` is your chosen namespace name
* `<EH_NAMESPACE_AUTH_RULE>` is your chosen rule name (e.g., CortexEventHubNamespaceAuthRule)

### 4.8 Create the consumer group

```shell
az eventhubs eventhub consumer-group create \
    --resource-group "<RG_NAME>" \
    --namespace-name "<EH_NAMESPACE>" \
    --eventhub-name "<EH_NAME>" \
    --name "<EH_CONSUMER_GROUP>"
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<EH_NAMESPACE>` is your chosen namespace name
* `<EH_NAME>` is your chosen Event Hub name (e.g., cortex-activity-logs)
* `<EH_CONSUMER_GROUP>` is your chosen consumer group name (e.g., cortex-cg)

### 4.9 Grant the UAMI Azure Event Hubs Data Receiver role on the namespace

```shell
EH_NAMESPACE_ID=$(az eventhubs namespace show \
    --resource-group "<RG_NAME>" \
    --name "<EH_NAMESPACE>" --query id -o tsv)

az role assignment create \
    --role "Azure Event Hubs Data Receiver" \
    --assignee-object-id "${AUDIT_UAMI_PRINCIPAL_ID}" \
    --assignee-principal-type ServicePrincipal \
    --scope "${EH_NAMESPACE_ID}"
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<EH_NAMESPACE>` is your chosen namespace name

### 4.10 Route the subscription Activity Log to the Event Hub

Create a subscription-level diagnostic setting that forwards administrative Activity Log entries to the Event Hub.

```shell
EH_AUTH_RULE_ID=$(az eventhubs namespace authorization-rule show \
    --resource-group "<RG_NAME>" \
    --namespace-name "<EH_NAMESPACE>" \
    --name "<EH_NAMESPACE_AUTH_RULE>" --query id -o tsv)

cat > /tmp/cortex-diag-logs.json << 'EOF'
[{"category": "Administrative", "enabled": true}]
EOF

az monitor diagnostic-settings subscription create \
    --name "cortex-activity-logs-export" \
    --location "<LOCATION>" \
    --event-hub-name "<EH_NAME>" \
    --event-hub-auth-rule "${EH_AUTH_RULE_ID}" \
    --logs "@/tmp/cortex-diag-logs.json"
```

Where:

* `<RG_NAME>` is your chosen resource group name (e.g. cortex-platform-rg)
* `<EH_NAMESPACE>` is your chosen namespace name
* `<EH_NAMESPACE_AUTH_RULE>` is your chosen rule name (e.g., CortexEventHubNamespaceAuthzRule)
* `<LOCATION>` is the Azure region where you want to create your subscription diagnostic setting (e.g. eastus)
* `<EH_NAME>` is your chosen Event Hub name (e.g., cortex-activity-logs).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/microsoft-azure-manual-onboarding/azure-manual-onboarding-guide/azure-manual-onboarding-subscription-scope/phase-4-audit-logs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
