Skip to content

[poc] SSL/TLS for standalone server #2598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 24 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e381066
add TLS support for standalone server
dare3path Apr 12, 2025
68fd57a
Cargo.lock got updated after the build
dare3path Apr 12, 2025
9512830
fix typo in comment
dare3path Apr 12, 2025
68808e6
`spacetime server` treat protocol as unique id
dare3path Apr 12, 2025
b31297a
print the warning on stderr
dare3path Apr 13, 2025
5e05d81
add --cert to more subcommands
dare3path Apr 13, 2025
0d6a459
fix(cli): resolve server fingerprint ambiguity for URLs and nicknames
dare3path Apr 13, 2025
bfd30d0
add --cert to subcommands sql,call,describe
dare3path Apr 13, 2025
b559ea9
fix 'spacetime subscribe'
dare3path Apr 13, 2025
8f60a10
move load_root_cert from util to lib
dare3path Apr 13, 2025
ce3af70
limit read cert size
dare3path Apr 13, 2025
494abaa
fix spacetime_server_fingerprint
dare3path Apr 13, 2025
8844345
add --cert to subcommands: rename, list, energy
dare3path Apr 14, 2025
5a33138
remove some commented out code / comments
dare3path Apr 14, 2025
00021c0
dedup Arg::new("cert")
dare3path Apr 14, 2025
b8677bb
say server.crt not cert.pem in 'start' cmd's help
dare3path Apr 14, 2025
31952e7
say server.key not key.pem in 'start' cmd's help
dare3path Apr 15, 2025
905bca1
restrict server to TLS 1.3
dare3path Apr 15, 2025
9754862
expect exactly 1 server cert/key
dare3path Apr 15, 2025
af8d61e
cert isn't pub key, it contains it
dare3path Apr 15, 2025
57a879b
mTLS + some fixes(1MiB thing was broken badly)
dare3path Apr 24, 2025
be19440
make 'spacetime publish' work
dare3path Apr 24, 2025
30159f6
show message about trusting or not the system store
dare3path Apr 24, 2025
9ee5f22
don't keep [patch.crates-io] section
dare3path Apr 24, 2025
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
373 changes: 342 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ lto = "thin"

[profile.dev]
opt-level = 0
debug = true
debug = 1
#debug = true #FIXME: put this back
debug-assertions = true
overflow-checks = true
lto = false
Expand Down Expand Up @@ -129,7 +130,12 @@ arrayvec = "0.7.2"
async-stream = "0.3.6"
async-trait = "0.1.68"
axum = { version = "0.7", features = ["tracing"] }
axum-server = { version = "0.7.2", features = ["tls-rustls"] }
axum-extra = { version = "0.9", features = ["typed-header"] }
#rustls-platform-verifier = "0.5"
x509-parser = "0.17"
sha2="0.10.8"
rustls-native-certs = "0.8"
backtrace = "0.3.66"
base64 = "0.21.2"
bigdecimal = "0.4.7"
Expand Down Expand Up @@ -178,8 +184,8 @@ home = "0.5"
hostname = "^0.3"
http = "1.0"
humantime = "2.1.0"
hyper = "1.0"
hyper-util = { version = "0.1", features = ["tokio"] }
hyper = "1.6"
hyper-util = { version = "0.1.11", features = ["tokio"] }
imara-diff = "0.1.3"
indexmap = "2.0.0"
indicatif = "0.17"
Expand Down Expand Up @@ -214,7 +220,12 @@ rand = "0.9"
rayon = "1.8"
rayon-core = "1.11.0"
regex = "1"
reqwest = { version = "0.12", features = ["stream", "json"] }
reqwest = { version = "0.12", features = ["stream", "json", "native-tls"] }
rustls-pemfile = "2.2"
#rustls = "0.23"
rustls= { version="0.23", default-features = true, features=[ "ring" ] }
native-tls = "0.2" # Explicitly add for Connector::NativeTls
ring = "0.17" # explicitly add this for the CryptoProvider, even tho it's included transitively.
ron = "0.8"
rusqlite = { version = "0.29.0", features = ["bundled", "column_decltype"] }
rust_decimal = { version = "1.29.1", features = ["db-tokio-postgres"] }
Expand Down
6 changes: 6 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ wasmbin.workspace = true
wasmtime.workspace = true
webbrowser.workspace = true
clap-markdown.workspace = true
#native-tls = "0.2"
native-tls.workspace=true
rustls-pemfile.workspace=true
x509-parser.workspace=true
sha2.workspace=true
#hyper.workspace=true

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = { workspace = true }
Expand Down
38 changes: 35 additions & 3 deletions crates/cli/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ use spacetimedb_lib::db::raw_def::v9::RawModuleDefV9;
use spacetimedb_lib::de::serde::DeserializeWrapper;
use spacetimedb_lib::Identity;

use crate::util::{AuthHeader, ResponseExt};
use crate::util::{AuthHeader, ResponseExt,
map_request_error // fn and macro
};
use crate::util;
use std::path::PathBuf;

static APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);

Expand All @@ -18,6 +22,11 @@ pub struct Connection {
pub(crate) database_identity: Identity,
pub(crate) database: String,
pub(crate) auth_header: AuthHeader,
// FIXME: bad idea to put these next ones here? else pass'em as arg?
pub(crate) trust_server_cert_path: Option<PathBuf>,
pub(crate) client_cert_path: Option<PathBuf>,
pub(crate) client_key_path: Option<PathBuf>,
pub(crate) trust_system: bool,
}

impl Connection {
Expand All @@ -34,15 +43,38 @@ impl Connection {
}

pub fn build_client(con: &Connection) -> Client {
let mut builder = Client::builder().user_agent(APP_USER_AGENT);
let trust_server_cert_path=con.trust_server_cert_path.as_deref();
let client_cert_path=con.client_cert_path.as_deref();
let client_key_path=con.client_key_path.as_deref();
let trust_system=con.trust_system;
//XXX: alternatively make this async and then make new() async, and ensure callers do .await on it
let mut builder = tokio::task::block_in_place(|| {
tokio::runtime::Handle::current()
.block_on(util::configure_tls(
trust_server_cert_path,
client_cert_path,
client_key_path,
trust_system
))
})
.unwrap();
builder = builder.user_agent(APP_USER_AGENT);

if let Some(auth_header) = con.auth_header.to_header() {
let headers = http::HeaderMap::from_iter([(header::AUTHORIZATION, auth_header)]);

builder = builder.default_headers(headers);
}

builder.build().unwrap()
map_request_error!(
util::build_client_with_context(builder,
trust_server_cert_path,
client_cert_path,
client_key_path,
trust_system,
), con.host, client_cert_path, client_key_path
)
.unwrap()
}

pub struct ClientApi {
Expand Down
1 change: 1 addition & 0 deletions crates/cli/src/common_args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::Arg;
use clap::ArgAction::SetTrue;
pub use spacetimedb_lib::{no_trust_system_root_store, trust_system_root_store, trust_server_cert, client_key, client_cert};

pub fn server() -> Arg {
Arg::new("server")
Expand Down
Loading