fix(legacy): keep github app secrets in production (#63423)

This commit is contained in:
Dax
2026-11-11 19:49:20 -05:00
committed by GitHub
Unverified
parent 6d023043ca
commit b451fe3952
6 changed files with 25 additions and 18 deletions
+9 -5
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# deploy-legacy.sh <dev|production> <dir> <secrets.json>: deploys the legacy
# deploy-legacy.sh <dev|production> <dir> [production-secrets.json]: deploys the legacy
# Worker from a verified Build Output artifact (services/legacy/.cloudflare/output)
# with the cf CLI pinned in cf/package-lock.json.
#
@@ -12,7 +12,6 @@
mode=$1
src=$(cd "$2" && pwd)
secrets=$(posix "$3")
release=$(cd "$(dirname "$0")" && pwd)
case "$mode" in
@@ -37,8 +36,13 @@ unexpected=$(cd "$src" && find . ! -type d ! -type f -o -type f ! -path ./SHA256
expect_json "$src/v0/config.json" "$target/root.json" "The legacy Worker's root config"
expect_json "$src/v0/workers/default/worker.config.json" "$target/worker.json" "The legacy Worker's config"
jq -e 'keys == ["GITHUB_APP_ID", "GITHUB_APP_PRIVATE_KEY"] and all(.[]; type == "string" and length > 0)' \
"$secrets" > /dev/null || die "The secrets file does not hold exactly GITHUB_APP_ID and GITHUB_APP_PRIVATE_KEY"
args=()
if [[ "$mode" == production ]]; then
secrets=$(posix "$3")
jq -e 'keys == ["GITHUB_APP_ID", "GITHUB_APP_PRIVATE_KEY"] and all(.[]; type == "string" and length > 0)' \
"$secrets" > /dev/null || die "The secrets file does not hold exactly GITHUB_APP_ID and GITHUB_APP_PRIVATE_KEY"
args=(--secrets-file "$secrets")
fi
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
@@ -52,4 +56,4 @@ cf="$release/cf/node_modules/.bin/cf"
[ -x "$cf" ] || die "Install the pinned cf CLI first: npm ci --ignore-scripts in .github/release/cf"
cd "$work"
"$cf" deploy --prebuilt --mode "$mode" --secrets-file "$secrets"
"$cf" deploy --prebuilt --mode "$mode" "${args[@]}"
@@ -7,10 +7,6 @@
"observability": { "enabled": true },
"workersDev": false,
"previewUrls": false,
"env": {
"GITHUB_APP_ID": { "type": "secret" },
"GITHUB_APP_PRIVATE_KEY": { "type": "secret" }
},
"manifest": {
"type": "complete",
"mainModule": "index.js",
+4 -1
View File
@@ -109,11 +109,14 @@ jobs:
# An explicit bash runs with pipefail, so a failed secret read fails the step.
shell: bash
run: |
if [[ "$STAGE" == dev ]]; then
exec bash .github/release/deploy-legacy.sh dev "$RUNNER_TEMP/in/legacy-dev"
fi
umask 077
secrets="$RUNNER_TEMP/legacy-secrets.json"
trap 'rm -f "$secrets"' EXIT
for name in GITHUB_APP_ID GITHUB_APP_PRIVATE_KEY; do
aws secretsmanager get-secret-value --secret-id "opencode/$STAGE/$name" --output json |
aws secretsmanager get-secret-value --secret-id "opencode/production/$name" --output json |
jq --arg name "$name" '{($name): .SecretString}'
done | jq -s add > "$secrets"
bash .github/release/deploy-legacy.sh "$STAGE" "$RUNNER_TEMP/in/legacy-$STAGE" "$secrets"
+4 -4
View File
@@ -9,13 +9,13 @@ One Worker that answers by hostname:
Session sharing was retired in #55716 and V2 has no sharing. They serve the "Session sharing has
been discontinued" page, and the old `/api/share` endpoints still answer so V1 clients keep working
(`src/share.ts`).
- `api.opencode.ai` (production) and `api.dev.opencode.ai` (development) exchange a GitHub Actions
- `api.opencode.ai` (production) exchanges a GitHub Actions
OIDC token for a GitHub App installation token for the V1 GitHub Action
(`POST /exchange_github_app_token`, `src/api.ts`).
(`POST /exchange_github_app_token`, `src/api.ts`). The dev endpoint returns 503.
`cloudflare.config.ts` defines the Worker. `deploy:dev` and `deploy:production` deploy it with `cf`
from `.github/workflows/deploy.yml`. The deploy job reads the `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY` Worker
secrets from AWS Secrets Manager (`opencode/<stage>/GITHUB_APP_*`) and uploads them with
from `.github/workflows/deploy.yml`. The production deploy reads the `GITHUB_APP_ID` and `GITHUB_APP_PRIVATE_KEY` Worker
secrets from AWS Secrets Manager (`opencode/production/GITHUB_APP_*`) and uploads them with
`--secrets-file`.
| Environment | Worker | Hostnames |
+2 -2
View File
@@ -17,8 +17,8 @@ export default defineConfig(({ mode }) => {
compatibilityFlags: ["nodejs_compat"],
entrypoint: "./src/index.ts",
domains: dev ? ["dev.opncd.ai", "api.dev.opencode.ai"] : ["opncd.ai", "api.opencode.ai"],
// Set from AWS Secrets Manager (opencode/<stage>/GITHUB_APP_*) by the deploy job with --secrets-file.
env: {
// The production deploy supplies these from AWS Secrets Manager with --secrets-file.
env: mode !== "production" ? undefined : {
GITHUB_APP_ID: bindings.secret(),
GITHUB_APP_PRIVATE_KEY: bindings.secret(),
},
+6 -2
View File
@@ -5,8 +5,8 @@ import { Octokit } from "@octokit/rest"
import { parseRepositoryClaim } from "./github"
export interface Env {
GITHUB_APP_ID: string
GITHUB_APP_PRIVATE_KEY: string
GITHUB_APP_ID?: string
GITHUB_APP_PRIVATE_KEY?: string
}
export default new Hono<{ Bindings: Env }>()
@@ -15,6 +15,10 @@ export default new Hono<{ Bindings: Env }>()
* Used by the GitHub action to get GitHub installation access token given the OIDC token
*/
.post("/exchange_github_app_token", async (c) => {
if (!c.env.GITHUB_APP_ID || !c.env.GITHUB_APP_PRIVATE_KEY) {
const dev = new URL(c.req.url).hostname === "api.dev.opencode.ai"
return c.json({ error: dev ? "not configured on dev" : "GitHub App not configured" }, 503)
}
const EXPECTED_AUDIENCE = "opencode-github-action"
const GITHUB_ISSUER = "https://token.actions.githubusercontent.com"
const JWKS_URL = `${GITHUB_ISSUER}/.well-known/jwks`