Skip to content

Commit 0c40472

Browse files
Merge pull request #13 from geico/server/begin-tuxtape-server
Begin `tuxtape-server`
2 parents 117fc7d + 0d47ce7 commit 0c40472

File tree

18 files changed

+1436
-2
lines changed

18 files changed

+1436
-2
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
resolver = "3"
3+
4+
members = [
5+
"tuxtape-server",
6+
"tuxtape-server/tuxtape-database-bridge"
7+
]

proto/tuxtape/common/v1/vulnerability.proto

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ message Vulnerability {
88
// Instances of this Vulnerability across different MainlineKernelVersions.
99
// Will be empty if no instances exist in the managed fleet.
1010
repeated VulnerabilityInstance instances = 1;
11-
11+
// A custom description that can be set for a Vulnerability.
12+
// Since a Vulnerability almost always describes a Cve, and since CVEs being
13+
// patched are typically evaluated by NIST, this value is most useful when
14+
// patching a Vulnerability which has not yet been catalogued as a CVE.
15+
// Usually, the description for the CVE will be more useful.
16+
optional string description = 2;
1217
// The CVE that this Vulnerability describes.
1318
// A Vulnerability will always describe a Cve unless a CVE has not yet been
1419
// published for this Vulnerability.
15-
optional Cve cve = 2;
20+
optional Cve cve = 3;
1621
}
1722

1823
// An instance of a Vulnerability.

tuxtape-server/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "tuxtape-server"
3+
edition = "2024"
4+
description = "The central server for a complete TuxTape environment."
5+
6+
[dependencies]
7+
clap = { version = "4.5", features = ["derive", "env"] }
8+
tokio = { version = "1.44", features = ["full"] }
9+
color-eyre = "0.6"
10+
tuxtape-database-bridge = { path = "tuxtape-database-bridge" }
11+
12+
[[bin]]
13+
name = "tuxtape-server"
14+
path = "src/main.rs"

tuxtape-server/diesel.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# For documentation on how to configure this file,
2+
# see https://diesel.rs/guides/configuring-diesel-cli
3+
4+
[print_schema]
5+
file = "tuxtape-database-bridge/src/schema.rs"
6+
custom_type_derives = ["diesel::query_builder::QueryId", "Clone"]
7+
8+
[migrations_directory]
9+
dir = "migrations"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DROP TABLE vulnerability;
2+
DROP TABLE vulnerability_instance;
3+
DROP TABLE vulnerability_instance_affected_file;
4+
DROP TABLE cve;
5+
DROP TABLE mainline_kernel_release;
6+
DROP TABLE kernel_release;
7+
DROP TABLE kernel_source;
8+
DROP TABLE kernel_file;
9+
DROP TABLE meta;
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
-- Initializes the TuxTape database
2+
3+
CREATE TABLE vulnerability (
4+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
5+
description TEXT
6+
);
7+
8+
CREATE TABLE vulnerability_instance (
9+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
10+
vulnerability_id INTEGER NOT NULL,
11+
description TEXT,
12+
mainline_kernel_release_introduced_id INTEGER,
13+
mainline_kernel_release_fixed_id INTEGER,
14+
fixed_commit TEXT,
15+
patch_diff TEXT,
16+
FOREIGN KEY(vulnerability_id) REFERENCES vulnerability(id),
17+
FOREIGN KEY(mainline_kernel_release_introduced_id) REFERENCES mainline_kernel_release(id),
18+
FOREIGN KEY(mainline_kernel_release_fixed_id) REFERENCES mainline_kernel_release(id)
19+
);
20+
21+
CREATE TABLE vulnerability_instance_affected_file (
22+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
23+
vulnerability_instance_id INTEGER NOT NULL,
24+
file_path TEXT NOT NULL,
25+
FOREIGN KEY(vulnerability_instance_id) REFERENCES vulnerability_instance(id)
26+
);
27+
28+
CREATE TABLE cve (
29+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
30+
cve_id TEXT NOT NULL,
31+
vulnerability_id INTEGER NOT NULL,
32+
base_score REAL,
33+
attack_vector TEXT,
34+
attack_complexity TEXT,
35+
privileges_required TEXT,
36+
user_interaction TEXT,
37+
scope TEXT,
38+
confidentiality_impact TEXT,
39+
integrity_impact TEXT,
40+
availability_impact TEXT,
41+
description TEXT,
42+
FOREIGN KEY(vulnerability_id) REFERENCES vulnerability(id)
43+
);
44+
45+
CREATE TABLE mainline_kernel_release (
46+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
47+
version_major INTEGER NOT NULL,
48+
version_minor INTEGER NOT NULL,
49+
version_patch INTEGER NOT NULL,
50+
version_extra TEXT NOT NULL,
51+
UNIQUE (version_major, version_minor, version_patch, version_extra)
52+
);
53+
54+
CREATE TABLE kernel_release (
55+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
56+
mainline_kernel_release_id INTEGER NOT NULL,
57+
version_local TEXT,
58+
FOREIGN KEY(mainline_kernel_release_id) REFERENCES mainline_kernel_release(id),
59+
UNIQUE (version_local)
60+
);
61+
62+
CREATE TABLE kernel_source (
63+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
64+
kernel_release_id INTEGER NOT NULL,
65+
url TEXT NOT NULL,
66+
FOREIGN KEY(kernel_release_id) REFERENCES kernel_release(id),
67+
UNIQUE (kernel_release_id, url)
68+
);
69+
70+
CREATE TABLE kernel_file (
71+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
72+
kernel_release_id INTEGER NOT NULL,
73+
file_path TEXT NOT NULL,
74+
FOREIGN KEY(kernel_release_id) REFERENCES kernel_release(id)
75+
);
76+
77+
CREATE TABLE meta (
78+
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT CHECK (id = 1),
79+
based_on_vulns_commit TEXT NOT NULL,
80+
last_run_unix_time INTEGER NOT NULL
81+
);

