Show a warning when manifesting from a harvest as reminder it should be trusted first

This commit is contained in:
Miguel Jacq 2026-06-29 12:25:35 +10:00
parent ddb18403c8
commit b3d4adf7d4
Signed by: mig5
GPG key ID: 03906B4110AAD3B8
2 changed files with 31 additions and 0 deletions

View file

@ -2,6 +2,7 @@ from __future__ import annotations
import os import os
import shutil import shutil
import sys
import tarfile import tarfile
import tempfile import tempfile
from pathlib import Path from pathlib import Path
@ -19,6 +20,16 @@ from .sopsutil import (
from .validate import validate_harvest from .validate import validate_harvest
_SEMANTIC_SAFETY_WARNING = (
"This harvest is structurally valid, but Enroll cannot prove it is semantically safe.\n"
"Only apply manifests generated from harvests whose provenance you trust.\n"
)
def _warn_semantic_safety() -> None:
sys.stderr.write(_SEMANTIC_SAFETY_WARNING)
def _prepare_bundle_dir( def _prepare_bundle_dir(
bundle: str, bundle: str,
*, *,
@ -217,6 +228,8 @@ def manifest(
+ validation.to_text().strip() + validation.to_text().strip()
) )
_warn_semantic_safety()
if not sops_mode: if not sops_mode:
manifest_ansible_from_bundle_dir( manifest_ansible_from_bundle_dir(
resolved_bundle_dir, resolved_bundle_dir,

View file

@ -87,6 +87,24 @@ def _write_state(bundle: Path, state: dict) -> None:
write_schema_state(bundle, state) write_schema_state(bundle, state)
def test_manifest_warns_that_validation_is_not_semantic_safety(tmp_path: Path, capsys):
bundle = tmp_path / "bundle"
out = tmp_path / "ansible"
_write_state(bundle, _minimal_package_state([]))
manifest.manifest(str(bundle), str(out))
captured = capsys.readouterr()
assert (
"This harvest is structurally valid, but Enroll cannot prove it is semantically safe."
in captured.err
)
assert (
"Only apply manifests generated from harvests whose provenance you trust."
in captured.err
)
def test_manifest_writes_roles_and_playbook_with_clean_when(tmp_path: Path): def test_manifest_writes_roles_and_playbook_with_clean_when(tmp_path: Path):
bundle = tmp_path / "bundle" bundle = tmp_path / "bundle"
out = tmp_path / "ansible" out = tmp_path / "ansible"