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.

fix(signals): send bucket-owner-full-control on inbox ranking mirror writes (#117999)

posthog[bot]a04a927869a4
diff --git a/products/signals/dags/inbox_ranking/common.py b/products/signals/dags/inbox_ranking/common.py
index 31386b11fe0a..f5ed0a3c1f8f 100644
--- a/products/signals/dags/inbox_ranking/common.py
+++ b/products/signals/dags/inbox_ranking/common.py
@@ -113,7 +113,7 @@ def skip_unconfigured(context: dagster.AssetExecutionContext) -> bool:
# boto3.client("s3") is left untyped on purpose: mypy and pyright resolve it to different stub
# packages (mypy_boto3_s3 vs types_boto3_s3), so a concrete S3Client annotation can't satisfy both.
def s3_client(): # noqa: ANN201
- # The dedicated bucket is reached via ambient AWS config (the node role on prod). Without it,
+ # The dedicated bucket is reached via ambient AWS config (the `dagster` IRSA role on prod). Without it,
# every other environment (local dev, self-hosted, CI) uses the deployment's object-storage
# service, which needs its explicit endpoint and credentials regardless of DEBUG.
if settings.INBOX_RANKING_DATASET_S3_BUCKET:
diff --git a/products/signals/dags/inbox_ranking/tests/test_training.py b/products/signals/dags/inbox_ranking/tests/test_training.py
index c3fae4c1a0c2..ba555ea73176 100644
--- a/products/signals/dags/inbox_ranking/tests/test_training.py
+++ b/products/signals/dags/inbox_ranking/tests/test_training.py
@@ -2789,6 +2789,7 @@ class _AppObjectStore:
self.objects = dict(existing or {})
self.fail_on = fail_on
self.written: list[str] = []
+ self.extras: dict[str, dict[str, str] | None] = {}
def head_object(self, bucket: str, file_key: str) -> dict[str, int] | None:
return {"ContentLength": len(self.objects[file_key])} if file_key in self.objects else None
@@ -2798,6 +2799,7 @@ class _AppObjectStore:
raise RuntimeError("object store write failed")
self.objects[key] = content if isinstance(content, bytes) else content.encode()
self.written.append(key)
+ self.extras[key] = extras
def _serving_dataset_s3(
@@ -2884,9 +2886,12 @@ def test_publishing_copies_every_model_the_manifest_names_and_writes_the_manifes
assert f"{entry.prefix}/{METADATA_FILE}" in store.objects
assert f"{entry.prefix}/{model_file}" in store.objects
assert store.written[-1] == serving_manifest_key(prefix)
+ assert all("ACL" not in (extras or {}) for extras in store.extras.values())
if mirror is not None:
assert mirror.objects == store.objects
assert mirror.written[-1] == serving_manifest_key(prefix)
+ # The mirror bucket is in another account, and its policy refuses a write without this ACL.
+ assert all((extras or {}).get("ACL") == "bucket-owner-full-control" for extras in mirror.extras.values())
assert _manifest_event(capture).get("mirror_published") is (True if mirrored else None)
diff --git a/products/signals/dags/inbox_ranking/training/dag.py b/products/signals/dags/inbox_ranking/training/dag.py
index 96f986639f74..7135caf13575 100644
--- a/products/signals/dags/inbox_ranking/training/dag.py
+++ b/products/signals/dags/inbox_ranking/training/dag.py
@@ -915,6 +915,16 @@ SERVING_MANIFEST_ASSET = "inbox_ranking_serving_manifest"
class _ServingStore:
storage: "ObjectStorageClient"
bucket: str
+ # A cross-account bucket refuses a write that does not hand ownership to the bucket owner.
+ acl: str | None = None
+
+ def write(self, key: str, content: str | bytes, content_type: str | None = None) -> None:
+ extras: dict[str, str] = {}
+ if content_type is not None:
+ extras["ContentType"] = content_type
+ if self.acl is not None:
+ extras["ACL"] = self.acl
+ self.storage.write(bucket=self.bucket, key=key, content=content, extras=extras or None)
@dagster.asset(name=SERVING_MANIFEST_ASSET, deps=["inbox_ranking_model_champion"], **COMMON_ASSET_KWARGS)
@@ -1111,7 +1121,11 @@ def _publish_mirror(
)
return False
try:
- mirror = _ServingStore(storage=serving_mirror_storage(), bucket=settings.INBOX_RANKING_SERVING_MIRROR_BUCKET)
+ mirror = _ServingStore(
+ storage=serving_mirror_storage(),
+ bucket=settings.INBOX_RANKING_SERVING_MIRROR_BUCKET,
+ acl="bucket-owner-full-control",
+ )
publish_serving_models(
context, client, bucket, prefix, manifest.model_copy(update={"project_vectors": None}), mirror
)
@@ -1163,7 +1177,7 @@ def publish_serving_models(
)
if body is None:
raise dagster.Failure(f"{entry.key} is missing {name} in the dataset bucket; manifest not written")
- target.storage.write(bucket=target.bucket, key=f"{entry.prefix}/{name}", content=body, extras=None)
+ target.write(f"{entry.prefix}/{name}", body)
bytes_copied += len(body)
copied.append(entry.key)
context.log.info(f"copied {entry.key} to {target.bucket}/{entry.prefix}")
@@ -1171,12 +1185,7 @@ def publish_serving_models(
bytes_copied += _publish_project_vectors(
context, client, bucket, project_vectors_source, manifest.project_vectors, target
)
- target.storage.write(
- bucket=target.bucket,
- key=serving_manifest_key(prefix),
- content=manifest.model_dump_json(indent=2),
- extras={"ContentType": "application/json"},
- )
+ target.write(serving_manifest_key(prefix), manifest.model_dump_json(indent=2), content_type="application/json")
return _ModelPublication(copied=copied, present=present, bytes_copied=bytes_copied)
@@ -1197,7 +1206,7 @@ def _publish_project_vectors(
body = None if source is None else _read_bytes_if_exists(client, bucket, source)
if body is None:
raise dagster.Failure(f"project vectors {source} are missing in the dataset bucket; manifest not written")
- target.storage.write(bucket=target.bucket, key=target_key, content=body, extras=None)
+ target.write(target_key, body)
context.log.info(f"copied project vectors to {target.bucket}/{target_key}")
return len(body)