From c16f2892b26e75880e717cbd4f1163d7ebfcb79f Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 3 Dec 2026 17:47:00 +1300 Subject: [PATCH 1/2] app/: production refuses to boot without GitHub configured (sc-8900): the OAuth application and the App, all five settings, named when missing --- app/src/forge/github_app.rs | 34 ++++++++++++++++++++++++++++++++++ app/src/lib.rs | 5 +++++ app/tests/hosts.rs | 32 +++++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/src/forge/github_app.rs b/app/src/forge/github_app.rs index 1707cd50..be3c22ef 100644 --- a/app/src/forge/github_app.rs +++ b/app/src/forge/github_app.rs @@ -21,6 +21,40 @@ pub struct GithubApp { pub webhook_secret: Option, } +/// At boot: production runs only with GitHub fully configured. Sign-in needs the OAuth application +/// (`GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`), and checks, pull request comments and the webhook need the App +/// (`GITHUB_APP_ID`, `GITHUB_APP_PRIVATE_KEY_BASE64`, `GITHUB_WEBHOOK_SECRET`). Without them the app would start +/// with no way to sign in and nothing reported to GitHub, and say so nowhere (3 Dec 2026: the cutover's manifests +/// read the wrong Secret keys, and the sign-in page offered no forge). +/// +/// # Errors +/// In production, naming each setting that's missing. +pub fn check(app: &GithubApp, apps: &crate::auth::sign_in::ForgeApps, production: bool) -> laravel::Result<()> { + if !production { + return Ok(()); + } + let set = |v: &Option| v.as_deref().is_some_and(|s| !s.trim().is_empty()); + let missing: Vec<&str> = [ + ("GITHUB_CLIENT_ID", &apps.github), + ("GITHUB_CLIENT_SECRET", &apps.github_secret), + ("GITHUB_APP_ID", &app.app_id), + ("GITHUB_APP_PRIVATE_KEY_BASE64", &app.private_key_base64), + ("GITHUB_WEBHOOK_SECRET", &app.webhook_secret), + ] + .into_iter() + .filter(|(_, v)| !set(v)) + .map(|(name, _)| name) + .collect(); + if missing.is_empty() { + return Ok(()); + } + Err(laravel::Error::msg(format!( + "GitHub isn't configured: {} not set. Production needs all five: without them nobody can sign in, and no \ + check or pull request comment reaches GitHub.", + missing.join(", ") + ))) +} + fn err(e: impl std::fmt::Display) -> laravel::Error { laravel::Error::msg(format!("GitHub: {e}")) } diff --git a/app/src/lib.rs b/app/src/lib.rs index 211206ff..4f5bd23b 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -49,6 +49,11 @@ pub fn configure() -> ApplicationBuilder { billing::check(config.section::(), config.app.env.is_production())?; http::security::check(config, config.app.env.is_production())?; config.section::().check(&config.app.env)?; + forge::github_app::check( + config.section::(), + config.section::(), + config.app.env.is_production(), + )?; Ok(()) }) .with_middleware(|middleware, _| { diff --git a/app/tests/hosts.rs b/app/tests/hosts.rs index bd662433..f8fcfa9e 100644 --- a/app/tests/hosts.rs +++ b/app/tests/hosts.rs @@ -45,6 +45,11 @@ fn in_production() -> laravel::foundation::ApplicationBuilder { ("S3_SECRET_ACCESS_KEY", "visualci-dev-secret"), ("RENDERER_TOKEN", "renderer-test-token"), ("RENDERER_VERSION", "1"), + ("GITHUB_CLIENT_ID", "Iv1.test"), + ("GITHUB_CLIENT_SECRET", "github-test-secret"), + ("GITHUB_APP_ID", "1"), + ("GITHUB_APP_PRIVATE_KEY_BASE64", "dGVzdA=="), + ("GITHUB_WEBHOOK_SECRET", "github-webhook-test-secret"), ]) } @@ -159,7 +164,7 @@ async fn every_response_carries_the_security_headers(app: Application) { } /// The development sign-in can't exist in production: production won't boot with DEV_LOGIN on, and without it the -/// route isn't there (a 404, not a refusal) and the providers don't offer it. +/// route isn't there (a 405: only GET /auth/{forge} matches the path) and the providers don't offer it. #[tokio::test(flavor = "multi_thread")] async fn production_has_no_development_sign_in() { let hosts = [ @@ -190,3 +195,28 @@ async fn production_has_no_development_sign_in() { // No such route: only the sign-in start, GET /auth/{forge}, matches the path .assert_status(405); } + +#[tokio::test(flavor = "multi_thread")] +async fn production_needs_github_configured() { + let hosts = [ + ("VISUALCI_SITE_URL", "https://visualci.test"), + ("VISUALCI_APP_URL", "https://app.visualci.test"), + ("VISUALCI_API_URL", "https://api.visualci.test"), + ("VISUALCI_MCP_URL", "https://mcp.visualci.test"), + ("OAUTH_ISSUER", "https://mcp.visualci.test"), + ("OAUTH_AUTHORIZATION_ENDPOINT", "https://app.visualci.test/oauth/authorize"), + ]; + // The cutover's mistake: the GitHub settings empty, as an optional secret key that doesn't exist leaves them + let unset = in_production().with_envs(hosts).with_envs([("GITHUB_CLIENT_ID", ""), ("GITHUB_WEBHOOK_SECRET", "")]); + let refused = unset.create().boot().await.expect_err("production doesn't boot without GitHub"); + let message = format!("{refused:?}"); + assert!(message.contains("GITHUB_CLIENT_ID, GITHUB_WEBHOOK_SECRET not set"), "{message}"); + + let app = in_production().with_envs(hosts).create(); + app.boot().await.expect("it boots with all five"); + app.get("/auth/providers") + .header("host", "app.visualci.test") + .await + .assert_ok() + .assert_json_path("forges.0", "github"); +} From 9eb690f0ae3307b157e2af9630da4c0928a1b651 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Thu, 3 Dec 2026 17:51:15 +1300 Subject: [PATCH 2/2] app/: production also refuses to boot without Stripe's key and webhook secret, or Postmark's token --- app/src/billing/mod.rs | 25 +++++++++++++++++++++---- app/src/lib.rs | 1 + app/src/notify/postmark.rs | 14 ++++++++++++++ app/tests/billing.rs | 6 +++++- app/tests/hosts.rs | 12 +++++++++++- 5 files changed, 52 insertions(+), 6 deletions(-) diff --git a/app/src/billing/mod.rs b/app/src/billing/mod.rs index 497029ed..66a7eded 100644 --- a/app/src/billing/mod.rs +++ b/app/src/billing/mod.rs @@ -74,13 +74,30 @@ impl Stripe { } } -/// At boot: production never runs on a test key (`sk_test_`, `rk_test_`), which would take no real payments while -/// granting real plans and credits. +/// At boot: production needs Stripe's key and webhook secret, and never runs on a test key (`sk_test_`, `rk_test_`), +/// which would take no real payments while granting real plans and credits. /// /// # Errors -/// In production, when the Stripe key isn't a live one. +/// In production, when either is missing or the key isn't a live one. pub fn check(stripe: &Stripe, production: bool) -> laravel::Result<()> { - if production && stripe.live() == Some(false) { + if !production { + return Ok(()); + } + let set = |v: &Option| v.as_deref().is_some_and(|s| !s.trim().is_empty()); + let missing: Vec<&str> = + [("STRIPE_SECRET_KEY", &stripe.secret_key), ("STRIPE_WEBHOOK_SECRET", &stripe.webhook_secret)] + .into_iter() + .filter(|(_, v)| !set(v)) + .map(|(name, _)| name) + .collect(); + if !missing.is_empty() { + return Err(laravel::Error::msg(format!( + "Stripe isn't configured: {} not set. Production needs both: without them nobody can pay, and Stripe's \ + events (payments, subscriptions) are refused.", + missing.join(", ") + ))); + } + if stripe.live() == Some(false) { return Err(laravel::Error::msg( "STRIPE_SECRET_KEY is a test key; production needs a live one (sk_live_ or rk_live_)", )); diff --git a/app/src/lib.rs b/app/src/lib.rs index 4f5bd23b..21cd9277 100644 --- a/app/src/lib.rs +++ b/app/src/lib.rs @@ -49,6 +49,7 @@ pub fn configure() -> ApplicationBuilder { billing::check(config.section::(), config.app.env.is_production())?; http::security::check(config, config.app.env.is_production())?; config.section::().check(&config.app.env)?; + notify::postmark::check(config.section::(), config.app.env.is_production())?; forge::github_app::check( config.section::(), config.section::(), diff --git a/app/src/notify/postmark.rs b/app/src/notify/postmark.rs index 3dd43373..3dbfe8b8 100644 --- a/app/src/notify/postmark.rs +++ b/app/src/notify/postmark.rs @@ -14,6 +14,20 @@ pub struct Postmark { pub reply_to: String, } +/// At boot: production sends email, so it needs `POSTMARK_SERVER_TOKEN`. Without it, every email (invitations, +/// receipts, sign-in notices) would wait in the outbox for good, and say so nowhere. +/// +/// # Errors +/// In production, when the token isn't set. +pub fn check(postmark: &Postmark, production: bool) -> laravel::Result<()> { + if production && postmark.token.as_deref().is_none_or(|t| t.trim().is_empty()) { + return Err(laravel::Error::msg( + "POSTMARK_SERVER_TOKEN isn't set: production needs it, or no email is ever sent", + )); + } + Ok(()) +} + /// Send one email with its text and HTML bodies. /// /// # Errors diff --git a/app/tests/billing.rs b/app/tests/billing.rs index 634dc799..6f4beda9 100644 --- a/app/tests/billing.rs +++ b/app/tests/billing.rs @@ -153,11 +153,15 @@ async fn only_admins_check_out_and_get_a_stripe_url(app: Application) -> laravel #[test] fn production_never_runs_on_a_test_key() { - let stripe = |key: &str| app::billing::Stripe { secret_key: Some(key.into()), webhook_secret: None }; + let stripe = + |key: &str| app::billing::Stripe { secret_key: Some(key.into()), webhook_secret: Some("whsec_x".into()) }; assert!(app::billing::check(&stripe("sk_test_x"), true).is_err()); assert!(app::billing::check(&stripe("rk_test_x"), true).is_err()); assert!(app::billing::check(&stripe("rk_live_x"), true).is_ok()); assert!(app::billing::check(&stripe("sk_test_x"), false).is_ok()); + let unset = app::billing::Stripe { secret_key: None, webhook_secret: None }; + assert!(app::billing::check(&unset, true).is_err(), "production needs Stripe"); + assert!(app::billing::check(&unset, false).is_ok()); } fn stripe_test_key() -> Application { diff --git a/app/tests/hosts.rs b/app/tests/hosts.rs index f8fcfa9e..ade0e584 100644 --- a/app/tests/hosts.rs +++ b/app/tests/hosts.rs @@ -50,6 +50,9 @@ fn in_production() -> laravel::foundation::ApplicationBuilder { ("GITHUB_APP_ID", "1"), ("GITHUB_APP_PRIVATE_KEY_BASE64", "dGVzdA=="), ("GITHUB_WEBHOOK_SECRET", "github-webhook-test-secret"), + ("STRIPE_SECRET_KEY", "rk_live_test"), + ("STRIPE_WEBHOOK_SECRET", "whsec_test"), + ("POSTMARK_SERVER_TOKEN", "postmark-test-token"), ]) } @@ -197,7 +200,7 @@ async fn production_has_no_development_sign_in() { } #[tokio::test(flavor = "multi_thread")] -async fn production_needs_github_configured() { +async fn production_needs_github_stripe_and_email_configured() { let hosts = [ ("VISUALCI_SITE_URL", "https://visualci.test"), ("VISUALCI_APP_URL", "https://app.visualci.test"), @@ -212,6 +215,13 @@ async fn production_needs_github_configured() { let message = format!("{refused:?}"); assert!(message.contains("GITHUB_CLIENT_ID, GITHUB_WEBHOOK_SECRET not set"), "{message}"); + // Stripe and Postmark the same way + for name in ["STRIPE_SECRET_KEY", "STRIPE_WEBHOOK_SECRET", "POSTMARK_SERVER_TOKEN"] { + let refused = in_production().with_envs(hosts).with_env(name, "").create().boot().await; + let message = format!("{:?}", refused.expect_err("production doesn't boot without it")); + assert!(message.contains(name), "{name}: {message}"); + } + let app = in_production().with_envs(hosts).create(); app.boot().await.expect("it boots with all five"); app.get("/auth/providers")