Skip to content
Latest (currently 2026.10.2) has the newest features, bug fixes, and CVE patches of Solo Enterprise for agentgateway.

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Microsoft Purview DLP

Enterprise
Page as Markdown

Enforce Microsoft Purview DLP policies.

Enforce your organization’s Microsoft Purview data loss prevention (DLP) policies on LLM prompts and completions that flow through Solo Enterprise for agentgateway.

About Purview DLP

Microsoft Purview DLP lets you define policies that detect sensitive information, such as Social Security numbers, credit card numbers, or other classified content. The Purview DLP prompt guard extends those existing policies to AI traffic, so you can reuse the same compliance rules instead of duplicating them for your LLM gateway.

When you configure the prompt guard, agentgateway sends the content of each LLM request and response to Microsoft Purview through the Microsoft Graph processContent API for evaluation against your DLP policy. When the content matches a policy rule, agentgateway rejects the interaction and returns a 403 response to the client. Agentgateway evaluates requests as uploads (uploadText) and responses as downloads (downloadText), so Purview selects the correct DLP policy set for each direction.

Keep the following behavior in mind:

  • Reject only: When content matches a DLP rule, the prompt guard rejects the interaction. It does not mask or redact matched content.
  • Request scope: Set scope on a request guard, next to purviewDlp rather than inside it, to choose which request content Purview evaluates. In Kubernetes, the values are SystemPrompt, Messages, ToolInput, and ToolOutput. In standalone configuration, the values are systemPrompt, messages, toolInput, and toolOutput. The list must have at least one value.
    • Default scope: If you omit scope, Purview evaluates system prompts, messages, and tool output. Tool input is not in the default. To exclude tool output, set scope and omit ToolOutput, or toolOutput in standalone configuration.
    • No content in scope: If a request has no content in the selected scope, the guard does not call Purview and the request continues.
  • Buffered responses by default: The response guard does not evaluate a streamed response until you turn on streaming guardrails. Until you do, a client that sends "stream": true receives the LLM response without DLP evaluation on the response path. Request evaluation is not affected.
  • Fail closed: If agentgateway cannot reach Purview or cannot acquire a Microsoft Graph token, the request fails with a 503 response rather than passing unevaluated content to the LLM.
  • User attribution: Purview’s Activity Explorer reports DLP events per user, and you choose how agentgateway attributes activity.
    • Gateway-level: Purview evaluates all content in the context of a single Microsoft Entra user that you name in the userId field, by calling the Graph /users/{userId} endpoint with app credentials. All gateway traffic appears as one identity in Activity Explorer.
    • Per-user: Agentgateway exchanges the signed-in user’s Entra token for a delegated Microsoft Graph token by using the Entra On-Behalf-Of (OBO) flow, and calls the Graph /me endpoint. DLP activity is attributed to the actual end user in Activity Explorer.

This guide sets up the gateway-level path in Steps 1 - 4. To attribute activity per user instead, complete Steps 1 - 4 and then continue with Per-user attribution with Entra OBO.

Before you begin

  1. Set up an agentgateway proxy.

  2. Set up access to the OpenAI LLM provider. The examples in this guide route to an OpenAI backend named openai.

  3. Make sure that you have the following Microsoft prerequisites to set up and evaluate Purview DLP policies:

    • A Microsoft 365 tenant with Microsoft Purview licensing for the user that you evaluate content against.
    • Tenant admin access to grant Microsoft Graph application permissions.
    • The Azure CLI (az) installed.
    • PowerShell with the ExchangeOnlineManagement module installed.

Step 1: Register a Microsoft Entra app

