From 404930a09ad79c62f67db7af5312627909def633 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 14:04:32 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m1/precut-fixes/archive-url-logs.md Quest-Claim: 490637380a8fa551 From 8ca1a08f8f2d1eff5622c63db33ee4623dcfd44e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 14:11:48 -0800 Subject: [PATCH 2/2] fix(cli): archive diagnostics redact the store URL Recording and replay logged the raw store URL at INFO, and opening a store quoted it in errors, along with object_store's own messages, which echo the URL they were given. Log every store URL through moq_tokio::RedactedUrl, scrub the raw URL out of object_store's error chain, and refuse a password, query, or fragment in the URL, which no store reads. Co-Authored-By: Claude Opus 5.5 --- doc/bin/cli.md | 4 +- quest/m1/precut-fixes/archive-url-logs.md | 9 ---- rs/moq-cli/src/archive.rs | 66 ++++++++++++++++++----- 3 files changed, 56 insertions(+), 23 deletions(-) delete mode 100644 quest/m1/precut-fixes/archive-url-logs.md diff --git a/doc/bin/cli.md b/doc/bin/cli.md index 9bc61b1445..a84872d319 100644 --- a/doc/bin/cli.md +++ b/doc/bin/cli.md @@ -382,7 +382,9 @@ import URL, URL-encode its literal `%` characters too: instance `a/b` records un Store URLs are `file:///absolute/path`, `s3://bucket/prefix`, `gs://bucket/prefix`, or `az://container/prefix`, with credentials from the -usual `AWS_*`, `GOOGLE_*`, and `AZURE_*` environment variables. +usual `AWS_*`, `GOOGLE_*`, and `AZURE_*` environment variables. A store URL +with a password, query, or fragment is refused, since no store reads them, and +logs and errors print it without its userinfo. ## Multiple stages diff --git a/quest/m1/precut-fixes/archive-url-logs.md b/quest/m1/precut-fixes/archive-url-logs.md deleted file mode 100644 index d903a43621..0000000000 --- a/quest/m1/precut-fixes/archive-url-logs.md +++ /dev/null @@ -1,9 +0,0 @@ -# [S] Redact store credentials in archive diagnostics - -## Goal - -Archive recording, replay and store setup expose only redacted store URLs in normal logs and error chains. - -## Plan - -A synthetic query marker was visible in the unsupported-store error in rs/moq-cli/src/archive.rs. Recording and replay also format the raw URL at INFO. The error formatter dates to [moq-dev/moq#7571](https://github.com/moq-dev/moq/pull/7571). Reuse moq_tokio::RedactedUrl and check representative success and failure diagnostics with synthetic userinfo and query data. diff --git a/rs/moq-cli/src/archive.rs b/rs/moq-cli/src/archive.rs index 7c583662aa..d04b50d33f 100644 --- a/rs/moq-cli/src/archive.rs +++ b/rs/moq-cli/src/archive.rs @@ -6,6 +6,7 @@ use std::sync::Arc; use std::time::Duration; use anyhow::Context; +use moq_tokio::RedactedUrl; use object_store::path::{Path, PathPart}; use object_store::{ObjectStore, ObjectStoreScheme}; use url::Url; @@ -81,7 +82,7 @@ pub async fn export(origin: moq_net::origin::Consumer, prefix: String, args: Exp let mut running = Running::default(); let claims = Claims::default(); - tracing::info!(%prefix, store = %args.store, "recording"); + tracing::info!(%prefix, store = %RedactedUrl::new(&args.store), "recording"); notify_ready(); loop { @@ -307,6 +308,7 @@ pub async fn import( instance: moq_net::Instance, ) -> anyhow::Result<()> { let store = open(&args.store)?; + let url = RedactedUrl::new(&args.store); let mut config = moq_archive::consumer::Config::default(); if let Some(refresh) = args.refresh { config = config.with_refresh(refresh.into()); @@ -320,22 +322,32 @@ pub async fn import( .context("failed to create broadcast")?; let consumer = moq_archive::Consumer::open(store, route.broadcast().clone(), config) .await - .with_context(|| format!("no readable recording at {}", args.store))?; + .with_context(|| format!("no readable recording at {url}"))?; route.announce().context("failed to announce broadcast")?; - tracing::info!(%name, store = %args.store, "replaying"); + tracing::info!(%name, store = %url, "replaying"); notify_ready(); - consumer - .run() - .await - .with_context(|| format!("replaying {} failed", args.store)) + consumer.run().await.with_context(|| format!("replaying {url} failed")) } /// Open the object store `url` names, taking cloud credentials from the `AWS_*`, `GOOGLE_*`, /// and `AZURE_*` environment variables, with the prefix the URL names. +/// +/// A password, query, or fragment is refused: no store reads one, and object_store echoes the +/// URL it was given in its errors, so refusing them keeps credentials out of every message. fn open_store(url: &Url) -> anyhow::Result<(Arc, Path)> { - let unsupported = || format!("unsupported archive store {url}"); - let (scheme, prefix) = ObjectStoreScheme::parse(url).with_context(unsupported)?; + let redacted = RedactedUrl::new(url).to_string(); + anyhow::ensure!( + url.password().is_none() && url.query().is_none() && url.fragment().is_none(), + "archive store {redacted} has a password, query, or fragment, which no store reads; \ + pass credentials through the environment instead", + ); + // object_store quotes the URL it was given, userinfo included, so its message is redacted too. + let unsupported = |err: anyhow::Error| { + let reason = format!("{err:#}").replace(url.as_str(), &redacted); + anyhow::anyhow!(reason).context(format!("unsupported archive store {redacted}")) + }; + let (scheme, prefix) = ObjectStoreScheme::parse(url).map_err(|err| unsupported(err.into()))?; // Each cloud builder signs through rind, which `parse_url_opts` has no way to pass. let store: Arc = match scheme { ObjectStoreScheme::Local => Arc::new(object_store::local::LocalFileSystem::new()), @@ -345,7 +357,7 @@ fn open_store(url: &Url) -> anyhow::Result<(Arc, Path)> { .with_url(url.as_str()) .with_crypto_provider(rind_object_store::default_provider()?) .build() - .with_context(unsupported)?, + .map_err(|err| unsupported(err.into()))?, ), #[cfg(feature = "gcs")] ObjectStoreScheme::GoogleCloudStorage => Arc::new( @@ -353,7 +365,7 @@ fn open_store(url: &Url) -> anyhow::Result<(Arc, Path)> { .with_url(url.as_str()) .with_crypto_provider(rind_object_store::default_provider()?) .build() - .with_context(unsupported)?, + .map_err(|err| unsupported(err.into()))?, ), #[cfg(feature = "azure")] ObjectStoreScheme::MicrosoftAzure => Arc::new( @@ -361,9 +373,9 @@ fn open_store(url: &Url) -> anyhow::Result<(Arc, Path)> { .with_url(url.as_str()) .with_crypto_provider(rind_object_store::default_provider()?) .build() - .with_context(unsupported)?, + .map_err(|err| unsupported(err.into()))?, ), - _ => anyhow::bail!(unsupported()), + _ => anyhow::bail!("unsupported archive store {redacted}"), }; Ok((store, prefix)) } @@ -774,4 +786,32 @@ mod tests { .unwrap(); assert!(literal.as_ref().starts_with("rec/live/a/%2540"), "{literal}"); } + + /// A store URL that fails to open is reported without its userinfo or query, whichever + /// layer refuses it. + #[test] + fn a_refused_store_hides_its_credentials() { + let mut urls = vec![ + // Refused up front: no store reads a password, query, or fragment. + "s3://user:SECRET@bucket/prefix", + "file:///rec?token=SECRET", + "file:///rec#SECRET", + // Refused by object_store, which quotes the URL it was given. + "ftp://SECRET@example.com/rec", + // Recognised, but not a store an archive opens. + "https://SECRET@example.com/rec", + ]; + if cfg!(feature = "azure") { + urls.push("az://SECRET@account.example.com/rec"); + } + for url in urls { + let url = Url::parse(url).unwrap(); + let Err(err) = open(&url) else { + panic!("{url} opened"); + }; + let err = format!("{err:#} {err:?}"); + assert!(!err.contains("SECRET"), "{err}"); + assert!(err.contains(&RedactedUrl::new(&url).to_string()), "{err}"); + } + } }