Skip to content

Azure Sign-ins

Microsoft Entra sign-in and directory audit logs

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-signins/index.md to help me query Azure Sign-ins 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 applications with failed sign-ins

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

SELECT app_display_name, count(*) AS failures
FROM azure.main.signin_logs()
WHERE _row_kind IS NULL AND status <> '0'
GROUP BY app_display_name
ORDER BY failures DESC

Quick start

Choose where to run Azure Sign-ins, 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-signins'
);

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 app_display_name, count(*) AS failures
FROM azure.main.signin_logs()
WHERE _row_kind IS NULL AND status <> '0'
GROUP BY app_display_name
ORDER BY failures DESC
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 sign-in & directory audit logs via Graph (lagged-watermark cursor) — vgi-azure-signins

Catalog

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

azure 1 schema
main 1 view · 2 functions

Microsoft Entra ID sign-in and directory audit logs as incremental Graph watermark feeds.

Schema examples (8)
Examples (8)

Backfill all available sign-in events

SELECT id, created_date_time, app_display_name, user_principal_name
FROM azure.main.signin_logs()
WHERE _row_kind IS NULL;

Incremental sign-in scan from a saved watermark

SELECT id, created_date_time, app_display_name
FROM azure.main.signin_logs(since := '<prior _watermark_next>')
WHERE _row_kind IS NULL;

Failed sign-ins per application (non-zero errorCode)

SELECT app_display_name, count(*) AS failures
FROM azure.main.signin_logs()
WHERE _row_kind IS NULL AND status <> '0'
GROUP BY app_display_name
ORDER BY failures DESC;

Read the sign-in watermark cursor to persist for the next scan

SELECT _watermark_next
FROM azure.main.signin_logs()
WHERE _row_kind = 'marker';
4 more examples

Directory audit events grouped by logging service

SELECT app_display_name, count(*) AS events
FROM azure.main.audit_logs()
WHERE _row_kind IS NULL
GROUP BY app_display_name
ORDER BY events DESC;

Users with failed sign-ins who later initiated directory audit events: failed sign-in count, first failure time, and how many audit events they initiated after it (users with no later audit event are omitted)

WITH failed AS (SELECT user_principal_name, count(*) AS failed_signins, min(created_date_time::TIMESTAMPTZ) AS first_failure FROM azure.main.signin_logs() WHERE _row_kind IS NULL AND status <> '0' GROUP BY user_principal_name) SELECT f.user_principal_name, f.failed_signins, f.first_failure, count(*) AS audit_events_after
FROM failed AS f
JOIN azure.main.audit_logs() AS a ON a.user_principal_name = f.user_principal_name AND a.created_date_time::TIMESTAMPTZ > f.first_failure
WHERE a._row_kind IS NULL
GROUP BY f.user_principal_name, f.failed_signins, f.first_failure
ORDER BY audit_events_after DESC, f.user_principal_name;

Directory audit events initiated from an IP address that also produced failed sign-ins, listing the users whose sign-ins failed from that IP (catches a different account acting from the same source)

SELECT a.id, a.created_date_time, a.app_display_name,
  a.user_principal_name AS initiated_by, a.status, s.failed_signin_users
FROM azure.main.audit_logs() AS a
JOIN (SELECT ip_address, list_sort(list(DISTINCT user_principal_name)) AS failed_signin_users FROM azure.main.signin_logs() WHERE _row_kind IS NULL AND status <> '0' GROUP BY ip_address) AS s ON s.ip_address = a.ip_address
WHERE a._row_kind IS NULL
ORDER BY a.created_date_time, a.id;

Per-user activity across both feeds: sign-ins, failed sign-ins, and directory audit events initiated (a user missing from one feed gets 0 there; app-initiated audit events with no user are excluded)

