Queries · q105 · Chief Information Security Officer · week 1, night 2
“Beyond the default 'Owner' role (which filled the entire first page of the prior report), what other roles across merchants carry significant permissions, how widely are they assigned, and how dormant are the users holding them?”
Fictional people at a fictional company, each played by a language-model agent. Who they are and what they are told
The manager, at the start of week 1
Subject: Where I'd like your help first — account security snapshot
Hi Noah,
Good to have you working with me this week. I'm still building my mental map of the business, so let's start broad and sharpen later. Here's what's on my mind, roughly in priority order:
What I need this for: I'm walking into enterprise deals where security questionnaires will ask us point-blank about authentication strength, access governance, credential hygiene, and auditability. I need an honest, evidence-based picture — good or bad — so I can brief the CEO and sales on what we can credibly claim today versus what needs fixing before the next review cycle.
Given the slot budget, let's pick whichever 3 of these will give us the most defensible starting picture this week, and we can go deeper on the rest next week.
Thanks, Henrik
The analyst · week 1, night 2, request 3 of 3
Reading critically: (1) login volumes look like a calm baseline — failure rate holds 5-8% and avg attempts-per-IP stays ~1.5 all 26 weeks, which doesn't look like credential stuffing. But the week of 2025-11-24 jumps ~41% in total attempts (and max-attempts-per-single-IP jumps to 24, the second-highest in the series) while failure rate stays normal — plausibly just Black Friday/Cyber Monday shopping traffic, but I want to confirm it's broad-based across tenants rather than concentrated on one tenant/IP before ruling out an attack. (2) MFA report 2 is a bombshell: shopper MFA is 0.0% for every one of the 50 worst-covered tenants, and staff MFA tops out at 50% even among the better of that bottom 50 — but this report only shows the worst half of tenants by staff rate, so I don't yet have the company-wide headline number Henrik actually needs to quote, nor do I know if MFA adoption is improving over time or flat. (3) Report 3's 50-row page got entirely consumed by the single "Owner" system role (26 permissions, tied for the most) across ~50 tenants, out of 434 qualifying tenant-role rows — I haven't seen any non-Owner privileged roles yet, so I can't say anything about custom role hygiene. I did spot two dormant privileged accounts worth keeping (Aurum & Ash: Owner account active in status but last login 2024-12-26, over a year stale, on a churned tenant; Halden Boots: Owner last login 2025-10-03). Tonight's three requests: a monthly MFA-adoption trend giving the defensible overall number and trajectory, a tenant breakdown of the anomalous Nov 24 week to test the Black-Friday-vs-attack hypothesis, and a company-wide rollup by role name (collapsing the 434 tenant-role rows) to see privileged access beyond "Owner" and its dormancy rate.
The engineer · 1 dry run on the empty schema, then the submission
WITH role_instance AS ( SELECT r.id AS role_id, r.tenant_id, r.name, r.is_system, COUNT(DISTINCT rp.permission_id) AS perm_count FROM roles r JOIN role_permissions rp ON rp.role_id = r.id GROUP BY r.id, r.tenant_id, r.name, r.is_system ), assigned AS ( SELECT ur.role_id, COUNT(DISTINCT u.id) AS assigned_users, COUNT(DISTINCT u.id) FILTER (WHERE u.status = 'active' AND (u.last_login_at IS NULL OR u.last_login_at < DATE '2025-10-05')) AS dormant_users FROM user_roles ur JOIN users u ON u.id = ur.user_id AND u.tenant_id = ur.tenant_id WHERE u.deleted_at IS NULL GROUP BY ur.role_id ), qualifying AS ( SELECT ri.tenant_id, ri.name, ri.is_system, ri.perm_count, a.assigned_users, a.dormant_users FROM role_instance ri JOIN assigned a ON a.role_id = ri.role_id WHERE ri.perm_count >= 1 AND a.assigned_users >= 1 ) SELECT name AS role_name, COUNT(DISTINCT tenant_id) AS tenant_count, ROUND(100.0 * SUM(CASE WHEN is_system THEN 1 ELSE 0 END) / COUNT(*), 1) AS pct_is_system, ROUND(AVG(perm_count), 1) AS avg_permission_count, MAX(perm_count) AS max_permission_count, SUM(assigned_users) AS total_users_assigned, SUM(dormant_users) AS total_users_dormant, ROUND(100.0 * SUM(dormant_users) / NULLIF(SUM(assigned_users), 0), 1) AS dormant_rate_pct FROM qualifying WHERE name <> 'Owner' GROUP BY name ORDER BY total_users_assigned DESC, role_name LIMIT 50
“Query compiles and matches the requested grain and columns. Submitting now.”
“Submitted. Summary of what the query does:
- Role instances: roles joined to role_permissions, grouped per (role_id, tenant_id, name, is_system) to get a permission count per role instance.
- Assignment & dormancy: user_roles joined to users (excluding soft-deleted users), aggregated per role_id into assigned-user counts and dormant-user counts (active status, and last login null or before 2025-10-05).
- Qualifying set: role instances with ≥1 permission and ≥1 assigned non-deleted user — matching the prior report's population — with 'Owner' excluded per the analyst's framing.
- Final grouping: by role_name across all tenants, computing tenant count, % flagged is_system, average/max permission counts, total assigned, total dormant, and dormant rate, ordered by total assigned descending (tie-break on role name), capped at 50 rows.”
As Noah Fischer saw it, from the small dataset the agents worked on
role_name | tenant_count | pct_is_system | avg_permission_count | max_permission_count | total_users_assigned | total_users_dormant | dormant_rate_pct --------------+--------------+---------------+----------------------+----------------------+----------------------+---------------------+----------------- Support Agent | 120 | 100.0 | 6.0 | 6 | 234 | 10 | 4.3 Administrator | 120 | 100.0 | 25.0 | 25 | 122 | 8 | 6.6 Warehouse | 33 | 100.0 | 4.0 | 4 | 37 | 0 | 0.0 Marketing | 18 | 100.0 | 5.0 | 5 | 19 | 0 | 0.0 Read-only | 8 | 0.0 | 4.0 | 4 | 10 | 0 | 0.0 Merchandiser | 8 | 100.0 | 4.0 | 4 | 8 | 0 | 0.0 Finance | 4 | 100.0 | 5.0 | 5 | 4 | 0 | 0.0 Sales Rep | 3 | 100.0 | 5.0 | 5 | 3 | 0 | 0.0 (8 rows)
The memo and the queries that followed; links found by title, so inferred
Later queries that build on this report:
It builds on:
Changed only where the benchmark needs the same result on every system
WITH role_instance AS ( SELECT r.id AS role_id, r.tenant_id, r.name, r.is_system, SELECT r.id AS role_id, r.tenant_id AS tenant_id, r.name AS name, r.is_system AS is_system, COUNT(DISTINCT rp.permission_id) AS perm_count FROM roles r JOIN role_permissions rp ON rp.role_id = r.id GROUP BY r.id, r.tenant_id, r.name, r.is_system),assigned AS ( SELECT ur.role_id, SELECT ur.role_id AS role_id, COUNT(DISTINCT u.id) AS assigned_users, COUNT(DISTINCT u.id) FILTER (WHERE u.status = 'active' AND (u.last_login_at IS NULL OR u.last_login_at < DATE '2025-10-05')) AS dormant_users FROM user_roles ur JOIN users u ON u.id = ur.user_id AND u.tenant_id = ur.tenant_id WHERE u.deleted_at IS NULL GROUP BY ur.role_id),qualifying AS ( SELECT ri.tenant_id, ri.name, ri.is_system, ri.perm_count, a.assigned_users, a.dormant_users SELECT ri.tenant_id AS tenant_id, ri.name AS name, ri.is_system AS is_system, ri.perm_count AS perm_count, a.assigned_users AS assigned_users, a.dormant_users AS dormant_users FROM role_instance ri JOIN assigned a ON a.role_id = ri.role_id WHERE ri.perm_count >= 1 AND a.assigned_users >= 1)SELECT name AS role_name, COUNT(DISTINCT tenant_id) AS tenant_count, ROUND(100.0 * SUM(CASE WHEN is_system THEN 1 ELSE 0 END) / COUNT(*), 1) AS pct_is_system, ROUND(AVG(perm_count), 1) AS avg_permission_count, 100.0 * SUM(CASE WHEN is_system THEN 1 ELSE 0 END) / COUNT(*) AS pct_is_system, AVG(CAST(perm_count AS NUMERIC(18,6))) AS avg_permission_count, MAX(perm_count) AS max_permission_count, SUM(assigned_users) AS total_users_assigned, SUM(dormant_users) AS total_users_dormant, ROUND(100.0 * SUM(dormant_users) / NULLIF(SUM(assigned_users), 0), 1) AS dormant_rate_pct 100.0 * SUM(dormant_users) / NULLIF(SUM(assigned_users), 0) AS dormant_rate_pctFROM qualifyingWHERE name <> 'Owner'GROUP BY nameORDER BY total_users_assigned DESC, role_nameLIMIT 50ORDER BY total_users_assigned DESC NULLS FIRST, role_name NULLS LAST{{fetch_first(50)}}
WITH role_instance AS ( SELECT r.id AS role_id, r.tenant_id AS tenant_id, r.name AS name, r.is_system AS is_system, COUNT(DISTINCT rp.permission_id) AS perm_count FROM roles r JOIN role_permissions rp ON rp.role_id = r.id GROUP BY r.id, r.tenant_id, r.name, r.is_system ), assigned AS ( SELECT ur.role_id AS role_id, COUNT(DISTINCT u.id) AS assigned_users, COUNT(DISTINCT u.id) FILTER (WHERE u.status = 'active' AND (u.last_login_at IS NULL OR u.last_login_at < DATE '2025-10-05')) AS dormant_users FROM user_roles ur JOIN users u ON u.id = ur.user_id AND u.tenant_id = ur.tenant_id WHERE u.deleted_at IS NULL GROUP BY ur.role_id ), qualifying AS ( SELECT ri.tenant_id AS tenant_id, ri.name AS name, ri.is_system AS is_system, ri.perm_count AS perm_count, a.assigned_users AS assigned_users, a.dormant_users AS dormant_users FROM role_instance ri JOIN assigned a ON a.role_id = ri.role_id WHERE ri.perm_count >= 1 AND a.assigned_users >= 1 ) SELECT name AS role_name, COUNT(DISTINCT tenant_id) AS tenant_count, 100.0 * SUM(CASE WHEN is_system THEN 1 ELSE 0 END) / COUNT(*) AS pct_is_system, AVG(CAST(perm_count AS NUMERIC(18,6))) AS avg_permission_count, MAX(perm_count) AS max_permission_count, SUM(assigned_users) AS total_users_assigned, SUM(dormant_users) AS total_users_dormant, 100.0 * SUM(dormant_users) / NULLIF(SUM(assigned_users), 0) AS dormant_rate_pct FROM qualifying WHERE name <> 'Owner' GROUP BY name ORDER BY total_users_assigned DESC NULLS FIRST, role_name NULLS LAST FETCH FIRST 50 ROWS ONLY
WITH role_instance AS ( SELECT r.id AS role_id, r.tenant_id AS tenant_id, r.name AS name, r.is_system AS is_system, COUNT(DISTINCT rp.permission_id) AS perm_count FROM roles r JOIN role_permissions rp ON rp.role_id = r.id GROUP BY r.id, r.tenant_id, r.name, r.is_system ), assigned AS ( SELECT ur.role_id AS role_id, COUNT(DISTINCT u.id) AS assigned_users, COUNT(DISTINCT u.id) FILTER (WHERE u.status = 'active' AND (u.last_login_at IS NULL OR u.last_login_at < DATE '2025-10-05')) AS dormant_users FROM user_roles ur JOIN users u ON u.id = ur.user_id AND u.tenant_id = ur.tenant_id WHERE u.deleted_at IS NULL GROUP BY ur.role_id ), qualifying AS ( SELECT ri.tenant_id AS tenant_id, ri.name AS name, ri.is_system AS is_system, ri.perm_count AS perm_count, a.assigned_users AS assigned_users, a.dormant_users AS dormant_users FROM role_instance ri JOIN assigned a ON a.role_id = ri.role_id WHERE ri.perm_count >= 1 AND a.assigned_users >= 1 ) SELECT name AS role_name, COUNT(DISTINCT tenant_id) AS tenant_count, 100.0 * SUM(CASE WHEN is_system THEN 1 ELSE 0 END) / COUNT(*) AS pct_is_system, AVG(CAST(perm_count AS NUMERIC(18,6))) AS avg_permission_count, MAX(perm_count) AS max_permission_count, SUM(assigned_users) AS total_users_assigned, SUM(dormant_users) AS total_users_dormant, 100.0 * SUM(dormant_users) / NULLIF(SUM(assigned_users), 0) AS dormant_rate_pct FROM qualifying WHERE name <> 'Owner' GROUP BY name ORDER BY total_users_assigned DESC NULLS FIRST, role_name NULLS LAST LIMIT 50
The agents' own records, as the role play wrote them; only the personal data of the person who ran it is redacted
Report request from Noah Fischer (analyst for the Chief Information Security Officer): Title: Privileged role landscape by role name, company-wide Question: Beyond the default 'Owner' role (which filled the entire first page of the prior report), what other roles across merchants carry significant permissions, how widely are they assigned, and how dormant are the users holding them? Grain: one row per distinct role name (roles.name), aggregated across all tenants that have a role with that name Columns: - role name - tenant count (distinct tenants with a role of this name) - share of those instances flagged is_system (%) - average permission count granted (across tenant instances of this role) - max permission count seen for this role name - total users currently assigned (summed across tenants, via user_roles, excluding deleted users) - total users dormant (status = active and last_login_at is null or before 2025-10-05, summed across tenants) - dormant rate among assigned users (%) Details: Source: roles joined to role_permissions (for permission counts per role instance), user_roles joined to users (excluding users.deleted_at is not null) for assignment and dormancy. Restrict to role instances with >=1 permission and >=1 assigned non-deleted user (same population as the prior 'Privileged roles per merchant' report, i.e. drawn from that same 434-row qualifying set, but now grouped by role_name instead of by tenant+role so the whole landscape fits on one page). 'Dormant' = users.status = 'active' and (last_login_at is null or last_login_at < 2025-10-05). Dormant rate = total dormant / total assigned, rounded to 1 decimal percent. Order by total users assigned descending, then role name as tie-break; cap at 50 rows and note how many distinct role names exist in total. Check your query with the warehouse's dry_run tool, then hand it in with submit.
dry_runWITH role_instance AS ( SELECT r.id AS role_id, r.tenant_id, r.name, r.is_system, COUNT(DISTINCT rp.permission_id) AS perm_count FROM roles r JOIN role_permissions rp ON rp.role_id = r.id GROUP BY r.id, r.tenant_id, r.name, r.is_system ), assigned AS ( SELECT ur.role_id, COUNT(DISTINCT u.id) AS assigned_users, COUNT(DISTINCT u.id) FILTER (WHERE u.status = 'active' AND (u.last_login_at IS NULL OR u.last_login_at < DATE '2025-10-05')) AS dormant_users FROM user_roles ur JOIN users u ON u.id = ur.user_id AND u.tenant_id = ur.tenant_id WHERE u.deleted_at IS NULL GROUP BY ur.role_id ), qualifying AS ( SELECT ri.tenant_id, ri.name, ri.is_system, ri.perm_count, a.assigned_users, a.dormant_users FROM role_instance ri JOIN assigned a ON a.role_id = ri.role_id WHERE ri.perm_count >= 1 AND a.assigned_users >= 1 ) SELECT name AS role_name, COUNT(DISTINCT tenant_id) AS tenant_count, ROUND(100.0 * SUM(CASE WHEN is_system THEN 1 ELSE 0 END) / COUNT(*), 1) AS pct_is_system, ROUND(AVG(perm_count), 1) AS avg_permission_count, MAX(perm_count) AS max_permission_count, SUM(assigned_users) AS total_users_assigned, SUM(dormant_users) AS total_users_dormant, ROUND(100.0 * SUM(dormant_users) / NULLIF(SUM(assigned_users), 0), 1) AS dormant_rate_pct FROM qualifying WHERE name <> 'Owner' GROUP BY name ORDER BY total_users_assigned DESC, role_name LIMIT 50
STATUS: COMPILES (dry run on the empty schema, no data read) COLUMNS: role_name, tenant_count, pct_is_system, avg_permission_count, max_permission_count, total_users_assigned, total_users_dormant, dormant_rate_pct
submitWITH role_instance AS ( SELECT r.id AS role_id, r.tenant_id, r.name, r.is_system, COUNT(DISTINCT rp.permission_id) AS perm_count FROM roles r JOIN role_permissions rp ON rp.role_id = r.id GROUP BY r.id, r.tenant_id, r.name, r.is_system ), assigned AS ( SELECT ur.role_id, COUNT(DISTINCT u.id) AS assigned_users, COUNT(DISTINCT u.id) FILTER (WHERE u.status = 'active' AND (u.last_login_at IS NULL OR u.last_login_at < DATE '2025-10-05')) AS dormant_users FROM user_roles ur JOIN users u ON u.id = ur.user_id AND u.tenant_id = ur.tenant_id WHERE u.deleted_at IS NULL GROUP BY ur.role_id ), qualifying AS ( SELECT ri.tenant_id, ri.name, ri.is_system, ri.perm_count, a.assigned_users, a.dormant_users FROM role_instance ri JOIN assigned a ON a.role_id = ri.role_id WHERE ri.perm_count >= 1 AND a.assigned_users >= 1 ) SELECT name AS role_name, COUNT(DISTINCT tenant_id) AS tenant_count, ROUND(100.0 * SUM(CASE WHEN is_system THEN 1 ELSE 0 END) / COUNT(*), 1) AS pct_is_system, ROUND(AVG(perm_count), 1) AS avg_permission_count, MAX(perm_count) AS max_permission_count, SUM(assigned_users) AS total_users_assigned, SUM(dormant_users) AS total_users_dormant, ROUND(100.0 * SUM(dormant_users) / NULLIF(SUM(assigned_users), 0), 1) AS dormant_rate_pct FROM qualifying WHERE name <> 'Owner' GROUP BY name ORDER BY total_users_assigned DESC, role_name LIMIT 50
Submitted to tonight's batch. Your work on this request is done.