Skip to content

Azure Governance

Entra governance posture — conditional access policies, role assignments and expiring credentials

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-governance/index.md to help me query Azure Governance 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 application credentials expiring within 30 days

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

SELECT owner_display_name, credential_type, end_date_time, days_until_expiry
FROM azure.main.app_credentials(expiring_within_days := 30)
ORDER BY days_until_expiry

Quick start

Choose where to run Azure Governance, 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-governance'
);

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 owner_display_name, credential_type, end_date_time, days_until_expiry
FROM azure.main.app_credentials(expiring_within_days := 30)
ORDER BY days_until_expiry
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 governance posture (CA policies, role assignments, credential expiry) via Graph — vgi-azure-governance

Catalog

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

azure 1 schema
main 2 tables · 1 function

Microsoft Entra ID governance snapshots (Conditional Access, directory role assignments, app credential expiry) via Microsoft Graph.

Schema examples (7)
Examples (7)

Enabled Conditional Access policies

SELECT id, display_name, state
FROM azure.main.conditional_access_policies()
WHERE state = 'enabled';

PIM-eligible directory role assignments

SELECT role_display_name, principal_id, status
FROM azure.main.role_assignments()
WHERE assignment_kind = 'eligible';

Credentials expiring within 30 days

SELECT owner_display_name, credential_type, end_date_time, days_until_expiry
FROM azure.main.app_credentials(expiring_within_days := 30)
ORDER BY days_until_expiry;

Already-expired app & service-principal credentials

SELECT owner_kind, owner_display_name, credential_type, end_date_time
FROM azure.main.app_credentials()
WHERE is_expired;
3 more examples

Directory-role holders (active or PIM-eligible) that an enabled Conditional Access policy explicitly excludes by user id — the break-glass / exclusion audit

WITH excluded AS (SELECT ca.display_name AS policy_name, x.principal_id FROM azure.main.conditional_access_policies() AS ca, unnest(from_json(ca.excluded_users_json, '["VARCHAR"]')) AS x(principal_id) WHERE ca.state = 'enabled') SELECT e.policy_name, r.role_display_name, r.principal_id, r.assignment_kind
FROM excluded AS e
JOIN azure.main.role_assignments() AS r ON r.principal_id = e.principal_id
ORDER BY e.policy_name, r.role_display_name, r.principal_id, r.assignment_kind;

Held directory roles that no enabled Conditional Access policy targets by role (conditions.users.includeRoles), with the number of distinct holders; policies scoped to all users are not counted

WITH targeted AS (SELECT DISTINCT t.role_id FROM azure.main.conditional_access_policies() AS ca, unnest(from_json(json_extract(ca.raw_json, '$.conditions.users.includeRoles'), '["VARCHAR"]')) AS t(role_id) WHERE ca.state = 'enabled') SELECT r.role_display_name, count(DISTINCT r.principal_id) AS holders
FROM azure.main.role_assignments() AS r
WHERE r.role_definition_id NOT IN (SELECT role_id FROM targeted)
GROUP BY r.role_display_name
ORDER BY holders DESC, r.role_display_name;

Credentials held directly on a service principal that also holds a directory role, expiring within 30 days or already expired (soonest first), with the roles it holds

WITH privileged AS (SELECT principal_id, string_agg(DISTINCT role_display_name, ', ' ORDER BY role_display_name) AS roles FROM azure.main.role_assignments() GROUP BY principal_id) SELECT c.owner_display_name, p.roles, c.credential_type, c.end_date_time, c.days_until_expiry
FROM azure.main.app_credentials(expiring_within_days := 30) AS c
JOIN privileged AS p ON p.principal_id = c.owner_id
WHERE c.owner_kind = 'servicePrincipal'
ORDER BY c.days_until_expiry, c.owner_display_name, c.credential_type;
Tables
conditional_access_policies 7 examples12 cols

Microsoft Entra Conditional Access policies (snapshot) via Microsoft Graph v1.0.

Columns
id VARCHAR
Conditional Access policy id (GUID).
display_name VARCHAR
Policy display name.
state VARCHAR
Policy state: `enabled`, `disabled`, or `enabledForReportingButNotEnforced`.
created_date_time VARCHAR
ISO-8601 (UTC) timestamp the policy was created; NULL if unknown.
modified_date_time VARCHAR
ISO-8601 (UTC) timestamp the policy was last modified; NULL if never modified.
included_users_json VARCHAR
JSON array of targeted user/role/group ids (conditions.users.includeUsers).
excluded_users_json VARCHAR
JSON array of excluded user/role/group ids.
included_apps_json VARCHAR
JSON array of targeted application ids (conditions.applications.includeApplications).
grant_controls_json VARCHAR
JSON object of grant controls (e.g. MFA, compliant device, terms of use).
session_controls_json VARCHAR
JSON object of session controls (e.g. sign-in frequency, app-enforced restrictions).
client_app_types_json VARCHAR
JSON array of client app types the policy applies to.
raw_json VARCHAR
The full Graph policy object as JSON.
ConstraintsPRIMARY KEY (id)
Examples (7)

