: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): add infisical environments, identity memberships and secret syncs tables (#111885)
Tom Owersa3ddfb8cfdf3
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.mdindex 0db2b9b8aa57..cd642749c7de 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@@ -4252,19 +4252,19 @@ Note: The Mintlify docs site serves the same 537KB SPA shell for every path (inc## Infisical — gaps-Today (11): `audit_logs`, `group_members`, `groups`, `identities`, `organization_memberships`, `organization_roles`, `project_group_memberships`, `project_memberships`, `project_roles`, `projects`, `secret_scanning_findings`+Today (14): `audit_logs`, `group_members`, `groups`, `identities`, `organization_memberships`, `organization_roles`, `project_environments`, `project_group_memberships`, `project_identity_memberships`, `project_memberships`, `project_roles`, `projects`, `secret_scanning_findings`, `secret_syncs`Diffed against: <https://app.infisical.com/api/docs/json>- [x] `/api/v1/organization/roles and /api/v2/workspace/{projectId}/roles` — lookup resolving the role IDs already carried on the synced organization_memberships and project_memberships rows (high)- [x] `/api/v1/groups (+ /{id}/users, /{id}/machine-identities, /{id}/projects)` — org group membership - the main way access is actually granted, invisible today (high)- [x] `/api/v2/workspace/{projectId}/groups` — which groups are attached to which project, the group half of project access (high)-- [ ] `/api/v2/workspace/{projectId}/identity-memberships` — machine identities scoped per project; `identities` today is org-level only, so no one can see which CI identity can read which project (high)-- [ ] `/api/v1/projects/{projectId}/environments/{envId}` — lookup resolving the environment IDs/slugs that audit_logs, folders and secrets all key on (also embedded in the project detail payload) (high)+- [x] `/api/v2/workspace/{projectId}/identity-memberships` — machine identities scoped per project; `identities` today is org-level only, so no one can see which CI identity can read which project (high)+- [x] `/api/v1/projects/{projectId}/environments/{envId}` — lookup resolving the environment IDs/slugs that audit_logs, folders and secrets all key on (also embedded in the project detail payload) (high)- [x] `/api/v2/secret-scanning/findings` — leaked-credential findings - the headline security metric of the product and the most obviously dashboardable table (high)- [ ] `/api/v2/folders` — the secret path tree; without it secret/audit rows referencing folderId cannot be resolved to a path (medium)- [ ] `/api/v2/secret-rotations` — rotation configs and last/next rotation timestamps - compliance reporting on stale credentials (medium)-- [ ] `/api/v1/secret-syncs` — sync destinations and their last sync status, for pipeline health reporting (medium)+- [x] `/api/v1/secret-syncs` — sync destinations and their last sync status, for pipeline health reporting (medium)- [ ] `/api/v2/secret-scanning/data-sources and /api/v2/secret-scanning/data-sources/{provider}/{dataSourceId}/scans` — scan run history that gives the findings table its denominator and coverage over time (medium)- [ ] `/api/v1/projects/{projectId}/secret-snapshots` — point-in-time change history of a project's secrets, the audit trail complement to audit_logs (medium)- [ ] `/api/v1/dynamic-secrets and /api/v1/dynamic-secrets/{name}/leases` — ephemeral credential leases - who checked out DB credentials and when (medium)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/canonical_descriptions.pyindex f1d0d80aea25..d5c8ee22fd94 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/canonical_descriptions.py@@ -172,4 +172,55 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {"updatedAt": "When the finding was last updated.",},},+ "project_environments": {+ "description": "Environments (e.g. dev, staging, prod) in each project. Use it to resolve the environment IDs and slugs that audit logs, secret syncs, and other tables reference.",+ "docs_url": "https://infisical.com/docs/api-reference/endpoints/environments/get",+ "columns": {+ "id": "Unique identifier for the environment.",+ "name": "Display name of the environment.",+ "slug": "URL-friendly slug of the environment, used in API paths and the CLI.",+ "position": "Order of the environment within the project.",+ "projectId": "ID of the project the environment belongs to.",+ "createdAt": "When the environment was created.",+ "updatedAt": "When the environment was last updated.",+ },+ },+ "project_identity_memberships": {+ "description": "Machine identity memberships per project: which machine identities can access which project and the roles they hold there. One row per identity-project membership across every project the machine identity can read.",+ "docs_url": "https://infisical.com/docs/documentation/platform/identities/overview",+ "columns": {+ "id": "Unique identifier for the project identity membership.",+ "identityId": "ID of the machine identity.",+ "identity": "Machine identity object with its ID, name, organization ID, and configured auth methods.",+ "project": "Project object with the project ID and name.",+ "roles": "Roles the identity holds in the project, including custom role details and temporary access windows.",+ "createdAt": "When the identity was added to the project.",+ "updatedAt": "When the membership was last updated.",+ },+ },+ "secret_syncs": {+ "description": "Secret syncs that push a project's secrets to an external destination such as AWS Secrets Manager, GitHub, or Vercel, with the status of their last sync, import, and remove jobs. One row per sync across every secrets management project the machine identity can read. Secret values are not included.",+ "docs_url": "https://infisical.com/docs/api-reference/endpoints/secret-syncs/list",+ "columns": {+ "id": "Unique identifier for the secret sync.",+ "name": "Name of the secret sync.",+ "description": "Description of the secret sync.",+ "destination": "Destination app the secrets are synced to (e.g. aws-secrets-manager, github, vercel).",+ "destinationConfig": "Destination-specific settings, such as the target region, repository, or path.",+ "isAutoSyncEnabled": "Whether secret changes are synced to the destination automatically.",+ "projectId": "ID of the project the secrets are synced from.",+ "environment": "Source environment object with its ID, name, and slug.",+ "folder": "Source folder object with its ID and path.",+ "connection": "App connection used to reach the destination, with its ID, name, and app.",+ "syncStatus": "Status of the most recent sync job (e.g. pending, running, succeeded, failed).",+ "lastSyncMessage": "Message from the most recent sync job, typically an error.",+ "lastSyncedAt": "When secrets were last synced to the destination.",+ "importStatus": "Status of the most recent import job.",+ "lastImportedAt": "When secrets were last imported from the destination.",+ "removeStatus": "Status of the most recent remove job.",+ "lastRemovedAt": "When secrets were last removed from the destination.",+ "createdAt": "When the secret sync was created.",+ "updatedAt": "When the secret sync was last updated.",+ },+ },}diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/infisical.py b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/infisical.pyindex 792a626c798a..3d6cb81e5e2b 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/infisical.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/infisical.py@@ -457,7 +457,7 @@ def validate_credentials(# they iterate instead.if config.fan_out_over == "groups":path = "/api/v1/groups"- elif config.fan_out_over == "projects":+ elif config.fan_out_over in ("projects", "environments"):path = "/api/v1/projects"else:path = _format_path(config.path, organization_id.strip())@@ -612,8 +612,10 @@ def _list_org_projects(client: InfisicalClient, organization_id: str) -> list[direturn [p for p in projects if p.get("orgId") == organization_id]-def _extract_rows(body: Any, data_key: str | None) -> list[dict[str, Any]]:+def _extract_rows(body: Any, data_key: str | None, single_object: bool = False) -> list[dict[str, Any]]:rows = body if data_key is None else (body.get(data_key) if isinstance(body, dict) else None)+ if single_object and isinstance(rows, dict):+ return [rows]return rows if isinstance(rows, list) else []@@ -645,7 +647,7 @@ def _get_fan_out_child_pages() -> Iterator[list[dict[str, Any]]]:if not config.paginated:_check_fan_out_budget(fan_out_deadline, config.name)- rows = _extract_rows(client.get(path, params).json(), config.data_key)+ rows = _extract_rows(client.get(path, params).json(), config.data_key, config.single_object)if rows:yield rowsreturn@@ -677,6 +679,15 @@ def _get_fan_out_rows(if config.fan_out_over == "groups":parents = _list_org_groups(client, organization_id)placeholder = "{group_id}"+ elif config.fan_out_over == "environments":+ parents = [+ {**env, "projectId": project["id"]}+ for project in _list_org_projects(client, organization_id)+ if project.get("id")+ for env in project.get("environments") or []+ if isinstance(env, dict)+ ]+ placeholder = "{environment_id}"else:parents = _list_org_projects(client, organization_id)if config.fan_out_project_type:@@ -709,6 +720,8 @@ def _get_fan_out_rows(continuepath = config.path.replace(placeholder, quote(str(parent_id), safe=""))+ if config.fan_out_over == "environments":+ path = path.replace("{project_id}", quote(str(parent["projectId"]), safe=""))params: dict[str, Any] = {config.parent_id_param: parent_id} if config.parent_id_param else {}yielded = Falsetry:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/settings.pyindex d832adab513e..579c7f44d21f 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/settings.py@@ -21,8 +21,9 @@ class InfisicalEndpointConfig:page_limit: int = 500# Extra query params sent on every request (e.g. an explicit stable sort).extra_params: dict[str, str] = field(default_factory=dict)- # Fan out over every project (`{project_id}`) or group (`{group_id}`) in the configured org.- fan_out_over: Literal["projects", "groups"] | None = None+ # Fan out over every project (`{project_id}`), group (`{group_id}`), or project environment+ # (`{project_id}` + `{environment_id}`) in the configured org.+ fan_out_over: Literal["projects", "groups", "environments"] | None = None# Only fan out over projects of this type, for endpoints that reject other project types.fan_out_project_type: str | None = None# Send the parent ID as this query param rather than as a path placeholder.@@ -32,6 +33,8 @@ class InfisicalEndpointConfig:# The endpoint is scoped by the access token's org rather than a path parameter, so an# identity in several orgs could see other orgs' rows. Keep only the configured org's rows.filter_by_org_id: bool = False+ # The response holds a single object under `data_key` rather than a list.+ single_object: bool = FalseINFISICAL_ENDPOINTS: dict[str, InfisicalEndpointConfig] = {@@ -131,6 +134,32 @@ INFISICAL_ENDPOINTS: dict[str, InfisicalEndpointConfig] = {fan_out_project_type="secret-scanning",parent_id_param="projectId",),+ # Project list entries embed only each environment's id, name, and slug, so fetch each one+ # for its position and timestamps.+ "project_environments": InfisicalEndpointConfig(+ name="project_environments",+ path="/api/v1/projects/{project_id}/environments/{environment_id}",+ data_key="environment",+ fan_out_over="environments",+ single_object=True,+ ),+ "project_identity_memberships": InfisicalEndpointConfig(+ name="project_identity_memberships",+ path="/api/v1/projects/{project_id}/identity-memberships",+ data_key="identityMemberships",+ paginated=True,+ page_limit=500,+ extra_params={"orderBy": "name", "orderDirection": "asc"},+ fan_out_over="projects",+ ),+ "secret_syncs": InfisicalEndpointConfig(+ name="secret_syncs",+ path="/api/v1/secret-syncs",+ data_key="secretSyncs",+ fan_out_over="projects",+ fan_out_project_type="secret-manager",+ parent_id_param="projectId",+ ),}ENDPOINTS = tuple(INFISICAL_ENDPOINTS.keys())diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/source.pyindex 619dad2e6653..c2e367df3774 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/source.py@@ -55,9 +55,9 @@ class InfisicalSource(ResumableSource[InfisicalSourceConfig, InfisicalResumeConfcategory=DataWarehouseSourceCategory.ENGINEERING___MONITORING,label="Infisical",releaseStatus=ReleaseStatus.ALPHA,- caption="""Connect an Infisical machine identity to pull your organization's audit logs, projects, identities, memberships, roles, groups, and secret scanning findings into the PostHog Data warehouse. Secret values are never synced.+ caption="""Connect an Infisical machine identity to pull your organization's audit logs, projects, environments, identities, memberships, roles, groups, secret syncs, and secret scanning findings into the PostHog Data warehouse. Secret values are never synced.-In Infisical, create a machine identity under **Organization settings > Access control > Identities**, add a **Universal Auth** method to it, and grant it read permissions for the data you want to sync (audit logs, projects, identities, memberships, roles, groups, and secret scanning findings). Note that audit log access and secret scanning are plan-gated on Infisical Cloud.+In Infisical, create a machine identity under **Organization settings > Access control > Identities**, add a **Universal Auth** method to it, and grant it read permissions for the data you want to sync (audit logs, projects, environments, identities, memberships, roles, groups, secret syncs, and secret scanning findings). Note that audit log access and secret scanning are plan-gated on Infisical Cloud.- **Base URL**: `https://app.infisical.com` (US cloud), `https://eu.infisical.com` (EU cloud), or your self-hosted URL.- **Organization ID**: found in your Infisical URL after `/org/`, or in organization settings.diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/tests/test_infisical.py b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/tests/test_infisical.pyindex 1aa3197970fc..8ff137927926 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/tests/test_infisical.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/infisical/tests/test_infisical.py@@ -351,24 +351,55 @@ class TestGroupMembersFanOut:assert [_query(u)["offset"] for u in urls[1:]] == [["0"], ["2"]]-class TestSecretScanningFindingsFanOut:- def test_only_secret_scanning_projects_are_queried_by_project_id(self):- # The findings endpoint rejects other project types with a 400, which would fail the sync.+class TestProjectTypeScopedFanOut:+ @pytest.mark.parametrize(+ "endpoint, project_type, path, data_key",+ [+ ("secret_scanning_findings", "secret-scanning", "/api/v2/secret-scanning/findings", "findings"),+ ("secret_syncs", "secret-manager", "/api/v1/secret-syncs", "secretSyncs"),+ ],+ )+ def test_only_matching_projects_are_queried_by_project_id(self, endpoint, project_type, path, data_key):+ # These endpoints reject other project types with a 400, which would fail the sync.+ projects = _response(+ json_data={+ "projects": [+ {"id": "p1", "orgId": "org-123", "type": "cert-manager"},+ {"id": "p2", "orgId": "org-123", "type": project_type},+ ]+ }+ )+ children = _response(json_data={data_key: [{"id": "c1", "projectId": "p2"}]})+ rows, session, _manager = _run_get_rows([_login_response(), projects, children], endpoint)++ assert [r["id"] for r in rows] == ["c1"]+ child_url = _get_urls(session)[1]+ assert urlparse(child_url).path == path+ assert _query(child_url) == {"projectId": ["p2"]}+++class TestProjectEnvironmentsFanOut:+ def test_fetches_each_embedded_environment_of_the_org_projects(self):projects = _response(json_data={"projects": [- {"id": "p1", "orgId": "org-123", "type": "secret-manager"},- {"id": "p2", "orgId": "org-123", "type": "secret-scanning"},+ {"id": "p1", "orgId": "org-123", "environments": [{"id": "e1"}, {"id": "e2"}]},+ {"id": "p2", "orgId": "other-org", "environments": [{"id": "e3"}]},+ {"id": "p3", "orgId": "org-123", "environments": []},]})- findings = _response(json_data={"findings": [{"id": "f1", "projectId": "p2"}]})- rows, session, _manager = _run_get_rows([_login_response(), projects, findings], "secret_scanning_findings")+ env1 = _response(json_data={"environment": {"id": "e1", "slug": "dev", "projectId": "p1"}})+ env2 = _response(status_code=404)+ rows, session, _manager = _run_get_rows([_login_response(), projects, env1, env2], "project_environments")- assert [r["id"] for r in rows] == ["f1"]- findings_url = _get_urls(session)[1]- assert urlparse(findings_url).path == "/api/v2/secret-scanning/findings"- assert _query(findings_url) == {"projectId": ["p2"]}+ # A single-object body becomes one row; an environment deleted mid-sync is skipped.+ assert rows == [{"id": "e1", "slug": "dev", "projectId": "p1"}]+ assert [urlparse(u).path for u in _get_urls(session)] == [+ "/api/v1/projects",+ "/api/v1/projects/p1/environments/e1",+ "/api/v1/projects/p1/environments/e2",+ ]class TestOrgScoping:@@ -676,12 +707,18 @@ class TestValidateCredentials:result, _session = self._run([_response(status_code=status_code)])assert result == (False, INVALID_CREDENTIALS_ERROR)- def test_scoped_probe_success(self):- result, session = self._run(- [_login_response(), _response(json_data={"auditLogs": []})], schema_name="audit_logs"- )+ @pytest.mark.parametrize(+ "schema_name, body, expected_path",+ [+ ("audit_logs", {"auditLogs": []}, "/api/v1/organization/audit-logs"),+ # Fan-out tables probe the parent list, never a path with unfilled placeholders.+ ("project_environments", {"projects": []}, "/api/v1/projects"),+ ],+ )+ def test_scoped_probe_success(self, schema_name, body, expected_path):+ result, session = self._run([_login_response(), _response(json_data=body)], schema_name=schema_name)assert result == (True, None)- assert "/api/v1/organization/audit-logs" in _get_urls(session)[0]+ assert urlparse(_get_urls(session)[0]).path == expected_pathdef test_scoped_probe_403_names_the_table(self):result, _session = self._run([_login_response(), _response(status_code=403)], schema_name="audit_logs")