diff --git a/.env.example b/.env.example index f9adcf8d6..6e3c1c715 100644 --- a/.env.example +++ b/.env.example @@ -205,11 +205,6 @@ TWIGPINE_REQUIRE_SIGNATURE_NONCE=false # Example: /ip4/1.2.3.4/udp/7546/quic-v1/p2p/12D3KooW... TWIGPINE_P2P_BOOTSTRAP= -# ── Access control ──────────────────────────────────────────────────────── -# Reserved and currently inert. Repo reads are gated per repository by -# is_public and path-scoped visibility rules; this flag changes nothing. -TWIGPINE_PUBLIC_READ=true - # Maximum git smart-HTTP pack request size, in bytes. TWIGPINE_MAX_PACK_BYTES=2147483648 diff --git a/crates/twigpine-cli/src/doctor.rs b/crates/twigpine-cli/src/doctor.rs index 8acbd289c..e06cea12d 100644 --- a/crates/twigpine-cli/src/doctor.rs +++ b/crates/twigpine-cli/src/doctor.rs @@ -364,7 +364,11 @@ pub async fn run(args: DoctorArgs) -> Result<()> { // Settings still given under their names from before the rename. They // work; this row only appears when there is something to update. - if let Some(check) = legacy_settings_check(&twigpine_core::legacy_env::report()) { + let mut legacy = twigpine_core::legacy_env::report(); + if let Some(check) = removed_public_read_check(&mut legacy) { + checks.push(check); + } + if let Some(check) = legacy_settings_check(&legacy) { checks.push(check); } @@ -631,6 +635,27 @@ fn which_in_path(name: &str) -> bool { .unwrap_or(false) } +const REMOVED_PUBLIC_READ: &str = "TWIGPINE_PUBLIC_READ"; + +/// Drop the removed public-read setting from the legacy report and return +/// its own removal-notice row when either name is set, even if empty. +fn removed_public_read_check(report: &mut twigpine_core::legacy_env::Report) -> Option { + if std::env::var_os("TWIGPINE_PUBLIC_READ").is_none() + && std::env::var_os("GITLAWB_PUBLIC_READ").is_none() + { + return None; + } + report + .legacy_only + .retain(|name| name != REMOVED_PUBLIC_READ); + report.conflicts.retain(|name| name != REMOVED_PUBLIC_READ); + Some(Check::warn( + "public read", + "TWIGPINE_PUBLIC_READ and GITLAWB_PUBLIC_READ were removed and have no effect. Reads follow each repository's visibility.", + "unset TWIGPINE_PUBLIC_READ and GITLAWB_PUBLIC_READ in your shell profile or service unit", + )) +} + /// Fetch the latest release tag from Twigpine/node (the actual release repo — see install.sh's /// `TWIGPINE_RELEASE_REPO` default) and compare to current version. /// A warn row naming settings given under their old `GITLAWB_` names, or diff --git a/crates/twigpine-cli/tests/doctor_transport_node.rs b/crates/twigpine-cli/tests/doctor_transport_node.rs index 5ab0e4e13..d365ac4eb 100644 --- a/crates/twigpine-cli/tests/doctor_transport_node.rs +++ b/crates/twigpine-cli/tests/doctor_transport_node.rs @@ -833,3 +833,73 @@ fn no_settings_row_without_an_old_name() { let r = doctor_with(Some(&url), None, &[]); assert!(settings_row(&r).is_none(), "{}", r.stdout); } + +/// The row doctor prints when a removed public-read setting is present. +fn public_read_row(r: &Run) -> Option<&str> { + r.stdout + .lines() + .find(|l| l.contains("were removed and have no effect")) +} + +#[test] +fn a_removed_public_read_setting_is_not_reported_as_working() { + for env in [ + vec![("GITLAWB_PUBLIC_READ", "false")], + vec![("TWIGPINE_PUBLIC_READ", "true")], + vec![("GITLAWB_PUBLIC_READ", "")], + vec![ + ("TWIGPINE_PUBLIC_READ", "true"), + ("GITLAWB_PUBLIC_READ", "false"), + ], + ] { + let (port, _) = serve(|_, _| did_ok()); + let url = format!("http://127.0.0.1:{port}"); + let r = doctor_with(Some(&url), None, &env); + let row = public_read_row(&r) + .unwrap_or_else(|| panic!("no removed public-read row for {env:?}:\n{}", r.stdout)); + assert!( + row.contains("Reads follow each repository's visibility."), + "{row}" + ); + assert!( + settings_row(&r).is_none(), + "the removed setting must not be reported as working ({env:?}):\n{}", + r.stdout + ); + assert_eq!( + r.stdout + .matches("TWIGPINE_PUBLIC_READ and GITLAWB_PUBLIC_READ were removed and have no effect. Reads follow each repository's visibility.") + .count(), + 1, + "the removal notice must appear exactly once ({env:?}):\n{}", + r.stdout + ); + } +} + +#[test] +fn the_removed_public_read_row_does_not_hide_other_old_names() { + let (port, _) = serve(|_, _| did_ok()); + let url = format!("http://127.0.0.1:{port}"); + let r = doctor_with( + None, + None, + &[("GITLAWB_NODE", &url), ("GITLAWB_PUBLIC_READ", "false")], + ); + let row = settings_row(&r).unwrap_or_else(|| panic!("no settings row:\n{}", r.stdout)); + assert!(row.contains("TWIGPINE_NODE"), "{row}"); + assert!(!row.contains("PUBLIC_READ"), "{row}"); + assert!( + public_read_row(&r).is_some(), + "no removed public-read row:\n{}", + r.stdout + ); +} + +#[test] +fn no_public_read_row_when_unset() { + let (port, _) = serve(|_, _| did_ok()); + let url = format!("http://127.0.0.1:{port}"); + let r = doctor_with(Some(&url), None, &[]); + assert!(public_read_row(&r).is_none(), "{}", r.stdout); +} diff --git a/crates/twigpine-node/src/config.rs b/crates/twigpine-node/src/config.rs index a339b49f0..a701e2d7c 100644 --- a/crates/twigpine-node/src/config.rs +++ b/crates/twigpine-node/src/config.rs @@ -93,13 +93,6 @@ pub struct Config { #[arg(long, env = "TWIGPINE_KEY", default_value = DEFAULT_KEY_PATH)] pub key_path: String, - /// Reserved and currently inert: read access is enforced per repository - /// through `is_public` and path-scoped visibility rules, not this flag. - /// Setting it to false changes nothing; make a repo private through its - /// own visibility instead. - #[arg(long, env = "TWIGPINE_PUBLIC_READ", default_value_t = true)] - pub public_read: bool, - /// Public URL of this node (for peer announcements) #[arg(long, env = "TWIGPINE_PUBLIC_URL")] pub public_url: Option, @@ -2685,26 +2678,10 @@ mod tests { ); } - /// #338: TWIGPINE_PUBLIC_READ is inert, so its help must not claim read - /// enforcement is missing; it must tell the operator the flag changes - /// nothing and where the real control lives. #[test] - fn public_read_help_describes_the_flag_as_inert() { - use clap::CommandFactory; - let cmd = Config::command(); - let arg = cmd - .get_arguments() - .find(|a| a.get_id() == "public_read") - .expect("the argument must exist"); - let help = arg.get_help().map(|h| h.to_string()).unwrap_or_default(); - assert!( - !help.contains("not wired"), - "the help still claims read enforcement is unwired: {help}" - ); - assert!( - help.contains("inert"), - "the help must say the flag is inert so an operator does not rely on it: {help}" - ); + fn public_read_flag_is_not_accepted() { + let error = Config::try_parse_from(["twigpine-node", "--public-read"]).unwrap_err(); + assert_eq!(error.kind(), clap::error::ErrorKind::UnknownArgument); } /// The flip must not strand an operator mid-upgrade. diff --git a/crates/twigpine-node/src/lib.rs b/crates/twigpine-node/src/lib.rs index b6e337167..d07a6f257 100644 --- a/crates/twigpine-node/src/lib.rs +++ b/crates/twigpine-node/src/lib.rs @@ -105,10 +105,20 @@ pub async fn run() -> Result<()> { let mut config = Config::parse_with_sources(); + const PUBLIC_READ: &str = "TWIGPINE_PUBLIC_READ"; + let mut legacy = twigpine_core::legacy_env::report(); + if std::env::var_os(PUBLIC_READ).is_some() || std::env::var_os("GITLAWB_PUBLIC_READ").is_some() + { + legacy.legacy_only.retain(|name| name != PUBLIC_READ); + legacy.conflicts.retain(|name| name != PUBLIC_READ); + warn!( + "TWIGPINE_PUBLIC_READ and GITLAWB_PUBLIC_READ were removed and have no effect. Reads follow each repository's visibility." + ); + } + // Settings given under their names from before the rename still work // (`main` copied them over before anything read a setting). Say which, by // name only, so an operator can update the unit file at leisure. - let legacy = twigpine_core::legacy_env::report(); if !legacy.legacy_only.is_empty() { info!( settings = %legacy.legacy_only.join(", "), @@ -144,12 +154,6 @@ pub async fn run() -> Result<()> { .validate() .map_err(|e| anyhow::anyhow!("invalid configuration: {e}"))?; - if !config.public_read { - warn!( - "TWIGPINE_PUBLIC_READ=false has no effect; reads are gated per repository by is_public and path-scoped visibility rules, not this flag" - ); - } - // Load or generate the node's identity keypair let keypair = Arc::new(load_or_create_keypair(&config)?); // Sealing key for the legacy-scan continuation tokens, DERIVED from the identity diff --git a/crates/twigpine-node/tests/public_read_startup.rs b/crates/twigpine-node/tests/public_read_startup.rs new file mode 100644 index 000000000..25e0a16db --- /dev/null +++ b/crates/twigpine-node/tests/public_read_startup.rs @@ -0,0 +1,39 @@ +use std::process::Command; + +#[test] +fn warns_once_for_either_removed_public_read_env_var() { + let warning = "TWIGPINE_PUBLIC_READ and GITLAWB_PUBLIC_READ were removed and have no effect. Reads follow each repository's visibility."; + for (current, legacy) in [ + (None, None), + (Some(""), None), + (None, Some("false")), + (Some("true"), Some("false")), + ] { + let mut cmd = Command::new(env!("CARGO_BIN_EXE_twigpine-node")); + cmd.env_clear().env("RUST_LOG", "info").args([ + "--upstream-mirror-enabled", + "--enforce-owner-push", + "false", + ]); + if let Some(value) = current { + cmd.env("TWIGPINE_PUBLIC_READ", value); + } + if let Some(value) = legacy { + cmd.env("GITLAWB_PUBLIC_READ", value); + } + let output = cmd.output().unwrap(); + let stdout = String::from_utf8_lossy(&output.stdout); + let stderr = String::from_utf8_lossy(&output.stderr); + assert!(!output.status.success()); + assert!(stderr.contains("invalid configuration: TWIGPINE_UPSTREAM_MIRROR_ENABLED requires")); + assert_eq!( + stdout.matches(warning).count(), + usize::from(current.is_some() || legacy.is_some()), + "{stdout}" + ); + assert!(!stdout.contains("these settings were given under their old GITLAWB_ names")); + assert!( + !stdout.contains("these settings have a different value under their old GITLAWB_ name") + ); + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 516aebfcd..fca86ece5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -57,7 +57,6 @@ services: # rolling-upgrade opt-out reachable for an operator running compose. TWIGPINE_ENFORCE_OWNER_PUSH: ${TWIGPINE_ENFORCE_OWNER_PUSH:-${GITLAWB_ENFORCE_OWNER_PUSH:-true}} TWIGPINE_P2P_BOOTSTRAP: ${TWIGPINE_P2P_BOOTSTRAP:-${GITLAWB_P2P_BOOTSTRAP:-}} - TWIGPINE_PUBLIC_READ: ${TWIGPINE_PUBLIC_READ:-${GITLAWB_PUBLIC_READ:-true}} TWIGPINE_MAX_PACK_BYTES: ${TWIGPINE_MAX_PACK_BYTES:-${GITLAWB_MAX_PACK_BYTES:-2147483648}} # Sync TWIGPINE_AUTO_SYNC: ${TWIGPINE_AUTO_SYNC:-${GITLAWB_AUTO_SYNC:-false}} diff --git a/docs/OSS-READINESS-AUDIT.md b/docs/OSS-READINESS-AUDIT.md index ecc504a69..4facbd7cd 100644 --- a/docs/OSS-READINESS-AUDIT.md +++ b/docs/OSS-READINESS-AUDIT.md @@ -95,7 +95,7 @@ Live-network blockers to prioritize: - GraphQL POST is still open for compatibility; GraphQL mutations should get mutation-aware auth before it becomes a public write API surface. - Push authorization is still not capability-complete. A valid DID signature is authentication, not authorization. Owner checks are now enforced on every branch, protected or not (`GITLAWB_ENFORCE_OWNER_PUSH`, on by default); what remains is that a UCAN `git/push` capability is not yet honored, so a delegated or CI key cannot push. - UCAN chain validation is incomplete and UCAN revocation/blocklisting is not implemented as an operator feature. -- Private repository reads are enforced per repository through `is_public` and path-scoped visibility rules. `GITLAWB_PUBLIC_READ` remains reserved and inert. +- Private repository reads are enforced per repository through `is_public` and path-scoped visibility rules. - Peer URLs are self-asserted by DIDs. Signatures prove control of the DID key when present, not ownership/safety of the announced URL. - Outbound peer fetch/ping/sync paths should be reviewed for SSRF protections before accepting arbitrary public peer registrations. @@ -146,11 +146,10 @@ Risks: ## Obvious live-network priorities 1. Implement repo write authorization: owner checks, UCAN capability checks, and clear delegation semantics for push/PR/issue/bounty operations. -2. Private reads are already enforced per repository (`is_public` plus path-scoped rules); retire the reserved and inert `GITLAWB_PUBLIC_READ` flag or document it as permanently reserved. -3. Add UCAN revocation/blocklisting and operator docs for emergency key compromise. -4. Harden peer registration and outbound fetch behavior against SSRF and peer-list poisoning. -5. Add Docker/installer/release smoke tests to CI. -6. Label PoS/economics docs consistently with the current live contract and rewards status. +2. Add UCAN revocation/blocklisting and operator docs for emergency key compromise. +3. Harden peer registration and outbound fetch behavior against SSRF and peer-list poisoning. +4. Add Docker/installer/release smoke tests to CI. +5. Label PoS/economics docs consistently with the current live contract and rewards status. ## Status updates (post-snapshot)