WITH s AS (SELECT user_principal_name, count(*) AS signins, count(*) FILTER (WHERE status <> '0') AS failed_signins FROM azure.main.signin_logs() WHERE _row_kind IS NULL GROUP BY user_principal_name), a AS (SELECT user_principal_name, count(*) AS audit_events FROM azure.main.audit_logs() WHERE _row_kind IS NULL AND user_principal_name IS NOT NULL GROUP BY user_principal_name) SELECT coalesce(s.user_principal_name, a.user_principal_name) AS user_principal_name, coalesce(s.signins, 0) AS signins, coalesce(s.failed_signins, 0) AS failed_signins, coalesce(a.audit_events, 0) AS audit_events
FROM s
FULL OUTER JOIN a ON a.user_principal_name = s.user_principal_name
ORDER BY failed_signins DESC, audit_events DESC, user_principal_name;
Views
audit_feeds 2 examples4 cols

The audit feeds this catalog exposes (sign-in logs, directory audit logs) and the watermark table function that serves each. Browsable without credentials.

Columns
feed VARCHAR
The audit feed's human name (sign-in logs / directory audit logs).
table_function VARCHAR
The catalog table function that syncs this feed as a lagged-watermark incremental feed.
graph_endpoint VARCHAR
The Microsoft Graph endpoint the feed reads from.
description VARCHAR
A one-line description of the feed.
Examples (2)

List every audit feed and the table function that serves it

SELECT feed, table_function FROM azure.main.audit_feeds ORDER BY feed;

Find the Graph endpoint backing the sign-in feed

SELECT graph_endpoint
FROM azure.main.audit_feeds
WHERE table_function = 'signin_logs';
Link
Table functions
audit_logs (filter := VARCHAR, lag_minutes := BIGINT, page_size := BIGINT, since := VARCHAR, until := VARCHAR) 7 examples

Entra ID directory audit logs via Microsoft Graph (lagged-watermark on createdDateTime; at-least-once + dedup-by-id).

