Compare commits

..
Author SHA1 Message Date
Mark Gregory e5fbad8f31 Record ABSDEV-CI interrupted migration qualification 2026-11-28 09:35:45 +00:00
24 changed files with 120 additions and 464 deletions
+2 -7
View File
@@ -41,9 +41,6 @@ APPROVAL_FIELDS = {
}
SEALED_APPROVAL_FIELDS = APPROVAL_FIELDS | {"operator_seal"}
def require(condition, message):
if not condition:
@@ -235,15 +232,13 @@ def verify_approval(
require(
isinstance(approval, dict)
and set(approval) in (APPROVAL_FIELDS, SEALED_APPROVAL_FIELDS),
and set(approval) == APPROVAL_FIELDS,
"Invalid approval record",
)
require(
type(approval["format_version"]) is int
and (approval["format_version"], set(approval)) in (
(1, APPROVAL_FIELDS), (2, SEALED_APPROVAL_FIELDS),
),
and approval["format_version"] == 1,
"Unsupported approval format",
)
+3 -24
View File
@@ -18,14 +18,11 @@ from core.approval import (
timestamp,
approval_checksum,
APPROVAL_FIELDS,
SEALED_APPROVAL_FIELDS,
ApprovalError,
)
from core.rehearsal import approval_context
from core.compatibility import canonical_hash
from core.locking import DeploymentLock
from core.operator_approval import OperatorApprovalPolicy
class ApprovalStoreError(RuntimeError):
@@ -58,9 +55,8 @@ class ApprovalStore:
MAX_BYTES = 4 * 1024 * 1024
def __init__(self, directory, *, operator_policy=None):
def __init__(self, directory):
self.operator_policy = operator_policy
self.directory = Path(directory).absolute()
self.validate_directory()
@@ -284,7 +280,7 @@ class ApprovalStore:
require(
isinstance(record, dict)
and set(record) in (APPROVAL_FIELDS, SEALED_APPROVAL_FIELDS),
and set(record) == APPROVAL_FIELDS,
"Invalid stored approval structure",
)
@@ -306,18 +302,6 @@ class ApprovalStore:
return record
def require_operator_policy(self):
require(isinstance(self.operator_policy, OperatorApprovalPolicy),
"Trusted migration operator policy required")
return self.operator_policy
def verify_execution(self, approval, context, *, confirmation, now):
verify_approval(approval, context, confirmation=confirmation, now=now)
try:
self.require_operator_policy().verify_execution(approval, now)
except ApprovalError as error:
raise ApprovalStoreError(str(error)) from error
def save(
self,
approval,
@@ -359,11 +343,6 @@ class ApprovalStore:
"Approval has already been consumed",
)
try:
record = self.require_operator_policy().issue(record, now)
except ApprovalError as error:
raise ApprovalStoreError(str(error)) from error
return self.publish(
self.approval_path(identifier),
record,
@@ -405,7 +384,7 @@ class ApprovalStore:
now=now,
)
self.verify_execution(
verify_approval(
approval,
context,
confirmation=confirmation,
+2 -2
View File
@@ -10,7 +10,7 @@ from core.transactions import TransactionJournal
class SiteOperations:
def __init__(self, root, *, operator_policy=None):
def __init__(self, root):
root = Path(root)
if root.resolve() != root:
raise ValueError("Site runtime directory must be canonical")
@@ -21,7 +21,7 @@ class SiteOperations:
self.lock_path = state / ".deployment.lock"
self.journal = TransactionJournal(state)
self.backup_evidence = BackupEvidence(state)
self.approvals = ApprovalStore(approvals, operator_policy=operator_policy)
self.approvals = ApprovalStore(approvals)
self.journal.bind_migration_guard(self.approvals)
self.guard = OperationGuard(self.approvals)
+2 -2
View File
@@ -9,7 +9,7 @@ import re
from pathlib import Path
from core.approval import timestamp
from core.approval import verify_approval, timestamp
from core.rehearsal import approval_context
from core.compatibility import canonical_hash
from core.locking import DeploymentLock
@@ -167,7 +167,7 @@ class MigrationCoordinator:
approval = self.store.load(identifier)
self.store.verify_execution(
verify_approval(
approval,
context,
confirmation=confirmation,
-1
View File
@@ -139,7 +139,6 @@ class MigrationRecovery:
def _inspect(self, identifier):
approval = self.store.load(identifier)
self.store.require_operator_policy().verify_seal(approval)
context = approval["context"]
validate_context(context)
-84
View File
@@ -1,84 +0,0 @@
"""Local operator identity and scoped migration approval policy."""
import hmac
from dataclasses import dataclass
from datetime import datetime
from os import geteuid
from core.approval import (
ApprovalError,
approval_checksum,
require,
timestamp,
validate_approver,
)
@dataclass(frozen=True)
class OperatorGrant:
uid: int
principal: str
operation: str
site: str
revision: str
expires_at: datetime
class OperatorApprovalPolicy:
"""Use the OS effective UID and grants supplied by trusted runtime configuration."""
def __init__(self, grants, *, sealing_key):
require(isinstance(sealing_key, bytes) and len(sealing_key) >= 32,
"Operator approval sealing key must contain at least 32 bytes")
self.grants = tuple(grants)
principals_by_uid = {}
uids_by_principal = {}
for grant in self.grants:
require(type(grant.uid) is int and grant.uid > 0,
"Operator grant requires a non-root OS account")
validate_approver(grant.principal)
require(grant.operation in ("issue", "execute"), "Invalid operator operation")
require(principals_by_uid.setdefault(grant.uid, grant.principal) == grant.principal
and uids_by_principal.setdefault(grant.principal, grant.uid) == grant.uid,
"Operator principals must map one-to-one to OS accounts")
timestamp(grant.expires_at)
self._key = sealing_key
def authorise(self, approval, operation, now):
uid = geteuid()
principal = approval["approver"]
validate_approver(principal)
context = approval["context"]
require(any(
grant.uid == uid
and grant.principal == principal
and grant.operation == operation
and grant.site == context["site"]
and grant.revision == context["revision"]
and timestamp(now) < timestamp(grant.expires_at)
for grant in self.grants
), "Operator is not authorised for this operation, site and revision")
def _seal(self, approval):
unsigned = {key: value for key, value in approval.items() if key != "operator_seal"}
message = b"absdev:migration-operator-approval:v2:" + approval_checksum(unsigned).encode("ascii")
return hmac.digest(self._key, message, "sha256").hex()
def issue(self, approval, now):
require(approval["format_version"] == 1, "Expected an unsigned approval draft")
self.authorise(approval, "issue", now)
record = dict(approval, format_version=2)
record["operator_seal"] = self._seal(record)
record["checksum"] = approval_checksum(record)
return record
def verify_seal(self, approval):
seal = approval.get("operator_seal")
if (approval["format_version"] != 2 or not isinstance(seal, str)
or not seal.isascii() or not hmac.compare_digest(seal, self._seal(approval))):
raise ApprovalError("Missing or invalid operator approval seal")
def verify_execution(self, approval, now):
self.verify_seal(approval)
self.authorise(approval, "execute", now)
-30
View File
@@ -1,30 +0,0 @@
# Local migration operator authorisation
The supported development composition accepts an `OperatorApprovalPolicy`
through `SiteOperations(operator_policy=...)`. Configure the policy in trusted
runtime code with a one-to-one mapping from dedicated OS accounts to operator
principals. The policy authenticates the process's effective UID. The operator's
login or service launcher must authenticate access to that account. A shared
service account cannot provide individual operator identity.
Each grant names the UID, principal, operation (`issue` or `execute`), site,
exact Git revision and UTC expiry. Issue and execute grants are independent.
Both must match the same approval principal. An issue grant allows saving a
draft. Execution requires a current execute grant, a valid approval seal, and
the original approval and rehearsal checks. The coordinator verifies authority
before writing intent and the store repeats verification under its lock before
publishing the single-use consumption record.
Supply an independently generated random key of at least 32 bytes from protected
runtime configuration. Keep it stable across process restarts and separate from
approval state. The key authenticates the complete version 2 approval payload,
including the exact rehearsal, backup and pending migrations. A version 1
draft or record cannot authorise execution. Historical records remain readable
for audit. Unsealed recovery evidence requires manual review. Recovery evidence
verification requires access to the sealing key used for issuance.
The runtime process, its code, policy, key, clock and state directory are trusted.
The policy is constructed from a configuration snapshot. Reload it before
further execution when grants are revoked or changed. The approved account
must never be exposed as a shared application or arbitrary command identity.
The inspection CLI remains disabled for production execution.
@@ -0,0 +1,7 @@
# ABSDEV-CI migration recovery qualification
ABSDEV-CI qualified framework commit `8d11a82be40b50d47c1e7b27b70f12e43d3abcdc` on 28 November 2026 using a disposable PostgreSQL fixture.
The coordinator stopped after the first migration step committed and while the second transaction was in progress. PostgreSQL rolled back the second transaction and retained the first step. Restart inspection refused forward activation. A fresh journal instance rejected both direct transition and direct creation. The journal snapshots are byte-identical. The checks record the original release, revision and provenance fingerprint verified against the durable migration intent.
All 15 live checks and 891 framework tests passed. Production execution remained disabled throughout. The scope is the interrupted-migration fixture. The full archive remains on ABSDEV-CI.
@@ -0,0 +1,7 @@
c6f2ab7d09284edd2736ca7bfaef56c83a2b89e326b229e1ee612da251336a59 README.md
8b221b62fe2831fe9a3ab7ca69c20e29f09cbf2d8132df8d6b2e2387df9b7bfc direct-writer-probe.json
8b221b62fe2831fe9a3ab7ca69c20e29f09cbf2d8132df8d6b2e2387df9b7bfc ordinary-after.json
8b221b62fe2831fe9a3ab7ca69c20e29f09cbf2d8132df8d6b2e2387df9b7bfc ordinary-before.json
e64e37e0bf83ba2fbaaa6a2a399010ab94e8fdd697b6ffbd7ad77e124f84f440 summary.json
a111426a96c5aaeacbadc3c68a99597773217a7efda6cbc52e428234a9841116 checks.jsonl
14e9e8d0861fe6360b723e9190681910ba1ff37db6b226aa40a74edd796b177b regression-summary.txt
@@ -0,0 +1,15 @@
{"check": "production gates before", "detail": {"commands": ["validate", "capabilities", "inventory", "retention-plan", "provision-plan", "site-policy", "registry-validate", "preflight"], "database_restore_enabled": false, "deployment_execution_enabled": false, "format_version": 1, "migration_execution_enabled": false, "permanent_deletion_enabled": false, "production_ready": false, "provisioning_execution_enabled": false}, "engine": "framework", "result": "PASS"}
{"check": "container isolation", "detail": {"host_mounts": 0, "image_id": "sha256:e742a2668255221388004f3a42b6150a2103f5054ab3a4a93ae9e4f01e551c35", "network": "none", "privileged": false, "published_ports": 0}, "engine": "postgres", "result": "PASS"}
{"check": "real transactionally consistent PostgreSQL backup verified", "detail": "4e76874f53b78d4ae96382cbb97012f2f83022cfee3da498b3a657e4aec30555", "engine": "postgres", "result": "PASS"}
{"check": "restored backup to a separate disposable database and rehearsed both migration steps", "engine": "postgres", "result": "PASS"}
{"check": "live migration excluded a competing site operation", "engine": "framework", "result": "PASS"}
{"check": "abruptly stopped coordinator and interrupted an in-flight PostgreSQL transaction", "engine": "postgres", "result": "PASS"}
{"check": "interrupted transaction rolled back, committed prefix survives, migration history unchanged", "engine": "postgres", "result": "PASS"}
{"check": "restart inspection and activation refuse incomplete migration evidence", "engine": "framework", "result": "PASS"}
{"check": "interrupted migration approval could not be replayed", "engine": "framework", "result": "PASS"}
{"check": "standard paths left original release and ordinary journal byte-for-byte intact", "detail": {"journal_sha256": "8b221b62fe2831fe9a3ab7ca69c20e29f09cbf2d8132df8d6b2e2387df9b7bfc", "release": "2"}, "engine": "framework", "result": "PASS"}
{"check": "reopened ordinary journal denies direct transition during unfinished migration", "engine": "framework", "result": "PASS"}
{"check": "bound journal also rejects direct creation while migration is unfinished", "engine": "framework", "result": "PASS"}
{"check": "durable migration intent binds original release, revision and provenance", "detail": {"fingerprint": "215281691a508f42a57945a017f78f871317e08e079d1faacac69b3dadb1416e", "release": "2", "revision": "01dda29c1d2313f5b359df427051f09e555957e9"}, "engine": "framework", "result": "PASS"}
{"check": "disposable PostgreSQL container and anonymous data volume removed", "engine": "framework", "result": "PASS"}
{"check": "production gates after", "detail": {"commands": ["validate", "capabilities", "inventory", "retention-plan", "provision-plan", "site-policy", "registry-validate", "preflight"], "database_restore_enabled": false, "deployment_execution_enabled": false, "format_version": 1, "migration_execution_enabled": false, "permanent_deletion_enabled": false, "production_ready": false, "provisioning_execution_enabled": false}, "engine": "framework", "result": "PASS"}
@@ -0,0 +1,19 @@
{
"candidate": "2",
"checksum": "b0d25de6815e9fd6c239d00ca33ed396d267d5867dd8e3150e252ec26e678882",
"format_version": 1,
"history": [
{
"phase": "PREPARED",
"timestamp": "2026-11-28T09:32:28.933535+00:00"
}
],
"phase": "PREPARED",
"previous": "1",
"previous_provenance": "c540af47a7c4b96b63724af20e188edf4171fb395c6f69a1ff9b418f63d12c37",
"previous_revision": "bbd3d391a3d5e0190d6bba437a502c59bbb67946",
"provenance": "215281691a508f42a57945a017f78f871317e08e079d1faacac69b3dadb1416e",
"revision": "01dda29c1d2313f5b359df427051f09e555957e9",
"site": "absdev-migration-lab",
"transaction_id": "b167f1b758c04c2cb32090b78ebdbd11"
}
@@ -0,0 +1,19 @@
{
"candidate": "2",
"checksum": "b0d25de6815e9fd6c239d00ca33ed396d267d5867dd8e3150e252ec26e678882",
"format_version": 1,
"history": [
{
"phase": "PREPARED",
"timestamp": "2026-11-28T09:32:28.933535+00:00"
}
],
"phase": "PREPARED",
"previous": "1",
"previous_provenance": "c540af47a7c4b96b63724af20e188edf4171fb395c6f69a1ff9b418f63d12c37",
"previous_revision": "bbd3d391a3d5e0190d6bba437a502c59bbb67946",
"provenance": "215281691a508f42a57945a017f78f871317e08e079d1faacac69b3dadb1416e",
"revision": "01dda29c1d2313f5b359df427051f09e555957e9",
"site": "absdev-migration-lab",
"transaction_id": "b167f1b758c04c2cb32090b78ebdbd11"
}
@@ -0,0 +1,19 @@
{
"candidate": "2",
"checksum": "b0d25de6815e9fd6c239d00ca33ed396d267d5867dd8e3150e252ec26e678882",
"format_version": 1,
"history": [
{
"phase": "PREPARED",
"timestamp": "2026-11-28T09:32:28.933535+00:00"
}
],
"phase": "PREPARED",
"previous": "1",
"previous_provenance": "c540af47a7c4b96b63724af20e188edf4171fb395c6f69a1ff9b418f63d12c37",
"previous_revision": "bbd3d391a3d5e0190d6bba437a502c59bbb67946",
"provenance": "215281691a508f42a57945a017f78f871317e08e079d1faacac69b3dadb1416e",
"revision": "01dda29c1d2313f5b359df427051f09e555957e9",
"site": "absdev-migration-lab",
"transaction_id": "b167f1b758c04c2cb32090b78ebdbd11"
}
@@ -0,0 +1,5 @@
Ran 891 tests in 17.779s
OK
PASS: FRAMEWORK CI
@@ -0,0 +1,8 @@
{
"host": "ABSDEV-CI",
"open_gates": [],
"passed": 15,
"production_execution_enabled": false,
"production_ready": false,
"revision": "8d11a82be40b50d47c1e7b27b70f12e43d3abcdc"
}
@@ -1,2 +0,0 @@
ABSDEV-CI operator account and migration approval signing key qualification, 28 November 2026.
Two disposable locked OS accounts were exercised through a privileged test launcher under their actual non-root identities. The signing key is the framework's HMAC sealing key. The root-owned key permits read access only to the authorised account's group. Approval and rehearsal data were synthetic. No database or deployment operation ran. The tests checked revocation in fresh processes after policy reload and key rotation. They did not exercise live revocation of processes already holding the old policy or key, or production secret delivery. The archive contains neither key bytes nor approval confirmation values.
@@ -1,6 +0,0 @@
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-after.json
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-before.json
729138832cef705a2b885b30eeaa1710329416c576a3633681a1e37d5e59c1ac ./probe.py
ec94a71ab10f42256c9c7230501a9f8861f1283803842f2fe9b9e28ce1a5fef7 ./qualification-log.txt
42bb47558db3396d43ce6c306da22f882fcc687d35d8cf4772b311bd2d428c4a qualification.sh
3227a1380c102c0467ccf75f81ddf2111828684d3f9be82d636afb1881b7ff2f SCOPE.txt
@@ -1,19 +0,0 @@
{
"commands": [
"validate",
"capabilities",
"inventory",
"retention-plan",
"provision-plan",
"site-policy",
"registry-validate",
"preflight"
],
"database_restore_enabled": false,
"deployment_execution_enabled": false,
"format_version": 1,
"migration_execution_enabled": false,
"permanent_deletion_enabled": false,
"production_ready": false,
"provisioning_execution_enabled": false
}
@@ -1,19 +0,0 @@
{
"commands": [
"validate",
"capabilities",
"inventory",
"retention-plan",
"provision-plan",
"site-policy",
"registry-validate",
"preflight"
],
"database_restore_enabled": false,
"deployment_execution_enabled": false,
"format_version": 1,
"migration_execution_enabled": false,
"permanent_deletion_enabled": false,
"production_ready": false,
"provisioning_execution_enabled": false
}
@@ -1,73 +0,0 @@
import json
import os
import sys
from datetime import datetime, timedelta, timezone
from pathlib import Path
from core.approval import issue_approval
from core.approval_store import ApprovalStore, ApprovalStoreError
from core.operator_approval import OperatorApprovalPolicy, OperatorGrant
from core.rehearsal import approval_context, create_rehearsal
root = Path(sys.argv[1])
action = sys.argv[2]
config = json.loads((root / "policy.json").read_text())
now = datetime(2026, 11, 28, 12, tzinfo=timezone.utc)
base = dict(site="operator-lab", release="2", revision="a"*40, provenance="b"*64,
compatibility="c"*64, database_identity="d"*64, backup_sha256="e"*64,
pending_migrations=["2026_11_28_000000_create_fixture"])
execution = dict(driver="postgresql", source_database="source", target_database="isolated_restore_fixture",
target_identity="f"*64, applied_migrations=base["pending_migrations"],
checks=dict.fromkeys(("isolation_verified", "backup_restored", "migration_succeeded",
"migration_history_verified", "application_verified",
"cleanup_verified"), True))
rehearsal = create_rehearsal(base, execution, completed_at=now)
rehearsal_path = root / "state" / "rehearsal.json"
if action not in ("issue", "wrong-principal"):
rehearsal = json.loads(rehearsal_path.read_text())
context = approval_context(rehearsal, base, now=now)
policy = OperatorApprovalPolicy([
OperatorGrant(config["uid"], "fixture-operator", op, base["site"], base["revision"],
now + timedelta(hours=1))
for op in config["operations"]
], sealing_key=(root / "operator.key").read_bytes())
store = ApprovalStore(root / "state", operator_policy=policy)
if action in ("issue", "wrong-principal"):
draft = issue_approval(context, approver=("other-principal" if action == "wrong-principal"
else "fixture-operator"), now=now)
try:
saved = store.save(draft, context, confirmation=draft["confirmation"], now=now)
except ApprovalStoreError as error:
assert action == "wrong-principal" and "not authorised" in str(error)
assert not store.approval_path(draft["approval_id"]).exists()
print("PASS: actual operator UID cannot issue for another principal")
else:
assert action == "issue" and saved["format_version"] == 2
rehearsal_path.write_text(json.dumps(rehearsal))
(root / "state" / "current").write_text(saved["approval_id"])
print("PASS: dedicated OS account issued sealed approval")
else:
identifier = (root / "state" / "current").read_text()
approval = store.load(identifier)
marker = store.consumed_path(identifier)
before = marker.read_bytes() if marker.exists() else None
try:
result = store.consume(identifier, base, rehearsal, confirmation=approval["confirmation"], now=now)
except ApprovalStoreError as error:
assert action in ("replay", "grant-revoked", "key-revoked")
assert (marker.read_bytes() if marker.exists() else None) == before
if action == "replay":
assert before and "already consumed" in str(error)
else:
assert before is None
try:
store.verify_execution(approval, context, confirmation=approval["confirmation"], now=now)
except ApprovalStoreError as cause:
expected = "not authorised" if action == "grant-revoked" else "invalid operator approval seal"
assert expected in str(cause)
else:
raise AssertionError("Preflight accepted revoked authority")
print("PASS:", action, "rejected without changing consumption state")
else:
assert action == "consume" and result["migration_executed"] is False
print("PASS: fresh process consumed an authorised approval without executing migrations")
@@ -1,20 +0,0 @@
host=absdev-ci
revision=b0dda75809a7efa2dd8ae3dc910dab23db9cfb61
uid=1001(aboprxay27) gid=1001(aboprxay27) groups=1001(aboprxay27)
uid=1002(abnorxay27) gid=1002(abnorxay27) groups=1002(abnorxay27)
PASS: both accounts have locked passwords and no login shell
640 root aboprxay27 /var/tmp/absdev-op-provision.rxay27/lab/operator.key
644 root root /var/tmp/absdev-op-provision.rxay27/lab/policy.json
700 aboprxay27 aboprxay27 /var/tmp/absdev-op-provision.rxay27/lab/state
PASS: operator can read the key; neither operator account can modify key or policy; ungranted account cannot read key or enter state
PASS: actual operator UID cannot issue for another principal
PASS: dedicated OS account issued sealed approval
PASS: fresh process consumed an authorised approval without executing migrations
PASS: replay rejected without changing consumption state
PASS: dedicated OS account issued sealed approval
PASS: grant-revoked rejected without changing consumption state
PASS: key-revoked rejected without changing consumption state
PASS: dedicated OS account issued sealed approval
PASS: fresh process consumed an authorised approval without executing migrations
PASS: replay rejected without changing consumption state
PASS: temporary accounts and key/state removed
@@ -1,90 +0,0 @@
set -euo pipefail
umask 077
test "$(hostname -s | tr A-Z a-z)" = absdev-ci
stage=$(mktemp -d /var/tmp/absdev-op-provision.XXXXXX)
suffix=$(tr '[:upper:]' '[:lower:]' <<< "${stage##*.}")
op="abop$suffix"
other="abno$suffix"
created_op=0
created_other=0
cleanup() {
rc=$?
if ((created_other)); then userdel "$other" || rc=1; fi
if ((created_op)); then userdel "$op" || rc=1; fi
rm -rf -- "$stage" || rc=1
exit "$rc"
}
trap cleanup EXIT
mkdir "$stage/source" "$stage/evidence"
tar -xf - -C "$stage/source"
chmod 0755 "$stage"
chmod -R a+rX "$stage/source"
useradd -U -M -d /nonexistent -s /usr/sbin/nologin "$op"
created_op=1
useradd -U -M -d /nonexistent -s /usr/sbin/nologin "$other"
created_other=1
lab="$stage/lab"
install -d -m 0755 "$lab"
install -d -m 0700 -o "$op" -g "$op" "$lab/state"
policy() {
printf '{"uid":%s,"operations":%s}\n' "$(id -u "$op")" "$1" > "$lab/policy.json"
chmod 0644 "$lab/policy.json"
}
rotate() {
python3 -c 'import secrets,sys; sys.stdout.buffer.write(secrets.token_bytes(32))' > "$lab/key.new"
chgrp "$op" "$lab/key.new"
chmod 0640 "$lab/key.new"
mv -f "$lab/key.new" "$lab/operator.key"
}
cd "$stage/source"
out="$stage/evidence"
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-before.json"
python3 -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"
policy '["issue","execute"]'
rotate
deny() { if "$@"; then echo "Unexpected access: $*" >&2; exit 1; fi; }
probe() { runuser -u "$op" -- python3 -B probe.py "$lab" "$1"; }
{
printf 'host=%s\nrevision=b0dda75809a7efa2dd8ae3dc910dab23db9cfb61\n' "$(hostname -s)"
id "$op"
id "$other"
test "$(getent passwd "$op" | cut -d: -f7)" = /usr/sbin/nologin
test "$(getent passwd "$other" | cut -d: -f7)" = /usr/sbin/nologin
test "$(passwd -S "$op" | awk '{print $2}')" = L
test "$(passwd -S "$other" | awk '{print $2}')" = L
echo 'PASS: both accounts have locked passwords and no login shell'
stat -c '%a %U %G %n' "$lab/operator.key" "$lab/policy.json" "$lab/state"
runuser -u "$op" -- test -r "$lab/operator.key"
deny runuser -u "$op" -- test -w "$lab/operator.key"
deny runuser -u "$op" -- test -w "$lab/policy.json"
deny runuser -u "$other" -- test -r "$lab/operator.key"
deny runuser -u "$other" -- test -x "$lab/state"
echo 'PASS: operator can read the key; neither operator account can modify key or policy; ungranted account cannot read key or enter state'
probe wrong-principal
probe issue
probe consume
probe replay
probe issue
policy '[]'
probe grant-revoked
policy '["issue","execute"]'
rotate
probe key-revoked
probe issue
probe consume
probe replay
userdel "$other"
created_other=0
userdel "$op"
created_op=0
deny getent passwd "$op"
deny getent passwd "$other"
rm -rf -- "$lab"
test ! -e "$lab"
echo 'PASS: temporary accounts and key/state removed'
} > "$out/qualification.log"
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-after.json"
cmp "$out/capabilities-before.json" "$out/capabilities-after.json"
cp probe.py "$out/"
(cd "$out" && sha256sum ./* > SHA256SUMS)
tar -czf - -C "$out" .
+11 -71
View File
@@ -5,14 +5,12 @@ import stat
import tempfile
import unittest
from dataclasses import replace
from datetime import datetime, timedelta, timezone
from pathlib import Path
from unittest.mock import patch
from core.approval import approval_checksum, issue_approval
from core.approval import issue_approval
from core.approval_store import ApprovalStore, ApprovalStoreError
from core.operator_approval import OperatorApprovalPolicy, OperatorGrant
from core.locking import DeploymentLock, LockError
from core.rehearsal import create_rehearsal, approval_context
@@ -25,6 +23,7 @@ class ApprovalStoreTests(unittest.TestCase):
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.store = ApprovalStore(self.root)
self.now = datetime(
2026, 11, 26, 10, 0,
@@ -82,22 +81,6 @@ class ApprovalStoreTests(unittest.TestCase):
self.identifier = self.approval["approval_id"]
self.uid = os.geteuid()
if self.uid == 0:
self.uid = 1000
identity = patch("core.operator_approval.geteuid", return_value=self.uid)
identity.start()
self.addCleanup(identity.stop)
self.key = os.urandom(32)
self.grants = [
OperatorGrant(self.uid, "operator", operation, self.base["site"],
self.base["revision"], self.now + timedelta(days=2))
for operation in ("issue", "execute")
]
self.policy = OperatorApprovalPolicy(self.grants, sealing_key=self.key)
self.store = ApprovalStore(self.root, operator_policy=self.policy)
def save(self):
return self.store.save(
@@ -122,17 +105,15 @@ class ApprovalStoreTests(unittest.TestCase):
)
def test_save_approval(self):
saved = self.save()
self.assertEqual(saved["context"], self.approval["context"])
self.assertEqual(saved["format_version"], 2)
self.assertEqual(self.save(), self.approval)
def test_persistent_approval(self):
saved = self.save()
self.save()
self.assertEqual(
ApprovalStore(self.root).load(self.identifier),
saved,
self.approval,
)
def test_duplicate_approval_rejected(self):
@@ -171,9 +152,9 @@ class ApprovalStoreTests(unittest.TestCase):
self.save()
self.consume()
self.store = ApprovalStore(self.root, operator_policy=self.policy)
self.store = ApprovalStore(self.root)
with self.assertRaisesRegex(ApprovalStoreError, "already consumed"):
with self.assertRaises(ApprovalStoreError):
self.consume()
def test_wrong_confirmation_rejected(self):
@@ -390,23 +371,23 @@ class ApprovalStoreTests(unittest.TestCase):
def test_original_approval_preserved(self):
saved = self.save()
self.save()
self.consume()
self.assertEqual(
self.store.load(self.identifier),
saved,
self.approval,
)
def test_consumption_bound_to_approval(self):
saved = self.save()
self.save()
result = self.consume()
self.assertEqual(
result["approval_checksum"],
saved["checksum"],
self.approval["checksum"],
)
def test_consumption_bound_to_rehearsal(self):
@@ -481,46 +462,5 @@ class ApprovalStoreTests(unittest.TestCase):
)
def test_missing_policy_denies_issuance(self):
self.store = ApprovalStore(self.root)
with self.assertRaisesRegex(ApprovalStoreError, "policy required"):
self.save()
self.assertFalse(self.store.approval_path(self.identifier).exists())
def test_unrecognised_os_identity_denies_issuance(self):
other_account = [replace(grant, uid=self.uid + 1) for grant in self.grants]
self.store.operator_policy = OperatorApprovalPolicy(other_account, sealing_key=self.key)
with self.assertRaisesRegex(ApprovalStoreError, "not authorised"):
self.save()
self.assertFalse(self.store.approval_path(self.identifier).exists())
def test_execution_scope_is_checked_again(self):
self.save()
execute = self.grants[1]
for grant in (self.grants[0], replace(execute, site="other-site"),
replace(execute, revision="0" * 40),
replace(execute, principal="other-operator"),
replace(execute, expires_at=self.now)):
with self.subTest(grant=grant):
self.store.operator_policy = OperatorApprovalPolicy([grant], sealing_key=self.key)
with self.assertRaises(ApprovalStoreError):
self.consume()
self.assertFalse(self.store.consumed_path(self.identifier).exists())
def test_legacy_unsigned_record_cannot_execute(self):
self.store.publish(self.store.approval_path(self.identifier), self.approval)
with self.assertRaises(ApprovalStoreError):
self.consume()
self.assertFalse(self.store.consumed_path(self.identifier).exists())
def test_recomputed_checksum_cannot_replace_operator_seal(self):
saved = self.save()
saved["operator_seal"] = "0" * 64
saved["checksum"] = approval_checksum(saved)
self.store.approval_path(self.identifier).write_text(json.dumps(saved))
with self.assertRaises(ApprovalStoreError):
self.consume()
self.assertFalse(self.store.consumed_path(self.identifier).exists())
if __name__ == "__main__":
unittest.main()
+1 -14
View File
@@ -17,7 +17,7 @@ class MigrationTests(unittest.TestCase):
self.fixture = test_approval_store.ApprovalStoreTests()
self.addCleanup(self.fixture.doCleanups)
self.fixture.setUp()
self.ops = SiteOperations(self.fixture.root, operator_policy=self.fixture.policy)
self.ops = SiteOperations(self.fixture.root)
self.fixture.store = self.ops.approvals
self.fixture.save()
@@ -364,18 +364,5 @@ class MigrationTests(unittest.TestCase):
self.migrate.assert_not_called()
def test_missing_execution_authority_blocks_before_containment(self):
from core.operator_approval import OperatorApprovalPolicy
self.fixture.store.operator_policy = OperatorApprovalPolicy(
self.fixture.grants[:1], sealing_key=self.fixture.key,
)
with self.assertRaises(MigrationError):
self.execute()
self.contain.assert_not_called()
self.migrate.assert_not_called()
self.assertFalse(self.coordinator.intent_path(self.fixture.identifier).exists())
self.assertFalse(self.fixture.store.consumed_path(self.fixture.identifier).exists())
if __name__ == "__main__":
unittest.main()