Skip to content

Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.

fix(release): verify public OSS objects without read credentials (#7)

澄潭a040292349b7
diff --git a/.github/scripts/deploy-website-oss.sh b/.github/scripts/deploy-website-oss.sh
index f1bf330b..705ed8b7 100755
--- a/.github/scripts/deploy-website-oss.sh
+++ b/.github/scripts/deploy-website-oss.sh
@@ -14,14 +14,32 @@ region=cn-hongkong
common=(--endpoint "$endpoint" --region "$region" --access-key-id "$ACCESS_KEYID" --access-key-secret "$ACCESS_KEYSECRET")
asset_list=$(mktemp)
-trap 'rm -f "$asset_list"' EXIT
+object_headers=$(mktemp)
+head_error=$(mktemp)
+trap 'rm -f "$asset_list" "$object_headers" "$head_error"' EXIT
node apps/website/scripts/release-manifest.mjs artifacts "$manifest" > "$asset_list"
+head_object() {
+ local key=$1 status
+ : > "$object_headers"
+ : > "$head_error"
+ if ! status=$(curl --silent --show-error --head \
+ --output "$object_headers" --write-out '%{http_code}' \
+ --connect-timeout 10 --max-time 30 \
+ "https://$bucket.$endpoint/$key" 2> "$head_error"); then
+ cat "$head_error" >&2
+ echo "Could not inspect public release object: $key" >&2
+ return 1
+ fi
+ printf '%s' "$status"
+}
+
# A manifest entry is never exposed until its immutable object exists in OSS.
while IFS=$'\t' read -r _ key sha size; do
- facts=$(aliyun oss stat "oss://$bucket/$key" "${common[@]}")
- grep -Eiq "^X-Oss-Meta-Sha256[[:blank:]]*:[[:blank:]]*$sha[[:space:]]*$" <<<"$facts" || { echo "Release object metadata does not match manifest: $key" >&2; exit 1; }
- grep -Eiq "^Content-Length[[:blank:]]*:[[:blank:]]*$size[[:space:]]*$" <<<"$facts" || { echo "Release object size does not match manifest: $key" >&2; exit 1; }
+ status=$(head_object "$key") || exit 1
+ [[ "$status" == 200 ]] || { echo "Release object is not publicly readable (HTTP $status): $key" >&2; exit 1; }
+ grep -Eiq "^X-Oss-Meta-Sha256[[:blank:]]*:[[:blank:]]*$sha[[:space:]]*$" "$object_headers" || { echo "Release object metadata does not match manifest: $key" >&2; exit 1; }
+ grep -Eiq "^Content-Length[[:blank:]]*:[[:blank:]]*$size[[:space:]]*$" "$object_headers" || { echo "Release object size does not match manifest: $key" >&2; exit 1; }
done < "$asset_list"
# Upload website objects without deleting or replacing the releases/ prefix.
diff --git a/.github/scripts/publish-release-oss.sh b/.github/scripts/publish-release-oss.sh
index e8c888ef..2f0fba9b 100755
--- a/.github/scripts/publish-release-oss.sh
+++ b/.github/scripts/publish-release-oss.sh
@@ -13,10 +13,26 @@ region=cn-hongkong
common=(--endpoint "$endpoint" --region "$region" --access-key-id "$ACCESS_KEYID" --access-key-secret "$ACCESS_KEYSECRET")
asset_list=$(mktemp)
-stat_error=$(mktemp)
-trap 'rm -f "$asset_list" "$stat_error"' EXIT
+object_headers=$(mktemp)
+head_error=$(mktemp)
+trap 'rm -f "$asset_list" "$object_headers" "$head_error"' EXIT
node apps/website/scripts/release-manifest.mjs artifacts "$manifest" --tag "$tag" > "$asset_list"
+head_object() {
+ local key=$1 status
+ : > "$object_headers"
+ : > "$head_error"
+ if ! status=$(curl --silent --show-error --head \
+ --output "$object_headers" --write-out '%{http_code}' \
+ --connect-timeout 10 --max-time 30 \
+ "https://$bucket.$endpoint/$key" 2> "$head_error"); then
+ cat "$head_error" >&2
+ echo "Could not inspect public release object: $key" >&2
+ return 1
+ fi
+ printf '%s' "$status"
+}
+
# Resolve and check the entire local publication set before the first remote write.
while IFS=$'\t' read -r filename key sha size; do
[[ -n "$filename" && -f "$asset_dir/$filename" ]] || { echo "Missing release asset: $filename" >&2; exit 1; }
@@ -24,19 +40,23 @@ done < "$asset_list"
while IFS=$'\t' read -r filename key sha size; do
metadata="Cache-Control:public,max-age=31536000,immutable#Content-Disposition:attachment; filename=$filename#X-Oss-Meta-Sha256:$sha"
- if facts=$(aliyun oss stat "oss://$bucket/$key" "${common[@]}" 2> "$stat_error"); then
- grep -Eiq "^X-Oss-Meta-Sha256[[:blank:]]*:[[:blank:]]*$sha[[:space:]]*$" <<<"$facts" || { echo "Existing immutable object has a different SHA256: $key" >&2; exit 1; }
- grep -Eiq "^Content-Length[[:blank:]]*:[[:blank:]]*$size[[:space:]]*$" <<<"$facts" || { echo "Existing immutable object has a different size: $key" >&2; exit 1; }
- echo "Immutable release object already exists: $key"
- continue
- fi
- if ! grep -Eiq 'NoSuchKey|StatusCode[^0-9]*404|404[^0-9]+Not Found' "$stat_error"; then
- cat "$stat_error" >&2
- echo "Could not determine whether immutable release object exists: $key" >&2
- exit 1
- fi
+ status=$(head_object "$key") || exit 1
+ case "$status" in
+ 200)
+ grep -Eiq "^X-Oss-Meta-Sha256[[:blank:]]*:[[:blank:]]*$sha[[:space:]]*$" "$object_headers" || { echo "Existing immutable object has a different SHA256: $key" >&2; exit 1; }
+ grep -Eiq "^Content-Length[[:blank:]]*:[[:blank:]]*$size[[:space:]]*$" "$object_headers" || { echo "Existing immutable object has a different size: $key" >&2; exit 1; }
+ echo "Immutable release object already exists: $key"
+ continue
+ ;;
+ 404) ;;
+ *)
+ echo "Could not determine whether immutable release object exists (HTTP $status): $key" >&2
+ exit 1
+ ;;
+ esac
aliyun oss cp "$asset_dir/$filename" "oss://$bucket/$key" --meta "$metadata" "${common[@]}"
- facts=$(aliyun oss stat "oss://$bucket/$key" "${common[@]}")
- grep -Eiq "^X-Oss-Meta-Sha256[[:blank:]]*:[[:blank:]]*$sha[[:space:]]*$" <<<"$facts" || { echo "Uploaded object lacks expected SHA256 metadata: $key" >&2; exit 1; }
- grep -Eiq "^Content-Length[[:blank:]]*:[[:blank:]]*$size[[:space:]]*$" <<<"$facts" || { echo "Uploaded object size does not match: $key" >&2; exit 1; }
+ status=$(head_object "$key") || exit 1
+ [[ "$status" == 200 ]] || { echo "Uploaded object is not publicly readable (HTTP $status): $key" >&2; exit 1; }
+ grep -Eiq "^X-Oss-Meta-Sha256[[:blank:]]*:[[:blank:]]*$sha[[:space:]]*$" "$object_headers" || { echo "Uploaded object lacks expected SHA256 metadata: $key" >&2; exit 1; }
+ grep -Eiq "^Content-Length[[:blank:]]*:[[:blank:]]*$size[[:space:]]*$" "$object_headers" || { echo "Uploaded object size does not match: $key" >&2; exit 1; }
done < "$asset_list"
diff --git a/apps/website/tests/oss-publication.test.mjs b/apps/website/tests/oss-publication.test.mjs
index fb015506..7a68039b 100644
--- a/apps/website/tests/oss-publication.test.mjs
+++ b/apps/website/tests/oss-publication.test.mjs
@@ -28,9 +28,18 @@ function fixture() {
const manifestPath = path.join(root, 'releases.json');
fs.writeFileSync(manifestPath, JSON.stringify(manifest));
const log = path.join(root, 'aliyun.log');
- const fake = `#!/usr/bin/env bash\nset -euo pipefail\nprintf '%s\\n' \"$*\" >> \"$OSS_TEST_LOG\"\nif [[ \"$1 $2\" == 'oss stat' ]]; then printf 'Content-Length : %s\\nX-Oss-Meta-Sha256 : %s\\n' \"$OSS_TEST_SIZE\" \"$OSS_TEST_SHA\"; fi\n`;
- fs.writeFileSync(path.join(bin, 'aliyun'), fake, { mode: 0o755 });
- return { root, assets, bin, dist, manifestPath, log, state: path.join(root, 'uploaded'), filename, sha256, size: bytes.length };
+ const curlLog = path.join(root, 'curl.log');
+ const state = path.join(root, 'uploaded');
+ fs.writeFileSync(state, '');
+ const fakeAliyun = `#!/usr/bin/env bash\nset -euo pipefail\nprintf '%s\\n' \"$*\" >> \"$OSS_TEST_LOG\"\nif [[ \"$1 $2\" == 'oss cp' ]]; then touch \"$OSS_TEST_STATE\"; fi\n`;
+ const fakeCurl = `#!/usr/bin/env bash\nset -euo pipefail\nprintf '%s\\n' \"$*\" >> \"$CURL_TEST_LOG\"\noutput=\nwhile (( $# )); do\n case \"$1\" in\n --output) output=$2; shift 2 ;;\n *) shift ;;\n esac\ndone\nif [[ ! -f \"$OSS_TEST_STATE\" ]]; then\n printf 'HTTP/1.1 404 Not Found\\r\\n\\r\\n' > \"$output\"\n printf '404'\n exit 0\nfi\nprintf 'HTTP/1.1 200 OK\\r\\nContent-Length: %s\\r\\nx-oss-meta-sha256: %s\\r\\n\\r\\n' \"$OSS_TEST_SIZE\" \"$OSS_TEST_SHA\" > \"$output\"\nprintf '200'\n`;
+ fs.writeFileSync(path.join(bin, 'aliyun'), fakeAliyun, { mode: 0o755 });
+ fs.writeFileSync(path.join(bin, 'curl'), fakeCurl, { mode: 0o755 });
+ return { root, assets, bin, dist, manifestPath, log, curlLog, state, filename, sha256, size: bytes.length };
+}
+
+function readLog(filename) {
+ return fs.existsSync(filename) ? fs.readFileSync(filename, 'utf8') : '';
}
function execute(script, args, data, extraEnv = {}) {
@@ -38,6 +47,7 @@ function execute(script, args, data, extraEnv = {}) {
cwd: repository, encoding: 'utf8', env: {
...process.env, PATH: `${path.join(data.root, 'bin')}:${process.env.PATH}`,
ACCESS_KEYID: 'fixture-id', ACCESS_KEYSECRET: 'fixture-secret', OSS_TEST_LOG: data.log,
+ CURL_TEST_LOG: data.curlLog,
OSS_TEST_SHA: data.sha256, OSS_TEST_SIZE: String(data.size), OSS_TEST_STATE: data.state,
...extraEnv,
},
@@ -52,25 +62,22 @@ function run(script, args, data, extraEnv = {}) {
test('release publisher uses immutable hiroute-ai paths and SHA metadata', () => {
const data = fixture();
run('.github/scripts/publish-release-oss.sh', [data.assets, data.manifestPath, 'v1.2.3'], data);
- const log = fs.readFileSync(data.log, 'utf8');
- assert.match(log, new RegExp(`oss://hiroute-ai/releases/1\\.2\\.3/${data.filename}`));
+ const log = readLog(data.log);
+ assert.match(readLog(data.curlLog), new RegExp(`https://hiroute-ai\\.oss-cn-hongkong\\.aliyuncs\\.com/releases/1\\.2\\.3/${data.filename}`));
assert.doesNotMatch(log, /oss cp/);
+ assert.doesNotMatch(log, /oss stat/);
assert.doesNotMatch(log, /higress-ai/);
});
test('release publisher creates only a missing object and never forces an overwrite', () => {
const data = fixture();
- const fake = '#!/usr/bin/env bash\n' +
- 'set -euo pipefail\n' +
- 'printf "%s\\n" "$*" >> "$OSS_TEST_LOG"\n' +
- 'if [[ "$1 $2" == "oss stat" && ! -f "$OSS_TEST_STATE" ]]; then echo "ErrorCode: NoSuchKey; StatusCode: 404" >&2; exit 1; fi\n' +
- 'if [[ "$1 $2" == "oss cp" ]]; then touch "$OSS_TEST_STATE"; else printf "Content-Length : %s\\nX-Oss-Meta-Sha256 : %s\\n" "$OSS_TEST_SIZE" "$OSS_TEST_SHA"; fi\n';
- fs.writeFileSync(path.join(data.bin, 'aliyun'), fake, { mode: 0o755 });
+ fs.rmSync(data.state);
run('.github/scripts/publish-release-oss.sh', [data.assets, data.manifestPath, 'v1.2.3'], data);
- const log = fs.readFileSync(data.log, 'utf8');
+ const log = readLog(data.log);
assert.match(log, /oss cp/);
assert.match(log, new RegExp(`X-Oss-Meta-Sha256:${data.sha256}`));
assert.doesNotMatch(log, /--force/);
+ assert.doesNotMatch(log, /oss stat/);
});
test('release publisher rejects an existing object with different immutable metadata', () => {
@@ -79,7 +86,7 @@ test('release publisher rejects an existing object with different immutable meta
[data.assets, data.manifestPath, 'v1.2.3'], data, { OSS_TEST_SHA: '0'.repeat(64) });
assert.notEqual(result.status, 0);
assert.match(result.stderr, /different SHA256/);
- assert.doesNotMatch(fs.readFileSync(data.log, 'utf8'), /oss cp/);
+ assert.doesNotMatch(readLog(data.log), /oss cp/);
});
test('OSS object sizes must match the complete Content-Length field', () => {
@@ -91,16 +98,17 @@ test('OSS object sizes must match the complete Content-Length field', () => {
const result = execute(script, argumentsFor(data), data, { OSS_TEST_SIZE: `${data.size}0` });
assert.notEqual(result.status, 0);
assert.match(result.stderr, message);
- assert.doesNotMatch(fs.readFileSync(data.log, 'utf8'), /oss cp/);
+ assert.doesNotMatch(readLog(data.log), /oss cp/);
}
});
test('website deploy checks release metadata and never targets a destructive sync', () => {
const data = fixture();
run('.github/scripts/deploy-website-oss.sh', [data.dist, data.manifestPath], data);
- const log = fs.readFileSync(data.log, 'utf8');
- assert.match(log, /oss stat oss:\/\/hiroute-ai\/releases\//);
+ const log = readLog(data.log);
+ assert.match(readLog(data.curlLog), /https:\/\/hiroute-ai\.oss-cn-hongkong\.aliyuncs\.com\/releases\//);
assert.match(log, /oss cp .* oss:\/\/hiroute-ai\//);
+ assert.doesNotMatch(log, /oss stat/);
assert.doesNotMatch(log, /\b(?:rm|sync)\b/);
assert.doesNotMatch(log, /higress-ai/);
});
@@ -115,5 +123,6 @@ test('manifest generation failures stop OSS scripts before any remote command',
const result = execute(script, argumentsFor(data), data);
assert.notEqual(result.status, 0);
assert.equal(fs.existsSync(data.log), false);
+ assert.equal(fs.existsSync(data.curlLog), false);
}
});