Skip to content

Azure Risk

Entra ID Protection risk — risky users, risk detections and risky service principals

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/azure-risk/index.md to help me query Azure Risk with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Find users currently at risk

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT id, user_principal_name, risk_level
FROM azure.main.risky_users()
WHERE _row_kind IS NULL AND risk_state = 'atRisk'

Quick start

Choose where to run Azure Risk, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-azure-risk'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

azure_graph credentials

Microsoft Entra app-only (client-credentials) credentials for Microsoft Graph

Get these credentials →
secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT id, user_principal_name, risk_level
FROM azure.main.risky_users()
WHERE _row_kind IS NULL AND risk_state = 'atRisk'
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Microsoft Entra ID Protection risk data from Microsoft Graph as SQL tables: risky users, risky service principals and risk detection events, synced incrementally by watermark. Needs an app-only Microsoft Graph credential and an Entra ID P2 license.

Catalog

Everything azure exposes once attached — read straight from the worker's released build.

azure 1 schema
main 1 view · 3 functions

Microsoft Entra ID Protection risk objects (risky users, risky service principals, risk detections) as lagged-watermark Graph feeds.

Schema examples (6)
Examples (6)

Users currently at risk

SELECT id, user_principal_name, risk_level
FROM azure.main.risky_users()
WHERE _row_kind IS NULL AND risk_state = 'atRisk';

Incremental sync of risk detections from a saved watermark

SELECT id, user_id, risk_event_type
FROM azure.main.risk_detections(since := '<_watermark_next>')
WHERE _row_kind IS NULL;

Reconcile detections against the current per-user verdict (mandatory §2c join)

SELECT d.id, d.risk_event_type, u.risk_state AS current_verdict
FROM azure.main.risk_detections() d
JOIN azure.main.risky_users() u ON d.user_id = u.id
WHERE d._row_kind IS NULL AND u._row_kind IS NULL
ORDER BY d.id;

Detections whose own risk_state is stale: the detection still says one thing (e.g. atRisk) while the user's current verdict in risky_users has moved on (e.g. remediated or confirmedCompromised)

SELECT d.id, d.user_principal_name, d.risk_event_type,
  d.risk_state AS detection_state, u.risk_state AS current_verdict
FROM azure.main.risk_detections() d
JOIN azure.main.risky_users() u ON d.user_id = u.id
WHERE d._row_kind IS NULL AND u._row_kind IS NULL AND d.risk_state IS DISTINCT FROM u.risk_state
ORDER BY d.detected_date_time DESC, d.id;
2 more examples

Triage list: every user currently atRisk or confirmedCompromised with their number of risk detections, the latest detection time, and the distinct detection types (users with no detections show 0)

SELECT u.user_principal_name, u.risk_level, u.risk_state,
  count(d.id) AS detections, max(d.detected_date_time) AS last_detected,
  list(DISTINCT d.risk_event_type ORDER BY d.risk_event_type) FILTER (WHERE d.id IS NOT NULL) AS event_types
FROM azure.main.risky_users() u
LEFT JOIN azure.main.risk_detections() d ON d.user_id = u.id AND d._row_kind IS NULL
WHERE u._row_kind IS NULL AND u.risk_state IN ('atRisk', 'confirmedCompromised')
GROUP BY u.user_principal_name, u.risk_level, u.risk_state
ORDER BY detections DESC, u.user_principal_name;

High-risk service principals

SELECT id, app_id, display_name
FROM azure.main.risky_service_principals()
WHERE _row_kind IS NULL AND risk_level = 'high';
Views
risk_collections 2 examples5 cols

The Entra ID Protection risk feeds this catalog exposes and the lagged-watermark table function that serves each. Browsable without credentials.

Columns
collection VARCHAR
The risk feed slug (risky_users / risky_service_principals / risk_detections).
kind VARCHAR
Feed kind: 'state' (current mutable verdict per principal) or 'event' (immutable detection).
table_function VARCHAR
The catalog table function that syncs this feed as a lagged-watermark cursor.
watermark_field VARCHAR
The row time field the incremental watermark cursor advances on.
description VARCHAR
A one-line description of the feed.
Examples (2)

List every risk feed and the table function that serves it

SELECT collection, table_function
FROM azure.main.risk_collections
ORDER BY collection;

