railyard/apps/rithub-server/scripts/add-oauth-sources.sh
caelum0x 6801c08af9
Some checks failed
ci / cargo test (abacus) (push) Has been cancelled
ci / cargo test (agent-runtime) (push) Has been cancelled
ci / cargo test (context-passport) (push) Has been cancelled
ci / cargo test (game-economy) (push) Has been cancelled
ci / cargo test (ledgerline) (push) Has been cancelled
ci / cargo test (mint) (push) Has been cancelled
ci / cargo test (rago) (push) Has been cancelled
ci / cargo test (relay) (push) Has been cancelled
ci / node suites (push) Has been cancelled
ci / cargo test (toolgate) (push) Has been cancelled
ci / cargo test (turnstile) (push) Has been cancelled
ci / cargo test (vend) (push) Has been cancelled
feat(RIT-OPS,RIT-BRD): rename gitea -> rit everywhere we control, deployed + live-verified
apps/gitea -> apps/rithub-server; compose services/containers renamed
(rithub-server-app/postgres/act-runner) with explicit project name and
volume names pinned to the exact existing Docker volumes (no data loss);
our own GITEA_* compose/env var names -> RIT_*; new rit-admin CLI wrapper
on railyard-box; giteaSession.mjs/giteaOAuth.mjs/giteaInfo.mjs ->
ritSession/ritOAuth/ritInfo across 6 apps; GiteaForgeAdapter -> RitForgeAdapter
+ giteaSyncService/importGiteaRepos/syncGiteaRepos -> rit* in ritgram
(tsc clean); apps/console/lib/gitea.ts -> lib/ritProvision.ts; Go
internal/giteaclient -> internal/ritclient in rithub-async-import (go
build/test clean); new /auth/rit + /forges/rit/connect routes with
/gitea back-compat aliases; locale/swagger/footer/captcha template text
scrubbed of remaining "Gitea" strings.

Deployed to railyard-box: old containers stopped/removed, /srv/railyard-gitea
renamed to /srv/rithub-server with a symlink kept, docker compose up -d from
the new path, act_runner network-alias fix for its persisted instance URL.
Live-verified: docker compose config diff showed zero unintended value
changes, DB row counts unchanged (19 users, 635 repos), full route
regression 200/expected, 0 "gitea" in headers/bodies on every checked page,
real git clone+push over HTTPS and SSH with a disposable account (deleted
after). Deferred on purpose (documented in plans/railyard.md): the forge
discriminator / DB column names / Postgres role+volume names (data
migrations, not a naming change) and the upstream GITEA__ env-to-ini keys
and X-Gitea-* wire headers (hardcoded in the vendored engine binary).

See plans/railyard.md RIT-OPS/RIT-BRD entry for the full old->new map and
live evidence.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-12-01 16:34:39 +03:00

49 lines
2.8 KiB
Bash

#!/usr/bin/env bash
# Adds Google / Apple sign-in to Rithub (rithub.dev).
# Reads credentials from ~/products/.env. Run from the Mac:
# bash apps/rithub-server/scripts/add-oauth-sources.sh
# 2026-11-18: a second copy of this, add-rithub-oauth-sources.sh, runs
# ON railyard-box itself (no SSH hop) reading from the root-only
# /etc/products/rithub-oauth.env instead -- that's the one the owner's
# per-provider steps in plans/railyard.md actually point at now. Kept
# this Mac-side version working too (never delete a working path) for
# anyone who already has the creds in ~/products/.env.
# Callback URLs to register in each provider console:
# Google: https://rithub.dev/user/oauth2/Google/callback
# Apple : https://rithub.dev/user/oauth2/Apple/callback (Services ID, "Sign in with Apple")
# Each source is only added if its env vars are present; existing ones are skipped.
set -euo pipefail
ENV="$HOME/products/.env"
get() { grep -E "^$1=" "$ENV" | tail -1 | cut -d= -f2- | tr -d '"' || true; }
C=rithub-server-app
run() { ssh railyard-box "docker exec -u git $C gitea admin auth $*"; }
existing=$(ssh railyard-box "docker exec -u git $C gitea admin auth list" || true)
add() { # name provider key secret [extra args...]
local name=$1 provider=$2 key=$3 secret=$4; shift 4
if [ -z "$key" ] || [ -z "$secret" ]; then echo "skip $name: credentials not in .env"; return; fi
if grep -q "[[:space:]]$name[[:space:]]" <<<"$existing"; then echo "skip $name: already configured"; return; fi
run add-oauth --name "$name" --provider "$provider" --key "'$key'" --secret "'$secret'" "$@"
echo "added $name"
}
# GitHub sign-in removed for good (owner, 2026-11-30): Rithub auth = Google + email/password only.
add Google openidConnect "$(get RITHUB_GOOGLE_CLIENT_ID)" "$(get RITHUB_GOOGLE_CLIENT_SECRET)" \
--auto-discover-url https://accounts.google.com/.well-known/openid-configuration --scopes "'openid email profile'"
# Apple: client secret is an ES256 JWT signed with the Sign in with Apple .p8 key (max 6 months; re-run to rotate).
APPLE_ID=$(get RITHUB_APPLE_SERVICES_ID); TEAM=$(get APPLE_TEAM_ID); KID=$(get RITHUB_APPLE_KEY_ID); P8=$(get RITHUB_APPLE_P8_PATH)
if [ -n "$APPLE_ID" ] && [ -n "$TEAM" ] && [ -n "$KID" ] && [ -f "${P8:-/nonexistent}" ]; then
SECRET=$(python3 - "$TEAM" "$KID" "$APPLE_ID" "$P8" <<'PY'
import sys,time,jwt
team,kid,sub,p8=sys.argv[1:]
now=int(time.time())
print(jwt.encode({"iss":team,"iat":now,"exp":now+180*86400,"aud":"https://appleid.apple.com","sub":sub},open(p8).read(),algorithm="ES256",headers={"kid":kid}))
PY
)
add Apple openidConnect "$APPLE_ID" "$SECRET" --auto-discover-url https://appleid.apple.com/.well-known/openid-configuration --scopes "'openid'"
else
echo "skip Apple: RITHUB_APPLE_SERVICES_ID / APPLE_TEAM_ID / RITHUB_APPLE_KEY_ID / RITHUB_APPLE_P8_PATH not all set"
fi
ssh railyard-box "docker exec -u git $C gitea admin auth list"