All Conditional Access policies with their state

SELECT id, display_name, state FROM azure.main.conditional_access_policies;

Only the enabled (enforced) policies

SELECT display_name
FROM azure.main.conditional_access_policies
WHERE state = 'enabled';

Grant controls for each enabled policy

SELECT display_name, grant_controls_json
FROM azure.main.conditional_access_policies
WHERE state = 'enabled';
4 more examples
SELECT id, display_name, state
FROM azure.main.conditional_access_policies();
SELECT display_name
FROM azure.main.conditional_access_policies()
WHERE state = 'enabled';
SELECT display_name, grant_controls_json
FROM azure.main.conditional_access_policies()
WHERE state = 'enabled';
WITH excluded AS (SELECT ca.display_name AS policy_name, x.principal_id FROM azure.main.conditional_access_policies() AS ca, unnest(from_json(ca.excluded_users_json, '["VARCHAR"]')) AS x(principal_id) WHERE ca.state = 'enabled') SELECT e.policy_name, r.role_display_name, r.principal_id, r.assignment_kind
FROM excluded AS e
JOIN azure.main.role_assignments() AS r ON r.principal_id = e.principal_id
ORDER BY e.policy_name, r.role_display_name, r.principal_id, r.assignment_kind;
Link
role_assignments 7 examples12 cols

Microsoft Entra directory role assignments — active ∪ PIM-eligible (snapshot) via Microsoft Graph v1.0.

Columns
assignment_kind VARCHAR
`active` (a live roleAssignment) or `eligible` (a PIM roleEligibilityScheduleInstance).
id VARCHAR
The assignment / eligibility instance id.
principal_idnot null VARCHAR
Object id of the assigned principal (user, group, or service principal).
principal_type VARCHAR
Principal kind: `user`, `group`, or `servicePrincipal`; NULL if not resolvable.
role_definition_idnot null VARCHAR
The directory role definition (template) id.
role_display_name VARCHAR
Human-readable role name (e.g. Global Administrator); from the expanded roleDefinition; NULL if Graph returns none.
directory_scope_id VARCHAR
Scope of the assignment (e.g. `/` for tenant-wide).
start_date_time VARCHAR
Eligibility schedule start (ISO-8601 UTC); NULL for active assignments.
end_date_time VARCHAR
Assignment/eligibility end (ISO-8601 UTC); NULL means permanent.
member_type VARCHAR
How the assignment was granted (e.g. Direct, Group, Inherited).
status VARCHAR
Eligibility status (e.g. Provisioned); NULL for active assignments.
raw_json VARCHAR
The full Graph assignment object as JSON.
ConstraintsPRIMARY KEY (assignment_kind, id)
Examples (7)

All directory role assignments (active and PIM-eligible)

SELECT assignment_kind, role_display_name, principal_id
FROM azure.main.role_assignments;

Only PIM-eligible (not yet activated) assignments

SELECT role_display_name, principal_id, status
FROM azure.main.role_assignments
WHERE assignment_kind = 'eligible';

Active assignment count per directory role

SELECT role_display_name, count(*)
FROM azure.main.role_assignments
WHERE assignment_kind = 'active'
GROUP BY role_display_name
ORDER BY count(*) DESC;
4 more examples
SELECT assignment_kind, role_display_name, principal_id
FROM azure.main.role_assignments();
SELECT role_display_name, principal_id, status
FROM azure.main.role_assignments()
WHERE assignment_kind = 'eligible';
SELECT role_display_name, count(*)
FROM azure.main.role_assignments()
WHERE assignment_kind = 'active'
GROUP BY role_display_name
ORDER BY count(*) DESC;
WITH targeted AS (SELECT DISTINCT t.role_id FROM azure.main.conditional_access_policies() AS ca, unnest(from_json(json_extract(ca.raw_json, '$.conditions.users.includeRoles'), '["VARCHAR"]')) AS t(role_id) WHERE ca.state = 'enabled') SELECT r.role_display_name, count(DISTINCT r.principal_id) AS holders
FROM azure.main.role_assignments() AS r
WHERE r.role_definition_id NOT IN (SELECT role_id FROM targeted)
GROUP BY r.role_display_name
ORDER BY holders DESC, r.role_display_name;
Link
Table functions
app_credentials (expiring_within_days := BIGINT) 4 examples

Flattened app & service-principal password/key credentials with scan-time days_until_expiry / is_expired (snapshot). expiring_within_days filters after flatten.