Find the state feeds and their watermark field

SELECT collection, watermark_field
FROM azure.main.risk_collections
WHERE kind = 'state';
Link
Table functions
risk_detections (page_size := BIGINT, safety_lag := VARCHAR, since := VARCHAR) 4 examples

Entra ID Protection risk detections (immutable detection EVENTS) via Microsoft Graph, lagged-watermark on detectedDateTime. A detection's riskState transitions in place without moving detectedDateTime, so this cursor never re-surfaces a verdict change — consumers MUST join userId <-> risky_users.id and read the CURRENT verdict there (§2c), never act on the detection's own (possibly stale) riskState.

Named arguments
page_size := BIGINT
Maps to the Microsoft Graph `$top` page size; clamped to the range 1..1000 (defaults to 500). Controls request paging only, not the total number of rows returned. · default 500
safety_lag := VARCHAR
ISO-8601 duration (e.g. `PT10M`, `PT1H`, `P1D`) subtracted from the high-water mark before it is committed, so late-scored risk in the lag window is re-read on the next scan rather than lost. Defaults to `PT10M`; anything unparseable falls back to the 10-minute default. · default "PT10M"
since := VARCHAR
A previously persisted watermark (the `_watermark_next` value from a prior scan's marker row), an ISO-8601 instant. The scan returns rows whose time field is `>=` this value. Empty (the default) performs a full sync from epoch. · default ""
Returns columns
id VARCHAR
The risk detection's id (immutable event id). NULL on the marker row.
detected_date_time VARCHAR
ISO-8601 instant the detection was created (the watermark field; never moves once set). NULL on the marker row.
risk_level VARCHAR
Risk level at detection time (low/medium/high/hidden). NULL on the marker row.
risk_state VARCHAR
The detection's own (possibly stale) risk state; reconcile against risky_users for the current verdict. NULL on the marker row.
user_id VARCHAR
The affected user's object id; join key to risky_users.id.
user_principal_name VARCHAR
The affected user's UPN. PII.
risk_event_type VARCHAR
The detection type (e.g. unfamiliarFeatures, anonymizedIPAddress, maliciousIPAddress).
detection_timing_type VARCHAR
Detection timing: realtime or offline.
ip_address VARCHAR
IP address the detection fired from. PII.
_row_kind VARCHAR
NULL for data rows; 'marker' for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the ISO-8601 instant to persist and replay as the next scan's `since`; NULL on data rows. There is no authoritative per-row watermark.
Examples (4)

Full sync of all risk detections (data rows only)

SELECT id, user_id, risk_event_type, detected_date_time
FROM azure.main.risk_detections()
WHERE _row_kind IS NULL;

Reconcile detections against the current per-user verdict (mandatory §2c join)

SELECT d.id, d.risk_event_type, u.risk_state AS current_verdict
FROM azure.main.risk_detections() d
JOIN azure.main.risky_users() u ON d.user_id = u.id
WHERE d._row_kind IS NULL AND u._row_kind IS NULL
ORDER BY d.id;

Detections whose own risk_state is stale: the detection still says one thing (e.g. atRisk) while the user's current verdict in risky_users has moved on (e.g. remediated or confirmedCompromised)

SELECT d.id, d.user_principal_name, d.risk_event_type,
  d.risk_state AS detection_state, u.risk_state AS current_verdict
FROM azure.main.risk_detections() d
JOIN azure.main.risky_users() u ON d.user_id = u.id
WHERE d._row_kind IS NULL AND u._row_kind IS NULL AND d.risk_state IS DISTINCT FROM u.risk_state
ORDER BY d.detected_date_time DESC, d.id;
1 more example

Read the watermark to persist for the next sync

SELECT _watermark_next
FROM azure.main.risk_detections()
WHERE _row_kind = 'marker';
Link
risky_service_principals (page_size := BIGINT, safety_lag := VARCHAR, since := VARCHAR) 3 examples

Entra ID Protection risky service principals (current per-SP risk STATE) via Microsoft Graph, lagged-watermark on riskLastUpdatedDateTime. REQUIRES IdentityRiskyServicePrincipal.Read.All (the user-risk scope 403s here). Source of truth for current SP riskState; dismissal is a field change, not a delete.

Named arguments
page_size := BIGINT
Maps to the Microsoft Graph `$top` page size; clamped to the range 1..1000 (defaults to 500). Controls request paging only, not the total number of rows returned. · default 500
safety_lag := VARCHAR
ISO-8601 duration (e.g. `PT10M`, `PT1H`, `P1D`) subtracted from the high-water mark before it is committed, so late-scored risk in the lag window is re-read on the next scan rather than lost. Defaults to `PT10M`; anything unparseable falls back to the 10-minute default. · default "PT10M"
since := VARCHAR
A previously persisted watermark (the `_watermark_next` value from a prior scan's marker row), an ISO-8601 instant. The scan returns rows whose time field is `>=` this value. Empty (the default) performs a full sync from epoch. · default ""
Returns columns
id VARCHAR
The risky service principal's object id (GUID). NULL on the marker row.
risk_last_updated_date_time VARCHAR
ISO-8601 instant the SP's risk was last updated (the watermark field). NULL on the marker row.
risk_level VARCHAR
Current aggregate risk level (low/medium/high/hidden/none). NULL on the marker row.
risk_state VARCHAR
Current risk state (atRisk/confirmedCompromised/dismissed/remediated). NULL on the marker row.
app_id VARCHAR
The service principal's application (client) id.
display_name VARCHAR
The service principal's display name.
risk_detail VARCHAR
Latest risk detail / remediation reason.
ip_address VARCHAR
IP address associated with the risk, if any. PII.
_row_kind VARCHAR
NULL for data rows; 'marker' for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the ISO-8601 instant to persist and replay as the next scan's `since`; NULL on data rows. There is no authoritative per-row watermark.
Examples (3)

Full sync of all risky service principals (data rows only)

SELECT id, app_id, display_name, risk_level, risk_state
FROM azure.main.risky_service_principals()
WHERE _row_kind IS NULL;

High-risk service principals only

SELECT id, app_id, display_name
FROM azure.main.risky_service_principals()
WHERE _row_kind IS NULL AND risk_level = 'high';

Read the watermark to persist for the next sync

SELECT _watermark_next
FROM azure.main.risky_service_principals()
WHERE _row_kind = 'marker';
Link
risky_users (page_size := BIGINT, safety_lag := VARCHAR, since := VARCHAR) 4 examples

Entra ID Protection risky users (current per-user risk STATE) via Microsoft Graph, lagged-watermark on riskLastUpdatedDateTime. SOURCE OF TRUTH for current riskState: any risk_detections row MUST be reconciled against the matching risky_users row (join userId <-> id) before acting — a detection's riskState can be stale (§2c). Absence from a page NEVER means 'cleared'; dismissal is a riskState field change, not a delete.

Named arguments
page_size := BIGINT
Maps to the Microsoft Graph `$top` page size; clamped to the range 1..1000 (defaults to 500). Controls request paging only, not the total number of rows returned. · default 500
safety_lag := VARCHAR
ISO-8601 duration (e.g. `PT10M`, `PT1H`, `P1D`) subtracted from the high-water mark before it is committed, so late-scored risk in the lag window is re-read on the next scan rather than lost. Defaults to `PT10M`; anything unparseable falls back to the 10-minute default. · default "PT10M"
since := VARCHAR
A previously persisted watermark (the `_watermark_next` value from a prior scan's marker row), an ISO-8601 instant. The scan returns rows whose time field is `>=` this value. Empty (the default) performs a full sync from epoch. · default ""
Returns columns
id VARCHAR
The risky user's object id (GUID); join key to risk_detections.user_id. NULL on the marker row.
risk_last_updated_date_time VARCHAR
ISO-8601 instant the user's risk was last updated (the watermark field). NULL on the marker row.
risk_level VARCHAR
Current aggregate risk level (low/medium/high/hidden/none). NULL on the marker row.
risk_state VARCHAR
Current risk state (atRisk/confirmedCompromised/dismissed/remediated/confirmedSafe). NULL on the marker row.
user_principal_name VARCHAR
The user's UPN (sign-in name). PII.
user_display_name VARCHAR
The user's display name. PII.
risk_detail VARCHAR
Latest risk detail / remediation reason (e.g. adminConfirmedUserCompromised).
ip_address VARCHAR
IP address associated with the risk. PII.
_row_kind VARCHAR
NULL for data rows; 'marker' for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the ISO-8601 instant to persist and replay as the next scan's `since`; NULL on data rows. There is no authoritative per-row watermark.
Examples (4)

Full sync of users currently at risk (data rows only)

SELECT id, user_principal_name, risk_level, risk_state
FROM azure.main.risky_users()
WHERE _row_kind IS NULL AND risk_state = 'atRisk';

Triage list: every user currently atRisk or confirmedCompromised with their number of risk detections, the latest detection time, and the distinct detection types (users with no detections show 0)

SELECT u.user_principal_name, u.risk_level, u.risk_state,
  count(d.id) AS detections, max(d.detected_date_time) AS last_detected,
  list(DISTINCT d.risk_event_type ORDER BY d.risk_event_type) FILTER (WHERE d.id IS NOT NULL) AS event_types
FROM azure.main.risky_users() u
LEFT JOIN azure.main.risk_detections() d ON d.user_id = u.id AND d._row_kind IS NULL
WHERE u._row_kind IS NULL AND u.risk_state IN ('atRisk', 'confirmedCompromised')
GROUP BY u.user_principal_name, u.risk_level, u.risk_state
ORDER BY detections DESC, u.user_principal_name;

Incremental sync replaying a previously saved watermark

SELECT id, user_principal_name, risk_detail
FROM azure.main.risky_users(since := '<_watermark_next>')
WHERE _row_kind IS NULL;
1 more example

Read the watermark to persist for the next sync

SELECT _watermark_next
FROM azure.main.risky_users()
WHERE _row_kind = 'marker';
Link

Credentials

The secret type azure declares, as reported by the worker itself.

azure_graph

How to get these credentials

Microsoft Entra app-only (client-credentials) credentials for Microsoft Graph

secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Key Type Required Description
tenant_id VARCHAR — Directory (tenant) ID from the Entra app registration's Overview page.
client_id VARCHAR — Application (client) ID from the Entra app registration's Overview page.
client_secret secret VARCHAR — Client secret value created under the app registration's Certificates & secrets page.

The worker doesn't mark which keys are required.

Needed by risky_usersrisk_detectionsrisky_service_principals

Create the secret in the same session, after attaching azure — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

risky_users_bind_probe — Bind risky_users and expose its result columns (credential-free; drop LIMIT 0 and attach an azure_graph secret to sync real data)

SELECT id, user_principal_name, risk_level, risk_state
FROM azure.main.risky_users()
LIMIT 0;

Uses risky_users

risk_detections_bind_probe — Bind risk_detections and expose its result columns (credential-free; attach an azure_graph secret to sync real data)

SELECT id, user_id, risk_event_type, detected_date_time
FROM azure.main.risk_detections()
LIMIT 0;

Uses risk_detections

risky_service_principals_bind_probe — Bind risky_service_principals and expose its result columns (credential-free; attach an azure_graph secret to sync real data)

SELECT id, app_id, display_name, risk_level, risk_state
FROM azure.main.risky_service_principals()
LIMIT 0;

Uses risky_service_principals

Incremental sync of risk detections from a saved watermark

SELECT id, user_id, risk_event_type
FROM azure.main.risk_detections(since := '<_watermark_next>')
WHERE _row_kind IS NULL

Uses risk_detections

Reconcile detections against the current per-user verdict (mandatory §2c join)

SELECT d.id, d.risk_event_type, u.risk_state AS current_verdict
FROM azure.main.risk_detections() d
JOIN azure.main.risky_users() u ON d.user_id = u.id
WHERE d._row_kind IS NULL AND u._row_kind IS NULL
ORDER BY d.id

Uses risk_detectionsrisky_users

List every risk feed and the table function that serves it

SELECT collection, table_function
FROM azure.main.risk_collections
ORDER BY collection

Uses risk_collections

11 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • List the users in the Entra tenant who are currently at risk, with their risk level.
  • For each recent risk detection, what is the affected user's current risk verdict?
  • Which service principals (workload identities) in the tenant are currently high risk?
  • After syncing risky users, how do I get the cursor to use for the next incremental sync?
  • What risk feeds does this worker expose, and which table function serves each?

Azure Risk is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.