Queries · q313 · Chief Information Security Officer · week 2, night 1
“Beyond Owner/Administrator accounts, how much other access (ordinary staff logins, open sessions, active API keys, active webhooks) is still live on tenants that have already churned?”
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 2
Subject: Re: Account security snapshot — good start, three gaps worry me more now
Noah,
This is a strong first week — thank you. The sign-in and access-governance findings give me confidence I can defend in a questionnaire. Three things genuinely surprised me and I want to understand them better before Friday's memo, plus one follow-up.
If we can only chase a couple of these deeply this week, I'd prioritize the deletion-audit scope (#1) and the churn-deactivation scope (#3) — those are the two a due-diligence team is most likely to ask us to prove, one way or the other.
Thanks, Henrik
The analyst · week 2, night 1, request 3 of 3
Henrik asked us to prioritize #1 (how wide is the deletion-audit gap) and #3 (how far does the churn-deactivation problem go) this week, so all 3 slots go there tonight. For #1, last week's 6-table sample (products at 0% coverage, users at 69%, three others with zero soft-deletes ever recorded) isn't enough to tell him whether this is "fix one thing" or "fix deletion logging everywhere" — so tonight I'm running a full census across every table that actually supports soft-deletion, not a hand-picked sample. I'm also addressing a gap in how I framed this last week: orders, invoices and other financial documents don't use deleted_at at all — they're "deleted" via a status change (cancelled/void), so testing audit coverage for the specific things Henrik named (orders, financial documents) needs a different query than soft-delete matching, which is report 2. For #3, last week I only checked role holders; tonight's report sizes the exposure across every access surface on churned tenants (user accounts, sessions, API keys, webhooks) so Henrik can judge whether this is a one-line fix (deactivate Owner/Admin) or a broader deprovisioning gap. I'm deliberately not touching #2 (shopper MFA compensating controls) or #4 (old-key sensitivity) tonight per his stated priority, and will pick those up once #1 and #3 are sized.
The engineer · 1 dry run on the empty schema, then the submission
SELECT t.name AS tenant_name, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL) AS total_users, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL AND u.status = 'active') AS active_users, (SELECT COUNT(*) FROM sessions s WHERE s.tenant_id = t.id AND s.revoked_at IS NULL) AS open_sessions, (SELECT COUNT(*) FROM api_keys ak WHERE ak.tenant_id = t.id AND ak.status = 'active') AS active_api_keys, (SELECT COUNT(*) FROM webhooks w WHERE w.tenant_id = t.id AND w.is_active = true) AS active_webhooks, (SELECT COUNT(*) FROM service_accounts sa WHERE sa.tenant_id = t.id) AS service_accounts FROM tenants t WHERE t.status = 'churned' ORDER BY active_users DESC, tenant_name ASC
“Query compiles cleanly. Submitting as-is.”
“Submitted. The report returns one row per churned tenant with total users, active users, open sessions, active API keys, active webhooks, and service account counts, each computed via an independent aggregated subquery per tenant_id to avoid join fan-out, ordered by active users descending. Note on scope: the request's narrative mentioned "beyond Owner/Administrator accounts," but the concrete Details section didn't specify a roles join, so I counted all users regardless of role — flagged this in the submit note in case a role-filtered follow-up is wanted.”
As Noah Fischer saw it, from the small dataset the agents worked on
tenant_name | total_users | active_users | open_sessions | active_api_keys | active_webhooks | service_accounts -------------------+-------------+--------------+---------------+-----------------+-----------------+----------------- Saltmarsh Knitwear | 18 | 18 | 300 | 0 | 0 | 0 Petal & Pestle | 10 | 10 | 223 | 0 | 0 | 0 Dewdrop Studio | 9 | 9 | 171 | 1 | 1 | 1 Halden Boots | 8 | 8 | 120 | 0 | 0 | 0 Marginalia | 8 | 8 | 80 | 0 | 0 | 0 Aurum & Ash | 7 | 7 | 73 | 1 | 1 | 1 Northwire Audio | 7 | 7 | 191 | 0 | 0 | 0 Paddock & Pine | 7 | 7 | 46 | 0 | 0 | 0 Klara Beauty | 5 | 5 | 110 | 0 | 0 | 0 (9 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
SELECT t.name AS tenant_name, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL) AS total_users, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL AND u.status = 'active') AS active_users, (SELECT COUNT(*) FROM sessions s WHERE s.tenant_id = t.id AND s.revoked_at IS NULL) AS open_sessions, (SELECT COUNT(*) FROM api_keys ak WHERE ak.tenant_id = t.id AND ak.status = 'active') AS active_api_keys, (SELECT COUNT(*) FROM webhooks w WHERE w.tenant_id = t.id AND w.is_active = true) AS active_webhooks, (SELECT COUNT(*) FROM service_accounts sa WHERE sa.tenant_id = t.id) AS service_accountsFROM tenants tWHERE t.status = 'churned'ORDER BY active_users DESC, tenant_name ASCORDER BY active_users DESC NULLS FIRST, tenant_name ASC NULLS LAST, t.id NULLS LAST
SELECT t.name AS tenant_name, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL) AS total_users, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL AND u.status = 'active') AS active_users, (SELECT COUNT(*) FROM sessions s WHERE s.tenant_id = t.id AND s.revoked_at IS NULL) AS open_sessions, (SELECT COUNT(*) FROM api_keys ak WHERE ak.tenant_id = t.id AND ak.status = 'active') AS active_api_keys, (SELECT COUNT(*) FROM webhooks w WHERE w.tenant_id = t.id AND w.is_active = true) AS active_webhooks, (SELECT COUNT(*) FROM service_accounts sa WHERE sa.tenant_id = t.id) AS service_accounts FROM tenants t WHERE t.status = 'churned' ORDER BY active_users DESC NULLS FIRST, tenant_name ASC NULLS LAST, t.id NULLS LAST
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: Access still open on churned tenants, by surface Question: Beyond Owner/Administrator accounts, how much other access (ordinary staff logins, open sessions, active API keys, active webhooks) is still live on tenants that have already churned? Grain: one row per churned tenant (tenants.status = 'churned') Columns: - tenant name - total users (excluding deleted_at rows) - users with status = 'active' - sessions never revoked (revoked_at is null, regardless of expiry) - active API keys (status = 'active') - active webhooks (is_active = true) - service accounts (count, for context; no activity field exists for this table) Details: Source: tenants where status = 'churned', joined to users (tenant_id, status, deleted_at), sessions (tenant_id, revoked_at), api_keys (tenant_id, status), webhooks (tenant_id, is_active), service_accounts (tenant_id). Count each measure per tenant independently (not a single multi-join to avoid fan-out; use separate aggregated subqueries per tenant_id). Include every churned tenant, even if all counts are zero. Order by 'users with status = active' descending, tenant name as tie-break. Expect a small number of rows (well under 50) — note total churned tenant count. Check your query with the warehouse's dry_run tool, then hand it in with submit.
dry_runSELECT t.name AS tenant_name, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL) AS total_users, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL AND u.status = 'active') AS active_users, (SELECT COUNT(*) FROM sessions s WHERE s.tenant_id = t.id AND s.revoked_at IS NULL) AS open_sessions, (SELECT COUNT(*) FROM api_keys ak WHERE ak.tenant_id = t.id AND ak.status = 'active') AS active_api_keys, (SELECT COUNT(*) FROM webhooks w WHERE w.tenant_id = t.id AND w.is_active = true) AS active_webhooks, (SELECT COUNT(*) FROM service_accounts sa WHERE sa.tenant_id = t.id) AS service_accounts FROM tenants t WHERE t.status = 'churned' ORDER BY active_users DESC, tenant_name ASC
STATUS: COMPILES (dry run on the empty schema, no data read) COLUMNS: tenant_name, total_users, active_users, open_sessions, active_api_keys, active_webhooks, service_accounts
submitSELECT t.name AS tenant_name, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL) AS total_users, (SELECT COUNT(*) FROM users u WHERE u.tenant_id = t.id AND u.deleted_at IS NULL AND u.status = 'active') AS active_users, (SELECT COUNT(*) FROM sessions s WHERE s.tenant_id = t.id AND s.revoked_at IS NULL) AS open_sessions, (SELECT COUNT(*) FROM api_keys ak WHERE ak.tenant_id = t.id AND ak.status = 'active') AS active_api_keys, (SELECT COUNT(*) FROM webhooks w WHERE w.tenant_id = t.id AND w.is_active = true) AS active_webhooks, (SELECT COUNT(*) FROM service_accounts sa WHERE sa.tenant_id = t.id) AS service_accounts FROM tenants t WHERE t.status = 'churned' ORDER BY active_users DESC, tenant_name ASC
Submitted to tonight's batch. Your work on this request is done.