Named arguments
expiring_within_days := BIGINT
Optional expiry-window filter. When set, keep only credentials whose `days_until_expiry <= N` (already-expired credentials have negative days and stay in); credentials with no expiry are dropped. Leave unset (the default) to apply no filter and return every credential. · default null
Returns columns
owner_kind VARCHAR
application or servicePrincipal — which directory object owns the credential.
owner_id VARCHAR
Object id of the owning application or service principal.
app_id VARCHAR
The owner's appId (client id); NULL if absent.
owner_display_name VARCHAR
Display name of the owning app / service principal.
credential_type VARCHAR
password (client secret) or key (certificate).
credential_key_id VARCHAR
The credential's keyId (GUID); NULL if absent.
display_name VARCHAR
The credential's own display name / description.
start_date_time VARCHAR
ISO-8601 credential validity start.
end_date_time VARCHAR
ISO-8601 credential expiry; NULL if the credential has no expiry.
days_until_expiry BIGINT
Whole days from scan time to end_date_time (negative if already expired); NULL if no expiry. Scan-time snapshot — recompute downstream.
is_expired BOOLEAN
Whether the credential was expired at scan time; NULL if it has no expiry. Scan-time snapshot.
usage VARCHAR
For key credentials, Verify or Sign; NULL for password credentials.
raw_json VARCHAR
The credential fields plus owner id as JSON.
Examples (4)

Full credential inventory across apps and service principals

SELECT owner_display_name, credential_type, end_date_time, days_until_expiry
FROM azure.main.app_credentials();

Credentials expiring within the next 30 days (soonest first)

SELECT owner_display_name, credential_type, days_until_expiry
FROM azure.main.app_credentials(expiring_within_days := 30)
ORDER BY days_until_expiry;

Credentials that are already expired

SELECT owner_kind, owner_display_name, credential_type, end_date_time
FROM azure.main.app_credentials()
WHERE is_expired;
1 more example

Credentials held directly on a service principal that also holds a directory role, expiring within 30 days or already expired (soonest first), with the roles it holds

WITH privileged AS (SELECT principal_id, string_agg(DISTINCT role_display_name, ', ' ORDER BY role_display_name) AS roles FROM azure.main.role_assignments() GROUP BY principal_id) SELECT c.owner_display_name, p.roles, c.credential_type, c.end_date_time, c.days_until_expiry
FROM azure.main.app_credentials(expiring_within_days := 30) AS c
JOIN privileged AS p ON p.principal_id = c.owner_id
WHERE c.owner_kind = 'servicePrincipal'
ORDER BY c.days_until_expiry, c.owner_display_name, c.credential_type;
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 of the Microsoft Entra tenant, from the app registration's Overview page
client_id VARCHAR — Application (client) ID of the Microsoft Entra app registration, from its Overview page
client_secret secret VARCHAR — Client secret value created under the app registration's Certificates & secrets page (shown once, at creation)

The worker doesn't mark which keys are required.

Needed by conditional_access_policiesrole_assignmentsapp_credentials

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

conditional_access_policies_bind_probe — Bind conditional_access_policies and expose its result columns (credential-free; drop LIMIT 0 and attach an azure_graph secret to pull real policies)

SELECT id, display_name, state
FROM azure.main.conditional_access_policies()
LIMIT 0;

role_assignments_bind_probe — Bind role_assignments and expose its result columns (credential-free; attach an azure_graph secret to pull real assignments)

SELECT assignment_kind, principal_id, role_display_name
FROM azure.main.role_assignments()
LIMIT 0;

app_credentials_bind_probe — Bind app_credentials and expose its result columns (credential-free; attach an azure_graph secret to pull real credentials)

SELECT owner_display_name, credential_type, end_date_time,
  days_until_expiry, is_expired
FROM azure.main.app_credentials()
LIMIT 0;

Uses app_credentials

Enabled Conditional Access policies

SELECT id, display_name, state
FROM azure.main.conditional_access_policies()
WHERE state = 'enabled'

PIM-eligible directory role assignments

SELECT role_display_name, principal_id, status
FROM azure.main.role_assignments()
WHERE assignment_kind = 'eligible'

Directory-role holders (active or PIM-eligible) that an enabled Conditional Access policy explicitly excludes by user id — the break-glass / exclusion audit

WITH excluded AS (SELECT ca.display_name AS policy_name, x.principal_id FROM azure.main.conditional_access_policies() AS ca, unnest(from_json(ca.excluded_users_json, '["VARCHAR"]')) AS x(principal_id) WHERE ca.state = 'enabled') SELECT e.policy_name, r.role_display_name, r.principal_id, r.assignment_kind
FROM excluded AS e
JOIN azure.main.role_assignments() AS r ON r.principal_id = e.principal_id
ORDER BY e.policy_name, r.role_display_name, r.principal_id, r.assignment_kind

16 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 enabled Conditional Access policies in the Entra ID tenant with their display names.
  • Who holds the Global Administrator directory role, and are those assignments active or PIM-eligible?
  • Which application or service-principal credentials expire within the next 30 days?

Azure Governance 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.