From 9d2f6a090763e7fc1c9c99d9e99ce3d75f1a092a Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Tue, 27 Oct 2026 18:47:26 +0100 Subject: [PATCH] feat(hub): a store for the secrets of upstream MCP servers (ADR-0069) The first part of ADR-0069: `secrets::Secrets` keeps a secret per upstream in the OS keychain (`keyring` 4: Windows Credential Manager, macOS Keychain, the Linux Secret Service). A Linux machine without a Secret Service gets a `secrets.json` in the hub's state directory, readable by the user alone; a probe entry decides. Nothing uses it yet and no route hands a secret out. ADR-0069 amended with the spike: the crate, its licences, the Linux fallback. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 599 +++++++++++++++++- Cargo.toml | 2 + crates/devstack-hub/Cargo.toml | 1 + crates/devstack-hub/src/lib.rs | 1 + crates/devstack-hub/src/secrets.rs | 201 ++++++ ...carry-the-tools-of-upstream-mcp-servers.md | 20 +- docs/adr/README.md | 2 +- 7 files changed, 820 insertions(+), 6 deletions(-) create mode 100644 crates/devstack-hub/src/secrets.rs diff --git a/Cargo.lock b/Cargo.lock index 6beb57b6..5ee94b07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" +[[package]] +name = "aes" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35f0f96ce78e38c3dc6d8948aa8163d06385be74000f3c7a95bf1eef35d3ea32" +dependencies = [ + "cipher", + "cpubits", + "cpufeatures 0.3.1", +] + [[package]] name = "aho-corasick" version = "1.1.5" @@ -73,6 +84,17 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" +[[package]] +name = "apple-native-keyring-store" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b350bfd03649e07aa05c0a81b3e15934374e585c98204a57e20b9d49f49bb9a" +dependencies = [ + "keyring-core", + "log", + "security-framework", +] + [[package]] name = "arrayvec" version = "0.7.8" @@ -118,6 +140,126 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "async-broadcast" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532" +dependencies = [ + "event-listener", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "pin-project-lite", + "slab", +] + +[[package]] +name = "async-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" +dependencies = [ + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-lock" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-process" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75" +dependencies = [ + "async-channel", + "async-io", + "async-lock", + "async-signal", + "async-task", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "rustix", +] + +[[package]] +name = "async-recursion" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f8abc12baad266b1c8cec146854c195b5864b4221d4b2ca7296a7ae82d9e451" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + +[[package]] +name = "async-signal" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix", + "signal-hook-registry", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + [[package]] name = "async-trait" version = "0.1.92" @@ -260,6 +402,15 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "block-padding" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "710f1dd022ef4e93f8a438b4ba958de7f64308434fa6a87104481645cc30068b" +dependencies = [ + "hybrid-array", +] + [[package]] name = "block2" version = "0.6.2" @@ -269,6 +420,19 @@ dependencies = [ "objc2", ] +[[package]] +name = "blocking" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa" +dependencies = [ + "async-channel", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + [[package]] name = "bstr" version = "1.13.1" @@ -285,12 +449,27 @@ version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" +[[package]] +name = "cbc" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce2dc9ee5f88d11e0beb842c88b33c8a5cf0d1329c4b19494af42b07dbfe8896" +dependencies = [ + "cipher", +] + [[package]] name = "cc" version = "1.8.0" @@ -324,6 +503,16 @@ dependencies = [ "rand_core 0.10.1", ] +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "crypto-common 0.2.2", + "inout", +] + [[package]] name = "clap" version = "4.6.7" @@ -364,6 +553,12 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + [[package]] name = "colorchoice" version = "1.0.5" @@ -380,6 +575,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "const-oid" version = "0.10.2" @@ -408,6 +612,12 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -479,6 +689,15 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "ctutils" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe3e9d21d39e6f39ff46e03d5b621424f88ee23d8a1672c6bfc9ccc7f2da4f6a" +dependencies = [ + "cmov", +] + [[package]] name = "data-encoding" version = "2.11.1" @@ -664,7 +883,7 @@ dependencies = [ "tokio-stream", "windows", "windows-sys 0.61.2", - "zbus", + "zbus 6.0.0", ] [[package]] @@ -694,6 +913,7 @@ dependencies = [ "hyper", "hyper-util", "include_dir", + "keyring", "rand 0.10.3", "serde", "serde_json", @@ -776,6 +996,7 @@ dependencies = [ "block-buffer 0.12.1", "const-oid", "crypto-common 0.2.2", + "ctutils", ] [[package]] @@ -813,6 +1034,27 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099" +[[package]] +name = "enumflags2" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef" +dependencies = [ + "enumflags2_derive", + "serde", +] + +[[package]] +name = "enumflags2_derive" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "equivalent" version = "1.0.3" @@ -829,6 +1071,26 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "event-listener" +version = "5.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2" +dependencies = [ + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + [[package]] name = "fastrand" version = "2.5.0" @@ -892,6 +1154,30 @@ version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" +[[package]] +name = "futures-lite" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.9", +] + [[package]] name = "futures-sink" version = "0.3.34" @@ -911,6 +1197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" dependencies = [ "futures-core", + "futures-macro", "futures-sink", "futures-task", "pin-project-lite", @@ -987,12 +1274,36 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" + [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hkdf" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4aaa26c720c68b866f2c96ef5c1264b3e6f473fe5d4ce61cd44bbe913e553018" +dependencies = [ + "hmac", +] + +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.3", +] + [[package]] name = "http" version = "1.5.0" @@ -1148,6 +1459,16 @@ dependencies = [ "libc", ] +[[package]] +name = "inout" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b5cf4372d022092674a83b8febf5865f7a573cc0c5baec5e49c879b6a20978f" +dependencies = [ + "block-padding", + "hybrid-array", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.2" @@ -1284,6 +1605,27 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "keyring" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2270074a3d26bcac93c1dc5d2845eb4c089e8d761ccf6e0ea266a16004640627" +dependencies = [ + "apple-native-keyring-store", + "keyring-core", + "windows-native-keyring-store", + "zbus-secret-service-keyring-store", +] + +[[package]] +name = "keyring-core" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29fbf4b551298c67925f38cf341a1ada797a75f1837bdf8ae1fc8e2ebc6efb59" +dependencies = [ + "log", +] + [[package]] name = "kqueue" version = "1.2.1" @@ -1438,6 +1780,20 @@ dependencies = [ "bitflags 2.13.2", ] +[[package]] +name = "num" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + [[package]] name = "num-bigint" version = "0.4.8" @@ -1448,6 +1804,15 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-complex" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" +dependencies = [ + "num-traits", +] + [[package]] name = "num-conv" version = "0.2.2" @@ -1463,6 +1828,27 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-iter" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92800bd69a1eac91786bcfe9da64a897eb72911b8dc3095decbd07429e8048b" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" +dependencies = [ + "num-bigint", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.19" @@ -1559,6 +1945,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "pem" version = "4.0.0" @@ -1581,6 +1973,31 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "piper" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix", + "windows-sys 0.61.2", +] + [[package]] name = "pollster" version = "0.4.0" @@ -1617,6 +2034,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.107" @@ -1966,6 +2392,25 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "secret-service" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5107b24b91445dd2aa449a258a1807b63240942157292354dc5bfdbeb8bc6db8" +dependencies = [ + "aes", + "cbc", + "futures-util", + "getrandom 0.4.3", + "hkdf", + "hybrid-array", + "num", + "once_cell", + "serde", + "sha2", + "zbus 5.19.0", +] + [[package]] name = "security-framework" version = "3.7.0" @@ -2397,6 +2842,18 @@ dependencies = [ "serde_core", ] +[[package]] +name = "toml_edit" +version = "0.25.17+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3641d5bbb5349a79e1020a242d251efbc546ad8048d133958323ce9c40a9c9c" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + [[package]] name = "toml_parser" version = "1.1.5+spec-1.1.0" @@ -2448,9 +2905,21 @@ checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "tracing-core" version = "0.1.36" @@ -2776,6 +3245,19 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-native-keyring-store" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063426e76fdec7438d56bb777f67e318a84a25c707b07e575cb8b78e10c028f8" +dependencies = [ + "byteorder", + "keyring-core", + "regex", + "windows-sys 0.61.2", + "zeroize", +] + [[package]] name = "windows-numerics" version = "0.3.1" @@ -3022,6 +3504,41 @@ dependencies = [ "time", ] +[[package]] +name = "zbus" +version = "5.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5db4be7c075cb421e4b7ee645541604239bd243ba7c357511f4ff3a74b555907" +dependencies = [ + "async-broadcast", + "async-executor", + "async-io", + "async-lock", + "async-process", + "async-recursion", + "async-task", + "async-trait", + "blocking", + "enumflags2", + "event-listener", + "futures-core", + "futures-lite", + "hex", + "libc", + "ordered-stream", + "rustix", + "serde", + "serde_repr", + "tracing", + "uds_windows", + "uuid", + "windows-sys 0.61.2", + "winnow", + "zbus_macros 5.19.0", + "zbus_names", + "zvariant", +] + [[package]] name = "zbus" version = "6.0.0" @@ -3044,12 +3561,38 @@ dependencies = [ "uuid", "windows-sys 0.61.2", "winnow", - "zbus_macros", + "zbus_macros 6.0.0", "zbus_utils", "zcheapstr", "zruntime", ] +[[package]] +name = "zbus-secret-service-keyring-store" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74801d001b9e7729adb4f1825b67b398185fed424749aa3d8bacf70417137d9a" +dependencies = [ + "keyring-core", + "secret-service", + "zbus 5.19.0", +] + +[[package]] +name = "zbus_macros" +version = "5.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2990635d09ade6df1868f72f8cac69a876a90981e8bd3c40b1be413f8dc88f40" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 3.0.9", + "zbus_names", + "zvariant", + "zvariant_utils", +] + [[package]] name = "zbus_macros" version = "6.0.0" @@ -3062,6 +3605,17 @@ dependencies = [ "zbus_utils", ] +[[package]] +name = "zbus_names" +version = "4.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812a12be4ead7a59e18ea8f047d08add0066b73bc62fc1467066a2472ae088dd" +dependencies = [ + "serde", + "winnow", + "zvariant", +] + [[package]] name = "zbus_utils" version = "6.0.0" @@ -3158,3 +3712,44 @@ dependencies = [ "futures-core", "futures-io", ] + +[[package]] +name = "zvariant" +version = "5.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80bf6d6cd6a4b601acb64cfb8284cdc643fcfa75ef26ae3c46ec8aa4e8a1fbb7" +dependencies = [ + "endi", + "enumflags2", + "serde", + "winnow", + "zcheapstr", + "zvariant_derive", + "zvariant_utils", +] + +[[package]] +name = "zvariant_derive" +version = "5.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2672456ba1cb54b5eaec136e63135b3c7495fb938e53b28a62e633496d486d" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 3.0.9", + "zvariant_utils", +] + +[[package]] +name = "zvariant_utils" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn 3.0.9", + "winnow", +] diff --git a/Cargo.toml b/Cargo.toml index 6e4ff321..77395b89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,8 @@ http-body-util = "0.1" hyper = { version = "1", features = ["client", "server", "http1"] } hyper-util = { version = "0.1", features = ["tokio"] } include_dir = "0.7" +# The hub's secrets of upstream MCP servers in the OS keychain (ADR-0069). +keyring = "4" junction = { version = "2", default-features = false } jiff = "0.2" libc = "0.2" diff --git a/crates/devstack-hub/Cargo.toml b/crates/devstack-hub/Cargo.toml index 01aa0d25..79205601 100644 --- a/crates/devstack-hub/Cargo.toml +++ b/crates/devstack-hub/Cargo.toml @@ -23,6 +23,7 @@ http-body-util.workspace = true hyper.workspace = true hyper-util.workspace = true include_dir.workspace = true +keyring.workspace = true rand.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/crates/devstack-hub/src/lib.rs b/crates/devstack-hub/src/lib.rs index 06f449e0..741369cf 100644 --- a/crates/devstack-hub/src/lib.rs +++ b/crates/devstack-hub/src/lib.rs @@ -43,6 +43,7 @@ mod open; mod pool; mod prompts; pub mod release; +pub mod secrets; mod share; mod shared; mod summary; diff --git a/crates/devstack-hub/src/secrets.rs b/crates/devstack-hub/src/secrets.rs new file mode 100644 index 00000000..1c4dc3c9 --- /dev/null +++ b/crates/devstack-hub/src/secrets.rs @@ -0,0 +1,201 @@ +//! Where the hub keeps the secrets of the user's upstream MCP servers +//! (ADR-0069): their OAuth tokens and static bearer tokens. In the OS's +//! keychain (Windows Credential Manager, macOS Keychain, the Secret Service +//! on Linux), one entry per upstream. A Linux machine without a Secret +//! Service (a server, a headless session) has none: there they go into a +//! file only the user may read, beside the hub's other state, and +//! [`Secrets::kind`] says so for the dashboard to show. +//! +//! Nothing here leaves the hub: no route hands a secret out (no token +//! passthrough, ADR-0069). + +use std::collections::BTreeMap; +use std::path::PathBuf; +use std::sync::Mutex; + +/// The keychain's service name; each upstream is an account under it. +const SERVICE: &str = "devstack"; + +/// Where [`Secrets`] keeps them. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum Kind { + /// The OS's keychain. + Keychain, + /// A file only the user may read (Linux without a Secret Service). + File, +} + +pub struct Secrets { + store: Store, +} + +enum Store { + Keychain { service: String }, + File { path: PathBuf, lock: Mutex<()> }, +} + +impl Secrets { + /// The keychain when it takes, gives back and forgets a probe entry; + /// else (Linux only) the file `secrets.json` in `dir`. + pub fn open(dir: PathBuf) -> Self { + Self::open_as(SERVICE, dir) + } + + fn open_as(service: &str, dir: PathBuf) -> Self { + if probe(service) { + return Self { + store: Store::Keychain { + service: service.to_string(), + }, + }; + } + Self { + store: Store::File { + path: dir.join("secrets.json"), + lock: Mutex::new(()), + }, + } + } + + pub fn kind(&self) -> Kind { + match self.store { + Store::Keychain { .. } => Kind::Keychain, + Store::File { .. } => Kind::File, + } + } + + /// The secret of `upstream`; `None` when there is none. + pub fn get(&self, upstream: &str) -> Result, String> { + match &self.store { + Store::Keychain { service } => match entry(service, upstream)?.get_password() { + Ok(s) => Ok(Some(s)), + Err(keyring::Error::NoEntry) => Ok(None), + Err(e) => Err(e.to_string()), + }, + Store::File { path, lock } => { + let _held = lock.lock().unwrap(); + Ok(read_file(path)?.remove(upstream)) + } + } + } + + 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::File { path, lock } => { + let _held = lock.lock().unwrap(); + let mut all = read_file(path)?; + all.insert(upstream.to_string(), secret.to_string()); + write_file(path, &all) + } + } + } + + /// 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() { + Ok(()) | Err(keyring::Error::NoEntry) => Ok(()), + Err(e) => Err(e.to_string()), + }, + Store::File { path, lock } => { + let _held = lock.lock().unwrap(); + let mut all = read_file(path)?; + if all.remove(upstream).is_some() { + write_file(path, &all)?; + } + Ok(()) + } + } + } +} + +fn entry(service: &str, upstream: &str) -> Result { + keyring::Entry::new(service, &format!("upstream:{upstream}")).map_err(|e| e.to_string()) +} + +/// The keychain works here: a probe entry is written, read and removed. +/// Elsewhere than Linux it is the keychain even when the probe fails: a +/// locked keychain is said when a secret is used, not worked around. +fn probe(service: &str) -> bool { + if !cfg!(target_os = "linux") { + return true; + } + let Ok(e) = keyring::Entry::new(service, "probe") else { + return false; + }; + let ok = e.set_password("probe").is_ok() && e.get_password().is_ok_and(|p| p == "probe"); + let _ = e.delete_credential(); + ok +} + +fn read_file(path: &std::path::Path) -> Result, String> { + match std::fs::read(path) { + Ok(bytes) => serde_json::from_slice(&bytes).map_err(|e| format!("{}: {e}", path.display())), + Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(BTreeMap::new()), + Err(e) => Err(format!("{}: {e}", path.display())), + } +} + +fn write_file(path: &std::path::Path, all: &BTreeMap) -> Result<(), String> { + if let Some(dir) = path.parent() { + std::fs::create_dir_all(dir).map_err(|e| e.to_string())?; + } + let bytes = serde_json::to_vec_pretty(all).map_err(|e| e.to_string())?; + crate::write_private(path, &bytes).map_err(|e| format!("{}: {e}", path.display())) +} + +#[cfg(test)] +mod tests { + use super::*; + + /// Against the real store of the machine the test runs on (the keychain + /// on Windows and macOS, either on Linux), under a service of its own. + #[test] + fn a_secret_is_kept_given_back_and_forgotten() { + let d = tempfile::tempdir().unwrap(); + let service = format!("devstack-test-{}", std::process::id()); + let s = Secrets::open_as(&service, d.path().to_path_buf()); + if !cfg!(target_os = "linux") { + assert_eq!(s.kind(), Kind::Keychain); + } + assert_eq!(s.get("tracker").unwrap(), None); + s.set("tracker", "token-1").unwrap(); + s.set("tracker", "token-2").unwrap(); + s.set("wiki", "token-w").unwrap(); + assert_eq!(s.get("tracker").unwrap().as_deref(), Some("token-2")); + assert_eq!(s.get("wiki").unwrap().as_deref(), Some("token-w")); + s.delete("tracker").unwrap(); + s.delete("tracker").unwrap(); + assert_eq!(s.get("tracker").unwrap(), None); + assert_eq!(s.get("wiki").unwrap().as_deref(), Some("token-w")); + s.delete("wiki").unwrap(); + assert_eq!(s.get("wiki").unwrap(), None); + } + + #[test] + fn the_file_is_the_users_alone() { + let d = tempfile::tempdir().unwrap(); + let s = Secrets { + store: Store::File { + path: d.path().join("hub/secrets.json"), + lock: Mutex::new(()), + }, + }; + s.set("tracker", "token").unwrap(); + assert_eq!(s.get("tracker").unwrap().as_deref(), Some("token")); + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + let mode = std::fs::metadata(d.path().join("hub/secrets.json")) + .unwrap() + .permissions() + .mode(); + assert_eq!(mode & 0o777, 0o600); + } + s.delete("tracker").unwrap(); + assert_eq!(s.get("tracker").unwrap(), None); + } +} diff --git a/docs/adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md b/docs/adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md index acd767b7..5ed4b5ed 100644 --- a/docs/adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md +++ b/docs/adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md @@ -1,6 +1,6 @@ # ADR-0069: `devstack mcp` can carry the tools of upstream MCP servers, logged in once by the hub -- **Status:** Proposed (2026-10-27) +- **Status:** Proposed (2026-10-27); amended 2026-10-27 (the keychain spike: `keyring`, a file on Linux without a Secret Service) - **Date:** 2026-10-27 - **Deciders:** project owner - **Related:** [#316](https://github.com/nuetzliches/devstack/issues/316), [ADR-0007](0007-one-http-api-is-the-control-surface.md), [ADR-0019](0019-control-api-security.md), [ADR-0021](0021-a-hub-serves-the-dashboard.md), [ADR-0032](0032-the-pool-is-administered-in-the-dashboard.md), [ADR-0054](0054-macos-is-a-developer-platform-in-preview.md), [ADR-0060](0060-the-tray-is-a-client-of-the-hub.md), [ADR-0067](0067-a-change-at-runtime-says-who-made-it.md) @@ -83,6 +83,18 @@ MIT-compatible licence for Windows (Credential Manager), Linux (Secret Service, and what to do without one) and macOS (Keychain, ADR-0054). If none fits, this ADR is amended before any code depends on it. +*Amended 2026-10-27, the keychain spike.* The crate is `keyring` 4 (MIT OR +Apache-2.0, with its stores for Windows, macOS and the Linux Secret +Service; Rust 1.88 at most): every crate it pulls in, on every platform, is +on the licence list of `deny.toml`. Written, read and removed on Windows +(Credential Manager); macOS and Linux run the same test in CI. A Linux +machine without a Secret Service (a server, a headless session, CI) has no +keychain to use: the hub finds that with a probe entry when it opens the +store, and keeps the secrets in `secrets.json` in its state directory +instead, readable by the user alone (`0600`, as the hub's sessions file); +the dashboard is to say so. On Windows and macOS there is no file: a +keychain that refuses is said when a secret is used. + ## Alternatives considered - **A. Proxy in the hub, user level only.** Chosen. @@ -142,8 +154,10 @@ of these? ## Enforced by -To be built, after the keychain spike: `crates/devstack-hub` (upstream -connections, OAuth client and redirect, token storage, a loopback API for +`crates/devstack-hub/src/secrets.rs` (the store, with its test against +the machine's real keychain on every platform). To be built: +`crates/devstack-hub` (upstream +connections, OAuth client and redirect, a loopback API for `devstack mcp`), `crates/devstack/src/mcp.rs` (merging the tool lists, forwarding calls, starting the hub), `ui/` (upstreams and logins), `docs/dashboard-api.md`. diff --git a/docs/adr/README.md b/docs/adr/README.md index 3f09d2d5..6b68ae62 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -117,4 +117,4 @@ stay. | [0066](0066-a-measured-cpu-need-is-capped-at-half-of-what-its-node-gives-lanes.md) | A measured CPU need is capped at half of what its node gives lanes | Accepted | | [0067](0067-a-change-at-runtime-says-who-made-it.md) | A change at runtime says where it came from, and a journal keeps the last ones | Accepted; built 2026-10-27 (point 2 for the main slot and services) | | [0068](0068-a-stop-takes-the-containers-too.md) | A stop takes the stack's containers too, unless asked to keep them | Accepted | -| [0069](0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md) | `devstack mcp` can carry the tools of upstream MCP servers, logged in once by the hub | Proposed (option A: a proxy in the hub, per user) | +| [0069](0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md) | `devstack mcp` can carry the tools of upstream MCP servers, logged in once by the hub | Proposed (option A: a proxy in the hub, per user); amended 2026-10-27 (keychain via `keyring`, a file on Linux without a Secret Service) |