Files
maas-samba-ad/.gitea/workflows/build-image.yml
ilkermanap cf07702535 Initial commit: MAAS-deployable Samba Active Directory domain controller
Builds a Debian image that MAAS deploys to bare metal as an Active Directory
domain controller, with first-boot automation that either creates a domain or
joins an existing one without anyone logging in. To a Windows client the result
is an AD domain: same Kerberos, same LDAP, same Group Policy, same domain join.

The request was for "primary and backup domain controllers", which is NT 4
terminology. Active Directory has no such split — every DC holds a writable copy
and any of them can service a logon. What lives on one DC at a time are the five
FSMO roles, one confusingly named "PDC Emulator". The image therefore offers
provision (create the domain) and join (add another equal DC), which is the
distinction that actually exists.

Contents:

  * customize-samba-ad.sh, run inside the packer-maas build VM: installs samba,
    winbind, Kerberos, chrony and rsync, swaps the cloud kernel for the generic
    one, and deletes every trace of a domain so one image can produce many DCs
  * adc-maas-init, a first-boot state machine covering /etc/hosts, node-unique
    identifiers, time, the resolver, provisioning or joining, the service
    switchover and a self-test that proves Kerberos issues a ticket
  * adc-sysvol-sync, a systemd timer implementing the SYSVOL workaround
  * a MAAS curtin preseed, cloud-init examples, and the release pipeline

Two findings shaped the design.

Debian builds Samba against its bundled Heimdal rather than system MIT Kerberos
— samba-ad-dc does not depend on krb5-kdc — so the AD DC role is in Samba's
supported configuration, not the experimental MIT one. The build asserts this
and fails if it ever changes.

Samba implements neither DFS-R nor FRS, so SYSVOL — where Group Policy lives —
does not replicate between DCs. Left alone, a policy created on one DC never
reaches the others and clients behave differently depending on which DC answered
them, with nothing reporting an error. adc-sysvol-sync applies the Samba wiki's
rsync workaround: sync idmap.ldb once so SID-to-uid mappings agree, rsync the
tree, then samba-tool ntacl sysvolreset because rsync carries POSIX bits while
the Windows ACLs live in AD. Without an SSH key to the source DC it exits with
an explanation rather than letting Group Policy diverge quietly.

Also carried over from maas-proxmox, where they were verified on real hardware:
the curtin-hooks that skip the kernel install and pin interface names by MAC,
Type=simple on the first-boot unit to avoid the systemd ordering cycle, and
shipping networking.service disabled so MAAS owns the network on first boot.
Specific to this image, the Debian cloud kernel is replaced with the generic one
— a bare-metal node booted with the cloud kernel can come up with no disk.

Nothing here has been built or deployed. The README says so at the top and in a
Verified status section that separates what was checked from what was not.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-05 14:44:37 +02:00

118 lines
3.8 KiB
YAML

# Copyright (C) 2026 Ilker Manap
# SPDX-License-Identifier: AGPL-3.0-or-later
#
# Builds the MAAS image and publishes it as a Gitea release.
#
# Runs daily, but only *builds* when Debian actually carries a newer samba or
# kernel than the last published release, or once the newest image passes
# MAX_AGE_DAYS. An unconditional daily build would produce a pile of
# near-identical multi-gigabyte artifacts for nothing. Trigger manually with
# `force` to rebuild anyway.
#
# The runner is registered in host mode: steps run directly on the build machine
# as root, because the build needs /dev/kvm, qemu-nbd, FUSE and root privileges.
# Anything that can dispatch a workflow here therefore has root on that machine.
name: build-image
on:
schedule:
- cron: '0 3 * * *'
workflow_dispatch:
inputs:
force:
description: 'Build even if the version has not changed'
type: boolean
default: false
concurrency:
group: build-image
cancel-in-progress: false
jobs:
build:
runs-on: maas-builder
timeout-minutes: 120
env:
GITEA_API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
KEEP_RELEASES: '3'
# Rebuild even without a Proxmox version change once an image reaches this
# age, so Debian base security updates make it into the image.
MAX_AGE_DAYS: '30'
steps:
- name: Check out
# A plain clone rather than actions/checkout: the runner is in host mode
# and has no Node.js runtime for JavaScript actions.
run: |
set -eux
# Step out of the workspace before removing it: the shell starts *in*
# $GITHUB_WORKSPACE, and deleting the current working directory makes
# every later command fail with "Unable to read current working directory".
cd /
rm -rf "$GITHUB_WORKSPACE"
git clone --depth 1 --branch "$GITHUB_REF_NAME" \
"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" "$GITHUB_WORKSPACE"
cd "$GITHUB_WORKSPACE" && git log --oneline -1
- name: Decide whether to build
id: decide
run: |
set -eu
cd "$GITHUB_WORKSPACE"
./scripts/ci/decide-build.sh "$MAX_AGE_DAYS" > "$GITHUB_OUTPUT"
if [ "${{ inputs.force }}" = "true" ]; then
echo "forced by manual trigger"
sed -i 's/^build=no$/build=yes/' "$GITHUB_OUTPUT"
fi
cat "$GITHUB_OUTPUT"
- name: Build
if: steps.decide.outputs.build == 'yes'
run: |
set -eux
cd "$GITHUB_WORKSPACE"
make image
- name: Verify
if: steps.decide.outputs.build == 'yes'
run: |
set -eux
cd "$GITHUB_WORKSPACE"
make verify
- name: Assemble release artifacts
if: steps.decide.outputs.build == 'yes'
run: |
set -eu
cd "$GITHUB_WORKSPACE"
./scripts/ci/assemble-artifacts.sh "${{ steps.decide.outputs.version }}"
- name: Publish
if: steps.decide.outputs.build == 'yes'
run: |
set -eu
cd "$GITHUB_WORKSPACE"
./scripts/ci/publish-release.sh \
"${{ steps.decide.outputs.tag }}" \
"${{ steps.decide.outputs.version }}" \
dist
- name: Prune old releases
if: steps.decide.outputs.build == 'yes'
run: |
set -eu
cd "$GITHUB_WORKSPACE"
./scripts/ci/prune-releases.sh "$KEEP_RELEASES"
- name: Clean up
if: always()
run: |
# A 1.5 GB artifact per run would fill the builder otherwise.
# Runs even when an earlier step left the workspace missing, so cd out first.
cd /
rm -rf "$GITHUB_WORKSPACE/dist" "$GITHUB_WORKSPACE/build" || true
df -h / | tail -1