feat(meshcentral): restrict admin bootstrap and .env loading to debug builds (VS-28) #43
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/restrict-admin-bootstrap-debug-builds"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
VS-28: Restrict ADMIN_USERNAME/ADMIN_PASSWORD bootstrap and
./.envloading to debug buildsTwo dev conveniences in the
meshcentralbinary ran in every build, including the release binary shipped in the OCI image: the first-run admin bootstrap fromADMIN_USERNAME/ADMIN_PASSWORD, and unconditional./.envloading viadotenvy. A production container could silently gain an env-credential site admin (siteadmin = 0xFFFFFFFF) and pick up a stray.envfrom its working directory; the bootstrapped user also made/api/setupreturn 404 before an operator saw the onboarding flow.Changes
crates/meshcentral/src/main.rs:dotenvy::dotenv()is now#[cfg(debug_assertions)], so release binaries never read./.env. Thebootstrapmodule and themaybe_bootstrap_admincall are compiled out of release builds the same way. In the release path, ifADMIN_USERNAMEorADMIN_PASSWORDis present, a singlewarn!is logged pointing operators to setup mode (/api/setup) ormeshcentral create-account. The check is a plain env read and does not pull in any bootstrap logic..env.example: the "First-run admin bootstrap (DEV ONLY)" block now states release binaries ignore these vars and do not read.env, and points to setup mode /create-accountfor production.README.md: the setup-mode section notes the dev-only bootstrap is compiled out of release builds.Mechanism is
cfg!(debug_assertions)(no new feature flags or runtime knobs), which cleanly splitsjust devfrom the--releaseOCI image.cargo testbuilds withdebug_assertionson, so existing tests are unaffected.Verification
cargo fmt --check: cleancargo clippy --all-targets -- -D warnings: clean in both debug and release profiles (nodead_codefrom the cfg split)cargo build -p meshcentral --all-targets: okcargo test --lib: ok🤖 Generated with Claude Code