Preserve installed release metadata and receiver assignments

This commit is contained in:
parkel committed 2026-11-24 02:07:23 +01:00
1 parent 8f5f9ef510
commit 09672ef18e
4 files changed
+43 -11

No files matched your search

+14
View File
@@ -206,6 +206,19 @@ def check_destination(settings):
raise InstallError("Choose a dedicated mail or DNS receiver.") raise InstallError("Choose a dedicated mail or DNS receiver.")
if "mail" in settings["roles"] and settings["tls"] == "provided": if "mail" in settings["roles"] and settings["tls"] == "provided":
certificate(settings, "mail") certificate(settings, "mail")
for role in settings["roles"]:
unit = engine.SYSTEMD / f"coulobre-{role}-apply@.service"
state_file = NODE_STATE / f"{role}.json"
if unit.is_file() and (
not state_file.is_file()
or json.loads(state_file.read_text())["complete"]
):
engine.run(
engine.BINDIR / "coulobre-node-setup",
"check-receiver",
role,
label=f"Check the existing {role} service",
)
else: else:
standalone_plan(settings) standalone_plan(settings)
if ( if (
@@ -279,6 +292,7 @@ def install_on_node(settings):
settings["scope"], settings["scope"],
key, key,
*settings["domains"], *settings["domains"],
"--keep-domains",
) )
else: else:
command = ("authorize-panel", name, key) command = ("authorize-panel", name, key)
+13 -4
View File
@@ -288,7 +288,9 @@ def authorize_panel(role, key_path):
write_new_file(destination, entry, mode=0o644) write_new_file(destination, entry, mode=0o644)
def authorize_scoped_panel(role, panel, key_path, domains): def authorize_scoped_panel(
role, panel, key_path, domains, *, keep_domains=False
):
account = scoped_account(role.name, panel) account = scoped_account(role.name, panel)
key = one_public_key(key_path) key = one_public_key(key_path)
if not key.startswith("ssh-ed25519 "): if not key.startswith("ssh-ed25519 "):
@@ -335,8 +337,10 @@ def authorize_scoped_panel(role, panel, key_path, domains):
check_ssh_receiver(role, account) check_ssh_receiver(role, account)
entry = f'command="{role.relay}",restrict {key}\n' entry = f'command="{role.relay}",restrict {key}\n'
contents = json.dumps(sorted(domains)) + "\n" contents = json.dumps(sorted(domains)) + "\n"
if path.exists(): if path.exists() and scoped_domains(path) != domains and keep_domains:
scoped_domains(path) raise ValueError(
"Use the existing domain assignment when reenrolling a panel."
)
put_file(destination, entry) put_file(destination, entry)
replace_configuration(path, contents, mode=0o600) replace_configuration(path, contents, mode=0o600)
return account return account
@@ -594,6 +598,7 @@ def main(argv=None):
action.add_argument("panel") action.add_argument("panel")
action.add_argument("public_key", type=Path) action.add_argument("public_key", type=Path)
action.add_argument("domains", nargs="+") action.add_argument("domains", nargs="+")
action.add_argument("--keep-domains", action="store_true")
if command in {"begin-maintenance", "finish-maintenance"}: if command in {"begin-maintenance", "finish-maintenance"}:
action.add_argument("inventory", type=Path) action.add_argument("inventory", type=Path)
if command == "enrol-panel": if command == "enrol-panel":
@@ -625,7 +630,11 @@ def main(argv=None):
print(f"Authorized the panel key for the {role.name} receiver.") print(f"Authorized the panel key for the {role.name} receiver.")
elif args.command == "authorize-scoped-panel": elif args.command == "authorize-scoped-panel":
account = authorize_scoped_panel( account = authorize_scoped_panel(
role, args.panel, args.public_key, args.domains role,
args.panel,
args.public_key,
args.domains,
keep_domains=args.keep_domains,
) )
print( print(
f"Authorized {account}. Use --scope {args.panel} on the panel." f"Authorized {account}. Use --scope {args.panel} on the panel."
+11
View File
@@ -360,6 +360,16 @@ def run_deployment(payload, status):
raise DeploymentError( raise DeploymentError(
f"The {name} receiver did not pass its installation check." f"The {name} receiver did not pass its installation check."
) )
if name == "mail":
changes[name].update(
mail_hostname=mail_host, tls=tls, certificate=chain, key=key
)
for option in (
"COULOBRE_MAIL_IMAP_HOST",
"COULOBRE_MAIL_SUBMISSION_HOST",
):
if not re.search(rf"(?m)^[ \t]*{option}[ \t]*=", env):
env = env.rstrip("\n") + f"\n{option}={mail_host}\n"
installation["plan"][name] = changes[name] installation["plan"][name] = changes[name]
flag = ROLE_FLAGS[name] flag = ROLE_FLAGS[name]
env = re.sub(rf"(?m)^[ \t]*{flag}[ \t]*=[^\n]*\n?", "", env) env = re.sub(rf"(?m)^[ \t]*{flag}[ \t]*=[^\n]*\n?", "", env)
@@ -425,6 +435,7 @@ def handle(peer):
"Resolve the panel update before installing a host." "Resolve the panel update before installing a host."
) )
report(status, "running", "Preparing the selected release.") report(status, "running", "Preparing the selected release.")
with suppress(OSError):
send(peer, accepted=True) send(peer, accepted=True)
peer.close() peer.close()
try: try:
+5 -7
View File
@@ -14,9 +14,8 @@ from check_core_release import ROOT, git_files, verify_release
def build_package(source, wheel, ref, output): def build_package(source, wheel, ref, output):
verify_release(source, wheel, ref) verify_release(source, wheel, ref)
project = tomllib.loads(git_files(ref)["pyproject.toml"].decode())[ tracked = git_files(ref)
"project" project = tomllib.loads(tracked["pyproject.toml"].decode())["project"]
]
version = project["version"].replace("rc", "~rc") version = project["version"].replace("rc", "~rc")
epoch = subprocess.check_output( epoch = subprocess.check_output(
["git", "show", "-s", "--format=%ct", ref], cwd=ROOT, text=True ["git", "show", "-s", "--format=%ct", ref], cwd=ROOT, text=True
@@ -31,10 +30,9 @@ def build_package(source, wheel, ref, output):
with tarfile.open(source, "r:gz") as archive: with tarfile.open(source, "r:gz") as archive:
prefix = source.name.removesuffix(".tar.gz") prefix = source.name.removesuffix(".tar.gz")
for member in archive: for member in archive:
if member.isfile(): name = member.name.removeprefix(f"{prefix}/")
destination = source_dir / member.name.removeprefix( if member.isfile() and name in tracked:
f"{prefix}/" destination = source_dir / name
)
destination.parent.mkdir(parents=True, exist_ok=True) destination.parent.mkdir(parents=True, exist_ok=True)
destination.write_bytes(archive.extractfile(member).read()) destination.write_bytes(archive.extractfile(member).read())
destination.chmod(0o755 if member.mode & 0o111 else 0o644) destination.chmod(0o755 if member.mode & 0o111 else 0o644)