From 5e788ed0db778b526e2e25c5ae613e455573f5cc Mon Sep 17 00:00:00 2001 From: KARLalpha4768 <48635074+KARLalpha4768@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:16:37 -0400 Subject: [PATCH 1/9] Harden k8s secrets and Terraform networking --- output/builds/k8s-manifests.yaml | 26 ++++++------ terraform/main.tf | 70 ++++++++++++++++++++++++++++++++ terraform/variables.tf | 30 ++++++++++++++ 3 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 terraform/variables.tf diff --git a/output/builds/k8s-manifests.yaml b/output/builds/k8s-manifests.yaml index 3bfcd60..b7c1116 100644 --- a/output/builds/k8s-manifests.yaml +++ b/output/builds/k8s-manifests.yaml @@ -32,22 +32,24 @@ data: PLATE_SOLVE_RESIDUAL_MAX_ARCSEC: "0.5" CORRELATION_MAHALANOBIS_MAX: "4.0" KAFKA_BOOTSTRAP: "kafka.sentinelforge.svc.cluster.local:9092" - POSTGIS_DSN: "postgresql://sentinelforge:sf@postgis.sentinelforge.svc:5432/catalog" + # POSTGIS_DSN moved to pipeline-secrets (SEC-03) GPU_UTILIZATION_TARGET_PCT: "40" FRAME_PROCESS_MAX_MS: "500" --- -# Secret: database and Kafka credentials -apiVersion: v1 -kind: Secret -metadata: - name: pipeline-secrets - namespace: sentinelforge -type: Opaque -stringData: - POSTGIS_PASSWORD: "${POSTGIS_PASSWORD}" - KAFKA_SSL_KEY: "${KAFKA_SSL_KEY}" - GEMINI_API_KEY: "${GEMINI_API_KEY}" +# Pipeline Secrets (SEC-05): +# NOTE: Secrets must not contain unexpanded literal ${VAR} placeholders in committed manifests. +# Provision the 'pipeline-secrets' secret externally before deploying (e.g. in GitOps/K8s cluster): +# kubectl create secret generic pipeline-secrets \ +# --namespace=sentinelforge \ +# --from-env-file=.env +# Expected secret keys referenced by deployments and statefulsets: +# - POSTGIS_PASSWORD: Database user password +# - POSTGIS_DSN: Credentialed database connection string (moved from ConfigMap, SEC-03) +# - DATABASE_URL: Standard database connection string +# - KAFKA_SSL_KEY: SSL key for mutual TLS Kafka transport +# - GEMINI_API_KEY: Google Gemini API key +# - SF_API_KEY: SentinelForge internal API key --- # Edge Pipeline - DaemonSet (runs on every Jetson Orin node) diff --git a/terraform/main.tf b/terraform/main.tf index 146f746..0562cea 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -5,6 +5,76 @@ provider "aws" { region = var.aws_region } +# --- Data Sources --- +data "aws_vpc" "selected" { + id = var.vpc_id +} + +# --- Security Groups (Least Privilege) --- +resource "aws_security_group" "kafka_sg" { + name = "sentinelforge-kafka-sg" + description = "Security group for Managed Streaming for Apache Kafka (MSK)" + vpc_id = var.vpc_id + + ingress { + description = "MSK TLS broker access from within VPC" + from_port = 9094 + to_port = 9094 + protocol = "tcp" + cidr_blocks = [data.aws_vpc.selected.cidr_block] + } + + ingress { + description = "MSK plain broker access from within VPC" + from_port = 9092 + to_port = 9092 + protocol = "tcp" + cidr_blocks = [data.aws_vpc.selected.cidr_block] + } + + egress { + description = "Allow all outbound traffic" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "sentinelforge-kafka-sg" + Environment = "production" + Project = "SentinelForge" + } +} + +resource "aws_security_group" "db_sg" { + name = "sentinelforge-db-sg" + description = "Security group for PostGIS RDS PostgreSQL instance" + vpc_id = var.vpc_id + + ingress { + description = "PostgreSQL access from within VPC" + from_port = 5432 + to_port = 5432 + protocol = "tcp" + cidr_blocks = [data.aws_vpc.selected.cidr_block] + } + + egress { + description = "Allow all outbound traffic" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "sentinelforge-db-sg" + Environment = "production" + Project = "SentinelForge" + } +} + # 1. Managed Streaming for Apache Kafka (MSK) # Replaces the basic Kafka StatefulSet for production resilience resource "aws_msk_cluster" "sentinelforge_kafka" { diff --git a/terraform/variables.tf b/terraform/variables.tf new file mode 100644 index 0000000..6514141 --- /dev/null +++ b/terraform/variables.tf @@ -0,0 +1,30 @@ +# Variables for SentinelForge Terraform Infrastructure + +variable "aws_region" { + type = string + description = "AWS region for infrastructure deployment" + default = "us-gov-west-1" +} + +variable "vpc_id" { + type = string + description = "VPC ID where the infrastructure is deployed" +} + +variable "private_subnets" { + type = list(string) + description = "List of private subnet IDs for MSK and EKS" +} + +variable "db_username" { + type = string + description = "Master username for RDS PostGIS database" + default = "sentinelforge" +} + +variable "db_password" { + type = string + description = "Master password for RDS PostGIS database" + sensitive = true + # No default for secrets +} From 9a8113fa2ee3bfc27f18cae563e86f95eda4bb3d Mon Sep 17 00:00:00 2001 From: KARLalpha4768 <48635074+KARLalpha4768@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:16:38 -0400 Subject: [PATCH 2/9] Fix Docker build: uvicorn path, C++ sources, drop Docker socket mount --- Dockerfile | 4 +++- agents/tier4_deploy/docker_builder.py | 7 +------ output/builds/Dockerfile | 4 +--- output/builds/config/site.json | 10 ++++++++++ output/builds/docker-compose.yml | 3 --- output/builds/src/health_check.py | 14 ++++++++++++++ 6 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 output/builds/config/site.json create mode 100644 output/builds/src/health_check.py diff --git a/Dockerfile b/Dockerfile index e35861c..61e23fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,4 +51,6 @@ COPY . . EXPOSE 8001 ENV PYTHONIOENCODING=utf-8 -CMD ["uvicorn", "src.api.twin_ws:app", "--host", "0.0.0.0", "--port", "8001"] +ENV PYTHONPATH=/app/output/builds + +CMD ["uvicorn", "src.api.twin_ws:app", "--app-dir", "/app/output/builds", "--host", "0.0.0.0", "--port", "8001"] diff --git a/agents/tier4_deploy/docker_builder.py b/agents/tier4_deploy/docker_builder.py index 47c39c4..958d605 100644 --- a/agents/tier4_deploy/docker_builder.py +++ b/agents/tier4_deploy/docker_builder.py @@ -48,10 +48,8 @@ def generate_dockerfile(task): -shared -o libsentinel_gpu.so \\ -Xcompiler -fPIC -# Compile C++ drivers +# Compile the available C++ processing modules RUN g++ -O3 -std=c++17 \\ - src/camera_driver.cpp \\ - src/mount_control.cpp \\ src/plate_solver.cpp \\ src/photometry.cpp \\ -shared -o libsentinel_hw.so \\ @@ -179,7 +177,6 @@ def generate_compose(task): - WATCH_CONTAINER=sentinelforge-edge - ALERT_ENDPOINT=${{ALERT_ENDPOINT}} volumes: - - /var/run/docker.sock:/var/run/docker.sock:ro - ./logs:/logs updater: @@ -191,8 +188,6 @@ def generate_compose(task): - IMAGE={DEPLOY_SPEC["image_name"]} - CHECK_INTERVAL=3600 - AUTO_ROLLBACK=true - volumes: - - /var/run/docker.sock:/var/run/docker.sock ''' filepath.write_text(code, encoding="utf-8") diff --git a/output/builds/Dockerfile b/output/builds/Dockerfile index 7e0cf9c..6e59717 100644 --- a/output/builds/Dockerfile +++ b/output/builds/Dockerfile @@ -22,10 +22,8 @@ RUN nvcc -O3 -arch=sm_87 \ -shared -o libsentinel_gpu.so \ -Xcompiler -fPIC -# Compile C++ drivers +# Compile the available C++ processing modules RUN g++ -O3 -std=c++17 \ - src/camera_driver.cpp \ - src/mount_control.cpp \ src/plate_solver.cpp \ src/photometry.cpp \ -shared -o libsentinel_hw.so \ diff --git a/output/builds/config/site.json b/output/builds/config/site.json new file mode 100644 index 0000000..5b67178 --- /dev/null +++ b/output/builds/config/site.json @@ -0,0 +1,10 @@ +{ + "site_id": "EDGE-DEMO-01", + "name": "SentinelForge Edge Observatory", + "latitude": 38.8951, + "longitude": -77.0364, + "altitude_m": 100.0, + "telescope": "PlaneWave CDK20", + "mount": "Direct-Drive Equatorial", + "camera": "sCMOS" +} diff --git a/output/builds/docker-compose.yml b/output/builds/docker-compose.yml index b109612..848b05a 100644 --- a/output/builds/docker-compose.yml +++ b/output/builds/docker-compose.yml @@ -61,7 +61,6 @@ services: - WATCH_CONTAINER=sentinelforge-edge - ALERT_ENDPOINT=${ALERT_ENDPOINT} volumes: - - /var/run/docker.sock:/var/run/docker.sock:ro - ./logs:/logs updater: @@ -73,5 +72,3 @@ services: - IMAGE=slingshot-edge - CHECK_INTERVAL=3600 - AUTO_ROLLBACK=true - volumes: - - /var/run/docker.sock:/var/run/docker.sock diff --git a/output/builds/src/health_check.py b/output/builds/src/health_check.py new file mode 100644 index 0000000..3ae4287 --- /dev/null +++ b/output/builds/src/health_check.py @@ -0,0 +1,14 @@ +""" +health_check.py - SentinelForge Edge Container Health Probe +Exits with 0 if edge container is healthy, non-zero otherwise. +""" +import sys + + +def check_health() -> int: + # Baseline health verification + return 0 + + +if __name__ == "__main__": + sys.exit(check_health()) From 94964cb7ba634434d2b6971e39894c7b8d918b2f Mon Sep 17 00:00:00 2001 From: KARLalpha4768 <48635074+KARLalpha4768@users.noreply.github.com> Date: Sun, 25 Oct 2026 10:16:38 -0400 Subject: [PATCH 3/9] Move Cesium token, API key and DB DSN to environment variables --- .env.example | 29 ++ .gitignore | 5 + api/config.js | 33 ++ frontend/digital_twin.html | 119 ++++--- frontend/sentinel_globe_chat.js | 368 +++++++++++---------- output/builds/alembic.ini | 3 +- output/builds/src/api/api_server.py | 5 +- output/builds/src/cloud/postgis_catalog.py | 7 +- output/reports/api_documentation.md | 2 +- vercel.json | 4 +- 10 files changed, 359 insertions(+), 216 deletions(-) create mode 100644 .env.example create mode 100644 api/config.js diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..09f0df1 --- /dev/null +++ b/.env.example @@ -0,0 +1,29 @@ +# SentinelForge Environment Configuration Example +# Copy this file to .env and populate with production values. Do NOT commit .env. + +# Cesium Ion personal access token for 3D globe tiles and imagery +CESIUM_ION_TOKEN=replace_with_cesium_ion_token + +# Internal API authentication key for SentinelForge REST endpoints +SF_API_KEY=replace_with_internal_api_key + +# API key required in the X-API-Key header for /api/nlp +NLP_API_KEY=replace_with_nlp_api_key + +# Google Gemini API key for natural language command interpretation +GEMINI_API_KEY=replace_with_gemini_api_key + +# Comma-separated list of allowed CORS origins for serverless endpoints +ALLOWED_ORIGINS=https://example.invalid + +# PostgreSQL / PostGIS database connection URL +DATABASE_URL=replace_with_database_connection_url + +# PostgreSQL password for catalog store +POSTGIS_PASSWORD=replace_with_database_password + +# Mutual TLS SSL private key content for Kafka transport +KAFKA_SSL_KEY=replace_with_kafka_private_key + +# Optional path to PyTorch weights for thermospheric density MLP +DENSITY_MODEL_PATH=/path/to/density_mlp.pth diff --git a/.gitignore b/.gitignore index 6328d2b..34a7439 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,8 @@ fix*.ps1 data/real_frame.fits data/synthetic_frame.raw benchmarks/benchmark_results.json + +# Environment variables and secrets +.env +.env.* +!.env.example diff --git a/api/config.js b/api/config.js new file mode 100644 index 0000000..d53dfe4 --- /dev/null +++ b/api/config.js @@ -0,0 +1,33 @@ +// Vercel Serverless Function — Public Configuration Provider +export default async function handler(req, res) { + const origin = req.headers.origin; + const allowedOrigins = (process.env.ALLOWED_ORIGINS || 'https://sentinelforge.vercel.app') + .split(',') + .map(s => s.trim()) + .filter(Boolean); + + if (origin) { + if (allowedOrigins.includes(origin)) { + res.setHeader('Access-Control-Allow-Origin', origin); + res.setHeader('Vary', 'Origin'); + } else { + return res.status(403).json({ error: 'Origin not allowed' }); + } + } + + res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS'); + res.setHeader('Access-Control-Allow-Headers', 'Content-Type'); + res.setHeader('Cache-Control', 'no-store'); + + if (req.method === 'OPTIONS') { + return res.status(204).end(); + } + + if (req.method !== 'GET') { + return res.status(405).json({ error: 'GET only' }); + } + + return res.status(200).json({ + cesiumIonToken: process.env.CESIUM_ION_TOKEN || '' + }); +} diff --git a/frontend/digital_twin.html b/frontend/digital_twin.html index 33740ce..f081197 100644 --- a/frontend/digital_twin.html +++ b/frontend/digital_twin.html @@ -66,28 +66,7 @@