Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7a642b23c |
+4
-19
@@ -22,8 +22,7 @@ from core.approval import (
|
|||||||
ApprovalError,
|
ApprovalError,
|
||||||
)
|
)
|
||||||
|
|
||||||
from core.rehearsal import BASE_FIELDS, RehearsalError
|
from core.rehearsal import approval_context
|
||||||
from core.trusted_rehearsal import TrustedRehearsal
|
|
||||||
from core.compatibility import canonical_hash
|
from core.compatibility import canonical_hash
|
||||||
from core.locking import DeploymentLock
|
from core.locking import DeploymentLock
|
||||||
from core.operator_approval import OperatorApprovalPolicy
|
from core.operator_approval import OperatorApprovalPolicy
|
||||||
@@ -59,10 +58,9 @@ class ApprovalStore:
|
|||||||
|
|
||||||
MAX_BYTES = 4 * 1024 * 1024
|
MAX_BYTES = 4 * 1024 * 1024
|
||||||
|
|
||||||
def __init__(self, directory, *, operator_policy=None, trusted_rehearsal=None):
|
def __init__(self, directory, *, operator_policy=None):
|
||||||
|
|
||||||
self.operator_policy = operator_policy
|
self.operator_policy = operator_policy
|
||||||
self.trusted_rehearsal = trusted_rehearsal
|
|
||||||
self.directory = Path(directory).absolute()
|
self.directory = Path(directory).absolute()
|
||||||
self.validate_directory()
|
self.validate_directory()
|
||||||
|
|
||||||
@@ -325,20 +323,11 @@ class ApprovalStore:
|
|||||||
except ApprovalError as error:
|
except ApprovalError as error:
|
||||||
raise ApprovalStoreError(str(error)) from error
|
raise ApprovalStoreError(str(error)) from error
|
||||||
|
|
||||||
def rehearsal_context(self, rehearsal, base_context, *, now):
|
|
||||||
require(isinstance(self.trusted_rehearsal, TrustedRehearsal),
|
|
||||||
"Trusted rehearsal verifier required")
|
|
||||||
try:
|
|
||||||
return self.trusted_rehearsal.approval_context(rehearsal, base_context, now=now)
|
|
||||||
except RehearsalError as error:
|
|
||||||
raise ApprovalStoreError(str(error)) from error
|
|
||||||
|
|
||||||
def save(
|
def save(
|
||||||
self,
|
self,
|
||||||
approval,
|
approval,
|
||||||
context,
|
context,
|
||||||
*,
|
*,
|
||||||
rehearsal=None,
|
|
||||||
confirmation,
|
confirmation,
|
||||||
now,
|
now,
|
||||||
):
|
):
|
||||||
@@ -376,11 +365,7 @@ class ApprovalStore:
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
policy = self.require_operator_policy()
|
record = self.require_operator_policy().issue(record, now)
|
||||||
base = {name: context[name] for name in BASE_FIELDS}
|
|
||||||
require(self.rehearsal_context(rehearsal, base, now=now) == context,
|
|
||||||
"Approval does not bind the trusted rehearsal")
|
|
||||||
record = policy.issue(record, now)
|
|
||||||
except ApprovalError as error:
|
except ApprovalError as error:
|
||||||
raise ApprovalStoreError(str(error)) from error
|
raise ApprovalStoreError(str(error)) from error
|
||||||
|
|
||||||
@@ -419,7 +404,7 @@ class ApprovalStore:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
context = self.rehearsal_context(
|
context = approval_context(
|
||||||
rehearsal,
|
rehearsal,
|
||||||
base_context,
|
base_context,
|
||||||
now=now,
|
now=now,
|
||||||
|
|||||||
+11
-19
@@ -56,18 +56,6 @@ def provenance_fingerprint(data):
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def is_laravel_migration_path(value):
|
|
||||||
"""Match files Laravel discovers in supported registered directories."""
|
|
||||||
path = PurePosixPath(value)
|
|
||||||
parts = path.parts
|
|
||||||
application = len(parts) == 3 and parts[:2] == ("database", "migrations")
|
|
||||||
module = (
|
|
||||||
len(parts) == 5 and parts[0].lower() == "modules"
|
|
||||||
and tuple(part.lower() for part in parts[2:4]) == ("database", "migrations")
|
|
||||||
)
|
|
||||||
return (application or module) and "_" in path.stem and path.suffix == ".php"
|
|
||||||
|
|
||||||
|
|
||||||
def validate_migration_path(value, *, modular=False):
|
def validate_migration_path(value, *, modular=False):
|
||||||
|
|
||||||
require(
|
require(
|
||||||
@@ -82,8 +70,17 @@ def validate_migration_path(value, *, modular=False):
|
|||||||
and path.as_posix() == value
|
and path.as_posix() == value
|
||||||
and ".." not in path.parts
|
and ".." not in path.parts
|
||||||
and len(path.parts) >= 3
|
and len(path.parts) >= 3
|
||||||
and (is_laravel_migration_path(value) if modular
|
and (
|
||||||
else path.parts[:2] == ("database", "migrations"))
|
path.parts[:2] == ("database", "migrations")
|
||||||
|
or (
|
||||||
|
modular and len(path.parts) >= 5 and (
|
||||||
|
(path.parts[0] == "Modules"
|
||||||
|
and path.parts[2:4] == ("Database", "Migrations"))
|
||||||
|
or (path.parts[0] == "modules"
|
||||||
|
and path.parts[2:4] == ("database", "migrations"))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
and path.suffix == ".php"
|
and path.suffix == ".php"
|
||||||
and all(
|
and all(
|
||||||
re.fullmatch(
|
re.fullmatch(
|
||||||
@@ -122,14 +119,9 @@ def validate_provenance(data):
|
|||||||
"Invalid dependency inventory",
|
"Invalid dependency inventory",
|
||||||
)
|
)
|
||||||
|
|
||||||
basenames = set()
|
|
||||||
for name, digest in data["migrations"].items():
|
for name, digest in data["migrations"].items():
|
||||||
|
|
||||||
validate_migration_path(name, modular=version == 2)
|
validate_migration_path(name, modular=version == 2)
|
||||||
if version == 2:
|
|
||||||
basename = PurePosixPath(name).stem
|
|
||||||
require(basename not in basenames, "Duplicate migration basename")
|
|
||||||
basenames.add(basename)
|
|
||||||
|
|
||||||
require(
|
require(
|
||||||
valid_hash(digest, 64),
|
valid_hash(digest, 64),
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from core.transactions import TransactionJournal
|
|||||||
|
|
||||||
|
|
||||||
class SiteOperations:
|
class SiteOperations:
|
||||||
def __init__(self, root, *, operator_policy=None, trusted_rehearsal=None):
|
def __init__(self, root, *, operator_policy=None):
|
||||||
root = Path(root)
|
root = Path(root)
|
||||||
if root.resolve() != root:
|
if root.resolve() != root:
|
||||||
raise ValueError("Site runtime directory must be canonical")
|
raise ValueError("Site runtime directory must be canonical")
|
||||||
@@ -21,8 +21,7 @@ class SiteOperations:
|
|||||||
self.lock_path = state / ".deployment.lock"
|
self.lock_path = state / ".deployment.lock"
|
||||||
self.journal = TransactionJournal(state)
|
self.journal = TransactionJournal(state)
|
||||||
self.backup_evidence = BackupEvidence(state)
|
self.backup_evidence = BackupEvidence(state)
|
||||||
self.approvals = ApprovalStore(approvals, operator_policy=operator_policy,
|
self.approvals = ApprovalStore(approvals, operator_policy=operator_policy)
|
||||||
trusted_rehearsal=trusted_rehearsal)
|
|
||||||
self.journal.bind_migration_guard(self.approvals)
|
self.journal.bind_migration_guard(self.approvals)
|
||||||
self.guard = OperationGuard(self.approvals)
|
self.guard = OperationGuard(self.approvals)
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import os
|
|||||||
import stat
|
import stat
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.compatibility import (
|
from core.compatibility import canonical_hash, provenance_fingerprint, validate_provenance
|
||||||
canonical_hash, is_laravel_migration_path, provenance_fingerprint, validate_provenance,
|
|
||||||
)
|
|
||||||
from core.provenance import ProvenanceVerifier, require
|
from core.provenance import ProvenanceVerifier, require
|
||||||
|
|
||||||
|
|
||||||
@@ -60,10 +58,13 @@ class CompleteProvenance(ProvenanceVerifier):
|
|||||||
expected = {**tracked, **self.generated, "REVISION": marker}
|
expected = {**tracked, **self.generated, "REVISION": marker}
|
||||||
require(inventory(release) == expected,
|
require(inventory(release) == expected,
|
||||||
"Full release tree differs from authorised source or generated artifacts")
|
"Full release tree differs from authorised source or generated artifacts")
|
||||||
evidence["migrations"] = {
|
for name, (digest, _) in tracked.items():
|
||||||
name: digest for name, (digest, _) in tracked.items()
|
parts = Path(name).parts
|
||||||
if is_laravel_migration_path(name)
|
if (len(parts) >= 5 and name.endswith(".php") and
|
||||||
}
|
(parts[0], parts[2], parts[3]) in (
|
||||||
|
("Modules", "Database", "Migrations"), ("modules", "database", "migrations")
|
||||||
|
)):
|
||||||
|
evidence["migrations"][name] = digest
|
||||||
evidence.update(format_version=2, source_tree=canonical_hash(expected))
|
evidence.update(format_version=2, source_tree=canonical_hash(expected))
|
||||||
evidence["fingerprint"] = provenance_fingerprint(evidence)
|
evidence["fingerprint"] = provenance_fingerprint(evidence)
|
||||||
validate_provenance(evidence)
|
validate_provenance(evidence)
|
||||||
|
|||||||
+2
-1
@@ -10,6 +10,7 @@ import re
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from core.approval import timestamp
|
from core.approval import timestamp
|
||||||
|
from core.rehearsal import approval_context
|
||||||
from core.compatibility import canonical_hash
|
from core.compatibility import canonical_hash
|
||||||
from core.locking import DeploymentLock
|
from core.locking import DeploymentLock
|
||||||
from core.operation_guard import OperationGuard
|
from core.operation_guard import OperationGuard
|
||||||
@@ -160,7 +161,7 @@ class MigrationCoordinator:
|
|||||||
base = copy.deepcopy(self.context_probe())
|
base = copy.deepcopy(self.context_probe())
|
||||||
current_time = timestamp(self.clock())
|
current_time = timestamp(self.clock())
|
||||||
|
|
||||||
context = self.store.rehearsal_context(
|
context = approval_context(
|
||||||
rehearsal, base, now=current_time
|
rehearsal, base, now=current_time
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
+2
-21
@@ -4,7 +4,6 @@ The command runner must be supplied by the caller.
|
|||||||
This module does not execute subprocesses directly.
|
This module does not execute subprocesses directly.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import tempfile
|
import tempfile
|
||||||
@@ -38,7 +37,6 @@ class ServiceLifecycle:
|
|||||||
stop_timeout=90,
|
stop_timeout=90,
|
||||||
*,
|
*,
|
||||||
site_secrets=None,
|
site_secrets=None,
|
||||||
topology_runner=None,
|
|
||||||
):
|
):
|
||||||
|
|
||||||
require(
|
require(
|
||||||
@@ -88,8 +86,6 @@ class ServiceLifecycle:
|
|||||||
self._queue = docker["queue_service"]
|
self._queue = docker["queue_service"]
|
||||||
self._scheduler = docker["scheduler_service"]
|
self._scheduler = docker["scheduler_service"]
|
||||||
|
|
||||||
self._backend_network = docker["backend_network"]
|
|
||||||
self._topology_runner = topology_runner
|
|
||||||
self._runner = runner
|
self._runner = runner
|
||||||
self._stop_timeout = stop_timeout
|
self._stop_timeout = stop_timeout
|
||||||
|
|
||||||
@@ -118,18 +114,6 @@ class ServiceLifecycle:
|
|||||||
f"Service operation failed: {operation}",
|
f"Service operation failed: {operation}",
|
||||||
)
|
)
|
||||||
|
|
||||||
def _require_project_backend(self):
|
|
||||||
require(callable(self._topology_runner), "Trusted Compose topology runner required")
|
|
||||||
command = (*self._prefix, "config", "--format", "json")
|
|
||||||
try:
|
|
||||||
model = json.loads(self._topology_runner(command, timeout=30))
|
|
||||||
backend = model["networks"][self._backend_network]
|
|
||||||
except Exception:
|
|
||||||
raise ServiceError("Unable to verify Compose backend network") from None
|
|
||||||
require(isinstance(backend, dict), "Invalid Compose backend network")
|
|
||||||
require(backend.get("external", False) is False,
|
|
||||||
"External Compose backend networks are prohibited")
|
|
||||||
|
|
||||||
def quiesce(self):
|
def quiesce(self):
|
||||||
|
|
||||||
self._execute(
|
self._execute(
|
||||||
@@ -146,7 +130,6 @@ class ServiceLifecycle:
|
|||||||
|
|
||||||
def restart_php(self):
|
def restart_php(self):
|
||||||
|
|
||||||
self._require_project_backend()
|
|
||||||
self._execute(
|
self._execute(
|
||||||
"restart PHP",
|
"restart PHP",
|
||||||
(
|
(
|
||||||
@@ -198,7 +181,6 @@ class ServiceLifecycle:
|
|||||||
|
|
||||||
def resume(self):
|
def resume(self):
|
||||||
|
|
||||||
self._require_project_backend()
|
|
||||||
self._execute(
|
self._execute(
|
||||||
"resume workers",
|
"resume workers",
|
||||||
(
|
(
|
||||||
@@ -221,9 +203,8 @@ class ContainedServiceLifecycle(ServiceLifecycle):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config, runner, *, gate_directory, ingress_sealed,
|
def __init__(self, config, runner, *, gate_directory, ingress_sealed,
|
||||||
worker_running, stop_timeout=90, site_secrets=None, topology_runner=None):
|
worker_running, stop_timeout=90, site_secrets=None):
|
||||||
super().__init__(config, runner, stop_timeout, site_secrets=site_secrets,
|
super().__init__(config, runner, stop_timeout, site_secrets=site_secrets)
|
||||||
topology_runner=topology_runner)
|
|
||||||
require(callable(ingress_sealed) and callable(worker_running),
|
require(callable(ingress_sealed) and callable(worker_running),
|
||||||
"Containment probes are required")
|
"Containment probes are required")
|
||||||
self._gate_directory = Path(gate_directory)
|
self._gate_directory = Path(gate_directory)
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
"""Bind rehearsal results to a configured runner and an independent trust key."""
|
|
||||||
|
|
||||||
import copy
|
|
||||||
import hmac
|
|
||||||
|
|
||||||
from core.rehearsal import (
|
|
||||||
RECORD_FIELDS, approval_context, create_rehearsal, matches, require,
|
|
||||||
validate_base_context,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TrustedRehearsal:
|
|
||||||
def __init__(self, runner_id, runner, *, key, clock):
|
|
||||||
require(matches(runner_id, r"[a-zA-Z0-9_.-]{1,128}"), "Invalid rehearsal runner identity")
|
|
||||||
require(callable(runner) and callable(clock), "Trusted rehearsal runner and clock required")
|
|
||||||
require(isinstance(key, bytes) and len(key) >= 32, "Invalid rehearsal trust key")
|
|
||||||
self.runner_id = runner_id
|
|
||||||
self._runner = runner
|
|
||||||
self._key = key
|
|
||||||
self._clock = clock
|
|
||||||
|
|
||||||
def _seal(self, fingerprint):
|
|
||||||
payload = f"absdev:trusted-rehearsal:v1:{self.runner_id}:{fingerprint}".encode("ascii")
|
|
||||||
return hmac.digest(self._key, payload, "sha256").hex()
|
|
||||||
|
|
||||||
def run(self, context):
|
|
||||||
context = copy.deepcopy(context)
|
|
||||||
validate_base_context(context)
|
|
||||||
execution = self._runner(copy.deepcopy(context))
|
|
||||||
record = create_rehearsal(context, execution, completed_at=self._clock())
|
|
||||||
return dict(record, runner_id=self.runner_id, runner_seal=self._seal(record["fingerprint"]))
|
|
||||||
|
|
||||||
def approval_context(self, evidence, context, *, now):
|
|
||||||
require(isinstance(evidence, dict)
|
|
||||||
and set(evidence) == RECORD_FIELDS | {"runner_id", "runner_seal"},
|
|
||||||
"Trusted rehearsal evidence required")
|
|
||||||
require(evidence["runner_id"] == self.runner_id
|
|
||||||
and matches(evidence["runner_seal"], r"[a-f0-9]{64}"),
|
|
||||||
"Invalid rehearsal runner attestation")
|
|
||||||
record = {name: evidence[name] for name in RECORD_FIELDS}
|
|
||||||
approved = approval_context(record, context, now=now)
|
|
||||||
require(hmac.compare_digest(evidence["runner_seal"], self._seal(record["fingerprint"])),
|
|
||||||
"Untrusted rehearsal runner attestation")
|
|
||||||
return approved
|
|
||||||
@@ -34,11 +34,3 @@ result record the activation and health outcome independently of reopening.
|
|||||||
|
|
||||||
These controls are available to the trusted runtime composition. The
|
These controls are available to the trusted runtime composition. The
|
||||||
operational production CLI remains disabled.
|
operational production CLI remains disabled.
|
||||||
|
|
||||||
Pass a trusted `topology_runner(command, *, timeout)` that returns stdout
|
|
||||||
from a successful Compose command as JSON bytes or text and raises on failure.
|
|
||||||
The runtime resolves the exact project and Compose files with
|
|
||||||
`config --format json` before starting workers or restarting PHP. Missing,
|
|
||||||
unverifiable, or external configured backend networks deny those operations.
|
|
||||||
Keep Compose inputs under trusted control across validation and execution.
|
|
||||||
Stopping workers remains available if topology validation fails.
|
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
# Trusted rehearsal evidence
|
|
||||||
|
|
||||||
Configure `TrustedRehearsal(runner_id, runner, key=..., clock=...)` in trusted
|
|
||||||
runtime code and supply it to `SiteOperations(trusted_rehearsal=...)`.
|
|
||||||
Use a separately managed random key of at least 32 bytes and a stable runner
|
|
||||||
identifier. Only trusted runtime processes may have access to this key.
|
|
||||||
This is a symmetric attestation shared by the runner and approval runtime.
|
|
||||||
Keep it separate from the operator approval sealing key.
|
|
||||||
|
|
||||||
The configured runner receives a copy of the exact rehearsal context. It must
|
|
||||||
verify the candidate inventory, restore the verified backup into an isolated
|
|
||||||
database, run the approved migrations, observe migration history and application
|
|
||||||
checks, and clean up before returning execution evidence. The runner and clock
|
|
||||||
come from trusted composition, and callers cannot supply either per rehearsal.
|
|
||||||
|
|
||||||
Call `run(context)` to obtain evidence, then derive the approval context with
|
|
||||||
`approval_context(evidence, context, now=...)` and pass the same evidence as
|
|
||||||
`rehearsal` when saving the approval and attempting execution. The approval
|
|
||||||
store and migration coordinator independently verify the attestation. The
|
|
||||||
underlying structural rehearsal format remains readable for audit. Unsigned
|
|
||||||
historical evidence must be rerun under the trusted adapter before it can
|
|
||||||
authorise a migration.
|
|
||||||
|
|
||||||
The configured runner and protected key provisioning are deployment inputs.
|
|
||||||
Production execution remains disabled.
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-after.json
|
||||||
|
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-before.json
|
||||||
|
b2d5eb9eb65eae107efd1e7afdebef051e24f85e71ed9a556c35721a1df911d7 ./checks.jsonl
|
||||||
|
563b698c0d99294765669c84c96869f92dcae9f87df8f8e62de69dc8fa946d83 ./framework-ci.txt
|
||||||
|
eebbff2c0505a4e3e80a676500191b4d9b41fb8a18a39a235cc717d36aeb81ab ./scope.txt
|
||||||
|
8c89cb04d6f12405a9e0fcd5e0d3519d7511329699c0f27eeecd4df0f537a27e controller.py
|
||||||
|
afda0afc490c108f7e1ce1a1774185fe566e7d38f43918a426e11144425ce6e6 worker.py
|
||||||
|
3cea8a8d312caf532497e79d2d8aaa9dd29acf1008342be9862eefc8ea7efdb6 run.sh
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{"check": "authorised approval consumed once and replay rejected", "result": "PASS"}
|
||||||
|
{"check": "same running process rejected unconsumed approval after execute grant removal", "result": "PASS"}
|
||||||
|
{"check": "same running process rejected an approval sealed by the retired key", "result": "PASS"}
|
||||||
|
{"check": "missing authority failed closed without a consumption marker", "result": "PASS"}
|
||||||
|
{"check": "unsafe authority permissions failed closed without a consumption marker", "result": "PASS"}
|
||||||
|
{"check": "replacement key restored authorised consumption in the original process", "result": "PASS"}
|
||||||
|
{"check":"disposable operator and authority files removed","result":"PASS"}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
import secrets
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
account, uid, gid, root = sys.argv[1:]
|
||||||
|
uid, gid, root = int(uid), int(gid), Path(root)
|
||||||
|
path = root / "authority.json"
|
||||||
|
key = secrets.token_hex(32)
|
||||||
|
|
||||||
|
def publish(actions, signing_key):
|
||||||
|
grants = [dict(uid=uid, principal="operator", operation=op, site="example-absdev-net",
|
||||||
|
revision="a"*40, expires_at="2026-12-01T10:00:00+00:00") for op in actions]
|
||||||
|
with tempfile.NamedTemporaryFile(mode="w", dir=root, delete=False) as stream:
|
||||||
|
json.dump({"grants": grants, "sealing_key": signing_key}, stream)
|
||||||
|
stream.flush()
|
||||||
|
os.fchown(stream.fileno(), 0, gid)
|
||||||
|
os.fchmod(stream.fileno(), 0o440)
|
||||||
|
os.fsync(stream.fileno())
|
||||||
|
os.replace(stream.name, path)
|
||||||
|
|
||||||
|
def report(check):
|
||||||
|
print(json.dumps({"check": check, "result": "PASS"}), flush=True)
|
||||||
|
|
||||||
|
publish(("issue", "execute"), key)
|
||||||
|
with subprocess.Popen(("runuser", "-u", account, "--", "env", "TMPDIR=" + str(root.parent / "operator-tmp"), "python3", "-B", "worker.py", str(path)),
|
||||||
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True) as process:
|
||||||
|
def send(action, expected):
|
||||||
|
process.stdin.write(action + "\n")
|
||||||
|
process.stdin.flush()
|
||||||
|
assert process.stdout.readline().strip() == expected, action
|
||||||
|
|
||||||
|
send("issue", "issued")
|
||||||
|
send("consume", "consumed")
|
||||||
|
send("replay", "rejected")
|
||||||
|
report("authorised approval consumed once and replay rejected")
|
||||||
|
send("issue", "issued")
|
||||||
|
publish(("issue",), key)
|
||||||
|
send("reject", "rejected")
|
||||||
|
report("same running process rejected unconsumed approval after execute grant removal")
|
||||||
|
publish(("issue", "execute"), key)
|
||||||
|
rotated = secrets.token_hex(32)
|
||||||
|
publish(("issue", "execute"), rotated)
|
||||||
|
send("reject", "rejected")
|
||||||
|
report("same running process rejected an approval sealed by the retired key")
|
||||||
|
send("issue", "issued")
|
||||||
|
path.unlink()
|
||||||
|
send("reject", "rejected")
|
||||||
|
report("missing authority failed closed without a consumption marker")
|
||||||
|
publish(("issue", "execute"), rotated)
|
||||||
|
path.chmod(0o444)
|
||||||
|
send("reject", "rejected")
|
||||||
|
report("unsafe authority permissions failed closed without a consumption marker")
|
||||||
|
publish(("issue", "execute"), rotated)
|
||||||
|
send("consume", "consumed")
|
||||||
|
send("replay", "rejected")
|
||||||
|
report("replacement key restored authorised consumption in the original process")
|
||||||
|
process.stdin.close()
|
||||||
|
assert process.wait(timeout=10) == 0
|
||||||
+3
-3
@@ -2,12 +2,12 @@
|
|||||||
Python 3.14.4
|
Python 3.14.4
|
||||||
|
|
||||||
=== PYTHON SYNTAX VALIDATION ===
|
=== PYTHON SYNTAX VALIDATION ===
|
||||||
PASS: 89 Python sources compiled
|
PASS: 88 Python sources compiled
|
||||||
|
|
||||||
=== COMPLETE UNIT REGRESSION SUITE ===
|
=== COMPLETE UNIT REGRESSION SUITE ===
|
||||||
..........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
|
.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Ran 906 tests in 18.019s
|
Ran 901 tests in 18.524s
|
||||||
|
|
||||||
OK
|
OK
|
||||||
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
set -euo pipefail
|
||||||
|
umask 077
|
||||||
|
test "$(hostname -s | tr A-Z a-z)" = absdev-ci
|
||||||
|
stage=$(mktemp -d /var/tmp/absdev-revocation-fix.XXXXXX)
|
||||||
|
suffix=$(tr '[:upper:]' '[:lower:]' <<< "${stage##*.}")
|
||||||
|
account="abrev$suffix"
|
||||||
|
created=0
|
||||||
|
cleanup() {
|
||||||
|
rc=$?
|
||||||
|
if ((created)); then userdel "$account" || rc=1; fi
|
||||||
|
rm -rf -- "$stage" || rc=1
|
||||||
|
exit "$rc"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
mkdir "$stage/source" "$stage/evidence" "$stage/tmp"
|
||||||
|
tar -xm -f - -C "$stage/source"
|
||||||
|
chmod 0711 "$stage"
|
||||||
|
chmod -R a+rX "$stage/source"
|
||||||
|
useradd -U -M -d /nonexistent -s /usr/sbin/nologin "$account"
|
||||||
|
created=1
|
||||||
|
install -d -m 0750 -o root -g "$account" "$stage/authority"
|
||||||
|
install -d -m 0700 -o "$account" -g "$account" "$stage/operator-tmp"
|
||||||
|
export TMPDIR="$stage/tmp"
|
||||||
|
out="$stage/evidence"
|
||||||
|
cd "$stage/source"
|
||||||
|
printf 'host=%s\nrevision=2719378f67da153f0210b886d66e8e2b68cf6c01\noperator_uid=%s\n' "$(hostname -s)" "$(id -u "$account")" > "$out/scope.txt"
|
||||||
|
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-before.json"
|
||||||
|
python3 -B controller.py "$account" "$(id -u "$account")" "$(id -g "$account")" "$stage/authority" > "$out/checks.jsonl"
|
||||||
|
userdel "$account"
|
||||||
|
created=0
|
||||||
|
rm -rf -- "$stage/authority" "$stage/operator-tmp"
|
||||||
|
if getent passwd "$account"; then exit 1; fi
|
||||||
|
printf '%s\n' '{"check":"disposable operator and authority files removed","result":"PASS"}' >> "$out/checks.jsonl"
|
||||||
|
bash scripts/ci-check.sh > "$out/framework-ci.txt" 2>&1 || { tail -80 "$out/framework-ci.txt" >&2; exit 1; }
|
||||||
|
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-after.json"
|
||||||
|
cmp "$out/capabilities-before.json" "$out/capabilities-after.json"
|
||||||
|
(cd "$out" && sha256sum ./* > SHA256SUMS)
|
||||||
|
tar -czf - -C "$out" .
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
host=absdev-ci
|
||||||
|
revision=2719378f67da153f0210b886d66e8e2b68cf6c01
|
||||||
|
operator_uid=1001
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
sys.path.insert(0, str(Path("tests/unit").resolve()))
|
||||||
|
from test_approval_store import ApprovalStoreTests
|
||||||
|
from core.approval_store import ApprovalStore, ApprovalStoreError
|
||||||
|
from core.operator_approval import FileOperatorAuthority
|
||||||
|
|
||||||
|
fixture = ApprovalStoreTests()
|
||||||
|
try:
|
||||||
|
fixture.setUp()
|
||||||
|
assert os.geteuid() > 0
|
||||||
|
fixture.store = ApprovalStore(
|
||||||
|
fixture.root, operator_policy=FileOperatorAuthority(sys.argv[1], group=os.getegid())
|
||||||
|
)
|
||||||
|
original_draft = fixture.approval
|
||||||
|
for action in sys.stdin:
|
||||||
|
action = action.strip()
|
||||||
|
if action == "issue":
|
||||||
|
from core.approval import issue_approval
|
||||||
|
fixture.approval = issue_approval(fixture.context, approver=original_draft["approver"],
|
||||||
|
now=fixture.now)
|
||||||
|
fixture.identifier = fixture.approval["approval_id"]
|
||||||
|
fixture.save()
|
||||||
|
print("issued", flush=True)
|
||||||
|
elif action == "consume":
|
||||||
|
result = fixture.consume()
|
||||||
|
assert result["migration_executed"] is False
|
||||||
|
print("consumed", flush=True)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
fixture.consume()
|
||||||
|
except ApprovalStoreError as error:
|
||||||
|
marker = fixture.store.consumed_path(fixture.identifier)
|
||||||
|
if action == "replay":
|
||||||
|
assert "already consumed" in str(error) and marker.exists()
|
||||||
|
else:
|
||||||
|
assert not marker.exists()
|
||||||
|
print("rejected", flush=True)
|
||||||
|
else:
|
||||||
|
raise AssertionError("Expected rejection")
|
||||||
|
finally:
|
||||||
|
fixture.doCleanups()
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-after.json
|
|
||||||
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-before.json
|
|
||||||
5ea47740256cc6cd2cb3a9a224c836388ecc07128e3811042065553606a6857c ./framework-ci.txt
|
|
||||||
19158d14d7f207e6bcdbd5ff2a4031479585840a901104c019948f7d5c22541b ./rehearsal-attestation.json
|
|
||||||
d67e476d883681d5f54c62e67468ebcb2ff23fb0732a69d0001560b7ea1cd00c ./scope.txt
|
|
||||||
e62a74b5def068d3eaf560f0b9ac107ef74e4b780b400023714f7616b96e3ef7 run.sh
|
|
||||||
3f2caca8724625e8f852a9c85ae96d7c0661e4eee6e27ead8e7f3e105b8bc5f8 probe.py
|
|
||||||
65047c5a7a9c5900b5c6fd13b6c0f6c72eba7508fe87127220a689465e91c028 rehearsal.php
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
import copy
|
|
||||||
import hashlib
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import secrets
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from datetime import datetime, timezone
|
|
||||||
from pathlib import Path
|
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
sys.path.insert(0, str(Path("tests/unit").resolve()))
|
|
||||||
from test_provenance import ProvenanceTests
|
|
||||||
from core.dev3.provenance import CompleteProvenance
|
|
||||||
from core.rehearsal import RehearsalError, create_rehearsal
|
|
||||||
from core.trusted_rehearsal import TrustedRehearsal
|
|
||||||
from core.approval import issue_approval
|
|
||||||
from core.approval_store import ApprovalStore, ApprovalStoreError
|
|
||||||
from core.operator_approval import OperatorApprovalPolicy, OperatorGrant
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
PG = "sha256:e742a2668255221388004f3a42b6150a2103f5054ab3a4a93ae9e4f01e551c35"
|
|
||||||
PHP = "sha256:cac70f6c4aa761a1c04c6813c03a7678b9a5c061cc67a413a12736253e7128ee"
|
|
||||||
DEPS = "/var/tmp/absdev-dev3-ci.8yBxcV/public-fixture"
|
|
||||||
DIRS = ["database/migrations", "Modules/Orders/Database/Migrations",
|
|
||||||
"modules/products/database/migrations", "Modules/Billing/database/Migrations"]
|
|
||||||
PATHS = [
|
|
||||||
DIRS[0] + "/0001_create_users.php", DIRS[0] + "/0002_create_orders.php",
|
|
||||||
DIRS[1] + "/0003_add_order.php", DIRS[2] + "/0004_add_product.php",
|
|
||||||
DIRS[3] + "/0005_add_billing.php",
|
|
||||||
]
|
|
||||||
source, target = "rehearsal_source", "isolated_restore_laravel"
|
|
||||||
fixture = ProvenanceTests()
|
|
||||||
cid = None
|
|
||||||
|
|
||||||
def run(*args, data=None, check=True):
|
|
||||||
return subprocess.run(args, input=data, capture_output=True, check=check, timeout=90)
|
|
||||||
|
|
||||||
def pg(*args, data=None, check=True):
|
|
||||||
return run("docker", "exec", "-i", "--user", "postgres", cid, *args, data=data, check=check)
|
|
||||||
|
|
||||||
def sql(database, query):
|
|
||||||
return pg("psql", "-XqAt", "-v", "ON_ERROR_STOP=1", "-d", database, data=query.encode()).stdout.strip()
|
|
||||||
|
|
||||||
try:
|
|
||||||
fixture.setUp()
|
|
||||||
for index, name in enumerate(PATHS, 1):
|
|
||||||
body = r"""<?php
|
|
||||||
return new class extends \Illuminate\Database\Migrations\Migration {
|
|
||||||
public function up(): void {
|
|
||||||
\Illuminate\Database\Capsule\Manager::connection()
|
|
||||||
->table('rehearsal_items')->insert(['id' => INDEX, 'label' => 'migration-INDEX']);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
""".replace("INDEX", str(index))
|
|
||||||
for root in (fixture.repository, fixture.release):
|
|
||||||
path = root / name
|
|
||||||
path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
path.write_text(body)
|
|
||||||
fixture.git("add", ".")
|
|
||||||
fixture.git("commit", "-qm", "Add disposable migrations")
|
|
||||||
revision = fixture.git("rev-parse", "HEAD").strip()
|
|
||||||
(fixture.release / "REVISION").write_text(revision + "\n")
|
|
||||||
provenance = CompleteProvenance(fixture.repository, [revision], {}).verify(fixture.release)
|
|
||||||
pending = sorted(Path(p).stem for p in provenance["migrations"])
|
|
||||||
state = fixture.root
|
|
||||||
secret = secrets.token_hex(32)
|
|
||||||
env = state / "pg.env"
|
|
||||||
env.write_text(f"POSTGRES_PASSWORD={secret}\nPOSTGRES_INITDB_ARGS=--auth-host=scram-sha-256\n")
|
|
||||||
env.chmod(0o600)
|
|
||||||
cid = run("docker", "create", "--pull", "never", "--network", "none",
|
|
||||||
"--security-opt", "no-new-privileges", "--memory", "1g",
|
|
||||||
"--env-file", str(env), PG).stdout.decode().strip()
|
|
||||||
run("docker", "start", cid)
|
|
||||||
info = json.loads(run("docker", "inspect", "--format", "{{json .HostConfig}}", cid).stdout)
|
|
||||||
assert info["NetworkMode"] == "none" and not info["Privileged"] and not info["PortBindings"]
|
|
||||||
for _ in range(60):
|
|
||||||
if pg("pg_isready", "-h", "127.0.0.1", check=False).returncode == 0:
|
|
||||||
break
|
|
||||||
time.sleep(1)
|
|
||||||
else:
|
|
||||||
raise RuntimeError("Disposable PostgreSQL did not become ready")
|
|
||||||
sql("postgres", f"CREATE DATABASE {source}; CREATE DATABASE {target};")
|
|
||||||
sql(source, "CREATE TABLE rehearsal_items(id integer PRIMARY KEY, label text); "
|
|
||||||
"INSERT INTO rehearsal_items VALUES(0,'backup-sentinel');")
|
|
||||||
backup = pg("pg_dump", "--format=custom", source).stdout
|
|
||||||
assert backup.startswith(b"PGDMP")
|
|
||||||
identity = lambda db: hashlib.sha256((cid + ":" + db).encode()).hexdigest()
|
|
||||||
context = dict(site="rehearsal-lab", release="2", revision=revision,
|
|
||||||
provenance=provenance["fingerprint"], compatibility="a"*64,
|
|
||||||
database_identity=identity(source), backup_sha256=hashlib.sha256(backup).hexdigest(),
|
|
||||||
pending_migrations=pending)
|
|
||||||
observed = {}
|
|
||||||
|
|
||||||
def runner(request):
|
|
||||||
global cid
|
|
||||||
assert request == context
|
|
||||||
pg("pg_restore", "--exit-on-error", "-d", target, data=backup)
|
|
||||||
assert sql(target, "SELECT label FROM rehearsal_items;") == b"backup-sentinel"
|
|
||||||
credential = state / "credential.json"
|
|
||||||
credential.write_text(json.dumps({"driver": "pgsql", "host": "127.0.0.1", "port": 5432,
|
|
||||||
"database": target, "username": "postgres", "password": secret}))
|
|
||||||
credential.chmod(0o600)
|
|
||||||
result = run(
|
|
||||||
"docker", "run", "--rm", "--pull", "never", "--network", f"container:{cid}",
|
|
||||||
"--read-only", "--cap-drop", "ALL", "--cap-add", "DAC_OVERRIDE",
|
|
||||||
"--security-opt", "no-new-privileges",
|
|
||||||
"-v", f"{DEPS}:/deps:ro", "-v", f"{fixture.release}:/release:ro",
|
|
||||||
"-v", f"{credential}:/credential.json:ro",
|
|
||||||
"-v", f"{Path('rehearsal.php').resolve()}:/rehearsal.php:ro",
|
|
||||||
"--entrypoint", "php", PHP, "/rehearsal.php", *DIRS, check=False,
|
|
||||||
)
|
|
||||||
if result.returncode:
|
|
||||||
raise RuntimeError((result.stdout + result.stderr).decode(errors="replace").replace(secret, "[redacted]")[:2000])
|
|
||||||
outcome = json.loads(result.stdout)
|
|
||||||
assert sorted(outcome["inventory"].values()) == sorted(provenance["migrations"])
|
|
||||||
assert outcome["history"] == pending and outcome["database"] == target
|
|
||||||
assert outcome["restored_and_migrated_rows"] == ["backup-sentinel"] + [f"migration-{n}" for n in range(1, 6)]
|
|
||||||
assert sql(source, "SELECT label FROM rehearsal_items;") == b"backup-sentinel"
|
|
||||||
assert sql(source, "SELECT to_regclass('public.migrations') IS NULL;") == b"t"
|
|
||||||
execution = dict(driver="postgresql", source_database=source, target_database=target,
|
|
||||||
target_identity=identity(target), applied_migrations=outcome["history"],
|
|
||||||
checks=dict.fromkeys(("isolation_verified", "backup_restored", "migration_succeeded",
|
|
||||||
"migration_history_verified", "application_verified",
|
|
||||||
"cleanup_verified"), True))
|
|
||||||
run("docker", "rm", "-fv", cid)
|
|
||||||
cid = None
|
|
||||||
observed["outcome"] = outcome
|
|
||||||
return execution
|
|
||||||
|
|
||||||
now = datetime.now(timezone.utc)
|
|
||||||
trusted = TrustedRehearsal("absdev-ci-laravel", runner, key=secrets.token_bytes(32), clock=lambda: now)
|
|
||||||
record = trusted.run(context)
|
|
||||||
outcome = observed["outcome"]
|
|
||||||
approved_context = trusted.approval_context(record, context, now=now)
|
|
||||||
grants = [OperatorGrant(10001, "fixture-operator", action, context["site"], revision,
|
|
||||||
now + timedelta(hours=1)) for action in ("issue", "execute")]
|
|
||||||
policy = OperatorApprovalPolicy(grants, sealing_key=secrets.token_bytes(32))
|
|
||||||
area = state / "approvals"
|
|
||||||
area.mkdir(mode=0o700)
|
|
||||||
store = ApprovalStore(area, operator_policy=lambda: policy, trusted_rehearsal=trusted)
|
|
||||||
draft = issue_approval(approved_context, approver="fixture-operator", now=now)
|
|
||||||
choices = dict(confirmation=draft["confirmation"], now=now)
|
|
||||||
unsigned = {k: v for k, v in record.items() if k not in ("runner_id", "runner_seal")}
|
|
||||||
forged = dict(record, runner_seal="0"*64)
|
|
||||||
with patch("core.operator_approval.geteuid", return_value=10001):
|
|
||||||
for untrusted in (unsigned, forged):
|
|
||||||
try:
|
|
||||||
store.save(draft, approved_context, rehearsal=untrusted, **choices)
|
|
||||||
except ApprovalStoreError:
|
|
||||||
assert not store.approval_path(draft["approval_id"]).exists()
|
|
||||||
else:
|
|
||||||
raise AssertionError("Untrusted rehearsal accepted at issuance")
|
|
||||||
store.save(draft, approved_context, rehearsal=record, **choices)
|
|
||||||
for untrusted in (unsigned, forged):
|
|
||||||
try:
|
|
||||||
store.consume(draft["approval_id"], context, untrusted, **choices)
|
|
||||||
except ApprovalStoreError:
|
|
||||||
assert not store.consumed_path(draft["approval_id"]).exists()
|
|
||||||
else:
|
|
||||||
raise AssertionError("Untrusted rehearsal accepted at consumption")
|
|
||||||
receipt = store.consume(draft["approval_id"], context, record, **choices)
|
|
||||||
assert receipt["rehearsal_fingerprint"] == record["fingerprint"]
|
|
||||||
assert receipt["migration_executed"] is False
|
|
||||||
wrong = copy.deepcopy(record["execution"])
|
|
||||||
wrong["applied_migrations"].pop()
|
|
||||||
try:
|
|
||||||
create_rehearsal(context, wrong, completed_at=now)
|
|
||||||
except RehearsalError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise AssertionError("Incomplete migration evidence was accepted")
|
|
||||||
print(json.dumps({"laravel": outcome, "framework_inventory": sorted(provenance["migrations"]),
|
|
||||||
"same_paths_and_applied_names": True, "incomplete_history_rejected": True,
|
|
||||||
"source_unchanged": True, "disposable_database_removed": True,
|
|
||||||
"trusted_runner": record["runner_id"],
|
|
||||||
"unsigned_and_forged_evidence_rejected_at_issuance_and_consumption": True,
|
|
||||||
"trusted_rehearsal_approved_and_consumed": True,
|
|
||||||
"operator_scope": "Synthetic effective UID for approval integration",
|
|
||||||
"rehearsal_fingerprint": record["fingerprint"]}, indent=2))
|
|
||||||
finally:
|
|
||||||
if cid:
|
|
||||||
run("docker", "rm", "-fv", cid)
|
|
||||||
fixture.doCleanups()
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
{
|
|
||||||
"laravel": {
|
|
||||||
"laravel_version": "v13.44.1",
|
|
||||||
"database": "isolated_restore_laravel",
|
|
||||||
"inventory": {
|
|
||||||
"0001_create_users": "database/migrations/0001_create_users.php",
|
|
||||||
"0002_create_orders": "database/migrations/0002_create_orders.php",
|
|
||||||
"0003_add_order": "Modules/Orders/Database/Migrations/0003_add_order.php",
|
|
||||||
"0004_add_product": "modules/products/database/migrations/0004_add_product.php",
|
|
||||||
"0005_add_billing": "Modules/Billing/database/Migrations/0005_add_billing.php"
|
|
||||||
},
|
|
||||||
"history": [
|
|
||||||
"0001_create_users",
|
|
||||||
"0002_create_orders",
|
|
||||||
"0003_add_order",
|
|
||||||
"0004_add_product",
|
|
||||||
"0005_add_billing"
|
|
||||||
],
|
|
||||||
"restored_and_migrated_rows": [
|
|
||||||
"backup-sentinel",
|
|
||||||
"migration-1",
|
|
||||||
"migration-2",
|
|
||||||
"migration-3",
|
|
||||||
"migration-4",
|
|
||||||
"migration-5"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"framework_inventory": [
|
|
||||||
"Modules/Billing/database/Migrations/0005_add_billing.php",
|
|
||||||
"Modules/Orders/Database/Migrations/0003_add_order.php",
|
|
||||||
"database/migrations/0001_create_users.php",
|
|
||||||
"database/migrations/0002_create_orders.php",
|
|
||||||
"modules/products/database/migrations/0004_add_product.php"
|
|
||||||
],
|
|
||||||
"same_paths_and_applied_names": true,
|
|
||||||
"incomplete_history_rejected": true,
|
|
||||||
"source_unchanged": true,
|
|
||||||
"disposable_database_removed": true,
|
|
||||||
"trusted_runner": "absdev-ci-laravel",
|
|
||||||
"unsigned_and_forged_evidence_rejected_at_issuance_and_consumption": true,
|
|
||||||
"trusted_rehearsal_approved_and_consumed": true,
|
|
||||||
"operator_scope": "Synthetic effective UID for approval integration",
|
|
||||||
"rehearsal_fingerprint": "696706cb2e4527ac36629a633f10869588719b241f27f171568759e8ba9edd76"
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
require '/deps/vendor/autoload.php';
|
|
||||||
|
|
||||||
use Illuminate\Database\Capsule\Manager;
|
|
||||||
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
|
|
||||||
use Illuminate\Database\Migrations\Migrator;
|
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
|
|
||||||
$config = json_decode(file_get_contents('/credential.json'), true, flags: JSON_THROW_ON_ERROR);
|
|
||||||
$capsule = new Manager();
|
|
||||||
$capsule->addConnection($config);
|
|
||||||
$capsule->setAsGlobal();
|
|
||||||
$resolver = $capsule->getDatabaseManager();
|
|
||||||
$repository = new DatabaseMigrationRepository($resolver, 'migrations');
|
|
||||||
$repository->createRepository();
|
|
||||||
$migrator = new Migrator($repository, $resolver, new Filesystem());
|
|
||||||
$paths = array_map(fn ($dir) => '/release/'.$dir, array_slice($argv, 1));
|
|
||||||
$files = $migrator->getMigrationFiles($paths);
|
|
||||||
$migrator->run($paths);
|
|
||||||
$db = $capsule->getConnection();
|
|
||||||
$checks = $db->table('rehearsal_items')->orderBy('id')->pluck('label')->all();
|
|
||||||
$files = array_map(fn ($file) => substr($file, strlen('/release/')), $files);
|
|
||||||
echo json_encode([
|
|
||||||
'laravel_version' => Composer\InstalledVersions::getPrettyVersion('laravel/framework'),
|
|
||||||
'database' => $db->selectOne('SELECT current_database() AS name')->name,
|
|
||||||
'inventory' => $files,
|
|
||||||
'history' => $repository->getRan(),
|
|
||||||
'restored_and_migrated_rows' => $checks,
|
|
||||||
], JSON_THROW_ON_ERROR);
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
set -euo pipefail
|
|
||||||
umask 077
|
|
||||||
test "$(hostname -s | tr A-Z a-z)" = absdev-ci
|
|
||||||
stage=$(mktemp -d /var/tmp/absdev-rehearsal-trust.XXXXXX)
|
|
||||||
trap 'rm -rf -- "$stage"' EXIT
|
|
||||||
mkdir "$stage/source" "$stage/evidence" "$stage/tmp"
|
|
||||||
tar -xm -f - -C "$stage/source"
|
|
||||||
cd "$stage/source"
|
|
||||||
export TMPDIR="$stage/tmp"
|
|
||||||
out="$stage/evidence"
|
|
||||||
printf 'host=%s\nrevision=b0495d80f15848ad87783c143c77be44344132cf\n' "$(hostname -s)" > "$out/scope.txt"
|
|
||||||
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-before.json"
|
|
||||||
python3 -B -c 'import json,sys; d=json.load(open(sys.argv[1])); f=[v for k,v in d.items() if k.endswith("_enabled") or k=="production_ready"]; assert len(f)==6 and all(v is False for v in f)' "$out/capabilities-before.json"
|
|
||||||
python3 -B probe.py > "$out/rehearsal-attestation.json" || { cat "$out/rehearsal-attestation.json" >&2; exit 1; }
|
|
||||||
bash scripts/ci-check.sh > "$out/framework-ci.txt" 2>&1 || { tail -80 "$out/framework-ci.txt" >&2; exit 1; }
|
|
||||||
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-after.json"
|
|
||||||
cmp "$out/capabilities-before.json" "$out/capabilities-after.json"
|
|
||||||
(cd "$out" && sha256sum ./* > SHA256SUMS)
|
|
||||||
tar -czf - -C "$out" .
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
host=absdev-ci
|
|
||||||
revision=b0495d80f15848ad87783c143c77be44344132cf
|
|
||||||
@@ -14,8 +14,7 @@ from core.approval import approval_checksum, issue_approval
|
|||||||
from core.approval_store import ApprovalStore, ApprovalStoreError
|
from core.approval_store import ApprovalStore, ApprovalStoreError
|
||||||
from core.operator_approval import OperatorApprovalPolicy, OperatorGrant
|
from core.operator_approval import OperatorApprovalPolicy, OperatorGrant
|
||||||
from core.locking import DeploymentLock, LockError
|
from core.locking import DeploymentLock, LockError
|
||||||
from core.rehearsal import create_rehearsal, fingerprint
|
from core.rehearsal import create_rehearsal, approval_context
|
||||||
from core.trusted_rehearsal import TrustedRehearsal
|
|
||||||
|
|
||||||
|
|
||||||
class ApprovalStoreTests(unittest.TestCase):
|
class ApprovalStoreTests(unittest.TestCase):
|
||||||
@@ -63,13 +62,16 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
self.trusted_rehearsal = TrustedRehearsal(
|
self.rehearsal = create_rehearsal(
|
||||||
"fixture-runner", lambda _context: self.execution,
|
self.base,
|
||||||
key=os.urandom(32), clock=lambda: self.now,
|
self.execution,
|
||||||
|
completed_at=self.now,
|
||||||
)
|
)
|
||||||
self.rehearsal = self.trusted_rehearsal.run(self.base)
|
|
||||||
self.context = self.trusted_rehearsal.approval_context(
|
self.context = approval_context(
|
||||||
self.rehearsal, self.base, now=self.now,
|
self.rehearsal,
|
||||||
|
self.base,
|
||||||
|
now=self.now,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.approval = issue_approval(
|
self.approval = issue_approval(
|
||||||
@@ -94,15 +96,13 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
for operation in ("issue", "execute")
|
for operation in ("issue", "execute")
|
||||||
]
|
]
|
||||||
self.policy = OperatorApprovalPolicy(self.grants, sealing_key=self.key)
|
self.policy = OperatorApprovalPolicy(self.grants, sealing_key=self.key)
|
||||||
self.store = ApprovalStore(self.root, operator_policy=lambda: self.policy,
|
self.store = ApprovalStore(self.root, operator_policy=lambda: self.policy)
|
||||||
trusted_rehearsal=self.trusted_rehearsal)
|
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
|
||||||
return self.store.save(
|
return self.store.save(
|
||||||
self.approval,
|
self.approval,
|
||||||
self.context,
|
self.context,
|
||||||
rehearsal=self.rehearsal,
|
|
||||||
confirmation=self.approval["confirmation"],
|
confirmation=self.approval["confirmation"],
|
||||||
now=self.now,
|
now=self.now,
|
||||||
)
|
)
|
||||||
@@ -171,8 +171,7 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
self.save()
|
self.save()
|
||||||
self.consume()
|
self.consume()
|
||||||
|
|
||||||
self.store = ApprovalStore(self.root, operator_policy=lambda: self.policy,
|
self.store = ApprovalStore(self.root, operator_policy=lambda: self.policy)
|
||||||
trusted_rehearsal=self.trusted_rehearsal)
|
|
||||||
|
|
||||||
with self.assertRaisesRegex(ApprovalStoreError, "already consumed"):
|
with self.assertRaisesRegex(ApprovalStoreError, "already consumed"):
|
||||||
self.consume()
|
self.consume()
|
||||||
@@ -217,7 +216,6 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
self.store.save(
|
self.store.save(
|
||||||
self.approval,
|
self.approval,
|
||||||
self.context,
|
self.context,
|
||||||
rehearsal=self.rehearsal,
|
|
||||||
confirmation=self.approval["confirmation"],
|
confirmation=self.approval["confirmation"],
|
||||||
now=self.now + timedelta(hours=20),
|
now=self.now + timedelta(hours=20),
|
||||||
)
|
)
|
||||||
@@ -478,7 +476,6 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
self.store.save(
|
self.store.save(
|
||||||
self.approval,
|
self.approval,
|
||||||
self.context,
|
self.context,
|
||||||
rehearsal=self.rehearsal,
|
|
||||||
confirmation=self.approval["confirmation"],
|
confirmation=self.approval["confirmation"],
|
||||||
now=self.now + timedelta(hours=25),
|
now=self.now + timedelta(hours=25),
|
||||||
)
|
)
|
||||||
@@ -546,31 +543,5 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
self.assertFalse(self.store.consumed_path(self.identifier).exists())
|
self.assertFalse(self.store.consumed_path(self.identifier).exists())
|
||||||
|
|
||||||
|
|
||||||
def test_unsigned_rehearsal_cannot_authorise_issuance_or_consumption(self):
|
|
||||||
signed = self.rehearsal
|
|
||||||
self.rehearsal = {name: value for name, value in signed.items()
|
|
||||||
if name not in ("runner_id", "runner_seal")}
|
|
||||||
with self.assertRaisesRegex(ApprovalStoreError, "Trusted rehearsal evidence required"):
|
|
||||||
self.save()
|
|
||||||
self.assertFalse(self.store.approval_path(self.identifier).exists())
|
|
||||||
self.rehearsal = signed
|
|
||||||
self.save()
|
|
||||||
self.rehearsal = create_rehearsal(self.base, self.execution, completed_at=self.now)
|
|
||||||
with self.assertRaises(ApprovalStoreError):
|
|
||||||
self.consume()
|
|
||||||
self.assertFalse(self.store.consumed_path(self.identifier).exists())
|
|
||||||
|
|
||||||
def test_recomputed_fingerprint_does_not_authorise_forgery(self):
|
|
||||||
self.rehearsal["rehearsal_id"] = "f" * 32
|
|
||||||
unsigned = {name: value for name, value in self.rehearsal.items()
|
|
||||||
if name not in ("runner_id", "runner_seal")}
|
|
||||||
self.rehearsal["fingerprint"] = fingerprint(unsigned)
|
|
||||||
self.context["rehearsal_fingerprint"] = self.rehearsal["fingerprint"]
|
|
||||||
self.approval = issue_approval(self.context, approver="operator", now=self.now)
|
|
||||||
with self.assertRaisesRegex(ApprovalStoreError, "Untrusted rehearsal runner"):
|
|
||||||
self.save()
|
|
||||||
self.assertFalse(self.store.approval_path(self.approval["approval_id"]).exists())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ class ContainedServiceTests(unittest.TestCase):
|
|||||||
self.config, self.run_command, gate_directory=self.directory,
|
self.config, self.run_command, gate_directory=self.directory,
|
||||||
ingress_sealed=lambda: self.gate.is_file() and self.probe_ok,
|
ingress_sealed=lambda: self.gate.is_file() and self.probe_ok,
|
||||||
worker_running=lambda _name: self.running,
|
worker_running=lambda _name: self.running,
|
||||||
topology_runner=lambda _command, **_options: json.dumps({
|
|
||||||
"networks": {self.config["docker"]["backend_network"]: {"internal": True}},
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def run_command(self, args, *, timeout):
|
def run_command(self, args, *, timeout):
|
||||||
|
|||||||
@@ -20,21 +20,3 @@ class InventoryTests(unittest.TestCase):
|
|||||||
(root / "link").symlink_to(script)
|
(root / "link").symlink_to(script)
|
||||||
with self.assertRaises(ProvenanceError):
|
with self.assertRaises(ProvenanceError):
|
||||||
inventory(root)
|
inventory(root)
|
||||||
|
|
||||||
|
|
||||||
class LaravelMigrationPathTests(unittest.TestCase):
|
|
||||||
def test_inventory_matches_registered_directory_globs(self):
|
|
||||||
from core.compatibility import is_laravel_migration_path
|
|
||||||
|
|
||||||
for path in (
|
|
||||||
"Modules/Billing/database/Migrations/0001_add_invoice.php",
|
|
||||||
"modules/Orders/Database/migrations/0002_add_order.php",
|
|
||||||
"database/migrations/0003_add_user.php",
|
|
||||||
):
|
|
||||||
self.assertTrue(is_laravel_migration_path(path), path)
|
|
||||||
for path in (
|
|
||||||
"Modules/Billing/database/Migrations/nested/0001_add_invoice.php",
|
|
||||||
"database/migrations/README.php",
|
|
||||||
"database/migrations/nested/0003_add_user.php",
|
|
||||||
):
|
|
||||||
self.assertFalse(is_laravel_migration_path(path), path)
|
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ class MigrationTests(unittest.TestCase):
|
|||||||
self.fixture = test_approval_store.ApprovalStoreTests()
|
self.fixture = test_approval_store.ApprovalStoreTests()
|
||||||
self.addCleanup(self.fixture.doCleanups)
|
self.addCleanup(self.fixture.doCleanups)
|
||||||
self.fixture.setUp()
|
self.fixture.setUp()
|
||||||
self.ops = SiteOperations(self.fixture.root, operator_policy=lambda: self.fixture.policy,
|
self.ops = SiteOperations(self.fixture.root, operator_policy=lambda: self.fixture.policy)
|
||||||
trusted_rehearsal=self.fixture.trusted_rehearsal)
|
|
||||||
self.fixture.store = self.ops.approvals
|
self.fixture.store = self.ops.approvals
|
||||||
self.fixture.save()
|
self.fixture.save()
|
||||||
|
|
||||||
|
|||||||
@@ -19,14 +19,10 @@ class ServiceTests(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
self.runner = Mock(return_value=0)
|
self.runner = Mock(return_value=0)
|
||||||
self.topology = Mock(return_value=json.dumps({
|
|
||||||
"networks": {self.config["docker"]["backend_network"]: {"internal": True}},
|
|
||||||
}))
|
|
||||||
|
|
||||||
self.manager = ServiceLifecycle(
|
self.manager = ServiceLifecycle(
|
||||||
self.config,
|
self.config,
|
||||||
self.runner,
|
self.runner,
|
||||||
topology_runner=self.topology,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.prefix = [
|
self.prefix = [
|
||||||
@@ -78,26 +74,6 @@ class ServiceTests(unittest.TestCase):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_external_backend_blocks_start_and_restart(self):
|
|
||||||
self.topology.return_value = json.dumps({
|
|
||||||
"networks": {self.config["docker"]["backend_network"]: {"external": True}},
|
|
||||||
})
|
|
||||||
for operation in (self.manager.resume, self.manager.restart_php):
|
|
||||||
with self.assertRaisesRegex(ServiceError, "External Compose backend"):
|
|
||||||
operation()
|
|
||||||
self.runner.assert_not_called()
|
|
||||||
self.topology.assert_called_with(
|
|
||||||
(*self.prefix, "config", "--format", "json"), timeout=30,
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_unverifiable_backend_fails_closed(self):
|
|
||||||
for model in ("invalid json", '{"networks": {}}', '{"networks": null}'):
|
|
||||||
with self.subTest(model=model):
|
|
||||||
self.topology.return_value = model
|
|
||||||
with self.assertRaisesRegex(ServiceError, "Unable to verify"):
|
|
||||||
self.manager.resume()
|
|
||||||
self.runner.assert_not_called()
|
|
||||||
|
|
||||||
def test_validate_nginx(self):
|
def test_validate_nginx(self):
|
||||||
|
|
||||||
self.manager.validate_nginx()
|
self.manager.validate_nginx()
|
||||||
@@ -172,7 +148,6 @@ class ServiceTests(unittest.TestCase):
|
|||||||
manager = ServiceLifecycle(
|
manager = ServiceLifecycle(
|
||||||
self.config,
|
self.config,
|
||||||
self.runner,
|
self.runner,
|
||||||
topology_runner=self.topology,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
manager.restart_php()
|
manager.restart_php()
|
||||||
@@ -189,7 +164,6 @@ class ServiceTests(unittest.TestCase):
|
|||||||
manager = ServiceLifecycle(
|
manager = ServiceLifecycle(
|
||||||
self.config,
|
self.config,
|
||||||
self.runner,
|
self.runner,
|
||||||
topology_runner=self.topology,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
manager.validate_nginx()
|
manager.validate_nginx()
|
||||||
@@ -207,7 +181,6 @@ class ServiceTests(unittest.TestCase):
|
|||||||
manager = ServiceLifecycle(
|
manager = ServiceLifecycle(
|
||||||
self.config,
|
self.config,
|
||||||
self.runner,
|
self.runner,
|
||||||
topology_runner=self.topology,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
manager.quiesce()
|
manager.quiesce()
|
||||||
|
|||||||
Reference in New Issue
Block a user