windows: fix first-boot races and non-idempotent stages

A from-scratch rebuild surfaced three defects that only appear on a clean
deployment:

- dc01-post: `Set-ADObject -Identity <sAMAccountName>` raises
  ADIdentityNotFoundException even right after New-ADUser, so resolve the
  DN once and reuse it. The stage aborted before DNS, flags, DHCP and the
  audit policy, leaving a half-built domain.
- bootstrap ran the role script at first boot while `provision` also ran
  it. fs01 tried to join a domain that did not exist yet, and dc01 ran two
  promotions concurrently; the loser wrote "FAIL Stream was not readable".
  Roles are now only started by the harness, which orders them.
- fs01: the `.url` MIME existence test read the staticContent element
  (-Name '.') instead of its collection, so any re-run died on a duplicate
  entry. Test -Name 'collection'.

Every stage now takes a PID-based lock: a duplicate start exits instead of
racing the real one.

Validated on a fresh build: doctor 0 warnings, and the full path
(site -> SMB -> AS-REP -> Kerberoast -> WinRM -> ACL -> replication ->
DCSync) reproduces.
This commit is contained in:
2026-10-24 16:38:37 -04:00
parent 95d70fa5a4
commit ca72e1aa2e
7 changed files with 69 additions and 5 deletions
+5 -2
View File
@@ -98,10 +98,13 @@ try {
Set-Content -Path "$base\stamp.txt" -Encoding ascii
# ------------------------------------------------------------------ role
# The role stages are driven by the host (`./lab.sh provision`), which orders
# them: the DC must be promoted before a member tries to join. Running them
# here as well made every guest race the harness — fs01 joined before the
# domain existed, and dc01 ran two promotions at once.
$role = Join-Path $here "roles\$($Config.Role).ps1"
if (Test-Path $role) {
Write-Host "bootstrap: running role $($Config.Role)"
& $role
Write-Host "bootstrap: role $($Config.Role) staged, waiting for ./lab.sh provision"
} else {
Write-Host "bootstrap: no role script for '$($Config.Role)' yet (phase 5)"
}