Compare commits
6 Commits
debian-vm-
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
b2d9400f0e
|
|||
|
2838c584d3
|
|||
|
ce75aa509d
|
|||
|
87ef63b680
|
|||
|
6686b3bbe7
|
|||
|
f75b34f40c
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,7 +9,6 @@ result-*
|
|||||||
|
|
||||||
# Nix VM
|
# Nix VM
|
||||||
*.qcow2
|
*.qcow2
|
||||||
.nixos-test-history
|
|
||||||
|
|
||||||
# Packaging
|
# Packaging
|
||||||
!/assets/debian/config.toml
|
!/assets/debian/config.toml
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "muscl"
|
name = "muscl"
|
||||||
version = "0.1.0"
|
version = "1.0.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
license = "BSD-3-Clause"
|
license = "BSD-3-Clause"
|
||||||
authors = [
|
authors = [
|
||||||
"oysteikt@pvv.ntnu.no",
|
"Programvareverkstedet <projects@pvv.ntnu.no>",
|
||||||
"felixalb@pvv.ntnu.no",
|
|
||||||
]
|
]
|
||||||
homepage = "https://git.pvv.ntnu.no/Projects/muscl"
|
homepage = "https://git.pvv.ntnu.no/Projects/muscl"
|
||||||
repository = "https://git.pvv.ntnu.no/Projects/muscl"
|
repository = "https://git.pvv.ntnu.no/Projects/muscl"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Description=Muscl MySQL admin tool
|
|||||||
|
|
||||||
[Socket]
|
[Socket]
|
||||||
ListenStream=/run/muscl/muscl.sock
|
ListenStream=/run/muscl/muscl.sock
|
||||||
|
RemoveOnStop=true
|
||||||
Accept=no
|
Accept=no
|
||||||
PassCredentials=true
|
PassCredentials=true
|
||||||
|
|
||||||
|
|||||||
21
flake.lock
generated
21
flake.lock
generated
@@ -15,26 +15,6 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nix-vm-test": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1763976673,
|
|
||||||
"narHash": "sha256-QPeI8WR+brwodiy4YNfOnLI7rOHJfFPrGm+xT/HmtT4=",
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "nix-vm-test",
|
|
||||||
"rev": "8611bdd7a49750a880be9ee2ea9f68c53f8c9299",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "numtide",
|
|
||||||
"repo": "nix-vm-test",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1768127708,
|
"lastModified": 1768127708,
|
||||||
@@ -54,7 +34,6 @@
|
|||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"crane": "crane",
|
"crane": "crane",
|
||||||
"nix-vm-test": "nix-vm-test",
|
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,9 @@
|
|||||||
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
|
||||||
crane.url = "github:ipetkov/crane";
|
crane.url = "github:ipetkov/crane";
|
||||||
|
|
||||||
nix-vm-test.url = "github:numtide/nix-vm-test";
|
|
||||||
nix-vm-test.inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, rust-overlay, crane, nix-vm-test }:
|
outputs = { self, nixpkgs, rust-overlay, crane }:
|
||||||
let
|
let
|
||||||
inherit (nixpkgs) lib;
|
inherit (nixpkgs) lib;
|
||||||
|
|
||||||
@@ -98,8 +95,6 @@
|
|||||||
muscl = import ./nix/module.nix;
|
muscl = import ./nix/module.nix;
|
||||||
};
|
};
|
||||||
|
|
||||||
# vmlib = forAllSystems(system: _: _: nix-vm-test.lib.${system});
|
|
||||||
|
|
||||||
packages = forAllSystems (system: pkgs: _:
|
packages = forAllSystems (system: pkgs: _:
|
||||||
let
|
let
|
||||||
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
|
||||||
@@ -135,8 +130,6 @@
|
|||||||
filteredSource = pkgs.runCommandLocal "filtered-source" { } ''
|
filteredSource = pkgs.runCommandLocal "filtered-source" { } ''
|
||||||
ln -s ${src} $out
|
ln -s ${src} $out
|
||||||
'';
|
'';
|
||||||
|
|
||||||
debianVm = import ./nix/debian-vm-configuration.nix { inherit nix-vm-test nixpkgs system pkgs; };
|
|
||||||
});
|
});
|
||||||
|
|
||||||
checks = forAllSystems (system: pkgs: _: {
|
checks = forAllSystems (system: pkgs: _: {
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
{ nix-vm-test, nixpkgs, system, pkgs, ... }:
|
|
||||||
let
|
|
||||||
image = nix-vm-test.lib.${system}.debian.images."13";
|
|
||||||
|
|
||||||
generic = import "${nix-vm-test}/generic" { inherit pkgs nixpkgs; inherit (pkgs) lib; };
|
|
||||||
|
|
||||||
makeVmTestForImage =
|
|
||||||
image:
|
|
||||||
{
|
|
||||||
testScript,
|
|
||||||
sharedDirs ? {},
|
|
||||||
diskSize ? null,
|
|
||||||
config ? { }
|
|
||||||
}:
|
|
||||||
generic.makeVmTest {
|
|
||||||
inherit
|
|
||||||
system
|
|
||||||
testScript
|
|
||||||
sharedDirs;
|
|
||||||
image = nix-vm-test.lib.${system}.debian.prepareDebianImage {
|
|
||||||
inherit diskSize;
|
|
||||||
hostPkgs = pkgs;
|
|
||||||
originalImage = image;
|
|
||||||
};
|
|
||||||
machineConfigModule = config;
|
|
||||||
};
|
|
||||||
|
|
||||||
vmTest = makeVmTestForImage image {
|
|
||||||
diskSize = "10G";
|
|
||||||
sharedDirs = {
|
|
||||||
debDir = {
|
|
||||||
source = "${./.}";
|
|
||||||
target = "/mnt";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
testScript = ''
|
|
||||||
vm.wait_for_unit("multi-user.target")
|
|
||||||
vm.succeed("apt-get update && apt-get -y install mariadb-server build-essential curl")
|
|
||||||
vm.succeed("curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y")
|
|
||||||
vm.succeed("source /root/.cargo/env && cargo install cargo-deb")
|
|
||||||
vm.succeed("cp -r /mnt /root/src && chmod -R +w /root/src")
|
|
||||||
vm.succeed("source /root/.cargo/env && cd /root/src && ./create-deb.sh")
|
|
||||||
'';
|
|
||||||
config.nodes.vm = {
|
|
||||||
virtualisation.memorySize = 8192;
|
|
||||||
virtualisation.cpus = 4;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in vmTest.driverInteractive
|
|
||||||
@@ -54,11 +54,13 @@ for variant in debian-bookworm debian-trixie ubuntu-jammy ubuntu-noble; do
|
|||||||
DEB_VERSION=$(find "$TMPDIR/muscl-deb-$variant-$GIT_SHA"/*.deb -print0 | xargs -0 -n1 basename | cut -d'_' -f2 | head -n1)
|
DEB_VERSION=$(find "$TMPDIR/muscl-deb-$variant-$GIT_SHA"/*.deb -print0 | xargs -0 -n1 basename | cut -d'_' -f2 | head -n1)
|
||||||
DEB_ARCH=$(find "$TMPDIR/muscl-deb-$variant-$GIT_SHA"/*.deb -print0 | xargs -0 -n1 basename | cut -d'_' -f3 | cut -d'.' -f1 | head -n1)
|
DEB_ARCH=$(find "$TMPDIR/muscl-deb-$variant-$GIT_SHA"/*.deb -print0 | xargs -0 -n1 basename | cut -d'_' -f3 | cut -d'.' -f1 | head -n1)
|
||||||
|
|
||||||
|
echo "[DELETE] https://git.pvv.ntnu.no/api/packages/Projects/debian/pool/$DISTRO_VERSION_NAME/main/$DEB_NAME/$DEB_VERSION/$DEB_ARCH"
|
||||||
curl \
|
curl \
|
||||||
-X DELETE \
|
-X DELETE \
|
||||||
--user "$GITEA_USER:$GITEA_TOKEN" \
|
--user "$GITEA_USER:$GITEA_TOKEN" \
|
||||||
"https://git.pvv.ntnu.no/api/packages/Projects/debian/pool/$DISTRO_VERSION_NAME/main/$DEB_NAME/$DEB_VERSION/$DEB_ARCH"
|
"https://git.pvv.ntnu.no/api/packages/Projects/debian/pool/$DISTRO_VERSION_NAME/main/$DEB_NAME/$DEB_VERSION/$DEB_ARCH"
|
||||||
|
|
||||||
|
echo "[PUT] https://git.pvv.ntnu.no/api/packages/Projects/debian/pool/$DISTRO_VERSION_NAME/main/upload"
|
||||||
curl \
|
curl \
|
||||||
-X PUT \
|
-X PUT \
|
||||||
--user "$GITEA_USER:$GITEA_TOKEN" \
|
--user "$GITEA_USER:$GITEA_TOKEN" \
|
||||||
|
|||||||
@@ -319,7 +319,8 @@ fn main() -> anyhow::Result<()> {
|
|||||||
#[cfg(not(feature = "suid-sgid-mode"))]
|
#[cfg(not(feature = "suid-sgid-mode"))]
|
||||||
None,
|
None,
|
||||||
args.verbose,
|
args.verbose,
|
||||||
)?;
|
)
|
||||||
|
.context("Failed to connect to the server")?;
|
||||||
|
|
||||||
tokio_run_command(args.command, connection)?;
|
tokio_run_command(args.command, connection)?;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs,
|
fs,
|
||||||
|
os::unix::fs::FileTypeExt,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
@@ -7,7 +8,10 @@ use std::{
|
|||||||
|
|
||||||
use anyhow::{Context, anyhow};
|
use anyhow::{Context, anyhow};
|
||||||
use clap_verbosity_flag::{InfoLevel, Verbosity};
|
use clap_verbosity_flag::{InfoLevel, Verbosity};
|
||||||
use nix::libc::{EXIT_SUCCESS, exit};
|
use nix::{
|
||||||
|
libc::{EXIT_SUCCESS, exit},
|
||||||
|
unistd::{AccessFlags, access},
|
||||||
|
};
|
||||||
use sqlx::mysql::MySqlPoolOptions;
|
use sqlx::mysql::MySqlPoolOptions;
|
||||||
use std::os::unix::net::UnixStream as StdUnixStream;
|
use std::os::unix::net::UnixStream as StdUnixStream;
|
||||||
use tokio::{net::UnixStream as TokioUnixStream, sync::RwLock};
|
use tokio::{net::UnixStream as TokioUnixStream, sync::RwLock};
|
||||||
@@ -130,11 +134,28 @@ pub fn bootstrap_server_connection_and_drop_privileges(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn socket_path_is_ok(path: &Path) -> anyhow::Result<()> {
|
||||||
|
fs::metadata(path)
|
||||||
|
.context(format!("Failed to get metadata for {:?}", path))
|
||||||
|
.and_then(|meta| {
|
||||||
|
if !meta.file_type().is_socket() {
|
||||||
|
anyhow::bail!("{:?} is not a unix socket", path);
|
||||||
|
}
|
||||||
|
|
||||||
|
access(path, AccessFlags::R_OK | AccessFlags::W_OK)
|
||||||
|
.with_context(|| format!("Socket at {:?} is not readable/writable", path))?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn connect_to_external_server(
|
fn connect_to_external_server(
|
||||||
server_socket_path: Option<PathBuf>,
|
server_socket_path: Option<PathBuf>,
|
||||||
) -> anyhow::Result<StdUnixStream> {
|
) -> anyhow::Result<StdUnixStream> {
|
||||||
// TODO: ensure this is both readable and writable
|
|
||||||
if let Some(socket_path) = server_socket_path {
|
if let Some(socket_path) = server_socket_path {
|
||||||
|
tracing::trace!("Checking socket at {:?}", socket_path);
|
||||||
|
socket_path_is_ok(&socket_path)?;
|
||||||
|
|
||||||
tracing::debug!("Connecting to socket at {:?}", socket_path);
|
tracing::debug!("Connecting to socket at {:?}", socket_path);
|
||||||
return match StdUnixStream::connect(socket_path) {
|
return match StdUnixStream::connect(socket_path) {
|
||||||
Ok(socket) => Ok(socket),
|
Ok(socket) => Ok(socket),
|
||||||
@@ -147,6 +168,9 @@ fn connect_to_external_server(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if fs::metadata(DEFAULT_SOCKET_PATH).is_ok() {
|
if fs::metadata(DEFAULT_SOCKET_PATH).is_ok() {
|
||||||
|
tracing::trace!("Checking socket at {:?}", DEFAULT_SOCKET_PATH);
|
||||||
|
socket_path_is_ok(Path::new(DEFAULT_SOCKET_PATH))?;
|
||||||
|
|
||||||
tracing::debug!("Connecting to default socket at {:?}", DEFAULT_SOCKET_PATH);
|
tracing::debug!("Connecting to default socket at {:?}", DEFAULT_SOCKET_PATH);
|
||||||
return match StdUnixStream::connect(DEFAULT_SOCKET_PATH) {
|
return match StdUnixStream::connect(DEFAULT_SOCKET_PATH) {
|
||||||
Ok(socket) => Ok(socket),
|
Ok(socket) => Ok(socket),
|
||||||
@@ -158,7 +182,9 @@ fn connect_to_external_server(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
anyhow::bail!("No socket path provided, and no default socket found");
|
anyhow::bail!(
|
||||||
|
"No socket path provided, and no socket found found at default location {DEFAULT_SOCKET_PATH}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this function is security critical, it should be integration tested
|
// TODO: this function is security critical, it should be integration tested
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ fn parse_group_denylist(denylist_path: &Path, lines: Lines) -> GroupDenylist {
|
|||||||
}
|
}
|
||||||
.trim();
|
.trim();
|
||||||
|
|
||||||
|
if trimmed_line.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let parts: Vec<&str> = trimmed_line.splitn(2, ':').collect();
|
let parts: Vec<&str> = trimmed_line.splitn(2, ':').collect();
|
||||||
if parts.len() != 2 {
|
if parts.len() != 2 {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
|
|||||||
Reference in New Issue
Block a user