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(warehouse-sources): add fusionauth lookup and group membership tables (#109129)

Tom Owersfd08e3adac2d
diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
index 6ff602b78434..79e012d7329f 100644
--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt
@@ -600,7 +600,6 @@
1 products/warehouse_sources/backend/temporal/data_imports/sources/fulcrum/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/fullstory/fullstory.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/fusionauth.py
-1 products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/gainsight_px/gainsight_px.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/gainsight_px/settings.py
1 products/warehouse_sources/backend/temporal/data_imports/sources/gerrit/gerrit.py
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 9746921ece2e..96f4acbd3048 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
@@ -3484,10 +3484,10 @@ Today (4): `AuditLogs`, `EventLogs`, `LoginRecords`, `Users`
Diffed against: <https://raw.githubusercontent.com/FusionAuth/fusionauth-openapi/main/openapi.yaml>
-- [ ] `application (GET /api/application, POST /api/application/search)` — lookup that resolves the applicationId stamped on every login record, registration and audit entry (high)
-- [ ] `tenant (POST /api/tenant/search)` — lookup resolving the tenantId on users and login records — the top-level isolation dimension (high)
-- [ ] `group (POST /api/group/search)` — lookup naming the groups referenced by user memberships (high)
-- [ ] `group/member (POST /api/group/member/search)` — the user-to-group membership table; group-level access analysis is impossible without it (high)
+- [x] `application (GET /api/application, POST /api/application/search)` — lookup that resolves the applicationId stamped on every login record, registration and audit entry (high)
+- [x] `tenant (POST /api/tenant/search)` — lookup resolving the tenantId on users and login records — the top-level isolation dimension (high)
+- [x] `group (POST /api/group/search)` — lookup naming the groups referenced by user memberships (high)
+- [x] `group/member (POST /api/group/member/search)` — the user-to-group membership table; group-level access analysis is impossible without it (high)
- [ ] `user/registration (GET /api/user/registration/{userId}/{applicationId})` — which users are registered to which applications, with roles and registration dates (medium)
- [ ] `user/consent (GET /api/user/consent, POST /api/consent/search)` — consent grants per user plus the consent definition lookup — compliance reporting (medium)
- [ ] `entity + entity/grant (POST /api/entity/search, /api/entity/grant/search)` — non-user entities and the grants linking them to users — the machine-to-machine authorization graph (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/canonical_descriptions.py
index 6558a6be2930..68aa3bfe88bd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/canonical_descriptions.py
@@ -53,4 +53,53 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"ipAddress": "The IP address the login attempt was made from.",
},
},
+ "Applications": {
+ "description": "FusionAuth applications that users register for and log in to, with their roles and configuration.",
+ "docs_url": "https://fusionauth.io/docs/apis/applications",
+ "columns": {
+ "id": "Unique identifier for the application.",
+ "name": "The name of the application.",
+ "tenantId": "The unique identifier of the tenant the application belongs to.",
+ "active": "Whether the application is active.",
+ "state": "The state of the application (Active or Inactive).",
+ "roles": "The roles defined for the application.",
+ "insertInstant": "The instant (epoch milliseconds) the application was created.",
+ "lastUpdateInstant": "The instant (epoch milliseconds) the application was last updated.",
+ },
+ },
+ "Tenants": {
+ "description": "FusionAuth tenants, the top-level isolation boundary for users, applications and groups.",
+ "docs_url": "https://fusionauth.io/docs/apis/tenants",
+ "columns": {
+ "id": "Unique identifier for the tenant.",
+ "name": "The name of the tenant.",
+ "issuer": "The named issuer used to sign tokens issued for this tenant.",
+ "state": "The state of the tenant (Active or PendingDelete).",
+ "insertInstant": "The instant (epoch milliseconds) the tenant was created.",
+ "lastUpdateInstant": "The instant (epoch milliseconds) the tenant was last updated.",
+ },
+ },
+ "Groups": {
+ "description": "FusionAuth groups that users can be members of, each granting a set of application roles.",
+ "docs_url": "https://fusionauth.io/docs/apis/groups",
+ "columns": {
+ "id": "Unique identifier for the group.",
+ "name": "The name of the group.",
+ "tenantId": "The unique identifier of the tenant the group belongs to.",
+ "roles": "The application roles granted to members of the group, keyed by application id.",
+ "insertInstant": "The instant (epoch milliseconds) the group was created.",
+ "lastUpdateInstant": "The instant (epoch milliseconds) the group was last updated.",
+ },
+ },
+ "GroupMembers": {
+ "description": "Memberships linking FusionAuth users to groups.",
+ "docs_url": "https://fusionauth.io/docs/apis/groups",
+ "columns": {
+ "id": "Unique identifier for the group membership.",
+ "groupId": "The unique identifier of the group.",
+ "userId": "The unique identifier of the user who is a member of the group.",
+ "data": "Custom data stored on the membership.",
+ "insertInstant": "The instant (epoch milliseconds) the user was added to the group.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/fusionauth.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/fusionauth.py
index f553d24065f5..09aed5656ada 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/fusionauth.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/fusionauth.py
@@ -241,11 +241,24 @@ def _build_search_body(config: FusionAuthEndpointConfig, search_extra: dict[str,
elif config.sort_mode == "asc":
# AuditLogs/EventLogs document an explicit `orderBy` field (unlike LoginRecords),
# so we can request ascending order and use a simple advancing watermark.
- search["orderBy"] = "insertInstant ASC"
+ search["orderBy"] = config.order_by
search.update(search_extra)
return {"search": search}
+def _drop_fields(row: Any, paths: tuple[str, ...]) -> Any:
+ if not isinstance(row, dict):
+ return row
+ for path in paths:
+ *parents, leaf = path.split(".")
+ target: Any = row
+ for key in parents:
+ target = target.get(key) if isinstance(target, dict) else None
+ if isinstance(target, dict):
+ target.pop(leaf, None)
+ return row
+
+
def _get_headers() -> dict[str, str]:
return {"Accept": "application/json", "Content-Type": "application/json"}
@@ -357,7 +370,7 @@ def fusionauth_source(
if state and state.get("offset") is not None:
resumable_source_manager.save_state(FusionAuthResumeConfig(offset=int(state["offset"])))
- def items() -> Iterator[list[Any]]:
+ def pages() -> Iterator[list[Any]]:
# Re-check at run time (not just at source-create) in case the base URL was edited to
# now resolve to an internal address (SSRF / DNS rebinding). Only enforced on cloud. Refuse
# plaintext HTTP before the key is used. Both raise before any request leaves the process.
@@ -430,6 +443,12 @@ def fusionauth_source(
)
yield from resource
+ def items() -> Iterator[list[Any]]:
+ for page in pages():
+ if config.exclude_fields:
+ page = [_drop_fields(row, config.exclude_fields) for row in page]
+ yield page
+
return SourceResponse(
name=endpoint,
items=items,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/settings.py
index dad29d23e2d1..5f813a1ac26b 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/settings.py
@@ -13,7 +13,7 @@ def _datetime_incremental_field(name: str) -> IncrementalField:
}
-@dataclass
+@dataclass(frozen=True)
class FusionAuthEndpointConfig:
name: str
path: str
@@ -33,6 +33,10 @@ class FusionAuthEndpointConfig:
# Elasticsearch-backed search endpoints (currently just user search) cap the standard
# result window; None means no such cap is documented.
maximum_offset: Optional[int] = None
+ # Sent as `search.orderBy` on endpoints that document it (only used when sort_mode is "asc").
+ order_by: str = "insertInstant ASC"
+ # Dotted paths removed from every row before it is written, for secrets the API returns.
+ exclude_fields: tuple[str, ...] = ()
# Search endpoints only: FusionAuth also has non-search read APIs (e.g. GET /api/user/{id})
@@ -87,6 +91,46 @@ FUSIONAUTH_ENDPOINTS: dict[str, FusionAuthEndpointConfig] = {
# order — assume FusionAuth's usual newest-first default like the other log endpoints.
sort_mode="desc",
),
+ # Database-backed lookup searches (not Elasticsearch) with no server-side timestamp filter, so
+ # these are full refresh. `id ASC` keeps page boundaries stable while rows are being inserted.
+ "Applications": FusionAuthEndpointConfig(
+ name="Applications",
+ path="/api/application/search",
+ data_selector="applications",
+ primary_keys=["id"],
+ incremental_fields=[],
+ partition_key="insertInstant",
+ order_by="id ASC",
+ exclude_fields=("oauthConfiguration.clientSecret",),
+ ),
+ "Tenants": FusionAuthEndpointConfig(
+ name="Tenants",
+ path="/api/tenant/search",
+ data_selector="tenants",
+ primary_keys=["id"],
+ incremental_fields=[],
+ partition_key="insertInstant",
+ order_by="id ASC",
+ exclude_fields=("captchaConfiguration.secretKey", "emailConfiguration.password"),
+ ),
+ "Groups": FusionAuthEndpointConfig(
+ name="Groups",
+ path="/api/group/search",
+ data_selector="groups",
+ primary_keys=["id"],
+ incremental_fields=[],
+ partition_key="insertInstant",
+ order_by="id ASC",
+ ),
+ "GroupMembers": FusionAuthEndpointConfig(
+ name="GroupMembers",
+ path="/api/group/member/search",
+ data_selector="members",
+ primary_keys=["id"],
+ incremental_fields=[],
+ partition_key="insertInstant",
+ order_by="id ASC",
+ ),
}
ENDPOINTS = tuple(FUSIONAUTH_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/tests/test_fusionauth.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/tests/test_fusionauth.py
index 6ffe8aa2e925..e02612db721c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/tests/test_fusionauth.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/tests/test_fusionauth.py
@@ -101,6 +101,11 @@ class TestBuildSearchBody:
body = _build_search_body(FUSIONAUTH_ENDPOINTS[endpoint], {})
assert body["search"]["orderBy"] == "insertInstant ASC"
+ @pytest.mark.parametrize("endpoint", ["Applications", "Tenants", "Groups", "GroupMembers"])
+ def test_lookup_endpoints_order_by_id(self, endpoint):
+ body = _build_search_body(FUSIONAUTH_ENDPOINTS[endpoint], {})
+ assert body["search"] == {"orderBy": "id ASC"}
+
def test_login_records_has_no_order_by(self):
# LoginRecords documents no orderBy field, so it must never be sent.
body = _build_search_body(FUSIONAUTH_ENDPOINTS["LoginRecords"], {})
@@ -258,6 +263,10 @@ class TestFusionAuthSourceResponse:
("AuditLogs", ["id"], "asc", "insertInstant"),
("EventLogs", ["id"], "asc", "insertInstant"),
("LoginRecords", ["userId", "applicationId", "instant"], "desc", "instant"),
+ ("Applications", ["id"], "asc", "insertInstant"),
+ ("Tenants", ["id"], "asc", "insertInstant"),
+ ("Groups", ["id"], "asc", "insertInstant"),
+ ("GroupMembers", ["id"], "asc", "insertInstant"),
],
)
def test_response_shape(self, endpoint, primary_keys, sort_mode, partition_key):
@@ -277,6 +286,34 @@ class TestFusionAuthSourceResponse:
assert response.partition_format == "week"
+parameterized_secret_cases = pytest.mark.parametrize(
+ "endpoint, data_selector, row, expected",
+ [
+ (
+ "Applications",
+ "applications",
+ {"id": "a1", "oauthConfiguration": {"clientId": "a1", "clientSecret": "fake-secret"}},
+ {"id": "a1", "oauthConfiguration": {"clientId": "a1"}},
+ ),
+ (
+ "Tenants",
+ "tenants",
+ {
+ "id": "t1",
+ "captchaConfiguration": {"siteKey": "site", "secretKey": "fake-secret"},
+ "emailConfiguration": {"host": "smtp.example.com", "password": "fake-password"},
+ },
+ {
+ "id": "t1",
+ "captchaConfiguration": {"siteKey": "site"},
+ "emailConfiguration": {"host": "smtp.example.com"},
+ },
+ ),
+ ("Tenants", "tenants", {"id": "t2", "emailConfiguration": None}, {"id": "t2", "emailConfiguration": None}),
+ ],
+)
+
+
class TestFusionAuthAscendingPagination:
def _source(self, endpoint="AuditLogs", manager=None, base_url="https://auth.example.com", **kwargs):
return fusionauth_source(
@@ -365,6 +402,13 @@ class TestFusionAuthAscendingPagination:
assert snaps[0]["json"]["search"]["queryString"] == "*"
assert snaps[0]["json"]["search"]["numberOfResults"] == 100
+ @parameterized_secret_cases
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_secret_fields_are_dropped(self, MockSession, endpoint, data_selector, row, expected):
+ session = MockSession.return_value
+ _wire(session, [_response({data_selector: [row]})])
+ assert _rows(self._source(endpoint=endpoint)) == [expected]
+
@mock.patch(CLIENT_SESSION_PATCH)
def test_does_not_follow_redirects(self, MockSession):
session = MockSession.return_value
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/tests/test_fusionauth_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/tests/test_fusionauth_source.py
index 3fe532808992..1c2448445486 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/tests/test_fusionauth_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/fusionauth/tests/test_fusionauth_source.py
@@ -27,6 +27,10 @@ class TestFusionAuthSource:
("AuditLogs", True),
("EventLogs", True),
("LoginRecords", True),
+ ("Applications", False),
+ ("Tenants", False),
+ ("Groups", False),
+ ("GroupMembers", False),
],
)
def test_schema_incremental_support(self, endpoint, incremental):