tuxtape-server/src/cli.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use clap::Parser;
2+
use tuxtape_database_bridge::connection::DatabaseBackend;
3+
4+
#[derive(clap::ValueEnum, Clone, Debug)]
5+
pub enum CliDatabaseBackend {
6+
Pg,
7+
Sqlite,
8+
}
9+
10+
impl From<CliDatabaseBackend> for DatabaseBackend {
11+
fn from(val: CliDatabaseBackend) -> Self {
12+
match val {
13+
CliDatabaseBackend::Pg => DatabaseBackend::Pg,
14+
CliDatabaseBackend::Sqlite => DatabaseBackend::Sqlite,
15+
}
16+
}
17+
}
18+
19+
#[derive(Parser, Debug)]
20+
#[command(version, about, long_about = None)]
21+
pub struct Cli {
22+
/// The URL to the database. If Postgres, this should be a web URL. If SQLite, this should be a
23+
/// path to the database file, either relative or absolute.
24+
#[arg(short('d'), long, default_value = concat!(env!("HOME"), "/.cache/tuxtape-server/db.db3"))]
25+
pub db_url: String,
26+
/// The database backend. If Postgres, this should "pg". If SQLite, this should be "sqlite".
27+
#[arg(short('b'), long, default_value = "sqlite")]
28+
pub db_backend: CliDatabaseBackend,
29+
}

tuxtape-server/src/grpc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// TODO

tuxtape-server/src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use clap::Parser;
2+
use cli::Cli;
3+
use color_eyre::{Result, eyre::eyre};
4+
5+
mod cli;
6+
7+
#[tokio::main]
8+
async fn main() -> Result<()> {
9+
let args = Cli::parse();
10+
11+
// Attempt to connect to database and exit early and loudly if failed.
12+
let mut conn = tuxtape_database_bridge::connection::establish_connection(
13+
args.db_backend.into(),
14+
&args.db_url,
15+
)?;
16+
17+
// Run any pending database migrations before proceeding.
18+
tuxtape_database_bridge::migration::run_pending_migrations(&mut conn).map_err(|e| eyre!(e))?;
19+
20+
Ok(())
21+
}

0 commit comments

Comments
 (0)