9 Commits

Author SHA1 Message Date
Mikaël Cluseau 2aeb9ee132 chore: Release dkl version 1.2.3 2026-07-17 16:59:24 +02:00
Mikaël Cluseau a003043c93 version bump 2026-07-17 14:28:45 +02:00
Mikaël Cluseau 891c601466 also release dls 2026-07-17 14:27:32 +02:00
Mikaël Cluseau 8f94cccd41 cargo update 2026-07-17 14:25:28 +02:00
Mikaël Cluseau 4d4ce9068e dls: add ca cert restore 2026-07-17 14:12:03 +02:00
Mikaël Cluseau fdf6085a35 more verbose apply errors 2026-07-15 16:43:46 +02:00
Mikaël Cluseau 7fb751c2ef add golang's yaml serializer compat aliases 2026-07-01 11:23:00 +02:00
Mikaël Cluseau ae6c62d5de dls config upload 2026-06-25 12:26:37 +02:00
Mikaël Cluseau 8246e237bf clonable config 2026-06-25 11:45:36 +02:00
8 changed files with 289 additions and 472 deletions
Generated
+173 -433
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "dkl" name = "dkl"
version = "1.2.1" version = "1.2.3"
edition = "2024" edition = "2024"
[profile.release] [profile.release]
+2 -2
View File
@@ -1,4 +1,4 @@
from mcluseau/rust:1.95.0 as build from mcluseau/rust:1.97.0 as build
workdir /app workdir /app
copy . . copy . .
@@ -10,6 +10,6 @@ run \
&& find target/release -maxdepth 1 -type f -executable -exec cp -v {} /dist/ + && find target/release -maxdepth 1 -type f -executable -exec cp -v {} /dist/ +
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
from alpine:3.23.4 from alpine:3.24.0
copy --from=build /dist/ /bin/ copy --from=build /dist/ /bin/
+6 -4
View File
@@ -2,15 +2,17 @@ set -ex
tag=$(git describe --always) tag=$(git describe --always)
repo=novit.tech/direktil/dkl:$tag repo=novit.tech/direktil/dkl:$tag
docker build --push --platform=linux/amd64,linux/arm64 . -t $repo
publish() { publish() {
arch=$1 arch=$1
pf=$2 pf=$2
docker build --push --platform=$pf . -t $repo
for bin in dkl dls; do
curl --user $(jq '.auths["novit.tech"].auth' ~/.docker/config.json -r |base64 -d) \ curl --user $(jq '.auths["novit.tech"].auth' ~/.docker/config.json -r |base64 -d) \
--upload-file <(docker run --rm --platform $pf $repo cat /bin/dkl) \ --upload-file <(docker run --rm --platform $pf $repo cat /bin/$bin) \
https://novit.tech/api/packages/direktil/generic/dkl/$tag/dkl.$arch https://novit.tech/api/packages/direktil/generic/dkl/$tag/$bin.$arch
done
} }
publish x86_64 linux/amd64 publish x86_64 linux/amd64
+4 -4
View File
@@ -1,4 +1,4 @@
use eyre::{Result, format_err}; use eyre::{Result, format_err, eyre};
use log::info; use log::info;
use std::path::Path; use std::path::Path;
use tokio::fs; use tokio::fs;
@@ -36,14 +36,14 @@ pub async fn file(file: &File, root: &str, dry_run: bool) -> Result<()> {
if dry_run { if dry_run {
info!("would create {} ({} bytes)", file.path, content.len()); info!("would create {} ({} bytes)", file.path, content.len());
} else { } else {
fs::write(path, &content).await?; fs::write(path, &content).await.map_err(|e| eyre!("write {}: {e}", path.display()))?;
} }
} }
K::Dir => { K::Dir => {
if dry_run { if dry_run {
info!("would create {} (directory)", file.path); info!("would create {} (directory)", file.path);
} else { } else {
fs::create_dir(path).await?; fs::create_dir(path).await.map_err(|e| eyre!("create dir {}: {e}", path.display()))?;
} }
} }
K::Symlink(tgt) => { K::Symlink(tgt) => {
@@ -51,7 +51,7 @@ pub async fn file(file: &File, root: &str, dry_run: bool) -> Result<()> {
info!("would create {} (symlink to {})", file.path, tgt); info!("would create {} (symlink to {})", file.path, tgt);
} else { } else {
let _ = fs::remove_file(path).await; // we're ln --force let _ = fs::remove_file(path).await; // we're ln --force
fs::symlink(tgt, path).await?; fs::symlink(tgt, path).await.map_err(|e| eyre!("symlink {} -> {tgt}: {e}", path.display()))?;
} }
} }
} }
+38 -8
View File
@@ -22,6 +22,8 @@ struct Cli {
#[derive(Subcommand)] #[derive(Subcommand)]
enum Command { enum Command {
#[command(subcommand)]
Config(Config),
Clusters, Clusters,
Cluster { Cluster {
cluster: String, cluster: String,
@@ -48,6 +50,11 @@ enum Command {
}, },
} }
#[derive(Subcommand)]
enum Config {
Upload { config_path: PathBuf },
}
#[derive(Subcommand)] #[derive(Subcommand)]
enum DlSet { enum DlSet {
Sign { Sign {
@@ -77,6 +84,10 @@ enum ClusterCommand {
#[arg(default_value = "cluster")] #[arg(default_value = "cluster")]
name: String, name: String,
}, },
SetCaCert {
ca: String,
cert_path: PathBuf,
},
Token { Token {
#[arg(default_value = "admin")] #[arg(default_value = "admin")]
name: String, name: String,
@@ -131,18 +142,26 @@ async fn main() -> eyre::Result<()> {
let dls = dls(); let dls = dls();
let cluster = dls.cluster(cluster); let cluster = dls.cluster(cluster);
let Some(command) = command else {
write_json(&cluster.config().await?);
return Ok(());
};
use ClusterCommand as CC; use ClusterCommand as CC;
match command { match command {
None => write_json(&cluster.config().await?), CC::CaCert { name } => write_raw(&cluster.ca_cert(&name).await?),
Some(CC::CaCert { name }) => write_raw(&cluster.ca_cert(&name).await?), CC::SetCaCert { ca, cert_path } => {
Some(CC::Token { name }) => println!("{}", &cluster.token(&name).await?), let cert = tokio::fs::read(cert_path).await?;
Some(CC::Addons) => write_raw(&cluster.addons().await?), cluster.set_ca_cert(&ca, cert).await?;
Some(CC::SshSign { }
CC::Token { name } => println!("{}", &cluster.token(&name).await?),
CC::Addons => write_raw(&cluster.addons().await?),
CC::SshSign {
user_public_key, user_public_key,
principal, principal,
validity, validity,
options, options,
}) => { } => {
let pub_key = tokio::fs::read_to_string(user_public_key).await?; let pub_key = tokio::fs::read_to_string(user_public_key).await?;
let cert = cluster let cert = cluster
.ssh_userca_sign(&dls::SshSignReq { .ssh_userca_sign(&dls::SshSignReq {
@@ -154,12 +173,12 @@ async fn main() -> eyre::Result<()> {
.await?; .await?;
write_raw(&cert); write_raw(&cert);
} }
Some(CC::KubeSign { CC::KubeSign {
csr, csr,
user, user,
group, group,
validity, validity,
}) => { } => {
let csr = tokio::fs::read_to_string(csr).await?; let csr = tokio::fs::read_to_string(csr).await?;
let cert = cluster let cert = cluster
.kube_sign(&dls::KubeSignReq { .kube_sign(&dls::KubeSignReq {
@@ -255,6 +274,17 @@ async fn main() -> eyre::Result<()> {
StoreOp::Set { data_path, value } => s.write(data_path, value.as_bytes()).await?, StoreOp::Set { data_path, value } => s.write(data_path, value.as_bytes()).await?,
} }
} }
C::Config(cmd) => match cmd {
Config::Upload { config_path } => {
let cfg = fs::read(&config_path).await?;
let cfg: dls::Config = if config_path.ends_with(".yaml") {
serde_yaml::from_slice(&cfg)?
} else {
serde_json::from_slice(&cfg)?
};
dls().upload_config(&cfg).await?;
}
},
}; };
Ok(()) Ok(())
+57 -12
View File
@@ -77,6 +77,15 @@ impl Client {
Ok(resp.bytes_stream()) Ok(resp.bytes_stream())
} }
pub async fn upload_config(&self, config: &Config) -> Result<()> {
do_req(self.req(Method::POST, "configs")?.json(config), &self.token).await?;
Ok(())
}
pub async fn get_config(&self) -> Result<Config> {
self.get_json("config").await
}
pub async fn get_json<T: serde::de::DeserializeOwned>(&self, path: impl Display) -> Result<T> { pub async fn get_json<T: serde::de::DeserializeOwned>(&self, path: impl Display) -> Result<T> {
self.req_json(self.get(&path)?).await self.req_json(self.get(&path)?).await
} }
@@ -145,6 +154,18 @@ impl<'t> Cluster<'t> {
Ok(resp.bytes().await.map_err(Error::Read)?.to_vec()) Ok(resp.bytes().await.map_err(Error::Read)?.to_vec())
} }
pub async fn set_ca_cert(&self, ca: &str, cert: Vec<u8>) -> Result<()> {
let req = self.dls.req(
Method::PUT,
format!("clusters/{}/CAs/{ca}/certificate", self.name),
)?;
let req = req
.body(cert)
.header("Content-Type", "application/x-x509-ca-cert");
do_req(req, &self.dls.token).await?;
Ok(())
}
pub async fn kube_sign(&self, sign_req: &KubeSignReq) -> Result<Vec<u8>> { pub async fn kube_sign(&self, sign_req: &KubeSignReq) -> Result<Vec<u8>> {
let req = (self.dls).req(Method::POST, format!("clusters/{}/kube/sign", self.name))?; let req = (self.dls).req(Method::POST, format!("clusters/{}/kube/sign", self.name))?;
let req = req.json(sign_req); let req = req.json(sign_req);
@@ -174,17 +195,23 @@ impl<'t> Host<'t> {
} }
#[derive(Default, serde::Deserialize, serde::Serialize)] #[derive(Default, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "PascalCase")] #[serde(default, rename_all = "PascalCase")]
pub struct Config { pub struct Config {
#[serde(default, deserialize_with = "deserialize_null_as_default")] #[serde(deserialize_with = "deserialize_null_as_default", alias = "clusters")]
pub clusters: Vec<ClusterConfig>, pub clusters: Vec<ClusterConfig>,
#[serde(default, deserialize_with = "deserialize_null_as_default")] #[serde(deserialize_with = "deserialize_null_as_default", alias = "hosts")]
pub hosts: Vec<HostConfig>, pub hosts: Vec<HostConfig>,
#[serde(default, deserialize_with = "deserialize_null_as_default")] #[serde(
deserialize_with = "deserialize_null_as_default",
alias = "hosttemplates"
)]
pub host_templates: Vec<HostConfig>, pub host_templates: Vec<HostConfig>,
#[serde(default, rename = "SSLConfig")] #[serde(default, rename = "SSLConfig", alias = "sslconfig")]
pub ssl_config: String, pub ssl_config: String,
#[serde(default, deserialize_with = "deserialize_null_as_default")] #[serde(
deserialize_with = "deserialize_null_as_default",
alias = "extracacerts"
)]
pub extra_ca_certs: Map<String, String>, pub extra_ca_certs: Map<String, String>,
} }
@@ -202,40 +229,58 @@ where
#[derive(serde::Deserialize, serde::Serialize)] #[derive(serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "PascalCase")] #[serde(rename_all = "PascalCase")]
pub struct ClusterConfig { pub struct ClusterConfig {
#[serde(alias = "name")]
pub name: String, pub name: String,
#[serde(alias = "bootstrappods")]
pub bootstrap_pods: String, pub bootstrap_pods: String,
#[serde(alias = "addons")]
pub addons: String, pub addons: String,
} }
#[derive(Default, serde::Deserialize, serde::Serialize)] #[derive(Default, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "PascalCase")] #[serde(rename_all = "PascalCase")]
pub struct HostConfig { pub struct HostConfig {
#[serde(alias = "name")]
pub name: String, pub name: String,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "cluster_name",
alias = "clustername"
)]
pub cluster_name: Option<String>, pub cluster_name: Option<String>,
#[serde(rename = "IPs")] #[serde(rename = "IPs", alias = "ips")]
pub ips: Vec<IpAddr>, pub ips: Vec<IpAddr>,
#[serde(default, skip_serializing_if = "Map::is_empty")] #[serde(default, skip_serializing_if = "Map::is_empty", alias = "labels")]
pub labels: Map<String, String>, pub labels: Map<String, String>,
#[serde(default, skip_serializing_if = "Map::is_empty")] #[serde(default, skip_serializing_if = "Map::is_empty", alias = "annotations")]
pub annotations: Map<String, String>, pub annotations: Map<String, String>,
#[serde(rename = "IPXE", skip_serializing_if = "Option::is_none")] #[serde(
rename = "IPXE",
skip_serializing_if = "Option::is_none",
alias = "ipxe"
)]
pub ipxe: Option<String>, pub ipxe: Option<String>,
#[serde(alias = "initrd")]
pub initrd: String, pub initrd: String,
#[serde(alias = "kernel")]
pub kernel: String, pub kernel: String,
#[serde(alias = "versions")]
pub versions: Map<String, String>, pub versions: Map<String, String>,
/// initrd config template /// initrd config template
#[serde(alias = "bootstrapconfig")]
pub bootstrap_config: String, pub bootstrap_config: String,
/// files to add to the final initrd config, with rendering /// files to add to the final initrd config, with rendering
#[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty", alias = "initrdfiles")]
pub initrd_files: Vec<crate::File>, pub initrd_files: Vec<crate::File>,
/// system config template /// system config template
#[serde(alias = "config")]
pub config: String, pub config: String,
} }
+8 -8
View File
@@ -11,7 +11,7 @@ pub mod logger;
pub mod proxy; pub mod proxy;
pub mod rc; pub mod rc;
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
pub struct Config { pub struct Config {
pub layers: Vec<String>, pub layers: Vec<String>,
pub root_user: RootUser, pub root_user: RootUser,
@@ -25,14 +25,14 @@ pub struct Config {
pub users: Vec<User>, pub users: Vec<User>,
} }
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
pub struct RootUser { pub struct RootUser {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub password_hash: Option<String>, pub password_hash: Option<String>,
pub authorized_keys: Vec<String>, pub authorized_keys: Vec<String>,
} }
#[derive(Debug, Default, serde::Deserialize, serde::Serialize)] #[derive(Debug, Default, Clone, serde::Deserialize, serde::Serialize)]
pub struct Mount { pub struct Mount {
pub dev: String, pub dev: String,
pub path: String, pub path: String,
@@ -42,14 +42,14 @@ pub struct Mount {
pub options: Option<String>, pub options: Option<String>,
} }
#[derive(Debug, serde::Deserialize, serde::Serialize)] #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct Group { pub struct Group {
pub name: String, pub name: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub gid: Option<u32>, pub gid: Option<u32>,
} }
#[derive(Debug, serde::Deserialize, serde::Serialize)] #[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct User { pub struct User {
pub name: String, pub name: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@@ -58,7 +58,7 @@ pub struct User {
pub gid: Option<u32>, pub gid: Option<u32>,
} }
#[derive(Default, Debug, PartialEq, Eq, serde::Deserialize, serde::Serialize)] #[derive(Default, Debug, Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
pub struct File { pub struct File {
pub path: String, pub path: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@@ -111,12 +111,12 @@ impl Config {
} }
pub fn base64_decode(s: &str) -> Result<Vec<u8>, base64::DecodeError> { pub fn base64_decode(s: &str) -> Result<Vec<u8>, base64::DecodeError> {
use base64::{Engine as _, prelude::BASE64_STANDARD_NO_PAD as B64}; use base64::{prelude::BASE64_STANDARD_NO_PAD as B64, Engine as _};
B64.decode(s.trim_end_matches('=')) B64.decode(s.trim_end_matches('='))
} }
pub fn base64_encode(b: &[u8]) -> String { pub fn base64_encode(b: &[u8]) -> String {
use base64::{Engine as _, prelude::BASE64_STANDARD as B64}; use base64::{prelude::BASE64_STANDARD as B64, Engine as _};
B64.encode(b) B64.encode(b)
} }