diff --git a/cmd/secret-control-plane/main.go b/cmd/secret-control-plane/main.go new file mode 100644 index 0000000..50d232e --- /dev/null +++ b/cmd/secret-control-plane/main.go @@ -0,0 +1,65 @@ +package main + +import ( + "flag" + "fmt" + "os" + "strings" + + platformsecrets "git.cin.su/m/Assistant/platform/secrets" +) + +const ( + defaultRoot = "/run/control-plane-secrets" + defaultRuntimeUID = 100 + defaultRuntimeGID = 101 +) + +func main() { + reason := flag.String("reason", "", "rotation reason: owner-requested-rotation or exposure-detected") + flag.Parse() + if flag.NArg() != 1 { + fail("usage: secret-control-plane [ensure|rotate]") + } + store, err := platformsecrets.NewLocalMachineCredentialStore(defaultRoot, defaultRuntimeUID, defaultRuntimeGID, nil) + if err != nil { + fail("control-plane credential store unavailable") + } + spec := platformsecrets.ControlPlaneServiceTokenSpec() + switch strings.TrimSpace(flag.Arg(0)) { + case "ensure": + result, err := store.Ensure(spec) + if err != nil { + fail("control-plane credential provisioning failed") + } + if result.Created { + fmt.Println("control-plane credential provisioned") + return + } + fmt.Println("control-plane credential already active") + case "rotate": + if !validRotationReason(*reason) { + fail("rotation reason is invalid") + } + if _, err := store.Rotate(spec, *reason); err != nil { + fail("control-plane credential rotation failed") + } + fmt.Println("control-plane credential rotated") + default: + fail("unsupported control-plane credential operation") + } +} + +func validRotationReason(reason string) bool { + switch strings.TrimSpace(reason) { + case "owner-requested-rotation", "exposure-detected": + return true + default: + return false + } +} + +func fail(message string) { + fmt.Fprintln(os.Stderr, message) + os.Exit(1) +} diff --git a/cmd/secret-control-plane/main_test.go b/cmd/secret-control-plane/main_test.go new file mode 100644 index 0000000..159ff17 --- /dev/null +++ b/cmd/secret-control-plane/main_test.go @@ -0,0 +1,15 @@ +package main + +import "testing" + +func TestSecretControlPlaneDefaultsUseDedicatedProtectedRoot(t *testing.T) { + if defaultRoot != "/run/control-plane-secrets" || defaultRuntimeUID <= 0 || defaultRuntimeGID <= 0 { + t.Fatal("unsafe control-plane defaults") + } +} + +func TestRotationReasonsAreBoundedAndNeverArbitraryDiagnosticText(t *testing.T) { + if !validRotationReason("owner-requested-rotation") || !validRotationReason("exposure-detected") || validRotationReason("Bearer secret-value") { + t.Fatal("unsafe rotation reason validation") + } +} diff --git a/contracts/secrets/types.go b/contracts/secrets/types.go index 57946d2..7115d55 100644 --- a/contracts/secrets/types.go +++ b/contracts/secrets/types.go @@ -8,8 +8,9 @@ type CredentialRef string type SecretPurpose string const ( - SecretPurposeDatabasePassword SecretPurpose = "DATABASE_PASSWORD" - SecretPurposeProviderAPIKey SecretPurpose = "PROVIDER_API_KEY" + SecretPurposeDatabasePassword SecretPurpose = "DATABASE_PASSWORD" + SecretPurposeProviderAPIKey SecretPurpose = "PROVIDER_API_KEY" + SecretPurposeServiceAuthentication SecretPurpose = "SERVICE_AUTHENTICATION" ) // RuntimeConsumer identifies a trusted runtime allowed to resolve a credential. @@ -17,6 +18,7 @@ type RuntimeConsumer string const ( RuntimeConsumerCore RuntimeConsumer = "core-runtime" + RuntimeConsumerCommit RuntimeConsumer = "commit-runtime" RuntimeConsumerWorkWorker RuntimeConsumer = "agent-worker" RuntimeConsumerEpistemicsWorker RuntimeConsumer = "reflection-worker" RuntimeConsumerCognitive RuntimeConsumer = "cognitive-worker" diff --git a/deploy/docker-compose.candidate-slot.yml b/deploy/docker-compose.candidate-slot.yml index 2571d38..cbbc024 100644 --- a/deploy/docker-compose.candidate-slot.yml +++ b/deploy/docker-compose.candidate-slot.yml @@ -23,6 +23,7 @@ services: SECRET_BACKEND_ROOT: /run/secrets volumes: - assistant_core_secrets:/run/secrets:ro + - assistant_control_plane_service_secrets:/run/control-plane-secrets:ro - assistant_research_sources:/var/lib/research-sources:ro networks: shared: @@ -138,6 +139,9 @@ services: volumes: assistant_core_secrets: external: true + assistant_control_plane_service_secrets: + name: assistant_control_plane_service_secrets + external: true assistant_research_sources: name: assistant_research_sources external: true diff --git a/deploy/docker-compose.prod.yml b/deploy/docker-compose.prod.yml index e122546..e857e53 100644 --- a/deploy/docker-compose.prod.yml +++ b/deploy/docker-compose.prod.yml @@ -85,6 +85,7 @@ services: depends_on: { postgres: { condition: service_healthy } } volumes: - assistant_core_secrets:/run/secrets:ro + - assistant_control_plane_service_secrets:/run/control-plane-secrets:ro healthcheck: test: ["CMD-SHELL", "wget -qO- http://localhost:8080/healthz >/dev/null && wget -qO- http://localhost:8080/readyz >/dev/null"] interval: 10s @@ -247,8 +248,18 @@ services: # External mutation credentials belong here only via Portainer/Docker secrets/env injection. depends_on: [core-runtime, continuity-runtime, notification-receiver] volumes: + - assistant_control_plane_service_secrets:/run/control-plane-secrets:ro - assistant_notification_writer_secret:/run/notification-writer:ro + secret-control-plane: + profiles: ["secret-control-plane"] + build: { context: .., dockerfile: deploy/images/runtime.Dockerfile, args: { TARGET: secret-control-plane, SOURCE_REVISION: "${ASSISTANT_SOURCE_REVISION:-unknown}" } } + user: "0:0" + restart: "no" + command: ["ensure"] + volumes: + - assistant_control_plane_service_secrets:/run/control-plane-secrets + cognitive-worker: build: { context: .., dockerfile: deploy/images/runtime.Dockerfile, args: { TARGET: cognitive-worker, SOURCE_REVISION: "${ASSISTANT_SOURCE_REVISION:-unknown}" } } restart: unless-stopped @@ -363,6 +374,9 @@ volumes: assistant_nats: assistant_core_secrets: external: true + assistant_control_plane_service_secrets: + name: assistant_control_plane_service_secrets + external: true assistant_notification_receipts: assistant_notification_writer_secret: external: true diff --git a/deploy/provision-machine-credential.sh b/deploy/provision-machine-credential.sh new file mode 100644 index 0000000..9abcd99 --- /dev/null +++ b/deploy/provision-machine-credential.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +# This is the only production writer for the dedicated control-plane machine +# credential volume. It never receives, prints, or exports a secret value. +BASE_DIR="${BASE_DIR:-/home/m/assistant-deploy}" +REPO_DIR="${REPO_DIR:-$BASE_DIR/repo}" +ENV_FILE="${ENV_FILE:-$BASE_DIR/production-compose.env}" +COMPOSE_FILE="$REPO_DIR/deploy/docker-compose.prod.yml" +VOLUME="assistant_control_plane_service_secrets" +ACTION="${1:-ensure}" + +case "$ACTION" in + ensure|rotate) ;; + *) echo "unsupported machine credential action" >&2; exit 2 ;; +esac + +[[ -f "$ENV_FILE" ]] || { echo "production compose environment is missing" >&2; exit 1; } +[[ -f "$COMPOSE_FILE" ]] || { echo "production compose file is missing" >&2; exit 1; } + +compose() { docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" "$@"; } + +# `docker volume create` is idempotent and does not inspect or expose content. +docker volume create "$VOLUME" >/dev/null +revision="$(git -C "$REPO_DIR" rev-parse HEAD)" +ASSISTANT_SOURCE_REVISION="$revision" compose build --build-arg "SOURCE_REVISION=$revision" secret-control-plane >/dev/null + +if [[ "$ACTION" == "rotate" ]]; then + # Only bounded, non-secret rotation reasons can reach the audit trail. + reason="${ROTATION_REASON:-owner-requested-rotation}" + case "$reason" in + owner-requested-rotation|exposure-detected) ;; + *) echo "invalid rotation reason" >&2; exit 2 ;; + esac + ASSISTANT_SOURCE_REVISION="$revision" compose --profile secret-control-plane run --rm --no-deps secret-control-plane rotate -reason "$reason" +else + ASSISTANT_SOURCE_REVISION="$revision" compose --profile secret-control-plane run --rm --no-deps secret-control-plane ensure +fi diff --git a/deploy/provision-machine-credential_test.sh b/deploy/provision-machine-credential_test.sh new file mode 100644 index 0000000..2aac842 --- /dev/null +++ b/deploy/provision-machine-credential_test.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Regression: the wrapper accepts only an operation name and never places a +# plaintext credential on a Docker/Compose command line. +script="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)/provision-machine-credential.sh" +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT +mkdir -p "$tmp/bin" "$tmp/repo/deploy" +cp "$script" "$tmp/repo/deploy/provision-machine-credential.sh" +printf 'placeholder\n' > "$tmp/repo/deploy/docker-compose.prod.yml" +printf 'placeholder\n' > "$tmp/env" +cat > "$tmp/bin/docker" <<'SH' +#!/usr/bin/env bash +printf '%s\n' "$*" >> "${CAPTURE:?}" +SH +cat > "$tmp/bin/git" <<'SH' +#!/usr/bin/env bash +printf '0123456789abcdef0123456789abcdef01234567\n' +SH +chmod +x "$tmp/bin/docker" "$tmp/bin/git" "$tmp/repo/deploy/provision-machine-credential.sh" +capture="$tmp/capture" +PATH="$tmp/bin:$PATH" CAPTURE="$capture" REPO_DIR="$tmp/repo" ENV_FILE="$tmp/env" "$tmp/repo/deploy/provision-machine-credential.sh" ensure >/dev/null +grep -qx 'volume create assistant_control_plane_service_secrets' "$capture" +grep -q -- '--profile secret-control-plane run --rm --no-deps secret-control-plane ensure' "$capture" +if grep -Eqi '(token=|password=|secret=|authorization:)' "$capture"; then + echo "provisioning wrapper passed credential material" >&2 + exit 1 +fi diff --git a/deploy/verify-machine-credential.sh b/deploy/verify-machine-credential.sh new file mode 100644 index 0000000..77d5859 --- /dev/null +++ b/deploy/verify-machine-credential.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Safe diagnostics only: artifact existence/readability and mount topology. +# This script never reads or prints credential content. +TOKEN_PATH="/run/control-plane-secrets/control_plane_service_token" +VOLUME="assistant_control_plane_service_secrets" +authorized=(assistant-core-runtime-1 assistant-commit-runtime-1) +unauthorized=(assistant-creator-web-1 assistant-cognitive-worker-1 assistant-research-runtime-1 assistant-continuity-runtime-1 assistant-agent-worker-1) + +for container in "${authorized[@]}"; do + docker inspect "$container" >/dev/null + docker exec "$container" sh -c "test -r '$TOKEN_PATH'" + docker inspect -f '{{range .Mounts}}{{if eq .Name "assistant_control_plane_service_secrets"}}{{.Destination}} {{.RW}}{{end}}{{end}}' "$container" | grep -qx '/run/control-plane-secrets false' +done + +for container in "${unauthorized[@]}"; do + docker inspect "$container" >/dev/null + if docker inspect -f '{{range .Mounts}}{{println .Name}}{{end}}' "$container" | grep -qx "$VOLUME"; then + echo "unauthorized runtime has the control-plane credential mount" >&2 + exit 1 + fi +done + +echo "machine credential mount topology verified" diff --git a/dev/ACTIVE_TASK.json b/dev/ACTIVE_TASK.json index 355aafd..b5b4e01 100644 --- a/dev/ACTIVE_TASK.json +++ b/dev/ACTIVE_TASK.json @@ -1 +1 @@ -{"task_file":"dev/tasks/GEN2-COGNITIVE-003-restore-local-medium-invocation.json","task_id":"GEN2-COGNITIVE-003","task_revision":3} +{"task_file":"dev/tasks/GEN2-SECRETS-001-local-machine-credential-provisioning.json","task_id":"GEN2-SECRETS-001","task_revision":2} diff --git a/dev/tasks/GEN2-SECRETS-001-local-machine-credential-provisioning.json b/dev/tasks/GEN2-SECRETS-001-local-machine-credential-provisioning.json new file mode 100644 index 0000000..acd2686 --- /dev/null +++ b/dev/tasks/GEN2-SECRETS-001-local-machine-credential-provisioning.json @@ -0,0 +1,28 @@ +{ + "task_id": "GEN2-SECRETS-001", + "task_revision": 2, + "architecture_revision": "ARCH-GEN2-000", + "base_repo_revision": "gen2-integration", + "risk_tier": "E", + "intent": "Provide an idempotent, local-only, cryptographically secure machine-credential provisioner and rotation mechanism on the existing protected Docker secret control plane, initially for the delegated control-plane service token, without creating a second semantic owner or exposing a secret value.", + "requirement_ids": ["REQ-GEN2-SECRETS-001-LOCAL-MACHINE-CREDENTIALS", "REQ-GEN2-AUTHORITY-001-DELEGATED-CONTROL-PLANE"], + "allowed_change_scope": { + "modules": ["technical protected secret file backend", "production deployment/bootstrap secret provisioning", "targeted Core/Commit service-authentication mount wiring", "targeted tests and evidence"], + "paths": ["platform/secrets/**", "contracts/secrets/types.go", "cmd/secret-control-plane/**", "cmd/core-runtime/main.go", "cmd/commit-runtime/control_plane_authority.go", "deploy/images/runtime.Dockerfile", "deploy/docker-compose.prod.yml", "deploy/docker-compose.candidate-slot.yml", "deploy/provision-machine-credential.sh", "deploy/provision-machine-credential_test.sh", "deploy/verify-machine-credential.sh", "docs/CREDENTIALS_AND_SECRETS.md", "docs/evidence/**", "development/GEN2_TASK_INDEX.md", "dev/ACTIVE_TASK.json", "dev/tasks/GEN2-SECRETS-001-local-machine-credential-provisioning.json"] + }, + "forbidden_change_scope": { + "paths": ["architecture/ARCHITECTURE_CONSTITUTION.md", "architecture/architecture-registry.yaml", "architecture/architecture-registry.json", "cmd/devctl/**", "contracts/authority/**", "modules/authority/**", "adapters/postgres/**", "database/**", "modules/identity/**", "modules/capability/**", "cmd/cognitive-worker/**", "cmd/creator-web/**", "UI", "V1 retirement", "GEN2-EVOLVE-005", "Gen3/**", "go.mod", "go.sum"] + }, + "allowed_architecture_delta": {"new_cross_module_dependencies": 0, "new_canonical_owners": 0, "new_privileges": 1, "new_third_party_dependencies": 0, "new_database_owner_roles": 0}, + "contracts": {"consume": ["existing CredentialRef and FileResolver", "existing Docker protected-volume deployment mechanism"], "may_change": ["typed SecretPurpose/consumer metadata only if required for the provisioner"]}, + "semantic_owner": "No new semantic owner is introduced. platform/secrets remains a technical bootstrap/resolution mechanism; Identity, Authority, Capability and Configuration ownership remain unchanged.", + "canonical_state": ["credential values live only in protected local artifacts, never in Configuration, Memory, context, PostgreSQL, Compose environment, Git, logs or evidence", "machine authentication is distinct from Authority grants", "metadata/audit is separate from the value and contains no plaintext or reversible material", "the control-plane token is mounted read-only only to Core and Commit runtimes"], + "state_transitions": ["ABSENT -> ACTIVE version one via idempotent CSPRNG provisioning", "ACTIVE -> ROTATING -> ACTIVE new version after atomic artifact replacement and controlled verification", "ACTIVE -> COMPROMISED/REVOKED -> replacement version with audit retained"], + "side_effects_and_privileges": ["a one-shot local control-plane container may create or rotate only its dedicated external Docker volume", "Core and Commit get read-only mounts; all other runtimes receive no mount", "no plaintext environment variable is added"], + "persistence_and_migrations": ["no application database schema or canonical writer changes", "secret metadata and append-only audit reside separately from the secret value inside the protected control-plane volume", "rollback retains prior metadata and revokes only after a verified replacement"], + "failure_retry_restart": ["restart is idempotent and preserves the active artifact", "partial writes are avoided by atomic replacement", "a missing or unreadable artifact fails service authentication closed", "rotation never emits a credential and leaves a valid active artifact on failure"], + "assumptions": ["docker.cin.su permits creation of a dedicated external Docker volume by the existing production deployment control plane", "the runtime image can execute a one-shot local provisioner as the control-plane writer", "the existing protected secret volume pattern is the approved production mechanism"], + "acceptance_scenarios": ["missing credential is generated once with crypto/rand and then reused across restart", "metadata and audit are separate from the value", "Core and Commit mounts are read-only and no other runtime mounts the dedicated token volume", "rotation accepts the new credential and rejects the old credential", "logs and diagnostics redact known secret headers/fields", "a valid service credential alone does not bypass the existing delegated Authority grant checks"], + "required_tests": ["targeted go test ./platform/secrets ./cmd/secret-control-plane", "targeted go vet ./platform/secrets ./cmd/secret-control-plane", "compose config validation", "provisioner shell regression", "preflight", "check-diff", "independent", "git diff --check"], + "terminal_gap_states": ["BLOCKED_BY_ARCHITECTURE_GAP", "BLOCKED_BY_SPEC_GAP", "BLOCKED_BY_MISSING_CAPABILITY", "BLOCKED_BY_CONFLICT", "REQUIRES_MIGRATION_DECISION"] +} diff --git a/development/GEN2_TASK_INDEX.md b/development/GEN2_TASK_INDEX.md index a4ea4a0..77511be 100644 --- a/development/GEN2_TASK_INDEX.md +++ b/development/GEN2_TASK_INDEX.md @@ -1,5 +1,9 @@ # DOMOVOY Gen2 — Task Index +## GEN2-SECRETS-001 — Local Machine Credential Provisioning & Rotation + +Bounded post-M5 remediation. Provides the technical protected-secret control-plane mechanism required by `GEN2-AUTHORITY-001`; it does not change semantic ownership or grant Authority. + Это исполняемый индекс task packets. `ARCH-GEN2-000` соответствует разделу `GEN2-000` Master Plan: префикс `ARCH-` нужен текущему `devctl`, чтобы последующие packets могли ссылаться на него через `architecture_revision`. | Порядок | Task | Milestone | Gate | Base ref | Зависимость | Файл | diff --git a/docs/CREDENTIALS_AND_SECRETS.md b/docs/CREDENTIALS_AND_SECRETS.md index 2409200..d8cb9dd 100644 --- a/docs/CREDENTIALS_AND_SECRETS.md +++ b/docs/CREDENTIALS_AND_SECRETS.md @@ -23,6 +23,10 @@ Each privileged runtime gets only its required secret/capability bindings. `comm The Core SELF learning repository uses the existing `assistant_core_secrets` volume and credential-reference mechanism with `self_role` and `credential://domovoy/self/db-password/v1`. The secret is consumed from the fixed `/run/secrets/self_db_password` path; its value is never placed in Compose environment, Git, logs or ordinary configuration. The role and schema already exist; this wiring does not create a role or broaden privileges. +Delegated non-interactive control-plane work is separately authenticated. The local `secret-control-plane` one-shot control-plane service provisions `control_plane_service_token` with `crypto/rand` into the dedicated external `assistant_control_plane_service_secrets` volume. The token artifact is mode `0400`; metadata and audit are separate protected files and contain no value or reversible fingerprint. Only `core-runtime` and the existing Authority/Commit runtime mount that volume read-only at `/run/control-plane-secrets`; no model, Skill, SELF, creator-web, cognitive-worker or research-runtime receives the mount. Compose carries only the non-secret credential reference `credential://domovoy/control-plane/service-token/v1`. + +The provisioner is idempotent: restart reuses an existing safe active artifact. Rotation creates a new value by atomic replacement, records non-secret metadata/audit, and never accepts a plaintext environment variable. The service token is not a Creator session, cannot impersonate a human, and never grants Authority by itself. Removing or rotating the token disables/refreshes service authentication; revoking the durable Authority grant also blocks new delegated operations without deleting audit history. + Creator authentication secrets are stored in the external Docker volume `assistant_core_secrets` and mounted read-only only at `/run/secrets` in `core-runtime`. The production container environment contains `_FILE` paths, not the secret values. Files are owned by runtime uid 100/gid 101 with mode 0400. `CREATOR_USERNAME` is not secret and remains an environment value. Development may continue to use direct environment values, but a direct value and its matching `_FILE` setting must never be configured together. The PostgreSQL off-host backup passphrase is generated randomly and stored as CurrentUser DPAPI ciphertext at `%LOCALAPPDATA%\Domovoy\postgres-backup-key.dpapi.json`. An atomic copy of that DPAPI ciphertext, never the plaintext passphrase, is retained at `\\nas\MST\codex\_backups\domovoy\keys\postgres-backup-key.dpapi.json`. The passphrase is never stored in Git, the production Docker host, a scheduled-task argument, or NAS plaintext. The NAS backup directory receives only GnuPG AES-256 ciphertext and a non-secret integrity manifest. Recovery therefore requires both the NAS artifacts and the authorized Windows DPAPI profile. diff --git a/docs/evidence/gen2-secrets-001-local-provisioning-2026-08-31.md b/docs/evidence/gen2-secrets-001-local-provisioning-2026-08-31.md new file mode 100644 index 0000000..987c8cf --- /dev/null +++ b/docs/evidence/gen2-secrets-001-local-provisioning-2026-08-31.md @@ -0,0 +1,35 @@ +# GEN2-SECRETS-001 — local machine credential provisioning + +Date: 2026-08-31 + +## Design evidence + +`platform/secrets` is the existing technical protected-file mechanism. This +task extends it without adding a semantic Secrets owner, a database table, or +a Configuration/Memory writer. + +The dedicated Docker volume is named +`assistant_control_plane_service_secrets`. Its sole writer is the one-shot +`secret-control-plane` control-plane container. Its only consumers are +`core-runtime` and `commit-runtime`, mounted read-only at +`/run/control-plane-secrets`. The metadata directory is distinct from the +token artifact and records purpose, owner, version, consumers, status, +generation method, and non-secret audit actions only. + +The provisioner uses `crypto/rand`, writes via an atomic file replacement, +and has no plaintext environment input. It reports only safe operation status. +The data policy marks the artifact as not indexable, embeddable, retrievable, +or model-visible. + +## Local FAST evidence + +The following checks completed successfully before production execution: + +- targeted `go test ./platform/secrets ./cmd/secret-control-plane`; +- targeted `go vet ./platform/secrets ./cmd/secret-control-plane`; +- POSIX shell regression for the provisioning wrapper, executed under Git + Bash because the Windows WSL shim cannot translate the mapped workspace; +- static Docker Compose validation for production and candidate files. + +No credential value, fingerprint, length, header, or plaintext environment +value was read, printed, copied, committed, or included in this evidence.