mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
Ports the edge halves of two release-branch changes onto main, which production
edge deploys come from (prod edge = ba3f991):
- Ingress mode (#41986): signed ingress header (INGRESS_SECRETS) and token mode
for a cloud load balancer (INGRESS_TOKENS secret, INGRESS_ORIGINS,
INGRESS_SOURCE_CIDRS). All or nothing: a partial or malformed setup turns the
mode off and logs relay_edge_ingress_config_invalid; it never throws. Requests
from the configured egress ranges that fail the trust rule get 403. Admin calls
are matched first. Adds cloud/apps/relay-ingress (stateless proxy) and the
relay-contract ingress-header module.
- POST /__admin/verify (#42538, edge half): the director's check for a phone
resume token or invite that exists only on the edge. Hash only, read-only: an
object that never held the host (or no longer holds it here) answers not_here
before anything is written; otherwise the token's jti is its only write.
Replay and jti_full are 409. Adds hash-input variants to RelayCredentialStore
(shared with the edge; existing methods delegate, behaviour unchanged).
Kept from main: drain, single-use admin tokens (jti), signing-key rotation,
JWKS-outage tolerance, keepalive auto-response, health probe. The place label
keeps main's '<continent>/<colo>' and, only behind a verified ingress, appends
'/<country>/<ingress name>'.
No user effect until the ingress vars/secret are set or the director calls verify.
47 lines
2.3 KiB
TypeScript
47 lines
2.3 KiB
TypeScript
// The egress ranges a global load balancer uses to reach an internet NEG endpoint, for the edge's
|
|
// INGRESS_SOURCE_CIDRS. Published as an SPF-style TXT record; read here, never at request time.
|
|
// npx tsx scripts/ingress-source-cidrs.ts # print the comma-separated list
|
|
// npx tsx scripts/ingress-source-cidrs.ts --check "<deployed>" # exit 1 on drift (scheduled check)
|
|
import { Resolver } from 'node:dns/promises'
|
|
import { parseCidr } from '../src/ingress'
|
|
|
|
const RECORD = '_cloud-eoips.googleusercontent.com'
|
|
|
|
async function ranges(name: string, resolver: Resolver, depth = 0): Promise<string[]> {
|
|
if (depth > 5) { throw new Error(`include depth exceeded at ${name}`) }
|
|
const txt = (await resolver.resolveTxt(name)).map((chunks) => chunks.join('')).filter((t) => t.startsWith('v=spf1 '))
|
|
if (txt.length !== 1) { throw new Error(`expected one spf record at ${name}, got ${txt.length}`) }
|
|
const out: string[] = []
|
|
for (const term of txt[0]!.split(/\s+/).slice(1)) {
|
|
if (term.startsWith('ip4:') || term.startsWith('ip6:')) { out.push(term.slice(4)) }
|
|
else if (term.startsWith('include:')) { out.push(...(await ranges(term.slice(8), resolver, depth + 1))) }
|
|
}
|
|
return out
|
|
}
|
|
|
|
const normalize = (list: string[]) => [...new Set(list.map((c) => c.trim().toLowerCase()).filter(Boolean))].sort()
|
|
|
|
async function main(): Promise<void> {
|
|
const resolver = new Resolver()
|
|
resolver.setServers(['8.8.8.8', '8.8.4.4'])
|
|
const published = normalize(await ranges(RECORD, resolver))
|
|
if (published.length === 0 || published.some((c) => !parseCidr(c))) { throw new Error(`unusable ranges: ${published.join(',')}`) }
|
|
const checkAt = process.argv.indexOf('--check')
|
|
if (checkAt === -1) {
|
|
console.log(published.join(','))
|
|
return
|
|
}
|
|
const deployed = normalize((process.argv[checkAt + 1] ?? '').split(','))
|
|
const added = published.filter((c) => !deployed.includes(c))
|
|
const removed = deployed.filter((c) => !published.includes(c))
|
|
if (added.length || removed.length) {
|
|
console.error(JSON.stringify({ event: 'ingress_source_cidrs_drift', added, removed }))
|
|
process.exitCode = 1
|
|
} else { console.log(`ok: ${published.length} ranges match`) }
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error instanceof Error ? error.message : error)
|
|
process.exitCode = 1
|
|
})
|