forked from heavy-duty/stoke
fix: protect Debian publish credentials
This commit is contained in:
parent
1dfa2c173d
commit
dcb169e8ab
2 changed files with 18 additions and 5 deletions
|
|
@ -40,11 +40,24 @@ EOF
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "${RUNNER_TEMP:-}" ]; then
|
||||||
|
TMP="$(mktemp -d "$RUNNER_TEMP/stoke-publish.XXXXXX")"
|
||||||
|
else
|
||||||
|
TMP="$(mktemp -d)"
|
||||||
|
fi
|
||||||
|
trap 'rm -rf "$TMP"' EXIT
|
||||||
|
|
||||||
|
HEADER_FILE="$TMP/authorization-header"
|
||||||
|
RESPONSE_FILE="$TMP/response"
|
||||||
|
umask 077
|
||||||
|
printf 'Authorization: token %s\n' "$TOKEN" >"$HEADER_FILE"
|
||||||
|
chmod 0600 "$HEADER_FILE"
|
||||||
|
|
||||||
URL="$FORGE_URL/api/packages/$OWNER/debian/pool/$DISTRIBUTION/$COMPONENT/upload"
|
URL="$FORGE_URL/api/packages/$OWNER/debian/pool/$DISTRIBUTION/$COMPONENT/upload"
|
||||||
echo "Uploading $(basename "$DEB") to $URL"
|
echo "Uploading $(basename "$DEB") to $URL"
|
||||||
|
|
||||||
STATUS="$(curl -sS -o /tmp/stoke-publish-response.$$ -w '%{http_code}' \
|
STATUS="$(curl -sS -o "$RESPONSE_FILE" -w '%{http_code}' \
|
||||||
-X PUT -H "Authorization: token $TOKEN" \
|
-X PUT -H @"$HEADER_FILE" \
|
||||||
--upload-file "$DEB" "$URL")"
|
--upload-file "$DEB" "$URL")"
|
||||||
|
|
||||||
case "$STATUS" in
|
case "$STATUS" in
|
||||||
|
|
@ -52,9 +65,7 @@ case "$STATUS" in
|
||||||
409) echo "Already published (409): this exact version already exists in the registry." ;;
|
409) echo "Already published (409): this exact version already exists in the registry." ;;
|
||||||
*)
|
*)
|
||||||
echo "error: upload failed with HTTP $STATUS" >&2
|
echo "error: upload failed with HTTP $STATUS" >&2
|
||||||
cat /tmp/stoke-publish-response.$$ >&2 || true
|
cat "$RESPONSE_FILE" >&2 || true
|
||||||
rm -f /tmp/stoke-publish-response.$$
|
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
rm -f /tmp/stoke-publish-response.$$
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ process.stdout.write(process.env.CURL_HTTP_STATUS);
|
||||||
return {
|
return {
|
||||||
result,
|
result,
|
||||||
call,
|
call,
|
||||||
|
runnerTemp,
|
||||||
remainingTempEntries,
|
remainingTempEntries,
|
||||||
legacyAfter,
|
legacyAfter,
|
||||||
headerExistsAfter: call?.headerFile ? fs.existsSync(call.headerFile) : false,
|
headerExistsAfter: call?.headerFile ? fs.existsSync(call.headerFile) : false,
|
||||||
|
|
@ -110,6 +111,7 @@ test('curl reads a private authorization header file without receiving the token
|
||||||
assert.equal(scenario.result.status, 0, scenario.result.stderr);
|
assert.equal(scenario.result.status, 0, scenario.result.stderr);
|
||||||
assert.ok(scenario.call.args.includes('-H'));
|
assert.ok(scenario.call.args.includes('-H'));
|
||||||
assert.equal(scenario.call.args.every((arg) => !arg.includes(TOKEN)), true);
|
assert.equal(scenario.call.args.every((arg) => !arg.includes(TOKEN)), true);
|
||||||
|
assert.equal(path.dirname(scenario.call.tempDir), scenario.runnerTemp);
|
||||||
assert.ok(scenario.call.headerFile.startsWith(`${scenario.call.tempDir}${path.sep}`));
|
assert.ok(scenario.call.headerFile.startsWith(`${scenario.call.tempDir}${path.sep}`));
|
||||||
assert.equal(scenario.call.header, `Authorization: token ${TOKEN}\n`);
|
assert.equal(scenario.call.header, `Authorization: token ${TOKEN}\n`);
|
||||||
assert.equal(scenario.call.headerMode, 0o600);
|
assert.equal(scenario.call.headerMode, 0o600);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue