Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/scripts/public_release_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
SOURCE_RECEIPT_FILENAME = "public-release-publication-receipt.json"
OCTO_STS_DOMAIN = "webhooks.build.datadoghq.com"
OCTO_STS_AUDIENCE = "dd-octo-sts"
OCTO_STS_POOL_NAME = "dd-octo-sts"
VERSION_RE = re.compile(r"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$")
SHA256_RE = re.compile(r"^[0-9a-f]{64}$")
SOURCE_SHA_RE = re.compile(r"^[0-9a-f]{40}$")
Expand Down Expand Up @@ -1040,12 +1041,21 @@ def exchange_source_token(contract: dict[str, Any]) -> str:
{"Authorization": f"Bearer {oidc_request_token}"},
)
oidc_token = require_string(oidc.get("value"), "GitHub OIDC token")
source_repository = require_string(
contract["source_identity"]["repository"], "source repository"
)
source_parts = source_repository.split("/")
if len(source_parts) != 2 or not all(source_parts):
raise MirrorError("source repository must be an owner/repository pair")
source_owner, source_name = source_parts
exchange_url = (
f"https://{OCTO_STS_DOMAIN}/sts/exchange?"
f"https://{OCTO_STS_DOMAIN}/sts/pool/exchange?"
+ urllib.parse.urlencode(
{
"scope": contract["source_identity"]["repository"],
"identity": contract["source_identity"]["read_policy"],
"policy": contract["source_identity"]["read_policy"],
"pool_name": OCTO_STS_POOL_NAME,
"scope_repository.organization": source_owner,
"scope_repository.repository": source_name,
}
)
)
Expand Down
8 changes: 5 additions & 3 deletions tests/test_public_release_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,13 @@ def fake_request(url: str, headers: dict[str, str]) -> dict[str, str]:
self.assertEqual(calls[0][1]["Authorization"], "Bearer runner-token")
self.assertTrue(
calls[1][0].startswith(
"https://webhooks.build.datadoghq.com/sts/exchange?"
"https://webhooks.build.datadoghq.com/sts/pool/exchange?"
)
)
self.assertIn("scope=DataDog%2Ftrajectory", calls[1][0])
self.assertIn("identity=trajectory-labs.public-release-read", calls[1][0])
self.assertIn("policy=trajectory-labs.public-release-read", calls[1][0])
self.assertIn("pool_name=dd-octo-sts", calls[1][0])
self.assertIn("scope_repository.organization=DataDog", calls[1][0])
self.assertIn("scope_repository.repository=trajectory", calls[1][0])
self.assertEqual(calls[1][1]["Authorization"], "Bearer oidc-token")

def test_source_token_exchange_failure_reports_only_safe_identity_claims(self) -> None:
Expand Down