Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c7a642b23c | ||
|
|
2719378f67 |
@@ -307,9 +307,14 @@ class ApprovalStore:
|
|||||||
return record
|
return record
|
||||||
|
|
||||||
def require_operator_policy(self):
|
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")
|
"Trusted migration operator policy required")
|
||||||
return self.operator_policy
|
return policy
|
||||||
|
|
||||||
def verify_execution(self, approval, context, *, confirmation, now):
|
def verify_execution(self, approval, context, *, confirmation, now):
|
||||||
verify_approval(approval, context, confirmation=confirmation, now=now)
|
verify_approval(approval, context, confirmation=confirmation, now=now)
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
"""Local operator identity and scoped migration approval policy."""
|
"""Local operator identity and scoped migration approval policy."""
|
||||||
|
|
||||||
import hmac
|
import hmac
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from os import geteuid
|
from os import geteuid
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from core.approval import (
|
from core.approval import (
|
||||||
ApprovalError,
|
ApprovalError,
|
||||||
@@ -82,3 +86,46 @@ class OperatorApprovalPolicy:
|
|||||||
def verify_execution(self, approval, now):
|
def verify_execution(self, approval, now):
|
||||||
self.verify_seal(approval)
|
self.verify_seal(approval)
|
||||||
self.authorise(approval, "execute", now)
|
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"]))
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
# Local migration operator authorisation
|
# Local migration operator authorisation
|
||||||
|
|
||||||
The supported development composition accepts an `OperatorApprovalPolicy`
|
The supported development composition accepts a policy loader through
|
||||||
through `SiteOperations(operator_policy=...)`. Configure the policy in trusted
|
`SiteOperations(operator_policy=...)`. The loader must return a fresh
|
||||||
runtime code with a one-to-one mapping from dedicated OS accounts to operator
|
`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
|
principals. The policy authenticates the process's effective UID. The operator's
|
||||||
login or service launcher must authenticate access to that account. A shared
|
login or service launcher must authenticate access to that account. A shared
|
||||||
service account cannot provide individual operator identity.
|
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.
|
verification requires access to the sealing key used for issuance.
|
||||||
|
|
||||||
The runtime process, its code, policy, key, clock and state directory are trusted.
|
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.
|
must never be exposed as a shared application or arbitrary command identity.
|
||||||
The inspection CLI remains disabled for production execution.
|
The inspection CLI remains disabled for production execution.
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
# ABSDEV-CI live password cutover
|
|
||||||
|
|
||||||
Tested revision 1c3df42a68d75b825993f9e5b9a774e5eeacff4b with disposable MySQL and PostgreSQL containers. The harness mounted the site credential directory defined by the supported Compose override. FileSecretBackend delivered both the initial and replacement credential files. The framework adapters ran fresh connections under the designated non-root UID through CommandRunner.
|
|
||||||
|
|
||||||
Each live server rejected the old password after rotation. The new backend credential restored authentication without recreating the container. Re-delivering the retired file still failed, and restoring the new file succeeded again. The test used synthetic passwords and did not exercise sessions already connected during rotation. All 16 qualification checks and 898 framework tests passed. Disposable containers, volumes and temporary secret state were removed. Production capabilities remained disabled.
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-after.json
|
|
||||||
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-before.json
|
|
||||||
6873e42595287787b29f4f3a9fc45523fc77b51a096d24ac2d19a37d0277569a ./checks.jsonl
|
|
||||||
d66fc3ce71f6170433ef3c49fdc432ebaf16344af391f4dca1fa9a66961993f6 ./framework-ci.txt
|
|
||||||
77d1f72cb16529f15b54cd5be83178b26157f1cfa1b79997378ab9a6ce1f2f81 ./scope.txt
|
|
||||||
9bd7362c763e4cc05f530c8958a646d7a4d0302a41a2b73b8ad5df2c3e274b92 probe.py
|
|
||||||
dc7d2c5009290b0c19b5c350c660330a7facb996e7d3b7fede1eb0f5f8dbf2b2 run.sh
|
|
||||||
d7db8a2f86b9ee00f198c9e2b526f9f5acaae1c4550f5988d824b6d95bb3dc07 README.md
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{"engine": "framework", "result": "PASS", "check": "approved child receives fixed PATH and locale only"}
|
|
||||||
{"engine": "mysql", "result": "PASS", "check": "disposable database has no external network or published ports and only the read-only site credential bind"}
|
|
||||||
{"engine": "mysql", "result": "PASS", "check": "missing credential file rejects authentication without publishing output"}
|
|
||||||
{"engine": "mysql", "result": "PASS", "check": "adapter authenticates as the designated UID with backend-delivered file; unrelated UID cannot read it"}
|
|
||||||
{"engine": "mysql", "result": "PASS", "check": "server explicitly rejects the old credential after password rotation"}
|
|
||||||
{"engine": "mysql", "result": "PASS", "check": "new backend credential atomically delivered to the existing container authenticates"}
|
|
||||||
{"engine": "mysql", "result": "PASS", "check": "re-delivering the retired credential still fails server authentication"}
|
|
||||||
{"engine": "mysql", "result": "PASS", "check": "re-delivering the new credential works in the original running container"}
|
|
||||||
{"engine": "pgsql", "result": "PASS", "check": "disposable database has no external network or published ports and only the read-only site credential bind"}
|
|
||||||
{"engine": "pgsql", "result": "PASS", "check": "missing credential file rejects authentication without publishing output"}
|
|
||||||
{"engine": "pgsql", "result": "PASS", "check": "adapter authenticates as the designated UID with backend-delivered file; unrelated UID cannot read it"}
|
|
||||||
{"engine": "pgsql", "result": "PASS", "check": "server explicitly rejects the old credential after password rotation"}
|
|
||||||
{"engine": "pgsql", "result": "PASS", "check": "new backend credential atomically delivered to the existing container authenticates"}
|
|
||||||
{"engine": "pgsql", "result": "PASS", "check": "re-delivering the retired credential still fails server authentication"}
|
|
||||||
{"engine": "pgsql", "result": "PASS", "check": "re-delivering the new credential works in the original running container"}
|
|
||||||
{"engine": "framework", "result": "PASS", "check": "all disposable containers and their anonymous volumes removed"}
|
|
||||||
@@ -1,204 +0,0 @@
|
|||||||
import io
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import secrets
|
|
||||||
import subprocess
|
|
||||||
import tempfile
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from core.database import get_adapter
|
|
||||||
from core.execution import CommandRunner, ExecutionError
|
|
||||||
from core.secret_backend import FileSecretBackend
|
|
||||||
from core.site_secrets import SiteSecrets
|
|
||||||
|
|
||||||
IMAGES = {
|
|
||||||
"mysql": "sha256:8c233bad33d520a7aae1c1e619c3a9775f4a1ba2d463d692fada04ec7f40be00",
|
|
||||||
"pgsql": "sha256:e742a2668255221388004f3a42b6150a2103f5054ab3a4a93ae9e4f01e551c35",
|
|
||||||
}
|
|
||||||
KEY_PATHS = {"mysql": "/run/secrets/absdev-client.cnf", "pgsql": "/run/secrets/absdev-pgpass"}
|
|
||||||
containers = []
|
|
||||||
event_count = 0
|
|
||||||
|
|
||||||
def docker(*args, input_data=None):
|
|
||||||
return subprocess.run(("docker", *args), input=input_data, capture_output=True,
|
|
||||||
text=True, timeout=120)
|
|
||||||
|
|
||||||
def good(*args, input_data=None):
|
|
||||||
result = docker(*args, input_data=input_data)
|
|
||||||
if result.returncode:
|
|
||||||
raise RuntimeError(f"Docker {args[0]} failed with status {result.returncode}")
|
|
||||||
return result.stdout.strip()
|
|
||||||
|
|
||||||
def record(engine, check):
|
|
||||||
global event_count
|
|
||||||
event_count += 1
|
|
||||||
print(json.dumps(dict(engine=engine, result="PASS", check=check)), flush=True)
|
|
||||||
|
|
||||||
def start(engine, name, mount):
|
|
||||||
variable = "MYSQL_ROOT_PASSWORD" if engine == "mysql" else "POSTGRES_PASSWORD"
|
|
||||||
environment = Path.cwd().parent / (name + ".env")
|
|
||||||
environment.write_text(variable + "=" + secrets.token_hex(24) + "\n")
|
|
||||||
environment.chmod(0o600)
|
|
||||||
with environment.open("a") as handle:
|
|
||||||
if engine == "pgsql":
|
|
||||||
handle.write("POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256\n")
|
|
||||||
try:
|
|
||||||
cid = good("create", "--pull", "never", "--name", name, "--network", "none",
|
|
||||||
"--security-opt", "no-new-privileges", "--cap-drop", "NET_RAW",
|
|
||||||
"--memory", "1g", "--pids-limit", "256", "--env-file", str(environment),
|
|
||||||
"--mount", f"type=bind,source={mount},target=/run/secrets,readonly",
|
|
||||||
IMAGES[engine])
|
|
||||||
finally:
|
|
||||||
environment.unlink()
|
|
||||||
containers.append(cid)
|
|
||||||
good("start", cid)
|
|
||||||
details = json.loads(good("inspect", "--format", "{{json .HostConfig}}", cid))
|
|
||||||
assert details["NetworkMode"] == "none" and not details["Privileged"]
|
|
||||||
assert not details["PortBindings"]
|
|
||||||
live_mounts = json.loads(good("inspect", "--format", "{{json .Mounts}}", cid))
|
|
||||||
binds = [item for item in live_mounts if item["Type"] == "bind"]
|
|
||||||
assert len(binds) == 1 and binds[0]["Destination"] == "/run/secrets"
|
|
||||||
assert binds[0]["Source"] == str(mount) and not binds[0]["RW"]
|
|
||||||
record(engine, "disposable database has no external network or published ports and only the read-only site credential bind")
|
|
||||||
return name, cid
|
|
||||||
|
|
||||||
def admin(engine, cid, sql):
|
|
||||||
if engine == "mysql":
|
|
||||||
return docker("exec", "-i", cid, "sh", "-c",
|
|
||||||
'MYSQL_PWD="$MYSQL_ROOT_PASSWORD" exec mysql --no-defaults -uroot --batch',
|
|
||||||
input_data=sql)
|
|
||||||
return docker("exec", "-i", "--user", "postgres", cid, "psql", "-X", "-U", "postgres",
|
|
||||||
"-d", "postgres", "-v", "ON_ERROR_STOP=1", input_data=sql)
|
|
||||||
|
|
||||||
def ready(engine, cid):
|
|
||||||
for _ in range(90):
|
|
||||||
if engine == "pgsql":
|
|
||||||
status = docker("exec", cid, "pg_isready", "-h", "127.0.0.1", "-U", "postgres")
|
|
||||||
if status.returncode:
|
|
||||||
time.sleep(1)
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
status = docker("exec", cid, "sh", "-c",
|
|
||||||
'MYSQL_PWD="$MYSQL_ROOT_PASSWORD" mysql --no-defaults --protocol=TCP -h127.0.0.1 -uroot -e "SELECT 1"')
|
|
||||||
if status.returncode:
|
|
||||||
time.sleep(1)
|
|
||||||
continue
|
|
||||||
if admin(engine, cid, "SELECT 1;").returncode == 0:
|
|
||||||
return
|
|
||||||
time.sleep(1)
|
|
||||||
raise RuntimeError(f"{engine} did not become ready")
|
|
||||||
|
|
||||||
def publish(engine, backend, delivery, password):
|
|
||||||
filename = Path(KEY_PATHS[engine]).name
|
|
||||||
data = ("[client]\npassword=" + password + "\n" if engine == "mysql"
|
|
||||||
else "127.0.0.1:5432:fixture:fixture:" + password + "\n")
|
|
||||||
area = backend.directory / backend.site
|
|
||||||
with tempfile.NamedTemporaryFile(dir=area, delete=False) as stream:
|
|
||||||
stream.write(data.encode())
|
|
||||||
stream.flush()
|
|
||||||
os.fchown(stream.fileno(), 0, backend.group)
|
|
||||||
os.fchmod(stream.fileno(), 0o440)
|
|
||||||
os.fsync(stream.fileno())
|
|
||||||
os.replace(stream.name, area / filename)
|
|
||||||
backend.deliver(delivery, "database", filename)
|
|
||||||
|
|
||||||
def check_command(runner, command, success):
|
|
||||||
output = io.BytesIO()
|
|
||||||
try:
|
|
||||||
runner(command, output)
|
|
||||||
except ExecutionError:
|
|
||||||
assert not success and not output.getvalue()
|
|
||||||
else:
|
|
||||||
assert success and output.getvalue().strip() == b"1"
|
|
||||||
|
|
||||||
def qualify(engine):
|
|
||||||
name = "absdev-cutover-" + engine + "-" + secrets.token_hex(5)
|
|
||||||
root = Path.cwd().parent / name
|
|
||||||
root.mkdir(mode=0o700)
|
|
||||||
backend_root = root / "backend"
|
|
||||||
backend_root.mkdir()
|
|
||||||
backend_root.chmod(0o711)
|
|
||||||
area = backend_root / name
|
|
||||||
area.mkdir()
|
|
||||||
uid = 11001 if engine == "mysql" else 11002
|
|
||||||
os.chown(area, 0, uid)
|
|
||||||
area.chmod(0o750)
|
|
||||||
delivery_root = root / "delivery"
|
|
||||||
delivery_root.mkdir(mode=0o700)
|
|
||||||
config = json.loads(Path("config/site.example.json").read_text())
|
|
||||||
config["site"].update(identifier=name, root=str(root))
|
|
||||||
config["docker"]["project"] = name
|
|
||||||
config["database"].update(driver=engine, container=name, host="127.0.0.1",
|
|
||||||
port=3306 if engine == "mysql" else 5432,
|
|
||||||
name="fixture", username="fixture")
|
|
||||||
backend = FileSecretBackend(backend_root, name, uid)
|
|
||||||
delivery = SiteSecrets(config, delivery_root, {"database": uid})
|
|
||||||
override = json.loads(delivery.compose_file(config).read_text())
|
|
||||||
mount = override["services"]["database"]["volumes"][0]
|
|
||||||
assert mount["target"] == "/run/secrets" and mount["read_only"]
|
|
||||||
_, cid = start(engine, name, Path(mount["source"]))
|
|
||||||
ready(engine, cid)
|
|
||||||
original, rotated = secrets.token_hex(24), secrets.token_hex(24)
|
|
||||||
if engine == "mysql":
|
|
||||||
setup = ("CREATE DATABASE fixture; "
|
|
||||||
f"CREATE USER 'fixture'@'127.0.0.1' IDENTIFIED BY '{original}'; "
|
|
||||||
"GRANT SELECT ON fixture.* TO 'fixture'@'127.0.0.1';")
|
|
||||||
change = f"ALTER USER 'fixture'@'127.0.0.1' IDENTIFIED BY '{rotated}';"
|
|
||||||
else:
|
|
||||||
setup = f"CREATE ROLE fixture LOGIN PASSWORD '{original}';\nCREATE DATABASE fixture OWNER fixture;"
|
|
||||||
change = f"ALTER ROLE fixture PASSWORD '{rotated}';"
|
|
||||||
assert admin(engine, cid, setup).returncode == 0, f"{engine} fixture setup failed"
|
|
||||||
original_command = get_adapter(config).ping_command()
|
|
||||||
assert original_command[:3] == ["docker", "exec", name]
|
|
||||||
command = ["docker", "exec", "--user", f"{uid}:{uid}", cid, *original_command[3:]]
|
|
||||||
assert not any(value in arg for arg in command for value in (original, rotated))
|
|
||||||
runner = CommandRunner([command], timeout=15)
|
|
||||||
check_command(runner, command, False)
|
|
||||||
record(engine, "missing credential file rejects authentication without publishing output")
|
|
||||||
publish(engine, backend, delivery, original)
|
|
||||||
path = KEY_PATHS[engine]
|
|
||||||
assert docker("exec", "--user", "65534:65534", cid, "cat", path).returncode != 0
|
|
||||||
check_command(runner, command, True)
|
|
||||||
record(engine, "adapter authenticates as the designated UID with backend-delivered file; unrelated UID cannot read it")
|
|
||||||
assert admin(engine, cid, change).returncode == 0, f"{engine} password rotation failed"
|
|
||||||
check_command(runner, command, False)
|
|
||||||
denied = docker(*command[1:])
|
|
||||||
expected_error = "Access denied" if engine == "mysql" else "password authentication failed"
|
|
||||||
assert denied.returncode and expected_error in denied.stderr and not denied.stdout
|
|
||||||
record(engine, "server explicitly rejects the old credential after password rotation")
|
|
||||||
publish(engine, backend, delivery, rotated)
|
|
||||||
check_command(runner, command, True)
|
|
||||||
record(engine, "new backend credential atomically delivered to the existing container authenticates")
|
|
||||||
publish(engine, backend, delivery, original)
|
|
||||||
check_command(runner, command, False)
|
|
||||||
record(engine, "re-delivering the retired credential still fails server authentication")
|
|
||||||
publish(engine, backend, delivery, rotated)
|
|
||||||
check_command(runner, command, True)
|
|
||||||
assert good("inspect", "--format", "{{.State.Running}}", cid) == "true"
|
|
||||||
record(engine, "re-delivering the new credential works in the original running container")
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.environ.update(PATH="/untrusted", ABSDEV_TEST_SECRET="synthetic", DOCKER_HOST="synthetic",
|
|
||||||
PGPASSWORD="synthetic", MYSQL_PWD="synthetic")
|
|
||||||
argv = [sys.executable, "-I", "-c", "import json, os; print(json.dumps(dict(os.environ)))"]
|
|
||||||
output = io.BytesIO()
|
|
||||||
CommandRunner([argv])(argv, output)
|
|
||||||
assert json.loads(output.getvalue()) == {"PATH": os.defpath, "LC_ALL": "C"}
|
|
||||||
record("framework", "approved child receives fixed PATH and locale only")
|
|
||||||
# The qualification controller needs its own trusted Docker environment.
|
|
||||||
for name in ("ABSDEV_TEST_SECRET", "DOCKER_HOST", "PGPASSWORD", "MYSQL_PWD"):
|
|
||||||
os.environ.pop(name)
|
|
||||||
os.environ["PATH"] = os.defpath
|
|
||||||
for engine in IMAGES:
|
|
||||||
qualify(engine)
|
|
||||||
finally:
|
|
||||||
cleanup_failed = False
|
|
||||||
for cid in reversed(containers):
|
|
||||||
command = docker("rm", "-fv", cid)
|
|
||||||
if command.returncode:
|
|
||||||
cleanup_failed = True
|
|
||||||
if cleanup_failed:
|
|
||||||
raise RuntimeError("Disposable container cleanup failed")
|
|
||||||
record("framework", "all disposable containers and their anonymous volumes removed")
|
|
||||||
@@ -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-db-cutover.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=1c3df42a68d75b825993f9e5b9a774e5eeacff4b\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/checks.jsonl" || { cat "$out/checks.jsonl" >&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=1c3df42a68d75b825993f9e5b9a774e5eeacff4b
|
|
||||||
@@ -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
|
||||||
+2
-2
@@ -5,9 +5,9 @@ Python 3.14.4
|
|||||||
PASS: 88 Python sources compiled
|
PASS: 88 Python sources compiled
|
||||||
|
|
||||||
=== COMPLETE UNIT REGRESSION SUITE ===
|
=== COMPLETE UNIT REGRESSION SUITE ===
|
||||||
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
|
.....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
Ran 898 tests in 18.573s
|
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()
|
||||||
@@ -96,7 +96,7 @@ 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=self.policy)
|
self.store = ApprovalStore(self.root, operator_policy=lambda: self.policy)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
self.save()
|
self.save()
|
||||||
self.consume()
|
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"):
|
with self.assertRaisesRegex(ApprovalStoreError, "already consumed"):
|
||||||
self.consume()
|
self.consume()
|
||||||
@@ -483,13 +483,13 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
|
|
||||||
def test_missing_policy_denies_issuance(self):
|
def test_missing_policy_denies_issuance(self):
|
||||||
self.store = ApprovalStore(self.root)
|
self.store = ApprovalStore(self.root)
|
||||||
with self.assertRaisesRegex(ApprovalStoreError, "policy required"):
|
with self.assertRaisesRegex(ApprovalStoreError, "policy loader required"):
|
||||||
self.save()
|
self.save()
|
||||||
self.assertFalse(self.store.approval_path(self.identifier).exists())
|
self.assertFalse(self.store.approval_path(self.identifier).exists())
|
||||||
|
|
||||||
def test_unrecognised_os_identity_denies_issuance(self):
|
def test_unrecognised_os_identity_denies_issuance(self):
|
||||||
other_account = [replace(grant, uid=self.uid + 1) for grant in self.grants]
|
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"):
|
with self.assertRaisesRegex(ApprovalStoreError, "not authorised"):
|
||||||
self.save()
|
self.save()
|
||||||
self.assertFalse(self.store.approval_path(self.identifier).exists())
|
self.assertFalse(self.store.approval_path(self.identifier).exists())
|
||||||
@@ -502,7 +502,7 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
replace(execute, principal="other-operator"),
|
replace(execute, principal="other-operator"),
|
||||||
replace(execute, expires_at=self.now)):
|
replace(execute, expires_at=self.now)):
|
||||||
with self.subTest(grant=grant):
|
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):
|
with self.assertRaises(ApprovalStoreError):
|
||||||
self.consume()
|
self.consume()
|
||||||
self.assertFalse(self.store.consumed_path(self.identifier).exists())
|
self.assertFalse(self.store.consumed_path(self.identifier).exists())
|
||||||
@@ -522,5 +522,26 @@ class ApprovalStoreTests(unittest.TestCase):
|
|||||||
self.consume()
|
self.consume()
|
||||||
self.assertFalse(self.store.consumed_path(self.identifier).exists())
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@@ -17,7 +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=self.fixture.policy)
|
self.ops = SiteOperations(self.fixture.root, operator_policy=lambda: self.fixture.policy)
|
||||||
self.fixture.store = self.ops.approvals
|
self.fixture.store = self.ops.approvals
|
||||||
self.fixture.save()
|
self.fixture.save()
|
||||||
|
|
||||||
@@ -367,7 +367,7 @@ class MigrationTests(unittest.TestCase):
|
|||||||
def test_missing_execution_authority_blocks_before_containment(self):
|
def test_missing_execution_authority_blocks_before_containment(self):
|
||||||
from core.operator_approval import OperatorApprovalPolicy
|
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,
|
self.fixture.grants[:1], sealing_key=self.fixture.key,
|
||||||
)
|
)
|
||||||
with self.assertRaises(MigrationError):
|
with self.assertRaises(MigrationError):
|
||||||
|
|||||||
Reference in New Issue
Block a user