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): add aws security hub remediation tables (#119188)

Tom Owers44ecb8e45cf0
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 43cef17c43c0..6515b3fe7046 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
@@ -1309,6 +1309,8 @@ Diffed against: <https://raw.githubusercontent.com/boto/botocore/develop/botocor
- [ ] `Security Hub V2 findings (GetFindingsV2, POST /findingsv2)` — analyze findings from the newer Security Hub surface that legacy CSPM GetFindings does not provide (high)
- [ ] `Security Hub V2 resources (GetResourcesV2, POST /resourcesv2)` — analyze resource risk and connect newer findings to a separate resource inventory (medium)
- [ ] `Insight results (GET /insights/results/{InsightArn+})` — import grouped finding counts for insights instead of only their filter definitions (medium)
+- [x] `Remediations (GetRemediationsV2, POST /GetRemediationsV2)` — prioritize the resource changes that resolve or reduce exposure findings (high)
+- [x] `Exposures by remediation (ListExposuresByRemediationV2, POST /ListExposuresByRemediationV2)` — connect each remediation target to the exposure findings it resolves or reduces (medium)
Note: The official SDK model verifies REST paths, list responses, and required parent identifiers. Existing tables cover legacy CSPM findings, standards, subscriptions, and custom insight definitions. Standards controls, finding history, and insight results require requests for each parent; V2 needs a separate schema design. Authentication, automation settings, connectors, export jobs, and write operations are excluded.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/aws_security_hub.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/aws_security_hub.py
index c75e7dd5f7c8..cf7408c598c6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/aws_security_hub.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/aws_security_hub.py
@@ -1,6 +1,7 @@
from __future__ import annotations
import re
+import json
import datetime as dt
from collections.abc import Iterator
from typing import TYPE_CHECKING, Any
@@ -21,6 +22,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.aws_securi
ERROR_MESSAGES,
SECURITY_HUB_API_VERSION,
SUBSCRIPTION_MESSAGE,
+ UNMODELED_OPERATION_PATHS,
SecurityHubEndpoint,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
@@ -93,8 +95,19 @@ class AwsSecurityHubClient:
),
)
+ def serialize(self, operation: str, payload: dict[str, Any]) -> dict[str, Any]:
+ if operation in self.model.operation_names:
+ return self.serializer.serialize_to_request(payload, self.model.operation_model(operation))
+ return {
+ "method": "POST",
+ "url_path": UNMODELED_OPERATION_PATHS[operation],
+ "query_string": {},
+ "headers": {"Content-Type": "application/json"},
+ "body": json.dumps(payload).encode(),
+ }
+
def request(self, operation: str, payload: dict[str, Any]) -> dict[str, Any]:
- serialized = self.serializer.serialize_to_request(payload, self.model.operation_model(operation))
+ serialized = self.serialize(operation, payload)
url = self.base_url + serialized["url_path"]
if serialized["query_string"]:
url += "?" + urlencode(serialized["query_string"], doseq=True)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/canonical_descriptions.py
index 8e01e8eb5eca..ced2023b524e 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/canonical_descriptions.py
@@ -114,4 +114,30 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"updated_at": "When the member account was last updated.",
},
},
+ "remediations": {
+ "description": "Remediation targets for Security Hub exposure findings. Each target is a change to a resource that resolves or reduces one or more exposure findings.",
+ "docs_url": "https://docs.aws.amazon.com/securityhub/1.0/APIReference/API_GetRemediationsV2.html",
+ "columns": {
+ "target_uid": "The unique identifier of the remediation target.",
+ "outcome": "How many associated exposure findings the fix resolves, reduces in severity, or leaves unchanged.",
+ "priority": "The priority of the remediation target: Critical, High, Medium, or Low.",
+ "remediation_summary": "The action to take, its description, whether the effect is immediate, post-remediation steps, and knowledge base articles.",
+ "resource": "The resource the remediation target applies to, with its account, region, type, and identifier.",
+ "status": "Whether the remediation target is New, Updated, or Resolved.",
+ "trait": "The type and title of the trait associated with the remediation target.",
+ "updated_at": "When the remediation target was last updated.",
+ },
+ },
+ "remediation_exposures": {
+ "description": "Exposure findings linked to each remediation target, and the effect the fix has on each finding.",
+ "docs_url": "https://docs.aws.amazon.com/securityhub/1.0/APIReference/API_ListExposuresByRemediationV2.html",
+ "columns": {
+ "target_uid": "The remediation target, which matches target_uid in the remediations table.",
+ "metadata_uid": "The identifier of the exposure finding, from the metadata.uid field of the finding.",
+ "title": "The title of the exposure finding.",
+ "previous_severity": "The severity of the exposure finding before the remediation target is resolved.",
+ "projected_severity": "The severity of the exposure finding after the remediation target is resolved.",
+ "impact": "Whether resolving the remediation target Resolves, Reduces, or leaves Unchanged the exposure finding.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/settings.py
index f74ee8c5a408..0ea1d713eb13 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/settings.py
@@ -56,6 +56,22 @@ ENDPOINTS: dict[str, SecurityHubEndpoint] = {
# The API defaults to enabled members only. Include invited and removed accounts too.
params=(("OnlyAssociated", False),),
),
+ "remediations": SecurityHubEndpoint(
+ operation="GetRemediationsV2", result_key="Items", primary_keys=("target_uid",)
+ ),
+ "remediation_exposures": SecurityHubEndpoint(
+ operation="ListExposuresByRemediationV2",
+ result_key="Items",
+ # One exposure finding can link to several remediation targets.
+ primary_keys=("target_uid", "metadata_uid"),
+ parent=("remediations", "TargetUid"),
+ ),
+}
+
+# The pinned botocore model predates these operations. Each one is a POST with only JSON body members.
+UNMODELED_OPERATION_PATHS = {
+ "GetRemediationsV2": "/GetRemediationsV2",
+ "ListExposuresByRemediationV2": "/ListExposuresByRemediationV2",
}
INCREMENTAL_FIELDS = {"findings": [incremental_field("updated_at")]}
@@ -68,6 +84,8 @@ ENDPOINT_DESCRIPTIONS = {
"security_control_definitions": "Security control definitions with titles, severity, and remediation guidance.",
"products": "Product integrations that can send findings to Security Hub, with vendor names and descriptions.",
"members": "Member accounts of the Security Hub administrator account and their relationship status.",
+ "remediations": "Remediation targets for exposure findings, sorted by priority, with their expected outcome and affected resource.",
+ "remediation_exposures": "Exposure findings linked to each remediation target, with severity before and after the fix.",
}
ACCESS_DENIED_CODES = frozenset({"AccessDenied", "AccessDeniedException", "InvalidAccessException"})
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/source.py
index 5dcddfa802c1..3c57bd68ca1c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/source.py
@@ -127,12 +127,13 @@ class AwsSecurityHubSource(ResumableSource[AwsSecurityHubSourceConfig, AwsSecuri
name=ExternalDataSourceType.AWSSECURITYHUB,
category=DataWarehouseSourceCategory.ENGINEERING___MONITORING,
label="AWS Security Hub",
- caption="""Sync Security Hub CSPM findings, standards, controls, product integrations, member accounts, and custom insights from the configured AWS region.
+ caption="""Sync Security Hub CSPM findings, standards, controls, product integrations, member accounts, custom insights, and exposure remediations from the configured AWS region.
-Grant `securityhub:GetFindings`, `securityhub:DescribeStandards`, `securityhub:GetEnabledStandards`, `securityhub:GetInsights`, `securityhub:DescribeStandardsControls`, `securityhub:ListSecurityControlDefinitions`, `securityhub:DescribeProducts`, and `securityhub:ListMembers` to the IAM user or role.
+Grant `securityhub:GetFindings`, `securityhub:DescribeStandards`, `securityhub:GetEnabledStandards`, `securityhub:GetInsights`, `securityhub:DescribeStandardsControls`, `securityhub:ListSecurityControlDefinitions`, `securityhub:DescribeProducts`, `securityhub:ListMembers`, `securityhub:GetRemediationsV2`, and `securityhub:ListExposuresByRemediationV2` to the IAM user or role.
Enter its access key ID and secret access key. Add a session token for temporary credentials.
Enable Security Hub CSPM in the selected region.
-If you select an aggregation region, AWS can also return findings from linked regions.""",
+If you select an aggregation region, AWS can also return findings from linked regions.
+The remediation tables need Security Hub with exposure findings in the selected region.""",
iconPath="/static/services/aws_security_hub.png",
docsUrl="https://posthog.com/docs/cdp/sources/aws-security-hub",
releaseStatus=ReleaseStatus.ALPHA,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/tests/test_aws_security_hub.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/tests/test_aws_security_hub.py
index 5202858983e0..0768407f66c5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/tests/test_aws_security_hub.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aws_security_hub/tests/test_aws_security_hub.py
@@ -90,6 +90,8 @@ def test_region_is_a_connection_host_field() -> None:
("DescribeStandards", "GET", "/standards"),
("GetEnabledStandards", "POST", "/standards/get"),
("GetInsights", "POST", "/insights/get"),
+ ("GetRemediationsV2", "POST", "/GetRemediationsV2"),
+ ("ListExposuresByRemediationV2", "POST", "/ListExposuresByRemediationV2"),
],
)
def test_signed_rest_requests(operation: str, method: str, path: str) -> None:
@@ -372,6 +374,39 @@ def test_standards_controls_fan_out_over_enabled_standards() -> None:
]
+def test_remediation_exposures_fan_out_over_remediation_targets() -> None:
+ exposure = {"MetadataUid": "shared-exposure", "Title": "Example exposure", "Impact": "Resolves"}
+ script = route(
+ {
+ "/GetRemediationsV2": [
+ ScriptedResponse(json={"Items": [{"TargetUid": "target-b"}], "NextToken": "p2"}),
+ ScriptedResponse(json={"Items": [{"TargetUid": "target-a"}]}),
+ ],
+ "/ListExposuresByRemediationV2": [
+ ScriptedResponse(json={"TargetUid": "target-a", "Items": [exposure], "NextToken": "e2"}),
+ ScriptedResponse(json={"TargetUid": "target-a", "Items": []}),
+ ScriptedResponse(json={"TargetUid": "target-b", "Items": [exposure]}),
+ ],
+ }
+ )
+ result = driver().run("remediation_exposures", script)
+ assert result.raised is None
+ assert result.response is not None
+ primary_keys = result.response.primary_keys
+ assert primary_keys
+ assert [tuple(row[key] for key in primary_keys) for row in result.rows] == [
+ ("target-a", "shared-exposure"),
+ ("target-b", "shared-exposure"),
+ ]
+ assert [request.json() for request in result.requests] == [
+ {"MaxResults": 100},
+ {"MaxResults": 100, "NextToken": "p2"},
+ {"MaxResults": 100, "TargetUid": "target-a"},
+ {"MaxResults": 100, "TargetUid": "target-a", "NextToken": "e2"},
+ {"MaxResults": 100, "TargetUid": "target-b"},
+ ]
+
+
@pytest.mark.parametrize("next_token", ["saved", None])
def test_standards_controls_resume_skips_finished_subscriptions(next_token: str | None) -> None:
script = route(