From 5503ace396e7ab47d8552c5e1db9b261acb9848c Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Sun, 22 Nov 2026 18:06:36 +0000 Subject: [PATCH 01/16] Cohorter dir restructure. --- apps/cohorter/.gitignore | 5 +- apps/cohorter/NL2DSL/README.md | 8 +- apps/cohorter/README.md | 28 ++++--- apps/cohorter/WebAPP/README.md | 8 +- apps/cohorter/WebAPP/client-react/README.md | 8 +- .../WebAPP/client-react/vite.config.js | 11 +-- apps/cohorter/{ => docker}/docker-compose.yml | 8 +- .../{.env.example => env/cohorter.env} | 11 +-- .../.github/workflows/helm-smoke-test.yml | 80 ------------------- apps/jupyter-hub/README.md | 2 +- 10 files changed, 44 insertions(+), 125 deletions(-) rename apps/cohorter/{ => docker}/docker-compose.yml (96%) rename apps/cohorter/{.env.example => env/cohorter.env} (80%) delete mode 100644 apps/jupyter-hub/.github/workflows/helm-smoke-test.yml diff --git a/apps/cohorter/.gitignore b/apps/cohorter/.gitignore index 2e5dc746..41c0dea9 100644 --- a/apps/cohorter/.gitignore +++ b/apps/cohorter/.gitignore @@ -3,7 +3,9 @@ # ========================= .env .env.* -!.env.example +!/env/ +/env/* +!/env/cohorter.env *.key *.pem *.p12 @@ -50,7 +52,6 @@ __pycache__/ *$py.class .venv/ venv/ -env/ pip-wheel-metadata/ .pytest_cache/ .mypy_cache/ diff --git a/apps/cohorter/NL2DSL/README.md b/apps/cohorter/NL2DSL/README.md index 438ca681..6ca9fd68 100644 --- a/apps/cohorter/NL2DSL/README.md +++ b/apps/cohorter/NL2DSL/README.md @@ -4,7 +4,7 @@ This folder contains the **NL2DSL** service for the Cohorter application. NL2DSL accepts a **natural-language cohort request** and uses an LLM (via **Ollama**) to translate it into a **JSON cohort DSL**. It can optionally call the **MedCAT** service for clinical concept annotation / normalization (depending on your server implementation). -This service is designed to run as part of the full stack (recommended) using the repo-root `docker-compose.yml`. +This service is designed to run as part of the full stack (recommended) using [`docker/docker-compose.yml`](../docker/docker-compose.yml). --- @@ -19,10 +19,10 @@ This service is designed to run as part of the full stack (recommended) using th ## Run with Docker Compose (recommended) -From the **repo root**: +From `apps/cohorter/docker/`, using `env/cohorter.env`: ```bash -docker compose up --build nl2dsl +docker compose --env-file ../env/cohorter.env up --build nl2dsl ``` NL2DSL API will be available at: @@ -110,7 +110,7 @@ node server.js ### Ollama not reachable - If using Docker Compose with included Ollama: confirm `ollama` container is up ```bash - docker compose ps + docker compose --env-file ../env/cohorter.env ps ``` - Check Ollama is responding: ```bash diff --git a/apps/cohorter/README.md b/apps/cohorter/README.md index b46ed4f2..82ffe562 100644 --- a/apps/cohorter/README.md +++ b/apps/cohorter/README.md @@ -18,6 +18,8 @@ A lightweight cohort discovery application that combines: - `WebAPP/` Full application (frontend + backend) providing the UI and orchestration of the workflow. +- `docker/`: Docker Compose configuration for the full stack. + --- ## Quick start (Docker Compose) @@ -27,16 +29,18 @@ A lightweight cohort discovery application that combines: - (Optional) GPU setup if you want Ollama GPU acceleration (depends on your host OS) ### 1) Build and start all services -From this directory: +From `apps/cohorter/`, configure [`env/cohorter.env`](env/cohorter.env), then run +Compose from `docker/`: ```bash -docker compose up --build +cd docker +docker compose --env-file ../env/cohorter.env up --build ``` Or run in background: ```bash -docker compose up --build -d +docker compose --env-file ../env/cohorter.env up --build -d ``` ### 2) Access the app @@ -49,7 +53,7 @@ docker compose up --build -d ## Configuration -### NL2DSL environment variables (via docker-compose.yml) +### NL2DSL environment variables (via docker/docker-compose.yml) NL2DSL uses: - `OLLAMA_URL` (default in compose: `http://ollama:11434/api/generate`) @@ -62,13 +66,13 @@ WebAPP uses: - `NL2DSL_URL` (default: `http://cohorter-nl2dsl:3002`) ### WebAPP random data generation (optional) -The `WebAPP/Dockerfile` supports a build arg `random` to generate random data: +Set the runtime `RANDOM_DATA` variable to generate random data: ```bash -WEBAPP_RANDOM=true docker compose up --build +RANDOM_DATA=true docker compose --env-file ../env/cohorter.env up --build ``` -(If you don’t need random data generation, keep it `false`.) +Set `RANDOM_DATA=false` in `env/cohorter.env` to disable random data generation. --- @@ -86,7 +90,7 @@ Each folder contains its own `Dockerfile` and scripts. ## Notes on models and licensing - MedCAT model packs and any potentially sensitive data **must not** be committed to the repository. -- Ollama models are stored in a Docker named volume by default (`ollama:` in `docker-compose.yml`) so they persist across restarts. +- Ollama models are stored in a Docker named volume by default (`ollama:` in `docker/docker-compose.yml`) so they persist across restarts. --- @@ -94,20 +98,20 @@ Each folder contains its own `Dockerfile` and scripts. ### Rebuild everything cleanly ```bash -docker compose down -docker compose up --build +docker compose --env-file ../env/cohorter.env down +docker compose --env-file ../env/cohorter.env up --build ``` ### Remove Ollama downloaded models (if needed) This deletes the named volume that stores Ollama models: ```bash -docker compose down -v +docker compose --env-file ../env/cohorter.env down -v ``` ### Check logs ```bash -docker compose logs -f +docker compose --env-file ../env/cohorter.env logs -f ``` --- diff --git a/apps/cohorter/WebAPP/README.md b/apps/cohorter/WebAPP/README.md index 9b9e9153..7879a4c6 100644 --- a/apps/cohorter/WebAPP/README.md +++ b/apps/cohorter/WebAPP/README.md @@ -8,7 +8,7 @@ This webapp is a cohort app for users to obtain the number of patients satifying Other runtime dependencies include [ECharts](https://echarts.apache.org/en/index.html) for charts and [popper.js](https://popper.js.org/) for tooltips. -A GitHub Packages token with `read:packages` scope is required to install `@cogstack/frontend-common-react`. Set it in a `.env` file at the `apps/cohorter/` root (see `.env.example`) or export it in your shell: +A GitHub Packages token with `read:packages` scope is required to install `@cogstack/frontend-common-react`. Set it in [`env/cohorter.env`](../env/cohorter.env) for Compose or export it in your shell: ```bash export NPM_TOKEN=ghp_your_token_here @@ -44,7 +44,7 @@ There is a script `gen_random_data.js` in `server/data/` folder to generate the Please make sure to have the six data files ready in the `server/data/` folder before starting the server. To start the server, in the app folder run `cd server && npm install && npm run start`. -The recommended way to run the full stack (webapp + NL2DSL + MedCAT + Ollama) is via `docker-compose` from the `apps/cohorter/` root — see the root-level README and `.env.example` for details. The `NPM_TOKEN` is passed as a BuildKit secret; set it in the `.env` file before building. +The recommended way to run the full stack (webapp + NL2DSL + MedCAT + Ollama) uses [`docker/docker-compose.yml`](../docker/docker-compose.yml) from `apps/cohorter/docker/` — see the app-root README and [`env/cohorter.env`](../env/cohorter.env) for details. The `NPM_TOKEN` is passed as a BuildKit secret. ### Environment variables @@ -92,10 +92,10 @@ In Kubernetes these are set as env vars on the webapp container (via helm `cogst ### Run using Docker with random data -Set `RANDOM_DATA=true` in your `.env` file (or leave it unset — it defaults to `true`), then from the `apps/cohorter/` root: +Set `RANDOM_DATA=true` in `env/cohorter.env` (or leave it unset — it defaults to `true`), then from `apps/cohorter/docker/`: ```bash -docker compose up --build +docker compose --env-file ../env/cohorter.env up --build ``` The webapp will be available at `http://localhost:3000`. diff --git a/apps/cohorter/WebAPP/client-react/README.md b/apps/cohorter/WebAPP/client-react/README.md index 65c19739..b406fcb2 100644 --- a/apps/cohorter/WebAPP/client-react/README.md +++ b/apps/cohorter/WebAPP/client-react/README.md @@ -14,18 +14,14 @@ It keeps the existing Alpine-style template/data model behaviour, while using Re ## Requirements -- Node.js 18+ +- Node.js 20.12+ - npm - A GitHub Packages token with `read:packages` scope (to install `@cogstack/frontend-common-react`) - Cohorter backend server running at `http://localhost:3000` (proxied automatically in dev) ## Environment variables -A single `.env` file at the **`apps/cohorter/` root** (one level up from `WebAPP/`) is shared between Vite and `docker-compose`. Copy `.env.example` there and fill in values: - -```bash -cp ../../.env.example ../../.env -``` +Configure [`apps/cohorter/env/cohorter.env`](../../env/cohorter.env), shared by Vite and Docker Compose. | Variable | Required | Description | |---|---|---| diff --git a/apps/cohorter/WebAPP/client-react/vite.config.js b/apps/cohorter/WebAPP/client-react/vite.config.js index a2c57ea7..a704acc0 100644 --- a/apps/cohorter/WebAPP/client-react/vite.config.js +++ b/apps/cohorter/WebAPP/client-react/vite.config.js @@ -1,17 +1,18 @@ +import { existsSync } from 'node:fs'; +import { loadEnvFile } from 'node:process'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; // Express server port (same origin in production; proxied in dev) const API_ORIGIN = 'http://localhost:3000'; -// Point Vite at the apps/cohorter/ root so that it reads the same .env -// as docker-compose, eliminating the need for a separate client-react/.env. -// Both `npm run dev` (Vite) and `docker-compose build` resolve vars from one file. -const ENV_DIR = '../../'; +// Share the named environment file with Compose; image builds can omit it. +const ENV_FILE = new URL('../../env/cohorter.env', import.meta.url); +if (existsSync(ENV_FILE)) loadEnvFile(ENV_FILE); export default defineConfig({ plugins: [react()], - envDir: ENV_DIR, + envDir: false, build: { outDir: 'dist', diff --git a/apps/cohorter/docker-compose.yml b/apps/cohorter/docker/docker-compose.yml similarity index 96% rename from apps/cohorter/docker-compose.yml rename to apps/cohorter/docker/docker-compose.yml index f93dc50c..1139aa04 100644 --- a/apps/cohorter/docker-compose.yml +++ b/apps/cohorter/docker/docker-compose.yml @@ -1,3 +1,5 @@ +name: cohorter + services: ollama: image: ollama/ollama:latest @@ -38,7 +40,7 @@ services: nl2dsl: build: - context: ./NL2DSL + context: ../NL2DSL container_name: cohorter-nl2dsl ports: - "3002:3002" @@ -54,7 +56,7 @@ services: webapp: build: - context: ./WebAPP + context: ../WebAPP secrets: - npm_token args: @@ -84,7 +86,7 @@ services: # Mount your data directory here. It should contain either: # - snomed_terms_data.tar.gz (will be auto-extracted on startup), or # - pre-extracted files: snomed_terms.json (SNOMED term lookup by Concept Unique Identifier) and cui_pt2ch.json (SNOMED CT ontology hierachy map). - - ./WebAPP/server/data:/usr/src/app/server/data + - ../WebAPP/server/data:/usr/src/app/server/data depends_on: - medcat - nl2dsl diff --git a/apps/cohorter/.env.example b/apps/cohorter/env/cohorter.env similarity index 80% rename from apps/cohorter/.env.example rename to apps/cohorter/env/cohorter.env index 9191324f..121bff34 100644 --- a/apps/cohorter/.env.example +++ b/apps/cohorter/env/cohorter.env @@ -1,10 +1,5 @@ -# Single env file for cogstack-cohorter. -# Copy to .env and fill in values before running docker-compose or npm run dev. -# .env is gitignored — never commit it. -# -# This file is read by: -# • docker-compose — variable substitution for build args and runtime env -# • Vite dev server — VITE_* vars picked up via envDir in vite.config.js +# Shared Cohorter configuration for Docker Compose and the Vite dev server. +# Run from docker/: docker compose --env-file ../env/cohorter.env up --build # ── Required ───────────────────────────────────────────────────────────────── @@ -12,7 +7,7 @@ # Used as a BuildKit secret at image build time to install @cogstack/frontend-common-react. # Also needed locally for `npm install` in WebAPP/client-react/ (export NPM_TOKEN in your shell, # or ensure it is set here so docker-compose can pass it through). -NPM_TOKEN=ghp_your_token_here +NPM_TOKEN= # ── OAuth2 proxy paths (Vite build-time, baked into the client bundle) ─────── # Only override if your deployment uses non-standard oauth2-proxy routes. diff --git a/apps/jupyter-hub/.github/workflows/helm-smoke-test.yml b/apps/jupyter-hub/.github/workflows/helm-smoke-test.yml deleted file mode 100644 index 50ded414..00000000 --- a/apps/jupyter-hub/.github/workflows/helm-smoke-test.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: helm-smoke-test - -permissions: - contents: read - -on: - pull_request: - paths: - - "charts/**" - - "env/**" - - "config/**" - - "security/**" - - "scripts/helm_k8s_smoke_test.sh" - - "README.md" - - ".github/workflows/helm-smoke-test.yml" - push: - branches: - - "main" - paths: - - "charts/**" - - "env/**" - - "config/**" - - "security/**" - - "scripts/helm_k8s_smoke_test.sh" - - "README.md" - - ".github/workflows/helm-smoke-test.yml" - workflow_dispatch: - -concurrency: - group: helm-smoke-${{ github.ref }} - cancel-in-progress: true - -jobs: - smoke: - runs-on: ubuntu-22.04 - timeout-minutes: 15 - - steps: - - name: Checkout repository - uses: actions/checkout@v7 - - - name: Setup Helm - uses: azure/setup-helm@v5 - - - name: Setup kubectl - uses: azure/setup-kubectl@v5 - - - name: Run Helm and Kubernetes smoke tests - shell: bash - run: | - set -euo pipefail - bash scripts/helm_k8s_smoke_test.sh - - - name: Render manifests for diagnostics - if: failure() - shell: bash - run: | - set -euo pipefail - mkdir -p /tmp/helm-smoke - helm template cogstack-jupyterhub ./charts/cogstack-jupyterhub > /tmp/helm-smoke/render-default.yaml || true - helm template cogstack-jupyterhub ./charts/cogstack-jupyterhub \ - --set envFiles.useBundled=false \ - --set hubFiles.useBundled=false \ - --set securityFiles.useBundled=false \ - --set-file envFiles.jupyter=env/jupyter.env \ - --set-file envFiles.general=env/general.env \ - --set-file hubFiles.jupyterhubConfig=config/jupyterhub_config.py \ - --set-file hubFiles.userlist=config/userlist \ - --set-file hubFiles.teamlist=config/teamlist \ - --set-file securityFiles.cookieSecret=config/jupyterhub_cookie_secret \ - --set-file securityFiles.tlsKey=security/nifi.key \ - --set-file securityFiles.tlsCert=security/nifi.pem \ - > /tmp/helm-smoke/render-set-file.yaml || true - - - name: Upload smoke diagnostics - if: failure() - uses: actions/upload-artifact@v7 - with: - name: helm-smoke-diagnostics - path: /tmp/helm-smoke diff --git a/apps/jupyter-hub/README.md b/apps/jupyter-hub/README.md index 8953ab81..e11c9a49 100644 --- a/apps/jupyter-hub/README.md +++ b/apps/jupyter-hub/README.md @@ -166,7 +166,7 @@ Run local smoke checks for Helm/Kubernetes manifests: bash scripts/helm_k8s_smoke_test.sh ``` -CI also runs this via [`.github/workflows/helm-smoke-test.yml`](./.github/workflows/helm-smoke-test.yml) for changes affecting chart/env/config/security files. +CI chart validation lives in the shared [Helm workflow](../../.github/workflows/build_helm_charts.yml). ## Access and account control From 4984a7cba2b2361c00daf7613613b1d6cd35df65 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Sun, 22 Nov 2026 19:34:42 +0000 Subject: [PATCH 02/16] Cleaned nifi dir. --- apps/nifi/README.md | 11 +- apps/nifi/docker/Makefile | 500 +----------------------- apps/nifi/docker/docker-compose.dev.yml | 95 +---- apps/nifi/docker/export_env_vars.sh | 47 +-- 4 files changed, 29 insertions(+), 624 deletions(-) diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 0c4418fc..4b1463e3 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -69,12 +69,11 @@ The Kubernetes charts live in and [`deployment/charts/nginx`](../../deployment/charts/nginx/README.md). Their READMEs describe the required environment ConfigMaps, TLS Secrets and storage. -The NiFi build context and resource mounts in `docker/docker-compose.dev.yml` -point to this application directory. The Compose file, Makefile and environment -loader were brought over from the wider CogStack deployment and still reference -supporting configuration, security certificates, services and helper scripts. -Those dependencies need to be migrated or supplied before using the full -deployment helpers. The image build above works independently of them. +`docker/docker-compose.dev.yml` runs NiFi and the shared NGINX application from +`apps/nginx`. The environment loader uses the app's `env/general.env`, +`env/nifi.env`, `env/network_settings.env` and `env/nginx.env` files. Supply those +local files, NiFi credentials and TLS certificates before using the Compose +helpers. The image build above works independently of them. Mutable configuration, data repositories, processor logs and databases belong in deployment-owned storage. The image health check expects the configured TLS diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index e8c5cb79..df818d31 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -3,24 +3,10 @@ SHELL := /usr/bin/env bash DC_START_CMD := up -d DC_STOP_CMD := stop -DC_DOWN_CMD := down -REMOTE_COMPOSE_FILE ?= services.yml -REMOTE_SSH_KEY ?= -REMOTE_SSH_OPTS ?= -REMOTE_SSH_KEY_ARG = $(if $(strip $(REMOTE_SSH_KEY)),-i $(REMOTE_SSH_KEY),) -SECURITY_DIR ?= ../security -SECURITY_SCRIPTS_DIR ?= $(SECURITY_DIR)/scripts -SECURITY_CERTIFICATES_DIR ?= $(SECURITY_DIR)/certificates -SECURITY_ENV_DIR ?= $(SECURITY_DIR)/env -OPENSEARCH_CERT_NAMES ?= -COGSTACK_CONFIG_DIR ?= -export COGSTACK_CONFIG_DIR - define WITH_ENV source ./export_env_vars.sh || exit $$?; endef -# list all make targets in this file help: ## List available targets with descriptions @echo "Available targets:" @awk '\ @@ -28,11 +14,8 @@ help: ## List available targets with descriptions if (target ~ /^start-/) return "Start a service or service group"; \ if (target ~ /^stop-/) return "Stop a service or service group"; \ if (target ~ /^delete-/) return "Delete related containers/images/volumes"; \ - if (target ~ /^git-/) return "Run a git helper script"; \ if (target == "load-env") return "Load variables from export_env_vars.sh"; \ if (target == "show-env") return "Print current environment variables"; \ - if (target == "down-all") return "Stop all services from services.yml"; \ - if (target == "cleanup") return "Stop all services and remove volumes"; \ return "(no description)"; \ } \ /^[a-zA-Z0-9][a-zA-Z0-9_-]*:/ { \ @@ -57,218 +40,19 @@ help: ## List available targets with descriptions } \ ' $(MAKEFILE_LIST) | sort | awk -F '\t' '{printf " %-28s %s\n", $$1, $$2}' -.PHONY: help - -# utility commands - -git-freeze-security: ## Apply restricted git settings for safer shell operations - @../scripts/git_freeze_security.sh - -git-unfreeze-security: ## Revert restricted git settings - @../scripts/git_unfreeze_security.sh - -git-init-submodules: ## Initialize submodules at the commits recorded by this checkout - @../scripts/git_init_submodules_in_repo.sh - -git-update-submodules: ## Explicitly upgrade direct submodules for review (never stages or commits) - @../scripts/git_update_submodules_in_repo.sh - -.PHONY: git-init-submodules git-update-submodules - load-env: ## Load variables from export_env_vars.sh in a subshell $(WITH_ENV) echo "Environment variables loaded." show-env: ## Print sorted environment variables after loading export_env_vars.sh ${WITH_ENV} >/dev/null 2>&1; printenv | sort -init-security-root-ca: ## Generate the shared root CA only when no CA material exists - @set -euo pipefail; \ - $(WITH_ENV) \ - source "$${COGSTACK_CERTIFICATES_GENERAL_ENV_FILE}"; \ - root_dir="$(SECURITY_CERTIFICATES_DIR)/root"; \ - if [[ -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}.key" \ - && -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}.pem" \ - && -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}.p12" \ - && -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}-keystore.jks" \ - && -f "$$root_dir/$${ROOT_CERTIFICATE_NAME}-truststore.jks" ]]; then \ - echo "Root CA certificates already exist; leaving them unchanged."; \ - elif [[ -d "$$root_dir" && -n "$$(find "$$root_dir" -mindepth 1 -maxdepth 1 -print -quit)" ]]; then \ - echo "ERROR: $$root_dir contains an incomplete root CA set." >&2; \ - echo "Preserve and repair or explicitly replace that CA before rerunning this target." >&2; \ - exit 1; \ - else \ - echo "Generating the shared root CA certificates..."; \ - (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_root_ca_cert.sh); \ - fi - -init-security-nifi: init-security-opensearch init-security-postgresql ## Prepare NiFi certificates and its search/database certificate inputs - @set -euo pipefail; \ - nifi_dir="$(SECURITY_CERTIFICATES_DIR)/nifi"; \ - if [[ -f "$$nifi_dir/nifi.key" \ - && -f "$$nifi_dir/nifi.pem" \ - && -f "$$nifi_dir/nifi.p12" \ - && -f "$$nifi_dir/nifi-keystore.jks" \ - && -f "$$nifi_dir/nifi-truststore.jks" ]]; then \ - echo "NiFi certificates already exist; leaving them unchanged."; \ - else \ - echo "Generating NiFi certificates..."; \ - (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_nifi_certs.sh); \ - fi - -init-security-gitea: init-security-root-ca ## Generate a dedicated Gitea leaf certificate when it is missing - @set -euo pipefail; \ - gitea_dir="$(SECURITY_CERTIFICATES_DIR)/gitea"; \ - if [[ -f "$$gitea_dir/gitea.key" \ - && -f "$$gitea_dir/gitea.pem" \ - && -f "$$gitea_dir/gitea.crt" ]]; then \ - echo "Gitea leaf certificate already exists; leaving it unchanged."; \ - else \ - echo "Generating Gitea leaf certificate..."; \ - (cd "$(SECURITY_SCRIPTS_DIR)" && bash ./create_gitea_certs.sh); \ - fi - -init-security-opensearch: init-security-root-ca ## Generate OpenSearch node, client, and admin certificates when missing - @set -euo pipefail; \ - $(WITH_ENV) \ - source "$${COGSTACK_CERTIFICATES_ELASTICSEARCH_ENV_FILE}"; \ - if [[ -n "$(strip $(OPENSEARCH_CERT_NAMES))" ]]; then \ - read -r -a node_names <<< "$(strip $(OPENSEARCH_CERT_NAMES))"; \ - else \ - node_names=("$$ES_INSTANCE_NAME_1" "$$ES_INSTANCE_NAME_2" "$$ES_INSTANCE_NAME_3"); \ - fi; \ - opensearch_dir="$(SECURITY_CERTIFICATES_DIR)/elastic/opensearch"; \ - node_certificates_missing=0; \ - for node_name in "$${node_names[@]}"; do \ - node_dir="$$opensearch_dir/elasticsearch/$$node_name"; \ - for suffix in .crt .key .p12 -keystore.jks -truststore.key; do \ - if [[ ! -f "$$node_dir/$$node_name$$suffix" ]]; then \ - node_certificates_missing=1; \ - break 2; \ - fi; \ - done; \ - done; \ - if [[ ! -f "$$opensearch_dir/elastic-stack-ca.crt.pem" ]]; then \ - node_certificates_missing=1; \ - fi; \ - if (( node_certificates_missing )); then \ - echo "Generating OpenSearch node certificates for: $${node_names[*]}"; \ - (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_opensearch_node_cert.sh "$${node_names[@]}"); \ - else \ - echo "OpenSearch node certificates already exist; leaving them unchanged."; \ - fi; \ - if [[ -f "$$opensearch_dir/admin.crt" \ - && -f "$$opensearch_dir/admin.key.pem" \ - && -f "$$opensearch_dir/$${ES_CLIENT_CERT_NAME}.pem" \ - && -f "$$opensearch_dir/$${ES_CLIENT_CERT_NAME}.key" ]]; then \ - echo "OpenSearch client and admin certificates already exist; leaving them unchanged."; \ - else \ - echo "Generating OpenSearch client and admin certificates..."; \ - (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_opensearch_client_admin_certs.sh); \ - fi - -init-security-elasticsearch: ## Generate native Elasticsearch certificates when the output directory is absent - @set -euo pipefail; \ - $(WITH_ENV) \ - source "$${COGSTACK_CERTIFICATES_ELASTICSEARCH_ENV_FILE}"; \ - elasticsearch_dir="$(SECURITY_CERTIFICATES_DIR)/elastic/elasticsearch"; \ - certificate_set_complete=1; \ - for required_file in \ - "elastic-stack-ca.crt.pem" \ - "elastic-stack-ca.p12" \ - "elasticsearch/$${ES_INSTANCE_NAME_1}/$${ES_INSTANCE_NAME_1}.crt" \ - "elasticsearch/$${ES_INSTANCE_NAME_1}/$${ES_INSTANCE_NAME_1}.key" \ - "elasticsearch/$${ES_INSTANCE_NAME_2}/$${ES_INSTANCE_NAME_2}.crt" \ - "elasticsearch/$${ES_INSTANCE_NAME_2}/$${ES_INSTANCE_NAME_2}.key" \ - "elasticsearch/$${ES_INSTANCE_NAME_3}/$${ES_INSTANCE_NAME_3}.crt" \ - "elasticsearch/$${ES_INSTANCE_NAME_3}/$${ES_INSTANCE_NAME_3}.key"; do \ - if [[ ! -f "$$elasticsearch_dir/$$required_file" ]]; then \ - certificate_set_complete=0; \ - break; \ - fi; \ - done; \ - if (( certificate_set_complete )); then \ - echo "Native Elasticsearch certificates already exist; leaving them unchanged."; \ - elif [[ -e "$$elasticsearch_dir" ]]; then \ - echo "ERROR: $$elasticsearch_dir exists but contains an incomplete certificate set." >&2; \ - echo "Move or remove that directory after preserving anything needed, then rerun this target." >&2; \ - exit 1; \ - else \ - echo "Generating native Elasticsearch certificates with Docker..."; \ - (cd "$(SECURITY_SCRIPTS_DIR)" && ./create_es_native_certs.sh); \ - fi - -init-security-search: ## Generate certificates for ELASTICSEARCH_VERSION from elasticsearch.env - @set -euo pipefail; \ - $(WITH_ENV) \ - source "$${COGSTACK_ELASTICSEARCH_ENV_FILE}"; \ - case "$${ELASTICSEARCH_VERSION}" in \ - opensearch|elasticsearch) \ - $(MAKE) --no-print-directory "init-security-$${ELASTICSEARCH_VERSION}" \ - ;; \ - *) \ - echo "ERROR: unsupported ELASTICSEARCH_VERSION '$${ELASTICSEARCH_VERSION}'." >&2; \ - exit 1 \ - ;; \ - esac - -init-security-postgresql: init-security-root-ca ## Generate missing PostgreSQL TLS bundles, preserving supplied certificates - @$(WITH_ENV) SECURITY_CERTIFICATES_DIR="$(SECURITY_CERTIFICATES_DIR)" bash "$(SECURITY_SCRIPTS_DIR)/create_postgres_certs.sh" - -init-security: ## Generate missing NiFi, PostgreSQL, Gitea, and selected search-backend certificates - @$(MAKE) --no-print-directory init-security-nifi - @$(MAKE) --no-print-directory init-security-gitea - @$(MAKE) --no-print-directory init-security-search - -.PHONY: init-security init-security-root-ca init-security-nifi init-security-postgresql init-security-gitea init-security-opensearch init-security-elasticsearch init-security-search - -remote-deploy-service: ## Deploy one or more services to a remote machine via SSH + docker compose -remote-deploy-service: _check-remote-params - @ssh $(REMOTE_SSH_KEY_ARG) $(REMOTE_SSH_OPTS) "$(REMOTE_HOST)" 'cd "$(REMOTE_REPO_DIR)/deploy" && set -a && source ./export_env_vars.sh && docker compose -f "$(REMOTE_COMPOSE_FILE)" up -d $(REMOTE_SERVICES)' - -remote-stop-service: ## Stop one or more services on a remote machine via SSH + docker compose -remote-stop-service: _check-remote-params - @ssh $(REMOTE_SSH_KEY_ARG) $(REMOTE_SSH_OPTS) "$(REMOTE_HOST)" 'cd "$(REMOTE_REPO_DIR)/deploy" && set -a && source ./export_env_vars.sh && docker compose -f "$(REMOTE_COMPOSE_FILE)" stop $(REMOTE_SERVICES)' - -remote-delete-service: ## Delete one or more remote service containers via SSH + docker compose rm -remote-delete-service: _check-remote-params - @ssh $(REMOTE_SSH_KEY_ARG) $(REMOTE_SSH_OPTS) "$(REMOTE_HOST)" 'cd "$(REMOTE_REPO_DIR)/deploy" && set -a && source ./export_env_vars.sh && docker compose -f "$(REMOTE_COMPOSE_FILE)" rm -f -s $(REMOTE_SERVICES)' - -_check-remote-params: - @if [ -z "$(REMOTE_HOST)" ]; then \ - echo "REMOTE_HOST is required (example: REMOTE_HOST=user@machine)"; \ - exit 1; \ - fi - @if [ -z "$(REMOTE_REPO_DIR)" ]; then \ - echo "REMOTE_REPO_DIR is required (example: REMOTE_REPO_DIR=/opt/cogstack_nifi)"; \ - exit 1; \ - fi - @if [ -z "$(REMOTE_SERVICES)" ]; then \ - echo "REMOTE_SERVICES is required (example: REMOTE_SERVICES='nifi nifi-nginx')"; \ - exit 1; \ - fi - -.PHONY: remote-deploy-service remote-stop-service remote-delete-service _check-remote-params - -check-nifi-resources: ## Validate NiFi heap sizes against the container memory limit - @$(WITH_ENV) python3 ../scripts/tests/check_nifi_resources.py - -check-opensearch-settings: ## Validate search credentials, encryption keys, and image versions - @$(WITH_ENV) python3 ../scripts/tests/check_opensearch_settings.py - -check-config: check-nifi-resources check-opensearch-settings ## Validate resolved settings and both core Compose files - @$(WITH_ENV) docker compose --profile "*" -f services.yml config --quiet && docker compose --profile "*" -f docker-compose.dev.yml config --quiet - -.PHONY: check-nifi-resources check-opensearch-settings check-config +check-config: ## Validate the NiFi dev Compose file + @$(WITH_ENV) docker compose -f docker-compose.dev.yml config --quiet -# start services - -start-nifi: check-nifi-resources ## Start NiFi and NiFi nginx (services.yml) - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) nifi nifi-nginx - -start-nifi-dev: check-nifi-resources ## Start NiFi and NiFi nginx (docker-compose.dev.yml) +start-nifi-dev: ## Start NiFi and NiFi nginx (docker-compose.dev.yml) $(WITH_ENV) docker compose -f docker-compose.dev.yml $(DC_START_CMD) nifi nifi-nginx -start-nifi-dev-build: check-nifi-resources ## Build and start NiFi dev services +start-nifi-dev-build: ## Build and start NiFi dev services $(WITH_ENV) docker compose -f docker-compose.dev.yml up -d --build nifi nifi-nginx build-nifi-image: ## Build the local NiFi image without starting services @@ -281,146 +65,15 @@ build-nifi-image: ## Build the local NiFi image without starting services --file ../Dockerfile \ .. -start-elastic: check-opensearch-settings ## Start elasticsearch-1, elasticsearch-2 and kibana - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-1 elasticsearch-2 kibana - -start-elastic-cluster: check-opensearch-settings ## Start full 3-node Elasticsearch cluster - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-1 elasticsearch-2 elasticsearch-3 - -start-elastic-1: check-opensearch-settings - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-1 - -start-elastic-2: check-opensearch-settings - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-2 - -start-elastic-3: check-opensearch-settings - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) elasticsearch-3 - -start-metricbeat-1: - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) metricbeat-1 - -start-metricbeat-2: - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) metricbeat-2 - -start-metricbeat-3: - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) metricbeat-3 - -start-filebeat-1: - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) filebeat-1 - -start-filebeat-2: - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) filebeat-2 - -start-filebeat-3: - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) filebeat-3 - -start-kibana: check-opensearch-settings ## Start Kibana or OpenSearch Dashboards - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) kibana - -start-ollama: ## Start the Ollama inference service - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) ollama - -start-ollama-openai-proxy: ## Build and start the OpenSearch-to-Ollama compatibility proxy - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) --build ollama-openai-proxy - -pull-ollama-model: start-ollama ## Pull the model configured by OLLAMA_MODEL - $(WITH_ENV) docker compose -f services.yml exec -T ollama ollama pull "$${OLLAMA_MODEL}" - -setup-ollama: pull-ollama-model ## Start Ollama and pull its configured model - -opensearch-ai-init: ## Create or update OpenSearch AI connectors and agents using OPENSEARCH_AI_PROVIDER - $(WITH_ENV) \ - case "$${OPENSEARCH_AI_PROVIDER:-ollama}" in \ - ollama) docker compose -f services.yml $(DC_START_CMD) --build ollama-openai-proxy ;; \ - sglang) ;; \ - *) echo "Unsupported OPENSEARCH_AI_PROVIDER: $${OPENSEARCH_AI_PROVIDER}" >&2; exit 1 ;; \ - esac && ../scripts/opensearch-ai-init.sh - -opensearch-ai-init-sglang: ## Connect all OpenSearch AI features to the locally hosted SGLang server - $(WITH_ENV) OPENSEARCH_AI_PROVIDER=sglang ../scripts/opensearch-ai-init.sh - -start-openwebui: ## Start Open WebUI and its Ollama dependency - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) open-webui - -restart-openwebui: ## Restart the Open WebUI container - $(WITH_ENV) docker compose -f services.yml restart open-webui - -status-openwebui: ## Show Open WebUI and Ollama container status - $(WITH_ENV) docker compose -f services.yml ps open-webui ollama - -logs-openwebui: ## Follow the Open WebUI logs - $(WITH_ENV) docker compose -f services.yml logs --tail=100 -f open-webui - -start-samples: ## Start the sample database service - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) samples-db && \ - docker compose -f services.yml exec -T -e PGHOST=samples-db samples-db /docker-entrypoint-initdb.d/access/configure.sh - -start-clickhouse: ## Start the ClickHouse ingestion database - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) clickhouse - -status-clickhouse: ## Show ClickHouse container status - $(WITH_ENV) docker compose -f services.yml ps clickhouse - -logs-clickhouse: ## Follow ClickHouse logs - $(WITH_ENV) docker compose -f services.yml logs --tail=100 -f clickhouse - start-jupyter: $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.prod.yml $(DC_START_CMD) cogstack-jupyter-hub -start-medcat-service: - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml $(DC_START_CMD) nlp-medcat-service-production - -start-medcat-service-deid: - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml $(DC_START_CMD) nlp-medcat-service-production-deid - -start-medcat-trainer: - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-trainer/docker-compose-prod.yml $(DC_START_CMD) medcattrainer nginx solr - -start-production-db: - $(WITH_ENV) docker compose -f services.yml ${DC_START_CMD} cogstack-databank-db && \ - docker compose -f services.yml exec -T -e PGHOST=cogstack-databank-db cogstack-databank-db /docker-entrypoint-initdb.d/access/configure.sh - -start-production-db-mssql: ## Start SQL Server and wait for its schema initialization job - $(WITH_ENV) docker compose -f services.yml $(DC_START_CMD) cogstack-databank-db-mssql && \ - docker compose -f services.yml run --rm --no-deps cogstack-databank-db-mssql-init - -start-ocr-services: - $(WITH_ENV) docker compose -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.base.yml -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.prod.yml $(DC_START_CMD) ocr-service ocr-service-text-only - -start-git-ea: - $(WITH_ENV) docker compose -f services.yml ${DC_START_CMD} gitea - -start-data-infra: start-nifi start-elastic start-samples ## Start core data infrastructure - -start-all: start-data-infra start-medcat-service start-ocr-services ## Start all major services - -.PHONY: start-kibana start-all start-data-infra start-nifi start-nifi-dev start-nifi-dev-build build-nifi-image start-elastic start-ollama start-ollama-openai-proxy pull-ollama-model setup-ollama opensearch-ai-init opensearch-ai-init-sglang start-openwebui restart-openwebui status-openwebui logs-openwebui start-samples start-clickhouse status-clickhouse logs-clickhouse start-jupyter - - -# stop services -# -stop-nifi: ## Stop NiFi and NiFi nginx (services.yml) - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) nifi nifi-nginx - stop-nifi-dev: ## Stop NiFi and NiFi nginx (docker-compose.dev.yml) $(WITH_ENV) docker compose -f docker-compose.dev.yml $(DC_STOP_CMD) nifi nifi-nginx -delete-nifi: delete-nifi-containers ## Delete NiFi containers only - -delete-nifi-containers: ## Remove NiFi containers from services.yml - $(WITH_ENV) docker compose -f services.yml rm -f -s nifi nifi-nginx - delete-nifi-dev-containers: ## Remove NiFi containers from docker-compose.dev.yml $(WITH_ENV) docker compose -f docker-compose.dev.yml rm -f -s nifi nifi-nginx -delete-nifi-images: ## Delete NiFi images referenced in services.yml - $(WITH_ENV) images="$$(docker compose -f services.yml config --images nifi nifi-nginx | sort -u)"; \ - if [ -n "$$images" ]; then \ - docker image rm -f $$images; \ - else \ - echo "No NiFi images found in services.yml"; \ - fi - delete-nifi-dev-images: ## Delete NiFi images referenced in docker-compose.dev.yml $(WITH_ENV) images="$$(docker compose -f docker-compose.dev.yml config --images nifi nifi-nginx | sort -u)"; \ if [ -n "$$images" ]; then \ @@ -429,155 +82,12 @@ delete-nifi-dev-images: ## Delete NiFi images referenced in docker-compose.dev.y echo "No NiFi images found in docker-compose.dev.yml"; \ fi -delete-nifi-volumes: ## Delete NiFi volumes - $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v nifi nifi-nginx - -delete-elastic: ## Remove Elasticsearch and Kibana containers - $(WITH_ENV) docker compose -f services.yml rm -f -s elasticsearch-1 elasticsearch-2 elasticsearch-3 kibana - -delete-elastic-volumes: ## Delete Elasticsearch and Kibana volumes - $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v elasticsearch-1 elasticsearch-2 elasticsearch-3 kibana - -delete-ollama: ## Remove the Ollama container but preserve downloaded models - $(WITH_ENV) docker compose -f services.yml rm -f -s ollama - -delete-ollama-openai-proxy: ## Remove the OpenSearch-to-Ollama compatibility proxy container - $(WITH_ENV) docker compose -f services.yml rm -f -s ollama-openai-proxy - -delete-ollama-proxy: delete-ollama-openai-proxy ## Alias for delete-ollama-openai-proxy - -delete-openwebui: ## Remove the Open WebUI container but preserve its data - $(WITH_ENV) docker compose -f services.yml rm -f -s open-webui - -delete-databank: - $(WITH_ENV) docker compose -f services.yml rm -f -s cogstack-databank-db cogstack-databank-db-mssql-init cogstack-databank-db-mssql - -delete-databank-volumes: - $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v cogstack-databank-db cogstack-databank-db-mssql - -delete-samples-db: - $(WITH_ENV) docker compose -f services.yml rm -f -s samples-db - -delete-samples-db-volumes: - $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v samples-db - -delete-clickhouse: ## Remove the ClickHouse container but preserve its data - $(WITH_ENV) docker compose -f services.yml rm -f -s clickhouse - -delete-medcat-trainer: ## Remove MedCAT Trainer containers - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-trainer/docker-compose-prod.yml rm -f -s medcattrainer nginx solr - -delete-medcat-trainer-volumes: ## Delete MedCAT Trainer volumes - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-trainer/docker-compose-prod.yml $(DC_DOWN_CMD) -v medcattrainer nginx solr - delete-jupyter: ## Remove Jupyter container $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.prod.yml rm -f -s cogstack-jupyter-hub -delete-medcat-service: ## Remove MedCAT service container - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml rm -f -s nlp-medcat-service-production - -delete-medcat-service-deid: ## Remove MedCAT service (deid) container - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml rm -f -s nlp-medcat-service-production-deid - -delete-ocr-services: ## Remove OCR service containers - $(WITH_ENV) docker compose -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.base.yml -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.prod.yml rm -f -s ocr-service ocr-service-text-only - make-delete-jupyter: delete-jupyter ## Alias for delete-jupyter -make-delete-medcat-service: delete-medcat-service ## Alias for delete-medcat-service - -make-delete-medcat-service-deid: delete-medcat-service-deid ## Alias for delete-medcat-service-deid - -make-delete-ocr-services: delete-ocr-services ## Alias for delete-ocr-services - -stop-elastic: ## Stop elasticsearch-1, elasticsearch-2 and kibana - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-1 elasticsearch-2 kibana - -stop-elastic-cluster: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-1 elasticsearch-2 - -stop-elastic-1: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-1 - -stop-elastic-2: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-2 - -stop-elastic-3: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) elasticsearch-3 - -stop-metricbeat-1: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) metricbeat-1 - -stop-metricbeat-2: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) metricbeat-2 - -stop-filebeat-1: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) filebeat-1 - -stop-filebeat-2: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) filebeat-2 - -stop-filebeat-3: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) filebeat-3 - -stop-kibana: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) kibana - -stop-ollama: ## Stop the Ollama inference service - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) ollama - -stop-openwebui: ## Stop the Open WebUI service - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) open-webui - -stop-samples: ## Stop the sample database service - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) samples-db - -stop-clickhouse: ## Stop the ClickHouse ingestion database - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) clickhouse - stop-jupyter: $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.yml $(DC_STOP_CMD) cogstack-jupyter-hub -stop-medcat-trainer: - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-trainer/docker-compose-prod.yml $(DC_STOP_CMD) medcattrainer nginx solr - -stop-medcat-service: - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml $(DC_STOP_CMD) nlp-medcat-service-production - -stop-medcat-service-deid: - $(WITH_ENV) docker compose -f ../services/cogstack-nlp/medcat-service/docker/docker-compose.yml $(DC_STOP_CMD) nlp-medcat-service-production-deid - -stop-git-ea: - $(WITH_ENV) docker compose -f services.yml ${DC_STOP_CMD} gitea - -stop-ocr-services: - $(WITH_ENV) docker compose -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.base.yml -f ../services/cogstack-platform/apps/ocr-service/docker/docker-compose.prod.yml $(DC_STOP_CMD) ocr-service ocr-service-text-only - -stop-production-db: - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) cogstack-databank-db - -stop-production-db-mssql: ## Stop the SQL Server initializer and server without removing data - $(WITH_ENV) docker compose -f services.yml $(DC_STOP_CMD) cogstack-databank-db-mssql-init cogstack-databank-db-mssql - -.PHONY: start-production-db-mssql stop-production-db-mssql - -stop-data-infra: stop-nifi stop-elastic stop-samples ## Stop core data infrastructure - -stop-all: stop-data-infra stop-jupyter stop-medcat-service stop-ocr-services ## Stop all major services - -.PHONY: stop-data-infra stop-nifi stop-nifi-dev delete-nifi delete-nifi-containers delete-nifi-dev-containers delete-nifi-images delete-nifi-dev-images delete-nifi-volumes delete-elastic delete-elastic-volumes delete-ollama delete-ollama-openai-proxy delete-ollama-proxy delete-openwebui delete-databank delete-databank-volumes delete-samples-db delete-samples-db-volumes delete-clickhouse delete-medcat-trainer delete-medcat-trainer-volumes delete-jupyter delete-medcat-service delete-medcat-service-deid delete-ocr-services make-delete-jupyter make-delete-medcat-service make-delete-medcat-service-deid make-delete-ocr-services stop-elastic stop-ollama stop-openwebui stop-samples stop-clickhouse stop-jupyter - - -# cleanup -# -down-all: ## Run docker compose down for services.yml - $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) - -# deletes volumes associated with containers -cleanup: ## Run docker compose down -v for services.yml - $(WITH_ENV) docker compose -f services.yml $(DC_DOWN_CMD) -v - -.PHONY: down-all cleanup - -# Expose Kubernetes commands when their deployment helpers are present. --include kubernetes/Makefile +.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build build-nifi-image start-jupyter stop-nifi-dev delete-nifi-dev-containers delete-nifi-dev-images delete-jupyter make-delete-jupyter stop-jupyter diff --git a/apps/nifi/docker/docker-compose.dev.yml b/apps/nifi/docker/docker-compose.dev.yml index c3b5f313..2129b170 100644 --- a/apps/nifi/docker/docker-compose.dev.yml +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -10,42 +10,15 @@ x-nifi-logging-common: &nifi-logging-common x-env-files: all: &all-env - - "${COGSTACK_PROJECT_ENV_FILE:-./project.env}" - - "${COGSTACK_GENERAL_ENV_FILE:-./general.env}" - - "${COGSTACK_NIFI_ENV_FILE:-./nifi.env}" - - "${COGSTACK_GITEA_ENV_FILE:-./gitea.env}" - - "${COGSTACK_NGINX_ENV_FILE:-./nginx.env}" - - "${COGSTACK_TELEMETRY_ENV_FILE:-./telemetry.env}" - - "${COGSTACK_ELASTICSEARCH_ENV_FILE:-./elasticsearch.env}" - - "${COGSTACK_NETWORK_SETTINGS_ENV_FILE:-./network_settings.env}" - - "${COGSTACK_USERS_NIFI_ENV_FILE:-../security/env/users_nifi.env}" - - "${COGSTACK_USERS_NGINX_ENV_FILE:-../security/env/users_nginx.env}" - - "${COGSTACK_USERS_ELASTICSEARCH_ENV_FILE:-../security/env/users_elasticsearch.env}" - - "${COGSTACK_CERTIFICATES_GENERAL_ENV_FILE:-../security/env/certificates_general.env}" - - "${COGSTACK_CERTIFICATES_ELASTICSEARCH_ENV_FILE:-../security/env/certificates_elasticsearch.env}" - - "${COGSTACK_CERTIFICATES_NIFI_ENV_FILE:-../security/env/certificates_nifi.env}" - - search: &es-env - - "${COGSTACK_NETWORK_SETTINGS_ENV_FILE:-./network_settings.env}" - - "${COGSTACK_ELASTICSEARCH_ENV_FILE:-./elasticsearch.env}" - - "${COGSTACK_USERS_ELASTICSEARCH_ENV_FILE:-../security/env/users_elasticsearch.env}" - - "${COGSTACK_CERTIFICATES_ELASTICSEARCH_ENV_FILE:-../security/env/certificates_elasticsearch.env}" + - "${COGSTACK_GENERAL_ENV_FILE:-../env/general.env}" + - "${COGSTACK_NIFI_ENV_FILE:-../env/nifi.env}" + - "${COGSTACK_NETWORK_SETTINGS_ENV_FILE:-../env/network_settings.env}" nifi-nginx: &nifi-nginx-env-files - - "${COGSTACK_NGINX_ENV_FILE:-./nginx.env}" + - "${COGSTACK_NGINX_ENV_FILE:-../env/nginx.env}" x-env: nifi: &nifi-env - POSTGRES_SAMPLES_DB_NAME: ${POSTGRES_SAMPLES_DB_NAME:-db_samples} - POSTGRES_SAMPLES_JDBC_URL: ${POSTGRES_SAMPLES_JDBC_URL:-jdbc:postgresql://samples-db:5432/${POSTGRES_SAMPLES_DB_NAME:-db_samples}?sslmode=verify-full&sslrootcert=/run/database-cas/samples-ca.crt} - POSTGRES_INGEST_USER_SAMPLES: ${POSTGRES_INGEST_USER_SAMPLES:-cogstack_samples} - POSTGRES_INGEST_PASSWORD_SAMPLES: ${POSTGRES_INGEST_PASSWORD_SAMPLES:?Set the sample ingestion password} - DATABASE_DB_NAME: ${DATABASE_DB_NAME:-cogstack} - DATABASE_INGEST_USER: ${DATABASE_INGEST_USER:-cogstack_ingest} - DATABASE_INGEST_PASSWORD: ${DATABASE_INGEST_PASSWORD:?Set the PostgreSQL ingestion password} - MSSQL_INGEST_USER: ${MSSQL_INGEST_USER:-cogstack_ingest} - MSSQL_INGEST_PASSWORD: ${MSSQL_INGEST_PASSWORD:?Set the MSSQL ingestion password} - # Apache's native startup settings; existing deployment env names remain supported. AUTH: ${AUTH:-tls} NIFI_SECURITY_USER_AUTHORIZER: ${NIFI_SECURITY_USER_AUTHORIZER:-single-user-authorizer} @@ -90,29 +63,12 @@ x-mounts: - ../security/certificates/elastic/opensearch/es_kibana_client.pem:/security/certificates/elastic/opensearch/es_kibana_client.pem:ro - ../security/certificates/elastic/opensearch/es_kibana_client.key:/security/certificates/elastic/opensearch/es_kibana_client.key:ro - ../security/certificates/root/root-ca.pem:/security/certificates/root/root-ca.pem:ro - # Database clients receive only the public CA from each TLS bundle. - - type: bind - source: ${POSTGRES_SAMPLES_TLS_DIR:-../security/certificates/postgresql/samples}/ca.crt - target: /run/database-cas/samples-ca.crt - read_only: true - bind: - create_host_path: false - - type: bind - source: ${POSTGRES_DATABANK_TLS_DIR:-../security/certificates/postgresql/databank}/ca.crt - target: /run/database-cas/databank-ca.crt - read_only: true - bind: - create_host_path: false - # Apache startup configures image defaults in this persistent, writable directory. - nifi-vol-conf:/opt/nifi/nifi-current/conf # Ingest data directory - ${NIFI_DATA_PATH:-../data/}:/data/:rw - # MedCAT models - - ${NIFI_MEDCAT_SERVICE_MODEL_PRODUCTION_PATH:-../services/cogstack-nlp/medcat-service/models/}:/opt/models:rw - # NiFi repositories/state - nifi-vol-logs:/opt/nifi/nifi-current/logs - nifi-vol-provenance:/opt/nifi/nifi-current/provenance_repository @@ -128,17 +84,9 @@ x-mounts: - /tmp:mode=1777 nifi-nginx: &nifi-nginx-volumes - - ../services/nginx/sites-enabled:/etc/nginx/sites-enabled:ro - ../security/certificates/nifi:/certificates/nifi:ro - ../security/certificates/root/root-ca.pem:/certificates/root/root-ca.pem:ro - otel-collector: &otel-collector-volumes - - ./observability/otel-collector.yaml:/etc/otelcol-contrib/config.yaml:ro - - data-prepper: &data-prepper-volumes - - ./observability/data-prepper/config/data-prepper-config.yaml:/usr/share/data-prepper/config/data-prepper-config.yaml:ro - - ./observability/data-prepper/pipelines:/usr/share/data-prepper/pipelines:ro - x-networks: cognet: &cognet - cognet @@ -183,7 +131,7 @@ services: dockerfile: Dockerfile args: NIFI_VERSION: ${NIFI_VERSION:-2.12.0} - NIFI_BASE_IMAGE: ${NIFI_BASE_IMAGE:?Source deploy/export_env_vars.sh first} + NIFI_BASE_IMAGE: ${NIFI_BASE_IMAGE:?Source docker/export_env_vars.sh first} NIFI_UID: ${COGSTACK_LOCAL_UID:-1000} NIFI_GID: ${COGSTACK_LOCAL_GID:-1000} container_name: cogstack-nifi @@ -209,7 +157,7 @@ services: nifi-nginx: pull_policy: build build: - context: ../services/nginx + context: ../../nginx dockerfile: Dockerfile args: NGINX_UID: ${COGSTACK_LOCAL_UID:-1000} @@ -237,37 +185,6 @@ services: extra_hosts: *common-hosts logging: *nifi-logging-common -#---------------------------------------------------------------------------# -# Observability stack # -#---------------------------------------------------------------------------# - otel-collector: - image: ${OTEL_COLLECTOR_DOCKER_IMAGE:?Source deploy/export_env_vars.sh first} - container_name: cogstack-otel-collector - restart: unless-stopped - command: ["--config=/etc/otelcol-contrib/config.yaml"] - env_file: *all-env - volumes: *otel-collector-volumes - ports: - - "${OTEL_COLLECTOR_OTLP_GRPC_PORT:-4317}:4317" - - "${OTEL_COLLECTOR_OTLP_HTTP_PORT:-4318}:4318" - - "${OTEL_COLLECTOR_HEALTH_PORT:-13133}:13133" - networks: *cognet - extra_hosts: *common-hosts - logging: *nifi-logging-common - - data-prepper: - image: ${DATA_PREPPER_DOCKER_IMAGE:?Source deploy/export_env_vars.sh first} - container_name: cogstack-data-prepper - restart: unless-stopped - env_file: *all-env - volumes: *data-prepper-volumes - ports: - - "${DATA_PREPPER_API_PORT:-4900}:4900" - - "${DATA_PREPPER_OTEL_TRACE_PORT:-21890}:21890" - networks: *cognet - extra_hosts: *common-hosts - logging: *nifi-logging-common - #---------------------------------------------------------------------------# # Docker named volumes # #---------------------------------------------------------------------------# diff --git a/apps/nifi/docker/export_env_vars.sh b/apps/nifi/docker/export_env_vars.sh index f62884b1..bff998ca 100755 --- a/apps/nifi/docker/export_env_vars.sh +++ b/apps/nifi/docker/export_env_vars.sh @@ -11,42 +11,25 @@ _cogstack_load_environment() { fi local deploy_path deploy_path="$(cd "$(dirname "$loader_path")" && pwd)" || return 1 - # shellcheck disable=SC1091 - source "$deploy_path/config_files.sh" || return 1 - cogstack_config_init "$(cd "$deploy_path/.." && pwd)" || return 1 - local relative_files=( - security/env/certificates_nifi.env - security/env/certificates_general.env - security/env/certificates_elasticsearch.env - security/env/users_elasticsearch.env - security/env/users_database.env - security/env/users_nifi.env - security/env/users_nginx.env - deploy/general.env - deploy/nifi.env - deploy/elasticsearch.env - deploy/ollama.env - deploy/sglang.env - deploy/openwebui.env - deploy/database.env - deploy/network_settings.env - deploy/project.env - deploy/gitea.env - deploy/nginx.env - deploy/telemetry.env + ../env/general.env + ../env/nifi.env + ../env/network_settings.env + ../env/nginx.env ) local relative_file selected_file variable_name file_name local restore_allexport=1 case "$-" in *a*) restore_allexport=0 ;; esac set -a for relative_file in "${relative_files[@]}"; do - selected_file="$(cogstack_env_file "$relative_file")" || { - if [[ "$restore_allexport" == 1 ]]; then set +a; fi - return 1 - } file_name="${relative_file##*/}" variable_name="COGSTACK_$(printf '%s' "${file_name%.env}" | tr '[:lower:]' '[:upper:]')_ENV_FILE" + if [[ -n "${ZSH_VERSION:-}" ]]; then + eval 'selected_file=${(P)variable_name:-}' + else + selected_file="${!variable_name:-}" + fi + selected_file="${selected_file:-$deploy_path/$relative_file}" export "$variable_name=$selected_file" # shellcheck disable=SC1090 source "$selected_file" || { @@ -58,14 +41,10 @@ _cogstack_load_environment() { # Service-owned configuration remains optional and uses its own directories. local service_files=( - ../jupyter-hub/env/jupyter.env - services/cogstack-platform/apps/ocr-service/env/ocr_service.env - services/cogstack-nlp/medcat-service/env/app.env - services/cogstack-nlp/medcat-service/env/medcat.env - services/cogstack-nlp/medcat-trainer/envs/env-prod + ../../jupyter-hub/env/jupyter.env ) for relative_file in "${service_files[@]}"; do - selected_file="$COGSTACK_REPO_ROOT/$relative_file" + selected_file="$deploy_path/$relative_file" if [[ -f "$selected_file" ]]; then # shellcheck disable=SC1090 source "$selected_file" || { @@ -83,7 +62,7 @@ _cogstack_load_environment() { if [[ "$COGSTACK_LOCAL_GID" == 0 ]]; then export COGSTACK_LOCAL_GID=1000; fi export DOLLAR='$' if [[ "$restore_allexport" == 1 ]]; then set +a; fi - echo "Configuration loaded from ${COGSTACK_CONFIG_DIR:-repository defaults}." + echo "Configuration loaded." } if _cogstack_load_environment; then From c9dc119c4a47ff9e62d2aa3b5bfbb2c8cd5c3011 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Sun, 22 Nov 2026 20:38:54 +0000 Subject: [PATCH 03/16] NiFi cleanups. --- apps/nifi/README.md | 5 +++++ apps/nifi/docker/docker-compose.dev.yml | 16 ++++++++-------- deployment/security/certificates/.gitignore | 2 ++ 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 deployment/security/certificates/.gitignore diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 4b1463e3..270d7294 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -75,6 +75,11 @@ READMEs describe the required environment ConfigMaps, TLS Secrets and storage. local files, NiFi credentials and TLS certificates before using the Compose helpers. The image build above works independently of them. +Certificates live in the shared `deployment/security/certificates/` directory +at the repository root. Put the CA in `root/root-ca.pem` and the NiFi files +(`nifi.pem`, `nifi.key`, `nifi-keystore.jks`, `nifi-truststore.jks`) in `nifi/`. +Both containers mount these files read-only. Certificate contents are ignored by Git. + Mutable configuration, data repositories, processor logs and databases belong in deployment-owned storage. The image health check expects the configured TLS CA certificate at runtime. diff --git a/apps/nifi/docker/docker-compose.dev.yml b/apps/nifi/docker/docker-compose.dev.yml index 2129b170..0ef3041d 100644 --- a/apps/nifi/docker/docker-compose.dev.yml +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -57,12 +57,12 @@ x-mounts: - ../user_python_extensions:/opt/nifi/nifi-current/python_extensions:rw # Security certificates - - ../security/certificates/nifi:/security/certificates/nifi:ro - - ../security/certificates/elastic/opensearch/elasticsearch:/security/certificates/elastic/opensearch/elasticsearch:ro - - ../security/certificates/elastic/opensearch/elastic-stack-ca.crt.pem:/security/certificates/elastic/opensearch/elastic-stack-ca.crt.pem:ro - - ../security/certificates/elastic/opensearch/es_kibana_client.pem:/security/certificates/elastic/opensearch/es_kibana_client.pem:ro - - ../security/certificates/elastic/opensearch/es_kibana_client.key:/security/certificates/elastic/opensearch/es_kibana_client.key:ro - - ../security/certificates/root/root-ca.pem:/security/certificates/root/root-ca.pem:ro + - ../../../deployment/security/certificates/nifi:/security/certificates/nifi:ro + - ../../../deployment/security/certificates/elastic/opensearch/elasticsearch:/security/certificates/elastic/opensearch/elasticsearch:ro + - ../../../deployment/security/certificates/elastic/opensearch/elastic-stack-ca.crt.pem:/security/certificates/elastic/opensearch/elastic-stack-ca.crt.pem:ro + - ../../../deployment/security/certificates/elastic/opensearch/es_kibana_client.pem:/security/certificates/elastic/opensearch/es_kibana_client.pem:ro + - ../../../deployment/security/certificates/elastic/opensearch/es_kibana_client.key:/security/certificates/elastic/opensearch/es_kibana_client.key:ro + - ../../../deployment/security/certificates/root/root-ca.pem:/security/certificates/root/root-ca.pem:ro # Apache startup configures image defaults in this persistent, writable directory. - nifi-vol-conf:/opt/nifi/nifi-current/conf @@ -84,8 +84,8 @@ x-mounts: - /tmp:mode=1777 nifi-nginx: &nifi-nginx-volumes - - ../security/certificates/nifi:/certificates/nifi:ro - - ../security/certificates/root/root-ca.pem:/certificates/root/root-ca.pem:ro + - ../../../deployment/security/certificates/nifi:/certificates/nifi:ro + - ../../../deployment/security/certificates/root/root-ca.pem:/certificates/root/root-ca.pem:ro x-networks: cognet: &cognet diff --git a/deployment/security/certificates/.gitignore b/deployment/security/certificates/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/deployment/security/certificates/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From 5b826b140041ef239511e6cb03f146d66b00679d Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Sun, 22 Nov 2026 21:04:04 +0000 Subject: [PATCH 04/16] NiFi cleanups II. --- apps/nifi/README.md | 11 ++++++---- apps/nifi/docker/Makefile | 15 ++----------- apps/nifi/docker/docker-compose.dev.yml | 29 +++++-------------------- apps/nifi/docker/export_env_vars.sh | 16 -------------- 4 files changed, 15 insertions(+), 56 deletions(-) diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 270d7294..dd486958 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -25,7 +25,7 @@ alongside the application. Run from the platform repository root: ```bash -docker build --tag cogstack/cogstack-nifi:local apps/nifi +docker build --tag cogstacksystems/nifi:local apps/nifi ``` `apps/nifi` is the build context. The Dockerfile uses the checked-in dependency @@ -71,14 +71,17 @@ READMEs describe the required environment ConfigMaps, TLS Secrets and storage. `docker/docker-compose.dev.yml` runs NiFi and the shared NGINX application from `apps/nginx`. The environment loader uses the app's `env/general.env`, -`env/nifi.env`, `env/network_settings.env` and `env/nginx.env` files. Supply those -local files, NiFi credentials and TLS certificates before using the Compose -helpers. The image build above works independently of them. +`env/nifi.env` and `env/network_settings.env` files. NGINX uses its image defaults +and the resource limits in Compose. Supply the local files, NiFi credentials and +TLS certificates before using the Compose helpers. The image build above works +independently of them. Certificates live in the shared `deployment/security/certificates/` directory at the repository root. Put the CA in `root/root-ca.pem` and the NiFi files (`nifi.pem`, `nifi.key`, `nifi-keystore.jks`, `nifi-truststore.jks`) in `nifi/`. Both containers mount these files read-only. Certificate contents are ignored by Git. +Supply any ingestion-specific certificate mounts or host overrides in the deployment +that needs them. Mutable configuration, data repositories, processor logs and databases belong in deployment-owned storage. The image health check expects the configured TLS diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index df818d31..2d9d64b8 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -61,13 +61,10 @@ build-nifi-image: ## Build the local NiFi image without starting services --build-arg NIFI_BASE_IMAGE="$${NIFI_BASE_IMAGE}" \ --build-arg NIFI_UID="$${COGSTACK_LOCAL_UID:-1000}" \ --build-arg NIFI_GID="$${COGSTACK_LOCAL_GID:-1000}" \ - --tag "$${NIFI_LOCAL_DOCKER_IMAGE:-cogstack/cogstack-nifi:local}" \ + --tag "$${NIFI_LOCAL_DOCKER_IMAGE:-cogstacksystems/nifi:local}" \ --file ../Dockerfile \ .. -start-jupyter: - $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.prod.yml $(DC_START_CMD) cogstack-jupyter-hub - stop-nifi-dev: ## Stop NiFi and NiFi nginx (docker-compose.dev.yml) $(WITH_ENV) docker compose -f docker-compose.dev.yml $(DC_STOP_CMD) nifi nifi-nginx @@ -82,12 +79,4 @@ delete-nifi-dev-images: ## Delete NiFi images referenced in docker-compose.dev.y echo "No NiFi images found in docker-compose.dev.yml"; \ fi -delete-jupyter: ## Remove Jupyter container - $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.prod.yml rm -f -s cogstack-jupyter-hub - -make-delete-jupyter: delete-jupyter ## Alias for delete-jupyter - -stop-jupyter: - $(WITH_ENV) docker compose -f ../../jupyter-hub/docker/docker-compose.base.yml -f ../../jupyter-hub/docker/docker-compose.yml $(DC_STOP_CMD) cogstack-jupyter-hub - -.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build build-nifi-image start-jupyter stop-nifi-dev delete-nifi-dev-containers delete-nifi-dev-images delete-jupyter make-delete-jupyter stop-jupyter +.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build build-nifi-image stop-nifi-dev delete-nifi-dev-containers delete-nifi-dev-images diff --git a/apps/nifi/docker/docker-compose.dev.yml b/apps/nifi/docker/docker-compose.dev.yml index 0ef3041d..0cbf8e00 100644 --- a/apps/nifi/docker/docker-compose.dev.yml +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -14,9 +14,6 @@ x-env-files: - "${COGSTACK_NIFI_ENV_FILE:-../env/nifi.env}" - "${COGSTACK_NETWORK_SETTINGS_ENV_FILE:-../env/network_settings.env}" - nifi-nginx: &nifi-nginx-env-files - - "${COGSTACK_NGINX_ENV_FILE:-../env/nginx.env}" - x-env: nifi: &nifi-env # Apache's native startup settings; existing deployment env names remain supported. @@ -58,10 +55,6 @@ x-mounts: # Security certificates - ../../../deployment/security/certificates/nifi:/security/certificates/nifi:ro - - ../../../deployment/security/certificates/elastic/opensearch/elasticsearch:/security/certificates/elastic/opensearch/elasticsearch:ro - - ../../../deployment/security/certificates/elastic/opensearch/elastic-stack-ca.crt.pem:/security/certificates/elastic/opensearch/elastic-stack-ca.crt.pem:ro - - ../../../deployment/security/certificates/elastic/opensearch/es_kibana_client.pem:/security/certificates/elastic/opensearch/es_kibana_client.pem:ro - - ../../../deployment/security/certificates/elastic/opensearch/es_kibana_client.key:/security/certificates/elastic/opensearch/es_kibana_client.key:ro - ../../../deployment/security/certificates/root/root-ca.pem:/security/certificates/root/root-ca.pem:ro # Apache startup configures image defaults in this persistent, writable directory. - nifi-vol-conf:/opt/nifi/nifi-current/conf @@ -91,13 +84,6 @@ x-networks: cognet: &cognet - cognet -x-common-hosts: &common-hosts - - ${ELASTICSEARCH_1_HOST_NAME:-test-1:0.0.0.0} - - ${ELASTICSEARCH_2_HOST_NAME:-test-2:0.0.0.0} - - ${ELASTICSEARCH_3_HOST_NAME:-test-3:0.0.0.0} - - ${KIBANA_HOST_NAME:-test-4:0.0.0.0} - - ${NIFI_HOST_NAME:-test-5:0.0.0.0} - x-common-ulimits: &common-ulimits ulimits: nofile: @@ -112,7 +98,6 @@ x-nifi-common: &nifi-common <<: *common-ulimits restart: unless-stopped env_file: *all-env - extra_hosts: *common-hosts networks: *cognet #---------------------------------------------------------------------------# # Used services # @@ -124,7 +109,7 @@ services: #---------------------------------------------------------------------------# nifi: <<: *nifi-common - image: ${NIFI_LOCAL_DOCKER_IMAGE:-cogstack/cogstack-nifi:local} + image: ${NIFI_LOCAL_DOCKER_IMAGE:-cogstacksystems/nifi:local} pull_policy: build build: context: .. @@ -136,7 +121,7 @@ services: NIFI_GID: ${COGSTACK_LOCAL_GID:-1000} container_name: cogstack-nifi hostname: nifi - shm_size: ${NIFI_DOCKER_SHM_SIZE:-"1g"} + shm_size: ${NIFI_DOCKER_SHM_SIZE:-1g} environment: *nifi-env deploy: resources: @@ -165,7 +150,6 @@ services: container_name: cogstack-nifi-nginx restart: always shm_size: ${NGINX_SHM_SIZE:-512mb} - env_file: *nifi-nginx-env-files environment: *nifi-nginx-env stop_grace_period: 90s read_only: true @@ -173,16 +157,15 @@ services: deploy: resources: limits: - cpus: "${NGINX_DOCKER_CPU_MAX}" - memory: "${NGINX_DOCKER_RAM}" + cpus: "${NGINX_DOCKER_CPU_MAX:-1}" + memory: "${NGINX_DOCKER_RAM:-1g}" reservations: - cpus: "${NGINX_DOCKER_CPU_MIN}" - memory: "${NGINX_DOCKER_RAM}" + cpus: "${NGINX_DOCKER_CPU_MIN:-1}" + memory: "${NGINX_DOCKER_RAM:-1g}" volumes: *nifi-nginx-volumes ports: - "${NIFI_EXTERNAL_PORT_NGINX:-8443}:${NIFI_INTERNAL_PORT_NGINX:-8443}" networks: *cognet - extra_hosts: *common-hosts logging: *nifi-logging-common #---------------------------------------------------------------------------# diff --git a/apps/nifi/docker/export_env_vars.sh b/apps/nifi/docker/export_env_vars.sh index bff998ca..7eb1e47b 100755 --- a/apps/nifi/docker/export_env_vars.sh +++ b/apps/nifi/docker/export_env_vars.sh @@ -15,7 +15,6 @@ _cogstack_load_environment() { ../env/general.env ../env/nifi.env ../env/network_settings.env - ../env/nginx.env ) local relative_file selected_file variable_name file_name local restore_allexport=1 @@ -39,21 +38,6 @@ _cogstack_load_environment() { } done - # Service-owned configuration remains optional and uses its own directories. - local service_files=( - ../../jupyter-hub/env/jupyter.env - ) - for relative_file in "${service_files[@]}"; do - selected_file="$deploy_path/$relative_file" - if [[ -f "$selected_file" ]]; then - # shellcheck disable=SC1090 - source "$selected_file" || { - echo "ERROR: Failed to load service configuration: $selected_file" >&2 - if [[ "$restore_allexport" == 1 ]]; then set +a; fi - return 1 - } - fi - done # Local image builds match bind-mounted configuration/certificate ownership. # Published images retain their Dockerfile's default non-root UID/GID. export COGSTACK_LOCAL_UID="${COGSTACK_LOCAL_UID:-$(id -u)}" From 22caee3e04941f6a162cd8a61b2a8ccd769bed4b Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 10:17:26 +0000 Subject: [PATCH 05/16] Created symlinks to /apps//env/ files for prod use. --- apps/nifi/README.md | 4 ++-- apps/nifi/docker/Makefile | 4 +++- apps/nifi/docker/docker-compose.dev.yml | 1 - apps/nifi/docker/export_env_vars.sh | 1 - deployment/.gitignore | 7 +++++++ deployment/env/cohorter.env | 1 + deployment/env/jupyter.env | 1 + deployment/env/ocr_service.env | 1 + deployment/env/ocr_service_text_only.env | 1 + 9 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 deployment/.gitignore create mode 120000 deployment/env/cohorter.env create mode 120000 deployment/env/jupyter.env create mode 120000 deployment/env/ocr_service.env create mode 120000 deployment/env/ocr_service_text_only.env diff --git a/apps/nifi/README.md b/apps/nifi/README.md index dd486958..3aeb496b 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -70,8 +70,8 @@ and [`deployment/charts/nginx`](../../deployment/charts/nginx/README.md). Their READMEs describe the required environment ConfigMaps, TLS Secrets and storage. `docker/docker-compose.dev.yml` runs NiFi and the shared NGINX application from -`apps/nginx`. The environment loader uses the app's `env/general.env`, -`env/nifi.env` and `env/network_settings.env` files. NGINX uses its image defaults +`apps/nginx`. The environment loader uses the app's `env/general.env` and +`env/nifi.env` files. NGINX uses its image defaults and the resource limits in Compose. Supply the local files, NiFi credentials and TLS certificates before using the Compose helpers. The image build above works independently of them. diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index 2d9d64b8..8dd89e42 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -68,6 +68,8 @@ build-nifi-image: ## Build the local NiFi image without starting services stop-nifi-dev: ## Stop NiFi and NiFi nginx (docker-compose.dev.yml) $(WITH_ENV) docker compose -f docker-compose.dev.yml $(DC_STOP_CMD) nifi nifi-nginx +delete-nifi: delete-nifi-dev-containers ## Stop and remove the NiFi and NGINX containers + delete-nifi-dev-containers: ## Remove NiFi containers from docker-compose.dev.yml $(WITH_ENV) docker compose -f docker-compose.dev.yml rm -f -s nifi nifi-nginx @@ -79,4 +81,4 @@ delete-nifi-dev-images: ## Delete NiFi images referenced in docker-compose.dev.y echo "No NiFi images found in docker-compose.dev.yml"; \ fi -.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build build-nifi-image stop-nifi-dev delete-nifi-dev-containers delete-nifi-dev-images +.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build build-nifi-image stop-nifi-dev delete-nifi delete-nifi-dev-containers delete-nifi-dev-images diff --git a/apps/nifi/docker/docker-compose.dev.yml b/apps/nifi/docker/docker-compose.dev.yml index 0cbf8e00..7f5795a5 100644 --- a/apps/nifi/docker/docker-compose.dev.yml +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -12,7 +12,6 @@ x-env-files: all: &all-env - "${COGSTACK_GENERAL_ENV_FILE:-../env/general.env}" - "${COGSTACK_NIFI_ENV_FILE:-../env/nifi.env}" - - "${COGSTACK_NETWORK_SETTINGS_ENV_FILE:-../env/network_settings.env}" x-env: nifi: &nifi-env diff --git a/apps/nifi/docker/export_env_vars.sh b/apps/nifi/docker/export_env_vars.sh index 7eb1e47b..988dfaac 100755 --- a/apps/nifi/docker/export_env_vars.sh +++ b/apps/nifi/docker/export_env_vars.sh @@ -14,7 +14,6 @@ _cogstack_load_environment() { local relative_files=( ../env/general.env ../env/nifi.env - ../env/network_settings.env ) local relative_file selected_file variable_name file_name local restore_allexport=1 diff --git a/deployment/.gitignore b/deployment/.gitignore new file mode 100644 index 00000000..7893fda1 --- /dev/null +++ b/deployment/.gitignore @@ -0,0 +1,7 @@ +# Deployment links to app env files included in the repository. +!/env/ +/env/* +!/env/cohorter.env +!/env/jupyter.env +!/env/ocr_service.env +!/env/ocr_service_text_only.env diff --git a/deployment/env/cohorter.env b/deployment/env/cohorter.env new file mode 120000 index 00000000..6d2d7595 --- /dev/null +++ b/deployment/env/cohorter.env @@ -0,0 +1 @@ +../../apps/cohorter/env/cohorter.env \ No newline at end of file diff --git a/deployment/env/jupyter.env b/deployment/env/jupyter.env new file mode 120000 index 00000000..5c824515 --- /dev/null +++ b/deployment/env/jupyter.env @@ -0,0 +1 @@ +../../apps/jupyter-hub/env/jupyter.env \ No newline at end of file diff --git a/deployment/env/ocr_service.env b/deployment/env/ocr_service.env new file mode 120000 index 00000000..d65091cd --- /dev/null +++ b/deployment/env/ocr_service.env @@ -0,0 +1 @@ +../../apps/ocr-service/env/ocr_service.env \ No newline at end of file diff --git a/deployment/env/ocr_service_text_only.env b/deployment/env/ocr_service_text_only.env new file mode 120000 index 00000000..dd73e74b --- /dev/null +++ b/deployment/env/ocr_service_text_only.env @@ -0,0 +1 @@ +../../apps/ocr-service/env/ocr_service_text_only.env \ No newline at end of file From 4950d667205d3f8a9901e74025a9b46f2a44269a Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 10:23:41 +0000 Subject: [PATCH 06/16] apps: added extra Makefile opts to NiFi. --- apps/nifi/docker/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index 8dd89e42..825b66dd 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -73,6 +73,11 @@ delete-nifi: delete-nifi-dev-containers ## Stop and remove the NiFi and NGINX co delete-nifi-dev-containers: ## Remove NiFi containers from docker-compose.dev.yml $(WITH_ENV) docker compose -f docker-compose.dev.yml rm -f -s nifi nifi-nginx +delete-nifi-dev-volumes: delete-nifi-dev-containers ## Remove the NiFi and NGINX containers and delete NiFi dev volume data + @$(WITH_ENV) volumes="$$(docker compose -f docker-compose.dev.yml config --format json | \ + jq -r '.volumes[]? | select(.external != true) | .name')" || exit $$?; \ + if [ -n "$$volumes" ]; then docker volume rm -f $$volumes; fi + delete-nifi-dev-images: ## Delete NiFi images referenced in docker-compose.dev.yml $(WITH_ENV) images="$$(docker compose -f docker-compose.dev.yml config --images nifi nifi-nginx | sort -u)"; \ if [ -n "$$images" ]; then \ @@ -81,4 +86,4 @@ delete-nifi-dev-images: ## Delete NiFi images referenced in docker-compose.dev.y echo "No NiFi images found in docker-compose.dev.yml"; \ fi -.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build build-nifi-image stop-nifi-dev delete-nifi delete-nifi-dev-containers delete-nifi-dev-images +.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build build-nifi-image stop-nifi-dev delete-nifi delete-nifi-dev-containers delete-nifi-dev-volumes delete-nifi-dev-images From e209f258a1ed544ad5b5672cc761c936f183897e Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 10:42:45 +0000 Subject: [PATCH 07/16] apps: added extra nifi compose files. --- apps/nifi/README.md | 25 ++- apps/nifi/docker/Makefile | 38 +++-- apps/nifi/docker/docker-compose.base.yml | 172 +++++++++++++++++++ apps/nifi/docker/docker-compose.dev.yml | 201 ++--------------------- apps/nifi/docker/docker-compose.prod.yml | 5 + apps/nifi/docker/docker-compose.yml | 4 + 6 files changed, 241 insertions(+), 204 deletions(-) create mode 100644 apps/nifi/docker/docker-compose.base.yml create mode 100644 apps/nifi/docker/docker-compose.prod.yml create mode 100644 apps/nifi/docker/docker-compose.yml diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 3aeb496b..6abf662c 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -69,12 +69,25 @@ The Kubernetes charts live in and [`deployment/charts/nginx`](../../deployment/charts/nginx/README.md). Their READMEs describe the required environment ConfigMaps, TLS Secrets and storage. -`docker/docker-compose.dev.yml` runs NiFi and the shared NGINX application from -`apps/nginx`. The environment loader uses the app's `env/general.env` and -`env/nifi.env` files. NGINX uses its image defaults -and the resource limits in Compose. Supply the local files, NiFi credentials and -TLS certificates before using the Compose helpers. The image build above works -independently of them. +NiFi and NGINX share service settings, TLS mounts and volumes in +`docker/docker-compose.base.yml`. Run these commands from `apps/nifi/docker`: + +| Command | Configuration | +| --- | --- | +| `make check-config` | Validate default, dev and prod without starting containers. | +| `make start-nifi-dev-build` | Apply `docker-compose.dev.yml` over the base. Build both images locally, mount local NiFi source, and use `nifi-dev-net`. | +| `source ./export_env_vars.sh && docker compose up -d` | Use `docker-compose.yml` to run published images on a Compose-managed `cogstack-net`. | +| `make start-nifi-prod` | Apply `docker-compose.prod.yml` over the base. Run published images on an existing `cogstack-net`. | + +Set `NIFI_IMAGE` and `NIFI_NGINX_IMAGE` to pin image references for default or +prod. Both publish NiFi through NGINX, and dev also exposes NiFi directly. +Compose uses `docker-compose.override.yml` with the default entry point if you +add one. Append an explicit `-f` for any additional dev or prod overrides. + +Provide `env/general.env`, `env/nifi.env`, NiFi credentials and TLS certificates +before starting the stack. For a published-image deployment, make the mounted +files readable by the image users and set `NIFI_WEB_PROXY_HOST` for the public +host and port. The image build above works independently of these files. Certificates live in the shared `deployment/security/certificates/` directory at the repository root. Put the CA in `root/root-ca.pem` and the NiFi files diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index 825b66dd..fd173eb4 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -3,6 +3,9 @@ SHELL := /usr/bin/env bash DC_START_CMD := up -d DC_STOP_CMD := stop +COMPOSE_DEV := docker compose -f docker-compose.base.yml -f docker-compose.dev.yml +COMPOSE_PROD := docker compose -f docker-compose.base.yml -f docker-compose.prod.yml + define WITH_ENV source ./export_env_vars.sh || exit $$?; endef @@ -46,14 +49,18 @@ load-env: ## Load variables from export_env_vars.sh in a subshell show-env: ## Print sorted environment variables after loading export_env_vars.sh ${WITH_ENV} >/dev/null 2>&1; printenv | sort -check-config: ## Validate the NiFi dev Compose file - @$(WITH_ENV) docker compose -f docker-compose.dev.yml config --quiet +check-config: ## Validate the default, dev and prod Compose configurations + @$(WITH_ENV) docker compose config --quiet && \ + $(COMPOSE_DEV) config --quiet && $(COMPOSE_PROD) config --quiet -start-nifi-dev: ## Start NiFi and NiFi nginx (docker-compose.dev.yml) - $(WITH_ENV) docker compose -f docker-compose.dev.yml $(DC_START_CMD) nifi nifi-nginx +start-nifi-dev: ## Start NiFi and NGINX with local builds + $(WITH_ENV) $(COMPOSE_DEV) $(DC_START_CMD) nifi nifi-nginx start-nifi-dev-build: ## Build and start NiFi dev services - $(WITH_ENV) docker compose -f docker-compose.dev.yml up -d --build nifi nifi-nginx + $(WITH_ENV) $(COMPOSE_DEV) up -d --build nifi nifi-nginx + +start-nifi-prod: ## Start the published NiFi and NGINX images on cogstack-net + $(WITH_ENV) $(COMPOSE_PROD) $(DC_START_CMD) build-nifi-image: ## Build the local NiFi image without starting services $(WITH_ENV) docker build \ @@ -65,25 +72,28 @@ build-nifi-image: ## Build the local NiFi image without starting services --file ../Dockerfile \ .. -stop-nifi-dev: ## Stop NiFi and NiFi nginx (docker-compose.dev.yml) - $(WITH_ENV) docker compose -f docker-compose.dev.yml $(DC_STOP_CMD) nifi nifi-nginx +stop-nifi-dev: ## Stop the NiFi dev services + $(WITH_ENV) $(COMPOSE_DEV) $(DC_STOP_CMD) nifi nifi-nginx + +stop-nifi-prod: ## Stop the NiFi prod services + $(WITH_ENV) $(COMPOSE_PROD) $(DC_STOP_CMD) delete-nifi: delete-nifi-dev-containers ## Stop and remove the NiFi and NGINX containers -delete-nifi-dev-containers: ## Remove NiFi containers from docker-compose.dev.yml - $(WITH_ENV) docker compose -f docker-compose.dev.yml rm -f -s nifi nifi-nginx +delete-nifi-dev-containers: ## Remove the NiFi dev containers + $(WITH_ENV) $(COMPOSE_DEV) rm -f -s nifi nifi-nginx delete-nifi-dev-volumes: delete-nifi-dev-containers ## Remove the NiFi and NGINX containers and delete NiFi dev volume data - @$(WITH_ENV) volumes="$$(docker compose -f docker-compose.dev.yml config --format json | \ + @$(WITH_ENV) volumes="$$($(COMPOSE_DEV) config --format json | \ jq -r '.volumes[]? | select(.external != true) | .name')" || exit $$?; \ if [ -n "$$volumes" ]; then docker volume rm -f $$volumes; fi -delete-nifi-dev-images: ## Delete NiFi images referenced in docker-compose.dev.yml - $(WITH_ENV) images="$$(docker compose -f docker-compose.dev.yml config --images nifi nifi-nginx | sort -u)"; \ +delete-nifi-dev-images: ## Delete the NiFi dev images + $(WITH_ENV) images="$$($(COMPOSE_DEV) config --images nifi nifi-nginx | sort -u)" || exit $$?; \ if [ -n "$$images" ]; then \ docker image rm -f $$images; \ else \ - echo "No NiFi images found in docker-compose.dev.yml"; \ + echo "No NiFi dev images found."; \ fi -.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build build-nifi-image stop-nifi-dev delete-nifi delete-nifi-dev-containers delete-nifi-dev-volumes delete-nifi-dev-images +.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build start-nifi-prod build-nifi-image stop-nifi-dev stop-nifi-prod delete-nifi delete-nifi-dev-containers delete-nifi-dev-volumes delete-nifi-dev-images diff --git a/apps/nifi/docker/docker-compose.base.yml b/apps/nifi/docker/docker-compose.base.yml new file mode 100644 index 00000000..163ec7c5 --- /dev/null +++ b/apps/nifi/docker/docker-compose.base.yml @@ -0,0 +1,172 @@ +#---------------------------------------------------------------------------# +# Common snippets / anchors # +#---------------------------------------------------------------------------# + +x-nifi-logging-common: &nifi-logging-common + driver: "json-file" + options: + max-size: ${NIFI_DOCKER_LOG_SIZE_PER_FILE:-250m} + max-file: ${NIFI_DOCKER_LOG_NUM_FILES:-10} + +x-env-files: + all: &all-env + - "${COGSTACK_GENERAL_ENV_FILE:-../env/general.env}" + - "${COGSTACK_NIFI_ENV_FILE:-../env/nifi.env}" + +x-env: + nifi: &nifi-env + # Apache's native startup settings; existing deployment env names remain supported. + AUTH: ${AUTH:-tls} + NIFI_SECURITY_USER_AUTHORIZER: ${NIFI_SECURITY_USER_AUTHORIZER:-single-user-authorizer} + NIFI_SECURITY_USER_LOGIN_IDENTITY_PROVIDER: ${NIFI_SECURITY_USER_LOGIN_IDENTITY_PROVIDER:-single-user-provider} + SINGLE_USER_CREDENTIALS_USERNAME: ${SINGLE_USER_CREDENTIALS_USERNAME:-${NIFI_SINGLE_USER_CREDENTIALS_USERNAME}} + SINGLE_USER_CREDENTIALS_PASSWORD: ${SINGLE_USER_CREDENTIALS_PASSWORD:-${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD}} + KEYSTORE_PATH: ${KEYSTORE_PATH:-${NIFI_KEYSTORE_PATH}} + KEYSTORE_TYPE: ${KEYSTORE_TYPE:-${NIFI_KEYSTORE_TYPE}} + KEYSTORE_PASSWORD: ${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD}} + TRUSTSTORE_PATH: ${TRUSTSTORE_PATH:-${NIFI_TRUSTSTORE_PATH}} + TRUSTSTORE_TYPE: ${TRUSTSTORE_TYPE:-${NIFI_TRUSTSTORE_TYPE}} + TRUSTSTORE_PASSWORD: ${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD}} + NIFI_WEB_HTTPS_PORT: ${NIFI_WEB_HTTPS_PORT:-${NIFI_INTERNAL_PORT:-8443}} + NIFI_REMOTE_INPUT_SOCKET_PORT: ${NIFI_REMOTE_INPUT_SOCKET_PORT:-${NIFI_INPUT_SOCKET_PORT:-10000}} + PYTHONPATH: ${NIFI_PYTHONPATH:-/opt/nifi/nifi-current/python/framework} + JVM_OPTS: ${NIFI_JVM_OPTS:--XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+ParallelRefProcEnabled -Djava.security.egd=file:/dev/./urandom} + + nifi-nginx: &nifi-nginx-env + NIFI_INTERNAL_PORT_NGINX: ${NIFI_INTERNAL_PORT_NGINX:-8443} + NIFI_WEB_PROXY_PORT: ${NIFI_WEB_PROXY_PORT:-8443} + NIFI_INTERNAL_PORT: ${NIFI_INTERNAL_PORT:-8443} + NIFI_UPSTREAM_HOST: ${NIFI_UPSTREAM_HOST:-nifi} + NIFI_UPSTREAM_PORT: ${NIFI_UPSTREAM_PORT:-${NIFI_INTERNAL_PORT:-8443}} + NIFI_UPSTREAM_TLS_NAME: ${NIFI_UPSTREAM_TLS_NAME:-nifi} + +x-mounts: + nifi: &nifi-volumes + # Security certificates + - ../../../deployment/security/certificates/nifi:/security/certificates/nifi:ro + - ../../../deployment/security/certificates/root/root-ca.pem:/security/certificates/root/root-ca.pem:ro + # Apache startup configures image defaults in this persistent, writable directory. + - nifi-vol-conf:/opt/nifi/nifi-current/conf + + # Ingest data directory + - ${NIFI_DATA_PATH:-../data/}:/data/:rw + + # NiFi repositories/state + - nifi-vol-logs:/opt/nifi/nifi-current/logs + - nifi-vol-provenance:/opt/nifi/nifi-current/provenance_repository + - nifi-vol-database:/opt/nifi/nifi-current/database_repository + - nifi-vol-flowfiles:/opt/nifi/nifi-current/flowfile_repository + - nifi-vol-content:/opt/nifi/nifi-current/content_repository + - nifi-vol-state:/opt/nifi/nifi-current/state + + # Flowfile error output + - nifi-vol-errors:/opt/nifi/pipeline/flowfile-errors + + nifi-nginx-tmpfs: &nifi-nginx-tmpfs + - /tmp:mode=1777 + + nifi-nginx: &nifi-nginx-volumes + - ../../../deployment/security/certificates/nifi:/certificates/nifi:ro + - ../../../deployment/security/certificates/root/root-ca.pem:/certificates/root/root-ca.pem:ro + +x-networks: + cognet: &cognet + - cognet + +x-common-ulimits: &common-ulimits + ulimits: + nofile: + soft: 65535 + hard: 65535 + nproc: 65535 + memlock: + soft: -1 + hard: -1 + +x-nifi-common: &nifi-common + <<: *common-ulimits + restart: unless-stopped + env_file: *all-env + networks: *cognet +#---------------------------------------------------------------------------# +# Used services # +#---------------------------------------------------------------------------# +services: + +#---------------------------------------------------------------------------# +# NiFi webapp # +#---------------------------------------------------------------------------# + nifi: + <<: *nifi-common + image: ${NIFI_IMAGE:-cogstacksystems/nifi:latest} + hostname: nifi + shm_size: ${NIFI_DOCKER_SHM_SIZE:-1g} + environment: *nifi-env + deploy: + resources: + limits: + cpus: "${NIFI_DOCKER_CPU_MAX}" + memory: "${NIFI_DOCKER_RAM}" + reservations: + cpus: "${NIFI_DOCKER_CPU_MIN}" + memory: "${NIFI_DOCKER_RAM}" + volumes: *nifi-volumes + + stop_grace_period: 120s + logging: *nifi-logging-common + + nifi-nginx: + image: ${NIFI_NGINX_IMAGE:-cogstacksystems/nginx:latest} + restart: always + shm_size: ${NGINX_SHM_SIZE:-512mb} + environment: *nifi-nginx-env + stop_grace_period: 90s + read_only: true + tmpfs: *nifi-nginx-tmpfs + deploy: + resources: + limits: + cpus: "${NGINX_DOCKER_CPU_MAX:-1}" + memory: "${NGINX_DOCKER_RAM:-1g}" + reservations: + cpus: "${NGINX_DOCKER_CPU_MIN:-1}" + memory: "${NGINX_DOCKER_RAM:-1g}" + volumes: *nifi-nginx-volumes + ports: + - "${NIFI_EXTERNAL_PORT_NGINX:-8443}:${NIFI_INTERNAL_PORT_NGINX:-8443}" + networks: *cognet + logging: *nifi-logging-common + +#---------------------------------------------------------------------------# +# Docker named volumes # +#---------------------------------------------------------------------------# +volumes: + nifi-vol-conf: + # NiFi related + nifi-vol-logs: + driver: local + + nifi-vol-provenance: + driver: local + + nifi-vol-database: + driver: local + + nifi-vol-flowfiles: + driver: local + + nifi-vol-content: + driver: local + + nifi-vol-state: + driver: local + + nifi-vol-errors: + driver: local + +#---------------------------------------------------------------------------# +# Docker networks. # +#---------------------------------------------------------------------------# +networks: + cognet: + name: cogstack-net diff --git a/apps/nifi/docker/docker-compose.dev.yml b/apps/nifi/docker/docker-compose.dev.yml index 7f5795a5..e2440b20 100644 --- a/apps/nifi/docker/docker-compose.dev.yml +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -1,144 +1,28 @@ -#---------------------------------------------------------------------------# -# Common snippets / anchors # -#---------------------------------------------------------------------------# - -x-nifi-logging-common: &nifi-logging-common - driver: "json-file" - options: - max-size: ${NIFI_DOCKER_LOG_SIZE_PER_FILE:-250m} - max-file: ${NIFI_DOCKER_LOG_NUM_FILES:-10} - -x-env-files: - all: &all-env - - "${COGSTACK_GENERAL_ENV_FILE:-../env/general.env}" - - "${COGSTACK_NIFI_ENV_FILE:-../env/nifi.env}" - -x-env: - nifi: &nifi-env - # Apache's native startup settings; existing deployment env names remain supported. - AUTH: ${AUTH:-tls} - NIFI_SECURITY_USER_AUTHORIZER: ${NIFI_SECURITY_USER_AUTHORIZER:-single-user-authorizer} - NIFI_SECURITY_USER_LOGIN_IDENTITY_PROVIDER: ${NIFI_SECURITY_USER_LOGIN_IDENTITY_PROVIDER:-single-user-provider} - SINGLE_USER_CREDENTIALS_USERNAME: ${SINGLE_USER_CREDENTIALS_USERNAME:-${NIFI_SINGLE_USER_CREDENTIALS_USERNAME}} - SINGLE_USER_CREDENTIALS_PASSWORD: ${SINGLE_USER_CREDENTIALS_PASSWORD:-${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD}} - KEYSTORE_PATH: ${KEYSTORE_PATH:-${NIFI_KEYSTORE_PATH}} - KEYSTORE_TYPE: ${KEYSTORE_TYPE:-${NIFI_KEYSTORE_TYPE}} - KEYSTORE_PASSWORD: ${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD}} - TRUSTSTORE_PATH: ${TRUSTSTORE_PATH:-${NIFI_TRUSTSTORE_PATH}} - TRUSTSTORE_TYPE: ${TRUSTSTORE_TYPE:-${NIFI_TRUSTSTORE_TYPE}} - TRUSTSTORE_PASSWORD: ${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD}} - NIFI_WEB_HTTPS_PORT: ${NIFI_WEB_HTTPS_PORT:-${NIFI_INTERNAL_PORT:-8443}} - NIFI_REMOTE_INPUT_SOCKET_PORT: ${NIFI_REMOTE_INPUT_SOCKET_PORT:-${NIFI_INPUT_SOCKET_PORT:-10000}} - PYTHONPATH: ${NIFI_PYTHONPATH:-/opt/nifi/nifi-current/python/framework} - JVM_OPTS: ${NIFI_JVM_OPTS:--XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+ParallelRefProcEnabled -Djava.security.egd=file:/dev/./urandom} - - nifi-nginx: &nifi-nginx-env - NIFI_INTERNAL_PORT_NGINX: ${NIFI_INTERNAL_PORT_NGINX:-8443} - NIFI_WEB_PROXY_PORT: ${NIFI_WEB_PROXY_PORT:-8443} - NIFI_INTERNAL_PORT: ${NIFI_INTERNAL_PORT:-8443} - NIFI_UPSTREAM_HOST: ${NIFI_UPSTREAM_HOST:-nifi} - NIFI_UPSTREAM_PORT: ${NIFI_UPSTREAM_PORT:-${NIFI_INTERNAL_PORT:-8443}} - NIFI_UPSTREAM_TLS_NAME: ${NIFI_UPSTREAM_TLS_NAME:-nifi} - -x-mounts: - nifi: &nifi-volumes - # Drivers - - ../drivers:/opt/nifi/drivers:ro - - # User overrides bundled in the image - - ../user_scripts:/opt/nifi/user_scripts:rw - - ../user_schemas:/opt/nifi/user_schemas:ro - - # Python processors (NiFi 2.x) - - ../user_python_extensions:/opt/nifi/nifi-current/python_extensions:rw - - # Security certificates - - ../../../deployment/security/certificates/nifi:/security/certificates/nifi:ro - - ../../../deployment/security/certificates/root/root-ca.pem:/security/certificates/root/root-ca.pem:ro - # Apache startup configures image defaults in this persistent, writable directory. - - nifi-vol-conf:/opt/nifi/nifi-current/conf - - # Ingest data directory - - ${NIFI_DATA_PATH:-../data/}:/data/:rw - - # NiFi repositories/state - - nifi-vol-logs:/opt/nifi/nifi-current/logs - - nifi-vol-provenance:/opt/nifi/nifi-current/provenance_repository - - nifi-vol-database:/opt/nifi/nifi-current/database_repository - - nifi-vol-flowfiles:/opt/nifi/nifi-current/flowfile_repository - - nifi-vol-content:/opt/nifi/nifi-current/content_repository - - nifi-vol-state:/opt/nifi/nifi-current/state - - # Flowfile error output - - nifi-vol-errors:/opt/nifi/pipeline/flowfile-errors - - nifi-nginx-tmpfs: &nifi-nginx-tmpfs - - /tmp:mode=1777 - - nifi-nginx: &nifi-nginx-volumes - - ../../../deployment/security/certificates/nifi:/certificates/nifi:ro - - ../../../deployment/security/certificates/root/root-ca.pem:/certificates/root/root-ca.pem:ro - -x-networks: - cognet: &cognet - - cognet - -x-common-ulimits: &common-ulimits - ulimits: - nofile: - soft: 65535 - hard: 65535 - nproc: 65535 - memlock: - soft: -1 - hard: -1 - -x-nifi-common: &nifi-common - <<: *common-ulimits - restart: unless-stopped - env_file: *all-env - networks: *cognet -#---------------------------------------------------------------------------# -# Used services # -#---------------------------------------------------------------------------# services: - -#---------------------------------------------------------------------------# -# NiFi webapp # -#---------------------------------------------------------------------------# nifi: - <<: *nifi-common + container_name: cogstack-nifi image: ${NIFI_LOCAL_DOCKER_IMAGE:-cogstacksystems/nifi:local} pull_policy: build build: - context: .. - dockerfile: Dockerfile - args: - NIFI_VERSION: ${NIFI_VERSION:-2.12.0} - NIFI_BASE_IMAGE: ${NIFI_BASE_IMAGE:?Source docker/export_env_vars.sh first} - NIFI_UID: ${COGSTACK_LOCAL_UID:-1000} - NIFI_GID: ${COGSTACK_LOCAL_GID:-1000} - container_name: cogstack-nifi - hostname: nifi - shm_size: ${NIFI_DOCKER_SHM_SIZE:-1g} - environment: *nifi-env - deploy: - resources: - limits: - cpus: "${NIFI_DOCKER_CPU_MAX}" - memory: "${NIFI_DOCKER_RAM}" - reservations: - cpus: "${NIFI_DOCKER_CPU_MIN}" - memory: "${NIFI_DOCKER_RAM}" - volumes: *nifi-volumes - - stop_grace_period: 120s + context: .. + dockerfile: Dockerfile + args: + NIFI_VERSION: ${NIFI_VERSION:-2.12.0} + NIFI_BASE_IMAGE: ${NIFI_BASE_IMAGE:?Source docker/export_env_vars.sh first} + NIFI_UID: ${COGSTACK_LOCAL_UID:-1000} + NIFI_GID: ${COGSTACK_LOCAL_GID:-1000} + volumes: + - ../drivers:/opt/nifi/drivers:ro + - ../user_scripts:/opt/nifi/user_scripts:rw + - ../user_schemas:/opt/nifi/user_schemas:ro + - ../user_python_extensions:/opt/nifi/nifi-current/python_extensions:rw ports: - "${NIFI_OUTPUT_PORT:-8082}:${NIFI_INTERNAL_PORT:-8443}" - "${NIFI_INPUT_SOCKET_PORT:-10000}" - logging: *nifi-logging-common - + nifi-nginx: + container_name: cogstack-nifi-nginx + image: cogstacksystems/nginx:local pull_policy: build build: context: ../../nginx @@ -146,58 +30,7 @@ services: args: NGINX_UID: ${COGSTACK_LOCAL_UID:-1000} NGINX_GID: ${COGSTACK_LOCAL_GID:-1000} - container_name: cogstack-nifi-nginx - restart: always - shm_size: ${NGINX_SHM_SIZE:-512mb} - environment: *nifi-nginx-env - stop_grace_period: 90s - read_only: true - tmpfs: *nifi-nginx-tmpfs - deploy: - resources: - limits: - cpus: "${NGINX_DOCKER_CPU_MAX:-1}" - memory: "${NGINX_DOCKER_RAM:-1g}" - reservations: - cpus: "${NGINX_DOCKER_CPU_MIN:-1}" - memory: "${NGINX_DOCKER_RAM:-1g}" - volumes: *nifi-nginx-volumes - ports: - - "${NIFI_EXTERNAL_PORT_NGINX:-8443}:${NIFI_INTERNAL_PORT_NGINX:-8443}" - networks: *cognet - logging: *nifi-logging-common - -#---------------------------------------------------------------------------# -# Docker named volumes # -#---------------------------------------------------------------------------# -volumes: - nifi-vol-conf: - # NiFi related - nifi-vol-logs: - driver: local - - nifi-vol-provenance: - driver: local - - nifi-vol-database: - driver: local - - nifi-vol-flowfiles: - driver: local - - nifi-vol-content: - driver: local - - nifi-vol-state: - driver: local - - nifi-vol-errors: - driver: local -#---------------------------------------------------------------------------# -# Docker networks. # -#---------------------------------------------------------------------------# networks: cognet: - driver: bridge - name: cogstack-net + name: nifi-dev-net diff --git a/apps/nifi/docker/docker-compose.prod.yml b/apps/nifi/docker/docker-compose.prod.yml new file mode 100644 index 00000000..cec3e1a5 --- /dev/null +++ b/apps/nifi/docker/docker-compose.prod.yml @@ -0,0 +1,5 @@ +name: nifi + +networks: + cognet: + external: true diff --git a/apps/nifi/docker/docker-compose.yml b/apps/nifi/docker/docker-compose.yml new file mode 100644 index 00000000..f0586041 --- /dev/null +++ b/apps/nifi/docker/docker-compose.yml @@ -0,0 +1,4 @@ +name: nifi + +include: + - docker-compose.base.yml From 3a0baec26ff4a29c1832100adab4f3dd17c59fed Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 12:19:39 +0000 Subject: [PATCH 08/16] apps: nifi cert mount simplification. --- apps/nifi/README.md | 11 +++++++---- apps/nifi/docker/docker-compose.base.yml | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 6abf662c..56aeb48d 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -89,10 +89,13 @@ before starting the stack. For a published-image deployment, make the mounted files readable by the image users and set `NIFI_WEB_PROXY_HOST` for the public host and port. The image build above works independently of these files. -Certificates live in the shared `deployment/security/certificates/` directory -at the repository root. Put the CA in `root/root-ca.pem` and the NiFi files -(`nifi.pem`, `nifi.key`, `nifi-keystore.jks`, `nifi-truststore.jks`) in `nifi/`. -Both containers mount these files read-only. Certificate contents are ignored by Git. +Place these files under `deployment/security/certificates/`: + +- `nifi/nifi-keystore.jks` and `nifi/nifi-truststore.jks` for NiFi. +- `nginx/tls.crt` and `nginx/tls.key` for the NGINX public hostname. +- `root/root-ca.pem` for both containers to verify NiFi. Keep `root/` limited to public CA material. + +Compose mounts the directories read-only. Git ignores the certificate contents. Supply any ingestion-specific certificate mounts or host overrides in the deployment that needs them. diff --git a/apps/nifi/docker/docker-compose.base.yml b/apps/nifi/docker/docker-compose.base.yml index 163ec7c5..fc28b312 100644 --- a/apps/nifi/docker/docker-compose.base.yml +++ b/apps/nifi/docker/docker-compose.base.yml @@ -39,12 +39,14 @@ x-env: NIFI_UPSTREAM_HOST: ${NIFI_UPSTREAM_HOST:-nifi} NIFI_UPSTREAM_PORT: ${NIFI_UPSTREAM_PORT:-${NIFI_INTERNAL_PORT:-8443}} NIFI_UPSTREAM_TLS_NAME: ${NIFI_UPSTREAM_TLS_NAME:-nifi} + NGINX_TLS_CERTIFICATE: /certificates/nginx/tls.crt + NGINX_TLS_CERTIFICATE_KEY: /certificates/nginx/tls.key x-mounts: nifi: &nifi-volumes # Security certificates - ../../../deployment/security/certificates/nifi:/security/certificates/nifi:ro - - ../../../deployment/security/certificates/root/root-ca.pem:/security/certificates/root/root-ca.pem:ro + - ../../../deployment/security/certificates/root:/security/certificates/root:ro # Apache startup configures image defaults in this persistent, writable directory. - nifi-vol-conf:/opt/nifi/nifi-current/conf @@ -66,8 +68,8 @@ x-mounts: - /tmp:mode=1777 nifi-nginx: &nifi-nginx-volumes - - ../../../deployment/security/certificates/nifi:/certificates/nifi:ro - - ../../../deployment/security/certificates/root/root-ca.pem:/certificates/root/root-ca.pem:ro + - ../../../deployment/security/certificates/nginx:/certificates/nginx:ro + - ../../../deployment/security/certificates/root:/certificates/root:ro x-networks: cognet: &cognet From 34788d4ede887e0e46ffc5f49605705c83e9dfcf Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 14:04:33 +0000 Subject: [PATCH 09/16] apps: removed unused nifi vols. --- apps/nifi/README.md | 2 +- apps/nifi/docker/docker-compose.base.yml | 9 --------- apps/nifi/docker/docker-compose.dev.yml | 1 + 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 56aeb48d..5018445f 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -75,7 +75,7 @@ NiFi and NGINX share service settings, TLS mounts and volumes in | Command | Configuration | | --- | --- | | `make check-config` | Validate default, dev and prod without starting containers. | -| `make start-nifi-dev-build` | Apply `docker-compose.dev.yml` over the base. Build both images locally, mount local NiFi source, and use `nifi-dev-net`. | +| `make start-nifi-dev-build` | Apply `docker-compose.dev.yml` over the base. Build both images locally, mount NiFi source and dev data, and use `nifi-dev-net`. | | `source ./export_env_vars.sh && docker compose up -d` | Use `docker-compose.yml` to run published images on a Compose-managed `cogstack-net`. | | `make start-nifi-prod` | Apply `docker-compose.prod.yml` over the base. Run published images on an existing `cogstack-net`. | diff --git a/apps/nifi/docker/docker-compose.base.yml b/apps/nifi/docker/docker-compose.base.yml index fc28b312..f05d3942 100644 --- a/apps/nifi/docker/docker-compose.base.yml +++ b/apps/nifi/docker/docker-compose.base.yml @@ -50,9 +50,6 @@ x-mounts: # Apache startup configures image defaults in this persistent, writable directory. - nifi-vol-conf:/opt/nifi/nifi-current/conf - # Ingest data directory - - ${NIFI_DATA_PATH:-../data/}:/data/:rw - # NiFi repositories/state - nifi-vol-logs:/opt/nifi/nifi-current/logs - nifi-vol-provenance:/opt/nifi/nifi-current/provenance_repository @@ -61,9 +58,6 @@ x-mounts: - nifi-vol-content:/opt/nifi/nifi-current/content_repository - nifi-vol-state:/opt/nifi/nifi-current/state - # Flowfile error output - - nifi-vol-errors:/opt/nifi/pipeline/flowfile-errors - nifi-nginx-tmpfs: &nifi-nginx-tmpfs - /tmp:mode=1777 @@ -163,9 +157,6 @@ volumes: nifi-vol-state: driver: local - nifi-vol-errors: - driver: local - #---------------------------------------------------------------------------# # Docker networks. # #---------------------------------------------------------------------------# diff --git a/apps/nifi/docker/docker-compose.dev.yml b/apps/nifi/docker/docker-compose.dev.yml index e2440b20..1cfab99b 100644 --- a/apps/nifi/docker/docker-compose.dev.yml +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -12,6 +12,7 @@ services: NIFI_UID: ${COGSTACK_LOCAL_UID:-1000} NIFI_GID: ${COGSTACK_LOCAL_GID:-1000} volumes: + - ${NIFI_DATA_PATH:-../data/}:/data/:rw - ../drivers:/opt/nifi/drivers:ro - ../user_scripts:/opt/nifi/user_scripts:rw - ../user_schemas:/opt/nifi/user_schemas:ro From ccc2bbba0395201d695bfd1b6eb98fe578473830 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 14:16:02 +0000 Subject: [PATCH 10/16] apps: NiFi updates, compose file cleanups. --- apps/nifi/README.md | 5 +++-- apps/nifi/docker/Makefile | 21 ++++++++++++++++----- apps/nifi/docker/docker-compose.base.yml | 4 ++-- apps/nifi/docker/docker-compose.dev.yml | 8 +++++--- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 5018445f..cfcdae3d 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -76,7 +76,7 @@ NiFi and NGINX share service settings, TLS mounts and volumes in | --- | --- | | `make check-config` | Validate default, dev and prod without starting containers. | | `make start-nifi-dev-build` | Apply `docker-compose.dev.yml` over the base. Build both images locally, mount NiFi source and dev data, and use `nifi-dev-net`. | -| `source ./export_env_vars.sh && docker compose up -d` | Use `docker-compose.yml` to run published images on a Compose-managed `cogstack-net`. | +| `make start-nifi` | Use `docker-compose.yml` to run published images on a Compose-managed `cogstack-net`. | | `make start-nifi-prod` | Apply `docker-compose.prod.yml` over the base. Run published images on an existing `cogstack-net`. | Set `NIFI_IMAGE` and `NIFI_NGINX_IMAGE` to pin image references for default or @@ -95,7 +95,8 @@ Place these files under `deployment/security/certificates/`: - `nginx/tls.crt` and `nginx/tls.key` for the NGINX public hostname. - `root/root-ca.pem` for both containers to verify NiFi. Keep `root/` limited to public CA material. -Compose mounts the directories read-only. Git ignores the certificate contents. +The start targets run `make check-tls` to check that these files are readable +and nonempty. Compose mounts the directories read-only. Git ignores their contents. Supply any ingestion-specific certificate mounts or host overrides in the deployment that needs them. diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index fd173eb4..47595514 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -53,19 +53,30 @@ check-config: ## Validate the default, dev and prod Compose configurations @$(WITH_ENV) docker compose config --quiet && \ $(COMPOSE_DEV) config --quiet && $(COMPOSE_PROD) config --quiet -start-nifi-dev: ## Start NiFi and NGINX with local builds +check-tls: ## Check the TLS files required by NiFi and NGINX + @for cert in root/root-ca.pem nifi/nifi-keystore.jks nifi/nifi-truststore.jks nginx/tls.crt nginx/tls.key; do \ + file="../../../deployment/security/certificates/$$cert"; \ + if [ ! -f "$$file" ] || [ ! -r "$$file" ] || [ ! -s "$$file" ]; then \ + printf 'TLS file missing, empty, or unreadable: %s\n' "$$file" >&2; exit 1; \ + fi; \ + done + +start-nifi: check-tls ## Start the default NiFi and NGINX stack + $(WITH_ENV) docker compose $(DC_START_CMD) + +start-nifi-dev: check-tls ## Start NiFi and NGINX with local builds $(WITH_ENV) $(COMPOSE_DEV) $(DC_START_CMD) nifi nifi-nginx -start-nifi-dev-build: ## Build and start NiFi dev services +start-nifi-dev-build: check-tls ## Build and start NiFi dev services $(WITH_ENV) $(COMPOSE_DEV) up -d --build nifi nifi-nginx -start-nifi-prod: ## Start the published NiFi and NGINX images on cogstack-net +start-nifi-prod: check-tls ## Start the published NiFi and NGINX images on cogstack-net $(WITH_ENV) $(COMPOSE_PROD) $(DC_START_CMD) build-nifi-image: ## Build the local NiFi image without starting services $(WITH_ENV) docker build \ --build-arg NIFI_VERSION="$${NIFI_VERSION:-2.12.0}" \ - --build-arg NIFI_BASE_IMAGE="$${NIFI_BASE_IMAGE}" \ + --build-arg NIFI_BASE_IMAGE \ --build-arg NIFI_UID="$${COGSTACK_LOCAL_UID:-1000}" \ --build-arg NIFI_GID="$${COGSTACK_LOCAL_GID:-1000}" \ --tag "$${NIFI_LOCAL_DOCKER_IMAGE:-cogstacksystems/nifi:local}" \ @@ -96,4 +107,4 @@ delete-nifi-dev-images: ## Delete the NiFi dev images echo "No NiFi dev images found."; \ fi -.PHONY: help load-env show-env check-config start-nifi-dev start-nifi-dev-build start-nifi-prod build-nifi-image stop-nifi-dev stop-nifi-prod delete-nifi delete-nifi-dev-containers delete-nifi-dev-volumes delete-nifi-dev-images +.PHONY: help load-env show-env check-config check-tls start-nifi start-nifi-dev start-nifi-dev-build start-nifi-prod build-nifi-image stop-nifi-dev stop-nifi-prod delete-nifi delete-nifi-dev-containers delete-nifi-dev-volumes delete-nifi-dev-images diff --git a/apps/nifi/docker/docker-compose.base.yml b/apps/nifi/docker/docker-compose.base.yml index f05d3942..0e535adf 100644 --- a/apps/nifi/docker/docker-compose.base.yml +++ b/apps/nifi/docker/docker-compose.base.yml @@ -34,10 +34,10 @@ x-env: nifi-nginx: &nifi-nginx-env NIFI_INTERNAL_PORT_NGINX: ${NIFI_INTERNAL_PORT_NGINX:-8443} - NIFI_WEB_PROXY_PORT: ${NIFI_WEB_PROXY_PORT:-8443} + NIFI_WEB_PROXY_PORT: ${NIFI_WEB_PROXY_PORT:-${NIFI_EXTERNAL_PORT_NGINX:-8443}} NIFI_INTERNAL_PORT: ${NIFI_INTERNAL_PORT:-8443} NIFI_UPSTREAM_HOST: ${NIFI_UPSTREAM_HOST:-nifi} - NIFI_UPSTREAM_PORT: ${NIFI_UPSTREAM_PORT:-${NIFI_INTERNAL_PORT:-8443}} + NIFI_UPSTREAM_PORT: ${NIFI_UPSTREAM_PORT:-${NIFI_WEB_HTTPS_PORT:-${NIFI_INTERNAL_PORT:-8443}}} NIFI_UPSTREAM_TLS_NAME: ${NIFI_UPSTREAM_TLS_NAME:-nifi} NGINX_TLS_CERTIFICATE: /certificates/nginx/tls.crt NGINX_TLS_CERTIFICATE_KEY: /certificates/nginx/tls.key diff --git a/apps/nifi/docker/docker-compose.dev.yml b/apps/nifi/docker/docker-compose.dev.yml index 1cfab99b..23159786 100644 --- a/apps/nifi/docker/docker-compose.dev.yml +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -8,9 +8,11 @@ services: dockerfile: Dockerfile args: NIFI_VERSION: ${NIFI_VERSION:-2.12.0} - NIFI_BASE_IMAGE: ${NIFI_BASE_IMAGE:?Source docker/export_env_vars.sh first} + NIFI_BASE_IMAGE: # Use the Dockerfile default when unset. NIFI_UID: ${COGSTACK_LOCAL_UID:-1000} NIFI_GID: ${COGSTACK_LOCAL_GID:-1000} + environment: + NIFI_DATA_PATH: /data/ volumes: - ${NIFI_DATA_PATH:-../data/}:/data/:rw - ../drivers:/opt/nifi/drivers:ro @@ -18,8 +20,8 @@ services: - ../user_schemas:/opt/nifi/user_schemas:ro - ../user_python_extensions:/opt/nifi/nifi-current/python_extensions:rw ports: - - "${NIFI_OUTPUT_PORT:-8082}:${NIFI_INTERNAL_PORT:-8443}" - - "${NIFI_INPUT_SOCKET_PORT:-10000}" + - "${NIFI_OUTPUT_PORT:-8082}:${NIFI_WEB_HTTPS_PORT:-${NIFI_INTERNAL_PORT:-8443}}" + - "${NIFI_REMOTE_INPUT_SOCKET_PORT:-${NIFI_INPUT_SOCKET_PORT:-10000}}" nifi-nginx: container_name: cogstack-nifi-nginx From 1c2aa709abd23e7bbb8cb9ee56007cfdf267bd62 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 14:25:30 +0000 Subject: [PATCH 11/16] apps: nifi readme updates. --- apps/nifi/README.md | 225 +++++++++++++++-------- apps/nifi/user_scripts/utils/lint_env.py | 4 +- 2 files changed, 148 insertions(+), 81 deletions(-) diff --git a/apps/nifi/README.md b/apps/nifi/README.md index cfcdae3d..e050fb34 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -1,113 +1,182 @@ # CogStack NiFi -The CogStack NiFi image, Python processors, JDBC drivers, schemas and flow -templates. These files were migrated from the `nifi/` directory of -`cogstack_nifi`; the Python project metadata, lockfile and type stubs now live -alongside the application. +CogStack's Apache NiFi image bundles Python processors, JDBC drivers, schemas, +and example ingestion flows. The Docker stack serves NiFi over HTTPS through +[CogStack NGINX](../nginx/README.md). -## Contents +## Docker setup -| Path | Purpose | -| --- | --- | -| `Dockerfile` | Build the customised Apache NiFi image. | -| `pyproject.toml`, `uv.lock` | Python package configuration and locked dependencies. | -| `pyrightconfig.json` | Pyright configuration for the local virtual environment, imports and type stubs. | -| `user_python_extensions/` | NiFi 2 Python processors. | -| `user_scripts/` | Shared Python utilities, processors and legacy scripts. | -| `drivers/` | JDBC drivers bundled in the image. | -| `user_schemas/`, `user_templates/` | Schemas and example ingestion flows. | -| `conf/` | Reference configuration from the original application. | -| `docker/` | Container health check and deployment helpers. | -| `typings/` | NiFi API and Py4J stubs for local type checking. | +Use Docker Compose v2 with support for `include`, and Make. The default and +production configurations use `cogstacksystems/nifi` and `cogstacksystems/nginx`. -## Build the image +### Environment files -Run from the platform repository root: +From the repository root, create `apps/nifi/env/` and add `general.env` and +`nifi.env`. Both files are Git-ignored. `general.env` can be empty if you have +no shared settings. Use the following as a starting point for `nifi.env` and +replace the example credentials and passwords before starting NiFi. -```bash -docker build --tag cogstacksystems/nifi:local apps/nifi +```dotenv +NIFI_DOCKER_CPU_MIN=1 +NIFI_DOCKER_CPU_MAX=2 +NIFI_DOCKER_RAM=4g + +SINGLE_USER_CREDENTIALS_USERNAME=admin +SINGLE_USER_CREDENTIALS_PASSWORD='replace-with-a-unique-password' +NIFI_SENSITIVE_PROPS_KEY='replace-with-a-stable-encryption-key' + +KEYSTORE_PATH=/security/certificates/nifi/nifi-keystore.jks +KEYSTORE_TYPE=JKS +KEYSTORE_PASSWORD='replace-with-the-keystore-password' +TRUSTSTORE_PATH=/security/certificates/nifi/nifi-truststore.jks +TRUSTSTORE_TYPE=JKS +TRUSTSTORE_PASSWORD='replace-with-the-truststore-password' + +NIFI_WEB_PROXY_HOST=localhost:8443 +NIFI_HEALTHCHECK_HOST=nifi ``` -`apps/nifi` is the build context. The Dockerfile uses the checked-in dependency -lockfile and bundles the application resources. It keeps Apache's default -configuration and startup scripts; host configuration and environment files are -excluded from the build context. +Use at least 12 characters for the single-user password. Preserve +`NIFI_SENSITIVE_PROPS_KEY` with the flow configuration so NiFi can decrypt +saved sensitive properties. For a non-local deployment, set `NIFI_WEB_PROXY_HOST` +to the browser-facing host and port. If you change `NIFI_EXTERNAL_PORT_NGINX`, +update that allowlist entry as well. See [Apache's startup script](https://github.com/apache/nifi/blob/rel/nifi-2.12.0/nifi-docker/dockerhub/sh/start.sh) +and [Docker setup guide](https://github.com/apache/nifi/blob/rel/nifi-2.12.0/nifi-docker/dockerhub/README.md) +for additional settings. -The `NIFI_BASE_IMAGE`, `NIFI_VERSION`, `GROOVY_VERSION`, `NIFI_UID` and `NIFI_GID` -build arguments can override the Dockerfile defaults. Keep the base image and -`NIFI_VERSION` aligned. Published image names and container resource paths such -as `/opt/nifi/user_scripts` remain the same. +### TLS certificates -## Python development +Place the following under `deployment/security/certificates/`: + +| Files | Purpose | +| --- | --- | +| `nifi/nifi-keystore.jks`, `nifi/nifi-truststore.jks` | NiFi's server identity and truststore. The server certificate must cover the upstream TLS name, `nifi` by default, and the health check hostname. | +| `nginx/tls.crt`, `nginx/tls.key` | NGINX server identity for the hostname users open in their browser. The browser must trust its issuer. | +| `root/root-ca.pem` | Public CA used by NGINX and the NiFi health check to verify NiFi's server certificate. | + +Compose mounts the directories read-only. Keep `root/` for public CA material +and make the mounted files readable by their container users. The start targets +run `make check-tls`, which checks for readable, nonempty regular files. If +`root-ca.pem` is a directory from an earlier bind mount, replace it with the +actual PEM file. Certificate validation occurs when the services connect over TLS. -Use Python 3.11 or later and a version of `uv` satisfying -`tool.uv.required-version` in `pyproject.toml`: +### Start and verify + +Run these commands from `apps/nifi/docker/`: + +| Command | Configuration | +| --- | --- | +| `make check-config` | Resolve and validate all three Compose configurations using the env files. | +| `make start-nifi` | Use `docker-compose.yml` to start published images with a Compose-managed `cogstack-net`. | +| `make start-nifi-dev-build` | Apply `docker-compose.dev.yml` over the base, build both images locally, mount editable NiFi resources and dev data, and use `nifi-dev-net`. | +| `make start-nifi-prod` | Apply `docker-compose.prod.yml` over the base and start published images on an existing `cogstack-net`. | + +Default and prod use Compose project `nifi` and share its named volumes. Dev uses +separate volumes by default. To pin the published images, set `NIFI_IMAGE` and +`NIFI_NGINX_IMAGE` to specific tags or digests. Compose automatically loads a +local `docker-compose.override.yml` with the default entry point. For dev or +prod, pass additional overrides as the last `-f` argument when running Compose +directly. + +Startup runs in the background. With the example settings and working TLS, open +`https://localhost:8443/nifi/` through NGINX. To check the default stack's health +and logs from the same directory: ```bash -uv sync --directory apps/nifi --locked --dev -uv run --directory apps/nifi --locked ruff check user_python_extensions --select F,E9 -uv run --directory apps/nifi --locked mypy --config-file pyproject.toml user_python_extensions +source ./export_env_vars.sh +docker compose ps +docker compose logs --tail=100 nifi nifi-nginx ``` -The package maps this application directory to the existing `nifi` Python -namespace, so imports such as `nifi.user_scripts.utils.generic` continue to work -after installation. When adding Python subpackages, include them in -`tool.setuptools.packages`. Native NiFi processors run inside NiFi, which supplies -the `nifiapi` framework; `typings/` contains stubs for development. +For dev or prod, add `-f docker-compose.base.yml -f docker-compose.dev.yml` or +`-f docker-compose.base.yml -f docker-compose.prod.yml` after `docker compose`. +NiFi checks its local HTTPS API and NGINX checks the upstream path to NiFi. Dev +also publishes NiFi directly on port `8082` by default. Its host data directory +is `apps/nifi/data/` unless overridden by `NIFI_DATA_PATH`, and processors see +it at `/data/`. Add a deployment-specific mount if a published-image flow needs +host data. -Some files under `user_scripts/tests/` are integration tests or example scripts -requiring running services, credentials and sample data. +### Storage and cleanup -For Pyright, use `apps/nifi/pyrightconfig.json` as the project configuration. It -uses the application's `.venv`, resolves the `nifi` package from the parent -`apps/` directory, and includes the local processor and type-stub directories. +The base configuration keeps seven named volumes for configuration, state, +logs, and the database, FlowFile, content, and provenance repositories. Use +`make stop-nifi-dev`, `make stop-nifi-prod`, or `docker compose stop` for the +default stack after sourcing the env files. `make delete-nifi` removes the +**dev** containers and preserves their volumes. `make delete-nifi-dev-volumes` +also deletes their named storage, including saved flows and queued data. Back +up FlowFile and content repositories together when preserving queues. -## Deployment helpers +## Build the image -The Kubernetes charts live in -[`deployment/charts/nifi`](../../deployment/charts/nifi/README.md) -and [`deployment/charts/nginx`](../../deployment/charts/nginx/README.md). Their -READMEs describe the required environment ConfigMaps, TLS Secrets and storage. +From the repository root: -NiFi and NGINX share service settings, TLS mounts and volumes in -`docker/docker-compose.base.yml`. Run these commands from `apps/nifi/docker`: +```bash +docker build --tag cogstacksystems/nifi:local apps/nifi +``` -| Command | Configuration | +The image installs Python dependencies from `uv.lock` and uses Apache's startup +scripts and configuration, with TLS reload and shutdown settings adjusted in the +Dockerfile. [`conf/`](conf/) is reference configuration. The build context +excludes it along with local env files and runtime state. + +Override `NIFI_BASE_IMAGE` and `NIFI_VERSION` together when changing the Apache +version. `GROOVY_VERSION`, `NIFI_UID`, and `NIFI_GID` can also be overridden. + +## Processors and flow resources + +| Path | Contents | | --- | --- | -| `make check-config` | Validate default, dev and prod without starting containers. | -| `make start-nifi-dev-build` | Apply `docker-compose.dev.yml` over the base. Build both images locally, mount NiFi source and dev data, and use `nifi-dev-net`. | -| `make start-nifi` | Use `docker-compose.yml` to run published images on a Compose-managed `cogstack-net`. | -| `make start-nifi-prod` | Apply `docker-compose.prod.yml` over the base. Run published images on an existing `cogstack-net`. | +| [`user_python_extensions/`](user_python_extensions/) | NiFi 2 native Python processors. See the [sample processor](user_python_extensions/sample_processor.py). | +| [`user_scripts/`](user_scripts/) | Shared `nifi.user_scripts` modules, standalone processors, integration examples, and older scripts. | +| [`drivers/`](drivers/) | DuckDB, MySQL, PostgreSQL, and SQL Server JDBC drivers. | +| [`user_schemas/`](user_schemas/) | Search settings and schema examples. | +| [`user_templates/`](user_templates/) | NiFi JSON process groups and legacy XML templates. | + +The image places scripts, drivers, schemas, and templates under `/opt/nifi/` +with the same directory names. Native Python extensions are discovered in +`/opt/nifi/nifi-current/python_extensions`. + +Upload a top-level JSON flow as a process group in the NiFi UI. Configure its +controller services, endpoints, and credentials before enabling the group. +Depending on the example, this may require OpenSearch, PostgreSQL, Azure Blob +Storage, OCR, or MedCAT. Legacy XML templates and schemas are migration +references. Some include older driver names and service paths. + +For the JSON record schema converter, set `json_mapper_schema_path` explicitly. +The bundled common mapping is at +`/opt/nifi/user_schemas/legacy/cogstack_common_schema_mapping.json`. + +## Python development -Set `NIFI_IMAGE` and `NIFI_NGINX_IMAGE` to pin image references for default or -prod. Both publish NiFi through NGINX, and dev also exposes NiFi directly. -Compose uses `docker-compose.override.yml` with the default entry point if you -add one. Append an explicit `-f` for any additional dev or prod overrides. +Use Python 3.11 or later and the `uv` version required by +[`pyproject.toml`](pyproject.toml). From `apps/nifi/`: -Provide `env/general.env`, `env/nifi.env`, NiFi credentials and TLS certificates -before starting the stack. For a published-image deployment, make the mounted -files readable by the image users and set `NIFI_WEB_PROXY_HOST` for the public -host and port. The image build above works independently of these files. +```bash +uv sync --locked --dev +uv run --locked ruff check user_python_extensions --select F,E9 +uv run --locked mypy --config-file pyproject.toml user_python_extensions +``` -Place these files under `deployment/security/certificates/`: +Set your editor's Pyright project to [`pyrightconfig.json`](pyrightconfig.json). +The project uses the local `.venv` and [`typings/`](typings/) for NiFi API and Py4J +stubs. The real `nifiapi` runtime is supplied by NiFi. The package maps this +application directory to the `nifi` namespace. Add new subpackages to +`tool.setuptools.packages` when they need to be installed. -- `nifi/nifi-keystore.jks` and `nifi/nifi-truststore.jks` for NiFi. -- `nginx/tls.crt` and `nginx/tls.key` for the NGINX public hostname. -- `root/root-ca.pem` for both containers to verify NiFi. Keep `root/` limited to public CA material. +The commands above check the native extensions. Files under +[`user_scripts/tests/`](user_scripts/tests/) also include integration scripts +with external service, credential, or sample data requirements. -The start targets run `make check-tls` to check that these files are readable -and nonempty. Compose mounts the directories read-only. Git ignores their contents. -Supply any ingestion-specific certificate mounts or host overrides in the deployment -that needs them. +## Kubernetes -Mutable configuration, data repositories, processor logs and databases belong -in deployment-owned storage. The image health check expects the configured TLS -CA certificate at runtime. +The [NiFi chart](../../deployment/charts/nifi/README.md) and +[NGINX chart](../../deployment/charts/nginx/README.md) document their ConfigMaps, +TLS Secrets, and storage. Use those instructions for Helm deployments. ## Dependency auditing -From the platform repository root, audit the documentation and NiFi dependency -lockfiles with `uv` and `pip-audit` available on `PATH`: +From the repository root, audit the docs and NiFi lockfiles using `uv` and +`pip-audit` on `PATH`: ```bash bash deployment/scripts/maintenance/audit_pip_dependency.sh --include-nifi diff --git a/apps/nifi/user_scripts/utils/lint_env.py b/apps/nifi/user_scripts/utils/lint_env.py index 723927f6..40277971 100644 --- a/apps/nifi/user_scripts/utils/lint_env.py +++ b/apps/nifi/user_scripts/utils/lint_env.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -""" - Lightweight env file validator used by deploy/export_env_vars.sh. -""" +"""Check env files for common formatting and value errors.""" from __future__ import annotations From 08da9e1fe1341ebfa4d0946afbd5862cb9b60349 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 15:16:59 +0000 Subject: [PATCH 12/16] Ported nifi smoketest. --- .github/workflows/smoke_nifi_services.yml | 163 ++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 .github/workflows/smoke_nifi_services.yml diff --git a/.github/workflows/smoke_nifi_services.yml b/.github/workflows/smoke_nifi_services.yml new file mode 100644 index 00000000..8271642a --- /dev/null +++ b/.github/workflows/smoke_nifi_services.yml @@ -0,0 +1,163 @@ +name: smoke-nifi-services + +on: + push: + branches: ['**'] + paths: &paths + - 'apps/nifi/**' + - 'apps/nginx/**' + - '.github/workflows/smoke_nifi_services.yml' + - '!**/*.md' + - '!**/README*' + pull_request: + paths: *paths + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +defaults: + run: + shell: bash + working-directory: apps/nifi/docker + +jobs: + smoke: + name: Build and smoke-test NiFi services + runs-on: ubuntu-24.04 + timeout-minutes: 45 + env: + COMPOSE_FILE: docker-compose.base.yml:docker-compose.dev.yml + COMPOSE_PROJECT_NAME: nifi-smoke + CERT_DIR: ../../../deployment/security/certificates + + steps: + - uses: actions/checkout@v7 + + - name: Set up Java + uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: '21' + + - name: Generate smoke fixtures + run: | + scratch_dir="$(mktemp -d)" + trap 'rm -rf "$scratch_dir"' EXIT + mkdir -p "$CERT_DIR"/{root,nifi,nginx} ../env + ca_cert="$CERT_DIR/root/root-ca.pem" + password="$(openssl rand -hex 16)" + + openssl req -x509 -newkey rsa:2048 -nodes -days 1 -subj '/CN=NiFi smoke CA' \ + -addext 'basicConstraints=critical,CA:TRUE' \ + -addext 'keyUsage=critical,keyCertSign,cRLSign' \ + -keyout "$scratch_dir/ca.key" -out "$ca_cert" + + issue_cert() { + local subject="$1" san="$2" key="$3" cert="$4" + openssl req -new -newkey rsa:2048 -nodes -subj "/CN=$subject" \ + -keyout "$key" -out "$scratch_dir/leaf.csr" + openssl x509 -req -days 1 -in "$scratch_dir/leaf.csr" \ + -CA "$ca_cert" -CAkey "$scratch_dir/ca.key" \ + -CAserial "$scratch_dir/ca.srl" -CAcreateserial \ + -extfile <(printf 'subjectAltName=%s\nextendedKeyUsage=serverAuth\n' "$san") -out "$cert" + } + issue_cert nifi DNS:nifi "$scratch_dir/nifi.key" "$scratch_dir/nifi.pem" + issue_cert 127.0.0.1 IP:127.0.0.1 "$CERT_DIR/nginx/tls.key" "$CERT_DIR/nginx/tls.crt" + + openssl pkcs12 -export -name nifi -inkey "$scratch_dir/nifi.key" \ + -in "$scratch_dir/nifi.pem" -certfile "$ca_cert" \ + -out "$scratch_dir/nifi.p12" -passout "pass:$password" + keytool -importkeystore -noprompt \ + -srckeystore "$scratch_dir/nifi.p12" -srcstoretype PKCS12 -srcstorepass "$password" \ + -destkeystore "$CERT_DIR/nifi/nifi-keystore.jks" -deststoretype JKS -deststorepass "$password" + keytool -importcert -noprompt -alias root-ca -file "$ca_cert" \ + -keystore "$CERT_DIR/nifi/nifi-truststore.jks" -storetype JKS -storepass "$password" + + touch ../env/general.env + cat > ../env/nifi.env <&2; exit 1 ;; + esac + done + + for service in nifi nifi-nginx; do + docker compose exec -T "$service" sh -ec 'test "$(id -u)" -ne 0' + done + docker compose exec -T nifi /opt/nifi/scripts/cogstack-healthcheck.sh live + docker compose exec -T nifi /opt/nifi/scripts/cogstack-healthcheck.sh ready + for probe in live ready; do + docker compose exec -T nifi-nginx curl -fsS --output /dev/null "http://127.0.0.1:8080/healthz/$probe" + done + + response="$("${request[@]}" --data-urlencode "username=$SINGLE_USER_CREDENTIALS_USERNAME" \ + --data-urlencode "password=$SINGLE_USER_CREDENTIALS_PASSWORD" \ + --write-out $'\n%{http_code}' "$url/nifi-api/access/token")" + code="${response##*$'\n'}" + token="${response%$'\n'*}" + if [[ "$code" != 201 || -z "$token" ]]; then + echo "NiFi token request returned HTTP $code or an empty token" >&2 + exit 1 + fi + + code="$("${request[@]}" --header "Authorization: Bearer $token" --output /dev/null \ + --write-out '%{http_code}' "$url/nifi-api/flow/about")" + if [[ "$code" != 200 ]]; then + echo "Authenticated NiFi API returned HTTP $code" >&2 + exit 1 + fi + echo 'OK: authenticated NiFi API returned HTTP 200' + + - name: Dump container logs + if: failure() + run: | + [[ -f ../env/nifi.env ]] || exit 0 + source ./export_env_vars.sh + docker compose ps + docker compose logs --no-color nifi nifi-nginx + + - name: Shutdown stack + if: always() + run: | + [[ -f ../env/nifi.env ]] || exit 0 + source ./export_env_vars.sh + docker compose down -v + docker compose -p nifi-smoke-published -f docker-compose.yml down From 4389094ed0b02fabfe69afea2b9140a73f691b5d Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 17:09:32 +0000 Subject: [PATCH 13/16] Added crt generation. --- apps/nifi/README.md | 11 +- apps/nifi/docker/docker-compose.base.yml | 14 +- .../scripts/security/create_root_ca_cert.sh | 144 ++++++++++++++++++ .../templates/ssl-extensions-x509.cnf | 80 ++++++++++ 4 files changed, 242 insertions(+), 7 deletions(-) create mode 100755 deployment/scripts/security/create_root_ca_cert.sh create mode 100755 deployment/security/templates/ssl-extensions-x509.cnf diff --git a/apps/nifi/README.md b/apps/nifi/README.md index e050fb34..c8c3172c 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -54,11 +54,12 @@ Place the following under `deployment/security/certificates/`: | `nginx/tls.crt`, `nginx/tls.key` | NGINX server identity for the hostname users open in their browser. The browser must trust its issuer. | | `root/root-ca.pem` | Public CA used by NGINX and the NiFi health check to verify NiFi's server certificate. | -Compose mounts the directories read-only. Keep `root/` for public CA material -and make the mounted files readable by their container users. The start targets -run `make check-tls`, which checks for readable, nonempty regular files. If -`root-ca.pem` is a directory from an earlier bind mount, replace it with the -actual PEM file. Certificate validation occurs when the services connect over TLS. +Compose mounts the service certificate directories and `root/root-ca.pem` read-only. +The CA signing key and private bundles stay on the host. Make the mounted files +readable by their container users. The start targets run `make check-tls`, which +checks for readable, nonempty regular files. If `root-ca.pem` is a directory from an +earlier bind mount, replace it with the actual PEM file. Certificate validation +occurs when the services connect over TLS. ### Start and verify diff --git a/apps/nifi/docker/docker-compose.base.yml b/apps/nifi/docker/docker-compose.base.yml index 0e535adf..55763034 100644 --- a/apps/nifi/docker/docker-compose.base.yml +++ b/apps/nifi/docker/docker-compose.base.yml @@ -46,7 +46,12 @@ x-mounts: nifi: &nifi-volumes # Security certificates - ../../../deployment/security/certificates/nifi:/security/certificates/nifi:ro - - ../../../deployment/security/certificates/root:/security/certificates/root:ro + - type: bind + source: ../../../deployment/security/certificates/root/root-ca.pem + target: /security/certificates/root/root-ca.pem + read_only: true + bind: + create_host_path: false # Apache startup configures image defaults in this persistent, writable directory. - nifi-vol-conf:/opt/nifi/nifi-current/conf @@ -63,7 +68,12 @@ x-mounts: nifi-nginx: &nifi-nginx-volumes - ../../../deployment/security/certificates/nginx:/certificates/nginx:ro - - ../../../deployment/security/certificates/root:/certificates/root:ro + - type: bind + source: ../../../deployment/security/certificates/root/root-ca.pem + target: /certificates/root/root-ca.pem + read_only: true + bind: + create_host_path: false x-networks: cognet: &cognet diff --git a/deployment/scripts/security/create_root_ca_cert.sh b/deployment/scripts/security/create_root_ca_cert.sh new file mode 100755 index 00000000..0858dae7 --- /dev/null +++ b/deployment/scripts/security/create_root_ca_cert.sh @@ -0,0 +1,144 @@ +#!/usr/bin/env bash + +# ============================================================================================================================= +# 🔐 Create Root CA certificate, private key, and keystore/truststore bundle +# +# Usage: +# ./create_root_ca_cert.sh +# Set SECURITY_DIR to place the whole bundle under a different directory. +# +# Requires: +# - Bash, OpenSSL and Java keytool +# - ROOT_CERTIFICATE_KEYSTORE_PASSWORD in the environment +# - ../../security/templates/ssl-extensions-x509.cnf relative to this script +# +# Output: +# Default paths relative to the repository root. +# deployment/security/certificates/root/root-ca.key - RSA CA signing key +# deployment/security/certificates/root/root-ca.p12 - Encrypted PKCS#12 bundle with the CA key and certificate +# deployment/security/certificates/root/root-ca-keystore.jks - Java keystore with the CA key and certificate +# deployment/security/certificates/root/root-ca.pem - Self-signed X.509 CA certificate in PEM format +# deployment/security/certificates/root/root-ca.crt - The same CA certificate in binary DER format +# deployment/security/certificates/root/root-ca.csr - Certificate signing request for the CA key and subject +# deployment/security/certificates/root/root-ca-truststore.jks - Java truststore containing the public CA certificate +# ============================================================================================================================= + +set -euo pipefail +umask 077 + +# === Resolve the profile and output paths +# SECURITY_DIR controls the bundle location. Resolve the checked-in OpenSSL profile +# relative to this script. +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +SECURITY_DIR="${SECURITY_DIR:-$SCRIPT_DIR/../../security}" +EXT_FILE="$SCRIPT_DIR/../../security/templates/ssl-extensions-x509.cnf" +CA_NAME=root-ca +ROOT_DIR="$SECURITY_DIR/certificates/root" + +KEY_FILE="$ROOT_DIR/$CA_NAME.key" +P12_FILE="$ROOT_DIR/$CA_NAME.p12" +JKS_FILE="$ROOT_DIR/$CA_NAME-keystore.jks" +PEM_FILE="$ROOT_DIR/$CA_NAME.pem" +CRT_FILE="$ROOT_DIR/$CA_NAME.crt" +CSR_FILE="$ROOT_DIR/$CA_NAME.csr" +TRUSTSTORE_FILE="$ROOT_DIR/$CA_NAME-truststore.jks" + +# OpenSSL and keytool read the store password from the environment. +: "${ROOT_CERTIFICATE_KEYSTORE_PASSWORD:?Set ROOT_CERTIFICATE_KEYSTORE_PASSWORD}" +export ROOT_CERTIFICATE_KEYSTORE_PASSWORD + +# === Protect existing CA material +# Replacing a CA invalidates trust for certificates issued under the old key. +for output in "$KEY_FILE" "$PEM_FILE" "$CRT_FILE" "$CSR_FILE" "$P12_FILE" "$JKS_FILE" "$TRUSTSTORE_FILE"; do + if [[ -e "$output" || -L "$output" ]]; then + printf 'Output already exists: %s\n' "$output" >&2 + exit 1 + fi +done + +# Build the entire bundle in a private temporary directory. If publication fails, +# remove the files written by this run and clean up the temporary directory. +scratch_dir=$(mktemp -d) +published=() +cleanup() { + if (( $? != 0 )) && [[ -n ${published[0]:-} ]]; then + rm -f -- "${published[@]}" + fi + rm -rf -- "$scratch_dir" +} +trap cleanup EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +publish() { + { + published+=("$2") + cat "$1" + } > "$2" +} + +# === Generate the RSA signing key and self-signed CA certificate +# The v3_ca profile authorizes the 4096-bit key to sign certificates and revocation +# lists. Issue the PEM certificate for 1,460 days, then derive the binary DER copy. +openssl req -x509 \ + -newkey rsa:4096 -nodes \ + -keyout "$scratch_dir/ca.key" \ + -sha256 \ + -days 1460 \ + -out "$scratch_dir/ca.pem" \ + -extensions v3_ca \ + -config "$EXT_FILE" +openssl x509 -in "$scratch_dir/ca.pem" -out "$scratch_dir/ca.crt" -outform DER + +# === Write the signing request +# The CSR records the CA subject and public key and is signed with the CA key. +openssl req -new -key "$scratch_dir/ca.key" -out "$scratch_dir/ca.csr" -config "$EXT_FILE" + +# === Create the encrypted PKCS#12 bundle +# Use explicit AES encryption so OpenSSL and LibreSSL produce compatible bundles. +openssl pkcs12 -export \ + -in "$scratch_dir/ca.pem" \ + -inkey "$scratch_dir/ca.key" \ + -out "$scratch_dir/ca.p12" \ + -name "$CA_NAME" \ + -keypbe AES-256-CBC -certpbe AES-256-CBC \ + -passout env:ROOT_CERTIFICATE_KEYSTORE_PASSWORD + +# === Create the Java keystore +# Import the private key entry and its certificate under the CA name. +keytool -importkeystore \ + -destkeystore "$scratch_dir/keystore.jks" \ + -deststoretype JKS \ + -srckeystore "$scratch_dir/ca.p12" \ + -srcstoretype PKCS12 \ + -alias "$CA_NAME" \ + -srcstorepass:env ROOT_CERTIFICATE_KEYSTORE_PASSWORD \ + -deststorepass:env ROOT_CERTIFICATE_KEYSTORE_PASSWORD \ + -noprompt + +# === Create the Java truststore +# Import the public CA certificate as the trust anchor for Java consumers. +keytool -importcert \ + -file "$scratch_dir/ca.pem" \ + -alias "$CA_NAME" \ + -keystore "$scratch_dir/truststore.jks" \ + -storetype JKS \ + -storepass:env ROOT_CERTIFICATE_KEYSTORE_PASSWORD \ + -noprompt + +# === Publish the bundle +# Private files use mode 0600 and public files use mode 0644. Noclobber protects +# files that appear after the initial check, including those from a concurrent run. +(umask 022; mkdir -p -- "$ROOT_DIR") +set -o noclobber +publish "$scratch_dir/ca.key" "$KEY_FILE" +publish "$scratch_dir/ca.p12" "$P12_FILE" +publish "$scratch_dir/keystore.jks" "$JKS_FILE" +umask 022 +publish "$scratch_dir/ca.pem" "$PEM_FILE" +publish "$scratch_dir/ca.crt" "$CRT_FILE" +publish "$scratch_dir/ca.csr" "$CSR_FILE" +publish "$scratch_dir/truststore.jks" "$TRUSTSTORE_FILE" + +printf 'Created root CA certificate %s and signing key %s\n' "$PEM_FILE" "$KEY_FILE" + diff --git a/deployment/security/templates/ssl-extensions-x509.cnf b/deployment/security/templates/ssl-extensions-x509.cnf new file mode 100755 index 00000000..e5e74171 --- /dev/null +++ b/deployment/security/templates/ssl-extensions-x509.cnf @@ -0,0 +1,80 @@ +# ========================================================================================= +# 📜 OpenSSL X.509 v3 Extensions Configuration +# For: Root CA and Node/Client Certificates +# ========================================================================================= + +[v3_ca] +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid:always,issuer +basicConstraints = critical, CA:TRUE +keyUsage = critical, keyCertSign, cRLSign +subjectAltName=DNS:nifi,DNS:elasticsearch-1,DNS:elasticsearch-2,DNS:elasticsearch-3,DNS:cogstack,DNS:*.cogstack + +[v3_leaf] +basicConstraints = critical, CA:FALSE +keyUsage = critical, digitalSignature, keyEncipherment +extendedKeyUsage = serverAuth, clientAuth +subjectAltName = @alt_names +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer + +[alt_names] +DNS.1 = nifi +DNS.2 = nifi-registry-flow +DNS.3 = nifi-registry + +DNS.4 = nifi-nginx +DNS.5 = elasticsearch-1 +DNS.6 = elasticsearch-2 +DNS.7 = elasticsearch-3 +DNS.8 = ocr-service +DNS.9 = ocr-service-text-only +DNS.10 = medcat-trainer-nginx +DNS.11 = medcat-trainer-ui +DNS.12 = nlp-medcat-service-production +DNS.13 = nlp-medcat-service-production-deid +DNS.14 = cogstack-kibana +DNS.15 = cogstack-cohort +DNS.16 = cogstack-elasticsearch-1 +DNS.17 = cogstack-elasticsearch-2 +DNS.18 = cogstack-elasticsearch-3 +DNS.19 = cogstack-nifi +DNS.20 = cogstack-nifi-nginx +DNS.21 = cogstack-nifi-registry-flow +DNS.22 = cogstack-auth-service +DNS.23 = cogstack +DNS.24 = *.cogstack +DNS.25 = localhost +IP.1 = 127.0.0.1 +email.1 = admin@cogstack.net + +[v3_gitea] +basicConstraints = critical, CA:FALSE +keyUsage = critical, digitalSignature, keyEncipherment +extendedKeyUsage = serverAuth +subjectAltName = @gitea_alt_names +subjectKeyIdentifier = hash +authorityKeyIdentifier = keyid,issuer + +[gitea_alt_names] +DNS.1 = gitea +DNS.2 = cogstack-gitea +DNS.3 = localhost +IP.1 = 127.0.0.1 + +[req] +default_bits = 4096 +string_mask = utf8only +prompt = no +distinguished_name = req_distinguished_name +x509_extensions = v3_leaf +default_md = sha256 + +[req_distinguished_name] +CN = cogstack +C = UK +ST = London +L = UK +O = cogstack +OU = cogstack +CN = cogstack From 67fea7b7cc35d70659f7bf82f0f75ade52cc3d48 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 18:45:15 +0000 Subject: [PATCH 14/16] cert gen updates. --- deployment/.gitignore | 3 +- deployment/env/certificates.env | 24 +++ deployment/scripts/README.md | 66 +++++- .../scripts/security/create_nifi_certs.sh | 140 +++++++++++++ .../create_opensearch_client_admin_certs.sh | 127 ++++++++++++ .../security/create_opensearch_node_cert.sh | 188 ++++++++++++++++++ .../scripts/security/create_root_ca_cert.sh | 16 +- .../templates/ssl-extensions-x509.cnf | 47 +---- 8 files changed, 562 insertions(+), 49 deletions(-) create mode 100644 deployment/env/certificates.env create mode 100755 deployment/scripts/security/create_nifi_certs.sh create mode 100755 deployment/scripts/security/create_opensearch_client_admin_certs.sh create mode 100755 deployment/scripts/security/create_opensearch_node_cert.sh diff --git a/deployment/.gitignore b/deployment/.gitignore index 7893fda1..45a9af48 100644 --- a/deployment/.gitignore +++ b/deployment/.gitignore @@ -1,6 +1,7 @@ -# Deployment links to app env files included in the repository. +# Deployment env files and app env links included in the repository. !/env/ /env/* +!/env/certificates.env !/env/cohorter.env !/env/jupyter.env !/env/ocr_service.env diff --git a/deployment/env/certificates.env b/deployment/env/certificates.env new file mode 100644 index 00000000..4c2eadf5 --- /dev/null +++ b/deployment/env/certificates.env @@ -0,0 +1,24 @@ +# Non-secret settings for the certificate generators. Leave blank to use the +# script defaults. Supply store passwords separately and use --days DAYS to +# set validity when running a generator. +# +# Load from the repository root before running a generator. +# set -a +# source deployment/env/certificates.env +# set +a + +# Blank uses deployment/security/ for certificate inputs and outputs. +SECURITY_DIR= + +# Optional names to add to the NiFi certificate. Match the names NGINX and the +# health check verify in the deployment. +NIFI_UPSTREAM_TLS_NAME= +NIFI_HEALTHCHECK_HOST= + +# Set the namespace to include the NiFi web Service's full Kubernetes DNS name. +KUBE_NAMESPACE= +CLUSTER_DOMAIN=cluster.local + +# Optional comma-separated DNS aliases for each OpenSearch node and for Dashboards. +OPENSEARCH_NODE_DNS_NAMES= +OPENSEARCH_DASHBOARDS_DNS_NAMES= diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index 2d356ac5..68d4fae8 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -1,8 +1,68 @@ # Deployment scripts -Run commands from the repository root. Requires Make, Bash, `sudo`, systemd and network -access. Installation and cluster setup invoke `sudo` internally; run setup as the user who will -use `kubectl`. +Run commands from the repository root. Installation and cluster setup require Make, +Bash, `sudo`, systemd and network access. They invoke `sudo` internally. Run setup +as the user who will use `kubectl`. + +## Certificates + +These scripts use OpenSSL and Java's `keytool`. If you need a root CA, export +`ROOT_CERTIFICATE_KEYSTORE_PASSWORD` and run this from the repository root. +All four generators accept `--days DAYS`. The default validity is 1,460 days +for the root CA and OpenSearch certificates and 397 days for NiFi. + +```bash +./deployment/scripts/security/create_root_ca_cert.sh +``` + +Export the `KEYSTORE_PASSWORD` and `TRUSTSTORE_PASSWORD` that NiFi will use. +The legacy `NIFI_KEYSTORE_PASSWORD` and `NIFI_TRUSTSTORE_PASSWORD` names are +also accepted. Both scripts accept `SECURITY_DIR`, which defaults to +`deployment/security/`. + +Choose the command for your deployment. The default NiFi certificate covers +`nifi`, `localhost`, `cogstack-nifi`, `cogstack-nifi-web`, and `127.0.0.1`. + +```bash +./deployment/scripts/security/create_nifi_certs.sh +``` + +When NGINX and NiFi run on separate Docker hosts, add the DNS name NGINX will +verify. `NIFI_HEALTHCHECK_HOST` also adds a name when supplied. + +```bash +NIFI_UPSTREAM_TLS_NAME=nifi.internal.example ./deployment/scripts/security/create_nifi_certs.sh +``` + +For Kubernetes, set `KUBE_NAMESPACE` to include the web Service's full name. +For example, `cogstack` adds `cogstack-nifi-web.cogstack.svc.cluster.local`. +Set `CLUSTER_DOMAIN` if your cluster uses a domain other than `cluster.local`. + +```bash +KUBE_NAMESPACE=cogstack ./deployment/scripts/security/create_nifi_certs.sh +``` + +Each invocation writes `nifi.key`, `nifi.csr`, `nifi.pem`, `nifi.crt` (DER), +`nifi.p12`, `nifi-keystore.jks`, and `nifi-truststore.jks` under +`$SECURITY_DIR/certificates/nifi/`. + +### OpenSearch + +Export `ES_CERTIFICATE_PASSWORD` for the Java and PKCS#12 stores. Pass the node +hostnames when generating the node certificates. Generate the Dashboards and +admin certificates with the second command. + +```bash +./deployment/scripts/security/create_opensearch_node_cert.sh --days 365 opensearch-1 opensearch-2 +./deployment/scripts/security/create_opensearch_client_admin_certs.sh --days 365 +``` + +Add comma-separated DNS aliases using `OPENSEARCH_NODE_DNS_NAMES` or +`OPENSEARCH_DASHBOARDS_DNS_NAMES` when clients verify other names, such as +a Kubernetes Service FQDN. Outputs are under +`$SECURITY_DIR/certificates/opensearch/`, with each node's hostname as its file +prefix. Use the issued node and admin subjects in the corresponding OpenSearch +DN settings. ## Install, initialize and verify diff --git a/deployment/scripts/security/create_nifi_certs.sh b/deployment/scripts/security/create_nifi_certs.sh new file mode 100755 index 00000000..3019c430 --- /dev/null +++ b/deployment/scripts/security/create_nifi_certs.sh @@ -0,0 +1,140 @@ +#!/usr/bin/env bash + +# ============================================================================================================================= +# 🔐 Create the NiFi certificate, private key, and keystore/truststore bundle +# +# Usage: +# ./create_nifi_certs.sh [--days DAYS] +# DAYS is a positive integer. The default validity is 397 days. +# +# Requires: +# - Bash, OpenSSL and Java keytool +# - KEYSTORE_PASSWORD and TRUSTSTORE_PASSWORD in the environment +# - root-ca.pem and root-ca.key under certificates/root/ in SECURITY_DIR +# +# Optional environment variables: +# - SECURITY_DIR defaults to deployment/security/ +# - NIFI_UPSTREAM_TLS_NAME and NIFI_HEALTHCHECK_HOST add the names used by those clients +# - KUBE_NAMESPACE adds the NiFi web Service DNS name in CLUSTER_DOMAIN (defaults to cluster.local) +# +# Output: +# deployment/security/certificates/nifi/nifi.key - RSA private key +# deployment/security/certificates/nifi/nifi.csr - Certificate signing request +# deployment/security/certificates/nifi/nifi.pem - Signed certificate in PEM format +# deployment/security/certificates/nifi/nifi.crt - The same certificate in binary DER format +# deployment/security/certificates/nifi/nifi.p12 - Encrypted PKCS#12 bundle with the key and chain +# deployment/security/certificates/nifi/nifi-keystore.jks - Java keystore with the key and chain +# deployment/security/certificates/nifi/nifi-truststore.jks - Java truststore containing the public CA certificate +# ============================================================================================================================= + +set -euo pipefail +umask 077 + +days=397 +if (( $# > 0 )); then + if [[ $# -ne 2 || "$1" != --days || ! "$2" =~ ^[1-9][0-9]*$ ]]; then + printf 'Usage: %s [--days DAYS] (DAYS must be a positive integer)\n' "$0" >&2 + exit 2 + fi + days=$2 +fi + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +security_dir=${SECURITY_DIR:-"$script_dir/../../security"} +profile="$script_dir/../../security/templates/ssl-extensions-x509.cnf" +ca_cert="$security_dir/certificates/root/root-ca.pem" +ca_key="$security_dir/certificates/root/root-ca.key" +output_dir="$security_dir/certificates/nifi" + +export KEYSTORE_PASSWORD="${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}}" +export TRUSTSTORE_PASSWORD="${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD:-}}" +: "${KEYSTORE_PASSWORD:?Set KEYSTORE_PASSWORD}" "${TRUSTSTORE_PASSWORD:?Set TRUSTSTORE_PASSWORD}" + +for input in "$ca_cert" "$ca_key"; do + if [[ ! -f "$input" || ! -r "$input" || ! -s "$input" ]]; then + printf 'Missing or unreadable CA file %s. Run create_root_ca_cert.sh first.\n' "$input" >&2 + exit 1 + fi +done + +files=(nifi.key nifi.csr nifi.pem nifi.crt nifi.p12 nifi-keystore.jks nifi-truststore.jks) +for file in "${files[@]}"; do + if [[ -e "$output_dir/$file" || -L "$output_dir/$file" ]]; then + printf 'Output already exists: %s\n' "$output_dir/$file" >&2 + exit 1 + fi +done + +# Build the whole bundle before publishing it. Clean up files written by this +# run if any of the final writes fail. +scratch_dir=$(mktemp -d) +published=() +cleanup() { + if (( $? != 0 )) && [[ -n ${published[0]:-} ]]; then + rm -f -- "${published[@]}" + fi + rm -rf -- "$scratch_dir" +} +trap cleanup EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +# === Add deployment-specific SANs to the template defaults +names=("${NIFI_UPSTREAM_TLS_NAME:-}" "${NIFI_HEALTHCHECK_HOST:-}") +if [[ -n "${KUBE_NAMESPACE:-}" ]]; then + names+=("cogstack-nifi-web.${KUBE_NAMESPACE}.svc.${CLUSTER_DOMAIN:-cluster.local}") +fi + +{ + cat -- "$profile" + printf '\n[alt_names]\n' + index=100 + for name in "${names[@]}"; do + [[ -n "$name" ]] || continue + if [[ "$name" =~ ^[0-9]+(\.[0-9]+){3}$ || ( "$name" == *:* && "$name" =~ ^[[:xdigit:]:.]+$ ) ]]; then + type=IP + elif [[ "$name" =~ ^[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?$ ]]; then + type=DNS + else + printf 'Invalid TLS hostname or IP: %s\n' "$name" >&2 + exit 2 + fi + printf '%s.%d = %s\n' "$type" "$index" "$name" + index=$((index + 1)) + done +} > "$scratch_dir/leaf.cnf" + +# === Generate the key and issue the leaf certificate +openssl req -new -newkey rsa:4096 -nodes -config "$profile" \ + -keyout "$scratch_dir/nifi.key" -out "$scratch_dir/nifi.csr" +serial=$(openssl rand -hex 16) +openssl x509 -req -sha256 -days "$days" -set_serial "0x$serial" \ + -in "$scratch_dir/nifi.csr" -CA "$ca_cert" -CAkey "$ca_key" \ + -extfile "$scratch_dir/leaf.cnf" -extensions v3_leaf -out "$scratch_dir/nifi.pem" +openssl verify -CAfile "$ca_cert" "$scratch_dir/nifi.pem" >/dev/null +openssl x509 -in "$scratch_dir/nifi.pem" -outform DER -out "$scratch_dir/nifi.crt" + +# === Build the Java stores +# Include the public CA in the private key's chain and trust it in the truststore. +openssl pkcs12 -export -name nifi -inkey "$scratch_dir/nifi.key" \ + -in "$scratch_dir/nifi.pem" -certfile "$ca_cert" -out "$scratch_dir/nifi.p12" \ + -keypbe AES-256-CBC -certpbe AES-256-CBC -passout env:KEYSTORE_PASSWORD +keytool -importkeystore -noprompt -alias nifi \ + -srckeystore "$scratch_dir/nifi.p12" -srcstoretype PKCS12 -srcstorepass:env KEYSTORE_PASSWORD \ + -destkeystore "$scratch_dir/nifi-keystore.jks" -deststoretype JKS \ + -deststorepass:env KEYSTORE_PASSWORD -destkeypass:env KEYSTORE_PASSWORD +keytool -importcert -noprompt -alias root-ca -file "$ca_cert" \ + -keystore "$scratch_dir/nifi-truststore.jks" -storetype JKS -storepass:env TRUSTSTORE_PASSWORD + +# === Publish the bundle +# Noclobber keeps concurrent attempts from overwriting each other's files. +(umask 022; mkdir -p -- "$output_dir") +set -o noclobber +for file in "${files[@]}"; do + { + published+=("$output_dir/$file") + cat -- "$scratch_dir/$file" + } > "$output_dir/$file" +done +chmod 644 "$output_dir"/nifi.{csr,pem,crt} "$output_dir/nifi-truststore.jks" +printf 'Created NiFi certificates and Java stores under %s\n' "$output_dir" diff --git a/deployment/scripts/security/create_opensearch_client_admin_certs.sh b/deployment/scripts/security/create_opensearch_client_admin_certs.sh new file mode 100755 index 00000000..8870836a --- /dev/null +++ b/deployment/scripts/security/create_opensearch_client_admin_certs.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash + +# ============================================================================================================================= +# 🔐 Create the OpenSearch Dashboards and admin certificates and keys +# +# Usage: +# ./create_opensearch_client_admin_certs.sh [--days DAYS] +# DAYS is a positive integer. The default validity is 1,460 days. +# +# Requires: +# - Bash and OpenSSL +# - ES_CERTIFICATE_PASSWORD for the encrypted Dashboards PKCS#12 bundle +# - root-ca.pem and root-ca.key under certificates/root/ in SECURITY_DIR +# +# Optional environment variables: +# - SECURITY_DIR defaults to deployment/security/ +# - OPENSEARCH_DASHBOARDS_DNS_NAMES adds comma-separated DNS names to +# opensearch-dashboards and kibana +# +# Output: +# deployment/security/certificates/opensearch/es_kibana_client.key - Dashboards RSA private key in PKCS#8 format +# deployment/security/certificates/opensearch/es_kibana_client.csr - Dashboards certificate signing request +# deployment/security/certificates/opensearch/es_kibana_client.pem - Signed Dashboards certificate in PEM format +# deployment/security/certificates/opensearch/es_kibana_client.p12 - Encrypted PKCS#12 bundle with the key and chain +# deployment/security/certificates/opensearch/admin.key.pem - Admin RSA private key in PKCS#8 format +# deployment/security/certificates/opensearch/admin.csr - Admin certificate signing request +# deployment/security/certificates/opensearch/admin.crt - Signed admin client certificate in PEM format +# ============================================================================================================================= + +set -euo pipefail +umask 077 + +days=1460 +if (( $# > 0 )); then + if [[ $# -ne 2 || "$1" != --days || ! "$2" =~ ^[1-9][0-9]*$ ]]; then + printf 'Usage: %s [--days DAYS] (DAYS must be a positive integer)\n' "$0" >&2 + exit 2 + fi + days=$2 +fi + +: "${ES_CERTIFICATE_PASSWORD:?Set ES_CERTIFICATE_PASSWORD}" +export ES_CERTIFICATE_PASSWORD + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +security_dir=${SECURITY_DIR:-"$script_dir/../../security"} +ca_cert="$security_dir/certificates/root/root-ca.pem" +ca_key="$security_dir/certificates/root/root-ca.key" +output_dir="$security_dir/certificates/opensearch" + +for input in "$ca_cert" "$ca_key"; do + if [[ ! -f "$input" || ! -r "$input" || ! -s "$input" ]]; then + printf 'Missing or unreadable CA file %s. Run create_root_ca_cert.sh first.\n' "$input" >&2 + exit 1 + fi +done + +sans=DNS:opensearch-dashboards,DNS:kibana +if [[ -n "${OPENSEARCH_DASHBOARDS_DNS_NAMES:-}" ]]; then + dns_label='[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?' + dns_name="$dns_label(\.$dns_label)*" + if [[ ! "$OPENSEARCH_DASHBOARDS_DNS_NAMES" =~ ^$dns_name(,$dns_name)*$ ]]; then + printf 'OPENSEARCH_DASHBOARDS_DNS_NAMES must contain comma-separated DNS names.\n' >&2 + exit 2 + fi + sans+=",DNS:${OPENSEARCH_DASHBOARDS_DNS_NAMES//,/,DNS:}" +fi + +files=(es_kibana_client.pem es_kibana_client.key es_kibana_client.csr es_kibana_client.p12 admin.crt admin.key.pem admin.csr) +for file in "${files[@]}"; do + if [[ -e "$output_dir/$file" || -L "$output_dir/$file" ]]; then + printf 'Output already exists: %s\n' "$output_dir/$file" >&2 + exit 1 + fi +done + +# Finish both certificates and the bundle before publishing any outputs. +scratch_dir=$(mktemp -d) +published=() +cleanup() { + if (( $? != 0 )) && [[ -n ${published[0]:-} ]]; then + rm -f -- "${published[@]}" + fi + rm -rf -- "$scratch_dir" +} +trap cleanup EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +subject='/C=UK/ST=London/L=UK/O=cogstack/OU=cogstack' +for role in client admin; do + if [[ "$role" == client ]]; then + key=es_kibana_client.key + csr=es_kibana_client.csr + cert=es_kibana_client.pem + extensions=('keyUsage=critical,digitalSignature,keyEncipherment' 'extendedKeyUsage=serverAuth,clientAuth' "subjectAltName=$sans") + else + key=admin.key.pem + csr=admin.csr + cert=admin.crt + extensions=('keyUsage=critical,digitalSignature' 'extendedKeyUsage=clientAuth') + fi + + openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out "$scratch_dir/$key" + openssl req -new -sha256 -key "$scratch_dir/$key" -subj "$subject/CN=$role" -out "$scratch_dir/$csr" + serial=$(openssl rand -hex 16) + openssl x509 -req -sha256 -days "$days" -set_serial "0x$serial" \ + -in "$scratch_dir/$csr" -CA "$ca_cert" -CAkey "$ca_key" -out "$scratch_dir/$cert" \ + -extfile <(printf '%s\n' 'basicConstraints=critical,CA:FALSE' \ + 'subjectKeyIdentifier=hash' 'authorityKeyIdentifier=keyid,issuer' "${extensions[@]}") + openssl verify -CAfile "$ca_cert" "$scratch_dir/$cert" >/dev/null +done + +openssl pkcs12 -export -name es_kibana_client -inkey "$scratch_dir/es_kibana_client.key" \ + -in "$scratch_dir/es_kibana_client.pem" -certfile "$ca_cert" -out "$scratch_dir/es_kibana_client.p12" \ + -keypbe AES-256-CBC -certpbe AES-256-CBC -passout env:ES_CERTIFICATE_PASSWORD + +(umask 022; mkdir -p -- "$output_dir") +set -o noclobber +for file in "${files[@]}"; do + { + published+=("$output_dir/$file") + cat -- "$scratch_dir/$file" + } > "$output_dir/$file" +done +chmod 644 "$output_dir"/es_kibana_client.{pem,csr} "$output_dir"/admin.{crt,csr} +printf 'Created OpenSearch Dashboards and admin certificates under %s\n' "$output_dir" diff --git a/deployment/scripts/security/create_opensearch_node_cert.sh b/deployment/scripts/security/create_opensearch_node_cert.sh new file mode 100755 index 00000000..d416bbeb --- /dev/null +++ b/deployment/scripts/security/create_opensearch_node_cert.sh @@ -0,0 +1,188 @@ +#!/usr/bin/env bash + +# ============================================================================================================================= +# Create OpenSearch node certificates, keys, and Java stores using the shared root CA. +# +# Usage: +# ./create_opensearch_node_cert.sh [--days DAYS] [hostname ...] +# +# Requires: +# - Bash, OpenSSL and Java keytool +# - ES_CERTIFICATE_PASSWORD for the PKCS#12 bundle and Java stores +# - root-ca.pem and root-ca.key under certificates/root/ in SECURITY_DIR +# +# Optional settings: +# - --days defaults to 1460. +# - SECURITY_DIR defaults to deployment/security/. +# - OPENSEARCH_NODE_DNS_NAMES adds comma-separated DNS names to every node certificate. +# - Each certificate covers the node hostname and the Compose service name opensearch. +# +# Outputs under certificates/opensearch/: +# elastic-stack-ca.crt.pem - Public root CA certificate +# .key - PKCS#8 RSA private key +# .csr - Certificate signing request +# .crt - Signed PEM certificate +# .p12 - Encrypted PKCS#12 bundle with the key and chain +# -keystore.jks - Java keystore with the key and chain +# -truststore.key - JKS truststore containing the node certificate +# ============================================================================================================================= + +set -euo pipefail +umask 077 + +days=1460 +if [[ ${1:-} == --days ]]; then + if [[ ! ${2:-} =~ ^[1-9][0-9]*$ ]]; then + printf '%s\n' '--days must be a positive integer.' >&2 + exit 2 + fi + days=$2 + shift 2 +fi +if (( $# == 0 )); then + printf 'Usage: %s [--days DAYS] [hostname ...]\n' "$0" >&2 + exit 2 +fi + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +security_dir=${SECURITY_DIR:-"$script_dir/../../security"} +ca_cert="$security_dir/certificates/root/root-ca.pem" +ca_key="$security_dir/certificates/root/root-ca.key" +output_dir="$security_dir/certificates/opensearch" +ca_alias="$output_dir/elastic-stack-ca.crt.pem" + +hostname_pattern='^([A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)*[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?$' +validate_hostname() { + if (( ${#1} > 253 )) || [[ ! "$1" =~ $hostname_pattern || "$1" =~ ^[0-9]+(\.[0-9]+){3}$ ]]; then + printf 'Invalid OpenSearch DNS hostname: %s\n' "$1" >&2 + exit 2 + fi +} + +san_names=(opensearch) +if [[ -n ${OPENSEARCH_NODE_DNS_NAMES:-} ]]; then + if [[ ! "$OPENSEARCH_NODE_DNS_NAMES" =~ ^[A-Za-z0-9.-]+(,[A-Za-z0-9.-]+)*$ ]]; then + printf '%s\n' 'OPENSEARCH_NODE_DNS_NAMES must contain comma-separated DNS hostnames.' >&2 + exit 2 + fi + IFS=, read -r -a extra_names <<< "$OPENSEARCH_NODE_DNS_NAMES" + for name in "${extra_names[@]}"; do + validate_hostname "$name" + san_names+=("$name") + done +fi + +require_new_file() { + if [[ -e "$1" || -L "$1" ]]; then + printf 'Output already exists: %s\n' "$1" >&2 + exit 1 + fi +} + +suffixes=(.key .csr .crt .p12 -keystore.jks -truststore.key) +shopt -s nocasematch +for node in "$@"; do + validate_hostname "$node" + if (( ${#node} > 64 )) || [[ "$node" == root-ca || "$node" == admin || "$node" == client ]]; then + printf 'Use a node hostname up to 64 characters, distinct from root-ca, admin and client: %s\n' "$node" >&2 + exit 2 + fi + for suffix in "${suffixes[@]}"; do + require_new_file "$output_dir/$node$suffix" + done +done + +: "${ES_CERTIFICATE_PASSWORD:?Set ES_CERTIFICATE_PASSWORD}" +export ES_CERTIFICATE_PASSWORD +for input in "$ca_cert" "$ca_key"; do + if [[ ! -f "$input" || ! -r "$input" || ! -s "$input" ]]; then + printf 'Missing or unreadable CA file %s. Run create_root_ca_cert.sh first.\n' "$input" >&2 + exit 1 + fi +done + +write_ca_alias=true +if [[ -e "$ca_alias" || -L "$ca_alias" ]]; then + if [[ ! -f "$ca_alias" ]] || ! cmp -s -- "$ca_cert" "$ca_alias"; then + printf 'Existing OpenSearch CA differs from %s: %s\n' "$ca_cert" "$ca_alias" >&2 + exit 1 + fi + write_ca_alias=false +fi + +# Stage all node bundles before writing deployment files. Roll back writes on failure. +scratch_dir=$(mktemp -d) +published=() +cleanup() { + if (( $? != 0 )) && [[ -n ${published[0]:-} ]]; then + rm -f -- "${published[@]}" + fi + rm -rf -- "$scratch_dir" +} +trap cleanup EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +# DNS names are case-insensitive. Keep each SAN only once. +for node in "$@"; do + mkdir -- "$scratch_dir/$node" + stage="$scratch_dir/$node/$node" + sans="DNS:$node" + for name in "${san_names[@]}"; do + if [[ ",$sans," != *",DNS:$name,"* ]]; then + sans+=",DNS:$name" + fi + done + subject="/C=UK/ST=London/L=UK/O=cogstack/OU=cogstack/CN=$node" + + # Issue a leaf valid for both sides of OpenSearch node transport TLS. + openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out "$stage.key" + openssl req -new -sha256 -key "$stage.key" -subj "$subject" \ + -out "$stage.csr" -addext "subjectAltName=$sans" + serial=$(openssl rand -hex 16) + openssl x509 -req -sha256 -days "$days" -set_serial "0x$serial" \ + -in "$stage.csr" -CA "$ca_cert" -CAkey "$ca_key" -out "$stage.crt" \ + -extfile <(printf '%s\n' 'basicConstraints=critical,CA:FALSE' \ + 'keyUsage=critical,digitalSignature,keyEncipherment' 'extendedKeyUsage=serverAuth,clientAuth' \ + 'subjectKeyIdentifier=hash' 'authorityKeyIdentifier=keyid,issuer' "subjectAltName=$sans") + openssl verify -CAfile "$ca_cert" "$stage.crt" >/dev/null + + # Preserve OpenSearch's original aliases and the separate leaf-pinning truststore. + openssl pkcs12 -export -name "$node" -inkey "$stage.key" -in "$stage.crt" \ + -certfile "$ca_cert" -out "$stage.p12" -keypbe AES-256-CBC -certpbe AES-256-CBC \ + -passout env:ES_CERTIFICATE_PASSWORD + keytool -importkeystore -noprompt -alias "$node" \ + -srckeystore "$stage.p12" -srcstoretype PKCS12 -srcstorepass:env ES_CERTIFICATE_PASSWORD \ + -destkeystore "$stage-keystore.jks" -deststoretype JKS \ + -deststorepass:env ES_CERTIFICATE_PASSWORD -destkeypass:env ES_CERTIFICATE_PASSWORD + keytool -importcert -noprompt -alias root-ca -file "$ca_cert" \ + -keystore "$stage-keystore.jks" -storetype JKS -storepass:env ES_CERTIFICATE_PASSWORD + keytool -importcert -noprompt -alias "$node" -file "$stage.crt" \ + -keystore "$stage-truststore.key" -storetype JKS -storepass:env ES_CERTIFICATE_PASSWORD +done + +# Private files inherit mode 0600, and noclobber protects concurrent writes. +set -o noclobber +publish() { + local source=$1 target=$2 mode=$3 + require_new_file "$target" + { + published+=("$target") + cat -- "$source" + } > "$target" + chmod -- "$mode" "$target" +} +(umask 022; mkdir -p -- "$output_dir") +for node in "$@"; do + for suffix in "${suffixes[@]}"; do + case "$suffix" in + .key|.p12|-keystore.jks) mode=0600 ;; + *) mode=0644 ;; + esac + publish "$scratch_dir/$node/$node$suffix" "$output_dir/$node$suffix" "$mode" + done +done +if [[ "$write_ca_alias" == true ]]; then + publish "$ca_cert" "$ca_alias" 0644 +fi +printf 'Created OpenSearch node certificates and Java stores under %s\n' "$output_dir" diff --git a/deployment/scripts/security/create_root_ca_cert.sh b/deployment/scripts/security/create_root_ca_cert.sh index 0858dae7..7730d6a6 100755 --- a/deployment/scripts/security/create_root_ca_cert.sh +++ b/deployment/scripts/security/create_root_ca_cert.sh @@ -4,7 +4,8 @@ # 🔐 Create Root CA certificate, private key, and keystore/truststore bundle # # Usage: -# ./create_root_ca_cert.sh +# ./create_root_ca_cert.sh [--days DAYS] +# DAYS is a positive integer. The default validity is 1,460 days. # Set SECURITY_DIR to place the whole bundle under a different directory. # # Requires: @@ -26,6 +27,15 @@ set -euo pipefail umask 077 +days=1460 +if (( $# > 0 )); then + if [[ $# -ne 2 || "$1" != --days || ! "$2" =~ ^[1-9][0-9]*$ ]]; then + printf 'Usage: %s [--days DAYS] (DAYS must be a positive integer)\n' "$0" >&2 + exit 2 + fi + days=$2 +fi + # === Resolve the profile and output paths # SECURITY_DIR controls the bundle location. Resolve the checked-in OpenSSL profile # relative to this script. @@ -79,12 +89,12 @@ publish() { # === Generate the RSA signing key and self-signed CA certificate # The v3_ca profile authorizes the 4096-bit key to sign certificates and revocation -# lists. Issue the PEM certificate for 1,460 days, then derive the binary DER copy. +# lists. Issue the PEM certificate, then derive the binary DER copy. openssl req -x509 \ -newkey rsa:4096 -nodes \ -keyout "$scratch_dir/ca.key" \ -sha256 \ - -days 1460 \ + -days "$days" \ -out "$scratch_dir/ca.pem" \ -extensions v3_ca \ -config "$EXT_FILE" diff --git a/deployment/security/templates/ssl-extensions-x509.cnf b/deployment/security/templates/ssl-extensions-x509.cnf index e5e74171..a58badde 100755 --- a/deployment/security/templates/ssl-extensions-x509.cnf +++ b/deployment/security/templates/ssl-extensions-x509.cnf @@ -8,7 +8,6 @@ subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer basicConstraints = critical, CA:TRUE keyUsage = critical, keyCertSign, cRLSign -subjectAltName=DNS:nifi,DNS:elasticsearch-1,DNS:elasticsearch-2,DNS:elasticsearch-3,DNS:cogstack,DNS:*.cogstack [v3_leaf] basicConstraints = critical, CA:FALSE @@ -18,48 +17,13 @@ subjectAltName = @alt_names subjectKeyIdentifier = hash authorityKeyIdentifier = keyid,issuer +# NiFi defaults for Compose, local access and Kubernetes Service short names. +# Add deployment-specific DNS entries starting at DNS.100 when signing. [alt_names] DNS.1 = nifi -DNS.2 = nifi-registry-flow -DNS.3 = nifi-registry - -DNS.4 = nifi-nginx -DNS.5 = elasticsearch-1 -DNS.6 = elasticsearch-2 -DNS.7 = elasticsearch-3 -DNS.8 = ocr-service -DNS.9 = ocr-service-text-only -DNS.10 = medcat-trainer-nginx -DNS.11 = medcat-trainer-ui -DNS.12 = nlp-medcat-service-production -DNS.13 = nlp-medcat-service-production-deid -DNS.14 = cogstack-kibana -DNS.15 = cogstack-cohort -DNS.16 = cogstack-elasticsearch-1 -DNS.17 = cogstack-elasticsearch-2 -DNS.18 = cogstack-elasticsearch-3 -DNS.19 = cogstack-nifi -DNS.20 = cogstack-nifi-nginx -DNS.21 = cogstack-nifi-registry-flow -DNS.22 = cogstack-auth-service -DNS.23 = cogstack -DNS.24 = *.cogstack -DNS.25 = localhost -IP.1 = 127.0.0.1 -email.1 = admin@cogstack.net - -[v3_gitea] -basicConstraints = critical, CA:FALSE -keyUsage = critical, digitalSignature, keyEncipherment -extendedKeyUsage = serverAuth -subjectAltName = @gitea_alt_names -subjectKeyIdentifier = hash -authorityKeyIdentifier = keyid,issuer - -[gitea_alt_names] -DNS.1 = gitea -DNS.2 = cogstack-gitea -DNS.3 = localhost +DNS.2 = localhost +DNS.3 = cogstack-nifi +DNS.4 = cogstack-nifi-web IP.1 = 127.0.0.1 [req] @@ -67,7 +31,6 @@ default_bits = 4096 string_mask = utf8only prompt = no distinguished_name = req_distinguished_name -x509_extensions = v3_leaf default_md = sha256 [req_distinguished_name] From 422ffc75c74e1ae1dfefc3074e93c74727a44ef2 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 23 Nov 2026 21:52:20 +0000 Subject: [PATCH 15/16] Added nginx cert gen script. --- deployment/env/certificates.env | 4 + deployment/scripts/README.md | 31 ++++- .../scripts/security/create_nginx_certs.sh | 116 ++++++++++++++++++ 3 files changed, 145 insertions(+), 6 deletions(-) create mode 100755 deployment/scripts/security/create_nginx_certs.sh diff --git a/deployment/env/certificates.env b/deployment/env/certificates.env index 4c2eadf5..bf9fee25 100644 --- a/deployment/env/certificates.env +++ b/deployment/env/certificates.env @@ -19,6 +19,10 @@ NIFI_HEALTHCHECK_HOST= KUBE_NAMESPACE= CLUSTER_DOMAIN=cluster.local +# Browser-facing NGINX DNS names or IP addresses, comma-separated. +# Blank uses localhost,127.0.0.1. +NGINX_TLS_NAMES= + # Optional comma-separated DNS aliases for each OpenSearch node and for Dashboards. OPENSEARCH_NODE_DNS_NAMES= OPENSEARCH_DASHBOARDS_DNS_NAMES= diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index 68d4fae8..e432fe85 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -6,19 +6,23 @@ as the user who will use `kubectl`. ## Certificates -These scripts use OpenSSL and Java's `keytool`. If you need a root CA, export -`ROOT_CERTIFICATE_KEYSTORE_PASSWORD` and run this from the repository root. -All four generators accept `--days DAYS`. The default validity is 1,460 days -for the root CA and OpenSearch certificates and 397 days for NiFi. +All five generators use OpenSSL and accept `--days DAYS`. The default validity +is 1,460 days for the root CA and OpenSearch certificates and 397 days for +NiFi and NGINX. The root CA, NiFi and OpenSearch node generators also use +Java's `keytool`. `SECURITY_DIR` defaults to `deployment/security/`. + +If you need a root CA, export `ROOT_CERTIFICATE_KEYSTORE_PASSWORD` and run this +from the repository root. ```bash ./deployment/scripts/security/create_root_ca_cert.sh ``` +### NiFi + Export the `KEYSTORE_PASSWORD` and `TRUSTSTORE_PASSWORD` that NiFi will use. The legacy `NIFI_KEYSTORE_PASSWORD` and `NIFI_TRUSTSTORE_PASSWORD` names are -also accepted. Both scripts accept `SECURITY_DIR`, which defaults to -`deployment/security/`. +also accepted. Choose the command for your deployment. The default NiFi certificate covers `nifi`, `localhost`, `cogstack-nifi`, `cogstack-nifi-web`, and `127.0.0.1`. @@ -46,6 +50,21 @@ Each invocation writes `nifi.key`, `nifi.csr`, `nifi.pem`, `nifi.crt` (DER), `nifi.p12`, `nifi-keystore.jks`, and `nifi-truststore.jks` under `$SECURITY_DIR/certificates/nifi/`. +### NGINX + +Use the existing root CA to issue the browser-facing certificate. Set +`NGINX_TLS_NAMES` to a comma-separated list of DNS names or IP addresses, +including wildcard DNS names. The supplied list replaces the defaults of +`localhost` and `127.0.0.1`. + +```bash +NGINX_TLS_NAMES='*.cogstack.internal,192.0.2.10' ./deployment/scripts/security/create_nginx_certs.sh +``` + +The generator writes `tls.crt` and `tls.key` under +`$SECURITY_DIR/certificates/nginx/` and keeps the key at mode `0600`. +It runs without a store password or `keytool`. + ### OpenSearch Export `ES_CERTIFICATE_PASSWORD` for the Java and PKCS#12 stores. Pass the node diff --git a/deployment/scripts/security/create_nginx_certs.sh b/deployment/scripts/security/create_nginx_certs.sh new file mode 100755 index 00000000..ebea7a25 --- /dev/null +++ b/deployment/scripts/security/create_nginx_certs.sh @@ -0,0 +1,116 @@ +#!/usr/bin/env bash + +# ============================================================================================================================= +# 🔐 Create the NGINX HTTPS certificate and private key +# +# Usage: +# ./create_nginx_certs.sh [--days DAYS] +# DAYS is a positive integer. The default validity is 397 days. +# +# Requires: +# - Bash and OpenSSL +# - root-ca.pem and root-ca.key under certificates/root/ in SECURITY_DIR +# +# Optional environment variables: +# - SECURITY_DIR defaults to deployment/security/ +# - NGINX_TLS_NAMES is a comma-separated list of HTTPS hostnames or IP addresses +# and defaults to localhost,127.0.0.1. Wildcards such as *.cogstack.internal are supported. +# +# Output: +# deployment/security/certificates/nginx/tls.crt - CA-signed HTTPS certificate in PEM format +# deployment/security/certificates/nginx/tls.key - RSA private key with mode 0600 +# ============================================================================================================================= + +set -euo pipefail +umask 077 + +days=397 +if (( $# > 0 )); then + if [[ $# -ne 2 || "$1" != --days || ! "$2" =~ ^[1-9][0-9]*$ ]]; then + printf 'Usage: %s [--days DAYS] (DAYS must be a positive integer)\n' "$0" >&2 + exit 2 + fi + days=$2 +fi + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +security_dir=${SECURITY_DIR:-"$script_dir/../../security"} +ca_cert="$security_dir/certificates/root/root-ca.pem" +ca_key="$security_dir/certificates/root/root-ca.key" +output_dir="$security_dir/certificates/nginx" + +for input in "$ca_cert" "$ca_key"; do + if [[ ! -f "$input" || ! -r "$input" || ! -s "$input" ]]; then + printf 'Missing or unreadable CA file %s. Run create_root_ca_cert.sh first.\n' "$input" >&2 + exit 1 + fi +done + +require_new_file() { + if [[ -e "$1" || -L "$1" ]]; then + printf 'Output already exists: %s\n' "$1" >&2 + exit 1 + fi +} +require_new_file "$output_dir/tls.key" +require_new_file "$output_dir/tls.crt" + +# === Build the SAN list for the names clients use to reach NGINX +tls_names=${NGINX_TLS_NAMES:-localhost,127.0.0.1} +if [[ "$tls_names" == ,* || "$tls_names" == *, || "$tls_names" == *,,* || "$tls_names" == *[[:space:]]* ]]; then + printf 'NGINX_TLS_NAMES must contain comma-separated hostnames or IP addresses without spaces.\n' >&2 + exit 2 +fi +IFS=, read -r -a names <<< "$tls_names" +dns_label='[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?' +dns_name="^$dns_label(\.$dns_label)*$" +wildcard_name="^\*\.$dns_label(\.$dns_label)+$" +sans= +for name in "${names[@]}"; do + if [[ "$name" =~ ^[0-9]+(\.[0-9]+){3}$ || ( "$name" == *:* && "$name" =~ ^[[:xdigit:]:.]+$ ) ]]; then + type=IP + elif (( ${#name} <= 253 )) && [[ "$name" =~ $dns_name || "$name" =~ $wildcard_name ]]; then + type=DNS + else + printf 'Invalid NGINX TLS hostname or IP address: %s\n' "$name" >&2 + exit 2 + fi + sans+="${sans:+,}$type:$name" +done + +# Finish and verify both files before publishing the pair. +scratch_dir=$(mktemp -d) +published=() +cleanup() { + if (( $? != 0 )) && [[ -n ${published[0]:-} ]]; then + rm -f -- "${published[@]}" + fi + rm -rf -- "$scratch_dir" +} +trap cleanup EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +# === Generate the key and issue a server certificate +openssl req -new -newkey rsa:4096 -nodes -sha256 -subj '/CN=CogStack NGINX' \ + -keyout "$scratch_dir/tls.key" -out "$scratch_dir/tls.csr" +serial=$(openssl rand -hex 16) +openssl x509 -req -sha256 -days "$days" -set_serial "0x$serial" \ + -in "$scratch_dir/tls.csr" -CA "$ca_cert" -CAkey "$ca_key" -out "$scratch_dir/tls.crt" \ + -extfile <(printf '%s\n' 'basicConstraints=critical,CA:FALSE' \ + 'keyUsage=critical,digitalSignature,keyEncipherment' 'extendedKeyUsage=serverAuth' \ + 'subjectKeyIdentifier=hash' 'authorityKeyIdentifier=keyid,issuer' "subjectAltName=$sans") +openssl verify -purpose sslserver -CAfile "$ca_cert" "$scratch_dir/tls.crt" >/dev/null + +# === Publish the certificate and key at the NGINX mount paths +(umask 022; mkdir -p -- "$output_dir") +set -o noclobber +for file in tls.key tls.crt; do + require_new_file "$output_dir/$file" + { + published+=("$output_dir/$file") + cat -- "$scratch_dir/$file" + } > "$output_dir/$file" +done +chmod 644 "$output_dir/tls.crt" +printf 'Created NGINX certificate and key under %s\n' "$output_dir" From 319d013287e9362e05d2926503f442aa297cd10d Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Tue, 24 Nov 2026 10:35:26 +0000 Subject: [PATCH 16/16] apps: added nifi dev docker cert setup. --- apps/nifi/README.md | 18 +++++- apps/nifi/docker/Makefile | 47 ++++++++++---- apps/nifi/docker/docker-compose.dev-tls.yml | 22 +++++++ apps/nifi/docker/setup_dev_tls.sh | 70 +++++++++++++++++++++ 4 files changed, 143 insertions(+), 14 deletions(-) create mode 100644 apps/nifi/docker/docker-compose.dev-tls.yml create mode 100755 apps/nifi/docker/setup_dev_tls.sh diff --git a/apps/nifi/README.md b/apps/nifi/README.md index c8c3172c..a84f9d3a 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -46,7 +46,23 @@ for additional settings. ### TLS certificates -Place the following under `deployment/security/certificates/`: +For local development, keep TLS and demo login settings in +`deployment/env/cert_auth_settings_dev.env`. Set an absolute `SECURITY_DIR`, +`ROOT_CERTIFICATE_KEYSTORE_PASSWORD`, `KEYSTORE_PASSWORD`, `TRUSTSTORE_PASSWORD`, +`SINGLE_USER_CREDENTIALS_USERNAME`, and `SINGLE_USER_CREDENTIALS_PASSWORD`. +Prepare or reuse the TLS bundle from the repository root. + +```bash +make -C apps/nifi/docker setup-nifi-dev-tls +``` + +Keep this Git-ignored file at mode `0600`. It can also hold store paths, types, +and TLS names. `start-nifi-dev` and `start-nifi-dev-build` load it automatically +when present and mount the bundle's runtime TLS files. The CA signing key and +its store password stay on the host. + +To supply certificates manually, place the following under +`deployment/security/certificates/`. | Files | Purpose | | --- | --- | diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index 47595514..037f080b 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -5,11 +5,34 @@ DC_START_CMD := up -d DC_STOP_CMD := stop COMPOSE_DEV := docker compose -f docker-compose.base.yml -f docker-compose.dev.yml COMPOSE_PROD := docker compose -f docker-compose.base.yml -f docker-compose.prod.yml +DEV_CERT_ENV := $(abspath ../../../deployment/env/cert_auth_settings_dev.env) define WITH_ENV source ./export_env_vars.sh || exit $$?; endef +define WITH_DEV_CERTS +$(WITH_ENV) \ +cert_dir=../../../deployment/security/certificates; \ +dev_certs=(); \ +if [[ -f "$(DEV_CERT_ENV)" ]]; then \ + set -a; source "$(DEV_CERT_ENV)" || exit $$?; set +a; \ + : "$${SECURITY_DIR:?Set SECURITY_DIR in the dev settings file}"; \ + : "$${KEYSTORE_PASSWORD:?Set KEYSTORE_PASSWORD in the dev settings file}" "$${TRUSTSTORE_PASSWORD:?Set TRUSTSTORE_PASSWORD in the dev settings file}"; \ + cert_dir="$$SECURITY_DIR/certificates"; \ + dev_certs=(-f docker-compose.dev-tls.yml); \ +fi; +endef + +define CHECK_TLS_FILES +for cert in root/root-ca.pem nifi/nifi-keystore.jks nifi/nifi-truststore.jks nginx/tls.crt nginx/tls.key; do \ + file="$$cert_dir/$$cert"; \ + if [ ! -f "$$file" ] || [ ! -r "$$file" ] || [ ! -s "$$file" ]; then \ + printf 'TLS file missing, empty, or unreadable: %s\n' "$$file" >&2; exit 1; \ + fi; \ +done; +endef + help: ## List available targets with descriptions @echo "Available targets:" @awk '\ @@ -50,25 +73,23 @@ show-env: ## Print sorted environment variables after loading export_env_vars.sh ${WITH_ENV} >/dev/null 2>&1; printenv | sort check-config: ## Validate the default, dev and prod Compose configurations - @$(WITH_ENV) docker compose config --quiet && \ - $(COMPOSE_DEV) config --quiet && $(COMPOSE_PROD) config --quiet + @$(WITH_ENV) docker compose config --quiet && $(COMPOSE_PROD) config --quiet + @$(WITH_DEV_CERTS) $(COMPOSE_DEV) "$${dev_certs[@]}" config --quiet check-tls: ## Check the TLS files required by NiFi and NGINX - @for cert in root/root-ca.pem nifi/nifi-keystore.jks nifi/nifi-truststore.jks nginx/tls.crt nginx/tls.key; do \ - file="../../../deployment/security/certificates/$$cert"; \ - if [ ! -f "$$file" ] || [ ! -r "$$file" ] || [ ! -s "$$file" ]; then \ - printf 'TLS file missing, empty, or unreadable: %s\n' "$$file" >&2; exit 1; \ - fi; \ - done + @cert_dir=../../../deployment/security/certificates; $(CHECK_TLS_FILES) start-nifi: check-tls ## Start the default NiFi and NGINX stack $(WITH_ENV) docker compose $(DC_START_CMD) -start-nifi-dev: check-tls ## Start NiFi and NGINX with local builds - $(WITH_ENV) $(COMPOSE_DEV) $(DC_START_CMD) nifi nifi-nginx +setup-nifi-dev-tls: ## Generate or validate the local dev certificates using cert_auth_settings_dev.env + @./setup_dev_tls.sh "$(DEV_CERT_ENV)" + +start-nifi-dev: ## Start NiFi and NGINX with local builds + $(WITH_DEV_CERTS) $(CHECK_TLS_FILES) $(COMPOSE_DEV) "$${dev_certs[@]}" $(DC_START_CMD) nifi nifi-nginx -start-nifi-dev-build: check-tls ## Build and start NiFi dev services - $(WITH_ENV) $(COMPOSE_DEV) up -d --build nifi nifi-nginx +start-nifi-dev-build: ## Build and start NiFi dev services + $(WITH_DEV_CERTS) $(CHECK_TLS_FILES) $(COMPOSE_DEV) "$${dev_certs[@]}" up -d --build nifi nifi-nginx start-nifi-prod: check-tls ## Start the published NiFi and NGINX images on cogstack-net $(WITH_ENV) $(COMPOSE_PROD) $(DC_START_CMD) @@ -107,4 +128,4 @@ delete-nifi-dev-images: ## Delete the NiFi dev images echo "No NiFi dev images found."; \ fi -.PHONY: help load-env show-env check-config check-tls start-nifi start-nifi-dev start-nifi-dev-build start-nifi-prod build-nifi-image stop-nifi-dev stop-nifi-prod delete-nifi delete-nifi-dev-containers delete-nifi-dev-volumes delete-nifi-dev-images +.PHONY: help load-env show-env check-config check-tls start-nifi setup-nifi-dev-tls start-nifi-dev start-nifi-dev-build start-nifi-prod build-nifi-image stop-nifi-dev stop-nifi-prod delete-nifi delete-nifi-dev-containers delete-nifi-dev-volumes delete-nifi-dev-images diff --git a/apps/nifi/docker/docker-compose.dev-tls.yml b/apps/nifi/docker/docker-compose.dev-tls.yml new file mode 100644 index 00000000..c7ffcc41 --- /dev/null +++ b/apps/nifi/docker/docker-compose.dev-tls.yml @@ -0,0 +1,22 @@ +services: + nifi: + environment: + NIFI_HEALTHCHECK_HOST: ${NIFI_HEALTHCHECK_HOST:-nifi} + volumes: + - ${SECURITY_DIR}/certificates/nifi:/security/certificates/nifi:ro + - type: bind + source: ${SECURITY_DIR}/certificates/root/root-ca.pem + target: /security/certificates/root/root-ca.pem + read_only: true + bind: + create_host_path: false + + nifi-nginx: + volumes: + - ${SECURITY_DIR}/certificates/nginx:/certificates/nginx:ro + - type: bind + source: ${SECURITY_DIR}/certificates/root/root-ca.pem + target: /certificates/root/root-ca.pem + read_only: true + bind: + create_host_path: false diff --git a/apps/nifi/docker/setup_dev_tls.sh b/apps/nifi/docker/setup_dev_tls.sh new file mode 100755 index 00000000..9eef1d87 --- /dev/null +++ b/apps/nifi/docker/setup_dev_tls.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +set -euo pipefail +umask 077 + +if [[ $# -ne 1 || -z ${1:-} ]]; then + printf 'Usage: %s \n' "$0" >&2 + exit 1 +fi + +env_file=$1 +[[ "$env_file" == /* ]] || env_file="$PWD/$env_file" +if [[ ! -f "$env_file" || ! -r "$env_file" ]]; then + printf 'Cannot read certificate settings at %s.\n' "$env_file" >&2 + exit 1 +fi + +unset SECURITY_DIR ROOT_CERTIFICATE_KEYSTORE_PASSWORD KEYSTORE_PASSWORD TRUSTSTORE_PASSWORD +unset NIFI_UPSTREAM_TLS_NAME NIFI_HEALTHCHECK_HOST KUBE_NAMESPACE CLUSTER_DOMAIN NGINX_TLS_NAMES +set -a +# shellcheck disable=SC1090 +source "$env_file" +set +a + +: "${ROOT_CERTIFICATE_KEYSTORE_PASSWORD:?Set ROOT_CERTIFICATE_KEYSTORE_PASSWORD in the certificate env file}" +: "${KEYSTORE_PASSWORD:?Set KEYSTORE_PASSWORD in the certificate env file}" +: "${TRUSTSTORE_PASSWORD:?Set TRUSTSTORE_PASSWORD in the certificate env file}" +if [[ ${SECURITY_DIR:-} != /* ]]; then + printf 'Set SECURITY_DIR to an absolute path in %s.\n' "$env_file" >&2 + exit 1 +fi + +while [[ "$SECURITY_DIR" != / && "$SECURITY_DIR" == */ ]]; do + SECURITY_DIR=${SECURITY_DIR%/} +done +certs="$SECURITY_DIR/certificates" + +valid_bundle() { + local path + for path in "$SECURITY_DIR" "$certs" "$certs/"{root,nifi,nginx}; do + [[ -d "$path" && ! -L "$path" ]] || return 1 + done + for path in "$certs/root/root-ca.pem" \ + "$certs/nifi/"nifi-{keystore,truststore}.jks "$certs/nginx/"tls.{crt,key}; do + [[ -f "$path" && ! -L "$path" && -r "$path" && -s "$path" ]] || return 1 + done + + keytool -list -storetype JKS -keystore "$certs/nifi/nifi-keystore.jks" \ + -storepass:env KEYSTORE_PASSWORD >/dev/null 2>&1 && + keytool -list -storetype JKS -keystore "$certs/nifi/nifi-truststore.jks" \ + -storepass:env TRUSTSTORE_PASSWORD >/dev/null 2>&1 +} + +mkdir -p -- "$(dirname -- "$SECURITY_DIR")" +if ! mkdir -- "$SECURITY_DIR" 2>/dev/null; then + valid_bundle && exit 0 + printf 'Cannot create or reuse demo TLS bundle at %s. Use a new directory or fix the existing bundle.\n' "$SECURITY_DIR" >&2 + exit 1 +fi + +# Only remove a directory reserved by this invocation. +trap 'rm -rf -- "$SECURITY_DIR"' EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +generators="$script_dir/../../../deployment/scripts/security" +"$generators/create_root_ca_cert.sh" >/dev/null +"$generators/create_nifi_certs.sh" >/dev/null +"$generators/create_nginx_certs.sh" >/dev/null +trap - EXIT