fix(ci): verify fresh Gitea upload attachment URLs
Linux / keyless-cuda-gate (pull_request) Skipped
Linux / verify (pull_request) Successful in 5m15s
Linux / keyless-cuda (pull_request) Skipped
Linux / static-cuda-package (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 2m16s
Linux / linux-static-cli (pull_request) Failing after 7m52s
Linux / release-cli (pull_request) Skipped

This commit is contained in:
Pavlo Ratushnyi
2026-10-07 21:01:07 +02:00
parent f015052247
commit aaa9ecc472
3 changed files with 93 additions and 7 deletions
+13 -1
View File
@@ -12,10 +12,22 @@ All profiles reject missing/extra files, symlinks, mismatched checksums and sour
CUDA publication validates current package `loader_probe` receipts from `--probe-in-runtime-image`, image/package receipt binding and canonical compile-feature digests. These producers do not emit the historical `engine_help_probe` strings; their existing loader/identity/help probes must pass for assembly to emit the current receipts. Hosted toolchain publication additionally binds the actual builder image identity, source, engine hash, compile-feature digest, runtime image identity and saved archive hash. The inactive static CUDA profile preserves its original six-file contract and has no hosted compiler or license receipt qualification. Its runner and build inputs are unchanged.
Publication creates a draft prerelease, streams the exact verified assets, checks response names/sizes, and rereads each exact same-origin repository/tag/asset download URL to compare size and SHA256. It allows at most two same-origin redirects, restricted to attachment paths for the UUID returned by that asset upload. Only then does it remove draft status. Other redirect paths, queries, credentials and foreign asset URLs are rejected; tokens are not forwarded to them. HTTPS verifies certificates; plaintext is accepted only for loopback API fixtures. API error bodies are not printed. An upload or verification failure leaves a draft, and does not publish an incomplete release. A retry uses a fresh run attempt tag; existing release cleanup is an operator action. Gitea previews do not inherit the former GitHub artifact seven-day retention; retention is an operator policy.
Publication creates a draft prerelease, streams the exact verified assets, checks response names/sizes, and validates the returned UUID before accepting either the exact same-origin repository/tag/asset download URL or one of the existing exact attachment paths for that UUID, then rereads the remote bytes to compare size and SHA256. It allows at most two same-origin redirects, restricted to attachment paths for the UUID returned by that asset upload. Only then does it remove draft status. Other redirect paths, queries, credentials and foreign asset URLs are rejected; tokens are not forwarded to them. HTTPS verifies certificates; plaintext is accepted only for loopback API fixtures. API error bodies are not printed. An upload or verification failure leaves a draft, and does not publish an incomplete release. A retry uses a fresh run attempt tag; existing release cleanup is an operator action. Gitea previews do not inherit the former GitHub artifact seven-day retention; retention is an operator policy.
Receipts record CI/operator-declared source identity, not binary-to-source attestation. GPU/model qualification stays false; these publications do not establish inference quality, throughput, model readiness or deployment readiness. Synthetic tests exercise API streaming, remote corruption, interrupted uploads, exact profiles, forged rehashed receipts and the current producer validators. Real private Gitea publication remains a workflow qualification gate.
The download URL profile was checked against read-only Gitea release `cuda-preview-2495-1` on git.vezha.io: `/para/leleka/releases/download/{tag}/{asset}`. Gitea 1.27.3 [RedirectDownload](https://raw.githubusercontent.com/go-gitea/gitea/v1.27.3/routers/web/repo/repo.go) finds releases by repository/tag and includes drafts for writers; it serves the associated attachment without requiring a Git tag to exist. Synthetic tests verify download and redirect hashing while the release is still draft and before tag publication, and prove that foreign redirects receive no request or token. Actual fresh CI publication remains unqualified until that gate succeeds.
Publication jobs request `contents: read` and the Gitea-specific `releases: write` permission on their built-in job token; the workflow default and nonpublication jobs keep read-only permissions. This follows the [Gitea 1.27 token-permission contract](https://docs.gitea.com/1.27/usage/actions/token-permissions/). Owner/repository maximums can still clamp the effective token; the real publication gate must succeed before qualification. No stored PAT is read or created.
Gitea 1.27.3 fresh-upload POST and later GET/list metadata can expose different
URLs. [Attachment.DownloadURL](https://raw.githubusercontent.com/go-gitea/gitea/v1.27.3/models/repo/attachment.go)
uses the instance attachment route when the freshly created attachment has no
custom URL; subsequent [release attribute loading](https://raw.githubusercontent.com/go-gitea/gitea/v1.27.3/models/repo/release.go) can populate the repository
release route when attachment names are unique. The publisher admits the same narrowly bound UUID attachment
routes at the initial hop as at redirect hops. Origin, port, path, UUID, query,
fragment, credentials, two-redirect bound, byte count and remote SHA checks remain
mandatory. Synthetic POST tests cover each admitted attachment form, corruption,
invalid/mismatched UUIDs, foreign URLs and wrong repositories without forwarding
a token. This source-derived correction is not proof of fresh private CI publication;
that remains an actual workflow gate.
+4 -3
View File
@@ -272,13 +272,13 @@ def validate_download_url(parts, url, allowed_paths):
def verify_uploaded_asset(parts, token, metadata, expected, repository, tag):
# Gitea returns a release route, which can redirect to the same asset UUID.
# Gitea POST may return the UUID attachment route; later reads may return
# the exact release route. Both are bound to the same uploaded asset.
# Validate every hop before sending a scoped token; never follow foreign URLs.
base_path = parts.path.rstrip('/').removesuffix('/api/v1')
repo_path = base_path + '/' + repository
release_path = f"{repo_path}/releases/download/{tag}/{metadata['name']}"
url = metadata.get('browser_download_url')
validate_download_url(parts, url, {release_path})
attachment = metadata.get('uuid')
if not isinstance(attachment, str) or not re.fullmatch(
r'[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}', attachment):
@@ -286,8 +286,9 @@ def verify_uploaded_asset(parts, token, metadata, expected, repository, tag):
attachment_paths = {f'{base_path}/attachments/{attachment}',
f'{repo_path}/attachments/{attachment}',
f'{repo_path}/releases/attachments/{attachment}'}
initial_paths = {release_path} | attachment_paths
for hop in range(3):
asset_url = validate_download_url(parts, url, {release_path} if hop == 0 else attachment_paths)
asset_url = validate_download_url(parts, url, initial_paths if hop == 0 else attachment_paths)
conn = connection(parts)
try:
conn.request('GET', asset_url.path, headers={'Authorization': f'token {token}'})
+76 -3
View File
@@ -197,12 +197,18 @@ class FakeGitea(BaseHTTPRequestHandler):
tag = self.server.release_payload['tag_name']
release_path = f'/owner/repo/releases/download/{tag}/{name}'
self.server.release_paths[release_path] = attachment
initial_path = {
None: release_path,
'attachment': f'/attachments/{attachment}',
'repo-attachment': f'/owner/repo/attachments/{attachment}',
'repo-release-attachment': f'/owner/repo/releases/attachments/{attachment}',
}[self.server.initial_attachment_route]
if self.server.wrong_download:
release_path = release_path.replace(*self.server.wrong_download)
download = f'http://127.0.0.1:{self.server.server_port}{release_path}'
initial_path = initial_path.replace(*self.server.wrong_download)
download = f'http://127.0.0.1:{self.server.server_port}{initial_path}'
if self.server.foreign_download:
download = 'https://foreign.invalid/attachments/id'
return self.send_json(201, {'name': name, 'size': size, 'browser_download_url': download, 'uuid': attachment})
return self.send_json(201, {'name': name, 'size': size, 'browser_download_url': download, 'uuid': self.server.uuid_override if self.server.uuid_override is not None else attachment})
self.send_json(404, {'message': 'unexpected route'})
def do_GET(self):
@@ -279,6 +285,8 @@ class PublisherTests(unittest.TestCase):
self.server.current_draft = True
self.server.tag_exists = False
self.server.wrong_download = None
self.server.initial_attachment_route = None
self.server.uuid_override = None
self.server.redirect_mode = None
self.server.foreign_url = 'http://foreign.invalid'
self.server.foreign_download = False
@@ -648,6 +656,71 @@ class PublisherTests(unittest.TestCase):
self.assertTrue(self.server.release_payload['draft'])
self.assertIsNone(self.server.finalize_payload)
def test_fresh_post_attachment_routes_verify_remote_bytes_before_finalizing(self):
for mode in ('attachment', 'repo-attachment', 'repo-release-attachment'):
with self.subTest(mode=mode):
self.server.initial_attachment_route = mode
self.server.gets = []
self.server.get_states = []
result = publisher.publish(self.api_url, 'owner/repo', TOKEN, 'cuda-preview-42-1', REVISION,
'title', 'notes', self.directory)
self.assertEqual(len(result['assets']), 8)
self.assertEqual(len(self.server.gets), 8)
self.assertEqual(self.server.get_states, [(True, False)] * 8)
self.assertTrue(all('/attachments/' in path for path, _auth in self.server.gets))
self.assertTrue(all(auth == f'token {TOKEN}' for _path, auth in self.server.gets))
for asset in result['assets']:
self.assertEqual(asset['sha256'], hashlib.sha256(
(self.directory / asset['name']).read_bytes()).hexdigest())
self.assertEqual(self.server.finalize_payload, {'draft': False})
def test_fresh_post_attachment_remote_corruption_leaves_draft(self):
self.server.initial_attachment_route = 'attachment'
self.server.corrupt_download = True
with self.assertRaisesRegex(ValueError, 'checksum mismatch'):
publisher.publish(self.api_url, 'owner/repo', TOKEN, 'cuda-preview-42-1', REVISION,
'title', 'notes', self.directory)
self.assertEqual(len(self.server.gets), 1)
self.assertTrue(self.server.current_draft)
self.assertIsNone(self.server.finalize_payload)
def test_fresh_post_attachment_untrusted_routes_receive_no_token(self):
for mode, substitution in (
('attachment', ('/attachments/', '/attachments/00000000-0000-0000-0000-000000000000/')),
('repo-attachment', ('/owner/repo/', '/owner/other/')),
('repo-release-attachment', ('/owner/repo/', '/other/repo/')),
('attachment', ('/attachments/', '/attachments/?token=synthetic&uuid=')),
('attachment', ('/attachments/', '/attachments/#'))):
with self.subTest(mode=mode, substitution=substitution):
self.server.initial_attachment_route = mode
self.server.wrong_download = substitution
self.server.gets = []
with self.assertRaisesRegex(ValueError, 'same-origin'):
publisher.publish(self.api_url, 'owner/repo', TOKEN, 'cuda-preview-42-1', REVISION,
'title', 'notes', self.directory)
self.assertEqual(self.server.gets, [])
self.assertIsNone(self.server.finalize_payload)
self.server.wrong_download = None
self.server.foreign_download = True
self.server.gets = []
with self.assertRaisesRegex(ValueError, 'same-origin'):
publisher.publish(self.api_url, 'owner/repo', TOKEN, 'cuda-preview-42-1', REVISION,
'title', 'notes', self.directory)
self.assertEqual(self.server.gets, [])
self.assertIsNone(self.server.finalize_payload)
def test_fresh_post_requires_valid_matching_uuid_before_download(self):
self.server.initial_attachment_route = 'attachment'
for attachment in ('not-a-uuid', '', 73, '00000000-0000-0000-0000-000000000000'):
with self.subTest(attachment=attachment):
self.server.uuid_override = attachment
self.server.gets = []
with self.assertRaises(ValueError):
publisher.publish(self.api_url, 'owner/repo', TOKEN, 'cuda-preview-42-1', REVISION,
'title', 'notes', self.directory)
self.assertEqual(self.server.gets, [])
self.assertIsNone(self.server.finalize_payload)
def test_initial_download_url_requires_exact_repository_tag_and_asset(self):
for substitution in (('/owner/repo/', '/owner/other/'),
('cuda-preview-42-1', 'cuda-preview-43-1'),