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(data-warehouse): add 3 missing tables to the Gitguardian source (#118960)

Tom Owersaf2d4b02532b
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 c9266966cb43..3abaebd3d332 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
@@ -5240,7 +5240,7 @@ Note: Source is single-repo scoped ({repository} = owner/repo) and already has w
## Gitguardian — gaps
-Today (10): `honeytoken_events`, `honeytokens`, `members`, `secret_detectors`, `secret_incident_activity_logs`, `secret_incidents`, `secret_occurrences`, `sources`, `team_memberships`, `teams`
+Today (13): `audit_logs`, `custom_tags`, `honeytoken_events`, `honeytokens`, `members`, `public_secret_incidents`, `secret_detectors`, `secret_incident_activity_logs`, `secret_incidents`, `secret_occurrences`, `sources`, `team_memberships`, `teams`
Diffed against: <https://api.gitguardian.com/v1/openapi.json>
@@ -5249,9 +5249,9 @@ Diffed against: <https://api.gitguardian.com/v1/openapi.json>
- [x] `/v1/honeytokens_events` — honeytoken trigger events across the org; honeytokens are synced but the events they exist to capture are not (high)
- [x] `/v1/teams/{team_id}/team_memberships` — join table between the members and teams we already sync (high)
- [ ] `/v1/incidents/secrets/{incident_id}/notes` — analyst remediation notes attached to each incident (medium)
-- [ ] `/v1/custom_tags` — lookup resolving the custom tag IDs applied to incidents (medium)
-- [ ] `/v1/audit_logs` — org-wide audit trail of who changed what in GitGuardian (medium)
-- [ ] `/v1/public-incidents/secrets` — publicly leaked secrets — a separate perimeter from internal incidents, with its own severity picture (medium)
+- [x] `/v1/custom_tags` — lookup resolving the custom tag IDs applied to incidents (medium)
+- [x] `/v1/audit_logs` — org-wide audit trail of who changed what in GitGuardian (medium)
+- [x] `/v1/public-incidents/secrets` — publicly leaked secrets — a separate perimeter from internal incidents, with its own severity picture (medium)
- [ ] `/v1/teams/{team_id}/sources` — join table mapping the sources we sync to owning teams (medium)
- [ ] `/v1/incidents/secrets/{incident_id}/leaks` — where each secret surfaced publicly, the exposure dimension of an incident (medium)
- [ ] `/v1/public-perimeter/developers` — developers associated with public leaks, for per-developer exposure reporting (low)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/canonical_descriptions.py
index 95bd847e4f72..a6fb347284d7 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/canonical_descriptions.py
@@ -165,4 +165,53 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"resolved_incidents_count": "Number of resolved secret incidents on the workspace for this detector.",
},
},
+ "custom_tags": {
+ "description": "A custom tag (key/value pair) defined in the workspace and applied to incidents to organize them.",
+ "docs_url": "https://api.gitguardian.com/docs#tag/Custom-Tags",
+ "columns": {
+ "id": "Unique identifier of the custom tag. Incidents reference this id in their custom_tags.",
+ "key": "Key of the custom tag (e.g. env).",
+ "value": "Value of the custom tag (e.g. prod). Can be null for a key-only tag.",
+ },
+ },
+ "audit_logs": {
+ "description": "One entry in the workspace audit trail: an event performed by a member or an API token, such as a login or a settings change.",
+ "docs_url": "https://api.gitguardian.com/docs#tag/Audit-Logs",
+ "columns": {
+ "id": "Unique identifier of the audit log entry.",
+ "date": "Date and time the event happened.",
+ "member_id": "Identifier of the member who performed the event. Null if the member was deleted since.",
+ "member_name": "Name of the member at the time of the event.",
+ "member_email": "Email of the member at the time of the event.",
+ "api_token_id": "Identifier of the API token used for the event, if it was performed through the API.",
+ "ip_address": "IP address the event came from.",
+ "target_ids": "Identifiers of the objects the event acted on.",
+ "action_type": "Type of action (e.g. CREATE, READ, UPDATE, DELETE, OTHER).",
+ "event_name": "Name of the event (e.g. user.logged_in).",
+ "data": "Additional data associated with the event.",
+ },
+ },
+ "public_secret_incidents": {
+ "description": "A public secret incident: a secret linked to your organization that GitGuardian found leaked in public sources, with its triage status and remediation timeline.",
+ "docs_url": "https://api.gitguardian.com/docs#tag/Public-Secret-Incidents",
+ "columns": {
+ "id": "Unique identifier of the public incident.",
+ "date": "Date and time the secret was first detected. Immutable.",
+ "detector": "Detector that matched the secret (name, family, detector group).",
+ "secret_hash": "Hash of the detected secret, used to group occurrences of the same secret.",
+ "occurrences_count": "Number of times the secret occurs in public sources.",
+ "status": "Triage status of the incident (IGNORED, TRIGGERED, ASSIGNED, RESOLVED).",
+ "triggered_at": "Date and time the incident was triggered.",
+ "ignored_at": "Date and time the incident was ignored, if it was.",
+ "resolved_at": "Date and time the incident was resolved, if it was.",
+ "secret_revoked": "Whether the secret was revoked as part of remediation.",
+ "severity": "Severity assigned to the incident (critical, high, medium, low, info, unknown).",
+ "validity": "Whether the secret is still valid against its service (valid, invalid, failed_to_check, no_checker, unknown).",
+ "assignee_id": "Identifier of the workspace member the incident is assigned to.",
+ "gitguardian_url": "Link to the incident in the GitGuardian dashboard.",
+ "tags": "Tags attached to the incident.",
+ "custom_tags": "Custom tags attached to the incident; resolve them with the custom_tags table.",
+ "risk_score": "Risk score of the incident, from 0 (low) to 100 (critical). Null when not yet computed.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/gitguardian.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/gitguardian.py
index 93d97dba3ab4..3267943b9fbd 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/gitguardian.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/gitguardian.py
@@ -340,9 +340,9 @@ def gitguardian_source(
incremental_field=incremental_field,
),
primary_keys=endpoint_config.primary_keys,
- # Incremental endpoints request `ordering=date` explicitly, so rows arrive oldest-first
+ # Most incremental endpoints request `ordering=date` explicitly, so rows arrive oldest-first
# and the incremental watermark can checkpoint per batch.
- sort_mode="asc",
+ sort_mode=endpoint_config.sort_mode,
partition_count=1,
partition_size=1,
partition_mode="datetime" if endpoint_config.partition_key else None,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/settings.py
index 900057af6b1b..a382f3549acc 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/settings.py
@@ -1,7 +1,7 @@
from collections.abc import Set as AbstractSet
from dataclasses import dataclass, field
from datetime import timedelta
-from typing import Optional
+from typing import Literal, Optional
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
@@ -18,6 +18,9 @@ class GitGuardianEndpointConfig:
# Explicit `ordering` param so pagination walks a stable monotonic field; must match the
# endpoint's SourceResponse sort_mode (asc).
ordering: Optional[str] = None
+ # "desc" for incremental endpoints with no `ordering` param: the pipeline then promotes the
+ # watermark only when the sync completes, so it never depends on the API's row order.
+ sort_mode: Literal["asc", "desc"] = "asc"
page_size: int = 100 # GitGuardian caps per_page at 100
primary_keys: list[str] = field(default_factory=lambda: ["id"])
should_sync_default: bool = True
@@ -162,6 +165,46 @@ GITGUARDIAN_ENDPOINTS: dict[str, GitGuardianEndpointConfig] = {
required_scope="incidents:read",
incremental_fields=[],
),
+ # Custom tags: small key/value lookup resolving the custom tag ids applied to incidents. No
+ # timestamps or time filter, so full refresh.
+ "custom_tags": GitGuardianEndpointConfig(
+ name="custom_tags",
+ path="/v1/custom_tags",
+ required_scope="custom_tags:read",
+ incremental_fields=[],
+ ),
+ # Audit logs: immutable, org-wide trail of workspace events. The endpoint accepts a
+ # server-side `date_after` filter but no `ordering` param and documents no default order, so
+ # the response is declared desc. Off by default because the `audit_logs:read` scope is not
+ # granted to every token.
+ "audit_logs": GitGuardianEndpointConfig(
+ name="audit_logs",
+ path="/v1/audit_logs",
+ default_incremental_field="date",
+ partition_key="date",
+ sort_mode="desc",
+ required_scope="audit_logs:read",
+ resumable=True,
+ should_sync_default=False,
+ incremental_fields=_DATE_INCREMENTAL_FIELD,
+ ),
+ # Public secret incidents: secrets leaked on public GitHub, a perimeter separate from the
+ # internal incidents. Same `date_after` + `ordering=date` semantics and mutable triage fields
+ # as `secret_incidents`, hence the same lookback. Off by default because it needs the Public
+ # Monitoring product.
+ "public_secret_incidents": GitGuardianEndpointConfig(
+ name="public_secret_incidents",
+ path="/v1/public-incidents/secrets",
+ default_incremental_field="date",
+ partition_key="date",
+ ordering="date",
+ required_scope="incidents:read",
+ incremental_lookback=timedelta(days=7),
+ resumable=True,
+ should_sync_default=False,
+ excluded_fields=frozenset({"share_url"}),
+ incremental_fields=_DATE_INCREMENTAL_FIELD,
+ ),
}
ENDPOINTS = tuple(GITGUARDIAN_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/source.py
index 3ef80898b6ed..6c14e37af499 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/source.py
@@ -60,9 +60,9 @@ class GitguardianSource(ResumableSource[GitguardianSourceConfig, GitGuardianResu
category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
label="GitGuardian",
releaseStatus=ReleaseStatus.ALPHA,
- caption="""Enter a GitGuardian API token to sync your secret incidents, occurrences, incident activity logs, secret detectors, monitored sources, honeytokens, honeytoken events, members, teams, and team memberships into the PostHog Data warehouse.
+ caption="""Enter a GitGuardian API token to sync your secret incidents, public secret incidents, occurrences, incident activity logs, secret detectors, custom tags, monitored sources, honeytokens, honeytoken events, members, teams, team memberships, and audit logs into the PostHog Data warehouse.
-Create a service account token (recommended for unattended syncs) or a personal access token in your [GitGuardian API settings](https://dashboard.gitguardian.com/api). Grant the read scopes for the tables you want to sync: `incidents:read`, `sources:read`, `honeytokens:read`, `members:read`, and `teams:read`. Reading incidents requires a token with at least the Manager access level.
+Create a service account token (recommended for unattended syncs) or a personal access token in your [GitGuardian API settings](https://dashboard.gitguardian.com/api). Grant the read scopes for the tables you want to sync: `incidents:read`, `custom_tags:read`, `sources:read`, `honeytokens:read`, `members:read`, `teams:read`, and `audit_logs:read`. Reading incidents requires a token with at least the Manager access level.
Workspaces on the EU instance should set the API URL to `https://api.eu1.gitguardian.com`; self-hosted instances should enter their own API URL.
""",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/tests/test_gitguardian.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/tests/test_gitguardian.py
index 027094e3a277..fc1df6b0245a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/tests/test_gitguardian.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitguardian/tests/test_gitguardian.py
@@ -96,6 +96,38 @@ class TestLinkHeaderPagination:
assert result.raised is None
assert result.params("date_after") == [expected]
+ @parameterized.expand(
+ [
+ # Mutable triage fields: re-pull a 7-day trailing window, walking the detection date.
+ ("secret_incidents", "/v1/incidents/secrets", "2026-01-03T00:00:00Z", "date"),
+ ("public_secret_incidents", "/v1/public-incidents/secrets", "2026-01-03T00:00:00Z", "date"),
+ # Immutable rows and no `ordering` param on the API: exact watermark, no ordering sent.
+ ("audit_logs", "/v1/audit_logs", "2026-01-10T00:00:00Z", None),
+ ]
+ )
+ def test_incremental_request_shaping(
+ self, endpoint: str, path: str, expected_date_after: str, expected_ordering: str | None
+ ) -> None:
+ result = _driver().run(
+ endpoint,
+ [_page([{"id": 1}])],
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=datetime(2026, 1, 10),
+ )
+ assert result.raised is None
+ assert result.paths == [path]
+ assert result.params("date_after") == [expected_date_after]
+ assert result.params("ordering") == [expected_ordering]
+
+ @parameterized.expand([("secret_incidents",), ("public_secret_incidents",)])
+ def test_share_url_bearer_link_is_stripped(self, endpoint: str) -> None:
+ result = _driver().run(
+ endpoint,
+ [_page([{"id": 1, "share_url": "https://dashboard.example.com/share/fake-token", "severity": "high"}])],
+ )
+ assert result.raised is None
+ assert result.rows == [{"id": 1, "severity": "high"}]
+
def test_cross_origin_next_link_is_refused(self) -> None:
# Pagination URLs are fetched with the Authorization token attached; a tampered Link
# header must not be able to steer the token to another host.
@@ -172,6 +204,25 @@ class TestResumeCheckpoints:
assert "cross-origin" in str(result.raised)
assert result.requests == []
+ @parameterized.expand(
+ [
+ ("public_secret_incidents", "/v1/public-incidents/secrets"),
+ ("audit_logs", "/v1/audit_logs"),
+ ]
+ )
+ def test_incremental_endpoints_resume_from_the_saved_page(self, endpoint: str, path: str) -> None:
+ saved_url = f"{BASE_URL}{path}?cursor=c2&per_page=100"
+ result = _driver().run(
+ endpoint,
+ [_page([{"id": 2}])],
+ resume_state=GitGuardianResumeConfig(url=saved_url),
+ )
+ assert result.raised is None
+ assert result.urls == [saved_url]
+ assert result.rows == [{"id": 2}]
+ assert result.saved_states == [GitGuardianResumeConfig(url=saved_url)]
+ assert result.final_state is None
+
def test_full_refresh_endpoints_never_checkpoint(self) -> None:
# sources/members/teams merge nothing on resume, so a restart re-reads from page one.
previous = GitGuardianResumeConfig(url=f"{BASE_URL}/v1/sources?cursor=old")
@@ -222,6 +273,8 @@ class TestCheckEndpointAccess:
("secret_incidents", "incidents:read"),
("sources", "sources:read"),
("honeytokens", "honeytokens:read"),
+ ("custom_tags", "custom_tags:read"),
+ ("audit_logs", "audit_logs:read"),
]
)
def test_denial_without_detail_names_the_required_scope(self, endpoint: str, scope: str) -> None:
@@ -291,21 +344,24 @@ class TestFetchPageRetries:
class TestSourceResponseShape:
@parameterized.expand(
[
- ("secret_incidents", ["date"]),
- ("secret_occurrences", ["date"]),
+ ("secret_incidents", ["date"], "asc"),
+ ("secret_occurrences", ["date"], "asc"),
+ ("public_secret_incidents", ["date"], "asc"),
+ # No `ordering` param, so the watermark must only be promoted when the sync completes.
+ ("audit_logs", ["date"], "desc"),
]
)
def test_incremental_endpoints_partition_on_stable_detection_date(
- self, endpoint: str, expected_partition: list[str]
+ self, endpoint: str, expected_partition: list[str], expected_sort_mode: str
) -> None:
result = _driver().run(endpoint, [_page([])])
assert result.raised is None
assert result.response is not None
assert result.response.partition_keys == expected_partition
assert result.response.primary_keys == ["id"]
- assert result.response.sort_mode == "asc"
+ assert result.response.sort_mode == expected_sort_mode
- @parameterized.expand([("sources",), ("honeytokens",), ("members",), ("teams",)])
+ @parameterized.expand([("sources",), ("honeytokens",), ("members",), ("teams",), ("custom_tags",)])
def test_full_refresh_endpoints_are_unpartitioned(self, endpoint: str) -> None:
result = _driver().run(endpoint, [_page([])])
assert result.raised is None