From 793de5630621a00051e538a36b7d9cfa20061bf2 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Wed, 25 Nov 2026 16:09:37 +0000 Subject: [PATCH] Record web1 Production go-live and fix restrictive-umask release permissions --- Docs/Codex/Database.md | 6 +- Docs/Codex/Deployment.md | 10 +- .../activation-retry-timing.json | 5 + .../activation-successful-retry-timing.json | 5 + .../Phase2-20261125/activation-timing.json | 5 + .../configured-owner-entitlement.json | 15 ++ .../Phase2-20261125/final-preservation.json | 7 + .../final-ssh-verification.json | 5 + .../Evidence/Phase2-20261125/go-live.json | 12 + .../installer-permission-recovery.json | 11 + .../Phase2-20261125/live-account-status.json | 32 +++ .../Phase2-20261125/live-baseline.json | 7 + .../Phase2-20261125/operations-handover.json | 174 ++++++++++++++ .../Phase2-20261125/persistent-recovery.json | 65 ++++++ .../production-database-acceptance.json | 109 +++++++++ .../Phase2-20261125/public-acceptance.json | 71 ++++++ .../Phase2-20261125/restricted-access.json | 21 ++ .../sql-security-provisioning.json | 36 +++ Docs/Deployment/Phase2-20261125.md | 217 +++++++++++++----- Docs/Deployment/Production.md | 84 +++++-- Tools/Deployment/activate.py | 2 + .../provision/acceptance-permissions.py | 16 ++ Tools/Deployment/provision/acceptance.conf | 4 + .../provision/nginx-plotdirector.conf | 62 ++--- .../provision/plotdirector-maintenance.conf | 3 + Tools/Deployment/test_activation.py | 17 ++ 26 files changed, 894 insertions(+), 107 deletions(-) create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/activation-retry-timing.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/activation-successful-retry-timing.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/activation-timing.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/configured-owner-entitlement.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/final-preservation.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/final-ssh-verification.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/go-live.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/installer-permission-recovery.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/live-account-status.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/live-baseline.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/operations-handover.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/persistent-recovery.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/production-database-acceptance.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/public-acceptance.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/restricted-access.json create mode 100644 Docs/Deployment/Evidence/Phase2-20261125/sql-security-provisioning.json create mode 100644 Tools/Deployment/provision/acceptance-permissions.py create mode 100644 Tools/Deployment/provision/acceptance.conf create mode 100644 Tools/Deployment/provision/plotdirector-maintenance.conf diff --git a/Docs/Codex/Database.md b/Docs/Codex/Database.md index 3546b080..f368bbbf 100644 --- a/Docs/Codex/Database.md +++ b/Docs/Codex/Database.md @@ -17,7 +17,7 @@ Read this document only when the current task requires database inspection, SQL - `/sql/mssql` on the host maps to `/var/opt/mssql` in the container. - Host `sqlcmd` is not installed. - Container sqlcmd: `/opt/mssql-tools18/bin/sqlcmd`. -- Production migration target: `web1`, `85.190.124.132`, database `PlotLine`. Initial deployment is [blocked pending SQL administrative authentication](../Deployment/Phase2-20261125.md). Historical server `www`, `192.168.10.8`, is inactive and retained for recovery. Development authorisation does not authorise production changes. +- Current Production: `web1`, `85.190.124.132`, database `PlotLine` on `127.0.0.1,1433`; see [deployed state and Phase 2 handover](../Deployment/Phase2-20261125.md). Historical server `www`, `192.168.10.8`, is inactive and retained for recovery. Development authorisation does not authorise production changes. Never print, copy or commit connection strings, passwords, API keys, SMTP secrets, Stripe secrets or OpenAI keys. @@ -62,14 +62,14 @@ Scripts should be idempotent where practical: - guard table, column and index creation; - use `CREATE OR ALTER PROCEDURE`. -Migrations are manual SQL. Do not blindly replay the entire SQL directory, `Admin/`, or `Stripe_Price_IDs_Prod.sql`. +Migrations are reviewed SQL scripts executed through the manifest/history worker. Do not manually apply scripts to ledger-managed databases or blindly replay the SQL directory, `Admin/`, or `Stripe_Price_IDs_Prod.sql`. Before schema or data changes: 1. Verify the development database. 2. Back up development using a unique SQL Server backup filename. 3. Verify the backup command succeeded and the backup exists. -4. Apply only required scripts in dependency order. +4. Execute only the approved manifest through its deployment worker, in explicit dependency order. Apply scripts separately with `SET ANSI_NULLS ON` and `SET QUOTED_IDENTIFIER ON`. diff --git a/Docs/Codex/Deployment.md b/Docs/Codex/Deployment.md index fff02e3d..646012f1 100644 --- a/Docs/Codex/Deployment.md +++ b/Docs/Codex/Deployment.md @@ -11,6 +11,14 @@ pointed at Development by replacing credentials alone. Read this document only when deployment or detailed development-service operation is part of the task. +## Current Production + +Production is live on web1 (`85.190.124.132`) at https://plotdirector.com/. +Use the restricted manifest-driven helper, never the legacy www helper. See +[the operational standard](../Deployment/Production.md) and +[actual installation/acceptance and worker holds](../Deployment/Phase2-20261125.md). +www is an inactive recovery fallback. + ## Environment - Development host: Atlas. @@ -36,7 +44,7 @@ Confirm the intended commit: git status --short --branch git log -1 --oneline -If the change involves database migration, apply and verify required SQL before deploying dependent code. +If the change involves database migration, qualify an explicit manifest and let the worker back up, verify and apply it before activating dependent code; do not bypass migration history with manual SQL. Before stopping the service, confirm there is no active import, Story Intelligence run, synthesis or character enrichment work. Check queued and processing work as well as core imports. diff --git a/Docs/Deployment/Evidence/Phase2-20261125/activation-retry-timing.json b/Docs/Deployment/Evidence/Phase2-20261125/activation-retry-timing.json new file mode 100644 index 00000000..bd0ff648 --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/activation-retry-timing.json @@ -0,0 +1,5 @@ +{ + "started_utc": "2026-11-25T16:00:35.082553+00:00", + "finished_utc": "2026-11-25T16:00:45.274006+00:00", + "exit_code": 1 +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/activation-successful-retry-timing.json b/Docs/Deployment/Evidence/Phase2-20261125/activation-successful-retry-timing.json new file mode 100644 index 00000000..8b5ec8fa --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/activation-successful-retry-timing.json @@ -0,0 +1,5 @@ +{ + "started_utc": "2026-11-25T16:01:43.536259+00:00", + "finished_utc": "2026-11-25T16:02:06.014107+00:00", + "exit_code": 0 +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/activation-timing.json b/Docs/Deployment/Evidence/Phase2-20261125/activation-timing.json new file mode 100644 index 00000000..091daf0f --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/activation-timing.json @@ -0,0 +1,5 @@ +{ + "started_utc": "2026-11-25T15:58:10.956009+00:00", + "finished_utc": "2026-11-25T15:58:57.126096+00:00", + "exit_code": 1 +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/configured-owner-entitlement.json b/Docs/Deployment/Evidence/Phase2-20261125/configured-owner-entitlement.json new file mode 100644 index 00000000..2c38c26e --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/configured-owner-entitlement.json @@ -0,0 +1,15 @@ +{ + "configured_admin_accounts": [ + { + "EmailConfirmed": true, + "IsLocked": false, + "entitlement_active": true, + "MaxBooks": 10, + "subscription_row_active": true, + "IsTrial": false, + "StartDateUTC": "2026-06-08T15:42:14.3894585", + "StripeStatus": "active", + "CurrentPeriodEndUTC": "2026-12-08T18:18:47" + } + ] +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/final-preservation.json b/Docs/Deployment/Evidence/Phase2-20261125/final-preservation.json new file mode 100644 index 00000000..31e3102e --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/final-preservation.json @@ -0,0 +1,7 @@ +{ + "status": "passed", + "live_resulting_schema_sha256": "b17db2bbdc583cb7bd3c856fb4db5cf6fc470e87fbaee5dc1dbbe99b6878beb7", + "original_tables": 163, + "original_rows": 139554, + "all_original_fingerprints_match": true +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/final-ssh-verification.json b/Docs/Deployment/Evidence/Phase2-20261125/final-ssh-verification.json new file mode 100644 index 00000000..e50671d1 --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/final-ssh-verification.json @@ -0,0 +1,5 @@ +{ + "new_atlas_admin_ssh_rejected": true, + "permanent_deployment_validation_after_admin_key_removal": "passed", + "held_local_admin_ssh_sessions_closed": 1 +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/go-live.json b/Docs/Deployment/Evidence/Phase2-20261125/go-live.json new file mode 100644 index 00000000..58c834f6 --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/go-live.json @@ -0,0 +1,12 @@ +{ + "public_enabled_utc": "2026-11-25T16:03:21.935526+00:00", + "local_health": { + "healthy": true, + "version": "1.0.0", + "sourceCommit": "190c074d5202fdf8a94b3b7a70c94857f848aafd", + "database": "PlotLine", + "environment": "Production" + }, + "service_enabled": true, + "maintenance_removed": true +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/installer-permission-recovery.json b/Docs/Deployment/Evidence/Phase2-20261125/installer-permission-recovery.json new file mode 100644 index 00000000..83db04a8 --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/installer-permission-recovery.json @@ -0,0 +1,11 @@ +{ + "defect": "umask 077 masked intended directory 0750 to 0700", + "fix": "explicit chmod 0750 after release directory creation; regular files remain 0440", + "failed_attempt": "20261125T155815Z-7427734eba47", + "quarantine": "/srv/plotdirector/failed-attempts/20261125T155815Z-7427734eba47", + "prior_helper_backup": "/srv/backups/configuration/plotdirector-helper-before-umask-fix-20261125T155815Z-7427734eba47.py", + "installed_helper_sha256": "d49da1241f0350c0b5c93412740d99aadcafbead37c5fde85d0397a43977997e", + "migration_records_retained": 320, + "successful_activation_records_before_retry": 0, + "qualified_application_or_sql_changed": false +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/live-account-status.json b/Docs/Deployment/Evidence/Phase2-20261125/live-account-status.json new file mode 100644 index 00000000..ffc79a4e --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/live-account-status.json @@ -0,0 +1,32 @@ +{ + "email_queue": [ + { + "Status": "Sent", + "count": 16 + } + ], + "account_counts": [ + { + "total_accounts": 11, + "email_confirmed": 10, + "locked_accounts": 0 + } + ], + "entitlements": [ + { + "IsActive": false, + "MaxBooks": 2, + "owners": 7 + }, + { + "IsActive": true, + "MaxBooks": 2, + "owners": 1 + }, + { + "IsActive": true, + "MaxBooks": 10, + "owners": 1 + } + ] +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/live-baseline.json b/Docs/Deployment/Evidence/Phase2-20261125/live-baseline.json new file mode 100644 index 00000000..5d4ee1cf --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/live-baseline.json @@ -0,0 +1,7 @@ +{ + "status": "passed", + "live_starting_schema_sha256": "1eaa17d39bfdc2542743d6e911659141466f0bdf4efbeb62fb76b958ddd03c21", + "original_tables": 163, + "original_rows": 139554, + "all_original_fingerprints_match": true +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/operations-handover.json b/Docs/Deployment/Evidence/Phase2-20261125/operations-handover.json new file mode 100644 index 00000000..4ffcb890 --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/operations-handover.json @@ -0,0 +1,174 @@ +{ + "completed_utc": "2026-11-25T16:04:33.356842+00:00", + "catherine_original_configuration_and_certificate_unchanged": true, + "catherine_pid": 13134, + "sql_backup_timer": "active", + "certbot_timer": "active", + "original_data_protection_keys_verified": 2, + "current_key_file_count": 2, + "migration_timing": { + "executed": 110, + "summed_execution_milliseconds": 5909 + }, + "manifest_sha256": "58bac17161e1ea280617c15fba61ef26ac976417217fbb77accbb5ab4ababe13", + "production_trust_key_der_sha256": "72e7fd8e5530201397cbf41a736a8973053d4f22726cf03cdec5338bf9773e68", + "normal_worker_settings_recorded_not_enabled": { + "StoryIntelligence__WorkersEnabled": "true", + "Illustrations__GenerationWorkerEnabled": "true", + "WritingSolver__EnableIndexing": "true (qualified application default)", + "Geography__Enabled": "application default", + "EmailQueue": "Always registered; initial acceptance denies queue claims/reset; owner must authorise removal.", + "WritingActivityRetention": "Always registered; initial acceptance denies baseline discovery and pruning; owner must authorise removal." + }, + "temporary_admin_key_removed": true, + "other_admin_key_count_preserved": 2, + "admin_authorized_keys_recovery_copy": "/srv/backups/configuration/administrator-authorized-keys-before-plotdirector-removal-20261125T160433Z", + "sa_temporary_secret_removed": true, + "all_attempt_events": { + "20261125T160148Z-c2e69a3902f2.jsonl": [ + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "package_sha256": "0ec47c0c0e5ba17c0df34ce27105e183820947fd91bc466d276d305bf4cd10b9", + "phase": "validated", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:48Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "backup-start", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:50Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "path": "/srv/backups/sql/PlotLine-predeploy-20261125T160148Z-c2e69a3902f2.bak", + "phase": "backup-verified", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:53Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "migration-start", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:53Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "migration-complete", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:55Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "activation-start", + "previous_deployment": null, + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:02:00Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "health-passed", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:02:05Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "successful", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:02:05Z" + } + ], + "20261125T160039Z-4fd5821c9ee2.jsonl": [ + { + "deployment": "20261125T160039Z-4fd5821c9ee2", + "package_sha256": "0ec47c0c0e5ba17c0df34ce27105e183820947fd91bc466d276d305bf4cd10b9", + "phase": "validated", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:00:39Z" + }, + { + "deployment": "20261125T160039Z-4fd5821c9ee2", + "phase": "backup-start", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:00:41Z" + }, + { + "deployment": "20261125T160039Z-4fd5821c9ee2", + "path": "/srv/backups/sql/PlotLine-predeploy-20261125T160039Z-4fd5821c9ee2.bak", + "phase": "backup-verified", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:00:44Z" + }, + { + "error": "Service did not stop", + "phase": "failed", + "recovery": "Operator review required; no automatic database rollback.", + "service_stop_requested": true + } + ], + "20261125T155815Z-7427734eba47.jsonl": [ + { + "deployment": "20261125T155815Z-7427734eba47", + "package_sha256": "0ec47c0c0e5ba17c0df34ce27105e183820947fd91bc466d276d305bf4cd10b9", + "phase": "validated", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T15:58:15Z" + }, + { + "deployment": "20261125T155815Z-7427734eba47", + "phase": "backup-start", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T15:58:16Z" + }, + { + "deployment": "20261125T155815Z-7427734eba47", + "path": "/srv/backups/sql/PlotLine-predeploy-20261125T155815Z-7427734eba47.bak", + "phase": "backup-verified", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T15:58:20Z" + }, + { + "deployment": "20261125T155815Z-7427734eba47", + "phase": "migration-start", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T15:58:20Z" + }, + { + "deployment": "20261125T155815Z-7427734eba47", + "phase": "migration-complete", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T15:58:34Z" + }, + { + "deployment": "20261125T155815Z-7427734eba47", + "phase": "activation-start", + "previous_deployment": null, + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T15:58:35Z" + }, + { + "error": "Application HTTP health check failed", + "phase": "failed", + "recovery": "Operator review required; no automatic database rollback.", + "service_stop_requested": true + } + ], + "20261125T155759Z-ee159c8453ee.jsonl": [ + { + "deployment": "20261125T155759Z-ee159c8453ee", + "package_sha256": "0ec47c0c0e5ba17c0df34ce27105e183820947fd91bc466d276d305bf4cd10b9", + "phase": "validated", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T15:57:59Z" + }, + { + "deployment": "20261125T155759Z-ee159c8453ee", + "phase": "validation-only", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T15:58:01Z" + } + ] + }, + "runtime_release_directories_mode": "0750", + "runtime_release_files_owner": "root" +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/persistent-recovery.json b/Docs/Deployment/Evidence/Phase2-20261125/persistent-recovery.json new file mode 100644 index 00000000..eca22bf8 --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/persistent-recovery.json @@ -0,0 +1,65 @@ +{ + "uploads": 30, + "recovered_keys": 2, + "effective_configuration_names": [ + "Admin__AllowedEmails__0", + "AllowedHosts", + "ConnectionStrings__DefaultConnection", + "DataProtection__ApplicationName", + "DataProtection__KeysPath", + "EmailSettings__EnableSsl", + "EmailSettings__FromAddress", + "EmailSettings__FromName", + "EmailSettings__Password", + "EmailSettings__Port", + "EmailSettings__SmtpServer", + "EmailSettings__Username", + "Features__ParagraphManuscripts", + "Geography__Enabled", + "Illustrations__GenerationWorkerEnabled", + "Logging__LogLevel__Default", + "Logging__LogLevel__Microsoft.AspNetCore", + "Logging__LogLevel__PlotLine.Services.EmailQueueWorker", + "Logging__LogLevel__PlotLine.Services.WritingActivity.WritingActivityRetention", + "OpenAI__ApiKey", + "OpenAI__MaxOutputTokens", + "OpenAI__Model", + "OpenAI__TimeoutSeconds", + "Site__PublicBaseUrl", + "Storage__UploadsRoot", + "StoryIntelligence__AutomaticImageGenerationDuringImportEnabled", + "StoryIntelligence__ChapterStructureModel", + "StoryIntelligence__ClaimLeaseMinutes", + "StoryIntelligence__ImageGenerationModel", + "StoryIntelligence__ImageGenerationOutputFormat", + "StoryIntelligence__ImageGenerationQuality", + "StoryIntelligence__ImageGenerationSize", + "StoryIntelligence__MaxAssetImagesPerImport", + "StoryIntelligence__MaxCharacterImagesPerImport", + "StoryIntelligence__MaxConcurrentAiRequestsPerBook", + "StoryIntelligence__MaxConcurrentAiRequestsPerUser", + "StoryIntelligence__MaxGlobalConcurrentAiRequests", + "StoryIntelligence__MaxImagesPerImport", + "StoryIntelligence__MaxLocationImagesPerImport", + "StoryIntelligence__QueuePollingIntervalSeconds", + "StoryIntelligence__RequireImageGenerationApproval", + "StoryIntelligence__SceneIntelligenceMaxOutputTokens", + "StoryIntelligence__SceneIntelligenceModel", + "StoryIntelligence__WholeBookPlotSynthesisMaxOutputTokens", + "StoryIntelligence__WholeBookPlotSynthesisModel", + "StoryIntelligence__WorkersEnabled", + "Stripe__PublishableKey", + "Stripe__SecretKey", + "Stripe__WebhookSecret", + "WritingSolver__EnableIndexing" + ], + "normal_worker_settings": { + "StoryIntelligence__WorkersEnabled": "true", + "Illustrations__GenerationWorkerEnabled": "true", + "WritingSolver__EnableIndexing": "application default", + "Geography__Enabled": "application default", + "EmailQueue": "Always registered; initial acceptance denies queue claims/reset; owner must authorise removal.", + "WritingActivityRetention": "Always registered; initial acceptance denies baseline discovery and pruning; owner must authorise removal." + }, + "background_external_egress": "systemd deny-any allow-localhost" +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/production-database-acceptance.json b/Docs/Deployment/Evidence/Phase2-20261125/production-database-acceptance.json new file mode 100644 index 00000000..fb2f8259 --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/production-database-acceptance.json @@ -0,0 +1,109 @@ +{ + "status": "passed", + "active": { + "deployment": "20261125T160148Z-c2e69a3902f2", + "package_sha256": "0ec47c0c0e5ba17c0df34ce27105e183820947fd91bc466d276d305bf4cd10b9", + "release": "plotdirector-production-190c074d-20261125" + }, + "migration_history": [ + { + "RecordingKind": "Baselined", + "count": 210 + }, + { + "RecordingKind": "Executed", + "count": 110 + } + ], + "release_history": [ + { + "DeploymentIdentifier": "20261125T160148Z-c2e69a3902f2", + "ReleaseIdentifier": "plotdirector-production-190c074d-20261125", + "ApplicationVersion": "1.0.0", + "SourceCommit": "190c074d5202fdf8a94b3b7a70c94857f848aafd", + "PackageSha256": "0ec47c0c0e5ba17c0df34ce27105e183820947fd91bc466d276d305bf4cd10b9", + "ActivatedUtc": "2026-11-25T16:02:05.3916289", + "ActivationKind": "Deploy", + "EvidenceReference": "/srv/plotdirector/deployment-evidence/20261125T160148Z-c2e69a3902f2.jsonl" + } + ], + "dbcc_integrity": "passed", + "referential_integrity": "passed", + "migration_permissions": { + "sysadmin": 0, + "dbcreator": 0, + "target_db_owner": 1, + "catherine_access": 0 + }, + "runtime_permissions": { + "sysadmin": 0, + "db_owner": 0, + "database_alter": 0, + "database_backup": 0, + "migration_history_insert": 0, + "release_history_insert": 0, + "catherine_access": 0, + "email_claim": 0, + "retention_baseline": 0 + }, + "native_skia_milestone": 119, + "native_bitmap_constructor_destructor": "passed", + "fontconfig_init": "passed", + "egress_bpf_programs": 1, + "predeployment_backup": "/srv/backups/sql/PlotLine-predeploy-20261125T160148Z-c2e69a3902f2.bak", + "backup_verified": true, + "events": [ + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "package_sha256": "0ec47c0c0e5ba17c0df34ce27105e183820947fd91bc466d276d305bf4cd10b9", + "phase": "validated", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:48Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "backup-start", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:50Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "path": "/srv/backups/sql/PlotLine-predeploy-20261125T160148Z-c2e69a3902f2.bak", + "phase": "backup-verified", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:53Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "migration-start", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:53Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "migration-complete", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:01:55Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "activation-start", + "previous_deployment": null, + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:02:00Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "health-passed", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:02:05Z" + }, + { + "deployment": "20261125T160148Z-c2e69a3902f2", + "phase": "successful", + "release": "plotdirector-production-190c074d-20261125", + "utc": "2026-11-25T16:02:05Z" + } + ], + "pid": 23355 +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/public-acceptance.json b/Docs/Deployment/Evidence/Phase2-20261125/public-acceptance.json new file mode 100644 index 00000000..1dffa01a --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/public-acceptance.json @@ -0,0 +1,71 @@ +{ + "status": "passed", + "requests": { + "/": 200, + "/Account/Login": 200, + "/word-companion": 200, + "/css/word-companion.css": 200, + "/js/word-companion-host.js": 200, + "/Writer": { + "status": 302, + "unauthenticated_access_refused": true + }, + "/Writing/Context": { + "status": 302, + "unauthenticated_access_refused": true + }, + "/api/word-companion/projects": { + "status": 401, + "unauthenticated_access_refused": true + }, + "/api/native-companion/connection": { + "status": 401, + "unauthenticated_access_refused": true + }, + "/_deployment/health": 404, + "/_DEPLOYMENT/health": 404, + "/%5Fdeployment/health": 404, + "/hubs/word-companion-follow/negotiate?negotiateVersion=1": { + "status": 401, + "authentication_enforced": true + }, + "/hubs/native-companion/negotiate?negotiateVersion=1": { + "status": 401, + "authentication_enforced": true + }, + "/hubs/native-companion-agent/negotiate?negotiateVersion=1": { + "status": 401, + "authentication_enforced": true + }, + "websocket_unauthenticated_upgrade": { + "status": 401, + "authenticated_connection_not_claimed": true + } + }, + "recovered_upload_files_hash_verified_over_public_https": 30, + "certificates": { + "plotdirector.com": { + "not_after": "Feb 23 14:51:34 2027 GMT", + "subject_alt_names": [ + "plotdirector.com", + "www.plotdirector.com" + ], + "chain_and_hostname_verified": true, + "sha256": "e310795fc451f5662c9aa0551039f5cf03b4f874172f1591f236080281c77238" + }, + "www.plotdirector.com": { + "not_after": "Feb 23 14:51:34 2027 GMT", + "subject_alt_names": [ + "plotdirector.com", + "www.plotdirector.com" + ], + "chain_and_hostname_verified": true, + "sha256": "e310795fc451f5662c9aa0551039f5cf03b4f874172f1591f236080281c77238" + } + }, + "www_redirect": "https://plotdirector.com/", + "catherine_https_status": 200, + "authenticated_owner_acceptance": "pending; credentials unavailable", + "physical_word_companion_acceptance": "pending", + "authenticated_websocket_101_acceptance": "pending" +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/restricted-access.json b/Docs/Deployment/Evidence/Phase2-20261125/restricted-access.json new file mode 100644 index 00000000..56b26607 --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/restricted-access.json @@ -0,0 +1,21 @@ +{ + "id": "Authenticated SSH; forced dispatcher rejected operation", + "sudo -n /usr/bin/id": "Authenticated SSH; forced dispatcher rejected operation", + "/usr/lib/openssh/sftp-server": "Authenticated SSH; forced dispatcher rejected operation", + "file_permissions": { + "plotdirector-deploy:read:/etc/plotdirector-deployment/database.json": "denied", + "plotdirector-deploy:read:/etc/catherinelynwood/catherinelynwood.env": "denied", + "plotdirector-deploy:write:/usr/local/sbin/deploy-plotdirector": "denied", + "plotdirector-deploy:write:/usr/local/lib/plotdirector-deployment": "denied", + "plotdirector-deploy:write:/etc/plotdirector-deployment": "denied", + "plotdirector-deploy:write:/srv/plotdirector/releases": "denied", + "plotdirector-deploy:write:/srv/catherinelynwood": "denied", + "plotdirector:read:/etc/plotdirector-deployment/database.json": "denied", + "plotdirector:read:/etc/catherinelynwood/catherinelynwood.env": "denied", + "plotdirector:write:/usr/local/sbin/deploy-plotdirector": "denied", + "plotdirector:write:/usr/local/lib/plotdirector-deployment": "denied", + "plotdirector:write:/etc/plotdirector-deployment": "denied", + "plotdirector:write:/srv/plotdirector/releases": "denied", + "plotdirector:write:/srv/catherinelynwood": "denied" + } +} diff --git a/Docs/Deployment/Evidence/Phase2-20261125/sql-security-provisioning.json b/Docs/Deployment/Evidence/Phase2-20261125/sql-security-provisioning.json new file mode 100644 index 00000000..d27a7c2a --- /dev/null +++ b/Docs/Deployment/Evidence/Phase2-20261125/sql-security-provisioning.json @@ -0,0 +1,36 @@ +{ + "status": "passed", + "runtime_roles": [ + { + "name": "PlotLineApp", + "role_name": "PlotDirectorRuntime" + }, + { + "name": "PlotDirectorMigration", + "role_name": "db_owner" + } + ], + "server_permissions": [ + { + "name": "PlotLineApp", + "permission_name": "CONNECT SQL", + "state_desc": "GRANT" + }, + { + "name": "PlotDirectorMigration", + "permission_name": "CONNECT SQL", + "state_desc": "GRANT" + }, + { + "name": "PlotDirectorMigration", + "permission_name": "CREATE ANY DATABASE", + "state_desc": "GRANT" + } + ], + "catherine_user_mappings": 0, + "cross_database_chaining": false, + "runtime_owns_database_or_schema": false, + "sql_admin_temporary_secret_removed": true, + "sa_password_changed": false, + "sql_network_changed": false +} diff --git a/Docs/Deployment/Phase2-20261125.md b/Docs/Deployment/Phase2-20261125.md index b65f3db1..5af152e4 100644 --- a/Docs/Deployment/Phase2-20261125.md +++ b/Docs/Deployment/Phase2-20261125.md @@ -1,69 +1,170 @@ -# Production migration Phase 2 — 25 November 2026 +# PlotDirector Production deployment — 25 November 2026 -**BLOCKED before provisioning: SQL administrative authentication unavailable.** -PlotDirector is not deployed or publicly available with valid HTTPS. No web1 or -www configuration, account, database, service, certificate or firewall changes were -performed. No package transfer, migration or activation was attempted. +**COMPLETE: https://plotdirector.com/ is live on web1 over valid HTTPS.** +Public availability is not waiting for DNS or another deployment phase. Owner +manual authenticated and physical Word/Windows Companion acceptance remains. +Chargeable processing, outbound application traffic and queued email remain held +pending separate owner authorisation. -## Completed focused preflight +## Active installation -- Existing strict administrator SSH access and sudo work; hostname is web1. -- Exact signed Phase 1 package verified. The public key matches both the retained - private signing authority and the committed Phase 1 public-key fingerprint. - Qualified PlotLine.dll matches `70c516e0a112c4e61813e563405c979ad35069539ddc440bddbd6dac0a4379d1`. - Nothing was rebuilt, repackaged or requalified. -- Original recovered backup SHA-256 matches the approved value. Backup media remain - untouched. Native SQL 17.0.5065.9 and Nginx are active. The existing SQL backup - timer is active and its last service run succeeded, exit 0. -- .NET/ASP.NET runtimes are 10.0.15; about 554 GiB disk and 22120 MiB memory were - available. Ports 5001 and 5003 are free; Catherine remains on loopback 5002. -- Apex A resolves to 85.190.124.132; www aliases the apex and resolves identically. - Neither hostname has an effective AAAA record. No DNS changes were made. -- Catherine remains active at PID 13134; normal public HTTPS, following its - redirect, returns 200 with successful TLS verification. -- PlotDirector normal public HTTPS currently fails certificate hostname validation. - No certificate request was made; certificate issuance must accompany the resumed - provisioning. TLS verification was not disabled. +- Host web1, `85.190.124.132`; SQL PlotLine at IPv4 loopback 1433, unchanged. +- Release `plotdirector-production-190c074d-20261125`, application `1.0.0`, source + `190c074d5202fdf8a94b3b7a70c94857f848aafd`. +- Qualified DLL SHA-256: + `70c516e0a112c4e61813e563405c979ad35069539ddc440bddbd6dac0a4379d1`. +- Package SHA-256: + `0ec47c0c0e5ba17c0df34ce27105e183820947fd91bc466d276d305bf4cd10b9`. +- Manifest SHA-256: + `58bac17161e1ea280617c15fba61ef26ac976417217fbb77accbb5ab4ababe13`. +- `/srv/plotdirector/current` points to + `/srv/plotdirector/releases/plotdirector-production-190c074d-20261125/app`. +- `plotdirector.service` is enabled and active, PID 23355 at acceptance, runtime + identity plotdirector, Kestrel only `127.0.0.1:5001`. +- Successful deployment `20261125T160148Z-c2e69a3902f2`; one successful Deploy record + in ApplicationReleaseHistory, recorded after application/database health passed. +- The exact existing signed package was transferred through restricted SSH. The + installed public trust anchor matches the retained Atlas signing authority and + Phase 1 fingerprint. No application or SQL script was rebuilt or modified. -[Sanitized preflight evidence](Evidence/Phase2-20261125/preflight.json). +## Database and recovery -## Exact blocker and prerequisite +Live starting schema and all original fingerprints matched Phase 1 before migration. +The exact ordered manifest produced 320 history entries: **210 Baselined and 110 +Executed**, with five explicit omissions. Historical timestamps were not invented. +Migrations ran from 15:58:20 to 15:58:34 UTC (14 seconds wall clock; summed individual +execution durations 5909 ms). Retries skipped the completed migrations. -The only available documented SQL credential is the root-protected hourly backup -credential, authenticating as `SqlBackupService`. Effective SQL checks show -`db_backupoperator=1`, but no sysadmin/securityadmin, CONTROL SERVER, ALTER ANY -LOGIN, database CONTROL, database SELECT, VIEW DEFINITION or ALTER ANY USER. -It cannot establish the live schema/business baseline, inspect all security -mappings, or provision the required runtime/migration logins and users. A matching -original backup does not prove that the live database remains unchanged. +Final schema is +`b17db2bbdc583cb7bd3c856fb4db5cf6fc470e87fbaee5dc1dbbe99b6878beb7`. +CHECKDB and referential checks passed. Every original column across **163 tables / +139554 rows** remains fingerprint-identical, including content, identities, sync +metadata, accounts and asset references. No unexplained business-data changes +were accepted. New deployment histories are expected additions. -An existing web1 SQL administrative credential must be made available securely, -or an authorised DBA must provide the equivalent administrative session. It must -support the reviewed login/user/role setup and security inventory, including the -migration login's direct CREATE ANY DATABASE permission. Do not send a password -in chat, put it in command arguments, reset sa, grant sysadmin/dbcreator to a new -application account, or elevate/reuse the backup credential. A root-only temporary -credential file on web1 or an approved secret-management channel is suitable; it -must not become part of a package, deployment evidence or Git. +Before the migrations the helper created and CHECKSUM/VERIFYONLY-verified: +`/srv/backups/sql/PlotLine-predeploy-20261125T155815Z-7427734eba47.bak`. +The successful retry independently created and verified: +`/srv/backups/sql/PlotLine-predeploy-20261125T160148Z-c2e69a3902f2.bak`. +The intermediate retry backup is also retained. The original recovery backup +`/srv/backups/sql/PlotLine-20261124.bak` still matches its approved checksum. +No recovery media were overwritten/deleted and no Production restore was performed. +The existing hourly SQL backup timer remains active; it also retains responsibility +for Catherine's existing backups without configuration changes. -After that prerequisite is supplied, resume the already-authorised Phase 2 work: -verify live schema/business fingerprints, provision protected tooling/accounts and -runtime configuration, issue a new apex/www certificate using webroot-only Certbot, -transfer/validate/activate the exact existing package, and perform focused public -acceptance. Do not repeat Phase 1 or request deployment approval again. +## Security and persistent configuration -## Incomplete work and operational state +The restricted transfer account plotdirector-deploy cannot obtain a shell/SFTP, +forward TCP, run general sudo, write helper/config/releases or read migration and +Catherine credentials. These were verified after authentication. Root owns the +trusted helper, worker, public key, target configuration and installed release. +Release directories are 0750; release files are 0440. -Provisioning, SQL security setup, persistent-data recovery, Production configuration, -restricted SSH installation, new certificate/renewal setup, service/vhost setup, -pre-deployment backup, migrations, activation/history and public application -acceptance remain unstarted. Live account/entitlement inspection also requires SQL -access; Phase 1's expired-entitlement finding remains historical, not a fresh live -verification. No subscriptions, Stripe state or external worker settings changed. -The temporary Atlas administrator authorisation is retained because permanent -restricted access is not installed. No owner authenticated or physical Word tests -were performed. Existing uncommitted repository documents were preserved. +PlotLineApp was reconciled with the restored database user and receives only +PlotDirectorRuntime, with legacy db_owner removed. Actual runtime checks confirm +no sysadmin/db_owner, unrestricted DDL/backup or deployment-history mutation, and +no connection to CatherineLynwood. PlotDirectorMigration has PlotLine-only db_owner +and direct CREATE ANY DATABASE for VERIFYONLY; neither sysadmin nor dbcreator nor +Catherine access. Credentials are separate and protected. TRUSTWORTHY and +cross-database chaining remain disabled; runtime owns no database/schema. -Preflight stopped at 15:38 UTC. No provisioning or activation duration exists -because neither was started; the 15-minute activation target was not entered. -Readiness is **blocked**, with the signed candidate and recovery assets preserved. +The temporary root-only SQL administrator credential was used only for SQL +security setup/verification and removed. sa's password and SQL networking were not +changed or restarted. Only Atlas's temporary administrator SSH key was removed; +both other administration keys remain. New Atlas administrator SSH fails, while +restricted deployment validation succeeds. The held administrative session was closed. + +All 30 uploads and both recovered Data Protection XML files were installed under +`/srv/plotdirector/shared`; original archives are retained. Upload hashes match +both on disk and when served over public HTTPS. Both original key files remain +byte-identical. Stable DP application identity is `/var/www/plotdirector/`, with +shared key path configured; historical cookie/encrypted-payload compatibility is +not claimed as a tested result. Reauthentication is expected where necessary. + +`/etc/plotdirector/plotdirector.env` merges the read-only old appsettings.json and +recovered environment file, replacing obsolete database/storage settings. It +contains new runtime credentials, persistent paths, public URL, paragraph-manuscript +flag enabled, allowed hosts and recovered Site/Admin/SMTP/Stripe/OpenAI/logging +settings. No secret values appear in this report or Git. Actual external delivery, +payments and AI calls were not used as acceptance tests. + +## HTTPS and focused public acceptance + +A new Let's Encrypt certificate covers **plotdirector.com and www.plotdirector.com**, +expires **23 February 2027, 14:51:34 UTC**, and passed normal public chain/hostname +validation. Certbot used webroot-only issuance; no historical certificate was +transferred. HTTP redirects to HTTPS while preserving ACME challenge access; www +redirects to apex. certbot.timer is active; the targeted PlotDirector renewal dry +run and lineage-scoped validated Nginx reload hook passed. Catherine's certificate +was not renewed or replaced. + +Public homepage, login and Word host/static resources return 200. Writer/Context, +Companion APIs and SignalR negotiation correctly reject unauthenticated access. +An unauthenticated WebSocket upgrade is rejected by authentication, as expected; +**authenticated 101/SignalR operation remains a manual acceptance item**. Internal +health is 404 publicly, including case/encoded variants, and healthy locally with +correct Production/source/version/database identity. Nginx supports HTTP/1.1 +upgrade headers and required upload limits. Native Skia ABI/version/bitmap +construction and Fontconfig initialisation passed; an egress BPF filter is attached. + +Catherine remains active at its original PID 13134 and returns public HTTPS 200. +Its original vhost/service/certificate checksums are unchanged. www remains +inactive, PID 0; installed DLL/helper hashes match the historical release. No DNS, +Catherine, firewall or SQL network changes were made. Port 5003 remains reserved. + +## Initial worker holds and owner action + +Current settings: StoryIntelligence workers=false; illustration generation=false; +WritingSolver indexing=false; Geography=false. The service's acceptance drop-in +blocks egress except localhost. A fixed root-owned pre-start permission fence +prevents email queue claims/reset, accepted-manuscript baseline discovery and +writing/work pruning. Those services are always registered in this qualified +build, so configuration flags alone cannot suspend them. Internal presence, +notifications and in-memory capture expiry remain available for Companion operation. +No payment, subscription mutation or live API/email acceptance was performed. + +Recorded intended normal settings, **not enabled**: StoryIntelligence=true and +illustration generation=true (recovered settings), WritingSolver indexing=true +(qualified default), Geography=false until a provider is explicitly reviewed. +Email and retention resume only with owner authorisation, queue review, removal +of the pre-start fence and the corresponding five user-level EXECUTE denials. +Egress must be deliberately reviewed before restoring SMTP/Stripe/AI access. +See the operational standard for exact held procedure names and paths. + +The configured owner/admin account is email-confirmed and unlocked. Its stored +subscription is active, non-trial, with a ten-book entitlement and stored period +end **8 December 2026, 18:18:47 UTC**. This is a database finding, not a Stripe API +verification. Other historical accounts include expired entitlements; the Phase 1 +restore fixture selected a different account. No subscription records were changed. +Password-reset/notification emails will remain queued while the email hold is in +place. Existing-password authentication and authenticated Writer/Context, Word, +Companion, WebSocket and image workflows require owner manual testing. + +## Failures, timing and handover + +The first activation migrated successfully but failed startup because umask 077 +masked requested release-directory 0750 to 0700. A second attempt, before recovery +completed, failed the helper's inactive-service check against systemd's failed +state. Neither attempt received successful activation history. Both evidence and +all backups were retained. The failed installation/current-link evidence was +quarantined under `/srv/plotdirector/failed-attempts/20261125T155815Z-7427734eba47`. +The old helper was backed up. A narrow two-line installer correction explicitly +chmods directories to the already documented 0750; a focused real-filesystem umask +test passed. systemd's stopped/failed state was reset, and the unchanged signed +package was activated again through the helper. No validation was bypassed, +application/SQL changed, migration replayed or database rolled back. + +The root-owned initial-acceptance permission fence/egress profile and ACME/internal +health Nginx rules are checked into provisioning templates for maintainability. +No full Phase 1 regression/restore qualification was repeated. + +Tracked resumed operations: **15:45:06–16:04:33 UTC (~19m27s)**, including provisioning +and WAN transfer. Public availability began **16:03:22 UTC**. Initial activation +through successful recovery took **3m55s**, inside the 15-minute target; the final +successful attempt took **22.5 seconds**. The earlier blocked preflight is retained +as historical evidence. No further DNS/cutover step is required. + +Sanitized evidence is in [the Phase 2 evidence directory](Evidence/Phase2-20261125/operations-handover.json). +Private attempt logs and recovery evidence remain root-protected on web1. For +later work: owner manual acceptance/worker decisions, periodic restore testing, +approved signing-key custody and retention review. These do not defer public go-live. diff --git a/Docs/Deployment/Production.md b/Docs/Deployment/Production.md index d488f5f6..7638a49b 100644 --- a/Docs/Deployment/Production.md +++ b/Docs/Deployment/Production.md @@ -1,8 +1,9 @@ # PlotDirector production deployment standard This procedure separates Atlas preparation, immutable transfer and restricted -activation. Phase 1 does not authorise installing it or activating PlotDirector on -web1. Consult [Phase 1 qualification](Phase1-20261125.md) before Phase 2. +activation. Production is live on web1 following the authorised [Phase 2 deployment](Phase2-20261125.md). +[Phase 1 qualification](Phase1-20261125.md) remains historical release evidence; +future changes still require environment-specific authorisation and qualification. ## Trust and environment boundaries @@ -168,7 +169,7 @@ The helper refuses rollback if any migration is unrecorded. Health must pass bef a new Rollback history row is inserted. A SQL rollback is a separately authorised restore/recovery operation; never replace a database automatically. -## Phase 2 initial provisioning (administrator only; not executed in Phase 1) +## Phase 2 initial provisioning (administrator only; completed 25 November 2026) Review existing files and take uniquely named configuration backups first. Keep Catherine's service, virtual host, certificate, data and database unchanged. @@ -240,25 +241,76 @@ Catherine's service, virtual host, certificate, data and database unchanged. Test old key purposes/discriminator before claiming cookie or encrypted-payload continuity. Copying XML keys alone does not establish compatibility. Phase 1 does not claim a real historical authentication cookie was successfully replayed. -9. Install the reviewed service template; do not start it. Run systemd verification +9. Install the reviewed service template and initial-acceptance drop-in; do not start it. Install the fixed `provision/acceptance-permissions.py` root-owned 0755 at `/usr/local/lib/plotdirector-deployment/acceptance-permissions.py` and `acceptance.conf` at `/etc/systemd/system/plotdirector.service.d/acceptance.conf`. Run systemd verification and check its account, environment path, content root, writable paths and loopback endpoint. Install the reviewed sudoers fragment only after `visudo -cf` passes; validate the whole sudo configuration. Install the forced-command SSH Match block only after `sshd -t` passes. Keep an administrator session open during SSH reload. -10. Put the dedicated deployment public key in the root-owned authorised-keys file - named by the Match block, with `restrict` and an appropriate verified Atlas +10. Put the dedicated deployment public key in the root-owned **0644** authorised-keys file + named by the Match block (sshd must read it as the target user), with `restrict` and an appropriate verified Atlas source-address restriction where operationally stable. Verify upload/validate, shell and SFTP refusal, forwarding refusal, no general sudo, helper/config non-writability and no access to Catherine. Then remove **only** the temporary Atlas administrator key authorisation. Do not remove other administration access. -11. Provision PlotDirector's own certificate and reviewed virtual host/map templates. - Existing DNS still targeting www will affect certificate issuance; select an - explicitly authorised challenge/certificate-transfer approach. Run `nginx -t`; - verify Catherine before and after any later reload. Preserve ports 5002/5003. - Test HTTPS using `--resolve` and normal certificate validation before DNS cutover. -12. Activate only after Phase 2 approval and a verified starting-state/backup check. - Run authenticated feature, upload, image, Word/SignalR and account checks before - separately authorised DNS changes. Keep www inactive and unchanged as fallback. +11. DNS already points apex/www to web1. Use the independent PlotDirector HTTP maintenance/ACME webroot at `/srv/plotdirector/acme`, verify both public challenges, and issue a **new** certificate using `certbot certonly --webroot --webroot-path /srv/plotdirector/acme --cert-name plotdirector.com -d plotdirector.com -d www.plotdirector.com --non-interactive --agree-tos` with the existing registered account. Do not transfer a historical certificate or use the Nginx installer plugin. Install the independent vhost/map and initial maintenance snippet, keeping the case-insensitive internal-health deny rule. Run `nginx -t` before each reload and check Catherine afterwards. Use the lineage-scoped reload hook and `certbot renew --cert-name plotdirector.com --dry-run --run-deploy-hooks --non-interactive`; never target Catherine for this test. Preserve ports 5002/5003. Use normal public TLS validation; no further DNS change is required. +12. Activate only with explicit environment authorisation and a verified starting + state/backup check. Remove only the PlotDirector maintenance return after + automated health and preservation checks; normal public HTTPS is the acceptance + target. Owner authenticated feature, image, Word/SignalR and account acceptance + follows where credentials or physical clients are required; it does not defer + this authorised public go-live. Keep www inactive and unchanged as fallback. -No provisioning, remote transfer, production migration, service start, Nginx reload -or DNS change in this document is authorised merely by completing Phase 1. +Phase 2 authorisation covered this initial installation and go-live, now complete. +It does not authorise future releases, further DNS changes or enabling held workers. + + +## Actual initial-acceptance profile and recovery notes + +Production uses the base service plus +`/etc/systemd/system/plotdirector.service.d/acceptance.conf`. The per-service +IPAddressDeny=any / IPAddressAllow=localhost policy has an attached egress BPF +program. It changes no firewall or SQL listening configuration. The fixed root +pre-start fence reads only the protected migration configuration and drops its SQL +subprocess to plotdirector-migrate; no SQL password is in arguments or output. +It denies EXECUTE to the **PlotLineApp user** on these five procedures: + +- dbo.EmailQueue_ResetStuckSending +- dbo.EmailQueue_DequeueBatch +- dbo.WritingActivity_BaselineTargets +- dbo.WritingActivity_Prune +- dbo.WriterWork_Prune + +These always-registered background services cannot be stopped with configuration +flags in the qualified build. Configurable StoryIntelligence/illustration workers, +WritingSolver indexing and Geography are false. Presence/notifications and +in-memory capture expiry remain available. Queued/reset emails will not send. +Normal settings are recorded in `/etc/plotdirector/normal-worker-settings.json`; +see the handover for qualified defaults and owner decisions. **Do not enable these +workers or external processing without separate owner authorisation.** + +After such authorisation, review pending jobs/email and external credentials, then +review the acceptance drop-in and remove its pre-start fence only when intended. +The migration principal must explicitly REVOKE the five user-level EXECUTE denials +(the runtime role's existing schema EXECUTE grant then applies). Removing the hook +alone does not remove those denials; restarting with the hook reapplies them. +Review egress and worker flags separately, validate the unit and perform focused +acceptance before allowing chargeable processing. No such restoration happened +in Phase 2. + +`install()` explicitly chmods newly created release directories to 0750 because the +launcher intentionally uses umask 077. Files remain root-owned 0440. A focused +regression reproduces the real restrictive umask. During initial deployment this +missing chmod caused a failed start after successful migrations. The failed +installation, prior helper and backup/evidence were retained; no activation-success +row was written. After confirming PID=0/no successful activation, the failed release +and current link were quarantined, stopped/failed state reset, and the corrected +helper retried the **identical** signed package. Recorded migrations were skipped. +This is initial-failure recovery evidence, not permission to overwrite an active +release or erase histories on future failures. + +Current certificate renewal uses the existing certbot.timer and webroot challenge. +The root-owned `/etc/letsencrypt/renewal-hooks/deploy/plotdirector-reload` exits unless +RENEWED_LINEAGE is `/etc/letsencrypt/live/plotdirector.com`, then runs `nginx -t` +and reloads Nginx. The targeted dry run passed. Never replace Catherine's files. +The supplied vhost template requires the PlotDirector map and maintenance snippet; +initial provisioning starts with 503, while the live snippet contains only a comment. diff --git a/Tools/Deployment/activate.py b/Tools/Deployment/activate.py index ebf604ca..569776bd 100644 --- a/Tools/Deployment/activate.py +++ b/Tools/Deployment/activate.py @@ -129,11 +129,13 @@ def install(payload, destination, runtime_group): require(not destination.exists() and not destination.is_symlink(), 'Release already installed; use a new release identifier') gid = grp.getgrnam(runtime_group).gr_gid destination.mkdir(mode=0o750) + destination.chmod(0o750) # The launcher deliberately sets umask 077. for source in sorted(payload.rglob('*')): relative = source.relative_to(payload) target = destination / relative if source.is_dir(): target.mkdir(mode=0o750) + target.chmod(0o750) else: require(source.is_file() and not source.is_symlink(), 'Invalid payload entry') with source.open('rb') as src, target.open('xb') as out: diff --git a/Tools/Deployment/provision/acceptance-permissions.py b/Tools/Deployment/provision/acceptance-permissions.py new file mode 100644 index 00000000..e07ad9b3 --- /dev/null +++ b/Tools/Deployment/provision/acceptance-permissions.py @@ -0,0 +1,16 @@ +#!/usr/bin/python3 -I +# Fixed initial-acceptance permission fence. No arbitrary arguments or SQL hooks. +import json,os,pwd,subprocess,sys +from pathlib import Path +if len(sys.argv)!=1:raise SystemExit(2) +c=json.loads(Path('/etc/plotdirector-deployment/database.json').read_text()) +f=dict(x.split('=',1) for x in c['connection'].split(';') if '=' in x) +assert c['database']=='PlotLine' and c['expected_host']=='web1' and f['Server']=='127.0.0.1,1433' +procedures=['EmailQueue_ResetStuckSending','EmailQueue_DequeueBatch','WritingActivity_BaselineTargets','WritingActivity_Prune','WriterWork_Prune'] +sql='SET NOCOUNT ON; SET XACT_ABORT ON; BEGIN TRANSACTION; ' +for name in procedures: + sql+="IF OBJECT_ID(N'dbo."+name+"',N'P') IS NULL THROW 51000,'Acceptance prerequisite missing',1; DENY EXECUTE ON OBJECT::[dbo].["+name+"] TO [PlotLineApp]; " +sql+='COMMIT;' +u=pwd.getpwnam('plotdirector-migrate') +p=subprocess.run(['/opt/mssql-tools18/bin/sqlcmd','-S','tcp:127.0.0.1,1433','-U',f['User ID'],'-d','PlotLine','-C','-I','-b','-m','1','-l','5','-t','30'],input=sql,text=True,capture_output=True,user=u.pw_uid,group=u.pw_gid,extra_groups=[],env={'PATH':'/usr/bin:/bin','SQLCMDPASSWORD':f['Password']}) +if p.returncode:raise SystemExit('Acceptance permission fence failed; SQL diagnostics suppressed') diff --git a/Tools/Deployment/provision/acceptance.conf b/Tools/Deployment/provision/acceptance.conf new file mode 100644 index 00000000..53b72d11 --- /dev/null +++ b/Tools/Deployment/provision/acceptance.conf @@ -0,0 +1,4 @@ +[Service] +IPAddressDeny=any +IPAddressAllow=localhost +ExecStartPre=+/usr/local/lib/plotdirector-deployment/acceptance-permissions.py diff --git a/Tools/Deployment/provision/nginx-plotdirector.conf b/Tools/Deployment/provision/nginx-plotdirector.conf index fc0941b4..c16dc802 100644 --- a/Tools/Deployment/provision/nginx-plotdirector.conf +++ b/Tools/Deployment/provision/nginx-plotdirector.conf @@ -1,35 +1,39 @@ -# Phase 2: /etc/nginx/sites-available/plotdirector (no default_server). -# Certificate must already be valid for both hostnames. Do not edit Catherine's vhost. +# PlotDirector-only vhost. Requires its certificate, map and maintenance snippet. server { - listen 80; - listen [::]:80; - server_name plotdirector.com www.plotdirector.com; - return 301 https://plotdirector.com$request_uri; + listen 80; + listen [::]:80; + server_name plotdirector.com www.plotdirector.com; + location ^~ /.well-known/acme-challenge/ { root /srv/plotdirector/acme; default_type text/plain; } + location / { return 301 https://plotdirector.com$request_uri; } } server { - listen 443 ssl; - listen [::]:443 ssl; - server_name www.plotdirector.com; - ssl_certificate /etc/letsencrypt/live/plotdirector.com/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/plotdirector.com/privkey.pem; - return 301 https://plotdirector.com$request_uri; + listen 443 ssl; + listen [::]:443 ssl; + server_name www.plotdirector.com; + ssl_certificate /etc/letsencrypt/live/plotdirector.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/plotdirector.com/privkey.pem; + ssl_protocols TLSv1.2 TLSv1.3; + return 301 https://plotdirector.com$request_uri; } server { - listen 443 ssl; - listen [::]:443 ssl; - server_name plotdirector.com; - ssl_certificate /etc/letsencrypt/live/plotdirector.com/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/plotdirector.com/privkey.pem; - client_max_body_size 110m; - location / { - proxy_pass http://127.0.0.1:5001; - proxy_http_version 1.1; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $plotdirector_connection_upgrade; - proxy_read_timeout 3600s; - proxy_buffering off; - } + listen 443 ssl; + listen [::]:443 ssl; + server_name plotdirector.com; + ssl_certificate /etc/letsencrypt/live/plotdirector.com/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/plotdirector.com/privkey.pem; + ssl_protocols TLSv1.2 TLSv1.3; + client_max_body_size 110m; + location ~* ^/_deployment(?:/|$) { return 404; } + location / { + include /etc/nginx/snippets/plotdirector-maintenance.conf; + proxy_pass http://127.0.0.1:5001; + proxy_http_version 1.1; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $plotdirector_connection_upgrade; + proxy_read_timeout 3600s; + proxy_buffering off; + } } diff --git a/Tools/Deployment/provision/plotdirector-maintenance.conf b/Tools/Deployment/provision/plotdirector-maintenance.conf new file mode 100644 index 00000000..0d9ac449 --- /dev/null +++ b/Tools/Deployment/provision/plotdirector-maintenance.conf @@ -0,0 +1,3 @@ +# Initial provisioning only. Replace with a comment after successful activation. +add_header Retry-After 300 always; +return 503; diff --git a/Tools/Deployment/test_activation.py b/Tools/Deployment/test_activation.py index 75c02b67..76aeda63 100644 --- a/Tools/Deployment/test_activation.py +++ b/Tools/Deployment/test_activation.py @@ -1,4 +1,5 @@ import hashlib +import os import json from pathlib import Path import tempfile @@ -12,6 +13,22 @@ from release import Refused,canonical class ActivationFailureTests(unittest.TestCase): + def test_install_permissions_survive_restrictive_launcher_umask(self): + payload=self.root/'permission-payload' + (payload/'app/nested').mkdir(parents=True) + (payload/'app/nested/asset').write_bytes(b'qualified bytes') + destination=self.root/'releases/permission-release' + previous=os.umask(0o077) + try: + with patch.object(activate.os,'chown'): + activate.install(payload,destination,'root') + finally: + os.umask(previous) + for directory in [destination,*[p for p in destination.rglob('*') if p.is_dir()]]: + self.assertEqual(directory.stat().st_mode & 0o777,0o750) + self.assertEqual((destination/'app/nested/asset').stat().st_mode & 0o777,0o440) + self.assertEqual((destination/'app/nested/asset').read_bytes(),b'qualified bytes') + def setUp(self): self.temp=tempfile.TemporaryDirectory();self.root=Path(self.temp.name) for name in ('releases','inbox/new-release','evidence','backup','old/app'):(self.root/name).mkdir(parents=True)