Unverified Commit a1836169 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[ci] Use presigned URLs to upload preview builds (#97922)

Follow-up to #97256, pairing with
[vercel/vercel-packages#107](https://github.com/vercel/vercel-packages/pull/107).
The token exchange endpoint no longer returns a client-upload token
derived from a store read-write token; it presigns the upload URL with
the deployment's own Vercel OIDC identity and returns the URL, pinning
the pathname, expiry, size cap, and access and overwrite policy
server-side. No store credential exists anywhere after this lands, and
no Blob SDK is needed here for the new path — the script PUTs the
tarball bytes to the URL directly.

The client only uses presigned-URL. The server still supports client
tokens until we landed this and synced the mirror.
Co-authored-by: 's avatarClaude Code (kimi-k3[1m]) <noreply@anthropic.com>
parent f6c48e19
...@@ -67,5 +67,4 @@ jobs: ...@@ -67,5 +67,4 @@ jobs:
github.event.workflow_run.head_sha }}" "${{ runner.temp github.event.workflow_run.head_sha }}" "${{ runner.temp
}}/preview-tarballs" }}/preview-tarballs"
env: env:
BLOB_ACCESS: ${{ vars.PREVIEW_BUILDS_ACCESS }}
PREVIEW_BUILDS_BASE_URL: ${{ vars.PREVIEW_BUILDS_BASE_URL }} PREVIEW_BUILDS_BASE_URL: ${{ vars.PREVIEW_BUILDS_BASE_URL }}
// @ts-check // @ts-check
const { put } = require('@vercel/blob/client')
const fs = require('node:fs/promises') const fs = require('node:fs/promises')
const path = require('node:path') const path = require('node:path')
...@@ -116,12 +115,6 @@ async function main() { ...@@ -116,12 +115,6 @@ async function main() {
) )
} }
const blobAccess = process.env.BLOB_ACCESS
if (blobAccess !== 'private' && blobAccess !== 'public') {
throw new Error(
`BLOB_ACCESS environment variable can only be "private" or "public" but got "${blobAccess}".`
)
}
const baseUrl = const baseUrl =
process.env.PREVIEW_BUILDS_BASE_URL || DEFAULT_PREVIEW_BUILDS_BASE_URL process.env.PREVIEW_BUILDS_BASE_URL || DEFAULT_PREVIEW_BUILDS_BASE_URL
const getOidcToken = createGitHubOidcTokenGetter() const getOidcToken = createGitHubOidcTokenGetter()
...@@ -129,8 +122,8 @@ async function main() { ...@@ -129,8 +122,8 @@ async function main() {
for await (const { packageName, tarballPath } of findTarballs( for await (const { packageName, tarballPath } of findTarballs(
tarballDirectory tarballDirectory
)) { )) {
// vercel-packages authorizes the OIDC token and answers with a client // vercel-packages authorizes the OIDC token and answers with a presigned
// token scoped to this exact blob path. The bytes then flow directly to // upload URL scoped to this exact blob path. The bytes flow directly to
// the store, so the tarball size is not limited by a function's request // the store, so the tarball size is not limited by a function's request
// body limit. // body limit.
const response = await fetch( const response = await fetch(
...@@ -146,20 +139,21 @@ async function main() { ...@@ -146,20 +139,21 @@ async function main() {
`Response headers: ${JSON.stringify(Object.fromEntries(response.headers))}` `Response headers: ${JSON.stringify(Object.fromEntries(response.headers))}`
) )
} }
const { clientToken } = await response.json() const body = await response.json()
const fileBuffer = await fs.readFile(tarballPath) const fileBuffer = await fs.readFile(tarballPath)
const { url } = await put( const putResponse = await fetch(body.url, {
`next/commits/${githubHeadSha}/${packageName}.tgz`, method: 'PUT',
fileBuffer, body: new Uint8Array(fileBuffer),
{ headers: { 'content-type': 'application/gzip' },
access: blobAccess, })
token: clientToken, if (!putResponse.ok) {
contentType: 'application/gzip', throw new Error(
multipart: true, `Failed to upload ${packageName}: ${putResponse.status}. ` +
} `Response headers: ${JSON.stringify(Object.fromEntries(putResponse.headers))}`
) )
console.info(`Uploaded ${packageName} -> ${url}`) }
console.info(`Uploaded ${packageName} -> ${body.downloadUrl}`)
} }
console.info('All tarballs uploaded') console.info('All tarballs uploaded')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment