Compare commits

..
Author SHA1 Message Date
Mark Gregory a0ee4fc7ba Record ABSDEV-CI file secret backend qualification 2026-11-29 09:39:09 +00:00
Mark Gregory 1c3df42a68 Connect managed Compose delivery to a site-scoped file secret backend
ABSDEV Framework CI / framework-ci (push) Successful in 20s
2026-11-29 09:32:26 +00:00
12 changed files with 165 additions and 43 deletions
+61
View File
@@ -0,0 +1,61 @@
"""Read site-scoped credentials from a trusted local provisioner."""
import os
import re
import stat
from pathlib import Path
from core.site_secrets import SiteSecretError, SiteSecrets
class FileSecretBackend:
"""A root-provisioned store with per-site OS group access."""
def __init__(self, directory, site, group):
self.directory = Path(directory)
if (not self.directory.is_absolute() or self.directory.resolve() != self.directory
or not re.fullmatch(r"[a-z0-9][a-z0-9-]{0,62}", site)
or type(group) is not int or group <= 0):
raise SiteSecretError("Invalid file secret backend binding")
self.site = site
self.group = group
@staticmethod
def _require_metadata(descriptor, *, mode, group=None, directory=False):
info = os.fstat(descriptor)
valid_type = stat.S_ISDIR(info.st_mode) if directory else stat.S_ISREG(info.st_mode)
if (not valid_type or info.st_uid != 0 or stat.S_IMODE(info.st_mode) != mode
or (group is not None and info.st_gid != group)
or (not directory and info.st_nlink != 1)):
raise SiteSecretError("Unsafe file secret backend entry")
def read(self, filename):
if filename not in SiteSecrets.FILENAMES:
raise SiteSecretError("Unsupported credential filename")
flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC
try:
root = os.open(self.directory, os.O_PATH | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC)
try:
self._require_metadata(root, mode=0o711, directory=True)
site = os.open(self.site, flags, dir_fd=root)
try:
self._require_metadata(site, mode=0o750, group=self.group, directory=True)
item = os.open(filename, os.O_RDONLY | os.O_NOFOLLOW | os.O_CLOEXEC
| os.O_NONBLOCK, dir_fd=site)
with os.fdopen(item, "rb") as source:
self._require_metadata(source.fileno(), mode=0o440, group=self.group)
data = source.read(65537)
finally:
os.close(site)
finally:
os.close(root)
except OSError:
raise SiteSecretError("Unable to read managed backend credential") from None
if not 0 < len(data) <= 65536:
raise SiteSecretError("Invalid backend credential size")
return data
def deliver(self, delivery, service, filename):
if not isinstance(delivery, SiteSecrets) or delivery.site != self.site:
raise SiteSecretError("Backend and delivery must bind the same site")
delivery.rotate(service, filename, self.read(filename))
+17
View File
@@ -25,3 +25,20 @@ rotation and reconnect clients for new authentication. Existing connections
and programs that cache credentials require their own cutover. This runtime and programs that cache credentials require their own cutover. This runtime
accepts credential material from a trusted caller and does not operate a accepts credential material from a trusted caller and does not operate a
production secret backend. Production execution remains disabled. production secret backend. Production execution remains disabled.
## Local file backend
A trusted provisioner can use `FileSecretBackend(directory, site, group)`
and call `backend.deliver(site_secrets, service, filename)` to refresh the
runtime credential from the selected site. Place the store under
administrator-controlled ancestors. The root directory is root-owned mode
0711. Each site directory is root-owned mode 0750 with a dedicated site
group. Credential files are root-owned mode 0440 with that same group. Use
distinct groups for sites and grant each site identity only its own group.
The privileged provisioner is trusted across sites. Keep backend files out
of containers and use the read-only runtime mounts for delivery.
Publish replacements atomically in the backend, then trigger a fresh
delivery for the site. A failed backend read leaves the current delivery
unchanged. Any server-side update and client reconnect are managed by the
caller. Production execution remains disabled.
+7
View File
@@ -0,0 +1,7 @@
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-after.json
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-before.json
499359ffe91cf40ff270d33416162d1252b679d58e43f143d111eba37b2d4532 ./checks.jsonl
15c818e408d8b710ccf5c341b1d48b839e5f8e6c52ff0f6d8f0835c53a3e9c8a ./framework-ci.txt
fcbcfb1fd1737afb7f9663aaceebf76720583b05c0830285b3ae8db2e3ff9193 ./scope.txt
c3454343f7e7b582256cf41288abdfe5a194baec9b3edcc30a5091d628b429ee probe.py
707f621628fbdebd112b33d00e92318ec32eb4cd49cdc8e99831dd26300b0089 run.sh
@@ -1,5 +1,7 @@
{"check": "both supported Compose lifecycle instances started with independent read-only credential mounts", "result": "PASS"} {"check": "both supported Compose lifecycle instances started with independent read-only credential mounts", "result": "PASS"}
{"check": "same-UID services cannot read the other site's credentials or access their own site's ungranted mount", "result": "PASS"} {"check": "same-UID services cannot read the other site's credentials or access their own site's ungranted mount", "result": "PASS"}
{"check": "read-only mount rejects writes and runtime rejects mismatched site bindings", "result": "PASS"} {"check": "read-only mount rejects writes and runtime rejects mismatched site bindings", "result": "PASS"}
{"check": "dedicated OS identities can access only their own backend namespace; cross-site delivery rejected", "result": "PASS"}
{"check": "unsafe backend file permissions deny refresh and preserve current delivery", "result": "PASS"}
{"check": "atomic rotation reaches the existing container without affecting the other site", "result": "PASS"} {"check": "atomic rotation reaches the existing container without affecting the other site", "result": "PASS"}
{"check": "disposable Compose projects and volumes removed", "result": "PASS"} {"check": "disposable Compose projects, volumes and backend accounts removed", "result": "PASS"}
@@ -2,12 +2,12 @@
Python 3.14.4 Python 3.14.4
=== PYTHON SYNTAX VALIDATION === === PYTHON SYNTAX VALIDATION ===
PASS: 87 Python sources compiled PASS: 88 Python sources compiled
=== COMPLETE UNIT REGRESSION SUITE === === COMPLETE UNIT REGRESSION SUITE ===
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................. ..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
---------------------------------------------------------------------- ----------------------------------------------------------------------
Ran 898 tests in 19.038s Ran 898 tests in 18.300s
OK OK
@@ -7,6 +7,7 @@ import subprocess
import tempfile import tempfile
from pathlib import Path from pathlib import Path
from core.secret_backend import FileSecretBackend
from core.services import ServiceLifecycle from core.services import ServiceLifecycle
from core.site_secrets import SiteSecretError, SiteSecrets from core.site_secrets import SiteSecretError, SiteSecrets
@@ -17,6 +18,21 @@ store.mkdir(mode=0o700)
base = json.loads(Path("config/site.example.json").read_text()) base = json.loads(Path("config/site.example.json").read_text())
run = secrets.token_hex(5) run = secrets.token_hex(5)
projects = [] projects = []
accounts = []
backend_root = root / "backend"
root.chmod(0o711)
backend_root.mkdir()
backend_root.chmod(0o711)
def publish(site_root, gid, filename, data):
with tempfile.NamedTemporaryFile(dir=site_root, delete=False) as stream:
stream.write(data)
stream.flush()
os.fchown(stream.fileno(), 0, gid)
os.fchmod(stream.fileno(), 0o440)
os.fsync(stream.fileno())
os.replace(stream.name, site_root / filename)
def cmd(*args, allow_failure=False): def cmd(*args, allow_failure=False):
result = subprocess.run(args, capture_output=True, timeout=90) result = subprocess.run(args, capture_output=True, timeout=90)
@@ -47,7 +63,17 @@ def create(label, filename):
(project_root / "compose.yaml").write_text(json.dumps({"services": services})) (project_root / "compose.yaml").write_text(json.dumps({"services": services}))
site = SiteSecrets(config, store, {"queue": 10001}) site = SiteSecrets(config, store, {"queue": 10001})
data = secrets.token_bytes(32).hex().encode() + b"\n" data = secrets.token_bytes(32).hex().encode() + b"\n"
site.rotate("queue", filename, data) account = "absec" + label[0] + run
cmd("useradd", "-U", "-M", "-d", "/nonexistent", "-s", "/usr/sbin/nologin", account)
accounts.append(account)
gid = int(cmd("id", "-g", account).stdout)
area = backend_root / name
area.mkdir()
os.chown(area, 0, gid)
area.chmod(0o750)
publish(area, gid, filename, data)
backend = FileSecretBackend(backend_root, name, gid)
backend.deliver(site, "queue", filename)
path = store / name / "queue" / filename path = store / name / "queue" / filename
assert stat.S_IMODE(path.stat().st_mode) == 0o600 and path.stat().st_uid == 10001 assert stat.S_IMODE(path.stat().st_mode) == 0o600 and path.stat().st_uid == 10001
def runner(args, *, timeout): def runner(args, *, timeout):
@@ -64,7 +90,7 @@ def create(label, filename):
mount = [m for m in info["Mounts"] if m["Destination"] == "/run/secrets"] mount = [m for m in info["Mounts"] if m["Destination"] == "/run/secrets"]
assert len(mount) == 1 and mount[0]["Source"] == str(path.parent) and not mount[0]["RW"] assert len(mount) == 1 and mount[0]["Source"] == str(path.parent) and not mount[0]["RW"]
assert info["Image"] == IMAGE and info["HostConfig"]["NetworkMode"] == "none" assert info["Image"] == IMAGE and info["HostConfig"]["NetworkMode"] == "none"
return config, site, queue, scheduler, data return config, site, queue, scheduler, data, backend, account
def read(cid, file, expected=None): def read(cid, file, expected=None):
result = cmd("docker", "exec", cid, "cat", "/run/secrets/" + file, allow_failure=True) result = cmd("docker", "exec", cid, "cat", "/run/secrets/" + file, allow_failure=True)
@@ -74,8 +100,8 @@ def read(cid, file, expected=None):
assert not result.returncode and result.stdout == expected assert not result.returncode and result.stdout == expected
try: try:
a_config, a_site, a, a_other, first = create("alpha", "absdev-client.cnf") a_config, a_site, a, a_other, first, a_backend, a_account = create("alpha", "absdev-client.cnf")
b_config, _, b, b_other, second = create("beta", "absdev-pgpass") b_config, b_site, b, b_other, second, b_backend, b_account = create("beta", "absdev-pgpass")
passcheck("both supported Compose lifecycle instances started with independent read-only credential mounts") passcheck("both supported Compose lifecycle instances started with independent read-only credential mounts")
read(a, "absdev-client.cnf", first) read(a, "absdev-client.cnf", first)
read(b, "absdev-pgpass", second) read(b, "absdev-pgpass", second)
@@ -93,8 +119,44 @@ try:
else: else:
raise AssertionError("Cross-site override accepted") raise AssertionError("Cross-site override accepted")
passcheck("read-only mount rejects writes and runtime rejects mismatched site bindings") passcheck("read-only mount rejects writes and runtime rejects mismatched site bindings")
identity_probe = """from core.secret_backend import FileSecretBackend
from core.site_secrets import SiteSecretError
import sys
backend = FileSecretBackend(sys.argv[1], sys.argv[2], int(sys.argv[3]))
try:
backend.read(sys.argv[4])
except SiteSecretError:
sys.exit(3)
"""
for allowed, denied, backend, filename in (
(a_account, b_account, a_backend, "absdev-client.cnf"),
(b_account, a_account, b_backend, "absdev-pgpass"),
):
args = ("python3", "-B", "-c", identity_probe, str(backend_root),
backend.site, str(backend.group), filename)
assert cmd("runuser", "-u", allowed, "--", *args).returncode == 0
assert cmd("runuser", "-u", denied, "--", *args, allow_failure=True).returncode == 3
try:
a_backend.deliver(b_site, "queue", "absdev-client.cnf")
except SiteSecretError:
pass
else:
raise AssertionError("Backend delivered across site bindings")
passcheck("dedicated OS identities can access only their own backend namespace; cross-site delivery rejected")
file = backend_root / a_backend.site / "absdev-client.cnf"
file.chmod(0o444)
try:
a_backend.deliver(a_site, "queue", "absdev-client.cnf")
except SiteSecretError:
pass
else:
raise AssertionError("Backend accepted unsafe mode")
read(a, "absdev-client.cnf", first)
passcheck("unsafe backend file permissions deny refresh and preserve current delivery")
rotated = secrets.token_hex(32).encode() + b"\n" rotated = secrets.token_hex(32).encode() + b"\n"
a_site.rotate("queue", "absdev-client.cnf", rotated) publish(file.parent, a_backend.group, file.name, rotated)
a_backend.deliver(a_site, "queue", file.name)
read(a, "absdev-client.cnf", rotated) read(a, "absdev-client.cnf", rotated)
read(b, "absdev-pgpass", second) read(b, "absdev-pgpass", second)
read(b, "absdev-client.cnf") read(b, "absdev-client.cnf")
@@ -103,6 +165,8 @@ try:
finally: finally:
failures = [project for project in reversed(projects) failures = [project for project in reversed(projects)
if cmd(*project, "down", "--volumes", allow_failure=True).returncode] if cmd(*project, "down", "--volumes", allow_failure=True).returncode]
failures.extend(account for account in reversed(accounts)
if cmd("userdel", account, allow_failure=True).returncode)
if failures: if failures:
raise RuntimeError("Disposable Compose cleanup failed") raise RuntimeError("Disposable Compose cleanup failed")
passcheck("disposable Compose projects and volumes removed") passcheck("disposable Compose projects, volumes and backend accounts removed")
@@ -1,15 +1,17 @@
set -euo pipefail set -euo pipefail
umask 077 umask 077
test "$(hostname -s | tr A-Z a-z)" = absdev-ci test "$(hostname -s | tr A-Z a-z)" = absdev-ci
stage=$(mktemp -d /var/tmp/absdev-managed-secrets.XXXXXX) stage=$(mktemp -d /var/tmp/absdev-secret-backend.XXXXXX)
trap 'rm -rf -- "$stage"' EXIT trap 'rm -rf -- "$stage"' EXIT
mkdir "$stage/source" "$stage/evidence" "$stage/tmp" mkdir "$stage/source" "$stage/evidence" "$stage/tmp"
tar -xm -f - -C "$stage/source" tar -xm -f - -C "$stage/source"
chmod 0711 "$stage"
chmod -R a+rX "$stage/source"
cd "$stage/source" cd "$stage/source"
export TMPDIR="$stage/tmp" export TMPDIR="$stage/tmp"
export DOCKER_CONFIG=/var/tmp/absdev-supported-containment.L6qYEi/docker-config export DOCKER_CONFIG=/var/tmp/absdev-supported-containment.L6qYEi/docker-config
out="$stage/evidence" out="$stage/evidence"
printf 'host=%s\nrevision=2628f01c8c999e8cf5913a3fbecc0f79809c62b7\n' "$(hostname -s)" > "$out/scope.txt" printf 'host=%s\nrevision=1c3df42a68d75b825993f9e5b9a774e5eeacff4b\n' "$(hostname -s)" > "$out/scope.txt"
docker compose version >> "$out/scope.txt" docker compose version >> "$out/scope.txt"
sha256sum "$DOCKER_CONFIG/cli-plugins/docker-compose" >> "$out/scope.txt" sha256sum "$DOCKER_CONFIG/cli-plugins/docker-compose" >> "$out/scope.txt"
python3 -B bin/absdev-deploy capabilities > "$out/capabilities-before.json" python3 -B bin/absdev-deploy capabilities > "$out/capabilities-before.json"
@@ -1,4 +1,4 @@
host=absdev-ci host=absdev-ci
revision=2628f01c8c999e8cf5913a3fbecc0f79809c62b7 revision=1c3df42a68d75b825993f9e5b9a774e5eeacff4b
Docker Compose version 2.40.3+ds1-0ubuntu1 Docker Compose version 2.40.3+ds1-0ubuntu1
93226cc2ea191353641921350ad87d96cb942e29a21c7c68c430adfd9954af34 /var/tmp/absdev-supported-containment.L6qYEi/docker-config/cli-plugins/docker-compose 93226cc2ea191353641921350ad87d96cb942e29a21c7c68c430adfd9954af34 /var/tmp/absdev-supported-containment.L6qYEi/docker-config/cli-plugins/docker-compose
@@ -1,8 +0,0 @@
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-after.json
934a04b5d6ec9aa62cb991fb2f57256c439bac4b2ac110cabd524ad456e59491 ./capabilities-before.json
75b3136a5ca40071b522553c1c9572a0b29d35fb8708ac093dc3932a6f800a00 ./checks.jsonl
589d8a9e39002db208fe79eb101e3f4db3820c4d2f77bb811a4a1dee7820fe85 ./framework-ci.txt
70c94c4965546bd2be1471e2b162dc0a4ba4720a5d697bfeda91ce89e5749956 ./scope.txt
d47bbe08dd457b7fd1914bce010407699ff3464396c3f2179f053b04f537b0e6 probe.py
30d0243cd41155febfc0fedd9598208c3c6289b98b6705a105ff26d0ab8d20bd run.sh
1afb4dc55478474598dba17657f96a69f68e4112cc46ea32199a51bd86bbaf12 remaining-gates.md
@@ -1,23 +0,0 @@
# Remaining ABSDEV production qualification
Eight workstreams remain for production, grouped from the readiness checklist
and reconciled with the latest fixture evidence. The count refers to
qualification workstreams and can span multiple changes or runs.
1. Connect and qualify production secret delivery and rotation. The supported
Compose mount passed disposable cross-site isolation and live file rotation.
Earlier MySQL and PostgreSQL runs passed server-side credential rotation.
2. Qualify production operator account and key provisioning and revocation of
authority for already-running processes.
3. Qualify trusted runtime adapters, Docker project and network isolation, and
database grants on the intended production topology.
4. Prove complete modular migration inventory and trusted rehearsal execution.
5. Qualify candidate source integrity and repository/revision authorisation.
6. Qualify reviewed reconciliation of partially applied migrations and other
interrupted operations.
7. Qualify trusted release retention inventory.
8. Pin CI runner and dependency inputs immutably.
Production execution remained disabled before and after the run. This test used
synthetic credential files and disposable containers. It exercised file access
and replacement through the supported Compose lifecycle.