mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-23 11:25:56 +00:00
feat(phase15): release and security hardening, DPAPI key store, probe & protocol hardening, secret redaction, audit and readiness report
This commit is contained in:
1 parent
b69fa6b867
commit
51e0f136d6
207 files changed
+38235
-7770
No files matched your search
@@ -24,15 +24,30 @@ pub struct Params<'a> {
|
||||
}
|
||||
|
||||
/// Auth tables that hold player data. Everything else (permissions, build info, realmlist) is configuration.
|
||||
const AUTH_PLAYER_TABLES: [&str; 11] =
|
||||
["account", "account_access", "account_banned", "account_muted", "account_password_history", "ip_banned", "logs", "logs_ip_actions", "realmcharacters", "uptime", "rbac_account_permissions"];
|
||||
const AUTH_PLAYER_TABLES: [&str; 11] = [
|
||||
"account",
|
||||
"account_access",
|
||||
"account_banned",
|
||||
"account_muted",
|
||||
"account_password_history",
|
||||
"ip_banned",
|
||||
"logs",
|
||||
"logs_ip_actions",
|
||||
"realmcharacters",
|
||||
"uptime",
|
||||
"rbac_account_permissions",
|
||||
];
|
||||
|
||||
fn copy_dir(src: &Path, dst: &Path, skip: &dyn Fn(&str) -> bool, base: &Path) -> Result<u64> {
|
||||
let mut bytes = 0;
|
||||
for e in fs::read_dir(src)? {
|
||||
let e = e?;
|
||||
let p = e.path();
|
||||
let rel = p.strip_prefix(base).unwrap().to_string_lossy().replace('\\', "/");
|
||||
let rel = p
|
||||
.strip_prefix(base)
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.replace('\\', "/");
|
||||
if skip(&rel) {
|
||||
continue;
|
||||
}
|
||||
@@ -52,27 +67,44 @@ fn copy_dir(src: &Path, dst: &Path, skip: &dyn Fn(&str) -> bool, base: &Path) ->
|
||||
}
|
||||
|
||||
fn seven_zip() -> Result<PathBuf> {
|
||||
for c in ["C:/Program Files/7-Zip/7z.exe", "C:/Program Files (x86)/7-Zip/7z.exe"] {
|
||||
for c in [
|
||||
"C:/Program Files/7-Zip/7z.exe",
|
||||
"C:/Program Files (x86)/7-Zip/7z.exe",
|
||||
] {
|
||||
if Path::new(c).is_file() {
|
||||
return Ok(PathBuf::from(c));
|
||||
}
|
||||
}
|
||||
Err(Error::Invalid("7-Zip is needed to read the repack's database archive (install 7-Zip).".into()))
|
||||
Err(Error::Invalid(
|
||||
"7-Zip is needed to read the repack's database archive (install 7-Zip).".into(),
|
||||
))
|
||||
}
|
||||
|
||||
/// Which repack files belong to a base package's scaffolding.
|
||||
pub fn scaffolding(rel: &str) -> bool {
|
||||
let l = rel.to_lowercase();
|
||||
if l.starts_with(".state") || l.contains("__pycache__") || l.starts_with("core/") && !l.ends_with(".dll") || l.starts_with("source/") || l.starts_with("testing/") {
|
||||
if l.starts_with(".state")
|
||||
|| l.contains("__pycache__")
|
||||
|| l.starts_with("core/") && !l.ends_with(".dll")
|
||||
|| l.starts_with("source/")
|
||||
|| l.starts_with("testing/")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if l.starts_with("bugreport/") {
|
||||
return !(l.starts_with("bugreport/logs") || l.starts_with("bugreport/reports"));
|
||||
}
|
||||
if l.starts_with("mysql/") {
|
||||
return l.starts_with("mysql/bin") || l.starts_with("mysql/lib") || l.starts_with("mysql/share");
|
||||
return l.starts_with("mysql/bin")
|
||||
|| l.starts_with("mysql/lib")
|
||||
|| l.starts_with("mysql/share");
|
||||
}
|
||||
l.starts_with("runtime/") || l.starts_with("scripts/") || l.starts_with("settings/") || l.starts_with("licenses/") || l == "readme.txt" || (l.starts_with("core/") && l.ends_with(".dll") && !l[5..].contains('/'))
|
||||
l.starts_with("runtime/")
|
||||
|| l.starts_with("scripts/")
|
||||
|| l.starts_with("settings/")
|
||||
|| l.starts_with("licenses/")
|
||||
|| l == "readme.txt"
|
||||
|| (l.starts_with("core/") && l.ends_with(".dll") && !l[5..].contains('/'))
|
||||
}
|
||||
|
||||
/// A maintainer's repack may have "detailed logging" switched on: the launcher then rewrites the config templates to Trace
|
||||
@@ -102,7 +134,9 @@ pub fn restore_quiet_logging(settings: &Path) -> Result<()> {
|
||||
pub fn quiet_world_logging(text: &str) -> String {
|
||||
let nl = if text.contains("\r\n") { "\r\n" } else { "\n" };
|
||||
let mut out: Vec<String> = Vec::new();
|
||||
let has_coa = text.lines().any(|l| l.trim_start().starts_with("Logger.coa="));
|
||||
let has_coa = text
|
||||
.lines()
|
||||
.any(|l| l.trim_start().starts_with("Logger.coa="));
|
||||
for line in text.lines() {
|
||||
let l = line.trim();
|
||||
if l.starts_with("Logger.network=") {
|
||||
@@ -123,7 +157,10 @@ pub fn quiet_world_logging(text: &str) -> String {
|
||||
|
||||
pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
if p.out.exists() {
|
||||
return Err(Error::Invalid(format!("{} already exists; choose a new folder.", p.out.display())));
|
||||
return Err(Error::Invalid(format!(
|
||||
"{} already exists; choose a new folder.",
|
||||
p.out.display()
|
||||
)));
|
||||
}
|
||||
fsx::require_space(p.out, 12 * 1024 * 1024 * 1024)?;
|
||||
fs::create_dir_all(p.out)?;
|
||||
@@ -141,7 +178,16 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
}
|
||||
for d in top {
|
||||
// Only these folders can contain scaffolding; the per-file rule decides what inside them is kept.
|
||||
if !["runtime", "scripts", "settings", "bugreport", "licenses", "mysql"].contains(&d.to_lowercase().as_str()) {
|
||||
if ![
|
||||
"runtime",
|
||||
"scripts",
|
||||
"settings",
|
||||
"bugreport",
|
||||
"licenses",
|
||||
"mysql",
|
||||
]
|
||||
.contains(&d.to_lowercase().as_str())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
let dst = p.out.join(&d);
|
||||
@@ -160,11 +206,20 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
say("Extracting the pristine database archive");
|
||||
let archive = p.repack.join("mysql/data.7z");
|
||||
if !archive.is_file() {
|
||||
return Err(Error::Invalid("mysql/data.7z was not found in the repack.".into()));
|
||||
return Err(Error::Invalid(
|
||||
"mysql/data.7z was not found in the repack.".into(),
|
||||
));
|
||||
}
|
||||
let status7 = Command::new(seven_zip()?).arg("x").arg(&archive).arg(format!("-o{}", p.out.join("mysql").display())).arg("-y").output()?;
|
||||
let status7 = Command::new(seven_zip()?)
|
||||
.arg("x")
|
||||
.arg(&archive)
|
||||
.arg(format!("-o{}", p.out.join("mysql").display()))
|
||||
.arg("-y")
|
||||
.output()?;
|
||||
if !status7.status.success() || !p.out.join("mysql/data/acore_world").is_dir() {
|
||||
return Err(Error::Invalid("The database archive could not be extracted.".into()));
|
||||
return Err(Error::Invalid(
|
||||
"The database archive could not be extracted.".into(),
|
||||
));
|
||||
}
|
||||
let _ = fs::remove_file(p.out.join("mysql/data/auto.cnf")); // a new server UUID is generated on first start
|
||||
|
||||
@@ -172,7 +227,12 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
let repack_json = p.out.join("Settings/repack.json");
|
||||
let mut cfg: serde_json::Value = fsx::read_json(&repack_json)?;
|
||||
let real_ports = cfg.clone();
|
||||
for (k, v) in [("mysqlPort", 14307u16), ("authPort", 14724), ("worldPort", 14085), ("raPort", 14443)] {
|
||||
for (k, v) in [
|
||||
("mysqlPort", 14307u16),
|
||||
("authPort", 14724),
|
||||
("worldPort", 14085),
|
||||
("raPort", 14443),
|
||||
] {
|
||||
cfg[k] = v.into();
|
||||
}
|
||||
fsx::atomic_write_json(&repack_json, &cfg)?;
|
||||
@@ -181,7 +241,16 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
if let Some(b) = p.bots {
|
||||
sql.extend(collect_bots_sql(b)?);
|
||||
}
|
||||
let migrations: Vec<_> = sql.iter().map(|f| crate::manifest::Migration { compatible_sha256: vec![], id: f.id.clone(), db: f.db.clone(), sha256: f.sha256.clone(), destructive: false }).collect();
|
||||
let migrations: Vec<_> = sql
|
||||
.iter()
|
||||
.map(|f| crate::manifest::Migration {
|
||||
compatible_sha256: vec![],
|
||||
id: f.id.clone(),
|
||||
db: f.db.clone(),
|
||||
sha256: f.sha256.clone(),
|
||||
destructive: false,
|
||||
})
|
||||
.collect();
|
||||
let staging = std::env::temp_dir().join("coa-cleanbase-sql");
|
||||
let _ = fs::remove_dir_all(&staging);
|
||||
for f in &sql {
|
||||
@@ -191,10 +260,17 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
}
|
||||
// The maintainer's database records `rev_20260906_03_any_race_class.sql` as applied although its 86 race/class starts
|
||||
// are absent (the client patch offers those pairs, so creating such a character failed). The file is idempotent.
|
||||
let any_race_class = sql.iter().find(|f| f.id.contains("any_race_class")).map(|f| f.abs.clone());
|
||||
let any_race_class = sql
|
||||
.iter()
|
||||
.find(|f| f.id.contains("any_race_class"))
|
||||
.map(|f| f.abs.clone());
|
||||
let base_chars: Vec<PathBuf> = {
|
||||
let mut v: Vec<PathBuf> = fs::read_dir(p.core.join("data/sql/base/db_characters"))
|
||||
.map_err(|_| Error::Invalid("data/sql/base/db_characters was not found in the core checkout.".into()))?
|
||||
.map_err(|_| {
|
||||
Error::Invalid(
|
||||
"data/sql/base/db_characters was not found in the core checkout.".into(),
|
||||
)
|
||||
})?
|
||||
.flatten()
|
||||
.map(|e| e.path())
|
||||
.filter(|x| x.extension().map(|e| e == "sql").unwrap_or(false))
|
||||
@@ -208,11 +284,18 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
backup::with_database(out, |db| {
|
||||
// 1. accounts and session data out of auth
|
||||
let existing = db.tables("acore_auth")?;
|
||||
let mut sql = String::from("SET FOREIGN_KEY_CHECKS=0;
|
||||
");
|
||||
for t in AUTH_PLAYER_TABLES.iter().filter(|t| existing.iter().any(|e| e == *t)) {
|
||||
sql.push_str(&format!("TRUNCATE TABLE `acore_auth`.`{t}`;
|
||||
"));
|
||||
let mut sql = String::from(
|
||||
"SET FOREIGN_KEY_CHECKS=0;
|
||||
",
|
||||
);
|
||||
for t in AUTH_PLAYER_TABLES
|
||||
.iter()
|
||||
.filter(|t| existing.iter().any(|e| e == *t))
|
||||
{
|
||||
sql.push_str(&format!(
|
||||
"TRUNCATE TABLE `acore_auth`.`{t}`;
|
||||
"
|
||||
));
|
||||
}
|
||||
sql.push_str("SET FOREIGN_KEY_CHECKS=1;");
|
||||
db.query(&sql)?;
|
||||
@@ -220,7 +303,11 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
db.query("DROP DATABASE IF EXISTS `acore_characters`; CREATE DATABASE `acore_characters` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")?;
|
||||
// The ledger lives in world, so dropping characters does not clear its migration history.
|
||||
// Never carry that history into a freshly rebuilt character database.
|
||||
if db.tables("acore_world")?.iter().any(|t| t == "coa_manager_migrations") {
|
||||
if db
|
||||
.tables("acore_world")?
|
||||
.iter()
|
||||
.any(|t| t == "coa_manager_migrations")
|
||||
{
|
||||
db.query("DELETE FROM acore_world.coa_manager_migrations WHERE `db`='characters';")?;
|
||||
}
|
||||
for f in &base_chars {
|
||||
@@ -228,11 +315,18 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
}
|
||||
// 3. every migration up to the core commit (already-recorded ones are skipped)
|
||||
let before = status(db, &migrations)?;
|
||||
let pending: Vec<_> = migrations.iter().zip(&before).filter(|(_, i)| i.status != Status::Applied).map(|(m, _)| m.clone()).collect();
|
||||
let pending: Vec<_> = migrations
|
||||
.iter()
|
||||
.zip(&before)
|
||||
.filter(|(_, i)| i.status != Status::Applied)
|
||||
.map(|(m, _)| m.clone())
|
||||
.collect();
|
||||
say(&format!("Applying {} database updates", pending.len()));
|
||||
let report = apply_pending(db, &pending, &staging, &|| Ok("(scratch database)".into()))?;
|
||||
if let Some((id, why)) = report.failed {
|
||||
return Err(Error::Invalid(format!("Database update {id} failed: {why}")));
|
||||
return Err(Error::Invalid(format!(
|
||||
"Database update {id} failed: {why}"
|
||||
)));
|
||||
}
|
||||
// 3b. A module script older than a table rename re-creates the old table next to the renamed one (the core then
|
||||
// logs an error at every start). Fold its rows into the new table and drop it.
|
||||
@@ -242,7 +336,13 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
}
|
||||
// 3c. re-run the race/class starts when their effect is missing
|
||||
if let Some(file) = &any_race_class {
|
||||
if db.query("SELECT COUNT(*) FROM acore_world.playercreateinfo WHERE race=7 AND class=27;")?.trim() == "0" {
|
||||
if db
|
||||
.query(
|
||||
"SELECT COUNT(*) FROM acore_world.playercreateinfo WHERE race=7 AND class=27;",
|
||||
)?
|
||||
.trim()
|
||||
== "0"
|
||||
{
|
||||
db.run_sql_file("acore_world", file)?;
|
||||
}
|
||||
}
|
||||
@@ -251,20 +351,33 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
// 4. prove it is clean
|
||||
let accounts = db.query("SELECT COUNT(*) FROM acore_auth.account;")?;
|
||||
// nothing but the template characters may exist
|
||||
let chars = db.query(&format!("SELECT COUNT(*) FROM acore_characters.characters WHERE account<>{};", crate::companions::TEMPLATE_ACCOUNT))?;
|
||||
let chars = db.query(&format!(
|
||||
"SELECT COUNT(*) FROM acore_characters.characters WHERE account<>{};",
|
||||
crate::companions::TEMPLATE_ACCOUNT
|
||||
))?;
|
||||
let templates = crate::companions::template_count(db)?;
|
||||
if accounts != "0" || chars != "0" || templates != 21 {
|
||||
return Err(Error::Invalid(format!("The database is not clean ({accounts} accounts, {chars} player characters, {templates} templates).")));
|
||||
}
|
||||
if let Some(p) = crate::schema_check::check(db, p.tree)?.first() {
|
||||
return Err(Error::Invalid(format!("The rebuilt base database is incomplete: {}.{}.{}: {}", p.database, p.table, p.column, p.detail)));
|
||||
return Err(Error::Invalid(format!(
|
||||
"The rebuilt base database is incomplete: {}.{}.{}: {}",
|
||||
p.database, p.table, p.column, p.detail
|
||||
)));
|
||||
}
|
||||
crate::schema_check::capture(db, out)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
say("Removing run-time leftovers");
|
||||
for leftover in [".state", "mysql/logs", "mysql/my.ini", "mysql/admin-client.ini", "mysql/mysql.pid", "Core/Logs"] {
|
||||
for leftover in [
|
||||
".state",
|
||||
"mysql/logs",
|
||||
"mysql/my.ini",
|
||||
"mysql/admin-client.ini",
|
||||
"mysql/mysql.pid",
|
||||
"Core/Logs",
|
||||
] {
|
||||
let path = p.out.join(leftover);
|
||||
if path.is_dir() {
|
||||
fs::remove_dir_all(&path)?;
|
||||
@@ -279,7 +392,12 @@ pub fn build(p: &Params, say: &dyn Fn(&str)) -> Result<()> {
|
||||
fsx::atomic_write_json(&repack_json, &shipped)?;
|
||||
|
||||
say("Adding the release files");
|
||||
copy_dir(p.tree, p.out, &|rel| rel == crate::schema_check::CONTRACT, p.tree)?;
|
||||
copy_dir(
|
||||
p.tree,
|
||||
p.out,
|
||||
&|rel| rel == crate::schema_check::CONTRACT,
|
||||
p.tree,
|
||||
)?;
|
||||
if let Some(data) = p.data {
|
||||
say("Copying game data");
|
||||
fs::create_dir_all(p.out.join("Data"))?;
|
||||
@@ -294,10 +412,30 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn scaffolding_keeps_the_launcher_and_drops_runtime_state_and_live_data() {
|
||||
for keep in ["Runtime/python/python.exe", "Scripts/manage.py", "Settings/worldserver.conf.template", "mysql/bin/mysqld.exe", "mysql/share/english/errmsg.sys", "BugReport/relay.py", "Core/libssl-3-x64.dll", "README.txt"] {
|
||||
for keep in [
|
||||
"Runtime/python/python.exe",
|
||||
"Scripts/manage.py",
|
||||
"Settings/worldserver.conf.template",
|
||||
"mysql/bin/mysqld.exe",
|
||||
"mysql/share/english/errmsg.sys",
|
||||
"BugReport/relay.py",
|
||||
"Core/libssl-3-x64.dll",
|
||||
"README.txt",
|
||||
] {
|
||||
assert!(scaffolding(keep), "{keep}");
|
||||
}
|
||||
for drop in [".state/world.json", "mysql/data/acore_world/x.ibd", "mysql/logs/error.log", "Core/worldserver.exe", "Core/Logs/Server.log", "BugReport/reports/a.json", "Source/server-source.zip", "Scripts/__pycache__/x.pyc", "Testing/notes.md", "mysql/data.7z"] {
|
||||
for drop in [
|
||||
".state/world.json",
|
||||
"mysql/data/acore_world/x.ibd",
|
||||
"mysql/logs/error.log",
|
||||
"Core/worldserver.exe",
|
||||
"Core/Logs/Server.log",
|
||||
"BugReport/reports/a.json",
|
||||
"Source/server-source.zip",
|
||||
"Scripts/__pycache__/x.pyc",
|
||||
"Testing/notes.md",
|
||||
"mysql/data.7z",
|
||||
] {
|
||||
assert!(!scaffolding(drop), "{drop}");
|
||||
}
|
||||
}
|
||||
@@ -305,14 +443,29 @@ mod tests {
|
||||
#[test]
|
||||
fn detailed_logging_templates_are_replaced_by_their_originals() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
fs::write(d.path().join("worldserver.conf.template"), "Logger.root=6,Console Server").unwrap();
|
||||
fs::write(d.path().join("worldserver.conf.template.original"), "Logger.root=2,Console Server").unwrap();
|
||||
fs::write(
|
||||
d.path().join("worldserver.conf.template"),
|
||||
"Logger.root=6,Console Server",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
d.path().join("worldserver.conf.template.original"),
|
||||
"Logger.root=2,Console Server",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(d.path().join("authserver.conf.template"), "unchanged").unwrap();
|
||||
restore_quiet_logging(d.path()).unwrap();
|
||||
let restored = fs::read_to_string(d.path().join("worldserver.conf.template")).unwrap();
|
||||
assert!(restored.starts_with("Logger.root=2,Console Server") && !restored.contains("Logger.root=6"), "{restored}");
|
||||
assert!(
|
||||
restored.starts_with("Logger.root=2,Console Server")
|
||||
&& !restored.contains("Logger.root=6"),
|
||||
"{restored}"
|
||||
);
|
||||
assert!(!d.path().join("worldserver.conf.template.original").exists());
|
||||
assert_eq!(fs::read_to_string(d.path().join("authserver.conf.template")).unwrap(), "unchanged");
|
||||
assert_eq!(
|
||||
fs::read_to_string(d.path().join("authserver.conf.template")).unwrap(),
|
||||
"unchanged"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -326,7 +479,14 @@ mod tests {
|
||||
#[test]
|
||||
fn refuses_to_overwrite_an_existing_output_folder() {
|
||||
let d = tempfile::tempdir().unwrap();
|
||||
let p = Params { repack: d.path(), core: d.path(), bots: None, tree: d.path(), data: None, out: d.path() };
|
||||
let p = Params {
|
||||
repack: d.path(),
|
||||
core: d.path(),
|
||||
bots: None,
|
||||
tree: d.path(),
|
||||
data: None,
|
||||
out: d.path(),
|
||||
};
|
||||
assert!(build(&p, &|_| {}).is_err());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user