Compare commits

..
Author SHA1 Message Date
ABSDEV Qualification c33f41bcee Record verified SQLite power-loss recovery evidence 2026-11-27 18:48:25 +00:00
Mark Gregory a6daf917ad Reject empty SQLite backup artifacts during verification
ABSDEV Framework CI / framework-ci (push) Successful in 25s
2026-11-27 18:01:12 +00:00
Mark Gregory 5ce5781b08 Qualify pinned database identity and restricted MySQL backup profile
ABSDEV Framework CI / framework-ci (push) Successful in 24s
2026-11-27 17:15:42 +00:00
16 changed files with 827 additions and 8 deletions
+20 -4
View File
@@ -1,6 +1,6 @@
"""MySQL database command construction."""
from core.database import DatabaseAdapter
from core.database import DatabaseAdapter, DatabaseError
class MySQLAdapter(DatabaseAdapter):
@@ -11,6 +11,21 @@ class MySQLAdapter(DatabaseAdapter):
"--defaults-file=/run/secrets/absdev-client.cnf"
)
def __init__(self, config, *, read_only_backup=False):
super().__init__(config)
if type(read_only_backup) is not bool:
raise DatabaseError("Invalid MySQL backup option")
self.read_only_backup = read_only_backup
def backup_inventory_command(self):
if not self.read_only_backup:
return None
# The trusted definer procedure is installed outside the protected database.
return self.query_command("CALL absdev_backup_control.check_inventory(DATABASE())")
def backup_grants_command(self):
return self.query_command("SELECT @@GLOBAL.partial_revokes; SHOW GRANTS FOR CURRENT_USER()")
def connection_arguments(self):
return [
@@ -68,9 +83,10 @@ class MySQLAdapter(DatabaseAdapter):
"--skip-lock-tables",
"--set-gtid-purged=OFF",
"--hex-blob",
"--triggers",
"--routines",
"--events",
*(
("--skip-triggers", "--skip-routines", "--skip-events")
if self.read_only_backup else ("--triggers", "--routines", "--events")
),
self.database["name"],
]
)
+6
View File
@@ -55,6 +55,12 @@ class PostgreSQLAdapter(DatabaseAdapter):
"SELECT current_database(), current_user"
)
def live_identity_command(self):
return self.query_command(
"SELECT current_database(), current_user, system_identifier "
"FROM pg_catalog.pg_control_system()"
)
def backup_command(self):
return (
+53 -2
View File
@@ -17,6 +17,8 @@ import uuid
from datetime import datetime, timezone
from pathlib import Path
from core.database_identity import DatabaseIdentityProbe
class BackupError(RuntimeError):
"""Invalid or unsuccessful backup operation."""
@@ -154,11 +156,26 @@ def flush_file(handle):
class BackupEngine:
def __init__(self, adapter, directory, runner):
def __init__(self, adapter, directory, runner, *, live_identity=None):
self.adapter = adapter
self.root = Path(directory).absolute()
self.runner = runner
self.live_identity = live_identity
inventory = getattr(adapter, "backup_inventory_command", None)
self.inventory_command = inventory() if inventory is not None else None
require(
live_identity is None or (
isinstance(live_identity, DatabaseIdentityProbe)
and live_identity.adapter is adapter
and live_identity.runner is runner
),
"Live identity probe must use the backup adapter and runner",
)
require(
self.inventory_command is None or live_identity is not None,
"Read-only MySQL backup requires a pinned live identity",
)
require(
callable(runner),
@@ -177,8 +194,34 @@ class BackupEngine:
else "database.dump"
)
def check_inventory(self):
if self.inventory_command is None:
return
output = io.BytesIO()
self.runner(self.adapter.backup_grants_command(), output)
database, account, _server = self.live_identity.expected
user, host = account.split("@", 1)
principal = f"`{user}`@`{host}`"
expected = {
f"GRANT USAGE ON *.* TO {principal}",
f"GRANT SELECT, SHOW VIEW ON `{database}`.* TO {principal}",
"GRANT EXECUTE ON PROCEDURE `absdev_backup_control`.`check_inventory`"
f" TO {principal}",
}
lines = output.getvalue().decode("utf-8").splitlines()
require(lines[:1] == ["1"] and len(lines[1:]) == len(expected) and set(lines[1:]) == expected,
"Read-only MySQL backup account has unexpected grants")
output = io.BytesIO()
self.runner(self.inventory_command, output)
require(
output.getvalue() in (b"0\t0\t0\t0", b"0\t0\t0\t0\n"),
"Read-only MySQL backup cannot certify full object coverage",
)
def identity(self):
if self.live_identity is not None:
return self.live_identity.observe()
output = io.BytesIO()
self.runner(
@@ -210,7 +253,7 @@ class BackupEngine:
parts = raw.split(separator)
require(
len(parts) == (3 if driver == "mysql" else 2),
len(parts) in ((3,) if driver == "mysql" else (2, 3)),
"Unexpected database identity format",
)
@@ -240,6 +283,12 @@ class BackupEngine:
"Missing database server identity",
)
elif len(parts) == 3:
require(
re.fullmatch(r"[1-9][0-9]{0,19}", parts[2]) is not None,
"Invalid database cluster identifier",
)
return raw
def create(self):
@@ -252,6 +301,7 @@ class BackupEngine:
secure_directory(self.root)
identity_before = self.identity()
self.check_inventory()
stamp = datetime.now(timezone.utc).strftime(
"%Y%m%dT%H%M%S"
@@ -287,6 +337,7 @@ class BackupEngine:
require(size > 0, "Database backup is empty")
self.check_inventory()
identity_after = self.identity()
require(
+11 -2
View File
@@ -49,6 +49,12 @@ class DatabaseAdapter(ABC):
def identity_command(self):
pass
def live_identity_command(self):
return self.identity_command()
def backup_inventory_command(self):
return None
@abstractmethod
def backup_command(self):
pass
@@ -93,7 +99,7 @@ class DatabaseAdapter(ABC):
return target
def get_adapter(config):
def get_adapter(config, *, mysql_read_only_backup=False):
try:
@@ -111,10 +117,13 @@ def get_adapter(config):
from adapters.mysql.adapter import MySQLAdapter
return MySQLAdapter(validated)
return MySQLAdapter(validated, read_only_backup=mysql_read_only_backup)
if driver == "pgsql":
if mysql_read_only_backup:
raise DatabaseError("MySQL backup option used for PostgreSQL")
from adapters.postgresql.adapter import PostgreSQLAdapter
return PostgreSQLAdapter(validated)
+49
View File
@@ -0,0 +1,49 @@
"""Pinned live database identity for backup and runtime preflight."""
import io
import re
from core.database import DatabaseError
class DatabaseIdentityProbe:
"""Check a trusted server pin and the exact authenticated account."""
def __init__(self, adapter, runner, *, server_id, account=None):
self.adapter = adapter
self.runner = runner
database = adapter.database
self.driver = database["driver"]
self.database = database["name"]
username = database["username"]
if self.driver == "mysql":
valid_account = (
isinstance(account, str)
and account.startswith(username + "@")
and re.fullmatch(r"[A-Za-z0-9_.:%-]+", account[len(username) + 1:]) is not None
)
else:
account = username if account is None else account
valid_account = account == username
pattern = (r"[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}"
if self.driver == "mysql" else r"[1-9][0-9]{0,19}")
if (not callable(runner) or not valid_account or not isinstance(server_id, str)
or re.fullmatch(pattern, server_id) is None):
raise DatabaseError("Invalid pinned database identity")
self.expected = (self.database, account, server_id)
def observe(self):
output = io.BytesIO()
self.runner(self.adapter.live_identity_command(), output)
try:
row = output.getvalue().decode("utf-8").removesuffix("\n").removesuffix("\r")
except UnicodeError as error:
raise DatabaseError("Invalid live database identity output") from error
separator = "\t" if self.driver == "mysql" else "|"
if tuple(row.split(separator)) != self.expected:
raise DatabaseError("Live database identity differs from the configured pin")
return row
def __call__(self):
self.observe()
return True
+2
View File
@@ -84,6 +84,8 @@ class SandboxDatabase:
if db.execute("PRAGMA integrity_check").fetchall() != [("ok",)]:
raise DatabaseIdentityError("Backup integrity check failed")
digest, size = checksum(path)
if size == 0:
raise DatabaseIdentityError("SQLite backup is empty")
result = {
"backup_id": identifier, "driver": "sqlite", "database": "acceptance",
"username": "local_fixture", "container": "local_fixture",
+39
View File
@@ -0,0 +1,39 @@
# Pinned database identity and read-only MySQL backups
Supply a trusted server UUID (MySQL) or system identifier (PostgreSQL) to
`DatabaseIdentityProbe`. MySQL also requires the exact authenticated
`user@host` grant account. Obtain the pin and account from a trusted
provisioning inventory. The account's normal DNS address alone is insufficient.
PostgreSQL requires explicit execute access to `pg_catalog.pg_control_system()`
in the target database. The probe reads the configured database, authenticated
account and server identifier in one query. Use the probe as the runtime check
for inspection or deployment coordination. For backups, bind the probe to
`BackupEngine(..., live_identity=probe)` using the same adapter and runner.
The engine checks the pin before and after the dump. Existing backup manifests
can still be verified, including older PostgreSQL manifests without a server ID.
For supported MySQL schemas, opt in through
`get_adapter(config, mysql_read_only_backup=True)`. The backup account needs
only SELECT and SHOW VIEW on the site schema and EXECUTE on
`absdev_backup_control.check_inventory`. The framework validates these exact
direct grants, requires MySQL `partial_revokes=ON` for literal schema grants, and checks the schema inventory before and after the dump.
Extra grants, unverifiable inventory and unsupported schema objects block
publication. Keep schema-changing operations excluded throughout the dump.
The pre- and post-checks do not provide a database-wide DDL lock.
The DBA-owned control procedure must be outside the application database. Use
a locked definer with authority to see the target schema's inventory, constrain
it to approved callers and schemas, and return exactly one row with four
integer counts in this order:
1. Triggers
2. Stored routines
3. Events
4. Non-InnoDB base tables
All four counts must be zero. The read-only profile covers InnoDB tables and
views. A site with triggers, routines or events requires separately qualified
backup and recovery coverage for those objects. Existing full-dump callers
retain their current behavior.
These APIs do not enable a production command or change the production gates.
+16
View File
@@ -0,0 +1,16 @@
# SQLite backup verification and VM power-loss recovery
The ABSDEV-CI regression passed 882 tests for commit
`a6daf917ad2900a265af83c67e2c831668b22226`. All five hard-stop scenarios
passed on an isolated disposable VM.
After a cut during backup, the zero-byte artifact survived reboot and was
rejected with `SQLite backup is empty`. Release 1 stayed active, and the
transaction did not record a verified backup. Activation and journal write
interruptions recovered valid state, and rollback required explicit confirmation.
Production readiness and production execution stayed disabled. This evidence
covers abrupt stops of the virtual guest while the physical host stayed powered.
The full archive is retained privately on ABSDEV-CI. These files contain the
guest markers, selected hypervisor events, regression output and summary.
Verify the public evidence with `sha256sum -c SHA256SUMS`.
+5
View File
@@ -0,0 +1,5 @@
The host used libvirt to hard-stop only the recorded networkless disposable
VM UUID, then restarted that same VM on its persistent overlay. No graceful
shutdown occurred at an interruption boundary. The host and physical disk
stayed powered. Framework backup, release-link, transaction and reconciliation
code ran against SQLite and synthetic release and service fixtures.
+6
View File
@@ -0,0 +1,6 @@
1158e6617272e9c5ab696e187528e4a691839b276f2eceee941f87bc1570814b README.md
0c4cced1e290f030d13c83e750fd2375d8bf66688e99f69e04fdcac1193260ce SCOPE.txt
199ef783b24b15afac25f48f70f39f138ada12c556127855831bc1c27e74c9aa framework-regression.txt
296977fa6d6db7afc48445fcfcf915a5ce04b7cdad16e0bb4c075450a8b2f88a guest-markers.json
22448500de8f1290aa6f56adb9c9a932a665f7e06c9ad7112475251d357466c3 hypervisor-events.txt
4f5a2570d625cb0a2430f1ebc52fbc8a29dd2861127bb65a5ac4ac3539caca99 summary.json
@@ -0,0 +1,108 @@
=== ABSDEV FRAMEWORK CI ===
Python 3.14.4
=== PYTHON SYNTAX VALIDATION ===
PASS: 84 Python sources compiled
=== COMPLETE UNIT REGRESSION SUITE ===
..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 882 tests in 22.905s
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
========================================
@@ -0,0 +1,305 @@
{
"CUT": [
{
"boot_id": "bdbeb8b7-df8a-437a-a4ea-41c839aafa97",
"boundary": "SQLite copy after first page",
"case": "backup-mid-copy",
"current": "1",
"journal": "PREPARED",
"partial_bytes": 0,
"remaining_pages": 205,
"total_pages": 206
},
{
"boot_id": "425bac53-6dae-4015-8c29-49ac5ca4851e",
"boundary": "current symlink renamed before activation directory fsync",
"case": "activation-before-dir-sync",
"current": "2",
"journal": "ACTIVATING"
},
{
"boot_id": "ce2505b7-457d-44af-8471-53ab49bb7384",
"boundary": "activation directory fsynced before ACTIVATED journal",
"case": "activation-after-dir-sync",
"current": "2",
"journal": "ACTIVATING"
},
{
"attempted": "ACTIVATING",
"boot_id": "af749d61-98fd-4154-b23b-b7a79bef60b8",
"boundary": "journal temp file fsynced before atomic replacement",
"case": "journal-before-replace",
"current": "1",
"journal": "QUIESCED"
},
{
"attempted": "ACTIVATED",
"boot_id": "e8e0abce-a96e-431b-9b46-36341cd9808a",
"boundary": "journal renamed before directory fsync",
"case": "journal-before-dir-sync",
"current": "2",
"journal": "ACTIVATED"
}
],
"RECOVERED": [
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "1",
"backup_sha256": null,
"backup_verified": false,
"boot_id": "425bac53-6dae-4015-8c29-49ac5ca4851e",
"case": "backup-mid-copy",
"database_restored": false,
"explicit_rollback": false,
"findings": [
{
"bytes": 0,
"reason": "SQLite backup is empty",
"type": "zero_byte_backup_rejected"
}
],
"journal_phase_after_boot": "PREPARED",
"previous_boot_id": "bdbeb8b7-df8a-437a-a4ea-41c839aafa97",
"result": "PASS",
"review_status": "PREVIOUS_ACTIVE_REVIEW_REQUIRED"
},
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "1",
"backup_sha256": "b56b4e3aaa6e6d0b486f320d45e6804470fdaf210b5a449041010e579ddb7617",
"backup_verified": true,
"boot_id": "ce2505b7-457d-44af-8471-53ab49bb7384",
"case": "activation-before-dir-sync",
"database_restored": false,
"explicit_rollback": false,
"findings": [],
"journal_phase_after_boot": "ACTIVATING",
"previous_boot_id": "425bac53-6dae-4015-8c29-49ac5ca4851e",
"result": "PASS",
"review_status": "PREVIOUS_ACTIVE_REVIEW_REQUIRED"
},
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "2",
"backup_sha256": "b56b4e3aaa6e6d0b486f320d45e6804470fdaf210b5a449041010e579ddb7617",
"backup_verified": true,
"boot_id": "af749d61-98fd-4154-b23b-b7a79bef60b8",
"case": "activation-after-dir-sync",
"database_restored": false,
"explicit_rollback": true,
"findings": [],
"journal_phase_after_boot": "ACTIVATING",
"previous_boot_id": "ce2505b7-457d-44af-8471-53ab49bb7384",
"result": "PASS",
"review_status": "ROLLBACK_REVIEW_READY"
},
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "1",
"backup_sha256": "b56b4e3aaa6e6d0b486f320d45e6804470fdaf210b5a449041010e579ddb7617",
"backup_verified": true,
"boot_id": "e8e0abce-a96e-431b-9b46-36341cd9808a",
"case": "journal-before-replace",
"database_restored": false,
"explicit_rollback": false,
"findings": [],
"journal_phase_after_boot": "QUIESCED",
"previous_boot_id": "af749d61-98fd-4154-b23b-b7a79bef60b8",
"result": "PASS",
"review_status": "PREVIOUS_ACTIVE_REVIEW_REQUIRED"
},
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "2",
"backup_sha256": "b56b4e3aaa6e6d0b486f320d45e6804470fdaf210b5a449041010e579ddb7617",
"backup_verified": true,
"boot_id": "7ff1139f-7e9d-428c-b268-49d912aa0026",
"case": "journal-before-dir-sync",
"database_restored": false,
"explicit_rollback": true,
"findings": [],
"journal_phase_after_boot": "ACTIVATING",
"previous_boot_id": "e8e0abce-a96e-431b-9b46-36341cd9808a",
"result": "PASS",
"review_status": "ROLLBACK_REVIEW_READY"
}
],
"CAPABILITIES": [
{
"boot_id": "bdbeb8b7-df8a-437a-a4ea-41c839aafa97",
"report": {
"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
},
"revision": "a6daf917ad2900a265af83c67e2c831668b22226",
"when": "boot"
},
{
"boot_id": "425bac53-6dae-4015-8c29-49ac5ca4851e",
"report": {
"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
},
"revision": "a6daf917ad2900a265af83c67e2c831668b22226",
"when": "boot"
},
{
"boot_id": "ce2505b7-457d-44af-8471-53ab49bb7384",
"report": {
"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
},
"revision": "a6daf917ad2900a265af83c67e2c831668b22226",
"when": "boot"
},
{
"boot_id": "af749d61-98fd-4154-b23b-b7a79bef60b8",
"report": {
"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
},
"revision": "a6daf917ad2900a265af83c67e2c831668b22226",
"when": "boot"
},
{
"boot_id": "e8e0abce-a96e-431b-9b46-36341cd9808a",
"report": {
"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
},
"revision": "a6daf917ad2900a265af83c67e2c831668b22226",
"when": "boot"
},
{
"boot_id": "7ff1139f-7e9d-428c-b268-49d912aa0026",
"report": {
"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
},
"revision": "a6daf917ad2900a265af83c67e2c831668b22226",
"when": "boot"
},
{
"boot_id": "7ff1139f-7e9d-428c-b268-49d912aa0026",
"report": {
"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
},
"revision": "a6daf917ad2900a265af83c67e2c831668b22226",
"when": "after"
}
],
"DONE": [
{
"boot_id": "7ff1139f-7e9d-428c-b268-49d912aa0026",
"cases": 5,
"revision": "a6daf917ad2900a265af83c67e2c831668b22226"
}
],
"FAILURE": []
}
@@ -0,0 +1,10 @@
2026-11-27T18:05:20Z Hard power cut confirmed at backup-mid-copy
2026-11-27T18:05:38Z Recovery evidence received after restart for backup-mid-copy
2026-11-27T18:05:39Z Hard power cut confirmed at activation-before-dir-sync
2026-11-27T18:05:55Z Recovery evidence received after restart for activation-before-dir-sync
2026-11-27T18:05:56Z Hard power cut confirmed at activation-after-dir-sync
2026-11-27T18:06:13Z Recovery evidence received after restart for activation-after-dir-sync
2026-11-27T18:06:14Z Hard power cut confirmed at journal-before-replace
2026-11-27T18:06:33Z Recovery evidence received after restart for journal-before-replace
2026-11-27T18:06:34Z Hard power cut confirmed at journal-before-dir-sync
2026-11-27T18:06:51Z Recovery evidence received after restart for journal-before-dir-sync
+95
View File
@@ -0,0 +1,95 @@
{
"framework_revision": "a6daf917ad2900a265af83c67e2c831668b22226",
"cloud_image_sha256": "04e8f2461a16a44e78a370284471f29616cdd9baf1893df25807b71f985b6c94",
"framework_archive_sha256": "97c4bc961d7f78f57dfe9b6da025e29dd90c13737a68857f9281ab24023b0a93",
"hard_power_cuts": 5,
"distinct_boot_ids": 6,
"production_execution_enabled": false,
"production_ready": false,
"passed": 5,
"gaps": 0,
"scope": "Abrupt stops of an isolated QEMU/KVM virtual machine; SQLite fixture and synthetic release/service adapters.",
"cases": [
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "1",
"backup_sha256": null,
"backup_verified": false,
"boot_id": "425bac53-6dae-4015-8c29-49ac5ca4851e",
"case": "backup-mid-copy",
"database_restored": false,
"explicit_rollback": false,
"findings": [
{
"bytes": 0,
"reason": "SQLite backup is empty",
"type": "zero_byte_backup_rejected"
}
],
"journal_phase_after_boot": "PREPARED",
"previous_boot_id": "bdbeb8b7-df8a-437a-a4ea-41c839aafa97",
"result": "PASS",
"review_status": "PREVIOUS_ACTIVE_REVIEW_REQUIRED"
},
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "1",
"backup_sha256": "b56b4e3aaa6e6d0b486f320d45e6804470fdaf210b5a449041010e579ddb7617",
"backup_verified": true,
"boot_id": "ce2505b7-457d-44af-8471-53ab49bb7384",
"case": "activation-before-dir-sync",
"database_restored": false,
"explicit_rollback": false,
"findings": [],
"journal_phase_after_boot": "ACTIVATING",
"previous_boot_id": "425bac53-6dae-4015-8c29-49ac5ca4851e",
"result": "PASS",
"review_status": "PREVIOUS_ACTIVE_REVIEW_REQUIRED"
},
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "2",
"backup_sha256": "b56b4e3aaa6e6d0b486f320d45e6804470fdaf210b5a449041010e579ddb7617",
"backup_verified": true,
"boot_id": "af749d61-98fd-4154-b23b-b7a79bef60b8",
"case": "activation-after-dir-sync",
"database_restored": false,
"explicit_rollback": true,
"findings": [],
"journal_phase_after_boot": "ACTIVATING",
"previous_boot_id": "ce2505b7-457d-44af-8471-53ab49bb7384",
"result": "PASS",
"review_status": "ROLLBACK_REVIEW_READY"
},
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "1",
"backup_sha256": "b56b4e3aaa6e6d0b486f320d45e6804470fdaf210b5a449041010e579ddb7617",
"backup_verified": true,
"boot_id": "e8e0abce-a96e-431b-9b46-36341cd9808a",
"case": "journal-before-replace",
"database_restored": false,
"explicit_rollback": false,
"findings": [],
"journal_phase_after_boot": "QUIESCED",
"previous_boot_id": "af749d61-98fd-4154-b23b-b7a79bef60b8",
"result": "PASS",
"review_status": "PREVIOUS_ACTIVE_REVIEW_REQUIRED"
},
{
"active_release_after_recovery": "1",
"active_release_before_recovery": "2",
"backup_sha256": "b56b4e3aaa6e6d0b486f320d45e6804470fdaf210b5a449041010e579ddb7617",
"backup_verified": true,
"boot_id": "7ff1139f-7e9d-428c-b268-49d912aa0026",
"case": "journal-before-dir-sync",
"database_restored": false,
"explicit_rollback": true,
"findings": [],
"journal_phase_after_boot": "ACTIVATING",
"previous_boot_id": "e8e0abce-a96e-431b-9b46-36341cd9808a",
"result": "PASS",
"review_status": "ROLLBACK_REVIEW_READY"
}
]
}
+89
View File
@@ -0,0 +1,89 @@
import io
import json
import tempfile
import unittest
from pathlib import Path
from core.backup import BackupEngine, BackupError
from core.database import DatabaseError, get_adapter
from core.database_identity import DatabaseIdentityProbe
MYSQL_ID = "11111111-2222-3333-4444-555555555555"
ACCOUNT = "[email protected]"
def adapter(driver, **kwargs):
site = json.loads(Path("config/site.example.json").read_text())
site["database"].update(driver=driver, port=3306 if driver == "mysql" else 5432)
return get_adapter(site, **kwargs)
class IdentityTests(unittest.TestCase):
def test_strict_live_identity(self):
for driver, pin, account, separator, probe_account in (
("mysql", MYSQL_ID, ACCOUNT, "\t", ACCOUNT),
("pgsql", "112233445566778899", "example_app", "|", None),
):
with self.subTest(driver=driver):
db = adapter(driver)
expected = separator.join(("example_db", account, pin))
result = io.BytesIO()
def run(command, output):
self.assertEqual(command, db.live_identity_command())
output.write(result.getvalue())
probe = DatabaseIdentityProbe(db, run, server_id=pin, account=probe_account)
result.write((expected + "\n").encode())
self.assertTrue(probe())
for candidate in (expected.replace("example_db", "other_db"),
expected.replace(account, "other_user"), expected[:-1],
expected + "\n" + expected):
result = io.BytesIO(candidate.encode())
with self.assertRaises(DatabaseError):
probe()
def test_read_only_backup_fails_closed(self):
db = adapter("mysql", mysql_read_only_backup=True)
identity = f"example_db\t{ACCOUNT}\t{MYSQL_ID}\n".encode()
principal = "`example_app`@`127.0.0.1`"
grants = (
"1\n"
f"GRANT USAGE ON *.* TO {principal}\n"
f"GRANT SELECT, SHOW VIEW ON `example_db`.* TO {principal}\n"
f"GRANT EXECUTE ON PROCEDURE `absdev_backup_control`.`check_inventory` TO {principal}\n"
).encode()
inventory = [b"0\t0\t0\t0\n"]
commands = []
def run(command, output):
commands.append(command)
if command == db.live_identity_command():
output.write(identity)
elif command == db.backup_grants_command():
output.write(grants)
elif command == db.backup_inventory_command():
output.write(inventory.pop(0))
else:
self.assertEqual(command, db.backup_command())
output.write(b"backup data")
probe = DatabaseIdentityProbe(db, run, server_id=MYSQL_ID, account=ACCOUNT)
with tempfile.TemporaryDirectory() as directory:
root = Path(directory).resolve()
with self.assertRaises(BackupError):
BackupEngine(db, root, run)
engine = BackupEngine(db, root, run, live_identity=probe)
inventory[:] = [b"1\t0\t0\t0\n"]
with self.assertRaises(BackupError):
engine.create()
self.assertNotIn(db.backup_command(), commands)
self.assertEqual(list(root.iterdir()), [])
inventory[:] = [b"0\t0\t0\t0\n", b"0\t1\t0\t0\n"]
with self.assertRaises(BackupError):
engine.create()
self.assertEqual(list(root.iterdir()), [])
inventory[:] = [b"0\t0\t0\t0\n", b"0\t0\t0\t0\n"]
self.assertEqual(engine.verify(engine.create())["identity"], identity.decode().strip())
grants += f"GRANT INSERT ON `example_db`.* TO {principal}\n".encode()
commands.clear()
with self.assertRaises(BackupError):
engine.create()
self.assertNotIn(db.backup_command(), commands)
+13
View File
@@ -1,6 +1,7 @@
import sqlite3
import tempfile
import unittest
import uuid
from contextlib import closing
from pathlib import Path
@@ -26,3 +27,15 @@ class DatabaseTests(unittest.TestCase):
db.path.touch(mode=0o600)
with self.assertRaises(DatabaseIdentityError):
db.check()
def test_rejects_empty_backup_left_after_interruption(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory).resolve()
db = SandboxDatabase(root)
identifier = uuid.uuid4().hex
backup = root / identifier
backup.mkdir(mode=0o700)
path = backup / "database.sqlite"
path.touch(mode=0o600)
with self.assertRaisesRegex(DatabaseIdentityError, "SQLite backup is empty"):
db.verify(identifier)