Skip to content

Commit 01d41dc

Browse files
refactor(dgw): move the agent tunnel store into gateway-db
The agent_tunnel_* tables are created by gateway-db's migrations, so the code reading them now lives next to them as gateway_db::agent_tunnel. The agent-tunnel-libsql crate is removed.
1 parent 3abb65b commit 01d41dc

9 files changed

Lines changed: 21 additions & 51 deletions

File tree

‎Cargo.lock‎

Lines changed: 3 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/agent-tunnel-libsql/Cargo.toml‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎crates/gateway-db/Cargo.toml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ publish = false
99
workspace = true
1010

1111
[dependencies]
12+
agent-tunnel.path = "../agent-tunnel"
1213
anyhow = "1"
14+
async-trait = "0.1"
1315
camino = "1.1"
14-
libsql = { version = "0.9", default-features = false, features = ["core"] }
16+
libsql = { version = "0.9", default-features = false, features = ["core", "serde"] }
17+
tokio = { version = "1.52", features = ["sync"] }
1518
tracing = "0.1"
19+
uuid = "1.23"
1620

1721
[dev-dependencies]
1822
tempfile = "3.24"
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The agent tunnel's tables: accepted Agents, enrollment attempts and the CA they belong to.
2+
13
use agent_tunnel::authorization::{
24
AcceptedAgent, AgentAuthorizationStore, EnrollmentAttempt, EnrollmentConflict, EnrollmentOutcome, SpkiSha256,
35
};
@@ -15,7 +17,7 @@ pub struct LibSqlAgentAuthorizationStore {
1517
}
1618

1719
impl LibSqlAgentAuthorizationStore {
18-
/// Opens the store on a `gateway.db` connection of its own, from `GatewayDb::connect` in the `gateway-db` crate.
20+
/// Opens the store on a `gateway.db` connection of its own, from [`GatewayDb::connect`](crate::GatewayDb::connect).
1921
///
2022
/// The connection must already have up-to-date `agent_tunnel_*` tables; opening checks them and fails if they
2123
/// don't match. The stored Agents only make sense with the CA that signed their certificates, so the first open
@@ -490,7 +492,7 @@ mod tests {
490492
use super::*;
491493

492494
async fn connect(path: &str) -> anyhow::Result<Connection> {
493-
gateway_db::GatewayDb::open_path(path).await?.connect().await
495+
crate::GatewayDb::open_path(path).await?.connect().await
494496
}
495497

496498
async fn open_store(path: &str, ca_spki_sha256: SpkiSha256) -> anyhow::Result<LibSqlAgentAuthorizationStore> {
@@ -826,7 +828,7 @@ mod tests {
826828
.expect("record 2026.3 schema version");
827829
drop(legacy);
828830

829-
let conn = gateway_db::GatewayDb::open(&data_dir)
831+
let conn = crate::GatewayDb::open(&data_dir)
830832
.await
831833
.expect("open gateway database")
832834
.connect()

‎crates/gateway-db/src/lib.rs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
//! Gateway's own database, `gateway.db`.
22
//!
33
//! When a feature needs to remember a little data, it keeps it here in tables named after the feature
4-
//! (`agent_tunnel_*`, ...), so we don't end up with one database file per feature. The job queue is the
5-
//! exception: it tunes its database for queue work, so it keeps its own file.
4+
//! (`agent_tunnel_*`, ...), with the code reading them in a module of the same name, so we don't end up with one
5+
//! database file per feature. Queues are the exception: the job queue and the traffic audit tune their databases
6+
//! for queue work, so they keep their own files.
67
78
#[macro_use]
89
extern crate tracing;
910

11+
pub mod agent_tunnel;
12+
1013
use anyhow::{Context as _, bail};
1114
use camino::{Utf8Path, Utf8PathBuf};
1215
use libsql::{Connection, Database, TransactionBehavior, params};

‎devolutions-gateway/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ network-monitor.path = "../crates/network-monitor"
3636
sysevent.path = "../crates/sysevent"
3737
sysevent-codes.path = "../crates/sysevent-codes"
3838
agent-tunnel = { path = "../crates/agent-tunnel" }
39-
agent-tunnel-libsql = { path = "../crates/agent-tunnel-libsql" }
4039
gateway-db.path = "../crates/gateway-db"
4140
ironrdp-pdu = { version = "0.9", features = ["std"] }
4241
ironrdp-core = { version = "0.2", features = ["std"] }

‎devolutions-gateway/src/service.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ async fn spawn_tasks(conf_handle: ConfHandle) -> anyhow::Result<Tasks> {
288288
.connect()
289289
.await
290290
.context("failed to connect the agent tunnel to the gateway database")?;
291-
let agents_have_ca = agent_tunnel_libsql::LibSqlAgentAuthorizationStore::bound_ca(&agent_tunnel_conn)
291+
let agents_have_ca = gateway_db::agent_tunnel::LibSqlAgentAuthorizationStore::bound_ca(&agent_tunnel_conn)
292292
.await
293293
.context("failed to read the agent tunnel CA identity")?
294294
.is_some();
@@ -302,7 +302,7 @@ async fn spawn_tasks(conf_handle: ConfHandle) -> anyhow::Result<Tasks> {
302302
.ca_spki_sha256()
303303
.context("failed to identify agent tunnel CA")?;
304304
let authorization_store =
305-
agent_tunnel_libsql::LibSqlAgentAuthorizationStore::open(agent_tunnel_conn, ca_spki_sha256)
305+
gateway_db::agent_tunnel::LibSqlAgentAuthorizationStore::open(agent_tunnel_conn, ca_spki_sha256)
306306
.await
307307
.context("failed to initialize Agent authorization database")?;
308308
let authorization_store: agent_tunnel::authorization::DynAgentAuthorizationStore =

‎testsuite/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ tokio-tungstenite = { version = "0.29", features = ["rustls-tls-native-roots"] }
3333
[dev-dependencies]
3434
agent-sysevent-codes.path = "../crates/agent-sysevent-codes"
3535
agent-tunnel = { path = "../crates/agent-tunnel", features = ["test-utils"] }
36-
agent-tunnel-libsql = { path = "../crates/agent-tunnel-libsql" }
3736
agent-tunnel-proto = { path = "../crates/agent-tunnel-proto", features = ["serde"] }
3837
base64 = "0.23"
3938
camino = "1"

‎testsuite/tests/agent_tunnel/common.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub(super) async fn bind_test_listener() -> TestListener {
181181
.connect()
182182
.await
183183
.expect("connect to test gateway database");
184-
let authorization_store = agent_tunnel_libsql::LibSqlAgentAuthorizationStore::open(gateway_db, ca_spki_sha256)
184+
let authorization_store = gateway_db::agent_tunnel::LibSqlAgentAuthorizationStore::open(gateway_db, ca_spki_sha256)
185185
.await
186186
.expect("open test Agent authorization store");
187187
let listen_addr: SocketAddr = "127.0.0.1:0".parse().expect("parse listener address");

0 commit comments

Comments
 (0)