[control] Dev mode: throw-away CA and certificates for three dev hosts; push step skipped without a remote
This commit is contained in:
Generated
+1
@@ -1064,6 +1064,7 @@ dependencies = [
|
||||
"ianitor-edge",
|
||||
"ianitor-testkit",
|
||||
"log",
|
||||
"rcgen",
|
||||
"ring",
|
||||
"rustls",
|
||||
"serde",
|
||||
|
||||
@@ -29,6 +29,8 @@ ring.workspace = true
|
||||
base64.workspace = true
|
||||
http.workspace = true
|
||||
bytes.workspace = true
|
||||
# Dev mode only: a throw-away CA for the dev hosts (the Domi CA arrives in phase 3).
|
||||
rcgen.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
ianitor-testkit.workspace = true
|
||||
|
||||
@@ -18,6 +18,44 @@ use ianitor_control::repo::Repo;
|
||||
use ianitor_control::tokens::Tokens;
|
||||
use ianitor_control::util::{hex, random, write_atomic};
|
||||
|
||||
/// Hosts that get a certificate from the dev CA, so `tls = "domi"` works for them.
|
||||
const DEV_HOSTS: [&str; 3] = ["app.dev.test", "wiki.dev.test", "photos.dev.test"];
|
||||
|
||||
/// A throw-away CA and certificates for [`DEV_HOSTS`] in `certs/`; the CA as `dev-ca.crt`.
|
||||
fn dev_certs(dir: &Path) -> Result<(), String> {
|
||||
use rcgen::{
|
||||
BasicConstraints, CertificateParams, DnType, IsCa, Issuer, KeyPair, KeyUsagePurpose,
|
||||
};
|
||||
let e = |x: rcgen::Error| x.to_string();
|
||||
let ca_key = KeyPair::generate().map_err(e)?;
|
||||
let mut ca = CertificateParams::new(Vec::<String>::new()).map_err(e)?;
|
||||
ca.distinguished_name
|
||||
.push(DnType::CommonName, "Ianitor dev CA");
|
||||
ca.is_ca = IsCa::Ca(BasicConstraints::Constrained(0));
|
||||
ca.key_usages = vec![
|
||||
KeyUsagePurpose::KeyCertSign,
|
||||
KeyUsagePurpose::DigitalSignature,
|
||||
];
|
||||
let ca_cert = ca.self_signed(&ca_key).map_err(e)?;
|
||||
std::fs::write(dir.join("certs/dev-ca.crt"), ca_cert.pem()).map_err(|x| x.to_string())?;
|
||||
let issuer = Issuer::new(ca, ca_key);
|
||||
for h in DEV_HOSTS {
|
||||
let key = KeyPair::generate().map_err(e)?;
|
||||
let mut p = CertificateParams::new(vec![h.to_owned()]).map_err(e)?;
|
||||
p.distinguished_name.push(DnType::CommonName, h);
|
||||
let cert = p.signed_by(&key, &issuer).map_err(e)?;
|
||||
std::fs::write(dir.join(format!("certs/{h}.crt")), cert.pem())
|
||||
.map_err(|x| x.to_string())?;
|
||||
write_atomic(
|
||||
&dir.join(format!("certs/{h}.key")),
|
||||
key.serialize_pem().as_bytes(),
|
||||
0o600,
|
||||
)
|
||||
.map_err(|x| x.to_string())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const SITE: &str = "# Dev site settings. Sign-in goes to an Authelia that may not run here.\n\
|
||||
[forward_auth]\nurl = \"http://127.0.0.1:9091/api/authz/forward-auth\"\n";
|
||||
|
||||
@@ -90,6 +128,7 @@ pub async fn run(args: &[String]) -> Result<(), String> {
|
||||
] {
|
||||
std::fs::create_dir_all(dir.join(d)).map_err(|e| e.to_string())?;
|
||||
}
|
||||
dev_certs(&dir)?;
|
||||
let key = hex(&random::<32>().map_err(|e| e.to_string())?);
|
||||
write_atomic(&dir.join("creds/share-link-key"), key.as_bytes(), 0o600)
|
||||
.map_err(|e| e.to_string())?;
|
||||
@@ -153,9 +192,10 @@ pub async fn run(args: &[String]) -> Result<(), String> {
|
||||
println!("Routes repository: {}", cfg.routes.repo.display());
|
||||
match &edge_bin {
|
||||
Some(b) => println!(
|
||||
"Dev proxy: {} on https://127.0.0.1:18443 (HTTP 18080); Domi hosts need certificates in {}",
|
||||
"Dev proxy: {} on https://127.0.0.1:18443 (HTTP 18080). tls = \"domi\" works for {}; CA: {}",
|
||||
b.display(),
|
||||
dir.join("certs").display()
|
||||
DEV_HOSTS.join(", "),
|
||||
dir.join("certs/dev-ca.crt").display()
|
||||
),
|
||||
None => println!(
|
||||
"No ianitor-edge found: applies are written but not loaded or watched (use --edge-bin)."
|
||||
|
||||
@@ -790,11 +790,12 @@ impl Control {
|
||||
)
|
||||
.await;
|
||||
}
|
||||
let push_step = self.push_step();
|
||||
self.update(&id, |r| {
|
||||
r.step("write", "done");
|
||||
r.step("reload", "skipped");
|
||||
r.step("watch", "skipped");
|
||||
r.step("push", "pending");
|
||||
r.step("push", push_step);
|
||||
});
|
||||
self.finish(
|
||||
&id,
|
||||
@@ -963,11 +964,21 @@ impl Control {
|
||||
let _ = self.journal(&j);
|
||||
crash::point("promoted");
|
||||
self.clear_journal();
|
||||
self.update(&id, |r| r.step("push", "pending"));
|
||||
let push_step = self.push_step();
|
||||
self.update(&id, |r| r.step("push", push_step));
|
||||
self.finish(&id, "kept", Some(kept_reason), Vec::new());
|
||||
self.push_wake.notify_one();
|
||||
}
|
||||
|
||||
/// The push step of a kept apply: pending, or skipped when there is no remote.
|
||||
fn push_step(&self) -> &'static str {
|
||||
if self.cfg.routes.remote.is_some() {
|
||||
"pending"
|
||||
} else {
|
||||
"skipped"
|
||||
}
|
||||
}
|
||||
|
||||
fn promote(&self) -> std::io::Result<()> {
|
||||
for (trial, fin) in [
|
||||
(self.cfg.trial_path(), self.cfg.edge.config.clone()),
|
||||
@@ -1260,7 +1271,8 @@ impl Control {
|
||||
"confirmed" | "promoted" => {
|
||||
self.promote().map_err(|e| e.to_string())?;
|
||||
self.clear_journal();
|
||||
self.update(&j.apply_id, |r| r.step("push", "pending"));
|
||||
let push_step = self.push_step();
|
||||
self.update(&j.apply_id, |r| r.step("push", push_step));
|
||||
self.finish(&j.apply_id, "kept", None, Vec::new());
|
||||
}
|
||||
_ => {
|
||||
|
||||
Reference in New Issue
Block a user