For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Build an enterprise-edge engineering baseline that executes approved data operations inside the enterprise boundary and sends only policy-approved, minimized events to the control plane.
Architecture: Reuse the existing standalone Runner for governed execution and its single-use task-token and durable-ledger semantics. Add a focused app/core/edge_gateway/ boundary for contracts, egress/retention policy, an offline SQLite queue, control-plane PostgreSQL state, and gateway lifecycle services; expose management and machine pull/event endpoints through the existing data-source blueprint. The application records certificate fingerprints and rotation state, while private keys remain at the edge and real mTLS termination, enterprise network topology, and security/legal sign-off remain external UAT gates.
Tech Stack: Python 3.11, Flask, SQLAlchemy/PostgreSQL, SQLite WAL, PyJWT/cryptography, Alembic, Docker Compose, pytest, OpenAPI 3.1.
ENGINEERING_COMPLETE_ENTERPRISE_EDGE_UAT_BLOCKED.enterprise_source_1, enterprise_source_2, network, and security_legal remain TBD_EXTERNAL until enterprise evidence is supplied.collect, profile, quality, lineage, and controlled_query; the control plane may receive only desensitized_metadata, statistics, lineage, evidence, and bounded health/diagnostic summaries.canvas/ are outside this work package.Files:
app/core/edge_gateway/__init__.pyapp/core/edge_gateway/contracts.pyapp/core/edge_gateway/policy.pyapp/core/edge_gateway/queue.pydeployment/app/core/edge_gateway/Test: tests/test_phase3_wp04_edge_gateway.py
[x] Step 1: Write failing contract and policy tests
def test_raw_and_recent_detail_never_cross_the_control_plane_boundary():
policy = EdgeEgressPolicy(allowed_control_hosts={"control.example.com"})
for classification in ("raw", "recent_detail", "restricted"):
with pytest.raises(EdgePolicyError):
policy.approve_event({"classification": classification, "payload": {"rows": [{"secret": "x"}]}})
def test_only_supported_task_types_and_bounded_approved_results_are_valid():
task = EdgeTaskContract.from_mapping(APPROVED_TASK)
assert task.task_type == "profile"
with pytest.raises(EdgeContractError):
EdgeTaskContract.from_mapping({**APPROVED_TASK, "task_type": "shell"})
Run: PYTHONPATH=. .venv/bin/pytest -q tests/test_phase3_wp04_edge_gateway.py
Expected: collection/import failure because the edge gateway package does not exist.
Implement canonical SHA-256 digests, stable event IDs, strict enums, recursive sensitive-key rejection, per-channel byte limits, HTTPS host allowlisting, high-sensitivity default deny, and explicit retention classes:
EDGE_ONLY = {"raw", "recent_detail", "restricted"}
CONTROL_PLANE_ALLOWED = {
"desensitized_metadata",
"statistics",
"lineage",
"evidence",
"health_summary",
"diagnostic_summary",
}
RETENTION_DAYS = {"raw": 0, "recent_detail": 365, "metadata": 1095, "evidence": 2190}
SqliteEdgeQueue with WAL and idempotent event storageThe queue must atomically enqueue/claim/complete/cancel tasks, persist outbound events before delivery, retry with bounded exponential backoff, reject duplicate IDs with different digests, and return an existing terminal acknowledgement for exact replays.
Run: PYTHONPATH=. .venv/bin/pytest -q tests/test_phase3_wp04_edge_gateway.py -k 'contract or policy or queue'
Expected: all selected tests pass, including two independent queue connections claiming one task only.
Files:
app/core/edge_gateway/repository.pyapp/core/edge_gateway/service.pyapp/api/data_source/edge_routes.pyapp/api/data_source/__init__.pyapp/core/system/permissions.pyapp/models/edge_gateway.pyapp/models/__init__.pymigrations/versions/20260809_477_edge_gateway_control_plane.pymigrations/versions/20260809_478_edge_gateway_security_cleanup.pymigrations/versions/20260809_479_edge_gateway_signed_authority.pydeployment/app/ and deployment/migrations/tests/integration/test_phase3_wp04_edge_gateway_postgres.pyTest: tests/test_permission_matrix.py
[x] Step 1: Write failing PostgreSQL tests for registration and event idempotency
def test_gateway_registration_requires_one_time_enrollment_and_exact_certificate_binding(pg_session):
enrollment = service.issue_enrollment(APPROVED_GATEWAY)
gateway = service.register(enrollment.secret, certificate_sha256=CERT_SHA256)
assert gateway["status"] == "active"
with pytest.raises(EdgeAuthenticationError):
service.register(enrollment.secret, certificate_sha256=CERT_SHA256)
def test_same_event_id_with_different_digest_is_rejected(pg_service):
pg_service.accept_event(GATEWAY_ID, APPROVED_EVENT)
with pytest.raises(EdgeConflictError):
pg_service.accept_event(GATEWAY_ID, {**APPROVED_EVENT, "payload": {"count": 2}})
Run: TEST_DATABASE_URL=postgresql://dataops:dataops-test-password@127.0.0.1:15432/dataops PYTHONPATH=. .venv/bin/pytest -q tests/integration/test_phase3_wp04_edge_gateway_postgres.py
Expected: failure because migration 477, repository, and service are absent.
Create governed tables for gateways, one-time enrollments, credentials/certificate generations, tasks, outbound events, releases, and audit events. Add exact unique keys, digest conflict checks, status constraints, lease/cancel fields, and database triggers that prevent active gateways without an active credential and certificate fingerprint.
Support enrollment, register, heartbeat, credential/certificate rotate and revoke, task issue/pull/cancel, event accept/ack, reconnect reconciliation, safe diagnostic summary, release offer/ack/rollback, and stable audit evidence. Authenticate the complete gateway/environment/network-zone/certificate-generation binding before consuming one-time credentials.
Human management routes require edge-gateways:read|operate|manage; machine register, heartbeat, pull, event, and release acknowledgement routes are public only at the platform bearer layer and must require the dedicated one-time enrollment or edge credential plus exact certificate fingerprint.
Run the PostgreSQL file, permission matrix nodes, alembic current, and recursive parity checks. Actual expected head: 20260809_479.
Files:
app/edge_gateway/__init__.pyapp/edge_gateway/agent.pyapp/edge_gateway/transport.pyapp/edge_gateway/bootstrap.pyapp/runner/bootstrap.pyapp/runner/api.pydeployment/app/tests/security/test_phase3_wp04_data_boundary.pyTest: tests/integration/test_phase3_wp04_edge_agent.py
[x] Step 1: Write failing offline/reconnect and malicious-task tests
def test_offline_execution_reconnect_delivers_each_approved_event_once(tmp_path):
agent = build_agent(tmp_path, transport=FlakyPullTransport(disconnect_after=1))
agent.run_once()
agent.run_once()
assert agent.pending_events == 1
agent.transport.reconnect()
agent.flush_events()
agent.flush_events()
assert agent.transport.accepted_event_ids == {STABLE_EVENT_ID}
def test_malicious_task_cannot_request_raw_export_or_unapproved_host(agent):
with pytest.raises(EdgePolicyError):
agent.accept_task(MALICIOUS_RAW_EXPORT_TASK)
Run: PYTHONPATH=. .venv/bin/pytest -q tests/security/test_phase3_wp04_data_boundary.py tests/integration/test_phase3_wp04_edge_agent.py
The edge initiates all control traffic, verifies signed task contracts, stages tasks before execution, dispatches only allowlisted Runner node types, and converts results to approved summaries before enqueueing outbound events. Raw artifacts and recent details remain referenced by local digest only.
Use bounded backoff with jitter, exact event replay, task cancellation probes, safe diagnostics without log bodies, signed release manifest verification, candidate activation, health confirmation, and rollback to the previous locally verified release.
Expected tests include malicious task type, raw payload, secret-like fields, oversized summary, event replay with changed digest, revoked certificate, expired credential, unapproved host/proxy, disconnected control plane, and failed candidate rollback.
Files:
scripts/edge_gateway_admin.pyapp/edge_gateway/runtime.pyapp/edge_gateway/__main__.pyapp/edge_gateway/healthcheck.pydeploy/edge/Dockerfile.edgedeploy/edge/docker-compose.edge.ymldeploy/edge/edge.env.exampledeploy/edge/edge.config.example.jsondeploy/edge/edge.config.schema.jsondeploy/edge/README.mddocs/runbooks/EDGE_GATEWAY_OPERATIONS.mddocs/phase3/P3_WP04_EDGE_GATEWAY.mddocs/validation/P3_WP04_EDGE_GATEWAY_EVIDENCE.mddocs/validation/P3_WP04_FAILURE_INJECTION.jsonscripts/generate_openapi.pydocs/architecture/OPENAPI.yamldocs/DATAOPS_PHASE3_6_MONTH_DEVELOPMENT_PLAN_20260802.mddocs/phase3/P3_WP00_REQUIREMENTS.jsontests/test_phase3_wp04_delivery_contract.pyTest: tests/integration/test_phase3_wp04_edge_runtime.py
[x] Step 1: Write failing delivery-contract tests
Assert that the Compose topology is pull-only, mounts key/certificate paths read-only, uses a non-root/read-only container, defines no inbound control-plane port, requires explicit host/proxy allowlists, and exposes health without sensitive fields. Assert that the admin tool creates a private key and CSR locally with restrictive permissions and never prints or uploads private-key material.
Run: PYTHONPATH=. .venv/bin/pytest -q tests/test_phase3_wp04_delivery_contract.py
Provide init, csr, register-manifest, rotate, revoke-status, release-check, rollback, and read-only status operations. Require a dedicated absolute root, O_NOFOLLOW/fcntl mutation locking, same-file-descriptor artifact verification/copy, atomic files, full Ed25519 release authority, bounded backups, and operator confirmation for rollback; never embed credentials in Compose or documentation. The Edge image runs the actual pull-only loop, verifies a fresh server CRL with CRL_CHECK_LEAF, publishes only a safe health file, degrades safely during disconnect, and exposes no inbound listener.
Document architecture, allowed data classes, default-deny decisions, retention/legal hold/delete receipts, queue v1-to-v2 copy migration, incident thresholds and diagnostics, database role order, client/server CRL updates, install/rotate/revoke/upgrade/rollback procedures, and external UAT inputs. Package the full OpenAPI, failure-injection ledger, edge runtime/config schema and full-file SHA-256 closure. Mark only locally verified engineering work complete.
Run only P3-WP04 unit, security, PostgreSQL integration, edge-agent, Runner directly affected tests, permission/OpenAPI contracts, Ruff, py_compile, JSON/YAML parsing, Compose config validation, migration head, app/deployment parity, git diff --check, and secret scan. Do not run the repository-wide regression suite.
Require specification PASS and quality/security approval. Then stage only P3-WP04 files, preserve unrelated untracked assets, and create one local commit without pushing or deploying.