Named arguments
filter := VARCHAR
An additional OData `$filter` expression AND-ed onto the time-window predicate to narrow the feed (e.g. `"status/errorCode ne 0"`). Empty (the default) applies no extra filter. · default ""
lag_minutes := BIGINT
The safety-lag in minutes subtracted from the emitted high-watermark so late-arriving, boundary-unordered events are re-captured on the next scan. Defaults to 10. This overlap is why apply must be idempotent (dedup-by-id). · default 10
page_size := BIGINT
The Microsoft Graph `$top` page size for each request. Graph caps sign-ins at 1000 rows per page; defaults to 1000. Pages are followed inside a single scan. · default 1000
since := VARCHAR
The already-lagged high-watermark from the prior scan (the marker row's `_watermark_next`), replayed as the lower bound (`createdDateTime ge <since>`). Empty (the default) performs a backfill from the start of retention with no lower bound. · default ""
until := VARCHAR
Optional upper bound (`createdDateTime le <until>`) for historical replay of a bounded window. A caller-supplied `until` is a replay-only cursor and must NOT be persisted as the live ingestion watermark. Empty (the default) means no upper bound. · default ""
Returns columns
id VARCHAR
The Graph event's unique id (used for idempotent dedup-by-id on apply). NULL on the marker row.
created_date_time VARCHAR
ISO-8601 timestamp the audit event was logged (`createdDateTime`).
app_display_name VARCHAR
The Entra service that logged the event (`loggedByService`, e.g. Core Directory, Self-service Password Management).
user_principal_name VARCHAR
UPN of the user who initiated the activity (`initiatedBy.user.userPrincipalName`). PII — published through the vgi-pii -> vgi-mask (format-preserving) composition.
ip_address VARCHAR
IP address of the initiating user (`initiatedBy.user.ipAddress`). PII — published through the vgi-pii -> vgi-mask (format-preserving) composition.
status VARCHAR
The audit result (`result`, e.g. 'success' or 'failure').
_row_kind VARCHAR
NULL for data rows; 'marker' for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the ISO-8601 (already lag-adjusted) high-watermark to persist and replay via the `since` argument on the next scan; NULL on data rows.
Examples (7)

Backfill all available directory audit events (data rows only)

SELECT id, created_date_time, app_display_name, user_principal_name, status
FROM azure.main.audit_logs()
WHERE _row_kind IS NULL;

Incremental scan replaying a previously saved high-watermark cursor

SELECT id, created_date_time, app_display_name
FROM azure.main.audit_logs(since := '<prior _watermark_next>')
WHERE _row_kind IS NULL;

Directory audit events initiated from an IP address that also produced failed sign-ins, listing the users whose sign-ins failed from that IP (catches a different account acting from the same source)

SELECT a.id, a.created_date_time, a.app_display_name,
  a.user_principal_name AS initiated_by, a.status, s.failed_signin_users
FROM azure.main.audit_logs() AS a
JOIN (SELECT ip_address, list_sort(list(DISTINCT user_principal_name)) AS failed_signin_users FROM azure.main.signin_logs() WHERE _row_kind IS NULL AND status <> '0' GROUP BY ip_address) AS s ON s.ip_address = a.ip_address
WHERE a._row_kind IS NULL
ORDER BY a.created_date_time, a.id;
4 more examples

Per-user activity across both feeds: sign-ins, failed sign-ins, and directory audit events initiated (a user missing from one feed gets 0 there; app-initiated audit events with no user are excluded)

WITH s AS (SELECT user_principal_name, count(*) AS signins, count(*) FILTER (WHERE status <> '0') AS failed_signins FROM azure.main.signin_logs() WHERE _row_kind IS NULL GROUP BY user_principal_name), a AS (SELECT user_principal_name, count(*) AS audit_events FROM azure.main.audit_logs() WHERE _row_kind IS NULL AND user_principal_name IS NOT NULL GROUP BY user_principal_name) SELECT coalesce(s.user_principal_name, a.user_principal_name) AS user_principal_name, coalesce(s.signins, 0) AS signins, coalesce(s.failed_signins, 0) AS failed_signins, coalesce(a.audit_events, 0) AS audit_events
FROM s
FULL OUTER JOIN a ON a.user_principal_name = s.user_principal_name
ORDER BY failed_signins DESC, audit_events DESC, user_principal_name;

Read the high-watermark cursor to persist for the next scan

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

Count audit events per logging service

SELECT app_display_name, count(*) AS events
FROM azure.main.audit_logs()
WHERE _row_kind IS NULL
GROUP BY app_display_name
ORDER BY events DESC;

Replay a bounded historical window (since/until); the marker cursor here is replay-only, not the live watermark

SELECT id, created_date_time, app_display_name
FROM azure.main.audit_logs(since := '2026-01-01T00:00:00Z', until := '2026-02-01T00:00:00Z')
WHERE _row_kind IS NULL;
Link
signin_logs (filter := VARCHAR, lag_minutes := BIGINT, page_size := BIGINT, since := VARCHAR, until := VARCHAR) 6 examples

Entra ID sign-in logs via Microsoft Graph (lagged-watermark on createdDateTime; at-least-once + dedup-by-id).

Named arguments
filter := VARCHAR
An additional OData `$filter` expression AND-ed onto the time-window predicate to narrow the feed (e.g. `"status/errorCode ne 0"`). Empty (the default) applies no extra filter. · default ""
lag_minutes := BIGINT
The safety-lag in minutes subtracted from the emitted high-watermark so late-arriving, boundary-unordered events are re-captured on the next scan. Defaults to 10. This overlap is why apply must be idempotent (dedup-by-id). · default 10
page_size := BIGINT
The Microsoft Graph `$top` page size for each request. Graph caps sign-ins at 1000 rows per page; defaults to 1000. Pages are followed inside a single scan. · default 1000
since := VARCHAR
The already-lagged high-watermark from the prior scan (the marker row's `_watermark_next`), replayed as the lower bound (`createdDateTime ge <since>`). Empty (the default) performs a backfill from the start of retention with no lower bound. · default ""
until := VARCHAR
Optional upper bound (`createdDateTime le <until>`) for historical replay of a bounded window. A caller-supplied `until` is a replay-only cursor and must NOT be persisted as the live ingestion watermark. Empty (the default) means no upper bound. · default ""
Returns columns
id VARCHAR
The Graph event's unique id (used for idempotent dedup-by-id on apply). NULL on the marker row.
created_date_time VARCHAR
ISO-8601 timestamp the sign-in occurred (`createdDateTime`).
app_display_name VARCHAR
Display name of the application the user signed in to (`appDisplayName`).
user_principal_name VARCHAR
UPN of the signing-in user (`userPrincipalName`). PII — published through the vgi-pii -> vgi-mask (format-preserving) composition.
ip_address VARCHAR
Source IP address of the sign-in (`ipAddress`). PII — published through the vgi-pii -> vgi-mask (format-preserving) composition.
status VARCHAR
The sign-in status error code (`status.errorCode`); '0' denotes a successful sign-in.
_row_kind VARCHAR
NULL for data rows; 'marker' for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the ISO-8601 (already lag-adjusted) high-watermark to persist and replay via the `since` argument on the next scan; NULL on data rows.
Examples (6)

Backfill all available sign-in events (data rows only)

SELECT id, created_date_time, app_display_name, user_principal_name, status
FROM azure.main.signin_logs()
WHERE _row_kind IS NULL;

Incremental scan replaying a previously saved high-watermark cursor

SELECT id, created_date_time, app_display_name
FROM azure.main.signin_logs(since := '<prior _watermark_next>')
WHERE _row_kind IS NULL;

Users with failed sign-ins who later initiated directory audit events: failed sign-in count, first failure time, and how many audit events they initiated after it (users with no later audit event are omitted)

WITH failed AS (SELECT user_principal_name, count(*) AS failed_signins, min(created_date_time::TIMESTAMPTZ) AS first_failure FROM azure.main.signin_logs() WHERE _row_kind IS NULL AND status <> '0' GROUP BY user_principal_name) SELECT f.user_principal_name, f.failed_signins, f.first_failure, count(*) AS audit_events_after
FROM failed AS f
JOIN azure.main.audit_logs() AS a ON a.user_principal_name = f.user_principal_name AND a.created_date_time::TIMESTAMPTZ > f.first_failure
WHERE a._row_kind IS NULL
GROUP BY f.user_principal_name, f.failed_signins, f.first_failure
ORDER BY audit_events_after DESC, f.user_principal_name;
3 more examples

Count failed sign-ins per application (non-zero errorCode)

SELECT app_display_name, count(*) AS failures
FROM azure.main.signin_logs()
WHERE _row_kind IS NULL AND status <> '0'
GROUP BY app_display_name
ORDER BY failures DESC;

Read the high-watermark cursor to persist for the next scan

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

Narrow the feed server-side to failed sign-ins with an additive OData $filter

SELECT id, created_date_time, app_display_name
FROM azure.main.signin_logs(filter := 'status/errorCode ne 0')
WHERE _row_kind IS NULL;
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 signin_logsaudit_logs

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

signin_logs_bind_probe — Bind signin_logs and expose its result columns (credential-free; drop LIMIT 0 and attach an azure_graph secret to sync real sign-in events)

SELECT id, created_date_time, app_display_name, user_principal_name,
  ip_address, status
FROM azure.main.signin_logs()
LIMIT 0;

Uses signin_logs

audit_logs_bind_probe — Bind audit_logs and expose its result columns (credential-free; attach an azure_graph secret to sync real audit events)

SELECT id, created_date_time, app_display_name, user_principal_name,
  ip_address, status
FROM azure.main.audit_logs()
LIMIT 0;

Uses audit_logs

Backfill all available sign-in events

SELECT id, created_date_time, app_display_name, user_principal_name
FROM azure.main.signin_logs()
WHERE _row_kind IS NULL

Uses signin_logs

Incremental sign-in scan from a saved watermark

SELECT id, created_date_time, app_display_name
FROM azure.main.signin_logs(since := '<prior _watermark_next>')
WHERE _row_kind IS NULL

Uses signin_logs

Read the sign-in watermark cursor to persist for the next scan

SELECT _watermark_next
FROM azure.main.signin_logs()
WHERE _row_kind = 'marker'

Uses signin_logs

List every audit feed and the table function that serves it

SELECT feed, table_function FROM azure.main.audit_feeds ORDER BY feed

Uses audit_feeds

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.

  • Show the most recent sign-in events with the user principal name and the application they signed in to.
  • Which applications had the most failed sign-ins?
  • After a sign-in scan, how do I get the cursor to use for the next incremental scan?
  • List directory audit events grouped by the service that logged them.
  • What audit feeds can I sync, and which table function serves each?

Azure Sign-ins 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.