Agentgateway authenticates to Microsoft Graph by using the credentials of a Microsoft Entra app registration.

  1. Create a Microsoft Entra client and capture its tenant ID, client ID, and client secret, such as with the az CLI.

    $TENANT_ID = az account show --query tenantId -o tsv
    
    $CLIENT_ID = az ad app create `
      --display-name agentgateway-purview `
      --query appId -o tsv
    
    az ad sp create --id $CLIENT_ID
    
    $CLIENT_SECRET = az ad app credential reset `
      --id $CLIENT_ID `
      --append `
      --display-name "agentgateway-purview-secret" `
      --query password -o tsv
    
    Write-Host "tenantId=$TENANT_ID"
    Write-Host "clientId=$CLIENT_ID"
    Write-Host "clientSecret=$CLIENT_SECRET"
    TENANT_ID=$(az account show --query tenantId -o tsv)
    
    CLIENT_ID=$(az ad app create \
      --display-name agentgateway-purview \
      --query appId -o tsv)
    
    az ad sp create --id "$CLIENT_ID"
    
    CLIENT_SECRET=$(az ad app credential reset \
      --id "$CLIENT_ID" \
      --append \
      --display-name "agentgateway-purview-secret" \
      --query password -o tsv)
    
    echo "tenantId=$TENANT_ID"
    echo "clientId=$CLIENT_ID"
    echo "clientSecret=$CLIENT_SECRET"
  2. Grant the client app the following Microsoft Graph application permissions so that agentgateway can call Purview on its behalf.

    • Content.Process.All
    • ProtectionScopes.Compute.All
    $GRAPH_APP_ID = "00000003-0000-0000-c000-000000000000"
    
    $CONTENT_PERM_ID = az ad sp show --id $GRAPH_APP_ID `
      --query "appRoles[?value=='Content.Process.All'].id | [0]" -o tsv
    
    $SCOPES_PERM_ID = az ad sp show --id $GRAPH_APP_ID `
      --query "appRoles[?value=='ProtectionScopes.Compute.All'].id | [0]" -o tsv
    
    az ad app permission add `
      --id $CLIENT_ID `
      --api $GRAPH_APP_ID `
      --api-permissions "$CONTENT_PERM_ID=Role" "$SCOPES_PERM_ID=Role"
    
    az ad app permission admin-consent --id $CLIENT_ID
    GRAPH_APP_ID="00000003-0000-0000-c000-000000000000"
    
    CONTENT_PERM_ID=$(az ad sp show --id "$GRAPH_APP_ID" \
      --query "appRoles[?value=='Content.Process.All'].id | [0]" -o tsv)
    
    SCOPES_PERM_ID=$(az ad sp show --id "$GRAPH_APP_ID" \
      --query "appRoles[?value=='ProtectionScopes.Compute.All'].id | [0]" -o tsv)
    
    az ad app permission add \
      --id "$CLIENT_ID" \
      --api "$GRAPH_APP_ID" \
      --api-permissions "$CONTENT_PERM_ID=Role" "$SCOPES_PERM_ID=Role"
    
    az ad app permission admin-consent --id "$CLIENT_ID"

Step 2: Create a Purview DLP policy

Create a DLP policy that targets the Entra app and uses the Entra enforcement plane. A generic Exchange, SharePoint, or OneDrive DLP policy does not apply to the AI app flow.

Note

Note that this step must be completed in PowerShell, due to a Purview prerequisite.

  1. Find the object ID of the user for Purview to evaluate DLP policies in the context of. This value is the userId in your prompt guard configuration. The user must be covered by your Purview DLP policy and have the required Purview licensing.

    • The currently signed-in user:

      az ad signed-in-user show --query id -o tsv
    • A specific user, such as user@example.com

      az ad user show --id user@example.com --query id -o tsv
    $ENTRA_USER_OBJECT_ID = "<user_id>"
    export ENTRA_USER_OBJECT_ID="<user_id>"
  2. Create an Entra-scoped Purview DLP policy. The following PowerShell example creates a policy named agw-dlp-policy with a rule that blocks U.S. Social Security numbers. Replace $CLIENT_ID with the client ID from the previous section. On macOS or Linux, the interactive browser sign-in is not supported, so use device code authentication instead.

    Connect-IPPSSession does not support device code authentication directly. As a workaround, connect to Exchange Online with device code first, then Connect-IPPSSession reuses the cached token.

    1. Connect to your admin account. The following command prints a URL and one-time code.

      Install-Module ExchangeOnlineManagement -Force
      
      Connect-ExchangeOnline -UserPrincipalName your-admin@yourtenant.onmicrosoft.com -Device

      Example output:

      To sign in, use a web browser to open the page https://login.microsoft.com/device and enter the code FZAT8MUEM to authenticate.
      
    2. Open the URL in any browser, paste the code, and sign in with your admin account.

    3. Create the Purview DLP policy.

      Connect-IPPSSession -UserPrincipalName your-admin@yourtenant.onmicrosoft.com
      
      $policyName = "agw-dlp-policy"
      $appId = "$CLIENT_ID"
      $appName = "agentgateway-purview"
      
      $locations = @"
      [{"Workload":"Applications","Location":"$appId","LocationDisplayName":"$appName","LocationSource":"Entra","LocationType":"Individual","Inclusions":[{"Type":"Tenant","Identity":"All"}]}]
      "@
      
      New-DlpCompliancePolicy `
        -Name $policyName `
        -Mode Enable `
        -Locations $locations `
        -EnforcementPlanes @("Entra")
      
      New-DlpComplianceRule `
        -Name "block-ssn" `
        -Policy $policyName `
        -ContentContainsSensitiveInformation @{Name="U.S. Social Security Number (SSN)"; minCount="1"} `
        -RestrictAccess @(@{setting="UploadText";value="Block"})
    Install-Module ExchangeOnlineManagement -Force
    
    Connect-IPPSSession -UserPrincipalName your-admin@yourtenant.onmicrosoft.com
    
    $policyName = "agw-dlp-policy"
    $appId = "$CLIENT_ID"
    $appName = "agentgateway-purview"
    
    $locations = @"
    [{"Workload":"Applications","Location":"$appId","LocationDisplayName":"$appName","LocationSource":"Entra","LocationType":"Individual","Inclusions":[{"Type":"Tenant","Identity":"All"}]}]
    "@
    
    New-DlpCompliancePolicy `
      -Name $policyName `
      -Mode Enable `
      -Locations $locations `
      -EnforcementPlanes @("Entra")
    
    New-DlpComplianceRule `
      -Name "block-ssn" `
      -Policy $policyName `
      -ContentContainsSensitiveInformation @{Name="U.S. Social Security Number (SSN)"; minCount="1"} `
      -RestrictAccess @(@{setting="UploadText";value="Block"})
  3. Verify that the policy is enabled and scoped to the Entra enforcement plane.

    Get-DlpCompliancePolicy -Identity $policyName | Format-List Name,Enabled,Mode,EnforcementPlanes,Locations,Workload

    The policy EnforcementPlanes must include Entra and the Locations must contain your app ID.

Step 3: Configure the Purview DLP prompt guard

  1. Create a Kubernetes secret that holds the client secret of your Entra app. Agentgateway reads the secret from the clientSecret key.

    kubectl create secret generic purview-client-secret \
      -n agentgateway-system \
      --from-literal=clientSecret="$CLIENT_SECRET" \
      --type=Opaque \
      --dry-run=client -o yaml | kubectl apply -f -
  2. Create an EnterpriseAgentgatewayPolicy that applies the Purview DLP prompt guard to your LLM backend. The policy evaluates both requests and responses against your DLP policy. Replace the placeholder values with the IDs from the previous steps.

    kubectl apply -f - <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: openai-purview-dlp
      namespace: agentgateway-system
    spec:
      targetRefs:
      - group: enterpriseagentgateway.solo.io
        kind: EnterpriseAgentgatewayBackend
        name: openai
      backend:
        ai:
          entPromptGuard:
            request:
            - purviewDlp:
                tenantId: "$TENANT_ID"
                clientId: "$CLIENT_ID"
                purviewAppName: agentgateway-purview
                guardrailName: agw-dlp-policy
                userId: "$ENTRA_USER_OBJECT_ID"
                policies:
                  auth:
                    azure:
                      secretRef:
                        name: purview-client-secret
              scope:
              - SystemPrompt
              - Messages
              - ToolOutput
            response:
            - purviewDlp:
                tenantId: "$TENANT_ID"
                clientId: "$CLIENT_ID"
                purviewAppName: agentgateway-purview
                guardrailName: agw-dlp-policy
                userId: "$ENTRA_USER_OBJECT_ID"
                policies:
                  auth:
                    azure:
                      secretRef:
                        name: purview-client-secret
    EOF
    Review the following table to understand this configuration.
    SettingDescription
    tenantIdThe Microsoft Entra (Azure AD) tenant ID.
    clientIdThe client ID of the Entra app registration from Step 1.
    purviewAppNameThe application name registered in Microsoft Purview.
    guardrailNameThe name of the Purview DLP policy to evaluate content against, such as agw-dlp-policy.
    userIdThe Entra object ID of the user whose context Purview evaluates content against. See Step 2. Required for the gateway-level path. When you enable per-user attribution with policies.tokenExchange.entra, this field is optional and ignored, because the delegated token identifies the signed-in user.
    apiVersionOptional. The Microsoft Graph API version. Defaults to v1.0. Set to beta to use preview features.
    activityOptional. Overrides the Microsoft Graph activity used for evaluation. One of uploadText, downloadText, or both. Defaults to uploadText for request guards and downloadText for response guards.
    policies.auth.azure.secretRefA reference to the secret that holds the Entra app client secret.
    scopeOptional. A field of the request guard, at the same level as purviewDlp rather than inside it. The request content that Purview evaluates, as one or more of SystemPrompt, Messages, ToolInput, or ToolOutput. This example lists the default values. For more information, see About Purview DLP.

    To evaluate streamed responses as well as buffered ones, set entPromptGuard.streaming to Enabled.

Step 4: Verify the prompt guard

  1. Send a request that contains content that violates your DLP policy. The following example assumes a policy that blocks Social Security numbers.

    curl -i "$INGRESS_GW_ADDRESS/openai" \
      -H "content-type: application/json" \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"my SSN is 223-25-2789"}]}'
    kubectl port-forward -n agentgateway-system svc/agentgateway-proxy 8080:80
    curl -i "localhost:8080/openai" \
      -H "content-type: application/json" \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"my SSN is 223-25-2789"}]}'

    Agentgateway rejects the request with a 403 response.

    HTTP/1.1 403 Forbidden
    
    The request was rejected due to inappropriate content
    
  2. Send a benign request and verify that it is allowed through to the LLM provider.

    curl -i "localhost:8080/openai" \
      -H "content-type: application/json" \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"what is the meaning of life?"}]}'

Log DLP interventions

A guardrail that masks or rejects content records what it did in the request’s dynamic metadata, under the guardrails Common Expression Language (CEL) variable. Add that variable to an access log field to keep an audit trail of every intervention, including which guard acted and why.

The variable holds one entry per intervention, in either the request or the response phase, so a request that both guards act on produces two entries. Only CEL that runs after the request completes, such as an access log field or a metric field, receives the guardrails variable. An authorization or transformation expression that runs mid-request never sees it.

FieldDescription
guardrails[].phaseThe phase that the guardrail intervened in, either request or response.
guardrails[].guardThe guard kind that intervened, such as purviewDlp, bedrockGuardrails, googleModelArmor, azureContentSafety, openAIModeration, regex, or webhook.
guardrails[].actionThe action that the guardrail took, one of mask, reject, audit, or failOpen.
guardrails[].guardrailIdThe configured guardrail identifier.
guardrails[].guardrailVersionThe configured guardrail version.
guardrails[].actionReasonThe reason that the guardrail reported for its action.
guardrails[].assessmentsAssessment detail that the guardrail provider reported, redacted to metadata only. Content-bearing fields, such as the matched text, are never included.

Note

The assessments field carries provider metadata rather than the content that matched, so an access log never records the sensitive data that the guardrail found. To review the matched content, use the provider’s own console, such as the Microsoft Purview Activity Explorer.

  1. Create an EnterpriseAgentgatewayPolicy that adds the guardrails variable to the access logs for your gateway. The filter expression keeps the log volume down by writing an entry only for the requests that a guardrail acted on.

    kubectl apply -f - <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: guardrail-access-logs
      namespace: agentgateway-system
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: Gateway
        name: agentgateway-proxy
      frontend:
        accessLog:
          filter: guardrails.size() > 0
          attributes:
            add:
            - name: guardrails
              expression: guardrails
    EOF
    Review the following table to understand this configuration.
    SettingDescription
    targetRefsSelect the Gateway to log for. Access logging is a frontend policy, so it attaches to a Gateway rather than to the backend that the prompt guard attaches to.
    filterRestrict the log to requests that a guardrail intervened in. Remove this line to log every request, with guardrails absent from the entries that no guardrail acted on.
    attributes.addAdd the guardrails variable as a log field. To record one value instead of the whole list, use an expression such as guardrails[0].action.
  2. Send a request that violates your DLP policy, as in Step 4, and then read the proxy logs.

    kubectl logs -n agentgateway-system deploy/agentgateway-proxy | grep guardrails

    The entry names the phase, the guard, and the action, so a purviewDlp rejection is distinguishable from a mask by another guard on the same route.

Per-user attribution with Entra OBO

By default, the prompt guard evaluates all content as the single user in the userId field, so every gateway request appears as one identity in Purview’s Activity Explorer. To attribute DLP activity to the actual signed-in user, enable per-user attribution. Agentgateway resolves the end user’s Microsoft Entra token at request time, exchanges it for a delegated Microsoft Graph token through the built-in security token service (STS) by using the Entra On-Behalf-Of (OBO) flow, and evaluates the content against the Graph /me endpoint as that user.

    sequenceDiagram
    participant Client
    participant Gateway
    participant STS as Gateway STS
    participant Entra as Microsoft Entra ID
    participant Purview as Microsoft Purview<br/>(Graph /me)
    participant LLM as LLM provider

    Client->>Gateway: LLM request + user's Entra token
    Gateway->>STS: Exchange user token
    STS->>Entra: OBO exchange<br/>grant_type=jwt-bearer<br/>+ app client secret
    Entra-->>STS: Delegated Graph token<br/>(represents the user)
    STS-->>Gateway: Delegated Graph token
    Gateway->>Purview: processContent as /me
    Purview-->>Gateway: DLP verdict, attributed to the user
    Gateway->>LLM: Forward request (if allowed)
  

Keep the following behavior in mind:

  • Identity resolution: Agentgateway resolves the end user’s Entra token from a JWT that a JWT authentication policy validated on the route, or from an x-entra-jwt request header. Agentgateway strips the x-entra-jwt header before it forwards the request to the LLM provider, so the user’s token never reaches the backend.
  • Fail closed: If no user token is present, or the STS cannot complete the OBO exchange, agentgateway rejects the request with a 503 response. It never falls back to the gateway-level app credentials.
  • userId is ignored: When you set policies.tokenExchange.entra, the delegated token identifies the user, so the userId field is optional and ignored.
  • Client secret is still required: The OBO flow needs two proofs: the user’s token (the per-user part) and the gateway app’s client secret (the app authenticating itself to Entra). The client secret is the gateway app’s credential, not the user’s, and the data plane never sees it.

Step 1: Grant delegated Graph permissions

Extend the Entra app registration from Step 1 so that users can sign in to it and so that the delegated Graph token can call Purview.

Note

Adding delegated permissions and granting admin consent require Microsoft Entra tenant administrator privileges.

  1. Expose an API scope on the app so that users can get tokens with the app as the audience (aud: api://$CLIENT_ID). You can run the following commands, or in the Azure portal, go to your app registration and click Expose an API.

    az ad app update --id "$CLIENT_ID" --identifier-uris "api://$CLIENT_ID"
    
    az ad app show --id "$CLIENT_ID" --query id -o tsv | xargs -I{} az rest \
      --method PATCH \
      --url "https://graph.microsoft.com/v1.0/applications/{}" \
      --body '{"api":{"oauth2PermissionScopes":[{"id":"'"$(uuidgen | tr '[:upper:]' '[:lower:]')"'","adminConsentDescription":"Access agentgateway as the signed-in user","adminConsentDisplayName":"Access agentgateway","isEnabled":true,"type":"User","value":"access_as_user"}]}}'
  2. Grant the app the delegated Microsoft Graph permissions Content.Process.All and ProtectionScopes.Compute.All, and grant admin consent. These are in addition to the application permissions from Step 1, which the gateway-level path uses.

    GRAPH_APP_ID="00000003-0000-0000-c000-000000000000"
    
    CONTENT_SCOPE_ID=$(az ad sp show --id "$GRAPH_APP_ID" \
      --query "oauth2PermissionScopes[?value=='Content.Process.All'].id | [0]" -o tsv)
    
    SCOPES_SCOPE_ID=$(az ad sp show --id "$GRAPH_APP_ID" \
      --query "oauth2PermissionScopes[?value=='ProtectionScopes.Compute.All'].id | [0]" -o tsv)
    
    az ad app permission add \
      --id "$CLIENT_ID" \
      --api "$GRAPH_APP_ID" \
      --api-permissions "$CONTENT_SCOPE_ID=Scope" "$SCOPES_SCOPE_ID=Scope"
    
    az ad app permission admin-consent --id "$CLIENT_ID"
  3. Make sure that the users whose traffic you attribute are covered by your Purview DLP policy from Step 2 and have the required Purview licensing.

Step 2: Enable the STS

Enable the token exchange STS in the Solo Enterprise for agentgateway control plane. The STS validates the user’s incoming Entra token and performs the OBO exchange with Entra.

  1. Get your existing Helm values.

    helm get values enterprise-agentgateway -n agentgateway-system -o yaml > values.yaml
  2. Add the following gateway parameters and token exchange configuration to the Helm values file.

    gatewayClassParametersRefs:
      enterprise-agentgateway:
        group: enterpriseagentgateway.solo.io
        kind: EnterpriseAgentgatewayParameters
        name: agentgateway-params
        namespace: agentgateway-system
    tokenExchange:
      enabled: true
      issuer: "enterprise-agentgateway.agentgateway-system.svc.cluster.local:7777"
      tokenExpiration: 24h
      subjectValidator:
        validatorType: remote
        remoteConfig:
          url: "https://login.microsoftonline.com/$TENANT_ID/discovery/v2.0/keys"
      apiValidator:
        validatorType: remote
        remoteConfig:
          url: "https://login.microsoftonline.com/$TENANT_ID/discovery/v2.0/keys"
      actorValidator:
        validatorType: k8s
      elicitation:
        secretName: ""
    Review the following table to understand this configuration.
    SettingDescription
    gatewayClassParametersRefsBinds the enterprise-agentgateway GatewayClass to the EnterpriseAgentgatewayParameters resource that you create in the next step. Any Gateway that uses this GatewayClass automatically picks up the STS connection details.
    tokenExchange.enabledEnable the security token service (STS).
    subjectValidatorValidates the user’s incoming Entra JWT. Set to remote with the Entra JWKS discovery URL for your tenant. The v2.0 keys URL validates both v1 and v2 Entra tokens.
    apiValidatorRequired for Entra OBO. Set to the same Entra JWKS discovery URL.
    actorValidatorValidates the data plane by its Kubernetes service account token.
    elicitation.secretNameSet to an empty string to disable elicitation, which is not used in the Entra OBO flow.
  3. Upgrade Solo Enterprise for agentgateway with the token exchange configuration.

    helm upgrade -i enterprise-agentgateway oci://us-docker.pkg.dev/solo-public/enterprise-agentgateway/charts/enterprise-agentgateway \
      -n agentgateway-system \
      --version v2026.10.2 \
      -f values.yaml
  4. Verify that the control plane service now exposes port 7777 for the STS.

    kubectl get svc -n agentgateway-system enterprise-agentgateway

    Example output:

    NAME                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                               AGE
    enterprise-agentgateway   ClusterIP   10.96.195.136   <none>        9978/TCP,9093/TCP,7777/TCP,9092/TCP   2m
    
  5. Create the EnterpriseAgentgatewayParameters resource that gives the data plane the STS connection details. The proxy pods restart automatically to pick up the new environment variables.

    kubectl apply -f - <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayParameters
    metadata:
      name: agentgateway-params
      namespace: agentgateway-system
    spec:
      env:
        - name: STS_URI
          value: http://enterprise-agentgateway.agentgateway-system.svc.cluster.local:7777/oauth2/token
        - name: STS_AUTH_TOKEN
          value: ./var/run/secrets/xds-tokens/xds-token
    EOF

Step 3: Create the Entra JWKS backend

Create a backend to Microsoft Entra’s JWKS endpoint. The JWT authentication policy in the next step uses this backend to validate incoming user tokens.

kubectl apply -f - <<EOF
apiVersion: agentgateway.dev/v1alpha1
kind: AgentgatewayBackend
metadata:
  name: entra-jwks
  namespace: agentgateway-system
spec:
  static:
    host: login.microsoftonline.com
    port: 443
  policies:
    tls: {}
EOF

Step 4: Update the prompt guard for per-user OBO

Update the Purview DLP policy so that the guard exchanges the user’s token instead of using the gateway-level app credentials.

  1. Update the EnterpriseAgentgatewayPolicy to replace userId and policies.auth with policies.tokenExchange.entra.

    kubectl apply -f - <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: openai-purview-dlp
      namespace: agentgateway-system
    spec:
      targetRefs:
      - group: enterpriseagentgateway.solo.io
        kind: EnterpriseAgentgatewayBackend
        name: openai
      backend:
        ai:
          entPromptGuard:
            request:
            - purviewDlp:
                tenantId: "$TENANT_ID"
                clientId: "$CLIENT_ID"
                purviewAppName: agentgateway-purview
                guardrailName: agw-dlp-policy
                policies:
                  tokenExchange:
                    entra:
                      tenantId: "$TENANT_ID"
                      clientId: "$CLIENT_ID"
                      scope: "https://graph.microsoft.com/.default"
                      clientSecretRef:
                        name: purview-client-secret
                        key: clientSecret
              scope:
              - SystemPrompt
              - Messages
              - ToolOutput
            response:
            - purviewDlp:
                tenantId: "$TENANT_ID"
                clientId: "$CLIENT_ID"
                purviewAppName: agentgateway-purview
                guardrailName: agw-dlp-policy
                policies:
                  tokenExchange:
                    entra:
                      tenantId: "$TENANT_ID"
                      clientId: "$CLIENT_ID"
                      scope: "https://graph.microsoft.com/.default"
                      clientSecretRef:
                        name: purview-client-secret
                        key: clientSecret
    EOF
    Review the following table to understand this configuration.
    SettingDescription
    userIdOmitted. The delegated token identifies the signed-in user, so the guard calls the Graph /me endpoint and ignores userId.
    policies.tokenExchange.entra.tenantIdThe Entra tenant ID that the STS uses for the OBO exchange.
    policies.tokenExchange.entra.clientIdThe client ID of the Entra app registration. This must match the audience (aud) of the incoming user token, such as api://$CLIENT_ID.
    policies.tokenExchange.entra.scopeThe Microsoft Graph scope for the delegated token. The .default scope requests all of the delegated permissions that you consented to in Step 1.
    policies.tokenExchange.entra.clientSecretRefA reference to the secret that holds the Entra app client secret, including the key within the secret. This example reuses the purview-client-secret secret from Step 3, which stores the value in the clientSecret key.
    scopeOptional. A field of the request guard, at the same level as purviewDlp rather than inside it. The request content that Purview evaluates. This example keeps the same scope as the gateway-level policy in Step 3.
  2. Verify that the policy is accepted and attached.

    kubectl get enterpriseagentgatewaypolicy openai-purview-dlp -n agentgateway-system

    Example output:

    NAME                 ACCEPTED   ATTACHED   AGE
    openai-purview-dlp   True       True       9s
    

Step 5: Pass the user’s identity

Choose how agentgateway resolves the end user’s Entra token on each request.

Apply a JWT authentication policy to the route. Agentgateway validates the Authorization: Bearer token against Entra’s JWKS, and the validated claims become the OBO user assertion. Invalid or missing tokens are rejected with a 401 response before the guard runs.

kubectl apply -f - <<EOF
apiVersion: enterpriseagentgateway.solo.io/v1alpha1
kind: EnterpriseAgentgatewayPolicy
metadata:
  name: entra-jwt-auth
  namespace: agentgateway-system
spec:
  targetRefs:
    - group: gateway.networking.k8s.io
      kind: HTTPRoute
      name: openai
  traffic:
    jwtAuthentication:
      mode: Strict
      providers:
        - issuer: "https://sts.windows.net/$TENANT_ID/"
          audiences:
            - "api://$CLIENT_ID"
          jwks:
            remote:
              jwksPath: "/$TENANT_ID/discovery/v2.0/keys"
              cacheDuration: "5m"
              backendRef:
                name: entra-jwks
                kind: AgentgatewayBackend
                group: agentgateway.dev
                port: 443
EOF

Review the following table to understand this configuration.

SettingDescription
issuerThe issuer of the user’s Entra token. For v1 tokens ("ver": "1.0", the common case), the issuer is https://sts.windows.net/$TENANT_ID/ with a trailing slash. For v2 tokens, use https://login.microsoftonline.com/$TENANT_ID/v2.0.
audiencesThe audience of the user’s token, which is the app registration such as api://$CLIENT_ID.
jwks.remoteFetches Entra’s signing keys through the entra-jwks backend from Step 3.

Send the user’s Entra token in an x-entra-jwt request header. Use this option when the route’s own Authorization header carries a different credential, such as an API key for the gateway. No extra policy is needed.

Agentgateway reads the x-entra-jwt header for the OBO exchange and strips it before forwarding the request to the LLM provider. The STS still validates the token during the exchange, so agentgateway rejects requests with invalid tokens.

Step 6: Verify per-user attribution

  1. Get an Entra access token for a signed-in user. The token’s audience must be the app registration, such as api://$CLIENT_ID. For example, you can use the Azure CLI.

    az login --tenant "$TENANT_ID" --scope "api://$CLIENT_ID/.default"
    
    export USER_TOKEN=$(az account get-access-token \
      --tenant "$TENANT_ID" \
      --resource "api://$CLIENT_ID" \
      --query accessToken -o tsv)
  2. Send a request that violates your DLP policy, passing the user’s token. Choose the header that matches your identity option from Step 5.

    curl -i "localhost:8080/openai" \
      -H "content-type: application/json" \
      -H "Authorization: Bearer $USER_TOKEN" \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"my SSN is 223-25-2789"}]}'
    curl -i "localhost:8080/openai" \
      -H "content-type: application/json" \
      -H "x-entra-jwt: $USER_TOKEN" \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"my SSN is 223-25-2789"}]}'

    Agentgateway rejects the request with a 403 response.

  3. Send a benign request with the user’s token and verify that it is allowed through to the LLM provider.

  4. Send a request without a user token and verify that the request is rejected. The response code depends on the identity option that you chose in Step 5.

    curl -i "localhost:8080/openai" \
      -H "content-type: application/json" \
      -d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"what is the meaning of life?"}]}'
    • x-entra-jwt header option: The request reaches the guard, which fails closed with a 503 response because no user assertion is present. In the proxy logs, you can confirm the reason for the rejection.

      failed to call prompt guard webhook: Purview DLP per-user OBO is configured but no end-user assertion was found (expected `x-entra-jwt` header or a validated inbound JWT); failing closed
      
    • Validated JWT option: The JWT authentication policy rejects the request with a 401 response before it reaches the guard, so the guard’s fail-closed 503 does not apply. To trigger the guard’s fail-closed behavior instead, send a request with a valid user token but a misconfigured OBO exchange.

  5. In the Purview Activity Explorer, verify that the DLP events from step 2 are attributed to the signed-in user instead of the gateway’s service account user.

Cleanup

You can optionally remove the resources that you set up as part of this guide.
kubectl delete enterpriseagentgatewaypolicy openai-purview-dlp -n agentgateway-system
kubectl delete secret purview-client-secret -n agentgateway-system

If you set up per-user attribution, also remove the following resources.

kubectl delete enterpriseagentgatewaypolicy entra-jwt-auth -n agentgateway-system --ignore-not-found
kubectl delete agentgatewaybackend entra-jwks -n agentgateway-system --ignore-not-found
kubectl delete enterpriseagentgatewayparameters agentgateway-params -n agentgateway-system --ignore-not-found