Compare commits

...
Author SHA1 Message Date
Mark Gregory c7a642b23c Record ABSDEV-CI live operator revocation qualification 2026-11-29 09:57:26 +00:00
Mark Gregory 2719378f67 Reload trusted migration operator authority before approval consumption
ABSDEV Framework CI / framework-ci (push) Successful in 22s
2026-11-29 09:49:01 +00:00
14 changed files with 408 additions and 14 deletions
+7 -2
View File
@@ -307,9 +307,14 @@ class ApprovalStore:
return record
def require_operator_policy(self):
require(isinstance(self.operator_policy, OperatorApprovalPolicy),
require(callable(self.operator_policy), "Trusted migration operator policy loader required")
try:
policy = self.operator_policy()
except Exception:
raise ApprovalStoreError("Unable to verify current migration operator authority") from None
require(isinstance(policy, OperatorApprovalPolicy),
"Trusted migration operator policy required")
return self.operator_policy
return policy
def verify_execution(self, approval, context, *, confirmation, now):
verify_approval(approval, context, confirmation=confirmation, now=now)
+47
View File
@@ -1,10 +1,14 @@
"""Local operator identity and scoped migration approval policy."""
import hmac
import json
import os
import stat
from dataclasses import dataclass
from datetime import datetime
from os import geteuid
from pathlib import Path
from core.approval import (
ApprovalError,
@@ -82,3 +86,46 @@ class OperatorApprovalPolicy:
def verify_execution(self, approval, now):
self.verify_seal(approval)
self.authorise(approval, "execute", now)
class FileOperatorAuthority:
"""Load a fresh, atomic authority snapshot from a trusted local provisioner."""
MAX_BYTES = 65536
def __init__(self, path, *, group):
self.path = Path(path)
self.group = group
require(self.path.is_absolute() and self.path.parent.resolve() == self.path.parent
and type(group) is int and group > 0, "Invalid operator authority binding")
def __call__(self):
# The parent and its ancestors are trusted, and the final entry cannot
# be replaced by the reader or resolved through a symbolic link.
directory = os.open(self.path.parent, os.O_RDONLY | os.O_DIRECTORY
| os.O_NOFOLLOW | os.O_CLOEXEC)
try:
info = os.fstat(directory)
require(info.st_uid == 0 and info.st_gid == self.group
and stat.S_IMODE(info.st_mode) == 0o750,
"Unsafe operator authority directory")
descriptor = os.open(self.path.name, os.O_RDONLY | os.O_NOFOLLOW
| os.O_NONBLOCK | os.O_CLOEXEC, dir_fd=directory)
with os.fdopen(descriptor, "rb") as stream:
info = os.fstat(stream.fileno())
require(stat.S_ISREG(info.st_mode) and info.st_uid == 0
and info.st_gid == self.group and info.st_nlink == 1
and stat.S_IMODE(info.st_mode) == 0o440,
"Unsafe operator authority file")
data = stream.read(self.MAX_BYTES + 1)
finally:
os.close(directory)
require(0 < len(data) <= self.MAX_BYTES, "Invalid operator authority size")
snapshot = json.loads(data)
require(isinstance(snapshot, dict) and set(snapshot) == {"grants", "sealing_key"}
and isinstance(snapshot["grants"], list), "Invalid operator authority snapshot")
grants = [
OperatorGrant(**dict(grant, expires_at=datetime.fromisoformat(grant["expires_at"])))
for grant in snapshot["grants"]
]
return OperatorApprovalPolicy(grants, sealing_key=bytes.fromhex(snapshot["sealing_key"]))
+18 -5
View File
@@ -1,8 +1,8 @@
# 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
The supported development composition accepts a policy loader through
`SiteOperations(operator_policy=...)`. The loader must return a fresh
`OperatorApprovalPolicy` on each call. 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.
@@ -24,7 +24,20 @@ 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
Use `FileOperatorAuthority(path, group=...)` for a local authority source. Place
the root-owned mode 0440 JSON file in a root-owned mode 0750 directory whose
group matches the configured reader group, under administrator-controlled
ancestors. The JSON object contains `sealing_key` as hex and `grants` as a list
of objects with `uid`, `principal`, `operation`, `site`, `revision` and
`expires_at` (timezone-aware ISO 8601). Atomically replace the whole file when
removing grants or changing the key. The runtime reopens it for each authority
check, including consumption under the approval lock. Missing, unreadable,
unsafe or malformed state denies the operation. Key rotation invalidates
outstanding approvals and puts evidence sealed with the retired key into
manual review. Revocation is evaluated at the next authority read and cannot
recall an operation that already passed its final consumption check.
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,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,19 @@
{
"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
}
@@ -0,0 +1,19 @@
{
"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
}
@@ -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
@@ -0,0 +1,108 @@
=== ABSDEV FRAMEWORK CI ===
Python 3.14.4
=== PYTHON SYNTAX VALIDATION ===
PASS: 88 Python sources compiled
=== COMPLETE UNIT REGRESSION SUITE ===
.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 901 tests in 18.524s
OK
=== VERIFY PRODUCTION CAPABILITY RESTRICTIONS ===
PASS: production_ready=false
PASS: deployment_execution_enabled=false
PASS: migration_execution_enabled=false
PASS: provisioning_execution_enabled=false
PASS: database_restore_enabled=false
PASS: permanent_deletion_enabled=false
PASS: Unsupported command rejected: deploy
PASS: Unsupported command rejected: migrate
PASS: Unsupported command rejected: rollback
PASS: Unsupported command rejected: restore
PASS: Unsupported command rejected: provision
PASS: Unsupported command rejected: delete
=== EXAMPLE CONFIGURATION ===
PASS: Configuration valid
Site: example-absdev-net
Domain: example.absdev.net
Database: mysql
Schema: 1
No deployment performed
{
"configuration_fingerprint": "8067fa8477a7d50cbcc42b585961bcd4dbce5407fc7e4bffcfb3e07af529e483",
"execution_permitted": false,
"fingerprint": "d271a3a3ed2cbda032f905558fe9ada653c380c74306fc714ebc594483a63042",
"format_version": 1,
"runtime_verified": false,
"site": "example-absdev-net",
"static_policy_verified": true,
"status": "VALID"
}
{
"configuration_fingerprint": "8067fa8477a7d50cbcc42b585961bcd4dbce5407fc7e4bffcfb3e07af529e483",
"database": {
"container": "platform-mysql",
"driver": "mysql",
"name": "example_db",
"username": "example_app"
},
"database_creation_permitted": false,
"directories": [
"/opt/laravel-sites/example-absdev-net",
"/opt/laravel-sites/example-absdev-net/app",
"/opt/laravel-sites/example-absdev-net/app/releases",
"/opt/laravel-sites/example-absdev-net/app/shared",
"/opt/laravel-sites/example-absdev-net/deployment",
"/opt/laravel-sites/example-absdev-net/backups",
"/opt/laravel-sites/example-absdev-net/deployment/state",
"/opt/laravel-sites/example-absdev-net/deployment/approvals",
"/opt/laravel-sites/example-absdev-net/deployment/archives"
],
"docker": {
"networks": [
"laravel_backend",
"laravel_proxy"
],
"project": "site-example-absdev-net",
"services": [
"php",
"web",
"queue",
"scheduler"
]
},
"domain": "example.absdev.net",
"execution_permitted": false,
"filesystem_permissions_verified": false,
"fingerprint": "d8432e17dc1b91ce4712ab656c14c0b5a0957c54700b027b22444dc3a4c19feb",
"format_version": 1,
"origin_port": 8199,
"repository": {
"branch": "main",
"url": "[email protected]:example/application.git"
},
"resource_conflicts_checked": false,
"retention": {
"automatic_deletion": false,
"keep_releases": 5
},
"root": "/opt/laravel-sites/example-absdev-net",
"secrets_required": true,
"site": "example-absdev-net",
"site_policy_fingerprint": "d271a3a3ed2cbda032f905558fe9ada653c380c74306fc714ebc594483a63042",
"static_policy_verified": true,
"status": "PLAN_ONLY"
}
=== REFERENCE INTEGRITY ===
SKIP: Private reference excluded from checkout
========================================
PASS: FRAMEWORK CI
UNIT TESTS AND STATIC VALIDATION ONLY
DATABASE INTEGRATION NOT EXECUTED
========================================
+38
View File
@@ -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()
+26 -5
View File
@@ -96,7 +96,7 @@ class ApprovalStoreTests(unittest.TestCase):
for operation in ("issue", "execute")
]
self.policy = OperatorApprovalPolicy(self.grants, sealing_key=self.key)
self.store = ApprovalStore(self.root, operator_policy=self.policy)
self.store = ApprovalStore(self.root, operator_policy=lambda: self.policy)
def save(self):
@@ -171,7 +171,7 @@ class ApprovalStoreTests(unittest.TestCase):
self.save()
self.consume()
self.store = ApprovalStore(self.root, operator_policy=self.policy)
self.store = ApprovalStore(self.root, operator_policy=lambda: self.policy)
with self.assertRaisesRegex(ApprovalStoreError, "already consumed"):
self.consume()
@@ -483,13 +483,13 @@ class ApprovalStoreTests(unittest.TestCase):
def test_missing_policy_denies_issuance(self):
self.store = ApprovalStore(self.root)
with self.assertRaisesRegex(ApprovalStoreError, "policy required"):
with self.assertRaisesRegex(ApprovalStoreError, "policy loader 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)
self.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())
@@ -502,7 +502,7 @@ class ApprovalStoreTests(unittest.TestCase):
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)
self.policy = OperatorApprovalPolicy([grant], sealing_key=self.key)
with self.assertRaises(ApprovalStoreError):
self.consume()
self.assertFalse(self.store.consumed_path(self.identifier).exists())
@@ -522,5 +522,26 @@ class ApprovalStoreTests(unittest.TestCase):
self.consume()
self.assertFalse(self.store.consumed_path(self.identifier).exists())
def test_static_authority_is_rejected(self):
self.store.operator_policy = self.policy
with self.assertRaisesRegex(ApprovalStoreError, "policy loader required"):
self.save()
def test_unavailable_authority_fails_closed_after_issuance(self):
self.save()
with patch.object(self.store, "operator_policy", side_effect=OSError("unavailable")):
with self.assertRaises(ApprovalStoreError):
self.consume()
self.assertFalse(self.store.consumed_path(self.identifier).exists())
def test_running_store_rejects_retired_sealing_key(self):
self.save()
self.policy = OperatorApprovalPolicy(self.grants, sealing_key=os.urandom(32))
with self.assertRaises(ApprovalStoreError):
self.consume()
self.assertFalse(self.store.consumed_path(self.identifier).exists())
if __name__ == "__main__":
unittest.main()
+2 -2
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, operator_policy=lambda: self.fixture.policy)
self.fixture.store = self.ops.approvals
self.fixture.save()
@@ -367,7 +367,7 @@ class MigrationTests(unittest.TestCase):
def test_missing_execution_authority_blocks_before_containment(self):
from core.operator_approval import OperatorApprovalPolicy
self.fixture.store.operator_policy = OperatorApprovalPolicy(
self.fixture.policy = OperatorApprovalPolicy(
self.fixture.grants[:1], sealing_key=self.fixture.key,
)
with self.assertRaises(MigrationError):