Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(drata): sync audits and the control junction tables (#107275)

Tom Owersc8bdcf8f9240
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 39e34a332d49..dfbfc725a1a5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -2634,14 +2634,14 @@ Today (14): `assets`, `controls`, `devices`, `events`, `evidence_library`, `fram
Diffed against: <https://developers.drata.com/page-data/openapi/reference/v2/tag/Assets/page-data.json>
- [x] `GET /workspaces/{workspaceId}/framework-requirements` — the requirement catalogue each synced framework is composed of — without it frameworks are opaque IDs (high)
-- [ ] `GET /workspaces/{workspaceId}/controls/{controlId}/requirements` — control↔requirement mapping, the junction that makes compliance coverage queryable (high)
+- [x] `GET /workspaces/{workspaceId}/controls/{controlId}/requirements` — control↔requirement mapping, the junction that makes compliance coverage queryable (high) — added as `control_requirements`, fanning out over the already-synced controls.
- [x] `GET /workspaces/{workspaceId}/monitoring-tests/{testId}/failures` — test failure history — the headline continuous-monitoring metric; monitoring_tests today gives only current state (high)
- [x] `GET /workspaces/{workspaceId}/tasks` — remediation tasks with owners and due dates; the core operational work queue (high)
- [x] `GET /users/{userId}/assigned-policies` — policy acceptance per user — the compliance metric auditors ask for; policies sync but attestation does not (high)
- [ ] `GET /roles and GET /roles/{roleId}/users` — role lookup plus role↔user membership for the already-synced users table (medium)
-- [ ] `GET /workspaces/{workspaceId}/audits` — audit engagements that scope frameworks and evidence (medium)
-- [ ] `GET /workspaces/{workspaceId}/audits/{auditId}/requests` — auditor evidence requests and their fulfillment state (medium)
-- [ ] `GET /workspaces/{workspaceId}/controls/{controlId}/owners` — control↔personnel ownership junction (medium)
+- [x] `GET /workspaces/{workspaceId}/audits` — audit engagements that scope frameworks and evidence (medium) — added as `audits`.
+- [x] `GET /workspaces/{workspaceId}/audits/{auditId}/requests` — auditor evidence requests and their fulfillment state (medium) — added as `audit_requests`, fanning out over `audits`.
+- [x] `GET /workspaces/{workspaceId}/controls/{controlId}/owners` — control↔personnel ownership junction (medium) — added as `control_owners`. The rows carry user records, so they join to `users` rather than `personnel`.
- [ ] `GET /vendor-security-reviews` — vendor security review records and outcomes across all synced vendors (medium)
- [ ] `GET /vendor-types` — lookup resolving the type ID on every synced vendor (medium)
- [ ] `GET /policies/{policyId}/policy-versions` — policy version history for change tracking (low)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/drata/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/drata/canonical_descriptions.py
index 98cc86c37217..d536477dcd7d 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/drata/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/drata/canonical_descriptions.py
@@ -133,6 +133,44 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"updatedAt": "When the control was last updated.",
},
},
+ "control_requirements": {
+ "description": "The requirements each control satisfies, one row per control-requirement pair. This is the junction that makes framework coverage queryable: join it to controls and framework_requirements to see which requirements a control covers and which requirements no control covers yet.",
+ "docs_url": "https://developers.drata.com/openapi/reference/v2/tag/Controls/",
+ "columns": {
+ "workspaceId": "Identifier of the workspace the control belongs to (added by PostHog).",
+ "controlId": "Identifier of the control this requirement is mapped to (added by PostHog).",
+ "id": "Unique identifier for the requirement.",
+ "name": "Name of the requirement.",
+ "description": "Description of the requirement.",
+ "longDescription": "Long-form description of the requirement.",
+ "frameworkName": "Name of the framework the requirement belongs to.",
+ "frameworkSlug": "Slug of the framework the requirement belongs to.",
+ "frameworkTag": "Tag of the framework the requirement belongs to, e.g. SOC_2.",
+ "frameworkPill": "Short label Drata shows for the framework.",
+ "externalId": "Identifier the framework itself gives this requirement.",
+ "rationale": "Reason recorded for marking the requirement out of scope.",
+ "additionalInfo": "Additional information about the requirement.",
+ "additionalInfo2": "Second additional information field for the requirement.",
+ "additionalInfo3": "Third additional information field for the requirement.",
+ "archivedAt": "When the requirement was marked out of scope, if it was.",
+ "createdAt": "When the requirement was created.",
+ "updatedAt": "When the requirement was last updated.",
+ },
+ },
+ "control_owners": {
+ "description": "The users who own each control, one row per control-owner pair. Join it to controls to see who is accountable for a control, and to users to group ownership by person.",
+ "docs_url": "https://developers.drata.com/openapi/reference/v2/tag/Control-Owners/",
+ "columns": {
+ "workspaceId": "Identifier of the workspace the control belongs to (added by PostHog).",
+ "controlId": "Identifier of the control this person owns (added by PostHog).",
+ "id": "Identifier of the owning user.",
+ "email": "Email address of the owning user.",
+ "firstName": "First name of the owning user.",
+ "lastName": "Last name of the owning user.",
+ "createdAt": "When the owning user was created.",
+ "updatedAt": "When the owning user was last updated.",
+ },
+ },
"monitoring_tests": {
"description": "Automated monitoring tests in each workspace, with pass/fail status and check state.",
"docs_url": "https://developers.drata.com/openapi/reference/v2/tag/Monitoring-Tests/",
@@ -181,6 +219,38 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"updatedAt": "When the evidence item was last updated.",
},
},
+ "audits": {
+ "description": "Audit engagements run in each workspace, internal or with an external auditor. An audit scopes a framework over a date range and is what audit_requests hang off.",
+ "docs_url": "https://developers.drata.com/openapi/reference/v2/tag/Audits/",
+ "columns": {
+ "workspaceId": "Identifier of the workspace the audit belongs to (added by PostHog).",
+ "id": "Unique identifier for the audit.",
+ "frameworkType": "Framework the audit covers, e.g. SOC_2.",
+ "auditType": "Type of the audit.",
+ "isInternalAudit": "Whether the audit is run internally rather than by an external auditor.",
+ "status": "Current status of the audit.",
+ "startDate": "When the audit period starts.",
+ "endDate": "When the audit period ends.",
+ "completedAt": "When the audit was completed, or empty while it is still in progress.",
+ "createdAt": "When the audit was created.",
+ "updatedAt": "When the audit was last updated.",
+ },
+ },
+ "audit_requests": {
+ "description": "Evidence requests raised by an auditor during an audit, with their fulfillment status. This is the audit work queue: what the auditor asked for and whether it has been answered.",
+ "docs_url": "https://developers.drata.com/openapi/reference/v2/tag/Audit-Requests/",
+ "columns": {
+ "workspaceId": "Identifier of the workspace the audit belongs to (added by PostHog).",
+ "auditId": "Identifier of the audit the request belongs to.",
+ "id": "Unique identifier for the request.",
+ "code": "Short identifier code the auditor refers to the request by.",
+ "title": "Title of the request.",
+ "description": "Description of what the auditor asked for.",
+ "status": "Current fulfillment status of the request.",
+ "createdAt": "When the request was created.",
+ "updatedAt": "When the request was last updated.",
+ },
+ },
"frameworks": {
"description": "Compliance frameworks enabled in each workspace (SOC 2, ISO 27001, HIPAA, ...), with readiness counts.",
"docs_url": "https://developers.drata.com/openapi/reference/v2/tag/Frameworks/",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/drata/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/drata/settings.py
index b7825a3efbf3..2bb9bef92203 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/drata/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/drata/settings.py
@@ -103,6 +103,29 @@ DRATA_ENDPOINTS: dict[str, DrataEndpointConfig] = {
fan_out_parent_id_column="workspaceId",
primary_keys=["workspaceId", "id"],
),
+ "control_requirements": DrataEndpointConfig(
+ name="control_requirements",
+ path="/workspaces/{workspaceId}/controls/{parent_id}/requirements",
+ fan_out_parent="controls",
+ fan_out_parent_id_column="controlId",
+ fan_out_path_params={"parent_id": "id", "workspaceId": "workspaceId"},
+ fan_out_extra_parent_columns={"workspaceId": "workspaceId"},
+ # The control-to-requirement junction: one requirement is mapped by many controls, so the
+ # requirement's own id repeats and the control id has to be part of the key.
+ primary_keys=["workspaceId", "controlId", "id"],
+ ),
+ "control_owners": DrataEndpointConfig(
+ name="control_owners",
+ path="/workspaces/{workspaceId}/controls/{parent_id}/owners",
+ fan_out_parent="controls",
+ fan_out_parent_id_column="controlId",
+ fan_out_path_params={"parent_id": "id", "workspaceId": "workspaceId"},
+ fan_out_extra_parent_columns={"workspaceId": "workspaceId"},
+ # `id` here is the owning user's id, which repeats across every control they own.
+ # The row's only timestamp is the user's own `createdAt`, which is stable enough to
+ # partition on.
+ primary_keys=["workspaceId", "controlId", "id"],
+ ),
"monitoring_tests": DrataEndpointConfig(
name="monitoring_tests",
path="/workspaces/{parent_id}/monitoring-tests",
@@ -143,6 +166,23 @@ DRATA_ENDPOINTS: dict[str, DrataEndpointConfig] = {
fan_out_parent_id_column="workspaceId",
primary_keys=["workspaceId", "id"],
),
+ "audits": DrataEndpointConfig(
+ name="audits",
+ path="/workspaces/{parent_id}/audits",
+ fan_out_parent="workspaces",
+ fan_out_parent_id_column="workspaceId",
+ primary_keys=["workspaceId", "id"],
+ ),
+ "audit_requests": DrataEndpointConfig(
+ name="audit_requests",
+ path="/workspaces/{workspaceId}/audits/{parent_id}/requests",
+ fan_out_parent="audits",
+ fan_out_parent_id_column="auditId",
+ fan_out_path_params={"parent_id": "id", "workspaceId": "workspaceId"},
+ fan_out_extra_parent_columns={"workspaceId": "workspaceId"},
+ # Request ids are numbered within their audit, so both ancestor ids join the key.
+ primary_keys=["workspaceId", "auditId", "id"],
+ ),
"frameworks": DrataEndpointConfig(
name="frameworks",
path="/workspaces/{parent_id}/frameworks",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/drata/tests/test_drata.py b/products/warehouse_sources/backend/temporal/data_imports/sources/drata/tests/test_drata.py
index 3839f6919f0b..b13e44b1adcf 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/drata/tests/test_drata.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/drata/tests/test_drata.py
@@ -382,6 +382,59 @@ class TestWorkspaceFanOut:
assert rows == [{"id": 1, parent_column: 5}]
+class TestControlJunctionFanOut:
+ """Control junctions hang two fan-out levels deep: workspaces -> controls -> junction."""
+
+ def _route(self, child_segment: str) -> Route:
+ def route(url: str, params: dict[str, Any]) -> Response:
+ if url.endswith("/workspaces"):
+ return _resp({"data": [{"id": 10}], "pagination": {"cursor": None}})
+ if url.endswith("/workspaces/10/controls"):
+ return _resp({"data": [{"id": 88}], "pagination": {"cursor": None}})
+ if url.endswith(f"/workspaces/10/controls/88/{child_segment}"):
+ return _resp({"data": [{"id": 4}], "pagination": {"cursor": None}})
+ raise AssertionError(f"unexpected url {url}")
+
+ return route
+
+ @parameterized.expand(
+ [
+ ("requirements", "control_requirements", "requirements"),
+ ("owners", "control_owners", "owners"),
+ ]
+ )
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_binds_control_id_and_carries_both_ancestor_ids(
+ self, _name: str, endpoint: str, segment: str, mock_session: mock.MagicMock
+ ) -> None:
+ rows, calls = _run(mock_session, self._route(segment), endpoint, _FakeManager())
+ assert calls[-1]["url"] == f"{US_BASE_URL}/workspaces/10/controls/88/{segment}"
+ # Both junctions repeat their `id` across controls — a requirement is mapped by many
+ # controls, an owner owns many — so the control id has to be part of the key.
+ assert rows == [{"id": 4, "controlId": 88, "workspaceId": 10}]
+
+
+class TestAuditRequestFanOut:
+ """Audit requests hang two fan-out levels deep: workspaces -> audits -> requests."""
+
+ def _route(self, url: str, params: dict[str, Any]) -> Response:
+ if url.endswith("/workspaces"):
+ return _resp({"data": [{"id": 10}], "pagination": {"cursor": None}})
+ if url.endswith("/workspaces/10/audits"):
+ return _resp({"data": [{"id": "aud-1"}], "pagination": {"cursor": None}})
+ if url.endswith("/workspaces/10/audits/aud-1/requests"):
+ return _resp({"data": [{"id": 7, "auditId": "aud-1"}], "pagination": {"cursor": None}})
+ raise AssertionError(f"unexpected url {url}")
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_binds_string_audit_id_and_carries_workspace_id(self, mock_session: mock.MagicMock) -> None:
+ rows, calls = _run(mock_session, self._route, "audit_requests", _FakeManager())
+ # Audit ids are strings, unlike every other Drata parent id.
+ assert calls[-1]["url"] == f"{US_BASE_URL}/workspaces/10/audits/aud-1/requests"
+ # Request ids are numbered within their audit, so both ancestor ids ride along.
+ assert rows == [{"id": 7, "auditId": "aud-1", "workspaceId": 10}]
+
+
class TestMonitoringTestFailureFanOut:
"""Failures hang two fan-out levels deep: workspaces -> monitoring tests -> failures."""
@@ -542,6 +595,7 @@ class TestDrataSourceResponse:
("frameworks",),
("framework_requirements",),
("tasks",),
+ ("audits",),
]
)
def test_workspace_children_use_composite_primary_key(self, endpoint: str) -> None: