Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ and listed with their assets on the
worktree… in its menu; the same menu opens from a lane's "…" button or a
right click on its row in the branch picker. The separate "Stop
worktree" and "Discard data" buttons are gone.
- **A pool names MCP upstreams for its members** (ADR-0069 option B):
`devstack pool upstreams add|remove` (admins) or the pool area of the
dashboard keep a list of URLs on the coordinator, never a secret or a
command, each change in the audit log. Each member's hub offers them on
its *MCP upstreams* page, from which pool, and uses one only once its
user accepted it, with that user's own login; a new URL is accepted
again, the user's own upstreams go first, and an entry the pool drops
goes with its login.

### Changed

Expand Down Expand Up @@ -71,6 +79,10 @@ and listed with their assets on the
- **The dashboard's MCP upstreams page** has the spacing of the other
cards: a header with the Add button, the text and the form inside the
card's padding instead of on its border.
- **Logins in the Windows Credential Manager** can no longer be lost when
two are written or removed at once (seen in the tests; parallel tool
calls refreshing tokens could do it): the hub makes one keychain call at
a time.

## [0.27.1] - 2026-10-28

Expand Down
58 changes: 58 additions & 0 deletions crates/devstack-hub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,14 @@ pub fn serve() -> Result<(), String> {
)
.map_err(|e| e.to_string())?;
notify::start(state.clone());
// The pools' MCP upstreams (ADR-0069 option B), off the requests.
let ups = state.upstreams.clone();
std::thread::spawn(move || {
loop {
ups.refresh_pools();
std::thread::sleep(upstreams::POOLS_EVERY);
}
});
tray::start_quietly();
let app = router(state);
if let Some(v6) = v6 {
Expand Down Expand Up @@ -493,6 +501,14 @@ fn router(state: AppState) -> axum::Router {
.route("/hub/upstreams/{name}/login", post(upstream_login))
.route("/hub/upstreams/{name}/token", post(upstream_token))
.route("/hub/upstreams/{name}/logout", post(upstream_logout))
.route(
"/hub/upstreams/pool/{pool}/{name}/accept",
post(upstream_accept),
)
.route(
"/hub/upstreams/pool/{pool}/{name}/decline",
post(upstream_decline),
)
.route("/hub/pair", post(pair))
.route("/hub/shutdown", post(shutdown))
.route("/hub/session", get(session))
Expand Down Expand Up @@ -567,6 +583,11 @@ fn router(state: AppState) -> axum::Router {
get(pool::telemetry).put(pool::set_telemetry),
)
.route("/hub/pool/nodes/{id}/policy", post(pool::policy))
.route(
"/hub/pool/upstreams",
get(pool::upstreams).post(pool::upstream_put),
)
.route("/hub/pool/upstreams/{name}", delete(pool::upstream_remove))
.route("/hub/pool/join", post(pool::join))
.fallback(get(asset))
.layer(middleware::from_fn_with_state(state.clone(), guard))
Expand Down Expand Up @@ -2513,6 +2534,43 @@ async fn upstream_remove(State(s): State<AppState>, Path(name): Path<String>) ->
.await
}

#[derive(Deserialize, Default)]
struct AcceptBody {
/// A prefix of the user's instead of the pool's.
#[serde(default)]
prefix: Option<String>,
}

/// `POST /hub/upstreams/pool/{pool}/{name}/accept {prefix?}`: use an
/// upstream a pool names, at the URL it names now (ADR-0069 option B).
async fn upstream_accept(
State(s): State<AppState>,
Path((pool, name)): Path<(String, String)>,
body: Option<Json<AcceptBody>>,
) -> Response {
let b = body.map(|Json(b)| b).unwrap_or_default();
let what = serde_json::json!({ "pool": pool, "upstream": name });
let r = on_upstreams(&s, move |ups| ups.accept(&pool, &name, b.prefix)).await;
if r.status().is_success() {
diag::info("upstream_accept", what);
}
r
}

/// `POST /hub/upstreams/pool/{pool}/{name}/decline`: do not use it; its
/// login goes.
async fn upstream_decline(
State(s): State<AppState>,
Path((pool, name)): Path<(String, String)>,
) -> Response {
let what = serde_json::json!({ "pool": pool, "upstream": name });
let r = on_upstreams(&s, move |ups| ups.decline(&pool, &name)).await;
if r.status().is_success() {
diag::info("upstream_decline", what);
}
r
}

#[derive(Deserialize)]
struct TokenBody {
token: String,
Expand Down
50 changes: 50 additions & 0 deletions crates/devstack-hub/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
//! - `POST /hub/pool/join` `{coordinator, fingerprint, name?}`: ask to join a
//! pool (`devstack join` without waiting)
//! - `GET /hub/pools`: the pools this machine belongs to (ADR-0034)
//! - `GET /hub/pool/upstreams`: the MCP upstreams the pool names for its
//! members; `POST /hub/pool/upstreams` (one), `DELETE
//! /hub/pool/upstreams/{name}`: an admin's changes (ADR-0069 option B)
//!
//! Each takes `?pool=<name>`; without it, the default pool.

Expand Down Expand Up @@ -557,6 +560,53 @@ pub async fn role(
}
}

/// `GET /hub/pool/upstreams`: the MCP upstreams the pool names for its
/// members (ADR-0069 option B).
pub async fn upstreams(Query(q): Query<PoolQuery>) -> Response {
match blocking(&q, |l| l.upstreams()).await {
Ok(v) => Json(v).into_response(),
Err(e) => error(&e),
}
}

/// This hub asks its pools again now: an admin changed a list.
fn refresh(s: &crate::AppState) {
let ups = s.upstreams.clone();
tokio::task::spawn_blocking(move || ups.refresh_pools());
}

/// `POST /hub/pool/upstreams`: add an upstream to the pool's list, or
/// change the one of its name (admins).
pub async fn upstream_put(
axum::extract::State(s): axum::extract::State<crate::AppState>,
Query(q): Query<PoolQuery>,
Json(u): Json<devstack_node::upstreams::PoolUpstream>,
) -> Response {
match blocking(&q, move |l| l.admin_upstream_put(&u)).await {
Ok(v) => {
refresh(&s);
Json(v).into_response()
}
Err(e) => error(&e),
}
}

/// `DELETE /hub/pool/upstreams/{name}`: take an upstream off the pool's
/// list (admins).
pub async fn upstream_remove(
axum::extract::State(s): axum::extract::State<crate::AppState>,
Path(name): Path<String>,
Query(q): Query<PoolQuery>,
) -> Response {
match blocking(&q, move |l| l.admin_upstream_remove(&name)).await {
Ok(()) => {
refresh(&s);
StatusCode::NO_CONTENT.into_response()
}
Err(e) => error(&e),
}
}

#[cfg(test)]
mod tests {
#[test]
Expand Down
31 changes: 25 additions & 6 deletions crates/devstack-hub/src/secrets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ impl Secrets {
Self::open_as(SERVICE, dir)
}

fn open_as(service: &str, dir: PathBuf) -> Self {
/// [`Self::open`] under another service (tests: one each, so tests
/// running side by side, and the user's own entries, stay apart).
pub(crate) fn open_as(service: &str, dir: PathBuf) -> Self {
if probe(service) {
return Self {
store: Store::Keychain {
Expand Down Expand Up @@ -81,7 +83,10 @@ impl Secrets {
/// The secret of `upstream`; `None` when there is none.
pub fn get(&self, upstream: &str) -> Result<Option<String>, String> {
match &self.store {
Store::Keychain { service } => match entry(service, upstream)?.get_password() {
Store::Keychain { service } => match entry(service, upstream).map(|e| {
let _one = keychain();
e.get_password()
})? {
Ok(s) => Ok(Some(s)),
Err(keyring::Error::NoEntry) => Ok(None),
Err(e) => Err(e.to_string()),
Expand All @@ -96,9 +101,11 @@ impl Secrets {

pub fn set(&self, upstream: &str, secret: &str) -> Result<(), String> {
match &self.store {
Store::Keychain { service } => entry(service, upstream)?
.set_password(secret)
.map_err(|e| e.to_string()),
Store::Keychain { service } => {
let e = entry(service, upstream)?;
let _one = keychain();
e.set_password(secret).map_err(|e| e.to_string())
}
Store::File { path, lock } => {
let _held = lock.lock().unwrap();
let mut all = read_file(path)?;
Expand All @@ -112,7 +119,10 @@ impl Secrets {
/// Forget the secret of `upstream`; none there is no error.
pub fn delete(&self, upstream: &str) -> Result<(), String> {
match &self.store {
Store::Keychain { service } => match entry(service, upstream)?.delete_credential() {
Store::Keychain { service } => match entry(service, upstream).map(|e| {
let _one = keychain();
e.delete_credential()
})? {
Ok(()) | Err(keyring::Error::NoEntry) => Ok(()),
Err(e) => Err(e.to_string()),
},
Expand All @@ -129,6 +139,15 @@ impl Secrets {
}
}

/// Held for each call into the keychain: the Windows Credential Manager
/// loses writes and deletes made side by side from several threads (seen in
/// the tests; the hub refreshes logins of parallel tool calls).
fn keychain() -> std::sync::MutexGuard<'static, ()> {
static ONE: Mutex<()> = Mutex::new(());
ONE.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner)
}

fn entry(service: &str, upstream: &str) -> Result<keyring::Entry, String> {
keyring::Entry::new(service, &format!("upstream:{upstream}")).map_err(|e| e.to_string())
}
Expand Down
Loading
Loading