From 5503ace396e7ab47d8552c5e1db9b261acb9848c Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Sun, 22 Nov 2026 18:06:36 +0000 Subject: [PATCH 01/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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/63] 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 From b820c999d8dc274312f791aab410461d7a40ac8b Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Tue, 24 Nov 2026 12:10:04 +0000 Subject: [PATCH 17/63] apps: Added OpenBao. --- apps/nifi/README.md | 29 +++++++++++++ apps/nifi/docker/Makefile | 22 ++++++++-- apps/nifi/docker/openbao_dev.sh | 47 +++++++++++++++++++++ apps/openbao/.gitignore | 3 ++ apps/openbao/docker/docker-compose.base.yml | 3 ++ apps/openbao/docker/docker-compose.dev.yml | 8 ++++ apps/openbao/docker/docker-compose.yml | 7 +++ apps/openbao/env/openbao.env | 7 +++ deployment/Makefile | 15 ++++--- 9 files changed, 132 insertions(+), 9 deletions(-) create mode 100644 apps/nifi/docker/openbao_dev.sh create mode 100644 apps/openbao/.gitignore create mode 100644 apps/openbao/docker/docker-compose.base.yml create mode 100644 apps/openbao/docker/docker-compose.dev.yml create mode 100644 apps/openbao/docker/docker-compose.yml create mode 100644 apps/openbao/env/openbao.env diff --git a/apps/nifi/README.md b/apps/nifi/README.md index a84f9d3a..7b139279 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -77,6 +77,35 @@ checks for readable, nonempty regular files. If `root-ca.pem` is a directory fro earlier bind mount, replace it with the actual PEM file. Certificate validation occurs when the services connect over TLS. +### OpenBao for local dev + +With [OpenBao](../openbao/docker/docker-compose.yml) running, set +`NIFI_DEV_OPENBAO_ADDR` to its host URL and export `BAO_TOKEN` in your shell. +Use the dev root token to seed KV from `cert_auth_settings_dev.env`. + +```bash +export NIFI_DEV_OPENBAO_ADDR=http://127.0.0.1:8200 +make -C apps/nifi/docker seed-nifi-dev-openbao +``` + +Use the bundled CLI to grant read access to that entry and start with a short-lived token. + +```bash +bao_dev() { + docker compose -f apps/openbao/docker/docker-compose.yml exec -T \ + -e BAO_TOKEN -e BAO_ADDR=http://127.0.0.1:8200 openbao bao "$@" +} +printf '%s\n' 'path "secret/data/nifi/dev" { capabilities = ["read"] }' | + bao_dev policy write nifi-dev-read - +BAO_TOKEN="$(bao_dev token create -policy=nifi-dev-read -no-default-policy \ + -ttl=10m -renewable=false -field=token)" make -C apps/nifi/docker start-nifi-dev +``` + +Both dev start targets fetch the demo login and Java store passwords with +`curl` and `jq`. Keep the dev settings file for reseeding after an OpenBao +dev restart and retain the sensitive properties key for saved flows. With +`NIFI_DEV_OPENBAO_ADDR` unset, the dev targets use the local settings file. + ### Start and verify Run these commands from `apps/nifi/docker/`: diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index 037f080b..15fd68cf 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -18,7 +18,6 @@ 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; @@ -33,6 +32,18 @@ for cert in root/root-ca.pem nifi/nifi-keystore.jks nifi/nifi-truststore.jks ngi done; endef +define WITH_DEV_START +$(WITH_DEV_CERTS) \ +if [[ -n "$${NIFI_DEV_OPENBAO_ADDR:-}" ]]; then \ + source ./openbao_dev.sh && nifi_openbao_dev load || exit $$?; \ + unset BAO_TOKEN; \ +fi; \ +if (( $${#dev_certs[@]} )); then \ + : "$${KEYSTORE_PASSWORD:?Set KEYSTORE_PASSWORD}" "$${TRUSTSTORE_PASSWORD:?Set TRUSTSTORE_PASSWORD}"; \ +fi; \ +$(CHECK_TLS_FILES) +endef + help: ## List available targets with descriptions @echo "Available targets:" @awk '\ @@ -85,11 +96,14 @@ start-nifi: check-tls ## Start the default NiFi and NGINX stack setup-nifi-dev-tls: ## Generate or validate the local dev certificates using cert_auth_settings_dev.env @./setup_dev_tls.sh "$(DEV_CERT_ENV)" +seed-nifi-dev-openbao: ## Store the current demo credentials in a fresh OpenBao dev instance + @source ./openbao_dev.sh && nifi_openbao_dev seed "$(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 + $(WITH_DEV_START) $(COMPOSE_DEV) "$${dev_certs[@]}" $(DC_START_CMD) 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 + $(WITH_DEV_START) $(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) @@ -128,4 +142,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 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 +.PHONY: help load-env show-env check-config check-tls start-nifi setup-nifi-dev-tls seed-nifi-dev-openbao 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/openbao_dev.sh b/apps/nifi/docker/openbao_dev.sh new file mode 100644 index 00000000..3dc08955 --- /dev/null +++ b/apps/nifi/docker/openbao_dev.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# Source from the NiFi dev Make targets. + +_nifi_dev_openbao_request() { + : "${NIFI_DEV_OPENBAO_ADDR:?Set NIFI_DEV_OPENBAO_ADDR}" "${BAO_TOKEN:?Export BAO_TOKEN in your shell}" + curl --noproxy '*' --fail --silent --show-error --connect-timeout 3 --max-time 10 \ + --header @<(printf 'X-Vault-Token: %s\n' "$BAO_TOKEN") \ + "$@" "${NIFI_DEV_OPENBAO_ADDR%/}/v1/secret/data/nifi/dev" +} + +nifi_openbao_dev() { + local keys=(SINGLE_USER_CREDENTIALS_USERNAME SINGLE_USER_CREDENTIALS_PASSWORD + KEYSTORE_PASSWORD TRUSTSTORE_PASSWORD) + local secret key value + + if [[ $1 == seed ]]; then + ( + unset "${keys[@]}" + set -a + # shellcheck disable=SC1090 + source "$2" || exit + set +a + secret=$(jq -en --args ' + $ARGS.positional | map({(.): env[.]}) | add | + if all(.[]; type == "string" and length > 0) + then {options: {cas: 0}, data: .} + else error("Set all four NiFi demo credentials before seeding OpenBao") + end + ' "${keys[@]}") || exit + printf '%s' "$secret" | _nifi_dev_openbao_request \ + --header 'Content-Type: application/json' --data-binary @- >/dev/null + ) + return + fi + + secret=$(_nifi_dev_openbao_request) || { + printf 'Could not read OpenBao secret/nifi/dev. Check the address, token, and seed entry.\n' >&2 + return 1 + } + for key in "${keys[@]}"; do + value=$(jq -er --arg key "$key" '.data.data[$key] | select(type == "string" and length > 0)' <<< "$secret") || { + printf 'OpenBao secret/nifi/dev is missing %s.\n' "$key" >&2 + return 1 + } + export "$key=$value" + done +} diff --git a/apps/openbao/.gitignore b/apps/openbao/.gitignore new file mode 100644 index 00000000..1a56d0d2 --- /dev/null +++ b/apps/openbao/.gitignore @@ -0,0 +1,3 @@ +!/env/ +/env/* +!/env/openbao.env diff --git a/apps/openbao/docker/docker-compose.base.yml b/apps/openbao/docker/docker-compose.base.yml new file mode 100644 index 00000000..bfc36c4a --- /dev/null +++ b/apps/openbao/docker/docker-compose.base.yml @@ -0,0 +1,3 @@ +services: + openbao: + image: ${OPENBAO_DOCKER_IMAGE:?Set OPENBAO_DOCKER_IMAGE} diff --git a/apps/openbao/docker/docker-compose.dev.yml b/apps/openbao/docker/docker-compose.dev.yml new file mode 100644 index 00000000..59688003 --- /dev/null +++ b/apps/openbao/docker/docker-compose.dev.yml @@ -0,0 +1,8 @@ +services: + openbao: + # The upstream image starts an in-memory dev server by default. + environment: + BAO_ADDR: ${OPENBAO_ADDR:?Set OPENBAO_ADDR} + BAO_DEV_ROOT_TOKEN_ID: + ports: + - "127.0.0.1:${OPENBAO_HOST_PORT:?Set OPENBAO_HOST_PORT}:8200" diff --git a/apps/openbao/docker/docker-compose.yml b/apps/openbao/docker/docker-compose.yml new file mode 100644 index 00000000..f54551f7 --- /dev/null +++ b/apps/openbao/docker/docker-compose.yml @@ -0,0 +1,7 @@ +name: openbao + +include: + - path: + - docker-compose.base.yml + - docker-compose.dev.yml + env_file: ../env/openbao.env diff --git a/apps/openbao/env/openbao.env b/apps/openbao/env/openbao.env new file mode 100644 index 00000000..d98b1de1 --- /dev/null +++ b/apps/openbao/env/openbao.env @@ -0,0 +1,7 @@ +OPENBAO_DOCKER_IMAGE=openbao/openbao:2.7.3 +OPENBAO_HOST_PORT=8200 + +# Address for the bao CLI inside the container. +OPENBAO_ADDR=http://127.0.0.1:8200 + +# Export BAO_DEV_ROOT_TOKEN_ID in your shell if a demo script needs a known token. diff --git a/deployment/Makefile b/deployment/Makefile index 26b16018..00b09c69 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -1,18 +1,23 @@ SHELL := /usr/bin/env bash .SHELLFLAGS := -o pipefail -c -.PHONY: setup-install-pre-requisites setup-k3s-cluster-init setup-verify setup-k3s-cluster-remote +.PHONY: setup-install-pre-requisites setup-k3s-cluster-init setup-verify setup-k3s-cluster-remote help -setup-install-pre-requisites: +setup-install-pre-requisites: ## Install host tools, Docker, K3s, and Helm locally by default bash scripts/installation_utils/install_os_tools_and_software.sh -setup-k3s-cluster-init: +setup-k3s-cluster-init: ## Initialize the first K3s server on this machine bash scripts/installation_utils/setup_kubernetes_cluster.sh k3s server --cluster-init -setup-k3s-cluster-remote: +setup-k3s-cluster-remote: ## Install prerequisites, initialize the first server, and join the rest over SSH bash scripts/installation_utils/setup_k3s_cluster.sh $(NODES) -setup-verify: +setup-verify: ## Check local Docker, Docker Compose, and K3s access without sudo bash scripts/installation_utils/verify_docker.sh bash scripts/installation_utils/verify_k3s.sh +help: ## Show deployment commands + @printf '%s\n' 'Deployment commands' + @awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[[:alnum:]_-]+$$/ { printf " %-30s %s\n", $$1, $$2 }' "$(lastword $(MAKEFILE_LIST))" + @printf '\n%s\n %s\n' 'Remote setup example' \ + 'make setup-k3s-cluster-remote NODES="admin@server1 admin@server2 admin@server3"' From b8a6034d3bd7831dcb4ded94eabdf43eac4652d1 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Tue, 24 Nov 2026 15:34:26 +0000 Subject: [PATCH 18/63] apps: NiFi openbao integrations. --- apps/nifi/README.md | 86 ++++++------------- apps/nifi/docker/Makefile | 56 ++++-------- apps/nifi/docker/docker-compose.base.yml | 24 +++--- apps/nifi/docker/docker-compose.dev-tls.yml | 22 ----- apps/nifi/docker/openbao_dev.sh | 47 ---------- apps/nifi/docker/openbao_env.sh | 25 ++++++ apps/nifi/docker/setup_dev_tls.sh | 70 --------------- apps/openbao/docker/docker-compose.server.yml | 21 +++++ apps/openbao/docker/openbao.hcl | 12 +++ 9 files changed, 112 insertions(+), 251 deletions(-) delete mode 100644 apps/nifi/docker/docker-compose.dev-tls.yml delete mode 100644 apps/nifi/docker/openbao_dev.sh create mode 100644 apps/nifi/docker/openbao_env.sh delete mode 100755 apps/nifi/docker/setup_dev_tls.sh create mode 100644 apps/openbao/docker/docker-compose.server.yml create mode 100644 apps/openbao/docker/openbao.hcl diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 7b139279..9ebe4c08 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -13,25 +13,13 @@ production configurations use `cogstacksystems/nifi` and `cogstacksystems/nginx` 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. +no shared settings. Use the following as a starting point for `nifi.env`. ```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 ``` @@ -46,23 +34,9 @@ for additional settings. ### TLS 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/`. +Use the existing certificate generators or supply a TLS bundle. Place the files +under `deployment/security/certificates/`, or set `SECURITY_DIR` in `nifi.env` +to the parent of your deployment’s `certificates/` directory. | Files | Purpose | | --- | --- | @@ -72,40 +46,32 @@ To supply certificates manually, place the following under 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. - -### OpenBao for local dev - -With [OpenBao](../openbao/docker/docker-compose.yml) running, set -`NIFI_DEV_OPENBAO_ADDR` to its host URL and export `BAO_TOKEN` in your shell. -Use the dev root token to seed KV from `cert_auth_settings_dev.env`. +readable by their container users. The start targets check for readable, +nonempty files before launching. Certificate validation occurs when the services +connect over TLS. + +### OpenBao + +Dev and prod use the same lookup. Set `NIFI_OPENBAO_ADDR` in `nifi.env` to +that deployment’s OpenBao HTTPS endpoint. Set `BAO_CACERT` if its listener +uses a private CA. In KV v2 mounted at `secret`, create the `nifi` entry with +`SINGLE_USER_CREDENTIALS_USERNAME`, `SINGLE_USER_CREDENTIALS_PASSWORD`, +`KEYSTORE_PASSWORD`, and `TRUSTSTORE_PASSWORD`. Use the passwords that open +those stores. Export a `BAO_TOKEN` scoped to read `secret/data/nifi` and run +Make. `curl` and `jq` load the values before Compose starts. When the address +is unset, Make uses the credentials already supplied to Compose. Set +`COGSTACK_NIFI_ENV_FILE` to select a deployment's settings on a shared host. + +For a local persistent server, set `OPENBAO_TLS_DIR` to the absolute path +containing its `tls.crt` and `tls.key`. Run this from `apps/openbao/docker`, +then initialize and unseal via the OpenBao UI or CLI. Set `OPENBAO_HOST_PORT` +if port 8200 is occupied. ```bash -export NIFI_DEV_OPENBAO_ADDR=http://127.0.0.1:8200 -make -C apps/nifi/docker seed-nifi-dev-openbao +docker compose --env-file ../env/openbao.env \ + -f docker-compose.base.yml -f docker-compose.server.yml up -d ``` -Use the bundled CLI to grant read access to that entry and start with a short-lived token. - -```bash -bao_dev() { - docker compose -f apps/openbao/docker/docker-compose.yml exec -T \ - -e BAO_TOKEN -e BAO_ADDR=http://127.0.0.1:8200 openbao bao "$@" -} -printf '%s\n' 'path "secret/data/nifi/dev" { capabilities = ["read"] }' | - bao_dev policy write nifi-dev-read - -BAO_TOKEN="$(bao_dev token create -policy=nifi-dev-read -no-default-policy \ - -ttl=10m -renewable=false -field=token)" make -C apps/nifi/docker start-nifi-dev -``` - -Both dev start targets fetch the demo login and Java store passwords with -`curl` and `jq`. Keep the dev settings file for reseeding after an OpenBao -dev restart and retain the sensitive properties key for saved flows. With -`NIFI_DEV_OPENBAO_ADDR` unset, the dev targets use the local settings file. - ### Start and verify Run these commands from `apps/nifi/docker/`: diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index 15fd68cf..0ed599f1 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -5,43 +5,26 @@ 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}"; \ - 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"; \ +for cert in root/root-ca.pem nifi/nifi-{keystore,truststore}.jks nginx/tls.{crt,key}; do \ + file="$${SECURITY_DIR:-../../../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; endef -define WITH_DEV_START -$(WITH_DEV_CERTS) \ -if [[ -n "$${NIFI_DEV_OPENBAO_ADDR:-}" ]]; then \ - source ./openbao_dev.sh && nifi_openbao_dev load || exit $$?; \ +define WITH_START +$(WITH_ENV) $(CHECK_TLS_FILES) \ +if [[ -n "$${NIFI_OPENBAO_ADDR:-}" ]]; then \ + source ./openbao_env.sh && nifi_openbao_env || exit $$?; \ unset BAO_TOKEN; \ -fi; \ -if (( $${#dev_certs[@]} )); then \ - : "$${KEYSTORE_PASSWORD:?Set KEYSTORE_PASSWORD}" "$${TRUSTSTORE_PASSWORD:?Set TRUSTSTORE_PASSWORD}"; \ -fi; \ -$(CHECK_TLS_FILES) +fi; endef help: ## List available targets with descriptions @@ -84,29 +67,22 @@ 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_PROD) config --quiet - @$(WITH_DEV_CERTS) $(COMPOSE_DEV) "$${dev_certs[@]}" config --quiet + @$(WITH_ENV) docker compose config --quiet && $(COMPOSE_DEV) config --quiet && $(COMPOSE_PROD) config --quiet check-tls: ## Check the TLS files required by NiFi and NGINX - @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) - -setup-nifi-dev-tls: ## Generate or validate the local dev certificates using cert_auth_settings_dev.env - @./setup_dev_tls.sh "$(DEV_CERT_ENV)" + @$(WITH_ENV) $(CHECK_TLS_FILES) -seed-nifi-dev-openbao: ## Store the current demo credentials in a fresh OpenBao dev instance - @source ./openbao_dev.sh && nifi_openbao_dev seed "$(DEV_CERT_ENV)" +start-nifi: ## Start the default NiFi and NGINX stack + $(WITH_START) docker compose $(DC_START_CMD) start-nifi-dev: ## Start NiFi and NGINX with local builds - $(WITH_DEV_START) $(COMPOSE_DEV) "$${dev_certs[@]}" $(DC_START_CMD) nifi nifi-nginx + $(WITH_START) $(COMPOSE_DEV) $(DC_START_CMD) nifi nifi-nginx start-nifi-dev-build: ## Build and start NiFi dev services - $(WITH_DEV_START) $(COMPOSE_DEV) "$${dev_certs[@]}" up -d --build nifi nifi-nginx + $(WITH_START) $(COMPOSE_DEV) 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) +start-nifi-prod: ## Start the published NiFi and NGINX images on cogstack-net + $(WITH_START) $(COMPOSE_PROD) $(DC_START_CMD) build-nifi-image: ## Build the local NiFi image without starting services $(WITH_ENV) docker build \ @@ -142,4 +118,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 setup-nifi-dev-tls seed-nifi-dev-openbao 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 55763034..f1f1890c 100644 --- a/apps/nifi/docker/docker-compose.base.yml +++ b/apps/nifi/docker/docker-compose.base.yml @@ -19,14 +19,14 @@ x-env: 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}} + 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:-/security/certificates/nifi/nifi-keystore.jks}} + KEYSTORE_TYPE: ${KEYSTORE_TYPE:-${NIFI_KEYSTORE_TYPE:-JKS}} + KEYSTORE_PASSWORD: ${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}} + TRUSTSTORE_PATH: ${TRUSTSTORE_PATH:-${NIFI_TRUSTSTORE_PATH:-/security/certificates/nifi/nifi-truststore.jks}} + TRUSTSTORE_TYPE: ${TRUSTSTORE_TYPE:-${NIFI_TRUSTSTORE_TYPE:-JKS}} + 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} @@ -45,9 +45,9 @@ x-env: x-mounts: nifi: &nifi-volumes # Security certificates - - ../../../deployment/security/certificates/nifi:/security/certificates/nifi:ro + - ${SECURITY_DIR:-../../../deployment/security}/certificates/nifi:/security/certificates/nifi:ro - type: bind - source: ../../../deployment/security/certificates/root/root-ca.pem + source: ${SECURITY_DIR:-../../../deployment/security}/certificates/root/root-ca.pem target: /security/certificates/root/root-ca.pem read_only: true bind: @@ -67,9 +67,9 @@ x-mounts: - /tmp:mode=1777 nifi-nginx: &nifi-nginx-volumes - - ../../../deployment/security/certificates/nginx:/certificates/nginx:ro + - ${SECURITY_DIR:-../../../deployment/security}/certificates/nginx:/certificates/nginx:ro - type: bind - source: ../../../deployment/security/certificates/root/root-ca.pem + source: ${SECURITY_DIR:-../../../deployment/security}/certificates/root/root-ca.pem target: /certificates/root/root-ca.pem read_only: true bind: diff --git a/apps/nifi/docker/docker-compose.dev-tls.yml b/apps/nifi/docker/docker-compose.dev-tls.yml deleted file mode 100644 index c7ffcc41..00000000 --- a/apps/nifi/docker/docker-compose.dev-tls.yml +++ /dev/null @@ -1,22 +0,0 @@ -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/openbao_dev.sh b/apps/nifi/docker/openbao_dev.sh deleted file mode 100644 index 3dc08955..00000000 --- a/apps/nifi/docker/openbao_dev.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env bash -# Source from the NiFi dev Make targets. - -_nifi_dev_openbao_request() { - : "${NIFI_DEV_OPENBAO_ADDR:?Set NIFI_DEV_OPENBAO_ADDR}" "${BAO_TOKEN:?Export BAO_TOKEN in your shell}" - curl --noproxy '*' --fail --silent --show-error --connect-timeout 3 --max-time 10 \ - --header @<(printf 'X-Vault-Token: %s\n' "$BAO_TOKEN") \ - "$@" "${NIFI_DEV_OPENBAO_ADDR%/}/v1/secret/data/nifi/dev" -} - -nifi_openbao_dev() { - local keys=(SINGLE_USER_CREDENTIALS_USERNAME SINGLE_USER_CREDENTIALS_PASSWORD - KEYSTORE_PASSWORD TRUSTSTORE_PASSWORD) - local secret key value - - if [[ $1 == seed ]]; then - ( - unset "${keys[@]}" - set -a - # shellcheck disable=SC1090 - source "$2" || exit - set +a - secret=$(jq -en --args ' - $ARGS.positional | map({(.): env[.]}) | add | - if all(.[]; type == "string" and length > 0) - then {options: {cas: 0}, data: .} - else error("Set all four NiFi demo credentials before seeding OpenBao") - end - ' "${keys[@]}") || exit - printf '%s' "$secret" | _nifi_dev_openbao_request \ - --header 'Content-Type: application/json' --data-binary @- >/dev/null - ) - return - fi - - secret=$(_nifi_dev_openbao_request) || { - printf 'Could not read OpenBao secret/nifi/dev. Check the address, token, and seed entry.\n' >&2 - return 1 - } - for key in "${keys[@]}"; do - value=$(jq -er --arg key "$key" '.data.data[$key] | select(type == "string" and length > 0)' <<< "$secret") || { - printf 'OpenBao secret/nifi/dev is missing %s.\n' "$key" >&2 - return 1 - } - export "$key=$value" - done -} diff --git a/apps/nifi/docker/openbao_env.sh b/apps/nifi/docker/openbao_env.sh new file mode 100644 index 00000000..95d08c8b --- /dev/null +++ b/apps/nifi/docker/openbao_env.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Read NiFi's runtime credentials and keystore passwords from OpenBao's +# secret/nifi KV v2 entry, then export them for the Compose startup command. +nifi_openbao_env() { + : "${BAO_TOKEN:?Export BAO_TOKEN in your shell}" + local secret key value + + # Trust the OpenBao server with BAO_CACERT when using a private CA. + if [[ -n ${BAO_CACERT:-} ]]; then set -- --cacert "$BAO_CACERT"; fi + + # Keep the token out of curl's command-line arguments and require HTTPS. + secret=$(curl --proto '=https' --noproxy '*' --fail --silent --show-error \ + --connect-timeout 3 --max-time 10 --header @<(printf 'X-Vault-Token: %s\n' "$BAO_TOKEN") \ + "$@" "${NIFI_OPENBAO_ADDR%/}/v1/secret/data/nifi") || return + + # Fail before Compose starts if any required value is absent or empty. + for key in SINGLE_USER_CREDENTIALS_USERNAME SINGLE_USER_CREDENTIALS_PASSWORD KEYSTORE_PASSWORD TRUSTSTORE_PASSWORD; do + value=$(jq -er --arg key "$key" '.data.data[$key] | strings | select(length > 0)' <<< "$secret") || { + printf 'OpenBao secret/nifi is missing %s.\n' "$key" >&2 + return 1 + } + export "$key=$value" + done +} diff --git a/apps/nifi/docker/setup_dev_tls.sh b/apps/nifi/docker/setup_dev_tls.sh deleted file mode 100755 index 9eef1d87..00000000 --- a/apps/nifi/docker/setup_dev_tls.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/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 diff --git a/apps/openbao/docker/docker-compose.server.yml b/apps/openbao/docker/docker-compose.server.yml new file mode 100644 index 00000000..324cb785 --- /dev/null +++ b/apps/openbao/docker/docker-compose.server.yml @@ -0,0 +1,21 @@ +name: openbao-server + +services: + openbao: + command: [server] + environment: + BAO_API_ADDR: ${OPENBAO_API_ADDR:-https://127.0.0.1:${OPENBAO_HOST_PORT}} + ports: + - "127.0.0.1:${OPENBAO_HOST_PORT}:8200" + volumes: + - openbao-data:/openbao/file + - ./openbao.hcl:/openbao/config/openbao.hcl:ro + - type: bind + source: ${OPENBAO_TLS_DIR:?Set OPENBAO_TLS_DIR} + target: /openbao/tls + read_only: true + bind: + create_host_path: false + +volumes: + openbao-data: diff --git a/apps/openbao/docker/openbao.hcl b/apps/openbao/docker/openbao.hcl new file mode 100644 index 00000000..44b6fac1 --- /dev/null +++ b/apps/openbao/docker/openbao.hcl @@ -0,0 +1,12 @@ +ui = true +cluster_addr = "https://openbao:8201" + +storage "raft" { + path = "/openbao/file" +} + +listener "tcp" { + address = "0.0.0.0:8200" + tls_cert_file = "/openbao/tls/tls.crt" + tls_key_file = "/openbao/tls/tls.key" +} From 2c87ad681aefe570c2833fa252989e4ddb82638b Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Tue, 24 Nov 2026 18:10:23 +0000 Subject: [PATCH 19/63] apps: added openbao makefile. --- apps/openbao/Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 apps/openbao/Makefile diff --git a/apps/openbao/Makefile b/apps/openbao/Makefile new file mode 100644 index 00000000..1ba58979 --- /dev/null +++ b/apps/openbao/Makefile @@ -0,0 +1,12 @@ +OPENBAO_HOST_PORT ?= 8201 +OPENBAO_TLS_DIR ?= $(CURDIR)/local-server/tls + +.PHONY: start-openbao start-openbao-dev + +start-openbao: ## Start the persistent OpenBao server + OPENBAO_HOST_PORT="$(OPENBAO_HOST_PORT)" OPENBAO_TLS_DIR="$(OPENBAO_TLS_DIR)" \ + docker compose --project-name openbao-server --env-file env/openbao.env \ + -f docker/docker-compose.base.yml -f docker/docker-compose.server.yml up -d + +start-openbao-dev: ## Start the in-memory OpenBao server + docker compose -f docker/docker-compose.yml up -d From e8bb9fa707357782b845d2683f0ba7627c9fad36 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Tue, 24 Nov 2026 21:06:07 +0000 Subject: [PATCH 20/63] reversed openbao changes, back to dev env vars for security(dev). --- apps/nifi/README.md | 43 ++++++++++----------------- apps/nifi/docker/Makefile | 13 ++++---- apps/nifi/docker/openbao_env.sh | 25 ---------------- deployment/.gitignore | 2 ++ deployment/env/authentication_dev.env | 3 ++ deployment/env/certificates_dev.env | 4 +++ deployment/scripts/README.md | 9 ++++++ 7 files changed, 39 insertions(+), 60 deletions(-) delete mode 100644 apps/nifi/docker/openbao_env.sh create mode 100644 deployment/env/authentication_dev.env create mode 100644 deployment/env/certificates_dev.env diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 9ebe4c08..ac5976ee 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -24,11 +24,21 @@ NIFI_WEB_PROXY_HOST=localhost:8443 NIFI_HEALTHCHECK_HOST=nifi ``` -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) +Set `KEYSTORE_PASSWORD` and `TRUSTSTORE_PASSWORD` to match the mounted stores. +Set `SINGLE_USER_CREDENTIALS_USERNAME` and `SINGLE_USER_CREDENTIALS_PASSWORD` +for the NiFi login. Use at least 12 characters for the single-user password. +Use `COGSTACK_NIFI_ENV_FILE` to select another deployment's `nifi.env`. + +The dev Make targets take their sample store passwords and login from +[`certificates_dev.env`](../../deployment/env/certificates_dev.env) and +[`authentication_dev.env`](../../deployment/env/authentication_dev.env). +Set your own values in `nifi.env` to override the samples. + +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. @@ -50,28 +60,6 @@ readable by their container users. The start targets check for readable, nonempty files before launching. Certificate validation occurs when the services connect over TLS. -### OpenBao - -Dev and prod use the same lookup. Set `NIFI_OPENBAO_ADDR` in `nifi.env` to -that deployment’s OpenBao HTTPS endpoint. Set `BAO_CACERT` if its listener -uses a private CA. In KV v2 mounted at `secret`, create the `nifi` entry with -`SINGLE_USER_CREDENTIALS_USERNAME`, `SINGLE_USER_CREDENTIALS_PASSWORD`, -`KEYSTORE_PASSWORD`, and `TRUSTSTORE_PASSWORD`. Use the passwords that open -those stores. Export a `BAO_TOKEN` scoped to read `secret/data/nifi` and run -Make. `curl` and `jq` load the values before Compose starts. When the address -is unset, Make uses the credentials already supplied to Compose. Set -`COGSTACK_NIFI_ENV_FILE` to select a deployment's settings on a shared host. - -For a local persistent server, set `OPENBAO_TLS_DIR` to the absolute path -containing its `tls.crt` and `tls.key`. Run this from `apps/openbao/docker`, -then initialize and unseal via the OpenBao UI or CLI. Set `OPENBAO_HOST_PORT` -if port 8200 is occupied. - -```bash -docker compose --env-file ../env/openbao.env \ - -f docker-compose.base.yml -f docker-compose.server.yml up -d -``` - ### Start and verify Run these commands from `apps/nifi/docker/`: @@ -80,6 +68,7 @@ Run these commands from `apps/nifi/docker/`: | --- | --- | | `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` | Start NiFi and NGINX with the dev settings. | | `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`. | diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index 0ed599f1..be306492 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -3,7 +3,10 @@ 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_DEV := docker compose --env-file ../../../deployment/env/certificates_dev.env \ + --env-file ../../../deployment/env/authentication_dev.env \ + $(if $(wildcard .env),--env-file .env) \ + -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 @@ -19,13 +22,7 @@ for cert in root/root-ca.pem nifi/nifi-{keystore,truststore}.jks nginx/tls.{crt, done; endef -define WITH_START -$(WITH_ENV) $(CHECK_TLS_FILES) \ -if [[ -n "$${NIFI_OPENBAO_ADDR:-}" ]]; then \ - source ./openbao_env.sh && nifi_openbao_env || exit $$?; \ - unset BAO_TOKEN; \ -fi; -endef +WITH_START = $(WITH_ENV) $(CHECK_TLS_FILES) help: ## List available targets with descriptions @echo "Available targets:" diff --git a/apps/nifi/docker/openbao_env.sh b/apps/nifi/docker/openbao_env.sh deleted file mode 100644 index 95d08c8b..00000000 --- a/apps/nifi/docker/openbao_env.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -# Read NiFi's runtime credentials and keystore passwords from OpenBao's -# secret/nifi KV v2 entry, then export them for the Compose startup command. -nifi_openbao_env() { - : "${BAO_TOKEN:?Export BAO_TOKEN in your shell}" - local secret key value - - # Trust the OpenBao server with BAO_CACERT when using a private CA. - if [[ -n ${BAO_CACERT:-} ]]; then set -- --cacert "$BAO_CACERT"; fi - - # Keep the token out of curl's command-line arguments and require HTTPS. - secret=$(curl --proto '=https' --noproxy '*' --fail --silent --show-error \ - --connect-timeout 3 --max-time 10 --header @<(printf 'X-Vault-Token: %s\n' "$BAO_TOKEN") \ - "$@" "${NIFI_OPENBAO_ADDR%/}/v1/secret/data/nifi") || return - - # Fail before Compose starts if any required value is absent or empty. - for key in SINGLE_USER_CREDENTIALS_USERNAME SINGLE_USER_CREDENTIALS_PASSWORD KEYSTORE_PASSWORD TRUSTSTORE_PASSWORD; do - value=$(jq -er --arg key "$key" '.data.data[$key] | strings | select(length > 0)' <<< "$secret") || { - printf 'OpenBao secret/nifi is missing %s.\n' "$key" >&2 - return 1 - } - export "$key=$value" - done -} diff --git a/deployment/.gitignore b/deployment/.gitignore index 45a9af48..40a9649c 100644 --- a/deployment/.gitignore +++ b/deployment/.gitignore @@ -2,6 +2,8 @@ !/env/ /env/* !/env/certificates.env +!/env/certificates_dev.env +!/env/authentication_dev.env !/env/cohorter.env !/env/jupyter.env !/env/ocr_service.env diff --git a/deployment/env/authentication_dev.env b/deployment/env/authentication_dev.env new file mode 100644 index 00000000..e87bb059 --- /dev/null +++ b/deployment/env/authentication_dev.env @@ -0,0 +1,3 @@ +# Sample login for local NiFi development. +NIFI_SINGLE_USER_CREDENTIALS_USERNAME=admin +NIFI_SINGLE_USER_CREDENTIALS_PASSWORD=cogstackNiFi diff --git a/deployment/env/certificates_dev.env b/deployment/env/certificates_dev.env new file mode 100644 index 00000000..bbf53c9b --- /dev/null +++ b/deployment/env/certificates_dev.env @@ -0,0 +1,4 @@ +# Sample passwords for local development certificate stores. +ROOT_CERTIFICATE_KEYSTORE_PASSWORD=cogstackNiFi +NIFI_KEYSTORE_PASSWORD=cogstackNiFi +NIFI_TRUSTSTORE_PASSWORD=cogstackNiFi diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index e432fe85..1a66a5df 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -11,6 +11,15 @@ 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/`. +For local development, load the [sample store passwords](../env/certificates_dev.env) +before running the root CA and NiFi generators. + +```bash +set -a +source deployment/env/certificates_dev.env +set +a +``` + If you need a root CA, export `ROOT_CERTIFICATE_KEYSTORE_PASSWORD` and run this from the repository root. From 5bd44b863c3f2f7647e80a86a33c10222caee1b7 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Tue, 24 Nov 2026 22:35:29 +0000 Subject: [PATCH 21/63] apps/deploy: added OS charts. --- .../config/opensearch.yml | 151 +++++++++++ apps/opensearch/config/opensearch.yml | 244 ++++++++++++++++++ .../charts/opensearch-dashboards/.gitignore | 1 + .../charts/opensearch-dashboards/Chart.lock | 6 + .../charts/opensearch-dashboards/Chart.yaml | 13 + .../charts/opensearch-dashboards/README.md | 24 ++ .../charts/opensearch-dashboards/values.yaml | 2 + deployment/charts/opensearch/.gitignore | 1 + deployment/charts/opensearch/Chart.lock | 6 + deployment/charts/opensearch/Chart.yaml | 13 + deployment/charts/opensearch/README.md | 58 +++++ .../charts/opensearch/ci/ci-values.yaml | 5 + deployment/charts/opensearch/values.yaml | 11 + 13 files changed, 535 insertions(+) create mode 100644 apps/opensearch-dashboards/config/opensearch.yml create mode 100644 apps/opensearch/config/opensearch.yml create mode 100644 deployment/charts/opensearch-dashboards/.gitignore create mode 100644 deployment/charts/opensearch-dashboards/Chart.lock create mode 100644 deployment/charts/opensearch-dashboards/Chart.yaml create mode 100644 deployment/charts/opensearch-dashboards/README.md create mode 100644 deployment/charts/opensearch-dashboards/values.yaml create mode 100644 deployment/charts/opensearch/.gitignore create mode 100644 deployment/charts/opensearch/Chart.lock create mode 100644 deployment/charts/opensearch/Chart.yaml create mode 100644 deployment/charts/opensearch/README.md create mode 100644 deployment/charts/opensearch/ci/ci-values.yaml create mode 100644 deployment/charts/opensearch/values.yaml diff --git a/apps/opensearch-dashboards/config/opensearch.yml b/apps/opensearch-dashboards/config/opensearch.yml new file mode 100644 index 00000000..64113523 --- /dev/null +++ b/apps/opensearch-dashboards/config/opensearch.yml @@ -0,0 +1,151 @@ +# OpenSearch Dashboards is served by a back end server. This setting specifies the port to use. +server.port: 5601 + +# Specifies the address to which the OpenSearch Dashboards server will bind. IP addresses and host names are both valid values. +# The default is 'localhost', which usually means remote machines will not be able to connect. +# To allow connections from remote users, set this parameter to a non-loopback address. +server.host: "0.0.0.0" + +# Enables you to specify a path to mount OpenSearch Dashboards at if you are running behind a proxy. +# Use the `server.rewriteBasePath` setting to tell OpenSearch Dashboards if it should remove the basePath +# from requests it receives, and to prevent a deprecation warning at startup. +# This setting cannot end in a slash. +#server.basePath: "" + +# Specifies whether OpenSearch Dashboards should rewrite requests that are prefixed with +# `server.basePath` or require that they are rewritten by your reverse proxy. +#server.rewriteBasePath: false + +# The maximum payload size in bytes for incoming server requests. +#server.maxPayloadBytes: 1048576 + +# The OpenSearch Dashboards server's name. This is used for display purposes. +server.name: ${KIBANA_SERVER_NAME} + +# The URLs of the OpenSearch instances to use for all your queries. +opensearch.hosts: ${ELASTICSEARCH_HOSTS} + +opensearch_security.multitenancy.enabled: true +opensearch_security.multitenancy.tenants.enable_global: true +opensearch_security.multitenancy.tenants.enable_private: true +opensearch_security.multitenancy.tenants.preferred: ["Global"] +opensearch_security.readonly_mode.roles: ["kibana_read_only"] +opensearch_security.multitenancy.enable_filter: true +opensearch_security.cookie.secure: true + +# OpenSearch Dashboards uses an index in OpenSearch to store saved searches, visualizations and +# dashboards. OpenSearch Dashboards creates a new index if the index doesn't already exist. + +# We changed this from .opensearch_dashboards to .kibana because of a permission bug in OpenSearch Dashboards 2.19.x and 3.0.0 +# report: https://github.com/opensearch-project/security/issues/5360 +opensearchDashboards.index: ".opensearch_dashboards" + +# The default application to load. +#opensearchDashboards.defaultAppId: "home" + +# Setting for an optimized healthcheck that only uses the local OpenSearch node to do Dashboards healthcheck. +# This settings should be used for large clusters or for clusters with ingest heavy nodes. +# It allows Dashboards to only healthcheck using the local OpenSearch node rather than fan out requests across all nodes. +# +# It requires the user to create an OpenSearch node attribute with the same name as the value used in the setting +# This node attribute should assign all nodes of the same cluster an integer value that increments with each new cluster that is spun up +# e.g. in opensearch.yml file you would set the value to a setting using node.attr.cluster_id: +# Should only be enabled if there is a corresponding node attribute created in your OpenSearch config that matches the value here +#opensearch.optimizedHealthcheckId: "cluster_id" + +# If your OpenSearch is protected with basic authentication, these settings provide +# the username and password that the OpenSearch Dashboards server uses to perform maintenance on the OpenSearch Dashboards +# index at startup. Your OpenSearch Dashboards users still need to authenticate with OpenSearch, which +# is proxied through the OpenSearch Dashboards server. +opensearch.username: ${KIBANA_USER} +opensearch.password: ${KIBANA_PASSWORD} + +# Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively. +# These settings enable SSL for outgoing requests from the OpenSearch Dashboards server to the browser. +server.ssl.enabled: true +server.ssl.certificate: "/certificates/elastic/opensearch/es_kibana_client.pem" +server.ssl.key: "/certificates/elastic/opensearch/es_kibana_client.key" + +# Outgoing requests use KIBANA_USER/KIBANA_PASSWORD and verify the server CA. +# Do not send an admin client certificate: that would bypass the service account. + +# Optional setting that enables you to specify a path to the PEM file for the certificate +# authority for your OpenSearch instance. +opensearch.ssl.certificateAuthorities: ["/certificates/elastic/opensearch/elastic-stack-ca.crt.pem"] + +# To disregard the validity of SSL certificates, change this setting's value to 'none'. +opensearch.ssl.verificationMode: full + +# Time in milliseconds to wait for OpenSearch to respond to pings. Defaults to the value of +# the opensearch.requestTimeout setting. +opensearch.pingTimeout: 10000 + +# Time in milliseconds to wait for responses from the back end or OpenSearch. This value +# must be a positive integer. +opensearch.requestTimeout: 420000 + +# List of OpenSearch Dashboards client-side headers to send to OpenSearch. To send *no* client-side +# headers, set this value to [] (an empty list). +opensearch.requestHeadersAllowlist: ["securitytenant", "Authorization"] + +# Header names and values that are sent to OpenSearch. Any custom headers cannot be overwritten +# by client-side headers, regardless of the opensearch.requestHeadersAllowlist configuration. +# opensearch.customHeaders: {} + +# Time in milliseconds for OpenSearch to wait for responses from shards. Set to 0 to disable. +# opensearch.shardTimeout: 30000 + +# Logs queries sent to OpenSearch. Requires logging.verbose set to true. +# opensearch.logQueries: false + +# Specifies the path where OpenSearch Dashboards creates the process ID file. +# pid.file: /var/run/opensearchDashboards.pid + +# Enables you to specify a file where OpenSearch Dashboards stores log output. +# logging.dest: stdout + +# Set the value of this setting to true to suppress all logging output. +# logging.silent: false + +# Set the value of this setting to true to suppress all logging output other than error messages. +# logging.quiet: false + +# Set the value of this setting to true to log all events, including system usage information +# and all requests. +# logging.verbose: false + +# Set the interval in milliseconds to sample system and process performance +# metrics. Minimum is 100ms. Defaults to 5000. +# ops.interval: 5000 + +# Specifies locale to be used for all localizable strings, dates and number formats. +# Supported languages are the following: English - en , by default , Chinese - zh-CN . +# i18n.locale: "en" + +# Set the allowlist to check input graphite Url. Allowlist is the default check list. +#vis_type_timeline.graphiteAllowedUrls: ['https://www.hostedgraphite.com/UID/ACCESS_KEY/graphite'] + +# Set the value of this setting to true to capture region blocked warnings and errors +# for your map rendering services. +# map.showRegionBlockedWarning: false + +# Enable ML Commons model monitoring and management. Model registration and +# deployment are performed through the REST API or the Dashboards Dev Tools UI. +ml_commons_dashboards.enabled: true +assistant.chat.enabled: true +assistant.incontextInsight.enabled: true +assistant.next.enabled: true +assistant.text2viz.enabled: true +observability.query_assist.enabled: true + +savedObjects.permission.enabled: true + +# Set the value to true to enable multiple data source feature +data_source.enabled: false +# Set the value to true to enable workspace feature +workspace.enabled: true +# Set the value to true to enable explore feature +explore.enabled: true + +opensearchDashboards.dashboardAdmin.users: ["admin"] +opensearchDashboards.dashboardAdmin.groups: ["admin","all_access"] diff --git a/apps/opensearch/config/opensearch.yml b/apps/opensearch/config/opensearch.yml new file mode 100644 index 00000000..80cb72eb --- /dev/null +++ b/apps/opensearch/config/opensearch.yml @@ -0,0 +1,244 @@ +network.host: ${ELASTICSEARCH_NETWORK_HOST} +network.publish_host: ${ELASTICSEARCH_NETWORK_PUBLISH_HOST} + +###### CLUSTER CONFIGURATION ###### + +bootstrap.system_call_filter: false + +# To allow multiple nodes add the node"s IP addresses to the discovery pool. +# ["", "", ""] +discovery.seed_hosts: ${ELASTICSEARCH_SEED_HOSTS} +cluster.initial_cluster_manager_nodes: ${ELASTICSEARCH_INITIAL_CLUSTER_MANAGER_NODES} +discovery.type: zen + +# WARNING: revise all the lines below before you go into production +plugins.security.ssl.transport.pemcert_filepath: esnode.crt +plugins.security.ssl.transport.pemkey_filepath: esnode.key +plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.crt +transport.ssl.enforce_hostname_verification: false +#plugins.security.ssl.transport.keystore_filepath: esnode-pcks12.key +#plugins.security.ssl.transport.truststore_filepath: esnode-pcks12.key +plugins.security.ssl.http.enabled: true +plugins.security.ssl.transport.enabled: true +#plugins.security.ssl.http.keystore_type: PKCS12 +plugins.security.ssl.http.pemcert_filepath: esnode.crt +plugins.security.ssl.http.pemkey_filepath: esnode.key +plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.crt +plugins.security.allow_unsafe_democertificates: false +plugins.security.allow_default_init_securityindex: true + +plugins.security.authcz.admin_dn: + - "CN=admin,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - "CN=cogstack,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - "CN=elasticsearch-1,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - "CN=elasticsearch-2,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - "CN=elasticsearch-3,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - CN=admin + - CN=localhost + - CN=nifi + - CN=cogstack + +# IMPORTANT: Make sure you define the CN (Company Name) settings correctly, below you can see they match the server addresses of the containers i.e: elasticsearch-1, elasticsearch-2, +# and also extra patterns defined, these could also be domain names etc. +plugins.security.nodes_dn: + - "CN=cogstack,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - "CN=elasticsearch-1,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - "CN=elasticsearch-2,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - "CN=elasticsearch-3,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + - "CN=nifi" + - "CN=esnode*" + - "CN=localhost" + - "CN=cogstack" + - "CN=elasticsearch" + +plugins.security.enable_snapshot_restore_privilege: true +plugins.security.check_snapshot_restore_write_privileges: true +cluster.routing.allocation.disk.threshold_enabled: true + +plugins.security.ssl.http.clientauth_mode : OPTIONAL + +plugins.security.roles_mapping_resolution: MAPPING_ONLY + +# Keep these values identical on every node. Shared development values are in +# security/env/users_elasticsearch.env; inject deployment-specific values in production. +plugins.security.compliance.salt: ${OPENSEARCH_COMPLIANCE_SALT} +plugins.query.datasources.encryption.masterkey: ${OPENSEARCH_DATASOURCE_MASTER_KEY} + +############## REST Management API configuration settings ############## +# Enable or disable role based access to the REST management API +# Default is that no role is allowed to access the REST management API. +plugins.security.restapi.roles_enabled: ["all_access", "security_rest_api_access"] + +# Disable particular endpoints and their HTTP methods for roles. +# By default all endpoints/methods are allowed. +#plugins.security.restapi.endpoints_disabled..: +# Example: +#plugins.security.restapi.endpoints_disabled.all_access.ACTIONGROUPS: ["PUT","POST","DELETE"] +#plugins.security.restapi.endpoints_disabled.xyz_role.LICENSE: ["DELETE"] + +# The following endpoints exist: +# ACTIONGROUPS +# CACHE +# CONFIG +# ROLES +# ROLESMAPPING +# INTERNALUSERS +# SYSTEMINFO +# PERMISSIONSINFO + +############## Auditlog configuration settings ############## + +# Destination of the auditlog events +plugins.security.audit.type: internal_opensearch +plugins.security.audit.config.http_endpoints: ${ELASTICSEARCH_HOSTS} +plugins.security.audit.config.enable_ssl_client_auth: true + +#plugins.security.audit.enable_rest: false +#plugins.security.audit.enable_transport: false +#plugins.security.audit.config.disabled_rest_categories: NONE +#plugins.security.audit.config.disabled_transport_categories: NONE +#plugins.security.audit.config.index: auditlog6 # make sure you secure this index properly +#plugins.security.audit.config.index: "'auditlog6-'YYYY.MM.dd" #rotates index daily - make sure you secure this index properly +#plugins.security.audit.config.type: auditlog +#plugins.security.audit.config.username: auditloguser +#plugins.security.audit.config.password: auditlogpassword +#plugins.security.audit.config.enable_ssl: false +#plugins.security.audit.config.verify_hostnames: false +#plugins.security.audit.config.cert_alias: mycert +#plugins.security.audit.config.pemkey_filepath: key.pem +#plugins.security.audit.config.pemkey_content: <...pem base 64 content> +#plugins.security.audit.config.pemkey_password: secret +#plugins.security.audit.config.pemcert_filepath: cert.pem +#plugins.security.audit.config.pemcert_content: <...pem base 64 content> +#plugins.security.audit.config.pemtrustedcas_filepath: ca.pem +#plugins.security.audit.config.pemtrustedcas_content: <...pem base 64 content> + +# webhook settings +#plugins.security.audit.config.webhook.url: "http://mywebhook/endpoint" +# One of URL_PARAMETER_GET,URL_PARAMETER_POST,TEXT,JSON,SLACK +#plugins.security.audit.config.webhook.format: JSON +#plugins.security.audit.config.webhook.ssl.verify: false +#plugins.security.audit.config.webhook.ssl.pemtrustedcas_filepath: ca.pem +#plugins.security.audit.config.webhook.ssl.pemtrustedcas_content: <...pem base 64 content> + +# log4j settings +#plugins.security.audit.config.log4j.logger_name: auditlogger +#plugins.security.audit.config.log4j.level: INFO + +############## Kerberos configuration settings ############## +# If Kerberos authentication should be used you have to configure: + +# The Path to the krb5.conf file +# Can be absolute or relative to the OpenSearch config directory +#plugins.security.kerberos.krb5_filepath: '/etc/krb5.conf' + +# The Path to the keytab where the acceptor_principal credentials are stored. +# Must be relative to the OpenSearch config directory +#plugins.security.kerberos.acceptor_keytab_filepath: 'eskeytab.tab' + +# Acceptor (Server) Principal name, must be present in acceptor_keytab_path file +#plugins.security.kerberos.acceptor_principal: 'HTTP/localhost' + + +############## Expert settings ############## +# WARNING: Expert settings, do only use if you know what you are doing +# If you set wrong values here this this could be a security risk +# or make OpenSearch Security stop working + +# Name of the index where .opendistro_security stores its configuration. + +#plugins.security.config_index_name: .opendistro_security + +# This defines the OID of server node certificates +#plugins.security.cert.oid: '1.2.3.4.5.5' + +# This specifies the implementation of org.opensearch.security.transport.InterClusterRequestEvaluator +# that is used to determine inter-cluster request. +# Instances of org.opensearch.security.transport.InterClusterRequestEvaluator must implement a single argument +# constructor that takes an org.opensearch.common.settings.Settings +#plugins.security.cert.intercluster_request_evaluator_class: org.opensearch.security.transport.DefaultInterClusterRequestEvaluator + +# By default, normal users can restore snapshots if they have the priviliges 'cluster:admin/snapshot/restore', +# 'indices:admin/create', and 'indices:data/write/index' for the indices to be restored. +# To disable snapshot restore for normal users set 'plugins.security.enable_snapshot_restore_privilege: false'. +# This makes it so that only snapshot restore requests signed by an admin TLS certificate are accepted. +# A snapshot can only be restored when it does not contain global state and does not restore the '.opendistro_security' index +# If 'plugins.security.check_snapshot_restore_write_privileges: false' is set then the additional indices checks are omitted. +#plugins.security.enable_snapshot_restore_privilege: true +#plugins.security.check_snapshot_restore_write_privileges: true + +# Authentication cache timeout in minutes (A value of 0 disables caching, default is 60) +#plugins.security.cache.ttl_minutes: 60 + +# Disable OpenSearch Security +# WARNING: This can expose your configuration (including passwords) to the public. +#plugins.security.disabled: false + +# Protected indices are even more secure than normal indices. These indices require a role to access like any other index, but they require an additional role +# to be visible, listed in the plugins.security.protected_indices.roles setting. +# Enable protected indices +# plugins.security.protected_indices.enabled: true +# Specify a list of roles a user must be member of to touch any protected index. +# plugins.security.protected_indices.roles: ['all_access'] + +# Bundled plugins register their system indices with OpenSearch. Protect those +# registered indices without the deprecated plugins.security.system_indices.indices list. +# Allow explicit system:admin/system_index role permissions as well as super-admin access. +plugins.security.system_indices.enabled: true +plugins.security.system_indices.permission.enabled: true + +# ================= ML Commons ================= + +plugins.ml_commons.local_model.enabled: true +plugins.ml_commons.remote_inference.enabled: true +plugins.ml_commons.only_run_on_ml_node: false +plugins.ml_commons.allow_registering_model_via_url: true +plugins.ml_commons.allow_registering_model_via_local_file: true +# Permit HTTPS model repositories and only the dedicated read-only local model +# directory; do not allow arbitrary HTTP, FTP, or file-system paths. +plugins.ml_commons.trusted_url_regex: '^https://.*$|^file:///usr/share/opensearch/models/[^?#]+\.zip$' +# Permit ML Commons connectors to call only the Ollama service on the private +# CogStack Docker network. Docker resolves this stable service name to a +# private container IP, so both the general and private endpoint allowlists +# are required by OpenSearch 3.7 and later. +plugins.ml_commons.connector.private_ip_enabled: true +plugins.ml_commons.trusted_connector_endpoints_regex: + - '^http://ollama:11434/.*$' + - '^http://ollama-openai-proxy:11435/.*$' +plugins.ml_commons.trusted_connector_private_endpoints_regex: + - '^http://ollama:11434/.*$' + - '^http://ollama-openai-proxy:11435/.*$' +plugins.ml_commons.model_access_control_enabled: true +plugins.ml_commons.connector_access_control_enabled: true +plugins.ml_commons.safe_delete_model: true +plugins.ml_commons.agent_framework_enabled: true +plugins.ml_commons.rag_pipeline_feature_enabled: true +# Upper bound for asynchronous ML Commons tasks. Remote connector connection +# and response timeouts are configured per connector by opensearch-ai-init.sh. +plugins.ml_commons.ml_task_timeout_in_seconds: 600 + +# This cluster has no dedicated ML nodes, so allow both local and remote models +# to execute on data nodes. +plugins.ml_commons.task_dispatcher.eligible_node_role.local_model: + - data +plugins.ml_commons.task_dispatcher.eligible_node_role.remote_model: + - data + + +# Enable SQL-like queries, allows you to join across indices etc. +plugins.sql.enabled: true +plugins.ppl.enabled: true + +# Calcite (SQL v3 engine) +plugins.calcite.enabled: true +# WARNING: exists only in OpenSearch > 3.4, please DISABLE if you are not on this version as this setting doesn't exist. +plugins.calcite.all_join_types.allowed: true + +# coordinator-level kill switch for searches +search.cancel_after_time_interval: 5m + +# shard-level default timeout (can be overridden per request via "timeout") +search.default_search_timeout: 5m + +# relevant if SQL is paging via PIT +search.default_keep_alive: 10m diff --git a/deployment/charts/opensearch-dashboards/.gitignore b/deployment/charts/opensearch-dashboards/.gitignore new file mode 100644 index 00000000..0ad51707 --- /dev/null +++ b/deployment/charts/opensearch-dashboards/.gitignore @@ -0,0 +1 @@ +/charts/*.tgz diff --git a/deployment/charts/opensearch-dashboards/Chart.lock b/deployment/charts/opensearch-dashboards/Chart.lock new file mode 100644 index 00000000..818c76c0 --- /dev/null +++ b/deployment/charts/opensearch-dashboards/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: opensearch-dashboards + repository: https://opensearch-project.github.io/helm-charts/ + version: 3.9.0 +digest: sha256:d2da97a34837a14000abebae3ec47668d475081d9d8d0ac1ef6f8bbd4cdff9cf +generated: "2026-11-24T22:01:58.231528Z" diff --git a/deployment/charts/opensearch-dashboards/Chart.yaml b/deployment/charts/opensearch-dashboards/Chart.yaml new file mode 100644 index 00000000..8a1baf3e --- /dev/null +++ b/deployment/charts/opensearch-dashboards/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: opensearch-dashboards +description: Standalone OpenSearch Dashboards Helm chart +type: application +version: 0.1.0 + +maintainers: + - name: CogStack + +dependencies: + - name: opensearch-dashboards + version: "3.9.0" + repository: https://opensearch-project.github.io/helm-charts/ diff --git a/deployment/charts/opensearch-dashboards/README.md b/deployment/charts/opensearch-dashboards/README.md new file mode 100644 index 00000000..ad54ee2a --- /dev/null +++ b/deployment/charts/opensearch-dashboards/README.md @@ -0,0 +1,24 @@ +# Standalone OpenSearch Dashboards + +Install this release in the same namespace as [OpenSearch](../opensearch/README.md). +Dashboards connects to the OpenSearch Service and stores its saved objects in +OpenSearch. + +```bash +helm repo add opensearch https://opensearch-project.github.io/helm-charts/ +helm dependency build deployment/charts/opensearch-dashboards +helm upgrade --install opensearch-dashboards deployment/charts/opensearch-dashboards -n search +``` + +Set overrides under `opensearch-dashboards:` in your values file. Prepare the +[imported Compose config](../../../apps/opensearch-dashboards/config/opensearch.yml) +with the Kubernetes endpoint, credentials, and certificate paths before using it. +Use `--set-file` to load a prepared config. + +```bash +helm upgrade --install opensearch-dashboards deployment/charts/opensearch-dashboards -n search \ + --set-file 'opensearch-dashboards.config.opensearch_dashboards\.yml=/path/to/kubernetes/opensearch_dashboards.yml' +``` + +Mount TLS files from a Secret using `opensearch-dashboards.secretMounts`. See the +[upstream values](https://github.com/opensearch-project/helm-charts/blob/main/charts/opensearch-dashboards/values.yaml). diff --git a/deployment/charts/opensearch-dashboards/values.yaml b/deployment/charts/opensearch-dashboards/values.yaml new file mode 100644 index 00000000..c8f6fed5 --- /dev/null +++ b/deployment/charts/opensearch-dashboards/values.yaml @@ -0,0 +1,2 @@ +opensearch-dashboards: + opensearchHosts: https://opensearch-cluster-master:9200 diff --git a/deployment/charts/opensearch/.gitignore b/deployment/charts/opensearch/.gitignore new file mode 100644 index 00000000..0ad51707 --- /dev/null +++ b/deployment/charts/opensearch/.gitignore @@ -0,0 +1 @@ +/charts/*.tgz diff --git a/deployment/charts/opensearch/Chart.lock b/deployment/charts/opensearch/Chart.lock new file mode 100644 index 00000000..ad9ec22a --- /dev/null +++ b/deployment/charts/opensearch/Chart.lock @@ -0,0 +1,6 @@ +dependencies: +- name: opensearch + repository: https://opensearch-project.github.io/helm-charts/ + version: 3.9.0 +digest: sha256:5df49c2ae6f2d24003102623e6b74d44f67c74a5846d9ffe53d12361da52deed +generated: "2026-11-24T22:01:57.799564Z" diff --git a/deployment/charts/opensearch/Chart.yaml b/deployment/charts/opensearch/Chart.yaml new file mode 100644 index 00000000..a56ad989 --- /dev/null +++ b/deployment/charts/opensearch/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: opensearch +description: Standalone OpenSearch Helm chart +type: application +version: 0.1.0 + +maintainers: + - name: CogStack + +dependencies: + - name: opensearch + version: "3.9.0" + repository: https://opensearch-project.github.io/helm-charts/ diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md new file mode 100644 index 00000000..6086602d --- /dev/null +++ b/deployment/charts/opensearch/README.md @@ -0,0 +1,58 @@ +# Standalone OpenSearch + +This chart installs the upstream OpenSearch StatefulSet as its own Helm release. +The upstream chart supplies the Kubernetes templates. Set overrides under +`opensearch:` in your values file. + +## Install + +Run from the repository root. The `opensearch-admin` Secret holds the initial +admin password. Use a file containing just the password, with no trailing +newline. The upstream defaults create three pods with persistent storage. +Check the [cluster prerequisites](https://docs.opensearch.org/latest/opensearch/install/helm/#prerequisites). + +```bash +helm repo add opensearch https://opensearch-project.github.io/helm-charts/ +helm dependency build deployment/charts/opensearch +kubectl create namespace search +kubectl -n search create secret generic opensearch-admin --from-file=password=/path/to/password +helm upgrade --install opensearch deployment/charts/opensearch --namespace search +``` + +From inside the cluster, clients can use +`https://opensearch-cluster-master.search.svc:9200`. + +## Storage + +The StatefulSet creates one 8 GiB PVC per pod and mounts it at +`/usr/share/opensearch/data`. Set `opensearch.persistence.size` and +`opensearch.persistence.storageClass` before installing. The first command +shows the claim template. The second lists claims after installation. + +```bash +helm template opensearch deployment/charts/opensearch -n search \ + --show-only charts/opensearch/templates/statefulset.yaml +kubectl -n search get pvc +``` + +## Configuration and TLS + +The [imported OpenSearch config](../../../apps/opensearch/config/opensearch.yml) +uses the old Compose discovery variables and certificate paths. The default +install uses upstream config and demo certificates. Prepare a Kubernetes config +with the right discovery and TLS settings before using the imported file. + +Pass a prepared file to Helm. The chart creates a ConfigMap and uses it to +populate the file mounted at `/usr/share/opensearch/config/opensearch.yml`. + +```bash +helm upgrade --install opensearch deployment/charts/opensearch -n search \ + --set-file 'opensearch.config.opensearch\.yml=/path/to/kubernetes/opensearch.yml' +``` + +Put TLS keys and certificates in a Kubernetes Secret and mount it using +`opensearch.secretMounts`. Match the PEM paths in the config to the mount. +See the [upstream chart settings](https://github.com/opensearch-project/helm-charts/blob/main/charts/opensearch/README.md). + +Install Dashboards separately using the +[standalone Dashboards chart](../opensearch-dashboards/README.md). diff --git a/deployment/charts/opensearch/ci/ci-values.yaml b/deployment/charts/opensearch/ci/ci-values.yaml new file mode 100644 index 00000000..023d97a4 --- /dev/null +++ b/deployment/charts/opensearch/ci/ci-values.yaml @@ -0,0 +1,5 @@ +opensearch: + replicas: 1 + extraEnvs: + - name: OPENSEARCH_INITIAL_ADMIN_PASSWORD + value: "CogStack-Chart-Test9!" diff --git a/deployment/charts/opensearch/values.yaml b/deployment/charts/opensearch/values.yaml new file mode 100644 index 00000000..e2338333 --- /dev/null +++ b/deployment/charts/opensearch/values.yaml @@ -0,0 +1,11 @@ +opensearch: + # Each StatefulSet pod gets its own claim from the cluster's default StorageClass. + persistence: + enabled: true + size: 8Gi + extraEnvs: + - name: OPENSEARCH_INITIAL_ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: opensearch-admin + key: password From f6724e275f5ab075de94b7813903188ff1f686c9 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Tue, 24 Nov 2026 23:14:08 +0000 Subject: [PATCH 22/63] apps: opensearch/-dashboards updates. --- apps/opensearch-dashboards/.gitignore | 3 + .../config/opensearch.yml | 4 +- .../env/opensearch-dashboards.env | 20 ++ apps/opensearch/.gitignore | 3 + apps/opensearch/config/opensearch.yml | 10 +- apps/opensearch/env/opensearch.env | 200 ++++++++++++++++++ deployment/.gitignore | 2 + deployment/env/opensearch-dashboards.env | 1 + deployment/env/opensearch.env | 1 + 9 files changed, 237 insertions(+), 7 deletions(-) create mode 100644 apps/opensearch-dashboards/.gitignore create mode 100644 apps/opensearch-dashboards/env/opensearch-dashboards.env create mode 100644 apps/opensearch/.gitignore create mode 100644 apps/opensearch/env/opensearch.env create mode 120000 deployment/env/opensearch-dashboards.env create mode 120000 deployment/env/opensearch.env diff --git a/apps/opensearch-dashboards/.gitignore b/apps/opensearch-dashboards/.gitignore new file mode 100644 index 00000000..a05566ac --- /dev/null +++ b/apps/opensearch-dashboards/.gitignore @@ -0,0 +1,3 @@ +!/env/ +/env/* +!/env/opensearch-dashboards.env diff --git a/apps/opensearch-dashboards/config/opensearch.yml b/apps/opensearch-dashboards/config/opensearch.yml index 64113523..a24ca360 100644 --- a/apps/opensearch-dashboards/config/opensearch.yml +++ b/apps/opensearch-dashboards/config/opensearch.yml @@ -20,10 +20,10 @@ server.host: "0.0.0.0" #server.maxPayloadBytes: 1048576 # The OpenSearch Dashboards server's name. This is used for display purposes. -server.name: ${KIBANA_SERVER_NAME} +server.name: ${OPENSEARCH_DASHBOARDS_SERVER_NAME} # The URLs of the OpenSearch instances to use for all your queries. -opensearch.hosts: ${ELASTICSEARCH_HOSTS} +opensearch.hosts: ${OPENSEARCH_HOSTS} opensearch_security.multitenancy.enabled: true opensearch_security.multitenancy.tenants.enable_global: true diff --git a/apps/opensearch-dashboards/env/opensearch-dashboards.env b/apps/opensearch-dashboards/env/opensearch-dashboards.env new file mode 100644 index 00000000..03d23fee --- /dev/null +++ b/apps/opensearch-dashboards/env/opensearch-dashboards.env @@ -0,0 +1,20 @@ +########################################################################## OpenSearch Dashboards Env vars ########################################################################### + +OPENSEARCH_DASHBOARDS_HOST="https://kibana:5601" + +# possible values: +# - opensearch : opensearchproject/opensearch-dashboards:3.9.0 +# the custom cogstack image is always based on the last image of ES native + +OPENSEARCH_DASHBOARDS_DOCKER_IMAGE=opensearchproject/opensearch-dashboards:3.9.0@sha256:256d4cea5928868ac09bca642a0ac8285a2b7e4b7fdd45c4ec06e75a5cf3184c + +OPENSEARCH_DASHBOARDS_SERVER_NAME="cogstack-opensearch-dashboards" +OPENSEARCH_DASHBOARDS_PUBLIC_BASE_URL="https://elasticsearch-1:5601" + +OPENSEARCH_DASHBOARDS_SERVER_HOST="0.0.0.0" +OPENSEARCH_DASHBOARDS_SERVER_OUTPUT_PORT=5601 + +OPENSEARCH_DASHBOARDS_DOCKER_SHM_SIZE=512m +OPENSEARCH_DASHBOARDS_DOCKER_CPU_MIN=1 +OPENSEARCH_DASHBOARDS_DOCKER_CPU_MAX=1 +OPENSEARCH_DASHBOARDS_DOCKER_RAM=1g diff --git a/apps/opensearch/.gitignore b/apps/opensearch/.gitignore new file mode 100644 index 00000000..641f226a --- /dev/null +++ b/apps/opensearch/.gitignore @@ -0,0 +1,3 @@ +!/env/ +/env/* +!/env/opensearch.env diff --git a/apps/opensearch/config/opensearch.yml b/apps/opensearch/config/opensearch.yml index 80cb72eb..080469ee 100644 --- a/apps/opensearch/config/opensearch.yml +++ b/apps/opensearch/config/opensearch.yml @@ -1,5 +1,5 @@ -network.host: ${ELASTICSEARCH_NETWORK_HOST} -network.publish_host: ${ELASTICSEARCH_NETWORK_PUBLISH_HOST} +network.host: ${OPENSEARCH_NETWORK_HOST} +network.publish_host: ${OPENSEARCH_NETWORK_PUBLISH_HOST} ###### CLUSTER CONFIGURATION ###### @@ -7,8 +7,8 @@ bootstrap.system_call_filter: false # To allow multiple nodes add the node"s IP addresses to the discovery pool. # ["", "", ""] -discovery.seed_hosts: ${ELASTICSEARCH_SEED_HOSTS} -cluster.initial_cluster_manager_nodes: ${ELASTICSEARCH_INITIAL_CLUSTER_MANAGER_NODES} +discovery.seed_hosts: ${OPENSEARCH_SEED_HOSTS} +cluster.initial_cluster_manager_nodes: ${OPENSEARCH_INITIAL_CLUSTER_MANAGER_NODES} discovery.type: zen # WARNING: revise all the lines below before you go into production @@ -90,7 +90,7 @@ plugins.security.restapi.roles_enabled: ["all_access", "security_rest_api_access # Destination of the auditlog events plugins.security.audit.type: internal_opensearch -plugins.security.audit.config.http_endpoints: ${ELASTICSEARCH_HOSTS} +plugins.security.audit.config.http_endpoints: ${OPENSEARCH_HOSTS} plugins.security.audit.config.enable_ssl_client_auth: true #plugins.security.audit.enable_rest: false diff --git a/apps/opensearch/env/opensearch.env b/apps/opensearch/env/opensearch.env new file mode 100644 index 00000000..0a4b66c5 --- /dev/null +++ b/apps/opensearch/env/opensearch.env @@ -0,0 +1,200 @@ +# Based on CogStack-NiFi deploy/elasticsearch.env. +# Supply credentials and encryption keys through your private deployment settings. +####################################################################### OpenSearch Env vars ####################################################################### + +# possible values : +# - elasticsearch : docker.elastic.co/elasticsearch/elasticsearch:9.5.2 +# - elasticsearch (custom cogstack image) : cogstacksystems/cogstack-elasticsearch:latest +# - opensearch : opensearchproject/opensearch:3.9.0 +# the custom cogstack image is always based on the last image of ES native + +OPENSEARCH_DOCKER_IMAGE=opensearchproject/opensearch:3.9.0@sha256:3b55f6b6249cfdb92b52ee59adc8a266203ba9ef9f5d82544fad6f1af2f3609e + +OPENSEARCH_LOG_LEVEL=INFO + +OPENSEARCH_SEED_HOSTS=localhost,elasticsearch-2,elasticsearch-1 +OPENSEARCH_INITIAL_CLUSTER_MANAGER_NODES=es01 + + +OPENSEARCH_NETWORK_HOST="0.0.0.0" +OPENSEARCH_NETWORK_PUBLISH_HOST="0.0.0.0" + +OPENSEARCH_NODE_1_OUTPUT_PORT=9200 +OPENSEARCH_NODE_2_OUTPUT_PORT=9201 +OPENSEARCH_NODE_3_OUTPUT_PORT=9202 + +# cluster communication port +OPENSEARCH_NODE_1_COMM_OUTPUT_PORT=9300 +OPENSEARCH_NODE_2_COMM_OUTPUT_PORT=9301 +OPENSEARCH_NODE_3_COMM_OUTPUT_PORT=9302 + +# cluster analyzer port +OPENSEARCH_NODE_1_ANALYZER_OUTPUT_PORT=9600 +OPENSEARCH_NODE_2_ANALYZER_OUTPUT_PORT=9601 +OPENSEARCH_NODE_3_ANALYZER_OUTPUT_PORT=9602 + +# do not change these values unless you want to create new volumes manually in services.yml +# or you have a special case where you need to switch volumes +OPENSEARCH_NODE_1_DATA_VOL_NAME=elasticsearch-vol-1 +OPENSEARCH_NODE_2_DATA_VOL_NAME=elasticsearch-vol-2 +OPENSEARCH_NODE_3_DATA_VOL_NAME=elasticsearch-vol-3 + +# log volumes shared between filebeat and elasticsearch +OPENSEARCH_NODE_1_LOG_VOL_NAME=elasticsearch-vol-log-1 +OPENSEARCH_NODE_2_LOG_VOL_NAME=elasticsearch-vol-log-2 +OPENSEARCH_NODE_3_LOG_VOL_NAME=elasticsearch-vol-log-3 + +# Performance Analyzer volumes (OpenSearch) +OPENSEARCH_NODE_1_PA_VOL_NAME=elasticsearch-vol-performance-analyzer-1 +OPENSEARCH_NODE_2_PA_VOL_NAME=elasticsearch-vol-performance-analyzer-2 +OPENSEARCH_NODE_3_PA_VOL_NAME=elasticsearch-vol-performance-analyzer-3 + +# this is for native ES +# possible values: +# - trial # 30 day trial +# - basic + +OPENSEARCH_LICENSE_TYPE="trial" + +OPENSEARCH_SSL_ENABLED=true + +OPENSEARCH_CLUSTER_NAME="elasticsearch-cogstack-cluster" + +# the node names can be the same as the $ES_INSTANCE_NAME_1 variables set in security/certificates_elasticsearch.env +OPENSEARCH_NODE_1_NAME=es01 +OPENSEARCH_NODE_2_NAME=es02 +OPENSEARCH_NODE_3_NAME=es03 + +# corresponds to "node.attr.rack=" +OPENSEARCH_NODE_ATTR="elastic" + +OPENSEARCH_CORS_ENABLED="true" + +OPENSEARCH_HTTP_PORT=9200 + +# this setting represents the number of CPUS allocated to each cluster. +OPENSEARCH_NODE_PROCESSORS="2" + +OPENSEARCH_BACKUPS_PATH_REPO=["/mnt/es_data_backups","/mnt/es_config_backups"] + +# used for full snapshot backup +# this is the path on the physical drive, not inside the container +OPENSEARCH_BACKUP_PARTITION_FULL=/data/es_snapshot_backups/full_backup + +# this is the path on the physical drive, not inside the container +# used for snapshot backups of configs +OPENSEARCH_BACKUP_PARTITION_CONFIG=/data/es_snapshot_backups/config_backup + +# Security certificates +OPENSEARCH_SECURITY_DIR=../security/certificates/elastic/ + +# MEMORY CONFIG +OPENSEARCH_JAVA_OPTS="-Xms512m -Xmx512m -Des.failure_store_feature_flag_enabled=true --enable-native-access=ALL-UNNAMED" +ES_JAVA_OPTS=$OPENSEARCH_JAVA_OPTS + +OPENSEARCH_DOCKER_CPU_MIN=1 +OPENSEARCH_DOCKER_CPU_MAX=1 +# Leave room beyond the Java heap for direct buffers, native code, and plugins. +# OpenSearch 3.9 exceeds a 1 GiB container limit during plugin initialization. +OPENSEARCH_DOCKER_RAM=2g + +OPENSEARCH_DOCKER_SHM_SIZE=512m + +OPENSEARCH_DOCKER_LOG_SIZE_PER_FILE="1000m" +OPENSEARCH_DOCKER_LOG_NUM_FILES=10 + +# OpenSearch ML Commons bootstrap settings. Connector timeouts are seconds; +# the Dashboards opensearch.requestTimeout setting is milliseconds. +OPENSEARCH_AI_OPENSEARCH_CONTAINER=elasticsearch-1 +# Local development credentials; update these when the OpenSearch admin login +# is rotated or override them when invoking the bootstrap script. +OPENSEARCH_AI_OPENSEARCH_USER=admin +# OPENSEARCH_AI_OPENSEARCH_PASSWORD= +OPENSEARCH_AI_CONNECTION_TIMEOUT_SECONDS=720 +OPENSEARCH_AI_READ_TIMEOUT_SECONDS=1440 +OPENSEARCH_AI_DEPLOY_TIMEOUT_SECONDS=360 +OPENSEARCH_AI_MAX_TOKENS=16384 +OPENSEARCH_AI_UTILITY_MAX_TOKENS=16384 +OPENSEARCH_AI_REASONING_EFFORT=none +# Leave room for discovery, one bounded retry, and result summarization. +OPENSEARCH_AI_CHAT_MAX_ITERATIONS=8 +# Hard cap on rows returned by the chat assistant's executing PPL tool. +OPENSEARCH_AI_PPL_RESULT_LIMIT=100 + +# Stable resource names let scripts/opensearch-ai-init.sh safely find and +# update resources instead of creating duplicates on every run. +OPENSEARCH_AI_CHAT_CONNECTOR_NAME="Ollama Qwen Agent Connector" +OPENSEARCH_AI_CHAT_MODEL_NAME="Qwen 3.5 Ollama Agent Model" +OPENSEARCH_AI_CHAT_AGENT_NAME="Qwen 3.5 Conversational Agent v2" +OPENSEARCH_AI_ROOT_AGENT_NAME="Qwen Dashboards Root Agent" +OPENSEARCH_AI_PPL_CONNECTOR_NAME="Ollama Qwen PPL Connector" +OPENSEARCH_AI_PPL_MODEL_NAME="Qwen 3.5 Ollama PPL Model" +OPENSEARCH_AI_PPL_AGENT_NAME="Qwen PPL Query Assist Agent" +OPENSEARCH_AI_TIME_RANGE_CONNECTOR_NAME="Ollama Qwen Time Range Connector" +OPENSEARCH_AI_TIME_RANGE_MODEL_NAME="Qwen 3.5 Ollama Time Range Model" +OPENSEARCH_AI_TIME_RANGE_AGENT_NAME="Qwen Query Time Range Parser Agent" +OPENSEARCH_AI_UTILITY_CONNECTOR_NAME="Ollama Qwen Dashboards Utility Connector" +OPENSEARCH_AI_UTILITY_MODEL_NAME="Qwen 3.5 Dashboards Utility Model" +OPENSEARCH_AI_AD_CONNECTOR_NAME="Ollama Qwen Anomaly Suggestion Connector" +OPENSEARCH_AI_AD_MODEL_NAME="Qwen 3.5 Anomaly Suggestion Model" +OPENSEARCH_AI_VISUAL_CONNECTOR_NAME="Ollama Qwen Visualization Connector" +OPENSEARCH_AI_VISUAL_MODEL_NAME="Qwen 3.5 Visualization Model" + +# disables swapping, imporving r/w performance (at the expense of RAM) +OPENSEARCH_BOOTSTRAP_MEMORY_LOCK=true + +# system_call_filter | https://en.wikipedia.org/wiki/Seccomp +OPENSEARCH_SYSTEM_CALL_FILTER=false + +####### OpenID Connect (OpenSearch Security) ####### +# Values used by: security/es_roles/opensearch/config.yml (openid_auth_domain) +OPENSEARCH_OPENID_CONNECT_URL="https://keycloak.example.com:8080/auth/realms/master/.well-known/openid-configuration" +OPENSEARCH_OPENID_REQUIRED_AUDIENCE="your-openid-client-id" +OPENSEARCH_OPENID_SUBJECT_KEY="preferred_username" +OPENSEARCH_OPENID_ROLES_KEY="roles" + +####### This section is for AD user authentication ####### + +# example: network.xyz.uk +OPENSEARCH_AD_DOMAIN_NAME="network.xyz.uk" + +# example: "ldap://server1.xyz.uk:389,ldap://server2.xyz.uk:389" +OPENSEARCH_AD_URL="ldap://server1.xyz.uk:389,ldap://server2.xyz.uk:389" + +OPENSEARCH_AD_UNMAPPED_GROUPS_AS_ROLES=true +OPENSEARCH_AD_FOLLOW_REFERRALS=false + +OPENSEARCH_AD_TIMEOUT=60s + + +####### SMTP EMAIL section + +# example Watcher_Email +OPENSEARCH_EMAIL_ACCOUNT_PROFILE="Watcher_Email" + +OPENSEARCH_EMAIL_ACCOUNT_EMAIL_DEFAULTS=info@notifications.cogstack.net + +# example: smtpserver.xyz.uk +OPENSEARCH_EMAIL_SMTP_HOST="smtpserver.xyz.uk" +OPENSEARCH_EMAIL_SMTP_PORT=25 + + +# Other elasticsearch settings, important for indexing etc +OPENSEARCH_QUERY_BOOL_MAX_CLAUSE_COUNT=4096 +OPENSEARCH_INDICES_MEMORY_INDEX_BUFFER_SIZE="25%" + + +########################################################## + +############################################################ Shared Env vars for MetricBeats/Kibana etc ############################################################## + +# please respect the double quotes "" on each address or you may get type errors from Kibana +OPENSEARCH_HOSTS='["https://elasticsearch-1:9200","https://elasticsearch-2:9200"]' + +# You can generate values for the below strings by using openssl rand +# example, in bash: openssl rand -base64 32 +# the keys must be at least 32 characters long + +# xpack.security.encryptionKey: "something_at_least_32_characters" +# OPENSEARCH_XPACK_SECURITY_ENCRYPTION_KEY= + diff --git a/deployment/.gitignore b/deployment/.gitignore index 40a9649c..2e70d787 100644 --- a/deployment/.gitignore +++ b/deployment/.gitignore @@ -6,5 +6,7 @@ !/env/authentication_dev.env !/env/cohorter.env !/env/jupyter.env +!/env/opensearch.env +!/env/opensearch-dashboards.env !/env/ocr_service.env !/env/ocr_service_text_only.env diff --git a/deployment/env/opensearch-dashboards.env b/deployment/env/opensearch-dashboards.env new file mode 120000 index 00000000..fbe3d735 --- /dev/null +++ b/deployment/env/opensearch-dashboards.env @@ -0,0 +1 @@ +../../apps/opensearch-dashboards/env/opensearch-dashboards.env \ No newline at end of file diff --git a/deployment/env/opensearch.env b/deployment/env/opensearch.env new file mode 120000 index 00000000..3ddb229e --- /dev/null +++ b/deployment/env/opensearch.env @@ -0,0 +1 @@ +../../apps/opensearch/env/opensearch.env \ No newline at end of file From e8fd33954f54be083aa390c02385ea6f34a02b61 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 09:08:37 +0000 Subject: [PATCH 23/63] opensearch deployment + cert settings/scripts. --- apps/opensearch/config/opensearch.yml | 245 +----------------- apps/opensearch/env/opensearch.env | 5 +- deployment/Makefile | 29 +++ deployment/charts/opensearch/README.md | 27 ++ deployment/charts/opensearch/values-k3s.yaml | 27 ++ deployment/scripts/README.md | 2 +- .../create_opensearch_client_admin_certs.sh | 57 ++-- .../security/create_opensearch_node_cert.sh | 16 +- 8 files changed, 132 insertions(+), 276 deletions(-) mode change 100644 => 120000 apps/opensearch/config/opensearch.yml create mode 100644 deployment/charts/opensearch/values-k3s.yaml diff --git a/apps/opensearch/config/opensearch.yml b/apps/opensearch/config/opensearch.yml deleted file mode 100644 index 080469ee..00000000 --- a/apps/opensearch/config/opensearch.yml +++ /dev/null @@ -1,244 +0,0 @@ -network.host: ${OPENSEARCH_NETWORK_HOST} -network.publish_host: ${OPENSEARCH_NETWORK_PUBLISH_HOST} - -###### CLUSTER CONFIGURATION ###### - -bootstrap.system_call_filter: false - -# To allow multiple nodes add the node"s IP addresses to the discovery pool. -# ["", "", ""] -discovery.seed_hosts: ${OPENSEARCH_SEED_HOSTS} -cluster.initial_cluster_manager_nodes: ${OPENSEARCH_INITIAL_CLUSTER_MANAGER_NODES} -discovery.type: zen - -# WARNING: revise all the lines below before you go into production -plugins.security.ssl.transport.pemcert_filepath: esnode.crt -plugins.security.ssl.transport.pemkey_filepath: esnode.key -plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.crt -transport.ssl.enforce_hostname_verification: false -#plugins.security.ssl.transport.keystore_filepath: esnode-pcks12.key -#plugins.security.ssl.transport.truststore_filepath: esnode-pcks12.key -plugins.security.ssl.http.enabled: true -plugins.security.ssl.transport.enabled: true -#plugins.security.ssl.http.keystore_type: PKCS12 -plugins.security.ssl.http.pemcert_filepath: esnode.crt -plugins.security.ssl.http.pemkey_filepath: esnode.key -plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.crt -plugins.security.allow_unsafe_democertificates: false -plugins.security.allow_default_init_securityindex: true - -plugins.security.authcz.admin_dn: - - "CN=admin,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - "CN=cogstack,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - "CN=elasticsearch-1,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - "CN=elasticsearch-2,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - "CN=elasticsearch-3,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - CN=admin - - CN=localhost - - CN=nifi - - CN=cogstack - -# IMPORTANT: Make sure you define the CN (Company Name) settings correctly, below you can see they match the server addresses of the containers i.e: elasticsearch-1, elasticsearch-2, -# and also extra patterns defined, these could also be domain names etc. -plugins.security.nodes_dn: - - "CN=cogstack,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - "CN=elasticsearch-1,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - "CN=elasticsearch-2,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - "CN=elasticsearch-3,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" - - "CN=nifi" - - "CN=esnode*" - - "CN=localhost" - - "CN=cogstack" - - "CN=elasticsearch" - -plugins.security.enable_snapshot_restore_privilege: true -plugins.security.check_snapshot_restore_write_privileges: true -cluster.routing.allocation.disk.threshold_enabled: true - -plugins.security.ssl.http.clientauth_mode : OPTIONAL - -plugins.security.roles_mapping_resolution: MAPPING_ONLY - -# Keep these values identical on every node. Shared development values are in -# security/env/users_elasticsearch.env; inject deployment-specific values in production. -plugins.security.compliance.salt: ${OPENSEARCH_COMPLIANCE_SALT} -plugins.query.datasources.encryption.masterkey: ${OPENSEARCH_DATASOURCE_MASTER_KEY} - -############## REST Management API configuration settings ############## -# Enable or disable role based access to the REST management API -# Default is that no role is allowed to access the REST management API. -plugins.security.restapi.roles_enabled: ["all_access", "security_rest_api_access"] - -# Disable particular endpoints and their HTTP methods for roles. -# By default all endpoints/methods are allowed. -#plugins.security.restapi.endpoints_disabled..: -# Example: -#plugins.security.restapi.endpoints_disabled.all_access.ACTIONGROUPS: ["PUT","POST","DELETE"] -#plugins.security.restapi.endpoints_disabled.xyz_role.LICENSE: ["DELETE"] - -# The following endpoints exist: -# ACTIONGROUPS -# CACHE -# CONFIG -# ROLES -# ROLESMAPPING -# INTERNALUSERS -# SYSTEMINFO -# PERMISSIONSINFO - -############## Auditlog configuration settings ############## - -# Destination of the auditlog events -plugins.security.audit.type: internal_opensearch -plugins.security.audit.config.http_endpoints: ${OPENSEARCH_HOSTS} -plugins.security.audit.config.enable_ssl_client_auth: true - -#plugins.security.audit.enable_rest: false -#plugins.security.audit.enable_transport: false -#plugins.security.audit.config.disabled_rest_categories: NONE -#plugins.security.audit.config.disabled_transport_categories: NONE -#plugins.security.audit.config.index: auditlog6 # make sure you secure this index properly -#plugins.security.audit.config.index: "'auditlog6-'YYYY.MM.dd" #rotates index daily - make sure you secure this index properly -#plugins.security.audit.config.type: auditlog -#plugins.security.audit.config.username: auditloguser -#plugins.security.audit.config.password: auditlogpassword -#plugins.security.audit.config.enable_ssl: false -#plugins.security.audit.config.verify_hostnames: false -#plugins.security.audit.config.cert_alias: mycert -#plugins.security.audit.config.pemkey_filepath: key.pem -#plugins.security.audit.config.pemkey_content: <...pem base 64 content> -#plugins.security.audit.config.pemkey_password: secret -#plugins.security.audit.config.pemcert_filepath: cert.pem -#plugins.security.audit.config.pemcert_content: <...pem base 64 content> -#plugins.security.audit.config.pemtrustedcas_filepath: ca.pem -#plugins.security.audit.config.pemtrustedcas_content: <...pem base 64 content> - -# webhook settings -#plugins.security.audit.config.webhook.url: "http://mywebhook/endpoint" -# One of URL_PARAMETER_GET,URL_PARAMETER_POST,TEXT,JSON,SLACK -#plugins.security.audit.config.webhook.format: JSON -#plugins.security.audit.config.webhook.ssl.verify: false -#plugins.security.audit.config.webhook.ssl.pemtrustedcas_filepath: ca.pem -#plugins.security.audit.config.webhook.ssl.pemtrustedcas_content: <...pem base 64 content> - -# log4j settings -#plugins.security.audit.config.log4j.logger_name: auditlogger -#plugins.security.audit.config.log4j.level: INFO - -############## Kerberos configuration settings ############## -# If Kerberos authentication should be used you have to configure: - -# The Path to the krb5.conf file -# Can be absolute or relative to the OpenSearch config directory -#plugins.security.kerberos.krb5_filepath: '/etc/krb5.conf' - -# The Path to the keytab where the acceptor_principal credentials are stored. -# Must be relative to the OpenSearch config directory -#plugins.security.kerberos.acceptor_keytab_filepath: 'eskeytab.tab' - -# Acceptor (Server) Principal name, must be present in acceptor_keytab_path file -#plugins.security.kerberos.acceptor_principal: 'HTTP/localhost' - - -############## Expert settings ############## -# WARNING: Expert settings, do only use if you know what you are doing -# If you set wrong values here this this could be a security risk -# or make OpenSearch Security stop working - -# Name of the index where .opendistro_security stores its configuration. - -#plugins.security.config_index_name: .opendistro_security - -# This defines the OID of server node certificates -#plugins.security.cert.oid: '1.2.3.4.5.5' - -# This specifies the implementation of org.opensearch.security.transport.InterClusterRequestEvaluator -# that is used to determine inter-cluster request. -# Instances of org.opensearch.security.transport.InterClusterRequestEvaluator must implement a single argument -# constructor that takes an org.opensearch.common.settings.Settings -#plugins.security.cert.intercluster_request_evaluator_class: org.opensearch.security.transport.DefaultInterClusterRequestEvaluator - -# By default, normal users can restore snapshots if they have the priviliges 'cluster:admin/snapshot/restore', -# 'indices:admin/create', and 'indices:data/write/index' for the indices to be restored. -# To disable snapshot restore for normal users set 'plugins.security.enable_snapshot_restore_privilege: false'. -# This makes it so that only snapshot restore requests signed by an admin TLS certificate are accepted. -# A snapshot can only be restored when it does not contain global state and does not restore the '.opendistro_security' index -# If 'plugins.security.check_snapshot_restore_write_privileges: false' is set then the additional indices checks are omitted. -#plugins.security.enable_snapshot_restore_privilege: true -#plugins.security.check_snapshot_restore_write_privileges: true - -# Authentication cache timeout in minutes (A value of 0 disables caching, default is 60) -#plugins.security.cache.ttl_minutes: 60 - -# Disable OpenSearch Security -# WARNING: This can expose your configuration (including passwords) to the public. -#plugins.security.disabled: false - -# Protected indices are even more secure than normal indices. These indices require a role to access like any other index, but they require an additional role -# to be visible, listed in the plugins.security.protected_indices.roles setting. -# Enable protected indices -# plugins.security.protected_indices.enabled: true -# Specify a list of roles a user must be member of to touch any protected index. -# plugins.security.protected_indices.roles: ['all_access'] - -# Bundled plugins register their system indices with OpenSearch. Protect those -# registered indices without the deprecated plugins.security.system_indices.indices list. -# Allow explicit system:admin/system_index role permissions as well as super-admin access. -plugins.security.system_indices.enabled: true -plugins.security.system_indices.permission.enabled: true - -# ================= ML Commons ================= - -plugins.ml_commons.local_model.enabled: true -plugins.ml_commons.remote_inference.enabled: true -plugins.ml_commons.only_run_on_ml_node: false -plugins.ml_commons.allow_registering_model_via_url: true -plugins.ml_commons.allow_registering_model_via_local_file: true -# Permit HTTPS model repositories and only the dedicated read-only local model -# directory; do not allow arbitrary HTTP, FTP, or file-system paths. -plugins.ml_commons.trusted_url_regex: '^https://.*$|^file:///usr/share/opensearch/models/[^?#]+\.zip$' -# Permit ML Commons connectors to call only the Ollama service on the private -# CogStack Docker network. Docker resolves this stable service name to a -# private container IP, so both the general and private endpoint allowlists -# are required by OpenSearch 3.7 and later. -plugins.ml_commons.connector.private_ip_enabled: true -plugins.ml_commons.trusted_connector_endpoints_regex: - - '^http://ollama:11434/.*$' - - '^http://ollama-openai-proxy:11435/.*$' -plugins.ml_commons.trusted_connector_private_endpoints_regex: - - '^http://ollama:11434/.*$' - - '^http://ollama-openai-proxy:11435/.*$' -plugins.ml_commons.model_access_control_enabled: true -plugins.ml_commons.connector_access_control_enabled: true -plugins.ml_commons.safe_delete_model: true -plugins.ml_commons.agent_framework_enabled: true -plugins.ml_commons.rag_pipeline_feature_enabled: true -# Upper bound for asynchronous ML Commons tasks. Remote connector connection -# and response timeouts are configured per connector by opensearch-ai-init.sh. -plugins.ml_commons.ml_task_timeout_in_seconds: 600 - -# This cluster has no dedicated ML nodes, so allow both local and remote models -# to execute on data nodes. -plugins.ml_commons.task_dispatcher.eligible_node_role.local_model: - - data -plugins.ml_commons.task_dispatcher.eligible_node_role.remote_model: - - data - - -# Enable SQL-like queries, allows you to join across indices etc. -plugins.sql.enabled: true -plugins.ppl.enabled: true - -# Calcite (SQL v3 engine) -plugins.calcite.enabled: true -# WARNING: exists only in OpenSearch > 3.4, please DISABLE if you are not on this version as this setting doesn't exist. -plugins.calcite.all_join_types.allowed: true - -# coordinator-level kill switch for searches -search.cancel_after_time_interval: 5m - -# shard-level default timeout (can be overridden per request via "timeout") -search.default_search_timeout: 5m - -# relevant if SQL is paging via PIT -search.default_keep_alive: 10m diff --git a/apps/opensearch/config/opensearch.yml b/apps/opensearch/config/opensearch.yml new file mode 120000 index 00000000..a59db608 --- /dev/null +++ b/apps/opensearch/config/opensearch.yml @@ -0,0 +1 @@ +../../../deployment/charts/opensearch/templates/_opensearch.yml \ No newline at end of file diff --git a/apps/opensearch/env/opensearch.env b/apps/opensearch/env/opensearch.env index 0a4b66c5..5ec1fedf 100644 --- a/apps/opensearch/env/opensearch.env +++ b/apps/opensearch/env/opensearch.env @@ -57,10 +57,11 @@ OPENSEARCH_NODE_3_PA_VOL_NAME=elasticsearch-vol-performance-analyzer-3 OPENSEARCH_LICENSE_TYPE="trial" OPENSEARCH_SSL_ENABLED=true +OPENSEARCH_ALLOW_DEFAULT_INIT_SECURITYINDEX=true OPENSEARCH_CLUSTER_NAME="elasticsearch-cogstack-cluster" -# the node names can be the same as the $ES_INSTANCE_NAME_1 variables set in security/certificates_elasticsearch.env +# Match the node names to the hostnames passed to the certificate generator. OPENSEARCH_NODE_1_NAME=es01 OPENSEARCH_NODE_2_NAME=es02 OPENSEARCH_NODE_3_NAME=es03 @@ -90,7 +91,7 @@ OPENSEARCH_SECURITY_DIR=../security/certificates/elastic/ # MEMORY CONFIG OPENSEARCH_JAVA_OPTS="-Xms512m -Xmx512m -Des.failure_store_feature_flag_enabled=true --enable-native-access=ALL-UNNAMED" -ES_JAVA_OPTS=$OPENSEARCH_JAVA_OPTS +OS_JAVA_OPTS=$OPENSEARCH_JAVA_OPTS OPENSEARCH_DOCKER_CPU_MIN=1 OPENSEARCH_DOCKER_CPU_MAX=1 diff --git a/deployment/Makefile b/deployment/Makefile index 00b09c69..f6f5609c 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -16,6 +16,35 @@ setup-verify: ## Check local Docker, Docker Compose, and K3s access without sudo bash scripts/installation_utils/verify_docker.sh bash scripts/installation_utils/verify_k3s.sh +# ====================================================================================================================================================== + +.PHONY: certs certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-nodes + +certs: certs-root ## Generate the root CA and NiFi and NGINX certificates + $(MAKE) certs-nifi certs-nginx + +certs-root: ## Generate the root CA bundle + bash scripts/security/create_root_ca_cert.sh + +certs-nifi: ## Generate the NiFi certificate and stores with the existing CA + bash scripts/security/create_nifi_certs.sh + +certs-nginx: ## Generate the NGINX certificate with the existing CA + bash scripts/security/create_nginx_certs.sh + +certs-opensearch: ## Generate the shared OpenSearch node and admin client certificates + @service=opensearch-cluster-master; \ + service_dns="$$service.$${KUBE_NAMESPACE:-search}.svc"; \ + $(MAKE) certs-opensearch-nodes NODES=opensearch-shared \ + OPENSEARCH_NODE_DNS_NAMES="$${OPENSEARCH_NODE_DNS_NAMES:-localhost,$$service,$$service_dns,$$service_dns.$${CLUSTER_DOMAIN:-cluster.local}}" + bash scripts/security/create_opensearch_client_admin_certs.sh --admin-only + +certs-opensearch-nodes: ## Generate OpenSearch node certificates for NODES="node1 node2 ..." + @read -r -a nodes <<< "$$NODES"; \ + bash scripts/security/create_opensearch_node_cert.sh "$${nodes[@]}" + +# ====================================================================================================================================================== + help: ## Show deployment commands @printf '%s\n' 'Deployment commands' @awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[[:alnum:]_-]+$$/ { printf " %-30s %s\n", $$1, $$2 }' "$(lastword $(MAKEFILE_LIST))" diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index 6086602d..f576fdeb 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -37,6 +37,33 @@ kubectl -n search get pvc ## Configuration and TLS +### K3s with a shared node certificate + +Build the chart dependency as shown in Install. With an existing CA and +`OS_CERTIFICATE_PASSWORD` exported, generate the shared node and separate admin +client certificates. Use an absolute `SECURITY_DIR` for a custom output location. + +```bash +make -C deployment certs-opensearch +certs="${SECURITY_DIR:-deployment/security}/certificates/opensearch" +kubectl create namespace search +kubectl -n search create secret generic opensearch-node-tls \ + --from-file=node.crt="$certs/opensearch-shared.crt" \ + --from-file=node.key="$certs/opensearch-shared.key" \ + --from-file=ca.crt="$certs/elastic-stack-ca.crt.pem" +helm upgrade --install opensearch deployment/charts/opensearch -n search \ + -f deployment/charts/opensearch/values-k3s.yaml +``` + +The K3s profile checks the CA and shared node DN on transport connections and +disables transport hostname verification. Set `KUBE_NAMESPACE` or `CLUSTER_DOMAIN` +when issuing the certificate if either differs from `search` or `cluster.local`. +For a fresh cluster, initialize the Security index with your Security plugin +configuration and the local `admin.crt` and `admin.key.pem`. +[`securityadmin.sh` instructions](https://docs.opensearch.org/latest/security/configuration/security-admin/) + +### Custom values + The [imported OpenSearch config](../../../apps/opensearch/config/opensearch.yml) uses the old Compose discovery variables and certificate paths. The default install uses upstream config and demo certificates. Prepare a Kubernetes config diff --git a/deployment/charts/opensearch/values-k3s.yaml b/deployment/charts/opensearch/values-k3s.yaml new file mode 100644 index 00000000..61ede916 --- /dev/null +++ b/deployment/charts/opensearch/values-k3s.yaml @@ -0,0 +1,27 @@ +opensearch: + extraEnvs: + - name: DISABLE_INSTALL_DEMO_CONFIG + value: "true" + secretMounts: + - name: node-tls + secretName: opensearch-node-tls + path: /usr/share/opensearch/config/tls + defaultMode: 0440 + config: + opensearch.yml: | + cluster.name: opensearch-cluster + network.host: 0.0.0.0 + transport.ssl.enforce_hostname_verification: false + plugins.security.ssl.transport.pemcert_filepath: tls/node.crt + plugins.security.ssl.transport.pemkey_filepath: tls/node.key + plugins.security.ssl.transport.pemtrustedcas_filepath: tls/ca.crt + plugins.security.ssl.http.enabled: true + plugins.security.ssl.http.pemcert_filepath: tls/node.crt + plugins.security.ssl.http.pemkey_filepath: tls/node.key + plugins.security.ssl.http.pemtrustedcas_filepath: tls/ca.crt + plugins.security.ssl.http.clientauth_mode: OPTIONAL + plugins.security.allow_unsafe_democertificates: false + plugins.security.nodes_dn: + - 'CN=opensearch-shared,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK' + plugins.security.authcz.admin_dn: + - 'CN=admin,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK' diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index 1a66a5df..2b200931 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -76,7 +76,7 @@ It runs without a store password or `keytool`. ### OpenSearch -Export `ES_CERTIFICATE_PASSWORD` for the Java and PKCS#12 stores. Pass the node +Export `OS_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. diff --git a/deployment/scripts/security/create_opensearch_client_admin_certs.sh b/deployment/scripts/security/create_opensearch_client_admin_certs.sh index 8870836a..ea8a6f74 100755 --- a/deployment/scripts/security/create_opensearch_client_admin_certs.sh +++ b/deployment/scripts/security/create_opensearch_client_admin_certs.sh @@ -4,12 +4,13 @@ # 🔐 Create the OpenSearch Dashboards and admin certificates and keys # # Usage: -# ./create_opensearch_client_admin_certs.sh [--days DAYS] +# ./create_opensearch_client_admin_certs.sh [--admin-only] [--days DAYS] +# --admin-only skips the Dashboards certificate and PKCS#12 bundle. # 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 +# - OS_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: @@ -31,17 +32,19 @@ set -euo pipefail umask 077 days=1460 +create_dashboards=true +if [[ ${1:-} == --admin-only ]]; then + create_dashboards=false + shift +fi 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 + printf 'Usage: %s [--admin-only] [--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" @@ -55,18 +58,26 @@ for input in "$ca_cert" "$ca_key"; do 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 +roles=(admin) +files=(admin.crt admin.key.pem admin.csr) +if [[ "$create_dashboards" == true ]]; then + : "${OS_CERTIFICATE_PASSWORD:?Set OS_CERTIFICATE_PASSWORD}" + export OS_CERTIFICATE_PASSWORD + roles=(client admin) + files=(es_kibana_client.pem es_kibana_client.key es_kibana_client.csr es_kibana_client.p12 "${files[@]}") + + 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 - 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 @@ -88,7 +99,7 @@ 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 +for role in "${roles[@]}"; do if [[ "$role" == client ]]; then key=es_kibana_client.key csr=es_kibana_client.csr @@ -111,9 +122,11 @@ for role in client admin; do 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 +if [[ "$create_dashboards" == true ]]; then + 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:OS_CERTIFICATE_PASSWORD +fi (umask 022; mkdir -p -- "$output_dir") set -o noclobber @@ -122,6 +135,8 @@ for file in "${files[@]}"; do published+=("$output_dir/$file") cat -- "$scratch_dir/$file" } > "$output_dir/$file" + case "$file" in + *.crt|*.csr|es_kibana_client.pem) chmod 644 "$output_dir/$file" ;; + esac 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" +printf 'Created OpenSearch client 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 index d416bbeb..543939f0 100755 --- a/deployment/scripts/security/create_opensearch_node_cert.sh +++ b/deployment/scripts/security/create_opensearch_node_cert.sh @@ -8,7 +8,7 @@ # # Requires: # - Bash, OpenSSL and Java keytool -# - ES_CERTIFICATE_PASSWORD for the PKCS#12 bundle and Java stores +# - OS_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: @@ -92,8 +92,8 @@ for node in "$@"; do done done -: "${ES_CERTIFICATE_PASSWORD:?Set ES_CERTIFICATE_PASSWORD}" -export ES_CERTIFICATE_PASSWORD +: "${OS_CERTIFICATE_PASSWORD:?Set OS_CERTIFICATE_PASSWORD}" +export OS_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 @@ -150,15 +150,15 @@ for node in "$@"; do # 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 + -passout env:OS_CERTIFICATE_PASSWORD keytool -importkeystore -noprompt -alias "$node" \ - -srckeystore "$stage.p12" -srcstoretype PKCS12 -srcstorepass:env ES_CERTIFICATE_PASSWORD \ + -srckeystore "$stage.p12" -srcstoretype PKCS12 -srcstorepass:env OS_CERTIFICATE_PASSWORD \ -destkeystore "$stage-keystore.jks" -deststoretype JKS \ - -deststorepass:env ES_CERTIFICATE_PASSWORD -destkeypass:env ES_CERTIFICATE_PASSWORD + -deststorepass:env OS_CERTIFICATE_PASSWORD -destkeypass:env OS_CERTIFICATE_PASSWORD keytool -importcert -noprompt -alias root-ca -file "$ca_cert" \ - -keystore "$stage-keystore.jks" -storetype JKS -storepass:env ES_CERTIFICATE_PASSWORD + -keystore "$stage-keystore.jks" -storetype JKS -storepass:env OS_CERTIFICATE_PASSWORD keytool -importcert -noprompt -alias "$node" -file "$stage.crt" \ - -keystore "$stage-truststore.key" -storetype JKS -storepass:env ES_CERTIFICATE_PASSWORD + -keystore "$stage-truststore.key" -storetype JKS -storepass:env OS_CERTIFICATE_PASSWORD done # Private files inherit mode 0600, and noclobber protects concurrent writes. From f893e5c875da4d37e7e5b2b8986cc6a0792f73d2 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 09:15:14 +0000 Subject: [PATCH 24/63] Opensearch charts. --- .github/workflows/build_helm_charts.yml | 2 + apps/opensearch/config/opensearch.yml | 222 +++++++++++++++++- deployment/charts/opensearch/README.md | 69 +++--- .../charts/opensearch/ci/ci-values.yaml | 1 + .../charts/opensearch/config/opensearch.yml | 1 + deployment/charts/opensearch/values-k3s.yaml | 27 --- deployment/charts/opensearch/values.yaml | 13 +- 7 files changed, 266 insertions(+), 69 deletions(-) mode change 120000 => 100644 apps/opensearch/config/opensearch.yml create mode 120000 deployment/charts/opensearch/config/opensearch.yml delete mode 100644 deployment/charts/opensearch/values-k3s.yaml diff --git a/.github/workflows/build_helm_charts.yml b/.github/workflows/build_helm_charts.yml index 2b515fb9..f165e5e5 100644 --- a/.github/workflows/build_helm_charts.yml +++ b/.github/workflows/build_helm_charts.yml @@ -21,10 +21,12 @@ on: - "helm-charts/*-v*.*.*" # e.g., helm-charts/medcat-trainer-helm-v0.1.2 paths: - "deployment/charts/**" + - "apps/opensearch/config/opensearch.yml" - ".github/workflows/build_helm_charts.yml" pull_request: paths: - "deployment/charts/**" + - "apps/opensearch/config/opensearch.yml" - ".github/workflows/build_helm_charts.yml" defaults: diff --git a/apps/opensearch/config/opensearch.yml b/apps/opensearch/config/opensearch.yml deleted file mode 120000 index a59db608..00000000 --- a/apps/opensearch/config/opensearch.yml +++ /dev/null @@ -1 +0,0 @@ -../../../deployment/charts/opensearch/templates/_opensearch.yml \ No newline at end of file diff --git a/apps/opensearch/config/opensearch.yml b/apps/opensearch/config/opensearch.yml new file mode 100644 index 00000000..dde30ff7 --- /dev/null +++ b/apps/opensearch/config/opensearch.yml @@ -0,0 +1,221 @@ +network.host: '${OPENSEARCH_NETWORK_HOST:0.0.0.0}' +network.publish_host: '${OPENSEARCH_NETWORK_PUBLISH_HOST:}' + +###### CLUSTER CONFIGURATION ###### + +bootstrap.system_call_filter: '${OPENSEARCH_SYSTEM_CALL_FILTER:true}' + +# Docker supplies these settings through its environment. Helm supplies the +# Kubernetes discovery settings through the StatefulSet. +discovery.seed_hosts: '${OPENSEARCH_SEED_HOSTS:}' +cluster.initial_cluster_manager_nodes: '${OPENSEARCH_INITIAL_CLUSTER_MANAGER_NODES:}' +discovery.type: zen + +plugins.security.ssl.transport.pemcert_filepath: tls/node.crt +plugins.security.ssl.transport.pemkey_filepath: tls/node.key +plugins.security.ssl.transport.pemtrustedcas_filepath: tls/ca.crt +transport.ssl.enforce_hostname_verification: false +plugins.security.ssl.http.enabled: true +plugins.security.ssl.transport.enabled: true +plugins.security.ssl.http.pemcert_filepath: tls/node.crt +plugins.security.ssl.http.pemkey_filepath: tls/node.key +plugins.security.ssl.http.pemtrustedcas_filepath: tls/ca.crt +plugins.security.allow_unsafe_democertificates: false +plugins.security.allow_default_init_securityindex: '${OPENSEARCH_ALLOW_DEFAULT_INIT_SECURITYINDEX:false}' + +plugins.security.authcz.admin_dn: + - "CN=admin,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + +plugins.security.nodes_dn: + - "CN=opensearch-shared,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK" + +plugins.security.enable_snapshot_restore_privilege: true +plugins.security.check_snapshot_restore_write_privileges: true +cluster.routing.allocation.disk.threshold_enabled: true + +plugins.security.ssl.http.clientauth_mode : OPTIONAL + +plugins.security.roles_mapping_resolution: MAPPING_ONLY + +# Supply deployment-specific values on every node when using these features. +plugins.security.compliance.salt: '${OPENSEARCH_COMPLIANCE_SALT:}' +plugins.query.datasources.encryption.masterkey: '${OPENSEARCH_DATASOURCE_MASTER_KEY:}' + +############## REST Management API configuration settings ############## +# Enable or disable role based access to the REST management API +# Default is that no role is allowed to access the REST management API. +plugins.security.restapi.roles_enabled: ["all_access", "security_rest_api_access"] + +# Disable particular endpoints and their HTTP methods for roles. +# By default all endpoints/methods are allowed. +#plugins.security.restapi.endpoints_disabled..: +# Example: +#plugins.security.restapi.endpoints_disabled.all_access.ACTIONGROUPS: ["PUT","POST","DELETE"] +#plugins.security.restapi.endpoints_disabled.xyz_role.LICENSE: ["DELETE"] + +# The following endpoints exist: +# ACTIONGROUPS +# CACHE +# CONFIG +# ROLES +# ROLESMAPPING +# INTERNALUSERS +# SYSTEMINFO +# PERMISSIONSINFO + +############## Auditlog configuration settings ############## + +# Destination of the auditlog events +plugins.security.audit.type: internal_opensearch +plugins.security.audit.config.http_endpoints: '${OPENSEARCH_HOSTS:}' +plugins.security.audit.config.enable_ssl_client_auth: true + +#plugins.security.audit.enable_rest: false +#plugins.security.audit.enable_transport: false +#plugins.security.audit.config.disabled_rest_categories: NONE +#plugins.security.audit.config.disabled_transport_categories: NONE +#plugins.security.audit.config.index: auditlog6 # make sure you secure this index properly +#plugins.security.audit.config.index: "'auditlog6-'YYYY.MM.dd" #rotates index daily - make sure you secure this index properly +#plugins.security.audit.config.type: auditlog +#plugins.security.audit.config.username: auditloguser +#plugins.security.audit.config.password: auditlogpassword +#plugins.security.audit.config.enable_ssl: false +#plugins.security.audit.config.verify_hostnames: false +#plugins.security.audit.config.cert_alias: mycert +#plugins.security.audit.config.pemkey_filepath: key.pem +#plugins.security.audit.config.pemkey_content: <...pem base 64 content> +#plugins.security.audit.config.pemkey_password: secret +#plugins.security.audit.config.pemcert_filepath: cert.pem +#plugins.security.audit.config.pemcert_content: <...pem base 64 content> +#plugins.security.audit.config.pemtrustedcas_filepath: ca.pem +#plugins.security.audit.config.pemtrustedcas_content: <...pem base 64 content> + +# webhook settings +#plugins.security.audit.config.webhook.url: "http://mywebhook/endpoint" +# One of URL_PARAMETER_GET,URL_PARAMETER_POST,TEXT,JSON,SLACK +#plugins.security.audit.config.webhook.format: JSON +#plugins.security.audit.config.webhook.ssl.verify: false +#plugins.security.audit.config.webhook.ssl.pemtrustedcas_filepath: ca.pem +#plugins.security.audit.config.webhook.ssl.pemtrustedcas_content: <...pem base 64 content> + +# log4j settings +#plugins.security.audit.config.log4j.logger_name: auditlogger +#plugins.security.audit.config.log4j.level: INFO + +############## Kerberos configuration settings ############## +# If Kerberos authentication should be used you have to configure: + +# The Path to the krb5.conf file +# Can be absolute or relative to the OpenSearch config directory +#plugins.security.kerberos.krb5_filepath: '/etc/krb5.conf' + +# The Path to the keytab where the acceptor_principal credentials are stored. +# Must be relative to the OpenSearch config directory +#plugins.security.kerberos.acceptor_keytab_filepath: 'eskeytab.tab' + +# Acceptor (Server) Principal name, must be present in acceptor_keytab_path file +#plugins.security.kerberos.acceptor_principal: 'HTTP/localhost' + + +############## Expert settings ############## +# WARNING: Expert settings, do only use if you know what you are doing +# If you set wrong values here this this could be a security risk +# or make OpenSearch Security stop working + +# Name of the index where .opendistro_security stores its configuration. + +#plugins.security.config_index_name: .opendistro_security + +# This defines the OID of server node certificates +#plugins.security.cert.oid: '1.2.3.4.5.5' + +# This specifies the implementation of org.opensearch.security.transport.InterClusterRequestEvaluator +# that is used to determine inter-cluster request. +# Instances of org.opensearch.security.transport.InterClusterRequestEvaluator must implement a single argument +# constructor that takes an org.opensearch.common.settings.Settings +#plugins.security.cert.intercluster_request_evaluator_class: org.opensearch.security.transport.DefaultInterClusterRequestEvaluator + +# By default, normal users can restore snapshots if they have the priviliges 'cluster:admin/snapshot/restore', +# 'indices:admin/create', and 'indices:data/write/index' for the indices to be restored. +# To disable snapshot restore for normal users set 'plugins.security.enable_snapshot_restore_privilege: false'. +# This makes it so that only snapshot restore requests signed by an admin TLS certificate are accepted. +# A snapshot can only be restored when it does not contain global state and does not restore the '.opendistro_security' index +# If 'plugins.security.check_snapshot_restore_write_privileges: false' is set then the additional indices checks are omitted. +#plugins.security.enable_snapshot_restore_privilege: true +#plugins.security.check_snapshot_restore_write_privileges: true + +# Authentication cache timeout in minutes (A value of 0 disables caching, default is 60) +#plugins.security.cache.ttl_minutes: 60 + +# Disable OpenSearch Security +# WARNING: This can expose your configuration (including passwords) to the public. +#plugins.security.disabled: false + +# Protected indices are even more secure than normal indices. These indices require a role to access like any other index, but they require an additional role +# to be visible, listed in the plugins.security.protected_indices.roles setting. +# Enable protected indices +# plugins.security.protected_indices.enabled: true +# Specify a list of roles a user must be member of to touch any protected index. +# plugins.security.protected_indices.roles: ['all_access'] + +# Bundled plugins register their system indices with OpenSearch. Protect those +# registered indices without the deprecated plugins.security.system_indices.indices list. +# Allow explicit system:admin/system_index role permissions as well as super-admin access. +plugins.security.system_indices.enabled: true +plugins.security.system_indices.permission.enabled: true + +# ================= ML Commons ================= + +plugins.ml_commons.local_model.enabled: true +plugins.ml_commons.remote_inference.enabled: true +plugins.ml_commons.only_run_on_ml_node: false +plugins.ml_commons.allow_registering_model_via_url: true +plugins.ml_commons.allow_registering_model_via_local_file: true +# Permit HTTPS model repositories and only the dedicated read-only local model +# directory; do not allow arbitrary HTTP, FTP, or file-system paths. +plugins.ml_commons.trusted_url_regex: '^https://.*$|^file:///usr/share/opensearch/models/[^?#]+\.zip$' +# Permit ML Commons connectors to call only the Ollama service on the private +# CogStack Docker network. Docker resolves this stable service name to a +# private container IP, so both the general and private endpoint allowlists +# are required by OpenSearch 3.7 and later. +plugins.ml_commons.connector.private_ip_enabled: true +plugins.ml_commons.trusted_connector_endpoints_regex: + - '^http://ollama:11434/.*$' + - '^http://ollama-openai-proxy:11435/.*$' +plugins.ml_commons.trusted_connector_private_endpoints_regex: + - '^http://ollama:11434/.*$' + - '^http://ollama-openai-proxy:11435/.*$' +plugins.ml_commons.model_access_control_enabled: true +plugins.ml_commons.connector_access_control_enabled: true +plugins.ml_commons.safe_delete_model: true +plugins.ml_commons.agent_framework_enabled: true +plugins.ml_commons.rag_pipeline_feature_enabled: true +# Upper bound for asynchronous ML Commons tasks. Remote connector connection +# and response timeouts are configured per connector by opensearch-ai-init.sh. +plugins.ml_commons.ml_task_timeout_in_seconds: 600 + +# This cluster has no dedicated ML nodes, so allow both local and remote models +# to execute on data nodes. +plugins.ml_commons.task_dispatcher.eligible_node_role.local_model: + - data +plugins.ml_commons.task_dispatcher.eligible_node_role.remote_model: + - data + + +# Enable SQL-like queries, allows you to join across indices etc. +plugins.sql.enabled: true +plugins.ppl.enabled: true + +# Calcite (SQL v3 engine) +plugins.calcite.enabled: true +# WARNING: exists only in OpenSearch > 3.4, please DISABLE if you are not on this version as this setting doesn't exist. +plugins.calcite.all_join_types.allowed: true + +# coordinator-level kill switch for searches +search.cancel_after_time_interval: 5m + +# shard-level default timeout (can be overridden per request via "timeout") +search.default_search_timeout: 5m + +# relevant if SQL is paging via PIT +search.default_keep_alive: 10m diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index f576fdeb..f18306ae 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -6,19 +6,41 @@ The upstream chart supplies the Kubernetes templates. Set overrides under ## Install -Run from the repository root. The `opensearch-admin` Secret holds the initial -admin password. Use a file containing just the password, with no trailing -newline. The upstream defaults create three pods with persistent storage. -Check the [cluster prerequisites](https://docs.opensearch.org/latest/opensearch/install/helm/#prerequisites). +The chart defaults to a shared node certificate. From the repository root, build +the chart dependency and generate the node and admin client certificates with +an existing CA and `OS_CERTIFICATE_PASSWORD` exported. Use an absolute +`SECURITY_DIR` for a custom output location. +[Cluster prerequisites](https://docs.opensearch.org/latest/opensearch/install/helm/#prerequisites) ```bash +chart=deployment/charts/opensearch helm repo add opensearch https://opensearch-project.github.io/helm-charts/ -helm dependency build deployment/charts/opensearch +helm dependency build "$chart" +make -C deployment certs-opensearch +certs="${SECURITY_DIR:-deployment/security}/certificates/opensearch" +``` + +For a packaged chart, set `chart=./opensearch` after extracting it and point +`certs` at your certificate directory. The archive contains the chart dependency +and the shared OpenSearch config. + +```bash kubectl create namespace search -kubectl -n search create secret generic opensearch-admin --from-file=password=/path/to/password -helm upgrade --install opensearch deployment/charts/opensearch --namespace search +kubectl -n search create secret generic opensearch-node-tls \ + --from-file=node.crt="$certs/opensearch-shared.crt" \ + --from-file=node.key="$certs/opensearch-shared.key" \ + --from-file=ca.crt="$certs/elastic-stack-ca.crt.pem" +helm upgrade --install opensearch "$chart" -n search \ + --set-file "opensearch.config.opensearch\.yml=$chart/config/opensearch.yml" ``` +Helm loads the bundled [`opensearch.yml`](config/opensearch.yml) through `--set-file`. +Transport TLS checks the CA and shared node DN. Set `KUBE_NAMESPACE` or +`CLUSTER_DOMAIN` when issuing the certificate if either differs from `search` +or `cluster.local`. For a fresh cluster, initialize the Security index with +your Security plugin configuration and the local `admin.crt` and `admin.key.pem`. +[`securityadmin.sh` instructions](https://docs.opensearch.org/latest/security/configuration/security-admin/) + From inside the cluster, clients can use `https://opensearch-cluster-master.search.svc:9200`. @@ -37,38 +59,13 @@ kubectl -n search get pvc ## Configuration and TLS -### K3s with a shared node certificate - -Build the chart dependency as shown in Install. With an existing CA and -`OS_CERTIFICATE_PASSWORD` exported, generate the shared node and separate admin -client certificates. Use an absolute `SECURITY_DIR` for a custom output location. - -```bash -make -C deployment certs-opensearch -certs="${SECURITY_DIR:-deployment/security}/certificates/opensearch" -kubectl create namespace search -kubectl -n search create secret generic opensearch-node-tls \ - --from-file=node.crt="$certs/opensearch-shared.crt" \ - --from-file=node.key="$certs/opensearch-shared.key" \ - --from-file=ca.crt="$certs/elastic-stack-ca.crt.pem" -helm upgrade --install opensearch deployment/charts/opensearch -n search \ - -f deployment/charts/opensearch/values-k3s.yaml -``` - -The K3s profile checks the CA and shared node DN on transport connections and -disables transport hostname verification. Set `KUBE_NAMESPACE` or `CLUSTER_DOMAIN` -when issuing the certificate if either differs from `search` or `cluster.local`. -For a fresh cluster, initialize the Security index with your Security plugin -configuration and the local `admin.crt` and `admin.key.pem`. -[`securityadmin.sh` instructions](https://docs.opensearch.org/latest/security/configuration/security-admin/) +The chart links to the source at `apps/opensearch/config/opensearch.yml`. +In Docker, mount the source at `/usr/share/opensearch/config/opensearch.yml`. +Mount the shared certificate, key, and public CA as `node.crt`, `node.key`, +and `ca.crt` under `/usr/share/opensearch/config/tls`. ### Custom values -The [imported OpenSearch config](../../../apps/opensearch/config/opensearch.yml) -uses the old Compose discovery variables and certificate paths. The default -install uses upstream config and demo certificates. Prepare a Kubernetes config -with the right discovery and TLS settings before using the imported file. - Pass a prepared file to Helm. The chart creates a ConfigMap and uses it to populate the file mounted at `/usr/share/opensearch/config/opensearch.yml`. diff --git a/deployment/charts/opensearch/ci/ci-values.yaml b/deployment/charts/opensearch/ci/ci-values.yaml index 023d97a4..7e9ad185 100644 --- a/deployment/charts/opensearch/ci/ci-values.yaml +++ b/deployment/charts/opensearch/ci/ci-values.yaml @@ -1,5 +1,6 @@ opensearch: replicas: 1 + secretMounts: [] extraEnvs: - name: OPENSEARCH_INITIAL_ADMIN_PASSWORD value: "CogStack-Chart-Test9!" diff --git a/deployment/charts/opensearch/config/opensearch.yml b/deployment/charts/opensearch/config/opensearch.yml new file mode 120000 index 00000000..cc4c4ad4 --- /dev/null +++ b/deployment/charts/opensearch/config/opensearch.yml @@ -0,0 +1 @@ +../../../../apps/opensearch/config/opensearch.yml \ No newline at end of file diff --git a/deployment/charts/opensearch/values-k3s.yaml b/deployment/charts/opensearch/values-k3s.yaml deleted file mode 100644 index 61ede916..00000000 --- a/deployment/charts/opensearch/values-k3s.yaml +++ /dev/null @@ -1,27 +0,0 @@ -opensearch: - extraEnvs: - - name: DISABLE_INSTALL_DEMO_CONFIG - value: "true" - secretMounts: - - name: node-tls - secretName: opensearch-node-tls - path: /usr/share/opensearch/config/tls - defaultMode: 0440 - config: - opensearch.yml: | - cluster.name: opensearch-cluster - network.host: 0.0.0.0 - transport.ssl.enforce_hostname_verification: false - plugins.security.ssl.transport.pemcert_filepath: tls/node.crt - plugins.security.ssl.transport.pemkey_filepath: tls/node.key - plugins.security.ssl.transport.pemtrustedcas_filepath: tls/ca.crt - plugins.security.ssl.http.enabled: true - plugins.security.ssl.http.pemcert_filepath: tls/node.crt - plugins.security.ssl.http.pemkey_filepath: tls/node.key - plugins.security.ssl.http.pemtrustedcas_filepath: tls/ca.crt - plugins.security.ssl.http.clientauth_mode: OPTIONAL - plugins.security.allow_unsafe_democertificates: false - plugins.security.nodes_dn: - - 'CN=opensearch-shared,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK' - plugins.security.authcz.admin_dn: - - 'CN=admin,OU=cogstack,O=cogstack,L=UK,ST=London,C=UK' diff --git a/deployment/charts/opensearch/values.yaml b/deployment/charts/opensearch/values.yaml index e2338333..dc5f3ebf 100644 --- a/deployment/charts/opensearch/values.yaml +++ b/deployment/charts/opensearch/values.yaml @@ -3,9 +3,12 @@ opensearch: persistence: enabled: true size: 8Gi + # Supply opensearch.yml with --set-file as shown in the README. extraEnvs: - - name: OPENSEARCH_INITIAL_ADMIN_PASSWORD - valueFrom: - secretKeyRef: - name: opensearch-admin - key: password + - name: DISABLE_INSTALL_DEMO_CONFIG + value: "true" + secretMounts: + - name: node-tls + secretName: opensearch-node-tls + path: /usr/share/opensearch/config/tls + defaultMode: 0440 From 8803a510d241d8ad8920171cbf498ea6022afded Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 09:37:35 +0000 Subject: [PATCH 25/63] security cert gen pw prompting to scripts. --- deployment/charts/opensearch/README.md | 4 ++-- deployment/scripts/README.md | 14 ++++++----- .../scripts/security/create_nifi_certs.sh | 13 +++++++---- .../create_opensearch_client_admin_certs.sh | 5 ++-- .../security/create_opensearch_node_cert.sh | 6 +++-- .../scripts/security/create_root_ca_cert.sh | 10 ++++---- .../scripts/security/password_prompt.sh | 23 +++++++++++++++++++ 7 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 deployment/scripts/security/password_prompt.sh diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index f18306ae..bed477be 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -8,8 +8,8 @@ The upstream chart supplies the Kubernetes templates. Set overrides under The chart defaults to a shared node certificate. From the repository root, build the chart dependency and generate the node and admin client certificates with -an existing CA and `OS_CERTIFICATE_PASSWORD` exported. Use an absolute -`SECURITY_DIR` for a custom output location. +an existing CA. The generator prompts for `OS_CERTIFICATE_PASSWORD` when unset. +Use an absolute `SECURITY_DIR` for a custom output location. [Cluster prerequisites](https://docs.opensearch.org/latest/opensearch/install/helm/#prerequisites) ```bash diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index 2b200931..6ac712bf 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -11,8 +11,11 @@ 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/`. -For local development, load the [sample store passwords](../env/certificates_dev.env) -before running the root CA and NiFi generators. +The generators prompt for missing passwords with hidden input in a terminal. +Export the required variables before running from CI or with redirected input. + +To use [sample store passwords](../env/certificates_dev.env) for local development, +load them before running the root CA and NiFi generators. ```bash set -a @@ -20,8 +23,7 @@ source deployment/env/certificates_dev.env set +a ``` -If you need a root CA, export `ROOT_CERTIFICATE_KEYSTORE_PASSWORD` and run this -from the repository root. +The root CA generator uses `ROOT_CERTIFICATE_KEYSTORE_PASSWORD`. ```bash ./deployment/scripts/security/create_root_ca_cert.sh @@ -29,7 +31,7 @@ from the repository root. ### NiFi -Export the `KEYSTORE_PASSWORD` and `TRUSTSTORE_PASSWORD` that NiFi will use. +Use the `KEYSTORE_PASSWORD` and `TRUSTSTORE_PASSWORD` that NiFi will use. The legacy `NIFI_KEYSTORE_PASSWORD` and `NIFI_TRUSTSTORE_PASSWORD` names are also accepted. @@ -76,7 +78,7 @@ It runs without a store password or `keytool`. ### OpenSearch -Export `OS_CERTIFICATE_PASSWORD` for the Java and PKCS#12 stores. Pass the node +Use `OS_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. diff --git a/deployment/scripts/security/create_nifi_certs.sh b/deployment/scripts/security/create_nifi_certs.sh index 3019c430..5abf300f 100755 --- a/deployment/scripts/security/create_nifi_certs.sh +++ b/deployment/scripts/security/create_nifi_certs.sh @@ -9,7 +9,7 @@ # # Requires: # - Bash, OpenSSL and Java keytool -# - KEYSTORE_PASSWORD and TRUSTSTORE_PASSWORD in the environment +# - KEYSTORE_PASSWORD and TRUSTSTORE_PASSWORD (prompted when unset) # - root-ca.pem and root-ca.key under certificates/root/ in SECURITY_DIR # # Optional environment variables: @@ -46,10 +46,6 @@ 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 @@ -65,6 +61,13 @@ for file in "${files[@]}"; do fi done +KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}} +TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD:-}} +# shellcheck source=password_prompt.sh +source "$script_dir/password_prompt.sh" +require_password KEYSTORE_PASSWORD +require_password TRUSTSTORE_PASSWORD + # 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) diff --git a/deployment/scripts/security/create_opensearch_client_admin_certs.sh b/deployment/scripts/security/create_opensearch_client_admin_certs.sh index ea8a6f74..7d65142c 100755 --- a/deployment/scripts/security/create_opensearch_client_admin_certs.sh +++ b/deployment/scripts/security/create_opensearch_client_admin_certs.sh @@ -61,8 +61,9 @@ done roles=(admin) files=(admin.crt admin.key.pem admin.csr) if [[ "$create_dashboards" == true ]]; then - : "${OS_CERTIFICATE_PASSWORD:?Set OS_CERTIFICATE_PASSWORD}" - export OS_CERTIFICATE_PASSWORD + # shellcheck source=password_prompt.sh + source "$script_dir/password_prompt.sh" + require_password OS_CERTIFICATE_PASSWORD roles=(client admin) files=(es_kibana_client.pem es_kibana_client.key es_kibana_client.csr es_kibana_client.p12 "${files[@]}") diff --git a/deployment/scripts/security/create_opensearch_node_cert.sh b/deployment/scripts/security/create_opensearch_node_cert.sh index 543939f0..f5bf600a 100755 --- a/deployment/scripts/security/create_opensearch_node_cert.sh +++ b/deployment/scripts/security/create_opensearch_node_cert.sh @@ -92,8 +92,6 @@ for node in "$@"; do done done -: "${OS_CERTIFICATE_PASSWORD:?Set OS_CERTIFICATE_PASSWORD}" -export OS_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 @@ -110,6 +108,10 @@ if [[ -e "$ca_alias" || -L "$ca_alias" ]]; then write_ca_alias=false fi +# shellcheck source=password_prompt.sh +source "$script_dir/password_prompt.sh" +require_password OS_CERTIFICATE_PASSWORD + # Stage all node bundles before writing deployment files. Roll back writes on failure. scratch_dir=$(mktemp -d) published=() diff --git a/deployment/scripts/security/create_root_ca_cert.sh b/deployment/scripts/security/create_root_ca_cert.sh index 7730d6a6..baae3e01 100755 --- a/deployment/scripts/security/create_root_ca_cert.sh +++ b/deployment/scripts/security/create_root_ca_cert.sh @@ -10,7 +10,7 @@ # # Requires: # - Bash, OpenSSL and Java keytool -# - ROOT_CERTIFICATE_KEYSTORE_PASSWORD in the environment +# - ROOT_CERTIFICATE_KEYSTORE_PASSWORD (prompted when unset) # - ../../security/templates/ssl-extensions-x509.cnf relative to this script # # Output: @@ -53,10 +53,6 @@ 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 @@ -66,6 +62,10 @@ for output in "$KEY_FILE" "$PEM_FILE" "$CRT_FILE" "$CSR_FILE" "$P12_FILE" "$JKS_ fi done +# shellcheck source=password_prompt.sh +source "$SCRIPT_DIR/password_prompt.sh" +require_password ROOT_CERTIFICATE_KEYSTORE_PASSWORD + # 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) diff --git a/deployment/scripts/security/password_prompt.sh b/deployment/scripts/security/password_prompt.sh new file mode 100644 index 00000000..0f60a41e --- /dev/null +++ b/deployment/scripts/security/password_prompt.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +require_password() { + local name=$1 password + + if [[ -n ${!name:-} ]]; then + export "${name?}" + return + fi + + if [[ ! -t 0 ]]; then + printf 'Set %s in the environment or run this generator in a terminal.\n' "$name" >&2 + return 1 + fi + + if ! IFS= read -r -s -p "Enter $name: " password || [[ -z "$password" ]]; then + printf '\nSet %s to a nonempty password.\n' "$name" >&2 + return 1 + fi + + printf '\n' >&2 + export "$name=$password" +} From 986df6df840d3d9478b16f76edc91c5d32d59b08 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 11:26:33 +0000 Subject: [PATCH 26/63] workflows: updated NiFi smoke test. --- ...ifi_services.yml => docker_smoke_nifi.yml} | 49 +++++-------------- 1 file changed, 11 insertions(+), 38 deletions(-) rename .github/workflows/{smoke_nifi_services.yml => docker_smoke_nifi.yml} (65%) diff --git a/.github/workflows/smoke_nifi_services.yml b/.github/workflows/docker_smoke_nifi.yml similarity index 65% rename from .github/workflows/smoke_nifi_services.yml rename to .github/workflows/docker_smoke_nifi.yml index 8271642a..e37c9f3a 100644 --- a/.github/workflows/smoke_nifi_services.yml +++ b/.github/workflows/docker_smoke_nifi.yml @@ -1,4 +1,4 @@ -name: smoke-nifi-services +name: docker_smoke_nifi on: push: @@ -6,7 +6,11 @@ on: paths: &paths - 'apps/nifi/**' - 'apps/nginx/**' - - '.github/workflows/smoke_nifi_services.yml' + - 'deployment/Makefile' + - 'deployment/env/*_dev.env' + - 'deployment/scripts/security/**' + - 'deployment/security/templates/**' + - '.github/workflows/docker_smoke_nifi.yml' - '!**/*.md' - '!**/README*' pull_request: @@ -33,7 +37,7 @@ jobs: env: COMPOSE_FILE: docker-compose.base.yml:docker-compose.dev.yml COMPOSE_PROJECT_NAME: nifi-smoke - CERT_DIR: ../../../deployment/security/certificates + SECURITY_DIR: ${{ github.workspace }}/deployment/security steps: - uses: actions/checkout@v7 @@ -46,38 +50,11 @@ jobs: - 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)" + ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" KEYSTORE_PASSWORD="$password" TRUSTSTORE_PASSWORD="$password" \ + make -C ../../../deployment certs - 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" - + mkdir -p ../env touch ../env/general.env cat > ../env/nifi.env < Date: Wed, 25 Nov 2026 12:19:03 +0000 Subject: [PATCH 27/63] GHA: smoke tests + opensearch docker files. --- .github/workflows/docker_smoke_nifi.yml | 59 ++---------- .github/workflows/docker_smoke_opensearch.yml | 95 +++++++++++++++++++ .../docker/docker-compose.base.yml | 34 +++++++ .../docker/docker-compose.dev.yml | 10 ++ .../docker/docker-compose.prod.yml | 10 ++ .../docker/docker-compose.yml | 5 + apps/opensearch/README.md | 37 ++++++++ .../opensearch/docker/docker-compose.base.yml | 40 ++++++++ apps/opensearch/docker/docker-compose.dev.yml | 10 ++ .../opensearch/docker/docker-compose.prod.yml | 5 + apps/opensearch/docker/docker-compose.yml | 5 + .../create_opensearch_client_admin_certs.sh | 30 +++--- 12 files changed, 276 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/docker_smoke_opensearch.yml create mode 100644 apps/opensearch-dashboards/docker/docker-compose.base.yml create mode 100644 apps/opensearch-dashboards/docker/docker-compose.dev.yml create mode 100644 apps/opensearch-dashboards/docker/docker-compose.prod.yml create mode 100644 apps/opensearch-dashboards/docker/docker-compose.yml create mode 100644 apps/opensearch/README.md create mode 100644 apps/opensearch/docker/docker-compose.base.yml create mode 100644 apps/opensearch/docker/docker-compose.dev.yml create mode 100644 apps/opensearch/docker/docker-compose.prod.yml create mode 100644 apps/opensearch/docker/docker-compose.yml diff --git a/.github/workflows/docker_smoke_nifi.yml b/.github/workflows/docker_smoke_nifi.yml index e37c9f3a..e178fe95 100644 --- a/.github/workflows/docker_smoke_nifi.yml +++ b/.github/workflows/docker_smoke_nifi.yml @@ -7,7 +7,6 @@ on: - 'apps/nifi/**' - 'apps/nginx/**' - 'deployment/Makefile' - - 'deployment/env/*_dev.env' - 'deployment/scripts/security/**' - 'deployment/security/templates/**' - '.github/workflows/docker_smoke_nifi.yml' @@ -31,11 +30,10 @@ defaults: jobs: smoke: - name: Build and smoke-test NiFi services + name: 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 SECURITY_DIR: ${{ github.workspace }}/deployment/security @@ -53,6 +51,8 @@ jobs: password="$(openssl rand -hex 16)" ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" KEYSTORE_PASSWORD="$password" TRUSTSTORE_PASSWORD="$password" \ make -C ../../../deployment certs + # The published containers run as UID/GID 1000. + sudo chown 1000:1000 "$SECURITY_DIR"/certificates/{nifi/nifi-keystore.jks,nginx/tls.key} mkdir -p ../env touch ../env/general.env @@ -69,55 +69,13 @@ jobs: TRUSTSTORE_PASSWORD=$password EOF - - name: Validate published NGINX startup + - name: Start NiFi and NGINX run: | source ./export_env_vars.sh - # The runner owns the temporary NGINX key. - docker compose -p nifi-smoke-published -f docker-compose.yml run --rm --no-deps \ - --user "$(id -u):$(id -g)" nifi-nginx nginx -t - - - name: Smoke tests - run: | - make start-nifi-dev-build - source ./export_env_vars.sh - url=https://127.0.0.1:8443 - request=(curl --silent --show-error --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" --connect-timeout 5 --max-time 20) - - for route in / /nifi/; do - code="$("${request[@]}" --fail --retry 30 --retry-all-errors --retry-delay 10 --retry-max-time 600 \ - --output /dev/null --write-out '%{http_code}' "$url$route")" - case "$code" in - 200|301|302|303|307|308) echo "OK: $route returned HTTP $code" ;; - *) echo "Unexpected HTTP $code from $route" >&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' + docker compose up -d + curl -fsS --retry 30 --retry-all-errors --retry-delay 10 --retry-max-time 300 --max-time 10 \ + --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" -o /dev/null \ + https://127.0.0.1:8443/nifi-api/authentication/configuration - name: Dump container logs if: failure() @@ -133,4 +91,3 @@ jobs: [[ -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 diff --git a/.github/workflows/docker_smoke_opensearch.yml b/.github/workflows/docker_smoke_opensearch.yml new file mode 100644 index 00000000..62503584 --- /dev/null +++ b/.github/workflows/docker_smoke_opensearch.yml @@ -0,0 +1,95 @@ +name: docker_smoke_opensearch + +on: + push: + branches: ['**'] + paths: &paths + - 'apps/opensearch/**' + - 'apps/opensearch-dashboards/**' + - 'deployment/Makefile' + - 'deployment/scripts/security/**' + - 'deployment/security/templates/**' + - '.github/workflows/docker_smoke_opensearch.yml' + pull_request: + paths: *paths + workflow_dispatch: + +permissions: + contents: read + +jobs: + smoke: + runs-on: ubuntu-24.04 + timeout-minutes: 15 + env: + SMOKE_PROJECT: opensearch-smoke-${{ github.run_id }} + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: '21' + + - name: Smoke test OpenSearch and Dashboards + run: | + set -euo pipefail + source apps/opensearch/env/opensearch.env + source apps/opensearch-dashboards/env/opensearch-dashboards.env + SECURITY_DIR=$(mktemp -d "$RUNNER_TEMP/opensearch-smoke.XXXXXX") + password=$(openssl rand -hex 16) + export SECURITY_DIR ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" OS_CERTIFICATE_PASSWORD="$password" + make -C deployment certs-root + make -C deployment certs-opensearch-nodes NODES=opensearch-shared OPENSEARCH_NODE_DNS_NAMES=localhost + OPENSEARCH_DASHBOARDS_DNS_NAMES=localhost ./deployment/scripts/security/create_opensearch_client_admin_certs.sh + + certs="$SECURITY_DIR/certificates/opensearch" + ca="$certs/elastic-stack-ca.crt.pem" + mkdir "$SECURITY_DIR"/{node,dashboards} + install -m 644 "$certs/opensearch-shared.crt" "$SECURITY_DIR/node/node.crt" + install -m 644 "$certs/opensearch-shared.key" "$SECURITY_DIR/node/node.key" + install -m 644 "$ca" "$SECURITY_DIR/node/ca.crt" + install -m 644 "$certs"/es_kibana_client.{pem,key} "$ca" "$SECURITY_DIR/dashboards/" + + docker network create "$SMOKE_PROJECT" + docker run -d --name "$SMOKE_PROJECT" --network "$SMOKE_PROJECT" --network-alias opensearch \ + -p 127.0.0.1::9200 -e discovery.type=single-node -e "OPENSEARCH_JAVA_OPTS=$OPENSEARCH_JAVA_OPTS" \ + -e DISABLE_INSTALL_DEMO_CONFIG=true -e OPENSEARCH_ALLOW_DEFAULT_INIT_SECURITYINDEX=true \ + -v "$PWD/apps/opensearch/config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml:ro" \ + -v "$SECURITY_DIR/node:/usr/share/opensearch/config/tls:ro" "$OPENSEARCH_DOCKER_IMAGE" + + request=(curl -fsS --noproxy '*' --cacert "$ca" --connect-timeout 3 --max-time 20) + port=$(docker port "$SMOKE_PROJECT" 9200/tcp) + "${request[@]}" --retry 30 --retry-all-errors --retry-delay 3 --retry-max-time 180 \ + --cert "$certs/admin.crt" --key "$certs/admin.key.pem" \ + "https://localhost:${port##*:}/_cluster/health?wait_for_status=yellow&timeout=10s" | + jq -e '.timed_out == false and (.status == "green" or .status == "yellow")' + + docker run -d --name "$SMOKE_PROJECT-dashboards" --network "$SMOKE_PROJECT" -p 127.0.0.1::5601 \ + -e "OPENSEARCH_DASHBOARDS_SERVER_NAME=$OPENSEARCH_DASHBOARDS_SERVER_NAME" \ + -e 'OPENSEARCH_HOSTS=["https://opensearch:9200"]' -e KIBANA_USER=kibanaserver -e KIBANA_PASSWORD=kibanaserver \ + -v "$PWD/apps/opensearch-dashboards/config/opensearch.yml:/usr/share/opensearch-dashboards/config/opensearch_dashboards.yml:ro" \ + -v "$SECURITY_DIR/dashboards:/certificates/elastic/opensearch:ro" \ + "$OPENSEARCH_DASHBOARDS_DOCKER_IMAGE" --status.allowAnonymous=true + + port=$(docker port "$SMOKE_PROJECT-dashboards" 5601/tcp) + for _ in {1..40}; do + if "${request[@]}" "https://localhost:${port##*:}/api/status?v8format=true" 2>/dev/null | + jq -e '.status.core | .opensearch.level == "available" and .savedObjects.level == "available"'; then + exit 0 + fi + sleep 3 + done + echo 'Dashboards did not connect to OpenSearch' >&2 + exit 1 + + - name: Logs on failure + if: failure() + run: | + docker logs "$SMOKE_PROJECT" || true + docker logs "$SMOKE_PROJECT-dashboards" || true + + - name: Cleanup + if: always() + run: | + docker rm -fv "$SMOKE_PROJECT" "$SMOKE_PROJECT-dashboards" || true + docker network rm "$SMOKE_PROJECT" || true diff --git a/apps/opensearch-dashboards/docker/docker-compose.base.yml b/apps/opensearch-dashboards/docker/docker-compose.base.yml new file mode 100644 index 00000000..3118484a --- /dev/null +++ b/apps/opensearch-dashboards/docker/docker-compose.base.yml @@ -0,0 +1,34 @@ +services: + opensearch-dashboards: + image: ${OPENSEARCH_DASHBOARDS_DOCKER_IMAGE:?Load ../env/opensearch-dashboards.env} + restart: unless-stopped + mem_limit: ${OPENSEARCH_DASHBOARDS_DOCKER_RAM:-1g} + environment: + OPENSEARCH_DASHBOARDS_SERVER_NAME: ${OPENSEARCH_DASHBOARDS_SERVER_NAME:-cogstack-opensearch-dashboards} + OPENSEARCH_HOSTS: '${OPENSEARCH_HOSTS:-["https://opensearch-shared:9200"]}' + OPENSEARCHDASHBOARDS_INDEX: ${OPENSEARCHDASHBOARDS_INDEX:-.kibana} + KIBANA_USER: ${KIBANA_USER:-kibanaserver} + ports: + - '127.0.0.1:${OPENSEARCH_DASHBOARDS_SERVER_OUTPUT_PORT:-5601}:5601' + volumes: + - &bind + type: bind + source: ../config/opensearch.yml + target: /usr/share/opensearch-dashboards/config/opensearch_dashboards.yml + read_only: true + bind: + create_host_path: false + - <<: *bind + source: ${SECURITY_DIR:-../../../deployment/security}/certificates/opensearch/es_kibana_client.pem + target: /certificates/elastic/opensearch/es_kibana_client.pem + - <<: *bind + source: ${SECURITY_DIR:-../../../deployment/security}/certificates/opensearch/es_kibana_client.key + target: /certificates/elastic/opensearch/es_kibana_client.key + - <<: *bind + source: ${SECURITY_DIR:-../../../deployment/security}/certificates/root/root-ca.pem + target: /certificates/elastic/opensearch/elastic-stack-ca.crt.pem + networks: [cognet] + +networks: + cognet: + external: true diff --git a/apps/opensearch-dashboards/docker/docker-compose.dev.yml b/apps/opensearch-dashboards/docker/docker-compose.dev.yml new file mode 100644 index 00000000..90ccfb30 --- /dev/null +++ b/apps/opensearch-dashboards/docker/docker-compose.dev.yml @@ -0,0 +1,10 @@ +name: opensearch-dashboards-dev + +services: + opensearch-dashboards: + environment: + KIBANA_PASSWORD: ${KIBANA_PASSWORD:-kibanaserver} + +networks: + cognet: + name: opensearch-dev-net diff --git a/apps/opensearch-dashboards/docker/docker-compose.prod.yml b/apps/opensearch-dashboards/docker/docker-compose.prod.yml new file mode 100644 index 00000000..07c83e34 --- /dev/null +++ b/apps/opensearch-dashboards/docker/docker-compose.prod.yml @@ -0,0 +1,10 @@ +name: opensearch-dashboards + +services: + opensearch-dashboards: + environment: + KIBANA_PASSWORD: ${KIBANA_PASSWORD:?Set the Dashboards service account password} + +networks: + cognet: + name: cogstack-net diff --git a/apps/opensearch-dashboards/docker/docker-compose.yml b/apps/opensearch-dashboards/docker/docker-compose.yml new file mode 100644 index 00000000..4af24138 --- /dev/null +++ b/apps/opensearch-dashboards/docker/docker-compose.yml @@ -0,0 +1,5 @@ +name: opensearch-dashboards + +include: + - path: [docker-compose.base.yml, docker-compose.prod.yml] + env_file: ../env/opensearch-dashboards.env diff --git a/apps/opensearch/README.md b/apps/opensearch/README.md new file mode 100644 index 00000000..c1726cb0 --- /dev/null +++ b/apps/opensearch/README.md @@ -0,0 +1,37 @@ +# OpenSearch and Dashboards in Docker + +From the repository root, run the commands for any missing TLS files. + +```bash +make -C deployment certs-root +make -C deployment certs-opensearch +OPENSEARCH_DASHBOARDS_DNS_NAMES=localhost \ + ./deployment/scripts/security/create_opensearch_client_admin_certs.sh --dashboards-only +``` + +Set an absolute `SECURITY_DIR` to use a different certificate bundle. Each +container runs as UID 1000 and needs read access to its own private key. The +Dashboards certificate must cover the browser hostname. + +Start OpenSearch with `docker compose up -d` in `apps/opensearch/docker`. +Initialize the Security index with your users and the admin client certificate +on the first start. Export the Dashboards service account's `KIBANA_PASSWORD`, +then run `docker compose up -d` in `apps/opensearch-dashboards/docker`. +Dashboards joins the OpenSearch network and listens at `https://localhost:5601`. +[OpenSearch Security initialization](https://docs.opensearch.org/latest/security/configuration/security-admin/) + +Compose uses `.kibana` for saved objects to match the bundled Security role. +Set `OPENSEARCHDASHBOARDS_INDEX` when your Security configuration uses another index. + +For dev, run this from each app's `docker/` directory, starting with OpenSearch. +Use `opensearch-dashboards.env` for Dashboards. + +```bash +docker compose --env-file ../env/opensearch.env \ + -f docker-compose.base.yml -f docker-compose.dev.yml up -d +``` + +Dev uses the bundled Security users and a separate network. The corresponding +`docker-compose.prod.yml` overlay joins an existing `cogstack-net`. OpenSearch +stores indexes and Security state in `opensearch_data` or `opensearch-dev_data`, +which survive `docker compose down`. diff --git a/apps/opensearch/docker/docker-compose.base.yml b/apps/opensearch/docker/docker-compose.base.yml new file mode 100644 index 00000000..515c2dc8 --- /dev/null +++ b/apps/opensearch/docker/docker-compose.base.yml @@ -0,0 +1,40 @@ +services: + opensearch: + image: ${OPENSEARCH_DOCKER_IMAGE:?Load ../env/opensearch.env} + restart: unless-stopped + mem_limit: ${OPENSEARCH_DOCKER_RAM:-2g} + shm_size: ${OPENSEARCH_DOCKER_SHM_SIZE:-512m} + environment: + discovery.type: single-node + DISABLE_INSTALL_DEMO_CONFIG: 'true' + OPENSEARCH_JAVA_OPTS: ${OPENSEARCH_JAVA_OPTS:--Xms512m -Xmx512m} + ports: + - '127.0.0.1:${OPENSEARCH_NODE_1_OUTPUT_PORT:-9200}:9200' + volumes: + - data:/usr/share/opensearch/data + - &bind + type: bind + source: ../config/opensearch.yml + target: /usr/share/opensearch/config/opensearch.yml + read_only: true + bind: + create_host_path: false + - <<: *bind + source: ${SECURITY_DIR:-../../../deployment/security}/certificates/opensearch/opensearch-shared.crt + target: /usr/share/opensearch/config/tls/node.crt + - <<: *bind + source: ${SECURITY_DIR:-../../../deployment/security}/certificates/opensearch/opensearch-shared.key + target: /usr/share/opensearch/config/tls/node.key + - <<: *bind + source: ${SECURITY_DIR:-../../../deployment/security}/certificates/root/root-ca.pem + target: /usr/share/opensearch/config/tls/ca.crt + networks: + cognet: + aliases: [opensearch-shared] + +volumes: + data: + +networks: + cognet: + name: cogstack-net diff --git a/apps/opensearch/docker/docker-compose.dev.yml b/apps/opensearch/docker/docker-compose.dev.yml new file mode 100644 index 00000000..412878fd --- /dev/null +++ b/apps/opensearch/docker/docker-compose.dev.yml @@ -0,0 +1,10 @@ +name: opensearch-dev + +services: + opensearch: + environment: + OPENSEARCH_ALLOW_DEFAULT_INIT_SECURITYINDEX: 'true' + +networks: + cognet: + name: opensearch-dev-net diff --git a/apps/opensearch/docker/docker-compose.prod.yml b/apps/opensearch/docker/docker-compose.prod.yml new file mode 100644 index 00000000..ac008b13 --- /dev/null +++ b/apps/opensearch/docker/docker-compose.prod.yml @@ -0,0 +1,5 @@ +name: opensearch + +networks: + cognet: + external: true diff --git a/apps/opensearch/docker/docker-compose.yml b/apps/opensearch/docker/docker-compose.yml new file mode 100644 index 00000000..30218390 --- /dev/null +++ b/apps/opensearch/docker/docker-compose.yml @@ -0,0 +1,5 @@ +name: opensearch + +include: + - path: docker-compose.base.yml + env_file: ../env/opensearch.env diff --git a/deployment/scripts/security/create_opensearch_client_admin_certs.sh b/deployment/scripts/security/create_opensearch_client_admin_certs.sh index 7d65142c..e6c912d1 100755 --- a/deployment/scripts/security/create_opensearch_client_admin_certs.sh +++ b/deployment/scripts/security/create_opensearch_client_admin_certs.sh @@ -4,8 +4,9 @@ # 🔐 Create the OpenSearch Dashboards and admin certificates and keys # # Usage: -# ./create_opensearch_client_admin_certs.sh [--admin-only] [--days DAYS] +# ./create_opensearch_client_admin_certs.sh [--admin-only|--dashboards-only] [--days DAYS] # --admin-only skips the Dashboards certificate and PKCS#12 bundle. +# --dashboards-only skips the admin client certificate. # DAYS is a positive integer. The default validity is 1,460 days. # # Requires: @@ -32,14 +33,13 @@ set -euo pipefail umask 077 days=1460 -create_dashboards=true -if [[ ${1:-} == --admin-only ]]; then - create_dashboards=false - shift -fi +mode= +case ${1:-} in + --admin-only|--dashboards-only) mode=$1; shift ;; +esac if (( $# > 0 )); then if [[ $# -ne 2 || "$1" != --days || ! "$2" =~ ^[1-9][0-9]*$ ]]; then - printf 'Usage: %s [--admin-only] [--days DAYS] (DAYS must be a positive integer)\n' "$0" >&2 + printf 'Usage: %s [--admin-only|--dashboards-only] [--days DAYS] (DAYS must be a positive integer)\n' "$0" >&2 exit 2 fi days=$2 @@ -58,14 +58,14 @@ for input in "$ca_cert" "$ca_key"; do fi done -roles=(admin) -files=(admin.crt admin.key.pem admin.csr) -if [[ "$create_dashboards" == true ]]; then +roles=() +files=() +if [[ "$mode" != --admin-only ]]; then # shellcheck source=password_prompt.sh source "$script_dir/password_prompt.sh" require_password OS_CERTIFICATE_PASSWORD - roles=(client admin) - files=(es_kibana_client.pem es_kibana_client.key es_kibana_client.csr es_kibana_client.p12 "${files[@]}") + roles=(client) + files=(es_kibana_client.pem es_kibana_client.key es_kibana_client.csr es_kibana_client.p12) sans=DNS:opensearch-dashboards,DNS:kibana if [[ -n "${OPENSEARCH_DASHBOARDS_DNS_NAMES:-}" ]]; then @@ -78,6 +78,10 @@ if [[ "$create_dashboards" == true ]]; then sans+=",DNS:${OPENSEARCH_DASHBOARDS_DNS_NAMES//,/,DNS:}" fi fi +if [[ "$mode" != --dashboards-only ]]; then + roles+=(admin) + files+=(admin.crt admin.key.pem admin.csr) +fi for file in "${files[@]}"; do if [[ -e "$output_dir/$file" || -L "$output_dir/$file" ]]; then @@ -123,7 +127,7 @@ for role in "${roles[@]}"; do openssl verify -CAfile "$ca_cert" "$scratch_dir/$cert" >/dev/null done -if [[ "$create_dashboards" == true ]]; then +if [[ "$mode" != --admin-only ]]; then 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:OS_CERTIFICATE_PASSWORD From 9d487d4fae36d26c305402274b99287e58c04278 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 12:21:13 +0000 Subject: [PATCH 28/63] opensearch smoke test. --- .github/workflows/docker_smoke_opensearch.yml | 85 +++++++------------ 1 file changed, 30 insertions(+), 55 deletions(-) diff --git a/.github/workflows/docker_smoke_opensearch.yml b/.github/workflows/docker_smoke_opensearch.yml index 62503584..39e416fe 100644 --- a/.github/workflows/docker_smoke_opensearch.yml +++ b/.github/workflows/docker_smoke_opensearch.yml @@ -22,7 +22,8 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 15 env: - SMOKE_PROJECT: opensearch-smoke-${{ github.run_id }} + SECURITY_DIR: ${{ github.workspace }}/deployment/security + KIBANA_PASSWORD: kibanaserver steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 @@ -30,66 +31,40 @@ jobs: distribution: temurin java-version: '21' - - name: Smoke test OpenSearch and Dashboards + - name: Start the default stack and log in + shell: bash run: | - set -euo pipefail - source apps/opensearch/env/opensearch.env - source apps/opensearch-dashboards/env/opensearch-dashboards.env - SECURITY_DIR=$(mktemp -d "$RUNNER_TEMP/opensearch-smoke.XXXXXX") password=$(openssl rand -hex 16) - export SECURITY_DIR ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" OS_CERTIFICATE_PASSWORD="$password" - make -C deployment certs-root - make -C deployment certs-opensearch-nodes NODES=opensearch-shared OPENSEARCH_NODE_DNS_NAMES=localhost - OPENSEARCH_DASHBOARDS_DNS_NAMES=localhost ./deployment/scripts/security/create_opensearch_client_admin_certs.sh - + export ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" OS_CERTIFICATE_PASSWORD="$password" + make -C deployment certs-root certs-opensearch + OPENSEARCH_DASHBOARDS_DNS_NAMES=localhost ./deployment/scripts/security/create_opensearch_client_admin_certs.sh --dashboards-only certs="$SECURITY_DIR/certificates/opensearch" - ca="$certs/elastic-stack-ca.crt.pem" - mkdir "$SECURITY_DIR"/{node,dashboards} - install -m 644 "$certs/opensearch-shared.crt" "$SECURITY_DIR/node/node.crt" - install -m 644 "$certs/opensearch-shared.key" "$SECURITY_DIR/node/node.key" - install -m 644 "$ca" "$SECURITY_DIR/node/ca.crt" - install -m 644 "$certs"/es_kibana_client.{pem,key} "$ca" "$SECURITY_DIR/dashboards/" - - docker network create "$SMOKE_PROJECT" - docker run -d --name "$SMOKE_PROJECT" --network "$SMOKE_PROJECT" --network-alias opensearch \ - -p 127.0.0.1::9200 -e discovery.type=single-node -e "OPENSEARCH_JAVA_OPTS=$OPENSEARCH_JAVA_OPTS" \ - -e DISABLE_INSTALL_DEMO_CONFIG=true -e OPENSEARCH_ALLOW_DEFAULT_INIT_SECURITYINDEX=true \ - -v "$PWD/apps/opensearch/config/opensearch.yml:/usr/share/opensearch/config/opensearch.yml:ro" \ - -v "$SECURITY_DIR/node:/usr/share/opensearch/config/tls:ro" "$OPENSEARCH_DOCKER_IMAGE" - - request=(curl -fsS --noproxy '*' --cacert "$ca" --connect-timeout 3 --max-time 20) - port=$(docker port "$SMOKE_PROJECT" 9200/tcp) - "${request[@]}" --retry 30 --retry-all-errors --retry-delay 3 --retry-max-time 180 \ - --cert "$certs/admin.crt" --key "$certs/admin.key.pem" \ - "https://localhost:${port##*:}/_cluster/health?wait_for_status=yellow&timeout=10s" | - jq -e '.timed_out == false and (.status == "green" or .status == "yellow")' + sudo chown 1000:1000 "$certs"/{opensearch-shared.key,es_kibana_client.key} + request=(curl -fsS --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" \ + --retry 30 --retry-all-errors --retry-delay 3 --max-time 10) - docker run -d --name "$SMOKE_PROJECT-dashboards" --network "$SMOKE_PROJECT" -p 127.0.0.1::5601 \ - -e "OPENSEARCH_DASHBOARDS_SERVER_NAME=$OPENSEARCH_DASHBOARDS_SERVER_NAME" \ - -e 'OPENSEARCH_HOSTS=["https://opensearch:9200"]' -e KIBANA_USER=kibanaserver -e KIBANA_PASSWORD=kibanaserver \ - -v "$PWD/apps/opensearch-dashboards/config/opensearch.yml:/usr/share/opensearch-dashboards/config/opensearch_dashboards.yml:ro" \ - -v "$SECURITY_DIR/dashboards:/certificates/elastic/opensearch:ro" \ - "$OPENSEARCH_DASHBOARDS_DOCKER_IMAGE" --status.allowAnonymous=true + search() { docker compose -f apps/opensearch/docker/docker-compose.yml "$@"; } + search up -d + "${request[@]}" --cert "$certs/admin.crt" --key "$certs/admin.key.pem" \ + -o /dev/null https://localhost:9200/_cluster/health + tar -C "$certs" -cf - admin.crt admin.key.pem | search exec -T opensearch tar -xf - -C /tmp + search exec -T opensearch plugins/opensearch-security/tools/securityadmin.sh \ + -icl -cd config/opensearch-security -cacert config/tls/ca.crt \ + -cert /tmp/admin.crt -key /tmp/admin.key.pem - port=$(docker port "$SMOKE_PROJECT-dashboards" 5601/tcp) - for _ in {1..40}; do - if "${request[@]}" "https://localhost:${port##*:}/api/status?v8format=true" 2>/dev/null | - jq -e '.status.core | .opensearch.level == "available" and .savedObjects.level == "available"'; then - exit 0 - fi - sleep 3 - done - echo 'Dashboards did not connect to OpenSearch' >&2 - exit 1 - - - name: Logs on failure - if: failure() - run: | - docker logs "$SMOKE_PROJECT" || true - docker logs "$SMOKE_PROJECT-dashboards" || true + docker compose -f apps/opensearch-dashboards/docker/docker-compose.yml up -d + "${request[@]}" -H 'osd-xsrf: smoke' --json '{"username":"kibanaro","password":"kibanaro"}' \ + https://localhost:5601/auth/login | jq -e '.username == "kibanaro"' - name: Cleanup if: always() + env: + SMOKE_JOB_STATUS: ${{ job.status }} run: | - docker rm -fv "$SMOKE_PROJECT" "$SMOKE_PROJECT-dashboards" || true - docker network rm "$SMOKE_PROJECT" || true + for app in opensearch-dashboards opensearch; do + compose=(docker compose -f "apps/$app/docker/docker-compose.yml") + if [[ "$SMOKE_JOB_STATUS" == failure ]]; then + "${compose[@]}" logs --tail 50 || true + fi + "${compose[@]}" down -v + done From 8c1f37403c86fff83dec420ca2eb119919c9606c Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 13:04:41 +0000 Subject: [PATCH 29/63] GHA fixes to NiFi and OpenSearch. --- .github/workflows/docker_smoke_nifi.yml | 63 ++++++++++--------- .github/workflows/docker_smoke_opensearch.yml | 11 ++-- 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/.github/workflows/docker_smoke_nifi.yml b/.github/workflows/docker_smoke_nifi.yml index e178fe95..7f252367 100644 --- a/.github/workflows/docker_smoke_nifi.yml +++ b/.github/workflows/docker_smoke_nifi.yml @@ -34,8 +34,13 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 45 env: - COMPOSE_PROJECT_NAME: nifi-smoke - SECURITY_DIR: ${{ github.workspace }}/deployment/security + COMPOSE_PROJECT_NAME: nifi-smoke-${{ github.run_id }}-${{ github.run_attempt }} + COGSTACK_GENERAL_ENV_FILE: /dev/null + COGSTACK_NIFI_ENV_FILE: /dev/null + NIFI_DOCKER_CPU_MIN: '1' + NIFI_DOCKER_CPU_MAX: '2' + NIFI_DOCKER_RAM: 4g + SINGLE_USER_CREDENTIALS_USERNAME: smoke steps: - uses: actions/checkout@v7 @@ -46,48 +51,44 @@ jobs: distribution: temurin java-version: '21' - - name: Generate smoke fixtures + - name: Start NiFi and verify login run: | + SECURITY_DIR=$(mktemp -d "$RUNNER_TEMP/nifi-smoke.XXXXXX") + printf 'SECURITY_DIR=%s\n' "$SECURITY_DIR" >> "$GITHUB_ENV" password="$(openssl rand -hex 16)" - ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" KEYSTORE_PASSWORD="$password" TRUSTSTORE_PASSWORD="$password" \ - make -C ../../../deployment certs + NIFI_SENSITIVE_PROPS_KEY=$(openssl rand -hex 16) + export SECURITY_DIR NIFI_SENSITIVE_PROPS_KEY + export KEYSTORE_PASSWORD="$password" TRUSTSTORE_PASSWORD="$password" SINGLE_USER_CREDENTIALS_PASSWORD="$password" + ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" make -C ../../../deployment certs # The published containers run as UID/GID 1000. sudo chown 1000:1000 "$SECURITY_DIR"/certificates/{nifi/nifi-keystore.jks,nginx/tls.key} - mkdir -p ../env - touch ../env/general.env - cat > ../env/nifi.env <> "$GITHUB_ENV" password=$(openssl rand -hex 16) export ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" OS_CERTIFICATE_PASSWORD="$password" make -C deployment certs-root certs-opensearch @@ -43,7 +46,7 @@ jobs: request=(curl -fsS --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" \ --retry 30 --retry-all-errors --retry-delay 3 --max-time 10) - search() { docker compose -f apps/opensearch/docker/docker-compose.yml "$@"; } + search() { docker compose -p "opensearch-$SMOKE_PROJECT_SUFFIX" -f apps/opensearch/docker/docker-compose.yml "$@"; } search up -d "${request[@]}" --cert "$certs/admin.crt" --key "$certs/admin.key.pem" \ -o /dev/null https://localhost:9200/_cluster/health @@ -52,7 +55,7 @@ jobs: -icl -cd config/opensearch-security -cacert config/tls/ca.crt \ -cert /tmp/admin.crt -key /tmp/admin.key.pem - docker compose -f apps/opensearch-dashboards/docker/docker-compose.yml up -d + docker compose -p "opensearch-dashboards-$SMOKE_PROJECT_SUFFIX" -f apps/opensearch-dashboards/docker/docker-compose.yml up -d "${request[@]}" -H 'osd-xsrf: smoke' --json '{"username":"kibanaro","password":"kibanaro"}' \ https://localhost:5601/auth/login | jq -e '.username == "kibanaro"' @@ -62,7 +65,7 @@ jobs: SMOKE_JOB_STATUS: ${{ job.status }} run: | for app in opensearch-dashboards opensearch; do - compose=(docker compose -f "apps/$app/docker/docker-compose.yml") + compose=(docker compose -p "$app-$SMOKE_PROJECT_SUFFIX" -f "apps/$app/docker/docker-compose.yml") if [[ "$SMOKE_JOB_STATUS" == failure ]]; then "${compose[@]}" logs --tail 50 || true fi From fe2e5fbaed1c4731fa88aedf3541c4a8b3889b20 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 14:27:31 +0000 Subject: [PATCH 30/63] Added OS roles+mappings. --- .github/workflows/docker_smoke_opensearch.yml | 40 ++++++++------ apps/opensearch/README.md | 22 +++++--- apps/opensearch/security/bootstrap.sh | 54 +++++++++++++++++++ apps/opensearch/security/roles.yml | 18 +++++++ apps/opensearch/security/roles_mapping.yml | 19 +++++++ apps/opensearch/security/tenants.yml | 6 +++ .../charts/opensearch-dashboards/README.md | 6 +++ deployment/charts/opensearch/README.md | 18 +++++-- deployment/charts/opensearch/security | 1 + 9 files changed, 157 insertions(+), 27 deletions(-) create mode 100644 apps/opensearch/security/bootstrap.sh create mode 100644 apps/opensearch/security/roles.yml create mode 100644 apps/opensearch/security/roles_mapping.yml create mode 100644 apps/opensearch/security/tenants.yml create mode 120000 deployment/charts/opensearch/security diff --git a/.github/workflows/docker_smoke_opensearch.yml b/.github/workflows/docker_smoke_opensearch.yml index cf7772ef..ac225062 100644 --- a/.github/workflows/docker_smoke_opensearch.yml +++ b/.github/workflows/docker_smoke_opensearch.yml @@ -23,7 +23,6 @@ jobs: timeout-minutes: 15 env: SMOKE_PROJECT_SUFFIX: smoke-${{ github.run_id }}-${{ github.run_attempt }} - KIBANA_PASSWORD: kibanaserver steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 @@ -31,39 +30,48 @@ jobs: distribution: temurin java-version: '21' - - name: Start the default stack and log in + - name: Start the default stack and verify access shell: bash run: | SECURITY_DIR=$(mktemp -d "$RUNNER_TEMP/opensearch-smoke.XXXXXX") - export SECURITY_DIR - printf 'SECURITY_DIR=%s\n' "$SECURITY_DIR" >> "$GITHUB_ENV" + KIBANA_PASSWORD=$(openssl rand -hex 16) + OS_NIFI_PASSWORD=$(openssl rand -hex 16) + OS_ANALYST_PASSWORD=$(openssl rand -hex 16) + export SECURITY_DIR KIBANA_PASSWORD OS_NIFI_PASSWORD OS_ANALYST_PASSWORD + printf '::add-mask::%s\n' "$KIBANA_PASSWORD" + printf 'SECURITY_DIR=%s\nKIBANA_PASSWORD=%s\n' "$SECURITY_DIR" "$KIBANA_PASSWORD" >> "$GITHUB_ENV" password=$(openssl rand -hex 16) export ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" OS_CERTIFICATE_PASSWORD="$password" make -C deployment certs-root certs-opensearch OPENSEARCH_DASHBOARDS_DNS_NAMES=localhost ./deployment/scripts/security/create_opensearch_client_admin_certs.sh --dashboards-only certs="$SECURITY_DIR/certificates/opensearch" sudo chown 1000:1000 "$certs"/{opensearch-shared.key,es_kibana_client.key} - request=(curl -fsS --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" \ - --retry 30 --retry-all-errors --retry-delay 3 --max-time 10) + request=(curl -sS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" --max-time 10) - search() { docker compose -p "opensearch-$SMOKE_PROJECT_SUFFIX" -f apps/opensearch/docker/docker-compose.yml "$@"; } - search up -d - "${request[@]}" --cert "$certs/admin.crt" --key "$certs/admin.key.pem" \ - -o /dev/null https://localhost:9200/_cluster/health - tar -C "$certs" -cf - admin.crt admin.key.pem | search exec -T opensearch tar -xf - -C /tmp - search exec -T opensearch plugins/opensearch-security/tools/securityadmin.sh \ - -icl -cd config/opensearch-security -cacert config/tls/ca.crt \ - -cert /tmp/admin.crt -key /tmp/admin.key.pem + search=(docker compose -p "opensearch-$SMOKE_PROJECT_SUFFIX" -f apps/opensearch/docker/docker-compose.yml) + "${search[@]}" up -d + bash apps/opensearch/security/bootstrap.sh "${search[@]}" exec -T opensearch + + printf '%s\n' '{"index":{"_id":"smoke"}}' '{"ok":true}' | + "${request[@]}" -f -u "nifi:$OS_NIFI_PASSWORD" -H 'Content-Type: application/x-ndjson' \ + --data-binary @- https://localhost:9200/nifi_smoke/_bulk | jq -e '.errors == false' + "${request[@]}" -f -u "cogstack_user:$OS_ANALYST_PASSWORD" \ + https://localhost:9200/nifi_smoke/_doc/smoke | jq -e '._source.ok == true' + status=$("${request[@]}" -u "cogstack_user:$OS_ANALYST_PASSWORD" -o /dev/null -w '%{http_code}' \ + -X PUT --json '{"ok":false}' https://localhost:9200/nifi_smoke/_doc/smoke) + [[ "$status" == 403 ]] docker compose -p "opensearch-dashboards-$SMOKE_PROJECT_SUFFIX" -f apps/opensearch-dashboards/docker/docker-compose.yml up -d - "${request[@]}" -H 'osd-xsrf: smoke' --json '{"username":"kibanaro","password":"kibanaro"}' \ - https://localhost:5601/auth/login | jq -e '.username == "kibanaro"' + "${request[@]}" -f --retry 30 --retry-all-errors --retry-delay 3 -H 'osd-xsrf: smoke' \ + --json "{\"username\":\"cogstack_user\",\"password\":\"$OS_ANALYST_PASSWORD\"}" \ + https://localhost:5601/auth/login | jq -e '.username == "cogstack_user"' - name: Cleanup if: always() env: SMOKE_JOB_STATUS: ${{ job.status }} run: | + [[ -n "${SECURITY_DIR:-}" ]] || exit 0 for app in opensearch-dashboards opensearch; do compose=(docker compose -p "$app-$SMOKE_PROJECT_SUFFIX" -f "apps/$app/docker/docker-compose.yml") if [[ "$SMOKE_JOB_STATUS" == failure ]]; then diff --git a/apps/opensearch/README.md b/apps/opensearch/README.md index c1726cb0..9bd40f4c 100644 --- a/apps/opensearch/README.md +++ b/apps/opensearch/README.md @@ -13,12 +13,22 @@ Set an absolute `SECURITY_DIR` to use a different certificate bundle. Each container runs as UID 1000 and needs read access to its own private key. The Dashboards certificate must cover the browser hostname. -Start OpenSearch with `docker compose up -d` in `apps/opensearch/docker`. -Initialize the Security index with your users and the admin client certificate -on the first start. Export the Dashboards service account's `KIBANA_PASSWORD`, -then run `docker compose up -d` in `apps/opensearch-dashboards/docker`. -Dashboards joins the OpenSearch network and listens at `https://localhost:5601`. -[OpenSearch Security initialization](https://docs.opensearch.org/latest/security/configuration/security-admin/) +Export `KIBANA_PASSWORD` from your deployment secrets for the `kibanaserver` +account. Set `OS_NIFI_PASSWORD`, `OS_PIPELINE_PASSWORD`, or `OS_ANALYST_PASSWORD` +to create `nifi`, `cogstack_pipeline`, or `cogstack_user`, respectively. +Run from the repository root on a fresh deployment. + +```bash +docker compose -f apps/opensearch/docker/docker-compose.yml up -d +bash apps/opensearch/security/bootstrap.sh \ + docker compose -f apps/opensearch/docker/docker-compose.yml exec -T opensearch +docker compose -f apps/opensearch-dashboards/docker/docker-compose.yml up -d +``` + +The bootstrap hashes the supplied passwords and applies the shared policy in +[`security/`](security/). Apply changes to existing clusters through the +[Security REST API](https://docs.opensearch.org/latest/security/api/roles/). +Dashboards listens at `https://localhost:5601`. Compose uses `.kibana` for saved objects to match the bundled Security role. Set `OPENSEARCHDASHBOARDS_INDEX` when your Security configuration uses another index. diff --git a/apps/opensearch/security/bootstrap.sh b/apps/opensearch/security/bootstrap.sh new file mode 100644 index 00000000..2eea0020 --- /dev/null +++ b/apps/opensearch/security/bootstrap.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail +umask 077 + +if (( $# == 0 )); then + printf 'Usage: bash %s \n' "$0" >&2 + exit 2 +fi +: "${KIBANA_PASSWORD:?Set the Dashboards service account password}" + +policy_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P) +certs=$(cd -- "${SECURITY_DIR:-$policy_dir/../../../deployment/security}/certificates/opensearch" && pwd -P) +scratch=$(mktemp -d) +trap 'rm -rf -- "$scratch"' EXIT +printf '%s\0' kibanaserver "$KIBANA_PASSWORD" nifi "${OS_NIFI_PASSWORD:-}" \ + cogstack_pipeline "${OS_PIPELINE_PASSWORD:-}" cogstack_user "${OS_ANALYST_PASSWORD:-}" > "$scratch/passwords" + +bootstrap=$(cat <<'BASH' +set -euo pipefail +umask 077 +work=$(mktemp -d) +trap 'rm -rf -- "$work"' EXIT +tar -xf - -C "$work" + +opensearch_home=${OPENSEARCH_HOME:-/usr/share/opensearch} +tools="$opensearch_home/plugins/opensearch-security/tools" +ca="$opensearch_home/config/tls/ca.crt" +status=$(curl -sS --noproxy '*' --retry 30 --retry-all-errors --retry-delay 3 --max-time 10 \ + --cacert "$ca" --cert "$work/admin.crt" --key "$work/admin.key.pem" \ + --head --output /dev/null --write-out '%{http_code}' https://localhost:9200/.opendistro_security) +if [[ "$status" != 404 ]]; then + printf 'Bootstrap requires an empty Security index (index check returned HTTP %s).\n' "$status" >&2 + exit 1 +fi + +cp "$opensearch_home/config/opensearch-security"/{action_groups,allowlist,audit,config,nodes_dn}.yml "$work/" +{ + printf '_meta:\n type: internalusers\n config_version: 2\n' + while IFS= read -r -d '' user && IFS= read -r -d '' password; do + [[ -n "$password" ]] || continue + hash=$("$tools/hash.sh" -p "$password") + printf '%s:\n hash: "%s"\n' "$user" "$hash" + done < "$work/passwords" +} > "$work/internal_users.yml" +rm -- "$work/passwords" + +"$tools/securityadmin.sh" -icl -cd "$work" -cacert "$ca" \ + -cert "$work/admin.crt" -key "$work/admin.key.pem" +BASH +) + +tar -cf - -C "$scratch" passwords -C "$certs" admin.crt admin.key.pem \ + -C "$policy_dir" roles.yml roles_mapping.yml tenants.yml | + "$@" bash -c "$bootstrap" diff --git a/apps/opensearch/security/roles.yml b/apps/opensearch/security/roles.yml new file mode 100644 index 00000000..eb1eb737 --- /dev/null +++ b/apps/opensearch/security/roles.yml @@ -0,0 +1,18 @@ +_meta: + type: roles + config_version: 2 + +cogstack_ingest: + cluster_permissions: ['indices:data/write/bulk'] + index_permissions: + - index_patterns: ['nifi_*', 'cogstack_*'] + allowed_actions: [create_index, index] + +cogstack_access: + cluster_permissions: [cluster_composite_ops_ro] + index_permissions: + - index_patterns: ['nifi_*', 'cogstack_*'] + allowed_actions: [read] + tenant_permissions: + - tenant_patterns: [cogstack_tenant] + allowed_actions: [kibana_all_read] diff --git a/apps/opensearch/security/roles_mapping.yml b/apps/opensearch/security/roles_mapping.yml new file mode 100644 index 00000000..9eb7b9c0 --- /dev/null +++ b/apps/opensearch/security/roles_mapping.yml @@ -0,0 +1,19 @@ +_meta: + type: rolesmapping + config_version: 2 + +cogstack_ingest: + backend_roles: [cogstack_ingest] + users: [nifi, cogstack_pipeline] + +cogstack_access: + backend_roles: [cogstack_access] + users: [cogstack_user] + +kibana_user: + backend_roles: [cogstack_access] + users: [cogstack_user] + +kibana_server: + reserved: true + users: [kibanaserver] diff --git a/apps/opensearch/security/tenants.yml b/apps/opensearch/security/tenants.yml new file mode 100644 index 00000000..b538c77a --- /dev/null +++ b/apps/opensearch/security/tenants.yml @@ -0,0 +1,6 @@ +_meta: + type: tenants + config_version: 2 + +cogstack_tenant: + description: CogStack dashboards diff --git a/deployment/charts/opensearch-dashboards/README.md b/deployment/charts/opensearch-dashboards/README.md index ad54ee2a..f35765ec 100644 --- a/deployment/charts/opensearch-dashboards/README.md +++ b/deployment/charts/opensearch-dashboards/README.md @@ -4,6 +4,12 @@ Install this release in the same namespace as [OpenSearch](../opensearch/README. Dashboards connects to the OpenSearch Service and stores its saved objects in OpenSearch. +For the shared Security policy, set `opensearch-dashboards.opensearchAccount.secret` +to a Secret in the release namespace with keys `username`, `password`, and `cookie`. +Use `kibanaserver`, the same password as `KIBANA_PASSWORD` at bootstrap, and a +random cookie key. Use `opensearchDashboards.index: .kibana` in a fresh deployment +to match the built-in `kibana_server` role. + ```bash helm repo add opensearch https://opensearch-project.github.io/helm-charts/ helm dependency build deployment/charts/opensearch-dashboards diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index bed477be..26283096 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -21,8 +21,8 @@ certs="${SECURITY_DIR:-deployment/security}/certificates/opensearch" ``` For a packaged chart, set `chart=./opensearch` after extracting it and point -`certs` at your certificate directory. The archive contains the chart dependency -and the shared OpenSearch config. +`certs` at your certificate directory. The archive contains the chart dependency, +the shared OpenSearch config, and the Security policy. ```bash kubectl create namespace search @@ -37,9 +37,17 @@ helm upgrade --install opensearch "$chart" -n search \ Helm loads the bundled [`opensearch.yml`](config/opensearch.yml) through `--set-file`. Transport TLS checks the CA and shared node DN. Set `KUBE_NAMESPACE` or `CLUSTER_DOMAIN` when issuing the certificate if either differs from `search` -or `cluster.local`. For a fresh cluster, initialize the Security index with -your Security plugin configuration and the local `admin.crt` and `admin.key.pem`. -[`securityadmin.sh` instructions](https://docs.opensearch.org/latest/security/configuration/security-admin/) +or `cluster.local`. + +Export `KIBANA_PASSWORD` for `kibanaserver`. Set `OS_NIFI_PASSWORD`, +`OS_PIPELINE_PASSWORD`, or `OS_ANALYST_PASSWORD` to create `nifi`, +`cogstack_pipeline`, or `cogstack_user`, respectively. Export the absolute +`SECURITY_DIR` for a packaged chart or custom certificate location. Once the +OpenSearch pod is running, initialize Security before starting Dashboards. + +```bash +bash "$chart/security/bootstrap.sh" kubectl -n search exec -i opensearch-cluster-master-0 -- +``` From inside the cluster, clients can use `https://opensearch-cluster-master.search.svc:9200`. diff --git a/deployment/charts/opensearch/security b/deployment/charts/opensearch/security new file mode 120000 index 00000000..b8f68618 --- /dev/null +++ b/deployment/charts/opensearch/security @@ -0,0 +1 @@ +../../../apps/opensearch/security \ No newline at end of file From f241c137c790fc8939dd4d854ba0f0f0865e8461 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 16:12:41 +0000 Subject: [PATCH 31/63] Extra makefile commands in /deployment/ for env subst. --- deployment/Makefile | 36 +++++++++++++++++++ deployment/charts/README.md | 8 +++-- .../opensearch-dashboards/values.env.yaml | 9 +++++ deployment/charts/opensearch/values.env.yaml | 21 +++++++++++ deployment/charts/opensearch/values.yaml | 7 ++++ 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 deployment/charts/opensearch-dashboards/values.env.yaml create mode 100644 deployment/charts/opensearch/values.env.yaml diff --git a/deployment/Makefile b/deployment/Makefile index f6f5609c..abb458c2 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -45,6 +45,42 @@ certs-opensearch-nodes: ## Generate OpenSearch node certificates for NODES="node # ====================================================================================================================================================== +.PHONY: helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards + +helm-values-nifi: ## Render NiFi values.yaml from env/nifi.env +helm-values-nginx: ## Render NGINX values.yaml from env/nifi.env and optional env/nginx.env +helm-values-opensearch: ## Render OpenSearch values.yaml from env/opensearch.env +helm-values-opensearch-dashboards: ## Render OpenSearch Dashboards values.yaml from env/opensearch-dashboards.env + +helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards: + @set -e; \ + service=$(@:helm-values-%=%); \ + env_file="./env/$$service.env"; \ + set -a; \ + if [ "$$service" = nginx ]; then \ + : "$${NGINX_DOCKER_CPU_MIN:=1}" "$${NGINX_DOCKER_CPU_MAX:=1}" "$${NGINX_DOCKER_RAM:=512M}"; \ + if [ -f "$$env_file" ] && [ -f ./env/nifi.env ]; then . ./env/nifi.env; fi; \ + [ -f "$$env_file" ] || env_file=./env/nifi.env; \ + fi; \ + . "$$env_file"; \ + set +a; \ + chart="charts/$$service"; \ + template="$$chart/values.env.yaml"; \ + variables=$$(envsubst --variables "$$(cat "$$template")"); \ + for name in $$variables; do \ + value="$${!name:?Set $$name in $$env_file before rendering}"; \ + if [[ "$$name" == *_DOCKER_RAM && "$$value" =~ ^([0-9]+([.][0-9]+)?)([kmgtp])[bB]?$$ ]]; then \ + unit=$$(printf '%s' "$${BASH_REMATCH[3]}" | tr kmgtp KMGTP); \ + export "$$name=$${BASH_REMATCH[1]}$${unit}i"; \ + fi; \ + done; \ + tmp=$$(mktemp -d "$$chart/.values.XXXXXX"); \ + trap 'rm -rf -- "$$tmp"' EXIT; \ + envsubst < "$$template" > "$$tmp/values.yaml"; \ + mv -- "$$tmp/values.yaml" "$$chart/values.yaml" + +# ====================================================================================================================================================== + help: ## Show deployment commands @printf '%s\n' 'Deployment commands' @awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[[:alnum:]_-]+$$/ { printf " %-30s %s\n", $$1, $$2 }' "$(lastword $(MAKEFILE_LIST))" diff --git a/deployment/charts/README.md b/deployment/charts/README.md index 2d87edec..bcd557de 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -25,8 +25,12 @@ helm template cogstack-nginx deployment/charts/nginx --namespace cogstack ``` See each chart's README for the ConfigMaps, Secrets and storage needed before -installation. `values.env.yaml` files are optional `envsubst` inputs; render -their environment placeholders before supplying them to Helm. +installation. Run `make -C deployment helm-values-` for NiFi, NGINX, +OpenSearch, or OpenSearch Dashboards to render `values.env.yaml` into +`values.yaml` using `deployment/env/.env`. NGINX reads `nifi.env` for +the upstream connection and applies `nginx.env` when present. The local +`deployment/env/nifi.env` can link to `apps/nifi/env/nifi.env`. Docker memory +sizes such as `2g` render as `2Gi`. ## Validation and releases diff --git a/deployment/charts/opensearch-dashboards/values.env.yaml b/deployment/charts/opensearch-dashboards/values.env.yaml new file mode 100644 index 00000000..65464a6f --- /dev/null +++ b/deployment/charts/opensearch-dashboards/values.env.yaml @@ -0,0 +1,9 @@ +opensearch-dashboards: + opensearchHosts: https://opensearch-cluster-master:9200 + resources: + requests: + cpu: "${OPENSEARCH_DASHBOARDS_DOCKER_CPU_MIN}" + memory: "${OPENSEARCH_DASHBOARDS_DOCKER_RAM}" + limits: + cpu: "${OPENSEARCH_DASHBOARDS_DOCKER_CPU_MAX}" + memory: "${OPENSEARCH_DASHBOARDS_DOCKER_RAM}" diff --git a/deployment/charts/opensearch/values.env.yaml b/deployment/charts/opensearch/values.env.yaml new file mode 100644 index 00000000..fca1991f --- /dev/null +++ b/deployment/charts/opensearch/values.env.yaml @@ -0,0 +1,21 @@ +opensearch: + # Each StatefulSet pod gets its own claim from the cluster's default StorageClass. + persistence: + enabled: true + size: 8Gi + # Supply opensearch.yml with --set-file as shown in the README. + extraEnvs: + - name: DISABLE_INSTALL_DEMO_CONFIG + value: "true" + secretMounts: + - name: node-tls + secretName: opensearch-node-tls + path: /usr/share/opensearch/config/tls + defaultMode: 0440 + resources: + requests: + cpu: "${OPENSEARCH_DOCKER_CPU_MIN}" + memory: "${OPENSEARCH_DOCKER_RAM}" + limits: + cpu: "${OPENSEARCH_DOCKER_CPU_MAX}" + memory: "${OPENSEARCH_DOCKER_RAM}" diff --git a/deployment/charts/opensearch/values.yaml b/deployment/charts/opensearch/values.yaml index dc5f3ebf..e7325889 100644 --- a/deployment/charts/opensearch/values.yaml +++ b/deployment/charts/opensearch/values.yaml @@ -12,3 +12,10 @@ opensearch: secretName: opensearch-node-tls path: /usr/share/opensearch/config/tls defaultMode: 0440 + resources: + requests: + cpu: "1" + memory: "2Gi" + limits: + cpu: "1" + memory: "2Gi" From 67594056183b7287e26035bb11d9371df0d63063 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 16:27:37 +0000 Subject: [PATCH 32/63] Changed NiFi+nginx service charts. --- deployment/charts/nginx/README.md | 2 +- deployment/charts/nginx/templates/configmap.yaml | 2 +- deployment/charts/nginx/values.env.yaml | 2 +- deployment/charts/nginx/values.yaml | 2 +- deployment/charts/nifi/README.md | 12 ++++++++---- deployment/charts/nifi/templates/service.yaml | 5 +++-- deployment/charts/nifi/templates/statefulset.yaml | 2 +- deployment/scripts/README.md | 4 ++-- deployment/scripts/security/create_nifi_certs.sh | 2 +- .../security/templates/ssl-extensions-x509.cnf | 2 +- 10 files changed, 20 insertions(+), 15 deletions(-) diff --git a/deployment/charts/nginx/README.md b/deployment/charts/nginx/README.md index 3f9b9e2e..31ecc1e1 100644 --- a/deployment/charts/nginx/README.md +++ b/deployment/charts/nginx/README.md @@ -20,7 +20,7 @@ certificate Secret names with `tls.rootCASecret` and `tls.existingSecret`. The chart references these inputs rather than creating them from host files. By default, the proxy connects to -`cogstack-nifi-web..svc.cluster.local:8443`, which matches the +`cogstack-nifi..svc.cluster.local:8443`, which matches the Service from `deployment/charts/nifi`. Set `nifi.host` and `nifi.port` for another upstream. `nifi.tlsName` must match the upstream certificate's TLS name; it defaults to `nifi`. diff --git a/deployment/charts/nginx/templates/configmap.yaml b/deployment/charts/nginx/templates/configmap.yaml index eeddd90f..e2050ab8 100644 --- a/deployment/charts/nginx/templates/configmap.yaml +++ b/deployment/charts/nginx/templates/configmap.yaml @@ -3,7 +3,7 @@ kind: ConfigMap metadata: name: cogstack-nginx-env data: - NIFI_UPSTREAM_HOST: {{ default (printf "cogstack-nifi-web.%s.svc.cluster.local" .Release.Namespace) .Values.nifi.host | quote }} + NIFI_UPSTREAM_HOST: {{ default (printf "cogstack-nifi.%s.svc.cluster.local" .Release.Namespace) .Values.nifi.host | quote }} NIFI_UPSTREAM_PORT: {{ .Values.nifi.port | quote }} NIFI_UPSTREAM_TLS_NAME: {{ .Values.nifi.tlsName | quote }} NIFI_INTERNAL_PORT_NGINX: {{ .Values.nginx.internalPort | quote }} diff --git a/deployment/charts/nginx/values.env.yaml b/deployment/charts/nginx/values.env.yaml index 7b1227fa..03d7822b 100644 --- a/deployment/charts/nginx/values.env.yaml +++ b/deployment/charts/nginx/values.env.yaml @@ -9,7 +9,7 @@ nginx: internalPort: ${NIFI_INTERNAL_PORT_NGINX} nifi: - # Empty uses cogstack-nifi-web..svc.cluster.local; override with a full DNS name. + # Empty uses cogstack-nifi..svc.cluster.local; override with a full DNS name. host: "" port: ${NIFI_INTERNAL_PORT} tlsName: ${NIFI_UPSTREAM_TLS_NAME} diff --git a/deployment/charts/nginx/values.yaml b/deployment/charts/nginx/values.yaml index 7fc8e7df..8bb09bf2 100644 --- a/deployment/charts/nginx/values.yaml +++ b/deployment/charts/nginx/values.yaml @@ -9,7 +9,7 @@ nginx: internalPort: 8443 nifi: - # Empty uses cogstack-nifi-web..svc.cluster.local; override with a full DNS name. + # Empty uses cogstack-nifi..svc.cluster.local; override with a full DNS name. host: "" port: 8443 tlsName: nifi diff --git a/deployment/charts/nifi/README.md b/deployment/charts/nifi/README.md index ba4c074e..2b14c842 100644 --- a/deployment/charts/nifi/README.md +++ b/deployment/charts/nifi/README.md @@ -43,7 +43,7 @@ required by the deployment. For local access: ```bash -kubectl -n cogstack port-forward svc/cogstack-nifi-web 8443:8443 +kubectl -n cogstack port-forward svc/cogstack-nifi 8443:8443 ``` Open `https://localhost:8443/nifi/` using the deployment's trusted CA and @@ -86,7 +86,11 @@ passing it to Helm; Helm does not expand `${VARIABLE}` placeholders. ## Resource names -The chart currently uses fixed `cogstack-nifi` workload and headless Service names -and a `cogstack-nifi-web` web Service. Use separate namespaces for independent -deployments. Increasing `replicaCount` also requires appropriate NiFi cluster +The `cogstack-nifi` StatefulSet uses `cogstack-nifi-headless` for pod DNS. +Clients connect to the `cogstack-nifi` ClusterIP Service. Use separate namespaces +for independent deployments. Increasing `replicaCount` requires NiFi cluster configuration, node identities and certificates in the supplied runtime inputs. + +Upgrades from the previous Service names require recreating the StatefulSet and +the old `cogstack-nifi` headless Service. Keep the existing PVCs for the recreated +StatefulSet. diff --git a/deployment/charts/nifi/templates/service.yaml b/deployment/charts/nifi/templates/service.yaml index 387a45db..f3c24182 100644 --- a/deployment/charts/nifi/templates/service.yaml +++ b/deployment/charts/nifi/templates/service.yaml @@ -1,8 +1,9 @@ apiVersion: v1 kind: Service metadata: - name: cogstack-nifi + name: cogstack-nifi-headless spec: + type: ClusterIP clusterIP: None selector: app: cogstack-nifi @@ -13,7 +14,7 @@ spec: apiVersion: v1 kind: Service metadata: - name: cogstack-nifi-web + name: cogstack-nifi spec: type: ClusterIP selector: diff --git a/deployment/charts/nifi/templates/statefulset.yaml b/deployment/charts/nifi/templates/statefulset.yaml index 815c814d..f9ab4966 100644 --- a/deployment/charts/nifi/templates/statefulset.yaml +++ b/deployment/charts/nifi/templates/statefulset.yaml @@ -5,7 +5,7 @@ metadata: name: cogstack-nifi spec: - serviceName: cogstack-nifi + serviceName: cogstack-nifi-headless replicas: {{ .Values.replicaCount }} persistentVolumeClaimRetentionPolicy: whenDeleted: Retain diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index 6ac712bf..3ad8a19d 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -36,7 +36,7 @@ The legacy `NIFI_KEYSTORE_PASSWORD` and `NIFI_TRUSTSTORE_PASSWORD` names are 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`. +`nifi`, `localhost`, `cogstack-nifi`, `cogstack-nifi-headless`, and `127.0.0.1`. ```bash ./deployment/scripts/security/create_nifi_certs.sh @@ -50,7 +50,7 @@ NIFI_UPSTREAM_TLS_NAME=nifi.internal.example ./deployment/scripts/security/creat ``` For Kubernetes, set `KUBE_NAMESPACE` to include the web Service's full name. -For example, `cogstack` adds `cogstack-nifi-web.cogstack.svc.cluster.local`. +For example, `cogstack` adds `cogstack-nifi.cogstack.svc.cluster.local`. Set `CLUSTER_DOMAIN` if your cluster uses a domain other than `cluster.local`. ```bash diff --git a/deployment/scripts/security/create_nifi_certs.sh b/deployment/scripts/security/create_nifi_certs.sh index 5abf300f..eb72352a 100755 --- a/deployment/scripts/security/create_nifi_certs.sh +++ b/deployment/scripts/security/create_nifi_certs.sh @@ -85,7 +85,7 @@ 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}") + names+=("cogstack-nifi.${KUBE_NAMESPACE}.svc.${CLUSTER_DOMAIN:-cluster.local}") fi { diff --git a/deployment/security/templates/ssl-extensions-x509.cnf b/deployment/security/templates/ssl-extensions-x509.cnf index a58badde..1b626038 100755 --- a/deployment/security/templates/ssl-extensions-x509.cnf +++ b/deployment/security/templates/ssl-extensions-x509.cnf @@ -23,7 +23,7 @@ authorityKeyIdentifier = keyid,issuer DNS.1 = nifi DNS.2 = localhost DNS.3 = cogstack-nifi -DNS.4 = cogstack-nifi-web +DNS.4 = cogstack-nifi-headless IP.1 = 127.0.0.1 [req] From bb8b5e9c661324f2f5d0d921d73c14bdf730e0fe Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 17:45:59 +0000 Subject: [PATCH 33/63] Makefile commands for helm values. --- deployment/Makefile | 20 ++++++++++++++++++-- deployment/env/certificates.env | 5 +---- deployment/env/general.env | 28 ++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 deployment/env/general.env diff --git a/deployment/Makefile b/deployment/Makefile index abb458c2..ed179984 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -1,7 +1,7 @@ SHELL := /usr/bin/env bash .SHELLFLAGS := -o pipefail -c -.PHONY: setup-install-pre-requisites setup-k3s-cluster-init setup-verify setup-k3s-cluster-remote help +.PHONY: setup-install-pre-requisites setup-k3s-cluster-init setup-verify setup-k3s-cluster-remote setup-k3s-namespace help setup-install-pre-requisites: ## Install host tools, Docker, K3s, and Helm locally by default bash scripts/installation_utils/install_os_tools_and_software.sh @@ -12,17 +12,33 @@ setup-k3s-cluster-init: ## Initialize the first K3s server on this machine setup-k3s-cluster-remote: ## Install prerequisites, initialize the first server, and join the rest over SSH bash scripts/installation_utils/setup_k3s_cluster.sh $(NODES) +setup-k3s-namespace: ## Create the namespace configured in env/general.env + @set -eo pipefail; \ + . ./env/general.env; \ + kubectl create namespace "$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" --dry-run=client -o yaml | \ + kubectl apply --server-side --field-manager=cogstack-namespace -f - + setup-verify: ## Check local Docker, Docker Compose, and K3s access without sudo bash scripts/installation_utils/verify_docker.sh bash scripts/installation_utils/verify_k3s.sh # ====================================================================================================================================================== -.PHONY: certs certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-nodes +.PHONY: certs certs-all certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-nodes certs: certs-root ## Generate the root CA and NiFi and NGINX certificates $(MAKE) certs-nifi certs-nginx +certs-all: ## Generate the root CA and NiFi, NGINX, OpenSearch, and Dashboards certificates + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + export CLUSTER_DOMAIN; \ + $(MAKE) certs KUBE_NAMESPACE="$$namespace"; \ + $(MAKE) certs-opensearch KUBE_NAMESPACE="$$namespace" + OPENSEARCH_DASHBOARDS_DNS_NAMES="$${OPENSEARCH_DASHBOARDS_DNS_NAMES:-localhost}" \ + bash scripts/security/create_opensearch_client_admin_certs.sh --dashboards-only + certs-root: ## Generate the root CA bundle bash scripts/security/create_root_ca_cert.sh diff --git a/deployment/env/certificates.env b/deployment/env/certificates.env index bf9fee25..bbd30951 100644 --- a/deployment/env/certificates.env +++ b/deployment/env/certificates.env @@ -4,6 +4,7 @@ # # Load from the repository root before running a generator. # set -a +# source deployment/env/general.env # source deployment/env/certificates.env # set +a @@ -15,10 +16,6 @@ SECURITY_DIR= 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 - # Browser-facing NGINX DNS names or IP addresses, comma-separated. # Blank uses localhost,127.0.0.1. NGINX_TLS_NAMES= diff --git a/deployment/env/general.env b/deployment/env/general.env new file mode 100644 index 00000000..5c8a2e08 --- /dev/null +++ b/deployment/env/general.env @@ -0,0 +1,28 @@ +# any other variables that you may want to use go here + +# Kubernetes namespace and DNS domain. +KUBE_NAMESPACE=cogstack +CLUSTER_DOMAIN=cluster.local + +# This is used to explicitly inform systems that run on Apple silicon to emulate this architecture +# set only CPU_ARCHITECTURE to amd/arm64 +# remove if this causes issues on any other platform +# possible values: amd64, arm64 +CPU_ARCHITECTURE=arm64 +DOCKER_DEFAULT_PLATFORM=linux/${CPU_ARCHITECTURE:-amd64} +COMPOSE_BAKE=True + +COGSTACK_ADMIN_EMAIL=admin@cogstack.net + +# used in NiFi for the timezone +TZ="Europe/London" + +# IMPORTANT: this is used to prefix all volumes created by docker-compose for ALL services, this includes SUBMODULES +# this has been added for backward compatibility with existing deployments +VOLUME_PREFIX=deploy_ + + +# this is the default, for containers which dont rely on individual settings +DOCKER_SHM_SIZE=512m +DOCKER_LOG_SIZE_PER_FILE="100m" +DOCKER_LOG_NUM_FILES=10 From 01b2e9d1e2c93acd90e7eb35c37120561d356700 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 17:49:29 +0000 Subject: [PATCH 34/63] Makefile updates. --- deployment/Makefile | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/deployment/Makefile b/deployment/Makefile index ed179984..2312cef5 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -61,8 +61,48 @@ certs-opensearch-nodes: ## Generate OpenSearch node certificates for NODES="node # ====================================================================================================================================================== -.PHONY: helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards +.PHONY: k3s-load-certs k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-nginx k3s-load-certs-opensearch +k3s-load-certs: k3s-load-certs-all ## Alias for k3s-load-certs-all +k3s-load-certs-all: ## Load all TLS Secrets for NiFi, NGINX and OpenSearch +k3s-load-certs-root-ca: ## Load the public CA and NiFi truststore into cogstack-root-ca +k3s-load-certs-nifi: ## Load the NiFi keystore into nifi-tls +k3s-load-certs-nginx: ## Load the NGINX certificate and key into nginx-tls +k3s-load-certs-opensearch: ## Load the shared node certificate into opensearch-node-tls + +k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-nginx k3s-load-certs-opensearch: + @set -eo pipefail; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + certs="$${SECURITY_DIR:-security}/certificates"; \ + services=$(@:k3s-load-certs-%=%); \ + if [ "$$services" = all ]; then services="root-ca nifi nginx opensearch"; fi; \ + manifests=(); \ + for service in $$services; do \ + case "$$service" in \ + root-ca) secret=(generic cogstack-root-ca \ + --from-file="ca.crt=$$certs/root/root-ca.pem" \ + --from-file="truststore.jks=$$certs/nifi/nifi-truststore.jks");; \ + nifi) secret=(generic nifi-tls \ + --from-file="nifi-keystore.jks=$$certs/nifi/nifi-keystore.jks");; \ + nginx) secret=(tls nginx-tls \ + --cert="$$certs/nginx/tls.crt" --key="$$certs/nginx/tls.key");; \ + opensearch) secret=(generic opensearch-node-tls \ + --from-file="node.crt=$$certs/opensearch/opensearch-shared.crt" \ + --from-file="node.key=$$certs/opensearch/opensearch-shared.key" \ + --from-file="ca.crt=$$certs/opensearch/elastic-stack-ca.crt.pem");; \ + esac; \ + manifest=$$(kubectl -n "$$namespace" create secret "$${secret[@]}" --dry-run=client -o yaml); \ + manifests+=("$$manifest"); \ + done; \ + printf -- '---\n%s\n' "$${manifests[@]}" | \ + kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-certificates -f - + +# ====================================================================================================================================================== + +.PHONY: helm-values-all helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards + +helm-values-all: helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards ## Render all four charts' environment-based values helm-values-nifi: ## Render NiFi values.yaml from env/nifi.env helm-values-nginx: ## Render NGINX values.yaml from env/nifi.env and optional env/nginx.env helm-values-opensearch: ## Render OpenSearch values.yaml from env/opensearch.env From a442989dfe2f5fec2b03f18b750f13a003a0911c Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Wed, 25 Nov 2026 20:11:45 +0000 Subject: [PATCH 35/63] Whitelist/blacklisting for nifi and os. --- apps/opensearch/env/opensearch.env | 5 ++++ deployment/Makefile | 25 +++++++++++++++++++ deployment/charts/nifi/README.md | 8 +++--- .../charts/nifi/templates/statefulset.yaml | 12 +++++++++ deployment/charts/nifi/values.env.yaml | 1 + deployment/charts/nifi/values.yaml | 1 + .../charts/opensearch-dashboards/values.yaml | 7 ++++++ deployment/charts/opensearch/README.md | 22 ++++++++++++++-- deployment/charts/opensearch/values.env.yaml | 3 +++ deployment/charts/opensearch/values.yaml | 3 +++ 10 files changed, 81 insertions(+), 6 deletions(-) diff --git a/apps/opensearch/env/opensearch.env b/apps/opensearch/env/opensearch.env index 5ec1fedf..a348afe0 100644 --- a/apps/opensearch/env/opensearch.env +++ b/apps/opensearch/env/opensearch.env @@ -10,6 +10,11 @@ OPENSEARCH_DOCKER_IMAGE=opensearchproject/opensearch:3.9.0@sha256:3b55f6b6249cfdb92b52ee59adc8a266203ba9ef9f5d82544fad6f1af2f3609e +# Each K3s replica runs on a separate Kubernetes node. +OPENSEARCH_K3S_REPLICA_COUNT=1 +# Comma-separated Kubernetes node names to exclude. +OPENSEARCH_K3S_BLACKLIST= + OPENSEARCH_LOG_LEVEL=INFO OPENSEARCH_SEED_HOSTS=localhost,elasticsearch-2,elasticsearch-1 diff --git a/deployment/Makefile b/deployment/Makefile index 2312cef5..fef67b2c 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -120,6 +120,31 @@ helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch fi; \ . "$$env_file"; \ set +a; \ + case "$$service" in \ + nifi) node_setting=NIFI_K3S_WHITELIST; export NIFI_K3S_ALLOWED_NODES='[]';; \ + opensearch) node_setting=OPENSEARCH_K3S_BLACKLIST; export OPENSEARCH_K3S_NODE_AFFINITY='{}';; \ + *) node_setting=;; \ + esac; \ + if [ -n "$$node_setting" ]; then \ + node_list="$${!node_setting}"; \ + IFS=$$' ,\t' read -r -a nodes <<< "$${node_list//$$'\n'/ }"; \ + if (( $${#nodes[@]} )); then \ + node_label='[a-z0-9]([a-z0-9-]*[a-z0-9])?'; \ + for node in "$${nodes[@]}"; do \ + if [[ $${#node} -gt 253 || ! "$$node" =~ ^$$node_label([.]$$node_label)*$$ ]]; then \ + printf 'Invalid Kubernetes node name in %s: %s\n' "$$node_setting" "$$node" >&2; \ + exit 1; \ + fi; \ + done; \ + if [ "$$service" = nifi ]; then \ + printf -v names '"%s",' "$${nodes[@]}"; \ + NIFI_K3S_ALLOWED_NODES="[$${names%,}]"; \ + else \ + printf -v fields '{key: metadata.name, operator: NotIn, values: ["%s"]},' "$${nodes[@]}"; \ + OPENSEARCH_K3S_NODE_AFFINITY="{requiredDuringSchedulingIgnoredDuringExecution: {nodeSelectorTerms: [{matchFields: [$${fields%,}]}]}}"; \ + fi; \ + fi; \ + fi; \ chart="charts/$$service"; \ template="$$chart/values.env.yaml"; \ variables=$$(envsubst --variables "$$(cat "$$template")"); \ diff --git a/deployment/charts/nifi/README.md b/deployment/charts/nifi/README.md index 2b14c842..f3d6afc8 100644 --- a/deployment/charts/nifi/README.md +++ b/deployment/charts/nifi/README.md @@ -79,10 +79,10 @@ with the projected public CA. ## Environment-based values -`values.yaml` contains reusable defaults. `values.env.yaml` is an optional -`envsubst` input for deployment-specific UID/GID, ports and resource limits. -Populate all referenced variables and render it to a separate values file before -passing it to Helm; Helm does not expand `${VARIABLE}` placeholders. +Run `make -C deployment helm-values-nifi` to render `values.env.yaml` using +`deployment/env/nifi.env`. Set `NIFI_K3S_WHITELIST` to comma-separated names +from `kubectl get nodes` to populate `allowedNodes`. An empty list allows any +otherwise eligible node. ## Resource names diff --git a/deployment/charts/nifi/templates/statefulset.yaml b/deployment/charts/nifi/templates/statefulset.yaml index f9ab4966..3844fa3d 100644 --- a/deployment/charts/nifi/templates/statefulset.yaml +++ b/deployment/charts/nifi/templates/statefulset.yaml @@ -20,6 +20,18 @@ spec: annotations: checksum/tls-config: {{ include (print $.Template.BasePath "/tls-configmap.yaml") . | sha256sum }} spec: + {{- with .Values.allowedNodes }} + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + {{- range . }} + - matchFields: + - key: metadata.name + operator: In + values: [{{ . | quote }}] + {{- end }} + {{- end }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} diff --git a/deployment/charts/nifi/values.env.yaml b/deployment/charts/nifi/values.env.yaml index cf3b53f5..d57bbe24 100644 --- a/deployment/charts/nifi/values.env.yaml +++ b/deployment/charts/nifi/values.env.yaml @@ -2,6 +2,7 @@ nameOverride: "" fullnameOverride: "" replicaCount: 1 +allowedNodes: ${NIFI_K3S_ALLOWED_NODES} image: repository: cogstacksystems/nifi diff --git a/deployment/charts/nifi/values.yaml b/deployment/charts/nifi/values.yaml index 9afa52be..8ad924dd 100644 --- a/deployment/charts/nifi/values.yaml +++ b/deployment/charts/nifi/values.yaml @@ -2,6 +2,7 @@ nameOverride: "" fullnameOverride: "" replicaCount: 1 +allowedNodes: [] image: repository: cogstacksystems/nifi diff --git a/deployment/charts/opensearch-dashboards/values.yaml b/deployment/charts/opensearch-dashboards/values.yaml index c8f6fed5..15d3949d 100644 --- a/deployment/charts/opensearch-dashboards/values.yaml +++ b/deployment/charts/opensearch-dashboards/values.yaml @@ -1,2 +1,9 @@ opensearch-dashboards: opensearchHosts: https://opensearch-cluster-master:9200 + resources: + requests: + cpu: "1" + memory: "1Gi" + limits: + cpu: "1" + memory: "1Gi" diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index 26283096..df7637a4 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -42,8 +42,8 @@ or `cluster.local`. Export `KIBANA_PASSWORD` for `kibanaserver`. Set `OS_NIFI_PASSWORD`, `OS_PIPELINE_PASSWORD`, or `OS_ANALYST_PASSWORD` to create `nifi`, `cogstack_pipeline`, or `cogstack_user`, respectively. Export the absolute -`SECURITY_DIR` for a packaged chart or custom certificate location. Once the -OpenSearch pod is running, initialize Security before starting Dashboards. +`SECURITY_DIR` for a packaged chart or custom certificate location. After the +OpenSearch cluster forms, initialize Security once before starting Dashboards. ```bash bash "$chart/security/bootstrap.sh" kubectl -n search exec -i opensearch-cluster-master-0 -- @@ -52,6 +52,24 @@ bash "$chart/security/bootstrap.sh" kubectl -n search exec -i opensearch-cluster From inside the cluster, clients can use `https://opensearch-cluster-master.search.svc:9200`. +## Replicas + +Set `OPENSEARCH_K3S_REPLICA_COUNT` in `deployment/env/opensearch.env` +and run `make -C deployment helm-values-opensearch` before installing or +scaling up with Helm. The default is one replica. Required pod anti-affinity +places each replica on a separate Kubernetes node, so two replicas require +two schedulable nodes. + +To exclude nodes, set `OPENSEARCH_K3S_BLACKLIST` in the same env file to +comma-separated names from `kubectl get nodes`, such as `worker-1,worker-2`. +An empty list allows all otherwise eligible nodes. Rerender the values and +upgrade the release after editing the list. A replica with a PVC tied to an +excluded node can stay Pending. + +Both members of a two-node cluster are needed for quorum. Use three replicas +on three nodes to tolerate one node failure. +[OpenSearch quorum rules](https://docs.opensearch.org/3.9/tuning-your-cluster/discovery-cluster-formation/voting-quorums/) + ## Storage The StatefulSet creates one 8 GiB PVC per pod and mounts it at diff --git a/deployment/charts/opensearch/values.env.yaml b/deployment/charts/opensearch/values.env.yaml index fca1991f..5383e798 100644 --- a/deployment/charts/opensearch/values.env.yaml +++ b/deployment/charts/opensearch/values.env.yaml @@ -1,4 +1,7 @@ opensearch: + replicas: ${OPENSEARCH_K3S_REPLICA_COUNT} + antiAffinity: hard + nodeAffinity: ${OPENSEARCH_K3S_NODE_AFFINITY} # Each StatefulSet pod gets its own claim from the cluster's default StorageClass. persistence: enabled: true diff --git a/deployment/charts/opensearch/values.yaml b/deployment/charts/opensearch/values.yaml index e7325889..1dfd7ea0 100644 --- a/deployment/charts/opensearch/values.yaml +++ b/deployment/charts/opensearch/values.yaml @@ -1,4 +1,7 @@ opensearch: + replicas: 1 + antiAffinity: hard + nodeAffinity: {} # Each StatefulSet pod gets its own claim from the cluster's default StorageClass. persistence: enabled: true From 6b7e300d1c4f1bb1d70dba5d5d1ad84af6b1aa83 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 08:30:03 +0000 Subject: [PATCH 36/63] GHA: helm tests. --- .github/scripts/smoke_nifi_login.sh | 11 ++ .github/workflows/docker_smoke_nifi.yml | 10 +- .github/workflows/helm_smoke.yml | 153 ++++++++++++++++++++ .github/workflows/helm_smoke_nginx.yml | 12 ++ .github/workflows/helm_smoke_opensearch.yml | 12 ++ 5 files changed, 190 insertions(+), 8 deletions(-) create mode 100644 .github/scripts/smoke_nifi_login.sh create mode 100644 .github/workflows/helm_smoke.yml create mode 100644 .github/workflows/helm_smoke_nginx.yml create mode 100644 .github/workflows/helm_smoke_opensearch.yml diff --git a/.github/scripts/smoke_nifi_login.sh b/.github/scripts/smoke_nifi_login.sh new file mode 100644 index 00000000..4ea4f303 --- /dev/null +++ b/.github/scripts/smoke_nifi_login.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -euo pipefail + +api="${1%/}/nifi-api" +request=(curl -fsS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" --max-time 10) +token=$("${request[@]}" --retry 30 --retry-all-errors --retry-delay 10 --retry-max-time 300 \ + --data-urlencode "username=$SINGLE_USER_CREDENTIALS_USERNAME" \ + --data-urlencode "password=$SINGLE_USER_CREDENTIALS_PASSWORD" "$api/access/token") +[[ -n "$token" ]] +"${request[@]}" --header "Authorization: Bearer $token" "$api/flow/current-user" | + jq -e --arg user "$SINGLE_USER_CREDENTIALS_USERNAME" '.identity == $user and .anonymous == false' diff --git a/.github/workflows/docker_smoke_nifi.yml b/.github/workflows/docker_smoke_nifi.yml index 7f252367..89a37322 100644 --- a/.github/workflows/docker_smoke_nifi.yml +++ b/.github/workflows/docker_smoke_nifi.yml @@ -9,6 +9,7 @@ on: - 'deployment/Makefile' - 'deployment/scripts/security/**' - 'deployment/security/templates/**' + - '.github/scripts/smoke_nifi_login.sh' - '.github/workflows/docker_smoke_nifi.yml' - '!**/*.md' - '!**/README*' @@ -71,14 +72,7 @@ jobs: NIFI_WEB_PROXY_HOST: 127.0.0.1:8443 NIFI_SENSITIVE_PROPS_KEY: ${NIFI_SENSITIVE_PROPS_KEY} YAML - api=https://127.0.0.1:8443/nifi-api - request=(curl -fsS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" --max-time 10) - token=$("${request[@]}" --retry 30 --retry-all-errors --retry-delay 10 --retry-max-time 300 \ - --data-urlencode "username=$SINGLE_USER_CREDENTIALS_USERNAME" \ - --data-urlencode "password=$SINGLE_USER_CREDENTIALS_PASSWORD" "$api/access/token") - [[ -n "$token" ]] - "${request[@]}" --header "Authorization: Bearer $token" "$api/flow/current-user" | - jq -e --arg user "$SINGLE_USER_CREDENTIALS_USERNAME" '.identity == $user and .anonymous == false' + bash ../../../.github/scripts/smoke_nifi_login.sh https://127.0.0.1:8443 - name: Dump container logs if: failure() diff --git a/.github/workflows/helm_smoke.yml b/.github/workflows/helm_smoke.yml new file mode 100644 index 00000000..0e8a2e55 --- /dev/null +++ b/.github/workflows/helm_smoke.yml @@ -0,0 +1,153 @@ +name: helm_smoke + +on: + push: + branches: ['**'] + paths: &paths + - 'deployment/charts/nifi/**' + - 'deployment/charts/nginx/**' + - 'deployment/charts/opensearch/**' + - 'deployment/charts/opensearch-dashboards/**' + - 'deployment/Makefile' + - 'deployment/env/general.env' + - 'deployment/scripts/security/**' + - 'deployment/security/templates/**' + - 'apps/opensearch/**' + - '.github/scripts/smoke_nifi_login.sh' + - '.github/workflows/helm_smoke.yml' + pull_request: + paths: *paths + workflow_dispatch: + workflow_call: + inputs: + stacks: + type: string + required: true + +permissions: + contents: read + +defaults: + run: + shell: bash + +jobs: + smoke: + name: Helm smoke (${{ matrix.stack }}) + runs-on: ubuntu-24.04 + timeout-minutes: 35 + strategy: + fail-fast: false + matrix: + stack: ${{ fromJSON(inputs.stacks || '["nifi","opensearch"]') }} + env: + SINGLE_USER_CREDENTIALS_USERNAME: smoke + steps: + - uses: actions/checkout@v7 + - uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: '21' + - uses: azure/setup-helm@v5.1.0 + with: + version: v3.17.0 + - uses: helm/kind-action@v1.15.2 + + - name: Generate and load certificates + run: | + source deployment/env/general.env + SECURITY_DIR=$(mktemp -d "$RUNNER_TEMP/helm-smoke.XXXXXX") + password=$(openssl rand -hex 16) + printf '::add-mask::%s\n' "$password" + printf 'SECURITY_DIR=%s\nSMOKE_PASSWORD=%s\n' "$SECURITY_DIR" "$password" >> "$GITHUB_ENV" + export SECURITY_DIR ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" OS_CERTIFICATE_PASSWORD="$password" + export KEYSTORE_PASSWORD="$password" TRUSTSTORE_PASSWORD="$password" + make -C deployment -j1 setup-k3s-namespace certs-all k3s-load-certs-all + kubectl config set-context --current --namespace="$KUBE_NAMESPACE" + + - name: Install NiFi + if: matrix.stack == 'nifi' || matrix.stack == 'nginx' + run: | + kubectl create configmap nifi-env --from-literal=NIFI_WEB_PROXY_HOST=127.0.0.1:8443 + kubectl create secret generic nifi-auth \ + --from-literal=KEYSTORE_PASSWORD="$SMOKE_PASSWORD" --from-literal=TRUSTSTORE_PASSWORD="$SMOKE_PASSWORD" \ + --from-literal=SINGLE_USER_CREDENTIALS_USERNAME="$SINGLE_USER_CREDENTIALS_USERNAME" \ + --from-literal=SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ + --from-literal=INITIAL_ADMIN_IDENTITY="$SINGLE_USER_CREDENTIALS_USERNAME" \ + --from-literal=NIFI_SENSITIVE_PROPS_KEY="$(openssl rand -hex 16)" + helm install nifi deployment/charts/nifi --wait --timeout 15m + + - name: NiFi Helm login + if: matrix.stack == 'nifi' + run: | + kubectl port-forward svc/cogstack-nifi 8443:8443 & + trap 'kill "$!"' EXIT + SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" bash .github/scripts/smoke_nifi_login.sh https://127.0.0.1:8443 + + - name: NGINX Helm proxy login + if: matrix.stack == 'nifi' || matrix.stack == 'nginx' + run: | + kubectl create configmap nginx-env + helm install nginx deployment/charts/nginx --wait --timeout 5m + kubectl port-forward svc/cogstack-nginx 8443:8443 & + trap 'kill "$!"' EXIT + SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" bash .github/scripts/smoke_nifi_login.sh https://127.0.0.1:8443 + + - name: OpenSearch Helm authentication + if: matrix.stack == 'opensearch' + run: | + sudo sysctl -w vm.max_map_count=262144 + chart=deployment/charts/opensearch + helm dependency build "$chart" + helm install opensearch "$chart" --wait --timeout 10m \ + --set-file "opensearch.config.opensearch\\.yml=$chart/config/opensearch.yml" + KIBANA_PASSWORD="$SMOKE_PASSWORD" OS_ANALYST_PASSWORD="$SMOKE_PASSWORD" \ + bash "$chart/security/bootstrap.sh" kubectl exec -i opensearch-cluster-master-0 -- + kubectl port-forward svc/opensearch-cluster-master 9200:9200 & + trap 'kill "$!"' EXIT + curl -fsS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" \ + --retry 10 --retry-all-errors --retry-delay 2 --max-time 10 \ + -u "cogstack_user:$SMOKE_PASSWORD" https://localhost:9200/_plugins/_security/authinfo | + jq -e '.user_name == "cogstack_user"' + + - name: OpenSearch Dashboards Helm login + if: matrix.stack == 'opensearch' + run: | + certs="$SECURITY_DIR/certificates" + kubectl create secret generic dashboards-auth --from-literal=username=kibanaserver \ + --from-literal=password="$SMOKE_PASSWORD" --from-literal=cookie="$(openssl rand -hex 16)" + kubectl create secret tls dashboards-tls \ + --cert="$certs/opensearch/es_kibana_client.pem" --key="$certs/opensearch/es_kibana_client.key" + helm dependency build deployment/charts/opensearch-dashboards + helm install opensearch-dashboards deployment/charts/opensearch-dashboards --wait --timeout 5m -f - <<'YAML' + opensearch-dashboards: + opensearchAccount: + secret: dashboards-auth + secretMounts: + - {name: ca, secretName: cogstack-root-ca, path: /tls/ca} + - {name: server-tls, secretName: dashboards-tls, path: /tls/server} + config: + opensearch_dashboards.yml: + opensearchDashboards.index: .kibana + opensearch.ssl.certificateAuthorities: [/tls/ca/ca.crt] + opensearch.ssl.verificationMode: full + opensearch_security.cookie.secure: true + opensearch_security.cookie.password: ${COOKIE_PASS} + server.ssl.enabled: true + server.ssl.certificate: /tls/server/tls.crt + server.ssl.key: /tls/server/tls.key + YAML + kubectl port-forward svc/opensearch-dashboards 5601:5601 & + trap 'kill "$!"' EXIT + curl -fsS --noproxy '*' --cacert "$certs/root/root-ca.pem" --max-time 10 \ + --retry 30 --retry-all-errors --retry-delay 3 -H 'osd-xsrf: smoke' \ + --json "{\"username\":\"cogstack_user\",\"password\":\"$SMOKE_PASSWORD\"}" \ + https://localhost:5601/auth/login | jq -e '.username == "cogstack_user"' + + - name: Show pod logs on failure + if: failure() + run: | + kubectl get pods,svc,pvc + for pod in $(kubectl get pods -o name); do + kubectl logs "$pod" --all-containers --tail=100 || true + done diff --git a/.github/workflows/helm_smoke_nginx.yml b/.github/workflows/helm_smoke_nginx.yml new file mode 100644 index 00000000..7854ce27 --- /dev/null +++ b/.github/workflows/helm_smoke_nginx.yml @@ -0,0 +1,12 @@ +name: helm_smoke_nginx + +on: workflow_dispatch + +permissions: + contents: read + +jobs: + smoke: + uses: ./.github/workflows/helm_smoke.yml + with: + stacks: '["nginx"]' diff --git a/.github/workflows/helm_smoke_opensearch.yml b/.github/workflows/helm_smoke_opensearch.yml new file mode 100644 index 00000000..0ec3d374 --- /dev/null +++ b/.github/workflows/helm_smoke_opensearch.yml @@ -0,0 +1,12 @@ +name: helm_smoke_opensearch + +on: workflow_dispatch + +permissions: + contents: read + +jobs: + smoke: + uses: ./.github/workflows/helm_smoke.yml + with: + stacks: '["opensearch"]' From 5e10c30f188ed92fb78ff059cf134728100ccace Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 08:58:33 +0000 Subject: [PATCH 37/63] Fixed smoke tests + add makefile cmd for helm install. --- .../{helm_smoke.yml => helm_smoke_logins.yml} | 18 ++++++-------- .github/workflows/helm_smoke_nginx.yml | 2 +- .github/workflows/helm_smoke_opensearch.yml | 2 +- deployment/Makefile | 24 +++++++++++++++++++ 4 files changed, 33 insertions(+), 13 deletions(-) rename .github/workflows/{helm_smoke.yml => helm_smoke_logins.yml} (89%) diff --git a/.github/workflows/helm_smoke.yml b/.github/workflows/helm_smoke_logins.yml similarity index 89% rename from .github/workflows/helm_smoke.yml rename to .github/workflows/helm_smoke_logins.yml index 0e8a2e55..df0166f0 100644 --- a/.github/workflows/helm_smoke.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -1,4 +1,4 @@ -name: helm_smoke +name: helm_smoke_logins on: push: @@ -14,7 +14,7 @@ on: - 'deployment/security/templates/**' - 'apps/opensearch/**' - '.github/scripts/smoke_nifi_login.sh' - - '.github/workflows/helm_smoke.yml' + - '.github/workflows/helm_smoke_logins.yml' pull_request: paths: *paths workflow_dispatch: @@ -75,7 +75,7 @@ jobs: --from-literal=SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ --from-literal=INITIAL_ADMIN_IDENTITY="$SINGLE_USER_CREDENTIALS_USERNAME" \ --from-literal=NIFI_SENSITIVE_PROPS_KEY="$(openssl rand -hex 16)" - helm install nifi deployment/charts/nifi --wait --timeout 15m + make -C deployment helm-install CHART=nifi HELM_TIMEOUT=15m - name: NiFi Helm login if: matrix.stack == 'nifi' @@ -88,7 +88,7 @@ jobs: if: matrix.stack == 'nifi' || matrix.stack == 'nginx' run: | kubectl create configmap nginx-env - helm install nginx deployment/charts/nginx --wait --timeout 5m + make -C deployment helm-install CHART=nginx HELM_TIMEOUT=5m kubectl port-forward svc/cogstack-nginx 8443:8443 & trap 'kill "$!"' EXIT SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" bash .github/scripts/smoke_nifi_login.sh https://127.0.0.1:8443 @@ -97,12 +97,9 @@ jobs: if: matrix.stack == 'opensearch' run: | sudo sysctl -w vm.max_map_count=262144 - chart=deployment/charts/opensearch - helm dependency build "$chart" - helm install opensearch "$chart" --wait --timeout 10m \ - --set-file "opensearch.config.opensearch\\.yml=$chart/config/opensearch.yml" + make -C deployment helm-install CHART=opensearch KIBANA_PASSWORD="$SMOKE_PASSWORD" OS_ANALYST_PASSWORD="$SMOKE_PASSWORD" \ - bash "$chart/security/bootstrap.sh" kubectl exec -i opensearch-cluster-master-0 -- + bash deployment/charts/opensearch/security/bootstrap.sh kubectl exec -i opensearch-cluster-master-0 -- kubectl port-forward svc/opensearch-cluster-master 9200:9200 & trap 'kill "$!"' EXIT curl -fsS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" \ @@ -118,8 +115,7 @@ jobs: --from-literal=password="$SMOKE_PASSWORD" --from-literal=cookie="$(openssl rand -hex 16)" kubectl create secret tls dashboards-tls \ --cert="$certs/opensearch/es_kibana_client.pem" --key="$certs/opensearch/es_kibana_client.key" - helm dependency build deployment/charts/opensearch-dashboards - helm install opensearch-dashboards deployment/charts/opensearch-dashboards --wait --timeout 5m -f - <<'YAML' + make -C deployment helm-install CHART=opensearch-dashboards HELM_VALUES=- HELM_TIMEOUT=5m <<'YAML' opensearch-dashboards: opensearchAccount: secret: dashboards-auth diff --git a/.github/workflows/helm_smoke_nginx.yml b/.github/workflows/helm_smoke_nginx.yml index 7854ce27..39fd5f69 100644 --- a/.github/workflows/helm_smoke_nginx.yml +++ b/.github/workflows/helm_smoke_nginx.yml @@ -7,6 +7,6 @@ permissions: jobs: smoke: - uses: ./.github/workflows/helm_smoke.yml + uses: ./.github/workflows/helm_smoke_logins.yml with: stacks: '["nginx"]' diff --git a/.github/workflows/helm_smoke_opensearch.yml b/.github/workflows/helm_smoke_opensearch.yml index 0ec3d374..93e28f87 100644 --- a/.github/workflows/helm_smoke_opensearch.yml +++ b/.github/workflows/helm_smoke_opensearch.yml @@ -7,6 +7,6 @@ permissions: jobs: smoke: - uses: ./.github/workflows/helm_smoke.yml + uses: ./.github/workflows/helm_smoke_logins.yml with: stacks: '["opensearch"]' diff --git a/deployment/Makefile b/deployment/Makefile index fef67b2c..cb47b6fd 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -162,6 +162,30 @@ helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch # ====================================================================================================================================================== +.PHONY: helm-install + +helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIMEOUT + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + chart="charts/$${CHART:?Set CHART to a directory under deployment/charts}"; \ + release="$$CHART"; \ + args=(); \ + case "$$CHART" in \ + nifi|nginx) release="cogstack-$$CHART";; \ + opensearch|opensearch-dashboards) \ + helm repo add opensearch https://opensearch-project.github.io/helm-charts/; \ + helm dependency build "$$chart";; \ + esac; \ + if [ "$$CHART" = opensearch ]; then \ + args+=(--set-file "opensearch.config.opensearch\\.yml=$$chart/config/opensearch.yml"); \ + fi; \ + if [ -n "$${HELM_VALUES:-}" ]; then args+=(-f "$$HELM_VALUES"); fi; \ + helm upgrade --install "$$release" "$$chart" -n "$$namespace" \ + --wait --timeout "$${HELM_TIMEOUT:-10m}" "$${args[@]}" + +# ====================================================================================================================================================== + help: ## Show deployment commands @printf '%s\n' 'Deployment commands' @awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[[:alnum:]_-]+$$/ { printf " %-30s %s\n", $$1, $$2 }' "$(lastword $(MAKEFILE_LIST))" From eea7b50939422aab6ddead488db017f0d8ada064 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 09:34:41 +0000 Subject: [PATCH 38/63] Added more deployment/Makefile utils. --- .github/workflows/helm_smoke_logins.yml | 10 ++-- deployment/Makefile | 79 ++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 6 deletions(-) diff --git a/.github/workflows/helm_smoke_logins.yml b/.github/workflows/helm_smoke_logins.yml index df0166f0..a18ce8a7 100644 --- a/.github/workflows/helm_smoke_logins.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -75,7 +75,7 @@ jobs: --from-literal=SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ --from-literal=INITIAL_ADMIN_IDENTITY="$SINGLE_USER_CREDENTIALS_USERNAME" \ --from-literal=NIFI_SENSITIVE_PROPS_KEY="$(openssl rand -hex 16)" - make -C deployment helm-install CHART=nifi HELM_TIMEOUT=15m + make -C deployment helm-install-nifi HELM_TIMEOUT=15m - name: NiFi Helm login if: matrix.stack == 'nifi' @@ -88,7 +88,7 @@ jobs: if: matrix.stack == 'nifi' || matrix.stack == 'nginx' run: | kubectl create configmap nginx-env - make -C deployment helm-install CHART=nginx HELM_TIMEOUT=5m + make -C deployment helm-install-nginx HELM_TIMEOUT=5m kubectl port-forward svc/cogstack-nginx 8443:8443 & trap 'kill "$!"' EXIT SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" bash .github/scripts/smoke_nifi_login.sh https://127.0.0.1:8443 @@ -97,9 +97,9 @@ jobs: if: matrix.stack == 'opensearch' run: | sudo sysctl -w vm.max_map_count=262144 - make -C deployment helm-install CHART=opensearch + make -C deployment helm-install-opensearch KIBANA_PASSWORD="$SMOKE_PASSWORD" OS_ANALYST_PASSWORD="$SMOKE_PASSWORD" \ - bash deployment/charts/opensearch/security/bootstrap.sh kubectl exec -i opensearch-cluster-master-0 -- + make -C deployment k3s-bootstrap-opensearch kubectl port-forward svc/opensearch-cluster-master 9200:9200 & trap 'kill "$!"' EXIT curl -fsS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" \ @@ -115,7 +115,7 @@ jobs: --from-literal=password="$SMOKE_PASSWORD" --from-literal=cookie="$(openssl rand -hex 16)" kubectl create secret tls dashboards-tls \ --cert="$certs/opensearch/es_kibana_client.pem" --key="$certs/opensearch/es_kibana_client.key" - make -C deployment helm-install CHART=opensearch-dashboards HELM_VALUES=- HELM_TIMEOUT=5m <<'YAML' + make -C deployment helm-install-opensearch-dashboards HELM_VALUES=- HELM_TIMEOUT=5m <<'YAML' opensearch-dashboards: opensearchAccount: secret: dashboards-auth diff --git a/deployment/Makefile b/deployment/Makefile index cb47b6fd..4b0e488c 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -162,8 +162,24 @@ helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch # ====================================================================================================================================================== -.PHONY: helm-install +.PHONY: helm-install helm-install-nifi helm-install-nginx helm-install-nifi-stack +.PHONY: helm-install-opensearch helm-install-opensearch-dashboards helm-install-opensearch-stack k3s-bootstrap-opensearch +# Set KUBE_NAMESPACE in deployment/env/general.env and create the namespace +# and required Secrets and ConfigMaps. Run these from the repository root. +# make -C deployment helm-install-nifi HELM_TIMEOUT=15m +# make -C deployment helm-install-nginx +# make -C deployment helm-install-nifi-stack +# make -C deployment helm-install-opensearch +# Export KIBANA_PASSWORD and initialize Security on a fresh OpenSearch cluster. +# make -C deployment k3s-bootstrap-opensearch +# make -C deployment helm-install-opensearch-dashboards HELM_VALUES=/path/to/dashboards-values.yaml +# The stack initializes Security on first install. Export KIBANA_PASSWORD to match +# the Dashboards Secret, or set BOOTSTRAP_OPENSEARCH_SECURITY=0 to skip bootstrap. +# make -C deployment helm-install-opensearch-stack HELM_VALUES=/path/to/dashboards-values.yaml +# The stack target uses HELM_VALUES for Dashboards. +# HELM_VALUES accepts an absolute path, a path relative to deployment/, or - for stdin. +# HELM_TIMEOUT defaults to 10m. helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIMEOUT @set -e; \ . ./env/general.env; \ @@ -184,6 +200,67 @@ helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIM helm upgrade --install "$$release" "$$chart" -n "$$namespace" \ --wait --timeout "$${HELM_TIMEOUT:-10m}" "$${args[@]}" +helm-install-nifi: ## Install or upgrade NiFi + $(MAKE) helm-install CHART=nifi + +helm-install-nginx: ## Install or upgrade NGINX for NiFi + $(MAKE) helm-install CHART=nginx + +helm-install-nifi-stack: helm-install-nifi ## Wait for NiFi, then install or upgrade NGINX + $(MAKE) helm-install-nginx + +helm-install-opensearch: ## Install or upgrade OpenSearch + $(MAKE) helm-install CHART=opensearch + +helm-install-opensearch-dashboards: ## Install or upgrade OpenSearch Dashboards + $(MAKE) helm-install CHART=opensearch-dashboards + +k3s-bootstrap-opensearch: ## Initialize OpenSearch Security if needed + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + pod=opensearch-cluster-master-0; \ + status=$$(kubectl -n "$$namespace" exec "$$pod" -- curl -sS --noproxy '*' \ + --retry 3 --retry-delay 2 --retry-connrefused --max-time 10 \ + --cacert /usr/share/opensearch/config/tls/ca.crt --output /dev/null \ + --write-out '%{http_code}' https://localhost:9200/_plugins/_security/health); \ + case "$$status" in \ + 200) printf '%s\n' 'OpenSearch Security is already initialized.';; \ + 503) bash charts/opensearch/security/bootstrap.sh kubectl -n "$$namespace" exec -i "$$pod" --;; \ + *) printf 'OpenSearch Security health check returned HTTP %s.\n' "$$status" >&2; exit 1;; \ + esac + +helm-install-opensearch-stack: ## Install OpenSearch and then Dashboards + $(MAKE) helm-install-opensearch HELM_VALUES= + @if [ "$${BOOTSTRAP_OPENSEARCH_SECURITY:-1}" = 1 ]; then $(MAKE) k3s-bootstrap-opensearch; fi + $(MAKE) helm-install-opensearch-dashboards + +# ====================================================================================================================================================== + +.PHONY: helm-uninstall-nifi helm-uninstall-nginx helm-uninstall-nifi-stack +.PHONY: helm-uninstall-opensearch helm-uninstall-opensearch-dashboards helm-uninstall-opensearch-stack + +# Reinstall in the same namespace with the same StatefulSet names to reuse the retained PVCs. +helm-uninstall-nifi: ## Uninstall NiFi and retain its PVCs +helm-uninstall-nginx: ## Uninstall NGINX +helm-uninstall-opensearch: ## Uninstall OpenSearch and retain its PVCs +helm-uninstall-opensearch-dashboards: ## Uninstall OpenSearch Dashboards + +helm-uninstall-nifi helm-uninstall-nginx helm-uninstall-opensearch helm-uninstall-opensearch-dashboards: + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + release=$(@:helm-uninstall-%=%); \ + case "$$release" in nifi|nginx) release="cogstack-$$release";; esac; \ + helm uninstall "$$release" -n "$$namespace" --ignore-not-found \ + --cascade foreground --wait --timeout "$${HELM_TIMEOUT:-10m}" + +helm-uninstall-nifi-stack: helm-uninstall-nginx ## Uninstall NGINX, then NiFi, and retain PVCs + $(MAKE) helm-uninstall-nifi + +helm-uninstall-opensearch-stack: helm-uninstall-opensearch-dashboards ## Uninstall Dashboards, then OpenSearch, and retain PVCs + $(MAKE) helm-uninstall-opensearch + # ====================================================================================================================================================== help: ## Show deployment commands From e176d6d1249a1b7fcafb0186f7f279f59b37983a Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 09:44:59 +0000 Subject: [PATCH 39/63] Install scripts added jdk. --- deployment/scripts/installation_utils/install_host_utils.sh | 4 ++-- .../installation_utils/install_os_tools_and_software.sh | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/deployment/scripts/installation_utils/install_host_utils.sh b/deployment/scripts/installation_utils/install_host_utils.sh index d3a1ec73..41a37dc3 100755 --- a/deployment/scripts/installation_utils/install_host_utils.sh +++ b/deployment/scripts/installation_utils/install_host_utils.sh @@ -11,7 +11,7 @@ if [ "$os_distribution" == "debian" ] || [ "$os_distribution" == "ubuntu" ]; then install_missing_packages "$os_distribution" \ samba cifs-utils nfs-common nfs-kernel-server archivemount \ - htop iotop sysstat \ + htop iotop sysstat default-jdk \ jq gettext-base wget curl gnupg gnupg-agent git ca-certificates apt-transport-https python3 python3-pip python3-full openssl libssl-dev zip unzip tar nano gcc make python3-dev build-essential software-properties-common if command -v az >/dev/null 2>&1 || package_is_installed "$os_distribution" azure-cli; then @@ -27,7 +27,7 @@ elif [ "$os_distribution" == "redhat" ]; then install_missing_packages "$os_distribution" \ samba samba-client cifs-utils nfs-utils rpcbind archivemount \ - htop iotop sysstat \ + htop iotop sysstat java-21-openjdk-devel \ jq gettext yum-utils wget curl git device-mapper-persistent-data lvm2 python3 python3-pip libffi-devel openssl openssl-devel zip unzip tar nano gcc gcc-c++ make python3-devel libevent-devel if command -v az >/dev/null 2>&1 || package_is_installed "$os_distribution" azure-cli; then diff --git a/deployment/scripts/installation_utils/install_os_tools_and_software.sh b/deployment/scripts/installation_utils/install_os_tools_and_software.sh index 54c3076a..e95cfd95 100755 --- a/deployment/scripts/installation_utils/install_os_tools_and_software.sh +++ b/deployment/scripts/installation_utils/install_os_tools_and_software.sh @@ -22,6 +22,12 @@ os_distribution="$(bash "${script_dir}/detect_os.sh")" echo "Found distribution: $os_distribution " bash "${script_dir}/install_host_utils.sh" + +if ! keytool -help >/dev/null 2>&1; then + echo "Java keytool could not run after JDK installation." >&2 + exit 1 +fi + bash "${script_dir}/install_docker.sh" if [ "$install_k3s" = "true" ]; then From a5f765396bd7b4fa9756354e62bafcc1aaa1b208 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 10:16:22 +0000 Subject: [PATCH 40/63] Auth settings. --- .github/workflows/helm_smoke_logins.yml | 10 ++-- deployment/Makefile | 6 ++ deployment/env/authentication_dev.env | 5 ++ deployment/scripts/security/load_nifi_auth.sh | 57 +++++++++++++++++++ .../scripts/security/password_prompt.sh | 2 +- 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 deployment/scripts/security/load_nifi_auth.sh diff --git a/.github/workflows/helm_smoke_logins.yml b/.github/workflows/helm_smoke_logins.yml index a18ce8a7..3cebc436 100644 --- a/.github/workflows/helm_smoke_logins.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -69,12 +69,10 @@ jobs: if: matrix.stack == 'nifi' || matrix.stack == 'nginx' run: | kubectl create configmap nifi-env --from-literal=NIFI_WEB_PROXY_HOST=127.0.0.1:8443 - kubectl create secret generic nifi-auth \ - --from-literal=KEYSTORE_PASSWORD="$SMOKE_PASSWORD" --from-literal=TRUSTSTORE_PASSWORD="$SMOKE_PASSWORD" \ - --from-literal=SINGLE_USER_CREDENTIALS_USERNAME="$SINGLE_USER_CREDENTIALS_USERNAME" \ - --from-literal=SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ - --from-literal=INITIAL_ADMIN_IDENTITY="$SINGLE_USER_CREDENTIALS_USERNAME" \ - --from-literal=NIFI_SENSITIVE_PROPS_KEY="$(openssl rand -hex 16)" + NIFI_SINGLE_USER_CREDENTIALS_USERNAME="$SINGLE_USER_CREDENTIALS_USERNAME" \ + NIFI_SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ + KEYSTORE_PASSWORD="$SMOKE_PASSWORD" TRUSTSTORE_PASSWORD="$SMOKE_PASSWORD" \ + make -C deployment k3s-load-auth-nifi make -C deployment helm-install-nifi HELM_TIMEOUT=15m - name: NiFi Helm login diff --git a/deployment/Makefile b/deployment/Makefile index 4b0e488c..46789857 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -98,6 +98,12 @@ k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-ngi printf -- '---\n%s\n' "$${manifests[@]}" | \ kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-certificates -f - +.PHONY: k3s-load-auth-nifi + +# Uses env/authentication.env. Set NIFI_AUTH_FILE=env/authentication_dev.env for development. +k3s-load-auth-nifi: ## Prompt for missing credentials and load the NiFi auth Secret + @bash scripts/security/load_nifi_auth.sh + # ====================================================================================================================================================== .PHONY: helm-values-all helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards diff --git a/deployment/env/authentication_dev.env b/deployment/env/authentication_dev.env index e87bb059..3afd2bc3 100644 --- a/deployment/env/authentication_dev.env +++ b/deployment/env/authentication_dev.env @@ -1,3 +1,8 @@ # Sample login for local NiFi development. +# Set NIFI_AUTH_FILE=env/authentication_dev.env when running k3s-load-auth-nifi for dev. NIFI_SINGLE_USER_CREDENTIALS_USERNAME=admin NIFI_SINGLE_USER_CREDENTIALS_PASSWORD=cogstackNiFi + +# Helm and Compose load the dev JKS passwords from certificates_dev.env. +NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CREDENTIALS_USERNAME} +NIFI_SENSITIVE_PROPS_KEY=${NIFI_SENSITIVE_PROPS_KEY:-c6063c770f5a281732877e7a9f7de2bc} diff --git a/deployment/scripts/security/load_nifi_auth.sh b/deployment/scripts/security/load_nifi_auth.sh new file mode 100644 index 00000000..3f7c0e12 --- /dev/null +++ b/deployment/scripts/security/load_nifi_auth.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -euo pipefail + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../../env/general.env +source "$script_dir/../../env/general.env" +namespace="${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" +auth_file="${NIFI_AUTH_FILE:-$script_dir/../../env/authentication.env}" +# shellcheck disable=SC1090 # Optional deployment credentials. +if [[ -f "$auth_file" || -n ${NIFI_AUTH_FILE:-} ]]; then source "$auth_file"; fi +# shellcheck source=password_prompt.sh +source "$script_dir/password_prompt.sh" + +if [[ -z ${NIFI_SINGLE_USER_CREDENTIALS_USERNAME:-} && -t 0 ]]; then + IFS= read -r -p 'NiFi username: ' NIFI_SINGLE_USER_CREDENTIALS_USERNAME +fi +: "${NIFI_SINGLE_USER_CREDENTIALS_USERNAME:?Set NIFI_SINGLE_USER_CREDENTIALS_USERNAME or run in a terminal}" +require_password NIFI_SINGLE_USER_CREDENTIALS_PASSWORD +if (( ${#NIFI_SINGLE_USER_CREDENTIALS_PASSWORD} < 12 )); then + printf 'NiFi login password must be at least 12 characters.\n' >&2 + exit 1 +fi +KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}} +TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD:-}} +if [[ "$auth_file" -ef "$script_dir/../../env/authentication_dev.env" ]]; then + # shellcheck source=../../env/certificates_dev.env + source "$script_dir/../../env/certificates_dev.env" + KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}} + TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD:-}} +fi +require_password KEYSTORE_PASSWORD +require_password TRUSTSTORE_PASSWORD + +existing=$(kubectl -n "$namespace" get secret nifi-auth --ignore-not-found -o json) +version=$(jq -r '.metadata.resourceVersion' <<< "$existing") +key=$(jq -r '.data.NIFI_SENSITIVE_PROPS_KEY // "" | @base64d' <<< "$existing") +NIFI_SENSITIVE_PROPS_KEY=${key:-${NIFI_SENSITIVE_PROPS_KEY:-$(openssl rand -hex 16)}} +NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CREDENTIALS_USERNAME} +export NIFI_SENSITIVE_PROPS_KEY NIFI_INITIAL_ADMIN_IDENTITY NIFI_SINGLE_USER_CREDENTIALS_USERNAME + +manifest=$(jq -n --arg version "$version" '{ + apiVersion: "v1", kind: "Secret", + metadata: {name: "nifi-auth", resourceVersion: (if $version == "" then null else $version end)}, + stringData: { + SINGLE_USER_CREDENTIALS_USERNAME: env.NIFI_SINGLE_USER_CREDENTIALS_USERNAME, + SINGLE_USER_CREDENTIALS_PASSWORD: env.NIFI_SINGLE_USER_CREDENTIALS_PASSWORD, + INITIAL_ADMIN_IDENTITY: env.NIFI_INITIAL_ADMIN_IDENTITY, + KEYSTORE_PASSWORD: env.KEYSTORE_PASSWORD, + TRUSTSTORE_PASSWORD: env.TRUSTSTORE_PASSWORD, + NIFI_SENSITIVE_PROPS_KEY: env.NIFI_SENSITIVE_PROPS_KEY + } +}') +if [[ -z "$version" ]]; then + kubectl -n "$namespace" create -f - <<< "$manifest" +else + kubectl -n "$namespace" patch secret nifi-auth --type=merge --patch-file=/dev/stdin <<< "$manifest" +fi diff --git a/deployment/scripts/security/password_prompt.sh b/deployment/scripts/security/password_prompt.sh index 0f60a41e..5fe70e22 100644 --- a/deployment/scripts/security/password_prompt.sh +++ b/deployment/scripts/security/password_prompt.sh @@ -9,7 +9,7 @@ require_password() { fi if [[ ! -t 0 ]]; then - printf 'Set %s in the environment or run this generator in a terminal.\n' "$name" >&2 + printf 'Set %s in the environment or run this command in a terminal.\n' "$name" >&2 return 1 fi From 77147182518ced32ef9ca61707157528ee239d04 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 10:18:38 +0000 Subject: [PATCH 41/63] Makefile updates. --- deployment/Makefile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/deployment/Makefile b/deployment/Makefile index 46789857..4877b9aa 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -24,7 +24,7 @@ setup-verify: ## Check local Docker, Docker Compose, and K3s access without sudo # ====================================================================================================================================================== -.PHONY: certs certs-all certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-nodes +.PHONY: certs certs-all certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-nodes delete-certs-all certs: certs-root ## Generate the root CA and NiFi and NGINX certificates $(MAKE) certs-nifi certs-nginx @@ -59,6 +59,16 @@ certs-opensearch-nodes: ## Generate OpenSearch node certificates for NODES="node @read -r -a nodes <<< "$$NODES"; \ bash scripts/security/create_opensearch_node_cert.sh "$${nodes[@]}" +delete-certs-all: ## Delete generated local TLS certificates, keys, and stores + @set -e; \ + certs="$${SECURITY_DIR:-security}/certificates"; \ + if [ -L "$$certs" ]; then printf 'Certificate directory is a symlink: %s\n' "$$certs" >&2; exit 1; fi; \ + [ -d "$$certs" ] || exit 0; \ + CDPATH= cd -- "$$certs"; \ + find -P . -maxdepth 2 \( -type f -o -type l \) \ + \( -path './root/*' -o -path './nifi/*' -o -path './nginx/*' -o -path './opensearch/*' \) \ + \( -name '*.crt' -o -name '*.pem' -o -name '*.key' -o -name '*.csr' -o -name '*.p12' -o -name '*.jks' \) -delete + # ====================================================================================================================================================== .PHONY: k3s-load-certs k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-nginx k3s-load-certs-opensearch From 6928a4a7efb59b7e676abff3440c6fe3e1a4b431 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 10:23:04 +0000 Subject: [PATCH 42/63] Auth env updates. --- deployment/env/authentication.env | 7 ++++ deployment/env/certificates.env | 22 ++++++++----- deployment/env/certificates_dev.env | 33 ++++++++++++++++--- deployment/scripts/security/load_nifi_auth.sh | 9 ++--- 4 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 deployment/env/authentication.env diff --git a/deployment/env/authentication.env b/deployment/env/authentication.env new file mode 100644 index 00000000..7cc50672 --- /dev/null +++ b/deployment/env/authentication.env @@ -0,0 +1,7 @@ +# Local NiFi credentials for k3s-load-auth-nifi, using development sample values. +NIFI_SINGLE_USER_CREDENTIALS_USERNAME=admin +NIFI_SINGLE_USER_CREDENTIALS_PASSWORD=cogstackNiFi + +# Helm loads the JKS passwords from certificates.env. +NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CREDENTIALS_USERNAME} +NIFI_SENSITIVE_PROPS_KEY=${NIFI_SENSITIVE_PROPS_KEY:-c6063c770f5a281732877e7a9f7de2bc} diff --git a/deployment/env/certificates.env b/deployment/env/certificates.env index bbd30951..47a8e357 100644 --- a/deployment/env/certificates.env +++ b/deployment/env/certificates.env @@ -1,6 +1,5 @@ -# 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. +# Certificate generator settings with development sample passwords. +# Blank settings use the script defaults. Use --days DAYS to set validity. # # Load from the repository root before running a generator. # set -a @@ -9,17 +8,22 @@ # set +a # Blank uses deployment/security/ for certificate inputs and outputs. -SECURITY_DIR= +SECURITY_DIR="${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= +NIFI_UPSTREAM_TLS_NAME="${NIFI_UPSTREAM_TLS_NAME:-}" +NIFI_HEALTHCHECK_HOST="${NIFI_HEALTHCHECK_HOST:-}" # Browser-facing NGINX DNS names or IP addresses, comma-separated. # Blank uses localhost,127.0.0.1. -NGINX_TLS_NAMES= +NGINX_TLS_NAMES="${NGINX_TLS_NAMES:-}" # Optional comma-separated DNS aliases for each OpenSearch node and for Dashboards. -OPENSEARCH_NODE_DNS_NAMES= -OPENSEARCH_DASHBOARDS_DNS_NAMES= +OPENSEARCH_NODE_DNS_NAMES="${OPENSEARCH_NODE_DNS_NAMES:-}" +OPENSEARCH_DASHBOARDS_DNS_NAMES="${OPENSEARCH_DASHBOARDS_DNS_NAMES:-}" + +# Development store passwords. Environment values override these defaults. +ROOT_CERTIFICATE_KEYSTORE_PASSWORD="${ROOT_CERTIFICATE_KEYSTORE_PASSWORD:-cogstackNiFi}" +NIFI_KEYSTORE_PASSWORD="${NIFI_KEYSTORE_PASSWORD:-cogstackNiFi}" +NIFI_TRUSTSTORE_PASSWORD="${NIFI_TRUSTSTORE_PASSWORD:-cogstackNiFi}" diff --git a/deployment/env/certificates_dev.env b/deployment/env/certificates_dev.env index bbf53c9b..47a8e357 100644 --- a/deployment/env/certificates_dev.env +++ b/deployment/env/certificates_dev.env @@ -1,4 +1,29 @@ -# Sample passwords for local development certificate stores. -ROOT_CERTIFICATE_KEYSTORE_PASSWORD=cogstackNiFi -NIFI_KEYSTORE_PASSWORD=cogstackNiFi -NIFI_TRUSTSTORE_PASSWORD=cogstackNiFi +# Certificate generator settings with development sample passwords. +# Blank settings use the script defaults. Use --days DAYS to set validity. +# +# Load from the repository root before running a generator. +# set -a +# source deployment/env/general.env +# source deployment/env/certificates.env +# set +a + +# Blank uses deployment/security/ for certificate inputs and outputs. +SECURITY_DIR="${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_UPSTREAM_TLS_NAME:-}" +NIFI_HEALTHCHECK_HOST="${NIFI_HEALTHCHECK_HOST:-}" + +# Browser-facing NGINX DNS names or IP addresses, comma-separated. +# Blank uses localhost,127.0.0.1. +NGINX_TLS_NAMES="${NGINX_TLS_NAMES:-}" + +# Optional comma-separated DNS aliases for each OpenSearch node and for Dashboards. +OPENSEARCH_NODE_DNS_NAMES="${OPENSEARCH_NODE_DNS_NAMES:-}" +OPENSEARCH_DASHBOARDS_DNS_NAMES="${OPENSEARCH_DASHBOARDS_DNS_NAMES:-}" + +# Development store passwords. Environment values override these defaults. +ROOT_CERTIFICATE_KEYSTORE_PASSWORD="${ROOT_CERTIFICATE_KEYSTORE_PASSWORD:-cogstackNiFi}" +NIFI_KEYSTORE_PASSWORD="${NIFI_KEYSTORE_PASSWORD:-cogstackNiFi}" +NIFI_TRUSTSTORE_PASSWORD="${NIFI_TRUSTSTORE_PASSWORD:-cogstackNiFi}" diff --git a/deployment/scripts/security/load_nifi_auth.sh b/deployment/scripts/security/load_nifi_auth.sh index 3f7c0e12..5baed2db 100644 --- a/deployment/scripts/security/load_nifi_auth.sh +++ b/deployment/scripts/security/load_nifi_auth.sh @@ -20,14 +20,15 @@ if (( ${#NIFI_SINGLE_USER_CREDENTIALS_PASSWORD} < 12 )); then printf 'NiFi login password must be at least 12 characters.\n' >&2 exit 1 fi -KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}} -TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD:-}} if [[ "$auth_file" -ef "$script_dir/../../env/authentication_dev.env" ]]; then # shellcheck source=../../env/certificates_dev.env source "$script_dir/../../env/certificates_dev.env" - KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}} - TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD:-}} +elif [[ "$auth_file" -ef "$script_dir/../../env/authentication.env" ]]; then + # shellcheck source=../../env/certificates.env + source "$script_dir/../../env/certificates.env" fi +KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}} +TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD:-}} require_password KEYSTORE_PASSWORD require_password TRUSTSTORE_PASSWORD From 047912d3dc742fc14fd04ea600914aea60ecdf4f Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 10:33:55 +0000 Subject: [PATCH 43/63] Opensearch auth. --- deployment/Makefile | 32 ++++----- .../charts/opensearch-dashboards/README.md | 22 ++++-- deployment/charts/opensearch/README.md | 16 +++++ .../scripts/security/load_opensearch_auth.sh | 70 +++++++++++++++++++ 4 files changed, 116 insertions(+), 24 deletions(-) create mode 100644 deployment/scripts/security/load_opensearch_auth.sh diff --git a/deployment/Makefile b/deployment/Makefile index 4877b9aa..1a641508 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -108,12 +108,19 @@ k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-ngi printf -- '---\n%s\n' "$${manifests[@]}" | \ kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-certificates -f - -.PHONY: k3s-load-auth-nifi +.PHONY: k3s-load-auth-nifi k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards # Uses env/authentication.env. Set NIFI_AUTH_FILE=env/authentication_dev.env for development. k3s-load-auth-nifi: ## Prompt for missing credentials and load the NiFi auth Secret @bash scripts/security/load_nifi_auth.sh +# Both targets use env/authentication.env unless OPENSEARCH_AUTH_FILE is set. +k3s-load-auth-opensearch: ## Load configured users into a fresh OpenSearch cluster +k3s-load-auth-opensearch-dashboards: ## Load the OpenSearch Dashboards auth Secret + +k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards: + @bash scripts/security/load_opensearch_auth.sh $(@:k3s-load-auth-%=%) + # ====================================================================================================================================================== .PHONY: helm-values-all helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards @@ -186,12 +193,12 @@ helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch # make -C deployment helm-install-nifi HELM_TIMEOUT=15m # make -C deployment helm-install-nginx # make -C deployment helm-install-nifi-stack +# Load dashboards-auth first to share its service account password with bootstrap. +# make -C deployment k3s-load-auth-opensearch-dashboards # make -C deployment helm-install-opensearch -# Export KIBANA_PASSWORD and initialize Security on a fresh OpenSearch cluster. -# make -C deployment k3s-bootstrap-opensearch +# make -C deployment k3s-load-auth-opensearch # make -C deployment helm-install-opensearch-dashboards HELM_VALUES=/path/to/dashboards-values.yaml -# The stack initializes Security on first install. Export KIBANA_PASSWORD to match -# the Dashboards Secret, or set BOOTSTRAP_OPENSEARCH_SECURITY=0 to skip bootstrap. +# The stack initializes Security on first install. Set BOOTSTRAP_OPENSEARCH_SECURITY=0 to skip bootstrap. # make -C deployment helm-install-opensearch-stack HELM_VALUES=/path/to/dashboards-values.yaml # The stack target uses HELM_VALUES for Dashboards. # HELM_VALUES accepts an absolute path, a path relative to deployment/, or - for stdin. @@ -231,20 +238,7 @@ helm-install-opensearch: ## Install or upgrade OpenSearch helm-install-opensearch-dashboards: ## Install or upgrade OpenSearch Dashboards $(MAKE) helm-install CHART=opensearch-dashboards -k3s-bootstrap-opensearch: ## Initialize OpenSearch Security if needed - @set -e; \ - . ./env/general.env; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - pod=opensearch-cluster-master-0; \ - status=$$(kubectl -n "$$namespace" exec "$$pod" -- curl -sS --noproxy '*' \ - --retry 3 --retry-delay 2 --retry-connrefused --max-time 10 \ - --cacert /usr/share/opensearch/config/tls/ca.crt --output /dev/null \ - --write-out '%{http_code}' https://localhost:9200/_plugins/_security/health); \ - case "$$status" in \ - 200) printf '%s\n' 'OpenSearch Security is already initialized.';; \ - 503) bash charts/opensearch/security/bootstrap.sh kubectl -n "$$namespace" exec -i "$$pod" --;; \ - *) printf 'OpenSearch Security health check returned HTTP %s.\n' "$$status" >&2; exit 1;; \ - esac +k3s-bootstrap-opensearch: k3s-load-auth-opensearch ## Alias for k3s-load-auth-opensearch helm-install-opensearch-stack: ## Install OpenSearch and then Dashboards $(MAKE) helm-install-opensearch HELM_VALUES= diff --git a/deployment/charts/opensearch-dashboards/README.md b/deployment/charts/opensearch-dashboards/README.md index f35765ec..d1fe5433 100644 --- a/deployment/charts/opensearch-dashboards/README.md +++ b/deployment/charts/opensearch-dashboards/README.md @@ -4,11 +4,23 @@ Install this release in the same namespace as [OpenSearch](../opensearch/README. Dashboards connects to the OpenSearch Service and stores its saved objects in OpenSearch. -For the shared Security policy, set `opensearch-dashboards.opensearchAccount.secret` -to a Secret in the release namespace with keys `username`, `password`, and `cookie`. -Use `kibanaserver`, the same password as `KIBANA_PASSWORD` at bootstrap, and a -random cookie key. Use `opensearchDashboards.index: .kibana` in a fresh deployment -to match the built-in `kibana_server` role. +From the repository root, load the `dashboards-auth` Secret in the namespace set +in `deployment/env/general.env`. The target uses `KIBANA_PASSWORD` from the +environment, `deployment/env/authentication.env`, or the existing Secret, and +prompts if it needs a password. It generates a cookie key on first use and +reuses it on subsequent runs. Load this Secret before the OpenSearch bootstrap +to share the `kibanaserver` password. If OpenSearch is already initialized, use +its current `kibanaserver` password. + +```bash +make -C deployment k3s-load-auth-opensearch-dashboards +``` + +Set `opensearch-dashboards.opensearchAccount.secret: dashboards-auth` in your Helm +values. Set `opensearch_security.cookie.password: ${COOKIE_PASS}` in your +`opensearch_dashboards.yml` to use the cookie key from the Secret. Use +`opensearchDashboards.index: .kibana` in a fresh deployment to match the built-in +`kibana_server` role. ```bash helm repo add opensearch https://opensearch-project.github.io/helm-charts/ diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index df7637a4..95853a44 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -39,6 +39,22 @@ Transport TLS checks the CA and shared node DN. Set `KUBE_NAMESPACE` or `CLUSTER_DOMAIN` when issuing the certificate if either differs from `search` or `cluster.local`. +### Authentication + +For K3s, initialize Security after OpenSearch starts. The Make target uses +`KUBE_NAMESPACE` from `deployment/env/general.env`. + +```bash +make -C deployment k3s-load-auth-opensearch +``` + +Set `KIBANA_PASSWORD` in the environment or in `deployment/env/authentication.env`. +Use `OPENSEARCH_AUTH_FILE` to select a different file. If no password is supplied, +the target uses `dashboards-auth` if present or prompts in a terminal. The same +file or environment can supply the optional user passwords below. On an +initialized cluster the target reports that Security is already initialized. + +For direct Helm installs, run the bootstrap script with the following settings. Export `KIBANA_PASSWORD` for `kibanaserver`. Set `OS_NIFI_PASSWORD`, `OS_PIPELINE_PASSWORD`, or `OS_ANALYST_PASSWORD` to create `nifi`, `cogstack_pipeline`, or `cogstack_user`, respectively. Export the absolute diff --git a/deployment/scripts/security/load_opensearch_auth.sh b/deployment/scripts/security/load_opensearch_auth.sh new file mode 100644 index 00000000..f3b7560a --- /dev/null +++ b/deployment/scripts/security/load_opensearch_auth.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +set -euo pipefail + +service=${1:-} +case "$service" in + opensearch|opensearch-dashboards) ;; + *) printf '%s\n' 'Specify opensearch or opensearch-dashboards.' >&2; exit 2 ;; +esac + +script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../../env/general.env +source "$script_dir/../../env/general.env" +namespace="${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" +pod=opensearch-cluster-master-0 + +if [[ "$service" == opensearch ]]; then + status=$(kubectl -n "$namespace" exec "$pod" -- curl -sS --noproxy '*' \ + --retry 3 --retry-delay 2 --retry-connrefused --max-time 10 \ + --cacert /usr/share/opensearch/config/tls/ca.crt --output /dev/null \ + --write-out '%{http_code}' https://localhost:9200/_plugins/_security/health) + case "$status" in + 200) printf '%s\n' 'OpenSearch Security is already initialized.'; exit 0 ;; + 503) ;; + *) printf 'OpenSearch Security health check returned HTTP %s.\n' "$status" >&2; exit 1 ;; + esac +fi + +auth_file=${OPENSEARCH_AUTH_FILE:-$script_dir/../../env/authentication.env} +# shellcheck disable=SC1090 # Optional deployment credentials. +if [[ -f "$auth_file" || -n ${OPENSEARCH_AUTH_FILE:-} ]]; then source "$auth_file"; fi +# shellcheck source=password_prompt.sh +source "$script_dir/password_prompt.sh" + +existing= +if [[ "$service" == opensearch-dashboards || -z ${KIBANA_PASSWORD:-} ]]; then + existing=$(kubectl -n "$namespace" get secret dashboards-auth --ignore-not-found -o json) +fi +if [[ -z ${KIBANA_PASSWORD:-} && -n "$existing" ]]; then + # Append a character so command substitution preserves trailing newlines. + stored_password=$(jq -j '(.data.password // "" | @base64d) + "."' <<< "$existing") + KIBANA_PASSWORD=${stored_password%.} +fi +require_password KIBANA_PASSWORD + +if [[ "$service" == opensearch ]]; then + export OS_NIFI_PASSWORD OS_PIPELINE_PASSWORD OS_ANALYST_PASSWORD + exec bash "$script_dir/../../charts/opensearch/security/bootstrap.sh" kubectl -n "$namespace" exec -i "$pod" -- +fi + +DASHBOARDS_COOKIE_DATA=$(jq -r '.data.cookie // ""' <<< "$existing") +if [[ -z "$DASHBOARDS_COOKIE_DATA" ]]; then + cookie=$(openssl rand -hex 16) + DASHBOARDS_COOKIE_DATA=$(printf '%s' "$cookie" | openssl base64 -A) +fi +export DASHBOARDS_COOKIE_DATA + +manifest=$(jq -s '.[0] | { + apiVersion: "v1", kind: "Secret", type: "Opaque", + metadata: {name: "dashboards-auth", resourceVersion: .metadata.resourceVersion}, + data: { + username: ("kibanaserver" | @base64), + password: (env.KIBANA_PASSWORD | @base64), + cookie: env.DASHBOARDS_COOKIE_DATA + } +}' <<< "$existing") +if [[ -z "$existing" ]]; then + kubectl -n "$namespace" create -f - <<< "$manifest" +else + kubectl -n "$namespace" patch secret dashboards-auth --type=merge --patch-file=/dev/stdin <<< "$manifest" +fi From 46011b439f34a77f29136d3ff2b8e9803ddebcfc Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 10:34:48 +0000 Subject: [PATCH 44/63] Consolidated env files, removed _dev ones. --- .github/workflows/helm_smoke_logins.yml | 3 ++ apps/nifi/README.md | 4 +-- apps/nifi/docker/Makefile | 4 +-- deployment/.gitignore | 3 +- deployment/Makefile | 2 +- deployment/env/authentication.env | 9 +++--- deployment/env/authentication_dev.env | 8 ----- deployment/env/certificates_dev.env | 29 ------------------- deployment/scripts/README.md | 4 +-- deployment/scripts/security/load_nifi_auth.sh | 5 +--- 10 files changed, 17 insertions(+), 54 deletions(-) delete mode 100644 deployment/env/authentication_dev.env delete mode 100644 deployment/env/certificates_dev.env diff --git a/.github/workflows/helm_smoke_logins.yml b/.github/workflows/helm_smoke_logins.yml index 3cebc436..d34001be 100644 --- a/.github/workflows/helm_smoke_logins.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -9,6 +9,8 @@ on: - 'deployment/charts/opensearch/**' - 'deployment/charts/opensearch-dashboards/**' - 'deployment/Makefile' + - 'deployment/env/authentication.env' + - 'deployment/env/certificates.env' - 'deployment/env/general.env' - 'deployment/scripts/security/**' - 'deployment/security/templates/**' @@ -71,6 +73,7 @@ jobs: kubectl create configmap nifi-env --from-literal=NIFI_WEB_PROXY_HOST=127.0.0.1:8443 NIFI_SINGLE_USER_CREDENTIALS_USERNAME="$SINGLE_USER_CREDENTIALS_USERNAME" \ NIFI_SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ + NIFI_SENSITIVE_PROPS_KEY="$(openssl rand -hex 16)" \ KEYSTORE_PASSWORD="$SMOKE_PASSWORD" TRUSTSTORE_PASSWORD="$SMOKE_PASSWORD" \ make -C deployment k3s-load-auth-nifi make -C deployment helm-install-nifi HELM_TIMEOUT=15m diff --git a/apps/nifi/README.md b/apps/nifi/README.md index ac5976ee..36f90aa5 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -30,8 +30,8 @@ for the NiFi login. Use at least 12 characters for the single-user password. Use `COGSTACK_NIFI_ENV_FILE` to select another deployment's `nifi.env`. The dev Make targets take their sample store passwords and login from -[`certificates_dev.env`](../../deployment/env/certificates_dev.env) and -[`authentication_dev.env`](../../deployment/env/authentication_dev.env). +[`certificates.env`](../../deployment/env/certificates.env) and +[`authentication.env`](../../deployment/env/authentication.env). Set your own values in `nifi.env` to override the samples. Preserve `NIFI_SENSITIVE_PROPS_KEY` with the flow configuration so NiFi can diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index be306492..b347f961 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -3,8 +3,8 @@ SHELL := /usr/bin/env bash DC_START_CMD := up -d DC_STOP_CMD := stop -COMPOSE_DEV := docker compose --env-file ../../../deployment/env/certificates_dev.env \ - --env-file ../../../deployment/env/authentication_dev.env \ +COMPOSE_DEV := docker compose --env-file ../../../deployment/env/certificates.env \ + --env-file ../../../deployment/env/authentication.env \ $(if $(wildcard .env),--env-file .env) \ -f docker-compose.base.yml -f docker-compose.dev.yml COMPOSE_PROD := docker compose -f docker-compose.base.yml -f docker-compose.prod.yml diff --git a/deployment/.gitignore b/deployment/.gitignore index 2e70d787..241c1ce0 100644 --- a/deployment/.gitignore +++ b/deployment/.gitignore @@ -2,8 +2,7 @@ !/env/ /env/* !/env/certificates.env -!/env/certificates_dev.env -!/env/authentication_dev.env +!/env/authentication.env !/env/cohorter.env !/env/jupyter.env !/env/opensearch.env diff --git a/deployment/Makefile b/deployment/Makefile index 1a641508..3e652f66 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -110,7 +110,7 @@ k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-ngi .PHONY: k3s-load-auth-nifi k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards -# Uses env/authentication.env. Set NIFI_AUTH_FILE=env/authentication_dev.env for development. +# Uses env/authentication.env. Set NIFI_AUTH_FILE to choose another auth file. k3s-load-auth-nifi: ## Prompt for missing credentials and load the NiFi auth Secret @bash scripts/security/load_nifi_auth.sh diff --git a/deployment/env/authentication.env b/deployment/env/authentication.env index 7cc50672..c80717a6 100644 --- a/deployment/env/authentication.env +++ b/deployment/env/authentication.env @@ -1,7 +1,8 @@ -# Local NiFi credentials for k3s-load-auth-nifi, using development sample values. -NIFI_SINGLE_USER_CREDENTIALS_USERNAME=admin -NIFI_SINGLE_USER_CREDENTIALS_PASSWORD=cogstackNiFi +# NiFi sample credentials for Docker development and k3s-load-auth-nifi. +# Environment values override these defaults. +NIFI_SINGLE_USER_CREDENTIALS_USERNAME="${NIFI_SINGLE_USER_CREDENTIALS_USERNAME:-admin}" +NIFI_SINGLE_USER_CREDENTIALS_PASSWORD="${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD:-cogstackNiFi}" -# Helm loads the JKS passwords from certificates.env. +# Store passwords are configured in certificates.env. NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CREDENTIALS_USERNAME} NIFI_SENSITIVE_PROPS_KEY=${NIFI_SENSITIVE_PROPS_KEY:-c6063c770f5a281732877e7a9f7de2bc} diff --git a/deployment/env/authentication_dev.env b/deployment/env/authentication_dev.env deleted file mode 100644 index 3afd2bc3..00000000 --- a/deployment/env/authentication_dev.env +++ /dev/null @@ -1,8 +0,0 @@ -# Sample login for local NiFi development. -# Set NIFI_AUTH_FILE=env/authentication_dev.env when running k3s-load-auth-nifi for dev. -NIFI_SINGLE_USER_CREDENTIALS_USERNAME=admin -NIFI_SINGLE_USER_CREDENTIALS_PASSWORD=cogstackNiFi - -# Helm and Compose load the dev JKS passwords from certificates_dev.env. -NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CREDENTIALS_USERNAME} -NIFI_SENSITIVE_PROPS_KEY=${NIFI_SENSITIVE_PROPS_KEY:-c6063c770f5a281732877e7a9f7de2bc} diff --git a/deployment/env/certificates_dev.env b/deployment/env/certificates_dev.env deleted file mode 100644 index 47a8e357..00000000 --- a/deployment/env/certificates_dev.env +++ /dev/null @@ -1,29 +0,0 @@ -# Certificate generator settings with development sample passwords. -# Blank settings use the script defaults. Use --days DAYS to set validity. -# -# Load from the repository root before running a generator. -# set -a -# source deployment/env/general.env -# source deployment/env/certificates.env -# set +a - -# Blank uses deployment/security/ for certificate inputs and outputs. -SECURITY_DIR="${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_UPSTREAM_TLS_NAME:-}" -NIFI_HEALTHCHECK_HOST="${NIFI_HEALTHCHECK_HOST:-}" - -# Browser-facing NGINX DNS names or IP addresses, comma-separated. -# Blank uses localhost,127.0.0.1. -NGINX_TLS_NAMES="${NGINX_TLS_NAMES:-}" - -# Optional comma-separated DNS aliases for each OpenSearch node and for Dashboards. -OPENSEARCH_NODE_DNS_NAMES="${OPENSEARCH_NODE_DNS_NAMES:-}" -OPENSEARCH_DASHBOARDS_DNS_NAMES="${OPENSEARCH_DASHBOARDS_DNS_NAMES:-}" - -# Development store passwords. Environment values override these defaults. -ROOT_CERTIFICATE_KEYSTORE_PASSWORD="${ROOT_CERTIFICATE_KEYSTORE_PASSWORD:-cogstackNiFi}" -NIFI_KEYSTORE_PASSWORD="${NIFI_KEYSTORE_PASSWORD:-cogstackNiFi}" -NIFI_TRUSTSTORE_PASSWORD="${NIFI_TRUSTSTORE_PASSWORD:-cogstackNiFi}" diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index 3ad8a19d..e805aa8b 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -14,12 +14,12 @@ Java's `keytool`. `SECURITY_DIR` defaults to `deployment/security/`. The generators prompt for missing passwords with hidden input in a terminal. Export the required variables before running from CI or with redirected input. -To use [sample store passwords](../env/certificates_dev.env) for local development, +To use [sample store passwords](../env/certificates.env) for local development, load them before running the root CA and NiFi generators. ```bash set -a -source deployment/env/certificates_dev.env +source deployment/env/certificates.env set +a ``` diff --git a/deployment/scripts/security/load_nifi_auth.sh b/deployment/scripts/security/load_nifi_auth.sh index 5baed2db..4b6bd0e3 100644 --- a/deployment/scripts/security/load_nifi_auth.sh +++ b/deployment/scripts/security/load_nifi_auth.sh @@ -20,10 +20,7 @@ if (( ${#NIFI_SINGLE_USER_CREDENTIALS_PASSWORD} < 12 )); then printf 'NiFi login password must be at least 12 characters.\n' >&2 exit 1 fi -if [[ "$auth_file" -ef "$script_dir/../../env/authentication_dev.env" ]]; then - # shellcheck source=../../env/certificates_dev.env - source "$script_dir/../../env/certificates_dev.env" -elif [[ "$auth_file" -ef "$script_dir/../../env/authentication.env" ]]; then +if [[ "$auth_file" -ef "$script_dir/../../env/authentication.env" ]]; then # shellcheck source=../../env/certificates.env source "$script_dir/../../env/certificates.env" fi From 6bbcd9708e1b1129964fb3d2fc7b33a0101fac53 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 10:44:31 +0000 Subject: [PATCH 45/63] Added configmap laoders to makefile. --- deployment/Makefile | 15 +++++++++++++-- deployment/charts/nifi/README.md | 5 +++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/deployment/Makefile b/deployment/Makefile index 3e652f66..316924a4 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -121,6 +121,17 @@ k3s-load-auth-opensearch-dashboards: ## Load the OpenSearch Dashboards auth Secr k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards: @bash scripts/security/load_opensearch_auth.sh $(@:k3s-load-auth-%=%) +.PHONY: k3s-load-env-nifi + +k3s-load-env-nifi: ## Load the NiFi proxy hosts into the nifi-env ConfigMap + @set -eo pipefail; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + . ./env/nifi.env; \ + kubectl -n "$$namespace" create configmap nifi-env \ + --from-literal="NIFI_WEB_PROXY_HOST=$${NIFI_WEB_PROXY_HOST-}" --dry-run=client -o yaml | \ + kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-env -f - + # ====================================================================================================================================================== .PHONY: helm-values-all helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards @@ -223,13 +234,13 @@ helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIM helm upgrade --install "$$release" "$$chart" -n "$$namespace" \ --wait --timeout "$${HELM_TIMEOUT:-10m}" "$${args[@]}" -helm-install-nifi: ## Install or upgrade NiFi +helm-install-nifi: k3s-load-env-nifi ## Load the NiFi environment, then install or upgrade NiFi $(MAKE) helm-install CHART=nifi helm-install-nginx: ## Install or upgrade NGINX for NiFi $(MAKE) helm-install CHART=nginx -helm-install-nifi-stack: helm-install-nifi ## Wait for NiFi, then install or upgrade NGINX +helm-install-nifi-stack: helm-install-nifi ## Load the NiFi environment, then install or upgrade NiFi and NGINX $(MAKE) helm-install-nginx helm-install-opensearch: ## Install or upgrade OpenSearch diff --git a/deployment/charts/nifi/README.md b/deployment/charts/nifi/README.md index f3d6afc8..1a904ddd 100644 --- a/deployment/charts/nifi/README.md +++ b/deployment/charts/nifi/README.md @@ -16,6 +16,11 @@ Prepare these resources in the release namespace before installing: | Secret | `cogstack-root-ca` | `ca.crt` and `truststore.jks`; the public CA and shared truststore. | | Secret | `nifi-tls` | `nifi-keystore.jks`; the NiFi node certificate and private key. | +Both `make -C deployment helm-install-nifi` and +`make -C deployment helm-install-nifi-stack` load `NIFI_WEB_PROXY_HOST` from +`deployment/env/nifi.env` into the ConfigMap before installing NiFi. Use +`make -C deployment k3s-load-env-nifi` to apply the ConfigMap on its own. + Set `certificates.rootCASecret` and `certificates.existingSecret` to use different certificate Secret names. The environment ConfigMap and authentication Secret names are currently fixed in the workload template. From d0e228d8f2c79dd7682b616ccb13b302245d4d74 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 11:00:04 +0000 Subject: [PATCH 46/63] Env loads for NiFi/OS + env var changes. --- deployment/Makefile | 12 ++++++++++-- deployment/env/certificates.env | 10 ++++++---- deployment/scripts/README.md | 18 +++++++++++------- .../scripts/security/create_nifi_certs.sh | 7 ++++++- .../create_opensearch_client_admin_certs.sh | 7 ++++--- .../security/create_opensearch_node_cert.sh | 15 ++++++++------- deployment/scripts/security/load_nifi_auth.sh | 3 ++- 7 files changed, 47 insertions(+), 25 deletions(-) diff --git a/deployment/Makefile b/deployment/Makefile index 316924a4..b4e47a00 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -26,6 +26,8 @@ setup-verify: ## Check local Docker, Docker Compose, and K3s access without sudo .PHONY: certs certs-all certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-nodes delete-certs-all +load_certificates_env = set -e; set -a; if [ -f ./env/certificates.env ]; then . ./env/certificates.env; fi; set +a + certs: certs-root ## Generate the root CA and NiFi and NGINX certificates $(MAKE) certs-nifi certs-nginx @@ -36,27 +38,33 @@ certs-all: ## Generate the root CA and NiFi, NGINX, OpenSearch, and Dashboards c export CLUSTER_DOMAIN; \ $(MAKE) certs KUBE_NAMESPACE="$$namespace"; \ $(MAKE) certs-opensearch KUBE_NAMESPACE="$$namespace" + @$(load_certificates_env); \ OPENSEARCH_DASHBOARDS_DNS_NAMES="$${OPENSEARCH_DASHBOARDS_DNS_NAMES:-localhost}" \ bash scripts/security/create_opensearch_client_admin_certs.sh --dashboards-only certs-root: ## Generate the root CA bundle + @$(load_certificates_env); \ bash scripts/security/create_root_ca_cert.sh certs-nifi: ## Generate the NiFi certificate and stores with the existing CA bash scripts/security/create_nifi_certs.sh certs-nginx: ## Generate the NGINX certificate with the existing CA + @$(load_certificates_env); \ bash scripts/security/create_nginx_certs.sh certs-opensearch: ## Generate the shared OpenSearch node and admin client certificates - @service=opensearch-cluster-master; \ + @$(load_certificates_env); \ + service=opensearch-cluster-master; \ service_dns="$$service.$${KUBE_NAMESPACE:-search}.svc"; \ $(MAKE) certs-opensearch-nodes NODES=opensearch-shared \ OPENSEARCH_NODE_DNS_NAMES="$${OPENSEARCH_NODE_DNS_NAMES:-localhost,$$service,$$service_dns,$$service_dns.$${CLUSTER_DOMAIN:-cluster.local}}" + @$(load_certificates_env); \ bash scripts/security/create_opensearch_client_admin_certs.sh --admin-only certs-opensearch-nodes: ## Generate OpenSearch node certificates for NODES="node1 node2 ..." - @read -r -a nodes <<< "$$NODES"; \ + @$(load_certificates_env); \ + read -r -a nodes <<< "$$NODES"; \ bash scripts/security/create_opensearch_node_cert.sh "$${nodes[@]}" delete-certs-all: ## Delete generated local TLS certificates, keys, and stores diff --git a/deployment/env/certificates.env b/deployment/env/certificates.env index 47a8e357..2cb9665c 100644 --- a/deployment/env/certificates.env +++ b/deployment/env/certificates.env @@ -1,7 +1,8 @@ -# Certificate generator settings with development sample passwords. +# Certificate generator settings with development store passwords. # Blank settings use the script defaults. Use --days DAYS to set validity. # -# Load from the repository root before running a generator. +# The certificate Make targets load this file automatically. +# For a direct generator invocation, load it from the repository root. # set -a # source deployment/env/general.env # source deployment/env/certificates.env @@ -24,6 +25,7 @@ OPENSEARCH_NODE_DNS_NAMES="${OPENSEARCH_NODE_DNS_NAMES:-}" OPENSEARCH_DASHBOARDS_DNS_NAMES="${OPENSEARCH_DASHBOARDS_DNS_NAMES:-}" # Development store passwords. Environment values override these defaults. +NIFI_KEYSTORE_PASSWORD=${NIFI_KEYSTORE_PASSWORD:-cogstack} +NIFI_TRUSTSTORE_PASSWORD=${NIFI_TRUSTSTORE_PASSWORD:-cogstack} +OPENSEARCH_CERTIFICATE_PASSWORD=${OPENSEARCH_CERTIFICATE_PASSWORD:-${OS_CERTIFICATE_PASSWORD:-cogstack}} ROOT_CERTIFICATE_KEYSTORE_PASSWORD="${ROOT_CERTIFICATE_KEYSTORE_PASSWORD:-cogstackNiFi}" -NIFI_KEYSTORE_PASSWORD="${NIFI_KEYSTORE_PASSWORD:-cogstackNiFi}" -NIFI_TRUSTSTORE_PASSWORD="${NIFI_TRUSTSTORE_PASSWORD:-cogstackNiFi}" diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index e805aa8b..a5817416 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -12,10 +12,13 @@ NiFi and NGINX. The root CA, NiFi and OpenSearch node generators also use Java's `keytool`. `SECURITY_DIR` defaults to `deployment/security/`. The generators prompt for missing passwords with hidden input in a terminal. -Export the required variables before running from CI or with redirected input. +For non-interactive runs, provide the required passwords through the environment +or the generator's configuration. -To use [sample store passwords](../env/certificates.env) for local development, -load them before running the root CA and NiFi generators. +`make -C deployment certs`, `make -C deployment certs-all` and the individual +certificate targets load `deployment/env/certificates.env` automatically. For +a direct invocation of the root CA generator, load the file to use its sample +store password. ```bash set -a @@ -31,9 +34,10 @@ The root CA generator uses `ROOT_CERTIFICATE_KEYSTORE_PASSWORD`. ### NiFi -Use the `KEYSTORE_PASSWORD` and `TRUSTSTORE_PASSWORD` that NiFi will use. -The legacy `NIFI_KEYSTORE_PASSWORD` and `NIFI_TRUSTSTORE_PASSWORD` names are -also accepted. +The NiFi generator and the default `k3s-load-auth-nifi` workflow read +`NIFI_KEYSTORE_PASSWORD` and `NIFI_TRUSTSTORE_PASSWORD` from +`deployment/env/certificates.env`. `KEYSTORE_PASSWORD` and +`TRUSTSTORE_PASSWORD` take precedence when set. Choose the command for your deployment. The default NiFi certificate covers `nifi`, `localhost`, `cogstack-nifi`, `cogstack-nifi-headless`, and `127.0.0.1`. @@ -78,7 +82,7 @@ It runs without a store password or `keytool`. ### OpenSearch -Use `OS_CERTIFICATE_PASSWORD` for the Java and PKCS#12 stores. Pass the node +Use `OPENSEARCH_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. diff --git a/deployment/scripts/security/create_nifi_certs.sh b/deployment/scripts/security/create_nifi_certs.sh index eb72352a..f4ca0135 100755 --- a/deployment/scripts/security/create_nifi_certs.sh +++ b/deployment/scripts/security/create_nifi_certs.sh @@ -9,7 +9,8 @@ # # Requires: # - Bash, OpenSSL and Java keytool -# - KEYSTORE_PASSWORD and TRUSTSTORE_PASSWORD (prompted when unset) +# - NiFi store passwords from the environment or deployment/env/certificates.env +# (prompted when missing) # - root-ca.pem and root-ca.key under certificates/root/ in SECURITY_DIR # # Optional environment variables: @@ -40,6 +41,10 @@ if (( $# > 0 )); then fi script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) +if [[ -f "$script_dir/../../env/certificates.env" ]]; then + # shellcheck source=../../env/certificates.env + source "$script_dir/../../env/certificates.env" +fi 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" diff --git a/deployment/scripts/security/create_opensearch_client_admin_certs.sh b/deployment/scripts/security/create_opensearch_client_admin_certs.sh index e6c912d1..eaf36127 100755 --- a/deployment/scripts/security/create_opensearch_client_admin_certs.sh +++ b/deployment/scripts/security/create_opensearch_client_admin_certs.sh @@ -11,7 +11,7 @@ # # Requires: # - Bash and OpenSSL -# - OS_CERTIFICATE_PASSWORD for the encrypted Dashboards PKCS#12 bundle +# - OPENSEARCH_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: @@ -63,7 +63,8 @@ files=() if [[ "$mode" != --admin-only ]]; then # shellcheck source=password_prompt.sh source "$script_dir/password_prompt.sh" - require_password OS_CERTIFICATE_PASSWORD + OPENSEARCH_CERTIFICATE_PASSWORD=${OPENSEARCH_CERTIFICATE_PASSWORD:-${OS_CERTIFICATE_PASSWORD:-}} + require_password OPENSEARCH_CERTIFICATE_PASSWORD roles=(client) files=(es_kibana_client.pem es_kibana_client.key es_kibana_client.csr es_kibana_client.p12) @@ -130,7 +131,7 @@ done if [[ "$mode" != --admin-only ]]; then 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:OS_CERTIFICATE_PASSWORD + -keypbe AES-256-CBC -certpbe AES-256-CBC -passout env:OPENSEARCH_CERTIFICATE_PASSWORD fi (umask 022; mkdir -p -- "$output_dir") diff --git a/deployment/scripts/security/create_opensearch_node_cert.sh b/deployment/scripts/security/create_opensearch_node_cert.sh index f5bf600a..3dab08b7 100755 --- a/deployment/scripts/security/create_opensearch_node_cert.sh +++ b/deployment/scripts/security/create_opensearch_node_cert.sh @@ -8,7 +8,7 @@ # # Requires: # - Bash, OpenSSL and Java keytool -# - OS_CERTIFICATE_PASSWORD for the PKCS#12 bundle and Java stores +# - OPENSEARCH_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: @@ -110,7 +110,8 @@ fi # shellcheck source=password_prompt.sh source "$script_dir/password_prompt.sh" -require_password OS_CERTIFICATE_PASSWORD +OPENSEARCH_CERTIFICATE_PASSWORD=${OPENSEARCH_CERTIFICATE_PASSWORD:-${OS_CERTIFICATE_PASSWORD:-}} +require_password OPENSEARCH_CERTIFICATE_PASSWORD # Stage all node bundles before writing deployment files. Roll back writes on failure. scratch_dir=$(mktemp -d) @@ -152,15 +153,15 @@ for node in "$@"; do # 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:OS_CERTIFICATE_PASSWORD + -passout env:OPENSEARCH_CERTIFICATE_PASSWORD keytool -importkeystore -noprompt -alias "$node" \ - -srckeystore "$stage.p12" -srcstoretype PKCS12 -srcstorepass:env OS_CERTIFICATE_PASSWORD \ + -srckeystore "$stage.p12" -srcstoretype PKCS12 -srcstorepass:env OPENSEARCH_CERTIFICATE_PASSWORD \ -destkeystore "$stage-keystore.jks" -deststoretype JKS \ - -deststorepass:env OS_CERTIFICATE_PASSWORD -destkeypass:env OS_CERTIFICATE_PASSWORD + -deststorepass:env OPENSEARCH_CERTIFICATE_PASSWORD -destkeypass:env OPENSEARCH_CERTIFICATE_PASSWORD keytool -importcert -noprompt -alias root-ca -file "$ca_cert" \ - -keystore "$stage-keystore.jks" -storetype JKS -storepass:env OS_CERTIFICATE_PASSWORD + -keystore "$stage-keystore.jks" -storetype JKS -storepass:env OPENSEARCH_CERTIFICATE_PASSWORD keytool -importcert -noprompt -alias "$node" -file "$stage.crt" \ - -keystore "$stage-truststore.key" -storetype JKS -storepass:env OS_CERTIFICATE_PASSWORD + -keystore "$stage-truststore.key" -storetype JKS -storepass:env OPENSEARCH_CERTIFICATE_PASSWORD done # Private files inherit mode 0600, and noclobber protects concurrent writes. diff --git a/deployment/scripts/security/load_nifi_auth.sh b/deployment/scripts/security/load_nifi_auth.sh index 4b6bd0e3..2ae6dd3a 100644 --- a/deployment/scripts/security/load_nifi_auth.sh +++ b/deployment/scripts/security/load_nifi_auth.sh @@ -20,7 +20,8 @@ if (( ${#NIFI_SINGLE_USER_CREDENTIALS_PASSWORD} < 12 )); then printf 'NiFi login password must be at least 12 characters.\n' >&2 exit 1 fi -if [[ "$auth_file" -ef "$script_dir/../../env/authentication.env" ]]; then +if [[ -f "$script_dir/../../env/certificates.env" && + ( -z ${NIFI_AUTH_FILE:-} || "$auth_file" -ef "$script_dir/../../env/authentication.env" ) ]]; then # shellcheck source=../../env/certificates.env source "$script_dir/../../env/certificates.env" fi From f6761d7c5a4aaf7a4d391eb485623a92260429f9 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 11:00:17 +0000 Subject: [PATCH 47/63] Env updates. --- deployment/env/network_settings.env | 20 ++++++++++++++++++++ deployment/env/nifi.env | 1 + 2 files changed, 21 insertions(+) create mode 100644 deployment/env/network_settings.env create mode 120000 deployment/env/nifi.env diff --git a/deployment/env/network_settings.env b/deployment/env/network_settings.env new file mode 100644 index 00000000..5ae69fcb --- /dev/null +++ b/deployment/env/network_settings.env @@ -0,0 +1,20 @@ +# use this file to set EXTRA_HOSTS in docker-compose +# useful if you have the services on separate machines/servers +# and you have generated SSL certificates using the container names rather than IP addresses +# this is the equivalent of /etc/hosts file, read this: https://tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap9sec95.html + + +# example ELASTICSEARCH_1_HOST_NAME="elasticsearch-1:0.0.0.0" +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" + +# general network settings +HTTPS_PROXY="" +HTTP_PROXY="" +NO_PROXY="" +no_proxy="" +http_proxy="" +https_proxy="" diff --git a/deployment/env/nifi.env b/deployment/env/nifi.env new file mode 120000 index 00000000..29e37aa8 --- /dev/null +++ b/deployment/env/nifi.env @@ -0,0 +1 @@ +../../apps/nifi/env/nifi.env \ No newline at end of file From 090d2768ca12c9cf0413895695965657be747a15 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 11:14:03 +0000 Subject: [PATCH 48/63] Os auth+certs. --- .github/workflows/helm_smoke_logins.yml | 4 +-- apps/opensearch/config/opensearch.yml | 1 + apps/opensearch/security/bootstrap.sh | 9 ++++-- deployment/Makefile | 29 ++++++++++++++----- deployment/charts/nginx/README.md | 5 ++++ .../charts/opensearch-dashboards/README.md | 2 +- deployment/charts/opensearch/README.md | 11 +++++-- deployment/charts/opensearch/values.env.yaml | 4 +++ deployment/charts/opensearch/values.yaml | 4 +++ deployment/env/authentication.env | 6 ++++ .../scripts/security/load_opensearch_auth.sh | 14 +++++---- 11 files changed, 66 insertions(+), 23 deletions(-) diff --git a/.github/workflows/helm_smoke_logins.yml b/.github/workflows/helm_smoke_logins.yml index d34001be..bf46566c 100644 --- a/.github/workflows/helm_smoke_logins.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -70,7 +70,6 @@ jobs: - name: Install NiFi if: matrix.stack == 'nifi' || matrix.stack == 'nginx' run: | - kubectl create configmap nifi-env --from-literal=NIFI_WEB_PROXY_HOST=127.0.0.1:8443 NIFI_SINGLE_USER_CREDENTIALS_USERNAME="$SINGLE_USER_CREDENTIALS_USERNAME" \ NIFI_SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ NIFI_SENSITIVE_PROPS_KEY="$(openssl rand -hex 16)" \ @@ -88,7 +87,6 @@ jobs: - name: NGINX Helm proxy login if: matrix.stack == 'nifi' || matrix.stack == 'nginx' run: | - kubectl create configmap nginx-env make -C deployment helm-install-nginx HELM_TIMEOUT=5m kubectl port-forward svc/cogstack-nginx 8443:8443 & trap 'kill "$!"' EXIT @@ -99,7 +97,7 @@ jobs: run: | sudo sysctl -w vm.max_map_count=262144 make -C deployment helm-install-opensearch - KIBANA_PASSWORD="$SMOKE_PASSWORD" OS_ANALYST_PASSWORD="$SMOKE_PASSWORD" \ + OPENSEARCH_KIBANA_PASSWORD="$SMOKE_PASSWORD" OPENSEARCH_ANALYST_PASSWORD="$SMOKE_PASSWORD" \ make -C deployment k3s-bootstrap-opensearch kubectl port-forward svc/opensearch-cluster-master 9200:9200 & trap 'kill "$!"' EXIT diff --git a/apps/opensearch/config/opensearch.yml b/apps/opensearch/config/opensearch.yml index dde30ff7..1966adbd 100644 --- a/apps/opensearch/config/opensearch.yml +++ b/apps/opensearch/config/opensearch.yml @@ -1,5 +1,6 @@ network.host: '${OPENSEARCH_NETWORK_HOST:0.0.0.0}' network.publish_host: '${OPENSEARCH_NETWORK_PUBLISH_HOST:}' +logger.level: '${OPENSEARCH_LOG_LEVEL:INFO}' ###### CLUSTER CONFIGURATION ###### diff --git a/apps/opensearch/security/bootstrap.sh b/apps/opensearch/security/bootstrap.sh index 2eea0020..9eb75d26 100644 --- a/apps/opensearch/security/bootstrap.sh +++ b/apps/opensearch/security/bootstrap.sh @@ -6,14 +6,17 @@ if (( $# == 0 )); then printf 'Usage: bash %s \n' "$0" >&2 exit 2 fi -: "${KIBANA_PASSWORD:?Set the Dashboards service account password}" +OPENSEARCH_KIBANA_PASSWORD=${OPENSEARCH_KIBANA_PASSWORD:-${KIBANA_PASSWORD:-}} +: "${OPENSEARCH_KIBANA_PASSWORD:?Set the Dashboards service account password}" policy_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P) certs=$(cd -- "${SECURITY_DIR:-$policy_dir/../../../deployment/security}/certificates/opensearch" && pwd -P) scratch=$(mktemp -d) trap 'rm -rf -- "$scratch"' EXIT -printf '%s\0' kibanaserver "$KIBANA_PASSWORD" nifi "${OS_NIFI_PASSWORD:-}" \ - cogstack_pipeline "${OS_PIPELINE_PASSWORD:-}" cogstack_user "${OS_ANALYST_PASSWORD:-}" > "$scratch/passwords" +printf '%s\0' kibanaserver "$OPENSEARCH_KIBANA_PASSWORD" \ + nifi "${OPENSEARCH_NIFI_PASSWORD:-${OS_NIFI_PASSWORD:-}}" \ + cogstack_pipeline "${OPENSEARCH_PIPELINE_PASSWORD:-${OS_PIPELINE_PASSWORD:-}}" \ + cogstack_user "${OPENSEARCH_ANALYST_PASSWORD:-${OS_ANALYST_PASSWORD:-}}" > "$scratch/passwords" bootstrap=$(cat <<'BASH' set -euo pipefail diff --git a/deployment/Makefile b/deployment/Makefile index b4e47a00..45528b7d 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -129,15 +129,30 @@ k3s-load-auth-opensearch-dashboards: ## Load the OpenSearch Dashboards auth Secr k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards: @bash scripts/security/load_opensearch_auth.sh $(@:k3s-load-auth-%=%) -.PHONY: k3s-load-env-nifi +.PHONY: k3s-load-env-all k3s-load-env-nifi k3s-load-env-nginx k3s-load-env-opensearch +k3s-load-env-all: k3s-load-env-nifi k3s-load-env-nginx k3s-load-env-opensearch ## Load all runtime environment ConfigMaps k3s-load-env-nifi: ## Load the NiFi proxy hosts into the nifi-env ConfigMap +k3s-load-env-nginx: ## Load the NGINX runtime settings into the nginx-env ConfigMap +k3s-load-env-opensearch: ## Load the OpenSearch log level into the opensearch-env ConfigMap + +k3s-load-env-nifi k3s-load-env-nginx k3s-load-env-opensearch: @set -eo pipefail; \ . ./env/general.env; \ namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - . ./env/nifi.env; \ - kubectl -n "$$namespace" create configmap nifi-env \ - --from-literal="NIFI_WEB_PROXY_HOST=$${NIFI_WEB_PROXY_HOST-}" --dry-run=client -o yaml | \ + service=$(@:k3s-load-env-%=%); \ + env_file="./env/$$service.env"; \ + if [[ "$$service" != nginx || -f "$$env_file" ]]; then . "$$env_file"; fi; \ + args=(); \ + case "$$service" in \ + nifi) args+=("--from-literal=NIFI_WEB_PROXY_HOST=$${NIFI_WEB_PROXY_HOST-}");; \ + nginx) \ + for name in NGINX_NIFI_SERVER_NAME NGINX_PROXY_CONTEXT_PATH NGINX_PROXY_SCHEME; do \ + if [[ -n $${!name+x} ]]; then args+=("--from-literal=$$name=$${!name}"); fi; \ + done;; \ + opensearch) args+=("--from-literal=OPENSEARCH_LOG_LEVEL=$${OPENSEARCH_LOG_LEVEL:-INFO}");; \ + esac; \ + kubectl -n "$$namespace" create configmap "$$service-env" "$${args[@]}" --dry-run=client -o yaml | \ kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-env -f - # ====================================================================================================================================================== @@ -245,13 +260,13 @@ helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIM helm-install-nifi: k3s-load-env-nifi ## Load the NiFi environment, then install or upgrade NiFi $(MAKE) helm-install CHART=nifi -helm-install-nginx: ## Install or upgrade NGINX for NiFi +helm-install-nginx: k3s-load-env-nginx ## Load the NGINX environment, then install or upgrade NGINX $(MAKE) helm-install CHART=nginx -helm-install-nifi-stack: helm-install-nifi ## Load the NiFi environment, then install or upgrade NiFi and NGINX +helm-install-nifi-stack: helm-install-nifi ## Load the runtime environment and install or upgrade NiFi and NGINX $(MAKE) helm-install-nginx -helm-install-opensearch: ## Install or upgrade OpenSearch +helm-install-opensearch: k3s-load-env-opensearch ## Load the OpenSearch environment, then install or upgrade OpenSearch $(MAKE) helm-install CHART=opensearch helm-install-opensearch-dashboards: ## Install or upgrade OpenSearch Dashboards diff --git a/deployment/charts/nginx/README.md b/deployment/charts/nginx/README.md index 31ecc1e1..2d729170 100644 --- a/deployment/charts/nginx/README.md +++ b/deployment/charts/nginx/README.md @@ -15,6 +15,11 @@ Prepare these resources in the release namespace before installing: | Secret | `cogstack-root-ca` | `ca.crt`, the public CA for upstream TLS verification. | | TLS Secret | `nginx-tls` | `tls.crt` and `tls.key` for the proxy certificate. | +`make -C deployment helm-install-nginx` applies `nginx-env` before invoking Helm. +Set `NGINX_NIFI_SERVER_NAME`, `NGINX_PROXY_CONTEXT_PATH`, or `NGINX_PROXY_SCHEME` +in `deployment/env/nginx.env` to override the proxy defaults. Run +`make -C deployment k3s-load-env-nginx` to apply the ConfigMap separately. + The environment ConfigMap names are currently fixed in the template. Override certificate Secret names with `tls.rootCASecret` and `tls.existingSecret`. The chart references these inputs rather than creating them from host files. diff --git a/deployment/charts/opensearch-dashboards/README.md b/deployment/charts/opensearch-dashboards/README.md index d1fe5433..8c14f9ea 100644 --- a/deployment/charts/opensearch-dashboards/README.md +++ b/deployment/charts/opensearch-dashboards/README.md @@ -5,7 +5,7 @@ Dashboards connects to the OpenSearch Service and stores its saved objects in OpenSearch. From the repository root, load the `dashboards-auth` Secret in the namespace set -in `deployment/env/general.env`. The target uses `KIBANA_PASSWORD` from the +in `deployment/env/general.env`. The target uses `OPENSEARCH_KIBANA_PASSWORD` from the environment, `deployment/env/authentication.env`, or the existing Secret, and prompts if it needs a password. It generates a cookie key on first use and reuses it on subsequent runs. Load this Secret before the OpenSearch bootstrap diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index 95853a44..3d9d85b0 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -35,6 +35,10 @@ helm upgrade --install opensearch "$chart" -n search \ ``` Helm loads the bundled [`opensearch.yml`](config/opensearch.yml) through `--set-file`. +`make -C deployment helm-install-opensearch` applies `OPENSEARCH_LOG_LEVEL` +from `deployment/env/opensearch.env` before invoking Helm. To apply all three +runtime ConfigMaps together, run `make -C deployment k3s-load-env-all`. + Transport TLS checks the CA and shared node DN. Set `KUBE_NAMESPACE` or `CLUSTER_DOMAIN` when issuing the certificate if either differs from `search` or `cluster.local`. @@ -48,15 +52,16 @@ For K3s, initialize Security after OpenSearch starts. The Make target uses make -C deployment k3s-load-auth-opensearch ``` -Set `KIBANA_PASSWORD` in the environment or in `deployment/env/authentication.env`. +Set `OPENSEARCH_KIBANA_PASSWORD` in the environment or in `deployment/env/authentication.env`. Use `OPENSEARCH_AUTH_FILE` to select a different file. If no password is supplied, the target uses `dashboards-auth` if present or prompts in a terminal. The same file or environment can supply the optional user passwords below. On an initialized cluster the target reports that Security is already initialized. For direct Helm installs, run the bootstrap script with the following settings. -Export `KIBANA_PASSWORD` for `kibanaserver`. Set `OS_NIFI_PASSWORD`, -`OS_PIPELINE_PASSWORD`, or `OS_ANALYST_PASSWORD` to create `nifi`, +Export `OPENSEARCH_KIBANA_PASSWORD` for `kibanaserver`. Set +`OPENSEARCH_NIFI_PASSWORD`, `OPENSEARCH_PIPELINE_PASSWORD`, or +`OPENSEARCH_ANALYST_PASSWORD` to create `nifi`, `cogstack_pipeline`, or `cogstack_user`, respectively. Export the absolute `SECURITY_DIR` for a packaged chart or custom certificate location. After the OpenSearch cluster forms, initialize Security once before starting Dashboards. diff --git a/deployment/charts/opensearch/values.env.yaml b/deployment/charts/opensearch/values.env.yaml index 5383e798..5a67bade 100644 --- a/deployment/charts/opensearch/values.env.yaml +++ b/deployment/charts/opensearch/values.env.yaml @@ -10,6 +10,10 @@ opensearch: extraEnvs: - name: DISABLE_INSTALL_DEMO_CONFIG value: "true" + envFrom: + - configMapRef: + name: opensearch-env + optional: true secretMounts: - name: node-tls secretName: opensearch-node-tls diff --git a/deployment/charts/opensearch/values.yaml b/deployment/charts/opensearch/values.yaml index 1dfd7ea0..ea01e620 100644 --- a/deployment/charts/opensearch/values.yaml +++ b/deployment/charts/opensearch/values.yaml @@ -10,6 +10,10 @@ opensearch: extraEnvs: - name: DISABLE_INSTALL_DEMO_CONFIG value: "true" + envFrom: + - configMapRef: + name: opensearch-env + optional: true secretMounts: - name: node-tls secretName: opensearch-node-tls diff --git a/deployment/env/authentication.env b/deployment/env/authentication.env index c80717a6..aa871deb 100644 --- a/deployment/env/authentication.env +++ b/deployment/env/authentication.env @@ -6,3 +6,9 @@ NIFI_SINGLE_USER_CREDENTIALS_PASSWORD="${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD:- # Store passwords are configured in certificates.env. NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CREDENTIALS_USERNAME} NIFI_SENSITIVE_PROPS_KEY=${NIFI_SENSITIVE_PROPS_KEY:-c6063c770f5a281732877e7a9f7de2bc} + +# OpenSearch passwords for kibanaserver, nifi, cogstack_pipeline and cogstack_user. +OPENSEARCH_KIBANA_PASSWORD=${OPENSEARCH_KIBANA_PASSWORD:-} +OPENSEARCH_NIFI_PASSWORD=${OPENSEARCH_NIFI_PASSWORD:-} +OPENSEARCH_PIPELINE_PASSWORD=${OPENSEARCH_PIPELINE_PASSWORD:-} +OPENSEARCH_ANALYST_PASSWORD=${OPENSEARCH_ANALYST_PASSWORD:-} diff --git a/deployment/scripts/security/load_opensearch_auth.sh b/deployment/scripts/security/load_opensearch_auth.sh index f3b7560a..21d9b6ff 100644 --- a/deployment/scripts/security/load_opensearch_auth.sh +++ b/deployment/scripts/security/load_opensearch_auth.sh @@ -31,19 +31,21 @@ if [[ -f "$auth_file" || -n ${OPENSEARCH_AUTH_FILE:-} ]]; then source "$auth_fil # shellcheck source=password_prompt.sh source "$script_dir/password_prompt.sh" +OPENSEARCH_KIBANA_PASSWORD=${OPENSEARCH_KIBANA_PASSWORD:-${KIBANA_PASSWORD:-}} existing= -if [[ "$service" == opensearch-dashboards || -z ${KIBANA_PASSWORD:-} ]]; then +if [[ "$service" == opensearch-dashboards || -z "$OPENSEARCH_KIBANA_PASSWORD" ]]; then existing=$(kubectl -n "$namespace" get secret dashboards-auth --ignore-not-found -o json) fi -if [[ -z ${KIBANA_PASSWORD:-} && -n "$existing" ]]; then +if [[ -z "$OPENSEARCH_KIBANA_PASSWORD" && -n "$existing" ]]; then # Append a character so command substitution preserves trailing newlines. stored_password=$(jq -j '(.data.password // "" | @base64d) + "."' <<< "$existing") - KIBANA_PASSWORD=${stored_password%.} + OPENSEARCH_KIBANA_PASSWORD=${stored_password%.} fi -require_password KIBANA_PASSWORD +require_password OPENSEARCH_KIBANA_PASSWORD if [[ "$service" == opensearch ]]; then - export OS_NIFI_PASSWORD OS_PIPELINE_PASSWORD OS_ANALYST_PASSWORD + export OPENSEARCH_NIFI_PASSWORD OPENSEARCH_PIPELINE_PASSWORD OPENSEARCH_ANALYST_PASSWORD \ + OS_NIFI_PASSWORD OS_PIPELINE_PASSWORD OS_ANALYST_PASSWORD exec bash "$script_dir/../../charts/opensearch/security/bootstrap.sh" kubectl -n "$namespace" exec -i "$pod" -- fi @@ -59,7 +61,7 @@ manifest=$(jq -s '.[0] | { metadata: {name: "dashboards-auth", resourceVersion: .metadata.resourceVersion}, data: { username: ("kibanaserver" | @base64), - password: (env.KIBANA_PASSWORD | @base64), + password: (env.OPENSEARCH_KIBANA_PASSWORD | @base64), cookie: env.DASHBOARDS_COOKIE_DATA } }' <<< "$existing") From e72580c65537d80bb64a26a82377410901735e27 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 11:22:56 +0000 Subject: [PATCH 49/63] GHA fix nifi. --- deployment/Makefile | 2 +- deployment/charts/nifi/README.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deployment/Makefile b/deployment/Makefile index 45528b7d..d67e2e0b 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -142,7 +142,7 @@ k3s-load-env-nifi k3s-load-env-nginx k3s-load-env-opensearch: namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ service=$(@:k3s-load-env-%=%); \ env_file="./env/$$service.env"; \ - if [[ "$$service" != nginx || -f "$$env_file" ]]; then . "$$env_file"; fi; \ + if [[ "$$service" == opensearch || -f "$$env_file" ]]; then . "$$env_file"; fi; \ args=(); \ case "$$service" in \ nifi) args+=("--from-literal=NIFI_WEB_PROXY_HOST=$${NIFI_WEB_PROXY_HOST-}");; \ diff --git a/deployment/charts/nifi/README.md b/deployment/charts/nifi/README.md index 1a904ddd..4725a6a4 100644 --- a/deployment/charts/nifi/README.md +++ b/deployment/charts/nifi/README.md @@ -18,7 +18,8 @@ Prepare these resources in the release namespace before installing: Both `make -C deployment helm-install-nifi` and `make -C deployment helm-install-nifi-stack` load `NIFI_WEB_PROXY_HOST` from -`deployment/env/nifi.env` into the ConfigMap before installing NiFi. Use +`deployment/env/nifi.env` when present. With a missing env file, set +`NIFI_WEB_PROXY_HOST` in the shell to supply the proxy hosts. Use `make -C deployment k3s-load-env-nifi` to apply the ConfigMap on its own. Set `certificates.rootCASecret` and `certificates.existingSecret` to use different From 89255bf3729b73d954e7523795747851c02a4d36 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 15:48:05 +0000 Subject: [PATCH 50/63] chrome (helm): terminate public HTTPS at NGINX Proxy NiFi, OpenSearch REST, and Dashboards over internal HTTP. Authenticate NiFi at NGINX and restrict backend access with a NetworkPolicy. --- .github/workflows/helm_smoke_logins.yml | 89 ++++++-------- deployment/Makefile | 42 +++---- deployment/charts/README.md | 35 ++++-- deployment/charts/nginx/Chart.yaml | 2 +- deployment/charts/nginx/README.md | 92 +++++---------- deployment/charts/nginx/ci/ci-values.yaml | 2 + deployment/charts/nginx/nginx.conf.template | 62 ++++++++++ .../charts/nginx/templates/configmap.yaml | 9 +- .../charts/nginx/templates/deployment.yaml | 45 +++---- .../charts/nginx/templates/ingress.yaml | 41 ------- .../charts/nginx/templates/service.yaml | 4 +- deployment/charts/nginx/values.env.yaml | 22 ++-- deployment/charts/nginx/values.yaml | 22 ++-- deployment/charts/nifi/README.md | 58 +++------ .../charts/nifi/templates/networkpolicy.yaml | 17 +++ deployment/charts/nifi/templates/service.yaml | 6 +- .../charts/nifi/templates/statefulset.yaml | 66 +++++------ .../charts/nifi/templates/tls-configmap.yaml | 17 --- deployment/charts/nifi/values.env.yaml | 9 +- deployment/charts/nifi/values.yaml | 9 +- .../charts/opensearch-dashboards/README.md | 33 +++--- .../opensearch-dashboards/ci/ci-values.yaml | 3 + .../opensearch-dashboards/values.env.yaml | 13 ++- .../charts/opensearch-dashboards/values.yaml | 13 ++- deployment/charts/opensearch/README.md | 110 +++++++----------- .../charts/opensearch/ci/ci-values.yaml | 7 ++ deployment/charts/opensearch/values.env.yaml | 10 ++ deployment/charts/opensearch/values.yaml | 10 ++ deployment/scripts/README.md | 14 +-- deployment/scripts/security/load_nifi_auth.sh | 27 ++--- .../scripts/security/load_opensearch_auth.sh | 42 ++++--- .../scripts/security/password_prompt.sh | 9 ++ 32 files changed, 456 insertions(+), 484 deletions(-) create mode 100644 deployment/charts/nginx/nginx.conf.template delete mode 100644 deployment/charts/nginx/templates/ingress.yaml create mode 100644 deployment/charts/nifi/templates/networkpolicy.yaml delete mode 100644 deployment/charts/nifi/templates/tls-configmap.yaml create mode 100644 deployment/charts/opensearch-dashboards/ci/ci-values.yaml diff --git a/.github/workflows/helm_smoke_logins.yml b/.github/workflows/helm_smoke_logins.yml index bf46566c..71f20bb1 100644 --- a/.github/workflows/helm_smoke_logins.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -15,7 +15,6 @@ on: - 'deployment/scripts/security/**' - 'deployment/security/templates/**' - 'apps/opensearch/**' - - '.github/scripts/smoke_nifi_login.sh' - '.github/workflows/helm_smoke_logins.yml' pull_request: paths: *paths @@ -56,15 +55,20 @@ jobs: - uses: helm/kind-action@v1.15.2 - name: Generate and load certificates + env: + STACK: ${{ matrix.stack }} run: | + command -v htpasswd >/dev/null || sudo apt-get install -y apache2-utils source deployment/env/general.env SECURITY_DIR=$(mktemp -d "$RUNNER_TEMP/helm-smoke.XXXXXX") password=$(openssl rand -hex 16) printf '::add-mask::%s\n' "$password" printf 'SECURITY_DIR=%s\nSMOKE_PASSWORD=%s\n' "$SECURITY_DIR" "$password" >> "$GITHUB_ENV" export SECURITY_DIR ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" OS_CERTIFICATE_PASSWORD="$password" - export KEYSTORE_PASSWORD="$password" TRUSTSTORE_PASSWORD="$password" - make -C deployment -j1 setup-k3s-namespace certs-all k3s-load-certs-all + make -C deployment -j1 setup-k3s-namespace certs-root certs-nginx k3s-load-certs-nginx + if [[ "$STACK" == opensearch ]]; then + make -C deployment -j1 certs-opensearch-nodes k3s-load-certs-opensearch NODES=opensearch-shared + fi kubectl config set-context --current --namespace="$KUBE_NAMESPACE" - name: Install NiFi @@ -73,71 +77,50 @@ jobs: NIFI_SINGLE_USER_CREDENTIALS_USERNAME="$SINGLE_USER_CREDENTIALS_USERNAME" \ NIFI_SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ NIFI_SENSITIVE_PROPS_KEY="$(openssl rand -hex 16)" \ - KEYSTORE_PASSWORD="$SMOKE_PASSWORD" TRUSTSTORE_PASSWORD="$SMOKE_PASSWORD" \ make -C deployment k3s-load-auth-nifi make -C deployment helm-install-nifi HELM_TIMEOUT=15m - - name: NiFi Helm login - if: matrix.stack == 'nifi' + - name: Install OpenSearch and Dashboards + if: matrix.stack == 'opensearch' run: | - kubectl port-forward svc/cogstack-nifi 8443:8443 & - trap 'kill "$!"' EXIT - SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" bash .github/scripts/smoke_nifi_login.sh https://127.0.0.1:8443 + sudo sysctl -w vm.max_map_count=262144 + OPENSEARCH_KIBANA_PASSWORD="$SMOKE_PASSWORD" OPENSEARCH_ANALYST_PASSWORD="$SMOKE_PASSWORD" \ + make -C deployment helm-install-opensearch-stack + + - name: Install NGINX + run: | + make -C deployment helm-install-nginx HELM_VALUES=- HELM_TIMEOUT=5m <<'YAML' + service: + type: ClusterIP + YAML - name: NGINX Helm proxy login if: matrix.stack == 'nifi' || matrix.stack == 'nginx' run: | - make -C deployment helm-install-nginx HELM_TIMEOUT=5m - kubectl port-forward svc/cogstack-nginx 8443:8443 & + kubectl port-forward svc/cogstack-nginx 8443:443 & trap 'kill "$!"' EXIT - SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" bash .github/scripts/smoke_nifi_login.sh https://127.0.0.1:8443 + request=(curl -sS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" + --retry 12 --retry-all-errors --retry-delay 2 --max-time 10) + api=https://127.0.0.1:8443/nifi-api/flow/current-user + [[ $("${request[@]}" -o /dev/null -w '%{http_code}' "$api") == 401 ]] + "${request[@]}" -f -u "$SINGLE_USER_CREDENTIALS_USERNAME:$SMOKE_PASSWORD" "$api" | + jq -e '.anonymous == true' - - name: OpenSearch Helm authentication + - name: OpenSearch and Dashboards through NGINX if: matrix.stack == 'opensearch' run: | - sudo sysctl -w vm.max_map_count=262144 - make -C deployment helm-install-opensearch - OPENSEARCH_KIBANA_PASSWORD="$SMOKE_PASSWORD" OPENSEARCH_ANALYST_PASSWORD="$SMOKE_PASSWORD" \ - make -C deployment k3s-bootstrap-opensearch - kubectl port-forward svc/opensearch-cluster-master 9200:9200 & + kubectl port-forward svc/cogstack-nginx 8443:443 & trap 'kill "$!"' EXIT - curl -fsS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" \ - --retry 10 --retry-all-errors --retry-delay 2 --max-time 10 \ - -u "cogstack_user:$SMOKE_PASSWORD" https://localhost:9200/_plugins/_security/authinfo | + request=(curl -sS --noproxy '*' --cacert "$SECURITY_DIR/certificates/root/root-ca.pem" + --retry 30 --retry-all-errors --retry-delay 3 --max-time 10) + "${request[@]}" -f -u "cogstack_user:$SMOKE_PASSWORD" \ + https://127.0.0.1:8443/opensearch/_plugins/_security/authinfo | jq -e '.user_name == "cogstack_user"' - - - name: OpenSearch Dashboards Helm login - if: matrix.stack == 'opensearch' - run: | - certs="$SECURITY_DIR/certificates" - kubectl create secret generic dashboards-auth --from-literal=username=kibanaserver \ - --from-literal=password="$SMOKE_PASSWORD" --from-literal=cookie="$(openssl rand -hex 16)" - kubectl create secret tls dashboards-tls \ - --cert="$certs/opensearch/es_kibana_client.pem" --key="$certs/opensearch/es_kibana_client.key" - make -C deployment helm-install-opensearch-dashboards HELM_VALUES=- HELM_TIMEOUT=5m <<'YAML' - opensearch-dashboards: - opensearchAccount: - secret: dashboards-auth - secretMounts: - - {name: ca, secretName: cogstack-root-ca, path: /tls/ca} - - {name: server-tls, secretName: dashboards-tls, path: /tls/server} - config: - opensearch_dashboards.yml: - opensearchDashboards.index: .kibana - opensearch.ssl.certificateAuthorities: [/tls/ca/ca.crt] - opensearch.ssl.verificationMode: full - opensearch_security.cookie.secure: true - opensearch_security.cookie.password: ${COOKIE_PASS} - server.ssl.enabled: true - server.ssl.certificate: /tls/server/tls.crt - server.ssl.key: /tls/server/tls.key - YAML - kubectl port-forward svc/opensearch-dashboards 5601:5601 & - trap 'kill "$!"' EXIT - curl -fsS --noproxy '*' --cacert "$certs/root/root-ca.pem" --max-time 10 \ - --retry 30 --retry-all-errors --retry-delay 3 -H 'osd-xsrf: smoke' \ + headers=$(mktemp) + "${request[@]}" -f -D "$headers" -H 'osd-xsrf: smoke' \ --json "{\"username\":\"cogstack_user\",\"password\":\"$SMOKE_PASSWORD\"}" \ - https://localhost:5601/auth/login | jq -e '.username == "cogstack_user"' + https://127.0.0.1:8443/dashboards/auth/login | jq -e '.username == "cogstack_user"' + grep -qi '^set-cookie: .*; secure' "$headers" - name: Show pod logs on failure if: failure() diff --git a/deployment/Makefile b/deployment/Makefile index d67e2e0b..4b4a9387 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -79,30 +79,23 @@ delete-certs-all: ## Delete generated local TLS certificates, keys, and stores # ====================================================================================================================================================== -.PHONY: k3s-load-certs k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-nginx k3s-load-certs-opensearch +.PHONY: k3s-load-certs k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch k3s-load-certs: k3s-load-certs-all ## Alias for k3s-load-certs-all -k3s-load-certs-all: ## Load all TLS Secrets for NiFi, NGINX and OpenSearch -k3s-load-certs-root-ca: ## Load the public CA and NiFi truststore into cogstack-root-ca -k3s-load-certs-nifi: ## Load the NiFi keystore into nifi-tls +k3s-load-certs-all: ## Load the NGINX HTTPS and OpenSearch transport TLS Secrets k3s-load-certs-nginx: ## Load the NGINX certificate and key into nginx-tls k3s-load-certs-opensearch: ## Load the shared node certificate into opensearch-node-tls -k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-nginx k3s-load-certs-opensearch: +k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch: @set -eo pipefail; \ . ./env/general.env; \ namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ certs="$${SECURITY_DIR:-security}/certificates"; \ services=$(@:k3s-load-certs-%=%); \ - if [ "$$services" = all ]; then services="root-ca nifi nginx opensearch"; fi; \ + if [ "$$services" = all ]; then services="nginx opensearch"; fi; \ manifests=(); \ for service in $$services; do \ case "$$service" in \ - root-ca) secret=(generic cogstack-root-ca \ - --from-file="ca.crt=$$certs/root/root-ca.pem" \ - --from-file="truststore.jks=$$certs/nifi/nifi-truststore.jks");; \ - nifi) secret=(generic nifi-tls \ - --from-file="nifi-keystore.jks=$$certs/nifi/nifi-keystore.jks");; \ nginx) secret=(tls nginx-tls \ --cert="$$certs/nginx/tls.crt" --key="$$certs/nginx/tls.key");; \ opensearch) secret=(generic opensearch-node-tls \ @@ -119,24 +112,23 @@ k3s-load-certs-all k3s-load-certs-root-ca k3s-load-certs-nifi k3s-load-certs-ngi .PHONY: k3s-load-auth-nifi k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards # Uses env/authentication.env. Set NIFI_AUTH_FILE to choose another auth file. -k3s-load-auth-nifi: ## Prompt for missing credentials and load the NiFi auth Secret +k3s-load-auth-nifi: ## Load the NiFi flow encryption key and NGINX login Secret @bash scripts/security/load_nifi_auth.sh # Both targets use env/authentication.env unless OPENSEARCH_AUTH_FILE is set. -k3s-load-auth-opensearch: ## Load configured users into a fresh OpenSearch cluster +k3s-load-auth-opensearch: ## Load the bootstrap policy and users before installing OpenSearch k3s-load-auth-opensearch-dashboards: ## Load the OpenSearch Dashboards auth Secret k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards: @bash scripts/security/load_opensearch_auth.sh $(@:k3s-load-auth-%=%) -.PHONY: k3s-load-env-all k3s-load-env-nifi k3s-load-env-nginx k3s-load-env-opensearch +.PHONY: k3s-load-env-all k3s-load-env-nginx k3s-load-env-opensearch -k3s-load-env-all: k3s-load-env-nifi k3s-load-env-nginx k3s-load-env-opensearch ## Load all runtime environment ConfigMaps -k3s-load-env-nifi: ## Load the NiFi proxy hosts into the nifi-env ConfigMap +k3s-load-env-all: k3s-load-env-nginx k3s-load-env-opensearch ## Load all runtime environment ConfigMaps k3s-load-env-nginx: ## Load the NGINX runtime settings into the nginx-env ConfigMap k3s-load-env-opensearch: ## Load the OpenSearch log level into the opensearch-env ConfigMap -k3s-load-env-nifi k3s-load-env-nginx k3s-load-env-opensearch: +k3s-load-env-nginx k3s-load-env-opensearch: @set -eo pipefail; \ . ./env/general.env; \ namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ @@ -145,11 +137,7 @@ k3s-load-env-nifi k3s-load-env-nginx k3s-load-env-opensearch: if [[ "$$service" == opensearch || -f "$$env_file" ]]; then . "$$env_file"; fi; \ args=(); \ case "$$service" in \ - nifi) args+=("--from-literal=NIFI_WEB_PROXY_HOST=$${NIFI_WEB_PROXY_HOST-}");; \ - nginx) \ - for name in NGINX_NIFI_SERVER_NAME NGINX_PROXY_CONTEXT_PATH NGINX_PROXY_SCHEME; do \ - if [[ -n $${!name+x} ]]; then args+=("--from-literal=$$name=$${!name}"); fi; \ - done;; \ + nginx) args+=("--from-literal=NGINX_NIFI_SERVER_NAME=$${NGINX_NIFI_SERVER_NAME:-_}");; \ opensearch) args+=("--from-literal=OPENSEARCH_LOG_LEVEL=$${OPENSEARCH_LOG_LEVEL:-INFO}");; \ esac; \ kubectl -n "$$namespace" create configmap "$$service-env" "$${args[@]}" --dry-run=client -o yaml | \ @@ -229,10 +217,10 @@ helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch # make -C deployment helm-install-nifi-stack # Load dashboards-auth first to share its service account password with bootstrap. # make -C deployment k3s-load-auth-opensearch-dashboards -# make -C deployment helm-install-opensearch # make -C deployment k3s-load-auth-opensearch +# make -C deployment helm-install-opensearch # make -C deployment helm-install-opensearch-dashboards HELM_VALUES=/path/to/dashboards-values.yaml -# The stack initializes Security on first install. Set BOOTSTRAP_OPENSEARCH_SECURITY=0 to skip bootstrap. +# Set BOOTSTRAP_OPENSEARCH_SECURITY=0 to use existing auth Secrets. # make -C deployment helm-install-opensearch-stack HELM_VALUES=/path/to/dashboards-values.yaml # The stack target uses HELM_VALUES for Dashboards. # HELM_VALUES accepts an absolute path, a path relative to deployment/, or - for stdin. @@ -257,7 +245,7 @@ helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIM helm upgrade --install "$$release" "$$chart" -n "$$namespace" \ --wait --timeout "$${HELM_TIMEOUT:-10m}" "$${args[@]}" -helm-install-nifi: k3s-load-env-nifi ## Load the NiFi environment, then install or upgrade NiFi +helm-install-nifi: ## Install or upgrade NiFi $(MAKE) helm-install CHART=nifi helm-install-nginx: k3s-load-env-nginx ## Load the NGINX environment, then install or upgrade NGINX @@ -275,8 +263,10 @@ helm-install-opensearch-dashboards: ## Install or upgrade OpenSearch Dashboards k3s-bootstrap-opensearch: k3s-load-auth-opensearch ## Alias for k3s-load-auth-opensearch helm-install-opensearch-stack: ## Install OpenSearch and then Dashboards + @if [ "$${BOOTSTRAP_OPENSEARCH_SECURITY:-1}" = 1 ]; then \ + $(MAKE) k3s-load-auth-opensearch-dashboards && $(MAKE) k3s-bootstrap-opensearch; \ + fi $(MAKE) helm-install-opensearch HELM_VALUES= - @if [ "$${BOOTSTRAP_OPENSEARCH_SECURITY:-1}" = 1 ]; then $(MAKE) k3s-bootstrap-opensearch; fi $(MAKE) helm-install-opensearch-dashboards # ====================================================================================================================================================== diff --git a/deployment/charts/README.md b/deployment/charts/README.md index bcd557de..f7d020dd 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -4,19 +4,38 @@ Reusable deployment charts for CogStack. Each chart sits directly under this directory and declares its package name in `Chart.yaml`. Folder names use component names, such as `medcat-service` and `jupyter-hub`. -## NiFi charts +## Kubernetes HTTPS entry point -These charts were migrated from `cogstack_nifi/deploy/kubernetes/charts/`: +Deploy the four standalone charts in the same namespace. NGINX exposes HTTPS +through a LoadBalancer Service on port 443 and forwards to HTTP Services in the +cluster. On K3s with ServiceLB, disable the bundled Traefik controller to free +port 443. The cluster must enforce the NiFi NetworkPolicy. | Chart | Purpose | | --- | --- | -| [`nifi/`](nifi/README.md) | NiFi StatefulSet, Services, TLS settings and persistent storage. | -| [`nginx/`](nginx/README.md) | TLS reverse proxy for the NiFi web Service, with optional Ingress. | +| [`nginx/`](nginx/README.md) | HTTPS reverse proxy and NiFi login. | +| [`nifi/`](nifi/README.md) | NiFi StatefulSet and persistent storage. | +| [`opensearch/`](opensearch/README.md) | OpenSearch Security and node transport TLS. | +| [`opensearch-dashboards/`](opensearch-dashboards/README.md) | Dashboards UI. | -The `nifi/` directory declares `name: nifi` in `Chart.yaml`, so Helm -packages it as `nifi-.tgz`. +For a new deployment, set `NGINX_TLS_NAMES` to the hostname or IP clients will +use. Supply your deployment credentials and install `htpasswd` on the machine +running the loaders (`apache2-utils` on Debian/Ubuntu or `httpd-tools` on RHEL). +Run these commands from the repository root. -Run from the repository root: +```bash +make -C deployment setup-k3s-namespace +make -C deployment -j1 certs-root certs-nginx certs-opensearch-nodes NODES=opensearch-shared +make -C deployment k3s-load-certs-all k3s-load-auth-nifi +make -C deployment helm-install-nifi-stack +make -C deployment helm-install-opensearch-stack +``` + +Existing deployments must reload `nifi-auth` for NGINX before upgrading. +OpenSearch upgrades also require the bootstrap Secret and preparation of +administrative access when using an admin certificate. [OpenSearch upgrade details](opensearch/README.md#install) + +## Chart development ```bash helm lint deployment/charts/nifi deployment/charts/nginx @@ -28,7 +47,7 @@ See each chart's README for the ConfigMaps, Secrets and storage needed before installation. Run `make -C deployment helm-values-` for NiFi, NGINX, OpenSearch, or OpenSearch Dashboards to render `values.env.yaml` into `values.yaml` using `deployment/env/.env`. NGINX reads `nifi.env` for -the upstream connection and applies `nginx.env` when present. The local +its listener port and applies `nginx.env` when present. The local `deployment/env/nifi.env` can link to `apps/nifi/env/nifi.env`. Docker memory sizes such as `2g` render as `2Gi`. diff --git a/deployment/charts/nginx/Chart.yaml b/deployment/charts/nginx/Chart.yaml index c47eff23..02dd4e50 100644 --- a/deployment/charts/nginx/Chart.yaml +++ b/deployment/charts/nginx/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: nginx -description: TLS reverse proxy for CogStack Apache NiFi +description: TLS reverse proxy for CogStack Kubernetes services # A chart can be either an 'application' or a 'library' chart. # diff --git a/deployment/charts/nginx/README.md b/deployment/charts/nginx/README.md index 2d729170..9d9472d6 100644 --- a/deployment/charts/nginx/README.md +++ b/deployment/charts/nginx/README.md @@ -1,80 +1,40 @@ -# NiFi NGINX Helm chart +# CogStack NGINX Helm chart -Deploys `cogstacksystems/nifi-nginx` as the TLS reverse proxy for the NiFi web -Service. It creates a Deployment, a Service, an upstream-settings ConfigMap and -an optional Ingress. +This chart exposes NGINX over HTTPS on port `443` through a `LoadBalancer` +Service. NGINX forwards requests to the cluster-internal HTTP Services in the +release namespace. -## Prerequisites - -Prepare these resources in the release namespace before installing: - -| Resource | Default name | Required contents | +| HTTPS path | Backend | Client authentication | | --- | --- | --- | -| ConfigMap | `nginx-env` | Deployment-specific NGINX environment settings. | -| ConfigMap | `nifi-env` | Shared NiFi environment settings. | -| Secret | `cogstack-root-ca` | `ca.crt`, the public CA for upstream TLS verification. | -| TLS Secret | `nginx-tls` | `tls.crt` and `tls.key` for the proxy certificate. | - -`make -C deployment helm-install-nginx` applies `nginx-env` before invoking Helm. -Set `NGINX_NIFI_SERVER_NAME`, `NGINX_PROXY_CONTEXT_PATH`, or `NGINX_PROXY_SCHEME` -in `deployment/env/nginx.env` to override the proxy defaults. Run -`make -C deployment k3s-load-env-nginx` to apply the ConfigMap separately. +| `/nifi/`, `/nifi-api/` | NiFi on `8080` | NGINX Basic Auth | +| `/opensearch/` | OpenSearch on `9200` | OpenSearch Security | +| `/dashboards/` | OpenSearch Dashboards on `5601` | Dashboards login | -The environment ConfigMap names are currently fixed in the template. Override -certificate Secret names with `tls.rootCASecret` and `tls.existingSecret`. -The chart references these inputs rather than creating them from host files. +Load `nginx-tls` with `make -C deployment k3s-load-certs-nginx`, or provide a +TLS Secret and set `tls.existingSecret`. The certificate must cover the hostname +or IP that clients use. `NGINX_TLS_NAMES` controls the names when generating a +certificate with `make -C deployment certs-nginx`. -By default, the proxy connects to -`cogstack-nifi..svc.cluster.local:8443`, which matches the -Service from `deployment/charts/nifi`. Set `nifi.host` and `nifi.port` -for another upstream. `nifi.tlsName` must match the upstream certificate's TLS -name; it defaults to `nifi`. +For NiFi, run `make -C deployment k3s-load-auth-nifi` to load the password hash +into `nifi-auth`. NGINX needs the `htpasswd` key in this Secret to grant access +to NiFi. -## Render and install - -Run from the platform repository root: +On K3s using ServiceLB, disable the bundled Traefik controller on all servers +with `--disable=traefik` to free port `443` for NGINX. ```bash -helm lint ./deployment/charts/nginx -helm template cogstack-nginx ./deployment/charts/nginx --namespace cogstack -helm upgrade --install cogstack-nginx ./deployment/charts/nginx \ - --namespace cogstack --create-namespace +make -C deployment helm-install-nginx ``` -Pass deployment overrides with `-f /path/to/nginx-values.yaml`. Set `image.tag` -to the image release required by the deployment. - -## Optional Ingress +For local access, set `service.type: ClusterIP` and forward the NGINX Service. -Ingress is disabled by default. Example deployment values: - -```yaml -ingress: - enabled: true - className: nginx - annotations: - nginx.ingress.kubernetes.io/backend-protocol: HTTPS - hosts: - - host: nifi.example.org - paths: - - path: / - pathType: Prefix - tls: - - secretName: nifi-ingress-tls - hosts: - - nifi.example.org +```bash +kubectl -n cogstack port-forward svc/cogstack-nginx 8443:443 ``` -Configure annotations for the selected Ingress controller and provide any -referenced TLS Secret in the namespace. The chart's Service uses HTTPS on -`nginx.internalPort`, which defaults to `8443`. - -## Environment-based values - -`values.yaml` contains reusable defaults. `values.env.yaml` is an optional -`envsubst` input for deployment ports, upstream TLS name and resource limits. -Populate all referenced variables and render it to a separate values file before -passing it to Helm; Helm does not expand `${VARIABLE}` placeholders. +Use `https://localhost:8443` with the trusted CA for the certificate. -The chart currently uses fixed `cogstack-nginx` resource names. Use separate -namespaces for independent deployments. +Override `clusterDomain` if needed, or set `nifi.host`, `opensearch.host`, +`dashboards.host` and their corresponding `port` values to use other upstreams. +The optional `nginx-env` ConfigMap, loaded by `helm-install-nginx`, provides +`NGINX_NIFI_SERVER_NAME` from `deployment/env/nginx.env`. diff --git a/deployment/charts/nginx/ci/ci-values.yaml b/deployment/charts/nginx/ci/ci-values.yaml index bcd196df..bca9dab2 100644 --- a/deployment/charts/nginx/ci/ci-values.yaml +++ b/deployment/charts/nginx/ci/ci-values.yaml @@ -1,3 +1,5 @@ # CI validates resource installation without deployment-owned ConfigMaps and Secrets. # Runtime startup requires those inputs and a separate application smoke test. replicaCount: 0 +service: + type: ClusterIP diff --git a/deployment/charts/nginx/nginx.conf.template b/deployment/charts/nginx/nginx.conf.template new file mode 100644 index 00000000..6f345f42 --- /dev/null +++ b/deployment/charts/nginx/nginx.conf.template @@ -0,0 +1,62 @@ +{{- $domain := printf "%s.svc.%s" .Release.Namespace .Values.clusterDomain -}} +resolver ${NGINX_LOCAL_RESOLVERS} valid=10s; +resolver_timeout 3s; + +upstream nifi { + zone nifi 64k; + server {{ .Values.nifi.host | default (printf "cogstack-nifi.%s" $domain) }}:{{ .Values.nifi.port }} resolve; +} +upstream opensearch { + zone opensearch 64k; + server {{ .Values.opensearch.host | default (printf "opensearch-cluster-master.%s" $domain) }}:{{ .Values.opensearch.port }} resolve; +} +upstream dashboards { + zone dashboards 64k; + server {{ .Values.dashboards.host | default (printf "opensearch-dashboards.%s" $domain) }}:{{ .Values.dashboards.port }} resolve; +} + +map $request_port $nifi_public_port { + "" 443; + default $request_port; +} + +server { + listen {{ .Values.nginx.internalPort }} ssl; + server_name ${NGINX_NIFI_SERVER_NAME}; + ssl_certificate /certificates/tls.crt; + ssl_certificate_key /certificates/tls.key; + ssl_protocols TLSv1.2 TLSv1.3; + absolute_redirect off; + + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + + location = / { return 302 /nifi/; } + location = /nifi { return 308 /nifi/; } + + location /opensearch/ { + client_max_body_size 100m; + proxy_pass http://opensearch/; + } + + location /dashboards/ { + proxy_pass http://dashboards; + } + + location / { + auth_basic "NiFi"; + auth_basic_user_file /etc/nginx/nifi-auth/htpasswd; + proxy_set_header Authorization ""; + proxy_set_header Host $http_host; + proxy_set_header X-ProxyHost $host; + proxy_set_header X-ProxyPort $nifi_public_port; + proxy_set_header X-ProxyScheme $scheme; + proxy_set_header X-ProxyContextPath ""; + proxy_set_header X-Forwarded-Context ""; + proxy_set_header X-Forwarded-Prefix ""; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_redirect http://$http_host/ /; + proxy_pass http://nifi; + } +} diff --git a/deployment/charts/nginx/templates/configmap.yaml b/deployment/charts/nginx/templates/configmap.yaml index e2050ab8..3fb8f621 100644 --- a/deployment/charts/nginx/templates/configmap.yaml +++ b/deployment/charts/nginx/templates/configmap.yaml @@ -1,10 +1,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: cogstack-nginx-env + name: cogstack-nginx-config data: - NIFI_UPSTREAM_HOST: {{ default (printf "cogstack-nifi.%s.svc.cluster.local" .Release.Namespace) .Values.nifi.host | quote }} - NIFI_UPSTREAM_PORT: {{ .Values.nifi.port | quote }} - NIFI_UPSTREAM_TLS_NAME: {{ .Values.nifi.tlsName | quote }} - NIFI_INTERNAL_PORT_NGINX: {{ .Values.nginx.internalPort | quote }} - NIFI_WEB_PROXY_PORT: {{ .Values.nginx.internalPort | quote }} + nginx.conf.template: | + {{- tpl (.Files.Get "nginx.conf.template") . | nindent 4 }} diff --git a/deployment/charts/nginx/templates/deployment.yaml b/deployment/charts/nginx/templates/deployment.yaml index c69833c9..26961b2f 100644 --- a/deployment/charts/nginx/templates/deployment.yaml +++ b/deployment/charts/nginx/templates/deployment.yaml @@ -23,42 +23,43 @@ spec: imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - - containerPort: {{ .Values.nginx.internalPort }} + - name: https + containerPort: {{ .Values.nginx.internalPort }} envFrom: - configMapRef: name: nginx-env - - configMapRef: - name: nifi-env - - configMapRef: - name: cogstack-nginx-env + optional: true volumeMounts: + - name: config + mountPath: /etc/nginx/templates/nifi + readOnly: true - name: tls mountPath: /certificates readOnly: true + - name: nifi-auth + mountPath: /etc/nginx/nifi-auth + readOnly: true readinessProbe: - exec: - command: ["/usr/local/bin/cogstack-nginx-healthcheck.sh", "ready"] - timeoutSeconds: 10 + tcpSocket: + port: https resources: {{- toYaml .Values.resources | nindent 12 }} volumes: + - name: config + configMap: + name: cogstack-nginx-config - name: tls - projected: - sources: - - secret: - name: {{ .Values.tls.rootCASecret }} - items: - - key: ca.crt - path: root/root-ca.pem - - secret: - name: {{ .Values.tls.existingSecret }} - items: - - key: tls.crt - path: nifi/nifi.pem - - key: tls.key - path: nifi/nifi.key + secret: + secretName: {{ .Values.tls.existingSecret }} + - name: nifi-auth + secret: + secretName: nifi-auth + optional: true + items: + - key: htpasswd + path: htpasswd diff --git a/deployment/charts/nginx/templates/ingress.yaml b/deployment/charts/nginx/templates/ingress.yaml deleted file mode 100644 index e18130c2..00000000 --- a/deployment/charts/nginx/templates/ingress.yaml +++ /dev/null @@ -1,41 +0,0 @@ -{{- if .Values.ingress.enabled -}} -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: cogstack-nginx - labels: - app: cogstack-nginx - {{- with .Values.ingress.annotations }} - annotations: - {{- toYaml . | nindent 4 }} - {{- end }} -spec: - {{- with .Values.ingress.className }} - ingressClassName: {{ . }} - {{- end }} - {{- if .Values.ingress.tls }} - tls: - {{- range .Values.ingress.tls }} - - hosts: - {{- range .hosts }} - - {{ . | quote }} - {{- end }} - secretName: {{ .secretName }} - {{- end }} - {{- end }} - rules: - {{- range .Values.ingress.hosts }} - - host: {{ .host | quote }} - http: - paths: - {{- range .paths }} - - path: {{ .path }} - pathType: {{ .pathType | default "Prefix" }} - backend: - service: - name: cogstack-nginx - port: - number: {{ $.Values.nginx.internalPort }} - {{- end }} - {{- end }} -{{- end }} diff --git a/deployment/charts/nginx/templates/service.yaml b/deployment/charts/nginx/templates/service.yaml index 1c01190d..30e9d572 100644 --- a/deployment/charts/nginx/templates/service.yaml +++ b/deployment/charts/nginx/templates/service.yaml @@ -8,6 +8,6 @@ spec: app: cogstack-nginx ports: - name: https - port: {{ .Values.nginx.internalPort }} - targetPort: {{ .Values.nginx.internalPort }} + port: {{ .Values.service.port }} + targetPort: https protocol: TCP diff --git a/deployment/charts/nginx/values.env.yaml b/deployment/charts/nginx/values.env.yaml index 03d7822b..efcb1dbb 100644 --- a/deployment/charts/nginx/values.env.yaml +++ b/deployment/charts/nginx/values.env.yaml @@ -1,29 +1,31 @@ replicaCount: 1 image: - repository: cogstacksystems/nifi-nginx + repository: cogstacksystems/nginx tag: "latest" pullPolicy: Always nginx: internalPort: ${NIFI_INTERNAL_PORT_NGINX} +clusterDomain: cluster.local + nifi: - # Empty uses cogstack-nifi..svc.cluster.local; override with a full DNS name. host: "" - port: ${NIFI_INTERNAL_PORT} - tlsName: ${NIFI_UPSTREAM_TLS_NAME} + port: 8080 +opensearch: + host: "" + port: 9200 +dashboards: + host: "" + port: 5601 tls: - rootCASecret: cogstack-root-ca - # NGINX's own tls.crt/tls.key retain the image's existing /certificates/nifi paths. existingSecret: nginx-tls service: - type: ClusterIP - -ingress: - enabled: false + type: LoadBalancer + port: 443 resources: requests: diff --git a/deployment/charts/nginx/values.yaml b/deployment/charts/nginx/values.yaml index 8bb09bf2..3fd8f548 100644 --- a/deployment/charts/nginx/values.yaml +++ b/deployment/charts/nginx/values.yaml @@ -1,29 +1,31 @@ replicaCount: 1 image: - repository: cogstacksystems/nifi-nginx + repository: cogstacksystems/nginx tag: "latest" pullPolicy: Always nginx: internalPort: 8443 +clusterDomain: cluster.local + nifi: - # Empty uses cogstack-nifi..svc.cluster.local; override with a full DNS name. host: "" - port: 8443 - tlsName: nifi + port: 8080 +opensearch: + host: "" + port: 9200 +dashboards: + host: "" + port: 5601 tls: - rootCASecret: cogstack-root-ca - # NGINX's own tls.crt/tls.key retain the image's existing /certificates/nifi paths. existingSecret: nginx-tls service: - type: ClusterIP - -ingress: - enabled: false + type: LoadBalancer + port: 443 resources: requests: diff --git a/deployment/charts/nifi/README.md b/deployment/charts/nifi/README.md index 4725a6a4..19c7f24b 100644 --- a/deployment/charts/nifi/README.md +++ b/deployment/charts/nifi/README.md @@ -1,35 +1,22 @@ # CogStack NiFi Helm chart -Deploys the CogStack Apache NiFi image with a StatefulSet, headless and web -Services, a TLS configuration ConfigMap, and persistent storage for configuration -and NiFi repositories. Application sources and the Dockerfile live in -`apps/nifi/`. +Deploys the CogStack Apache NiFi image with a StatefulSet, cluster-internal HTTP +Services, and persistent storage for configuration and NiFi repositories. +NGINX handles HTTPS and login for the UI and API. [NGINX chart](../nginx/README.md) ## Prerequisites -Prepare these resources in the release namespace before installing: +Run `make -C deployment k3s-load-auth-nifi` to create or update `nifi-auth` with +the NiFi flow encryption key and the NGINX `htpasswd` entry. Set +`NIFI_SINGLE_USER_CREDENTIALS_USERNAME` and `NIFI_SINGLE_USER_CREDENTIALS_PASSWORD` +in the environment or `deployment/env/authentication.env`. The loader requires +`htpasswd` and prompts for a deployment password if needed. It preserves the +existing `NIFI_SENSITIVE_PROPS_KEY` when upgrading. -| Resource | Default name | Required contents | -| --- | --- | --- | -| ConfigMap | `nifi-env` | NiFi runtime environment settings for the deployment. | -| Secret | `nifi-auth` | Apache startup environment variables for login credentials, TLS passwords, the sensitive-properties key and the matching initial admin identity. | -| Secret | `cogstack-root-ca` | `ca.crt` and `truststore.jks`; the public CA and shared truststore. | -| Secret | `nifi-tls` | `nifi-keystore.jks`; the NiFi node certificate and private key. | - -Both `make -C deployment helm-install-nifi` and -`make -C deployment helm-install-nifi-stack` load `NIFI_WEB_PROXY_HOST` from -`deployment/env/nifi.env` when present. With a missing env file, set -`NIFI_WEB_PROXY_HOST` in the shell to supply the proxy hosts. Use -`make -C deployment k3s-load-env-nifi` to apply the ConfigMap on its own. - -Set `certificates.rootCASecret` and `certificates.existingSecret` to use different -certificate Secret names. The environment ConfigMap and authentication Secret -names are currently fixed in the workload template. - -The chart references these resources; it does not read host environment files or -create authentication or certificate Secrets. Keep private CA signing material -outside the pod. The namespace also needs a StorageClass or suitable -pre-provisioned persistent volumes for the six per-replica claims. +The namespace needs a StorageClass or persistent volumes for the six claims per +replica. NiFi grants full access in HTTP mode. Use a cluster that enforces +NetworkPolicy so the chart can restrict access to the NGINX pods in the same +namespace. ## Render and install @@ -46,14 +33,7 @@ Pass deployment overrides with `-f /path/to/nifi-values.yaml`. The default image is `cogstacksystems/nifi:latest`; set `image.tag` to the image release required by the deployment. -For local access: - -```bash -kubectl -n cogstack port-forward svc/cogstack-nifi 8443:8443 -``` - -Open `https://localhost:8443/nifi/` using the deployment's trusted CA and -credentials. +Use the NGINX `/nifi/` and `/nifi-api/` routes with HTTP Basic authentication. ## Persistent configuration and data @@ -80,8 +60,7 @@ StorageClass and access modes. Existing StatefulSet claim templates have Kubernetes immutability constraints; plan storage changes and backups separately. Drivers, schemas and Python processors are bundled by the NiFi image. Startup -and readiness probes call its `/opt/nifi/scripts/cogstack-healthcheck.sh` -with the projected public CA. +and readiness probes use NiFi's loopback HTTP endpoint. ## Environment-based values @@ -92,10 +71,9 @@ otherwise eligible node. ## Resource names -The `cogstack-nifi` StatefulSet uses `cogstack-nifi-headless` for pod DNS. -Clients connect to the `cogstack-nifi` ClusterIP Service. Use separate namespaces -for independent deployments. Increasing `replicaCount` requires NiFi cluster -configuration, node identities and certificates in the supplied runtime inputs. +The `cogstack-nifi` StatefulSet uses `cogstack-nifi-headless` for pod DNS. NGINX +connects to the `cogstack-nifi` ClusterIP Service on port `8080`. Use separate +namespaces for independent deployments. Upgrades from the previous Service names require recreating the StatefulSet and the old `cogstack-nifi` headless Service. Keep the existing PVCs for the recreated diff --git a/deployment/charts/nifi/templates/networkpolicy.yaml b/deployment/charts/nifi/templates/networkpolicy.yaml new file mode 100644 index 00000000..cc178c64 --- /dev/null +++ b/deployment/charts/nifi/templates/networkpolicy.yaml @@ -0,0 +1,17 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: cogstack-nifi +spec: + podSelector: + matchLabels: + app: cogstack-nifi + policyTypes: [Ingress] + ingress: + - from: + - podSelector: + matchLabels: + app: cogstack-nginx + ports: + - protocol: TCP + port: {{ .Values.nifi.internalPort }} diff --git a/deployment/charts/nifi/templates/service.yaml b/deployment/charts/nifi/templates/service.yaml index f3c24182..4065f680 100644 --- a/deployment/charts/nifi/templates/service.yaml +++ b/deployment/charts/nifi/templates/service.yaml @@ -8,7 +8,7 @@ spec: selector: app: cogstack-nifi ports: - - name: https + - name: http port: {{ .Values.nifi.internalPort }} --- apiVersion: v1 @@ -20,6 +20,6 @@ spec: selector: app: cogstack-nifi ports: - - name: https + - name: http port: {{ .Values.nifi.internalPort }} - targetPort: {{ .Values.nifi.internalPort }} + targetPort: http diff --git a/deployment/charts/nifi/templates/statefulset.yaml b/deployment/charts/nifi/templates/statefulset.yaml index 3844fa3d..4cbb1a48 100644 --- a/deployment/charts/nifi/templates/statefulset.yaml +++ b/deployment/charts/nifi/templates/statefulset.yaml @@ -17,8 +17,6 @@ spec: metadata: labels: app: cogstack-nifi - annotations: - checksum/tls-config: {{ include (print $.Template.BasePath "/tls-configmap.yaml") . | sha256sum }} spec: {{- with .Values.allowedNodes }} affinity: @@ -81,19 +79,32 @@ spec: - name: nifi securityContext: {{- toYaml .Values.securityContext | nindent 12 }} - envFrom: - - configMapRef: - name: nifi-env - - configMapRef: - name: cogstack-nifi-tls-env - # Login/password variables and matching INITIAL_ADMIN_IDENTITY only; no certificate files. - - secretRef: - name: nifi-auth + env: + - name: NIFI_SENSITIVE_PROPS_KEY + valueFrom: + secretKeyRef: + name: nifi-auth + key: NIFI_SENSITIVE_PROPS_KEY + command: ["/bin/sh", "-ec"] + args: + - | + # The upstream container entrypoint always configures HTTPS. + . /opt/nifi/scripts/common.sh + prop_replace 'nifi.web.http.host' '0.0.0.0' + prop_replace 'nifi.web.http.port' '{{ .Values.nifi.internalPort | int }}' + prop_replace 'nifi.remote.input.secure' 'false' + prop_replace 'nifi.security.autoreload.enabled' 'false' + sed -i -E \ + -e 's/^(nifi\.web\.https\.(host|port))=.*/\1=/' \ + -e 's/^(nifi\.security\.(keystore[^=]*|truststore[^=]*|keyPasswd))=.*/\1=/' \ + -e 's/^(nifi\.security\.user\.(authorizer|login\.identity\.provider))=.*/\1=/' "$nifi_props_file" + prop_replace 'nifi.sensitive.props.key' "$NIFI_SENSITIVE_PROPS_KEY" + uncomment 'nifi.python.command' "$nifi_props_file" + prop_replace 'nifi.python.extensions.source.directory.default' "$NIFI_HOME/python_extensions" + prop_replace 'nifi.nar.library.autoload.directory' "$NIFI_HOME/nar_extensions" + exec "$NIFI_HOME/bin/nifi.sh" run volumeMounts: - - name: tls - mountPath: /certificates - readOnly: true {{- range $directory := $directories }} - name: {{ $directory | replace "_" "-" }} mountPath: /opt/nifi/nifi-current/{{ $directory }} @@ -102,36 +113,19 @@ spec: image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - - containerPort: {{ .Values.nifi.internalPort | int }} + - name: http + containerPort: {{ .Values.nifi.internalPort | int }} startupProbe: - exec: - command: ["/opt/nifi/scripts/cogstack-healthcheck.sh", "startup"] + exec: &healthcheck + command: ["curl", "-fsS", "--noproxy", "*", "-o", "/dev/null", "http://127.0.0.1:{{ .Values.nifi.internalPort }}/nifi-api/authentication/configuration"] timeoutSeconds: 10 failureThreshold: 30 readinessProbe: - exec: - command: ["/opt/nifi/scripts/cogstack-healthcheck.sh", "ready"] + exec: *healthcheck timeoutSeconds: 10 - resources: + resources: {{- toYaml .Values.resources | nindent 12 }} - volumes: - - name: tls - projected: - sources: - - secret: - name: {{ .Values.certificates.rootCASecret }} - items: - - key: ca.crt - path: root/root-ca.pem - - key: truststore.jks - path: nifi/nifi-truststore.jks - - secret: - name: {{ .Values.certificates.existingSecret }} - items: - - key: nifi-keystore.jks - path: nifi/nifi-keystore.jks - volumeClaimTemplates: {{- range $directory := $directories }} {{- $claim := required (printf "persistence.volumes.%s is required" $directory) (index $.Values.persistence.volumes $directory) }} diff --git a/deployment/charts/nifi/templates/tls-configmap.yaml b/deployment/charts/nifi/templates/tls-configmap.yaml deleted file mode 100644 index 89669cff..00000000 --- a/deployment/charts/nifi/templates/tls-configmap.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: cogstack-nifi-tls-env -data: - AUTH: tls - NIFI_SECURITY_USER_AUTHORIZER: managed-authorizer - NIFI_SECURITY_USER_LOGIN_IDENTITY_PROVIDER: single-user-provider - NIFI_WEB_HTTPS_PORT: {{ .Values.nifi.internalPort | quote }} - # Kubernetes uses /certificates; Compose retains /security/certificates. - NIFI_KEYSTORE_PATH: /certificates/nifi/nifi-keystore.jks - NIFI_TRUSTSTORE_PATH: /certificates/nifi/nifi-truststore.jks - NIFI_HEALTHCHECK_CA_FILE: /certificates/root/root-ca.pem - KEYSTORE_PATH: /certificates/nifi/nifi-keystore.jks - TRUSTSTORE_PATH: /certificates/nifi/nifi-truststore.jks - KEYSTORE_TYPE: JKS - TRUSTSTORE_TYPE: JKS diff --git a/deployment/charts/nifi/values.env.yaml b/deployment/charts/nifi/values.env.yaml index d57bbe24..05d4c419 100644 --- a/deployment/charts/nifi/values.env.yaml +++ b/deployment/charts/nifi/values.env.yaml @@ -24,14 +24,7 @@ podSecurityContext: fsGroupChangePolicy: OnRootMismatch nifi: - internalPort: ${NIFI_INTERNAL_PORT} - outputPort: ${NIFI_OUTPUT_PORT} - -certificates: - # Shared CA only: ca.crt and truststore.jks; never the root private-key keystore. - rootCASecret: cogstack-root-ca - # NiFi's JKS contains its certificate and private key; the CA truststore is shared. - existingSecret: nifi-tls + internalPort: 8080 persistence: # null uses the cluster default; "" selects no StorageClass (pre-provisioned PVs). diff --git a/deployment/charts/nifi/values.yaml b/deployment/charts/nifi/values.yaml index 8ad924dd..63ebf65e 100644 --- a/deployment/charts/nifi/values.yaml +++ b/deployment/charts/nifi/values.yaml @@ -24,14 +24,7 @@ podSecurityContext: fsGroupChangePolicy: OnRootMismatch nifi: - internalPort: 8443 - outputPort: 8082 - -certificates: - # Shared CA only: ca.crt and truststore.jks; never the root private-key keystore. - rootCASecret: cogstack-root-ca - # NiFi's JKS contains its certificate and private key; the CA truststore is shared. - existingSecret: nifi-tls + internalPort: 8080 persistence: # null uses the cluster default; "" selects no StorageClass (pre-provisioned PVs). diff --git a/deployment/charts/opensearch-dashboards/README.md b/deployment/charts/opensearch-dashboards/README.md index 8c14f9ea..6e96fb3b 100644 --- a/deployment/charts/opensearch-dashboards/README.md +++ b/deployment/charts/opensearch-dashboards/README.md @@ -1,8 +1,8 @@ # Standalone OpenSearch Dashboards -Install this release in the same namespace as [OpenSearch](../opensearch/README.md). -Dashboards connects to the OpenSearch Service and stores its saved objects in -OpenSearch. +Deploy Dashboards in the same namespace as OpenSearch and NGINX. Dashboards +serves HTTP on its ClusterIP Service and connects to OpenSearch over HTTP. +Clients use `/dashboards/` over HTTPS through NGINX. The session cookie is Secure. From the repository root, load the `dashboards-auth` Secret in the namespace set in `deployment/env/general.env`. The target uses `OPENSEARCH_KIBANA_PASSWORD` from the @@ -14,29 +14,30 @@ its current `kibanaserver` password. ```bash make -C deployment k3s-load-auth-opensearch-dashboards +make -C deployment helm-install-opensearch-dashboards ``` -Set `opensearch-dashboards.opensearchAccount.secret: dashboards-auth` in your Helm -values. Set `opensearch_security.cookie.password: ${COOKIE_PASS}` in your -`opensearch_dashboards.yml` to use the cookie key from the Secret. Use -`opensearchDashboards.index: .kibana` in a fresh deployment to match the built-in -`kibana_server` role. +The default values use `dashboards-auth` and `.kibana`, which matches the +built-in `kibana_server` role. Keep any existing saved-object index override +when upgrading. If you supply a custom `opensearch_dashboards.yml`, set +`server.ssl.enabled: false`, `server.basePath: /dashboards`, +`server.rewriteBasePath: true` and `opensearch_security.cookie.secure: true`. +Use `opensearch_security.cookie.password: ${COOKIE_PASS}` for the cookie key +from the Secret. ```bash helm repo add opensearch https://opensearch-project.github.io/helm-charts/ helm dependency build deployment/charts/opensearch-dashboards -helm upgrade --install opensearch-dashboards deployment/charts/opensearch-dashboards -n search +helm upgrade --install opensearch-dashboards deployment/charts/opensearch-dashboards -n cogstack ``` -Set overrides under `opensearch-dashboards:` in your values file. Prepare the -[imported Compose config](../../../apps/opensearch-dashboards/config/opensearch.yml) -with the Kubernetes endpoint, credentials, and certificate paths before using it. -Use `--set-file` to load a prepared config. +Set overrides under `opensearch-dashboards:` in your values file. Use +`--set-file` to supply a complete Kubernetes configuration. ```bash -helm upgrade --install opensearch-dashboards deployment/charts/opensearch-dashboards -n search \ +helm upgrade --install opensearch-dashboards deployment/charts/opensearch-dashboards -n cogstack \ --set-file 'opensearch-dashboards.config.opensearch_dashboards\.yml=/path/to/kubernetes/opensearch_dashboards.yml' ``` -Mount TLS files from a Secret using `opensearch-dashboards.secretMounts`. See the -[upstream values](https://github.com/opensearch-project/helm-charts/blob/main/charts/opensearch-dashboards/values.yaml). +Dashboards inherits its Kubernetes templates from the upstream chart. +[Upstream values](https://github.com/opensearch-project/helm-charts/blob/main/charts/opensearch-dashboards/values.yaml) diff --git a/deployment/charts/opensearch-dashboards/ci/ci-values.yaml b/deployment/charts/opensearch-dashboards/ci/ci-values.yaml new file mode 100644 index 00000000..b7e22efb --- /dev/null +++ b/deployment/charts/opensearch-dashboards/ci/ci-values.yaml @@ -0,0 +1,3 @@ +# The login smoke test provides the Secret and OpenSearch service. +opensearch-dashboards: + replicaCount: 0 diff --git a/deployment/charts/opensearch-dashboards/values.env.yaml b/deployment/charts/opensearch-dashboards/values.env.yaml index 65464a6f..d26c6d81 100644 --- a/deployment/charts/opensearch-dashboards/values.env.yaml +++ b/deployment/charts/opensearch-dashboards/values.env.yaml @@ -1,5 +1,16 @@ opensearch-dashboards: - opensearchHosts: https://opensearch-cluster-master:9200 + opensearchHosts: http://opensearch-cluster-master:9200 + opensearchAccount: + secret: dashboards-auth + config: + opensearch_dashboards.yml: + server.ssl.enabled: false + server.basePath: /dashboards + server.rewriteBasePath: true + opensearchDashboards.index: .kibana + opensearch.requestHeadersAllowlist: [authorization, securitytenant] + opensearch_security.cookie.secure: true + opensearch_security.cookie.password: '{{ "$" }}{COOKIE_PASS}' resources: requests: cpu: "${OPENSEARCH_DASHBOARDS_DOCKER_CPU_MIN}" diff --git a/deployment/charts/opensearch-dashboards/values.yaml b/deployment/charts/opensearch-dashboards/values.yaml index 15d3949d..84c17a08 100644 --- a/deployment/charts/opensearch-dashboards/values.yaml +++ b/deployment/charts/opensearch-dashboards/values.yaml @@ -1,5 +1,16 @@ opensearch-dashboards: - opensearchHosts: https://opensearch-cluster-master:9200 + opensearchHosts: http://opensearch-cluster-master:9200 + opensearchAccount: + secret: dashboards-auth + config: + opensearch_dashboards.yml: + server.ssl.enabled: false + server.basePath: /dashboards + server.rewriteBasePath: true + opensearchDashboards.index: .kibana + opensearch.requestHeadersAllowlist: [authorization, securitytenant] + opensearch_security.cookie.secure: true + opensearch_security.cookie.password: '{{ "$" }}{COOKIE_PASS}' resources: requests: cpu: "1" diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index 3d9d85b0..42d2a180 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -6,72 +6,44 @@ The upstream chart supplies the Kubernetes templates. Set overrides under ## Install -The chart defaults to a shared node certificate. From the repository root, build -the chart dependency and generate the node and admin client certificates with -an existing CA. The generator prompts for `OS_CERTIFICATE_PASSWORD` when unset. -Use an absolute `SECURITY_DIR` for a custom output location. +OpenSearch serves HTTP on the internal `opensearch-cluster-master` Service. +OpenSearch Security requires TLS on its node transport. Generate the shared +node certificate with an existing CA and load it into the release namespace. +Use an absolute `SECURITY_DIR` for a custom certificate directory. [Cluster prerequisites](https://docs.opensearch.org/latest/opensearch/install/helm/#prerequisites) ```bash -chart=deployment/charts/opensearch -helm repo add opensearch https://opensearch-project.github.io/helm-charts/ -helm dependency build "$chart" -make -C deployment certs-opensearch -certs="${SECURITY_DIR:-deployment/security}/certificates/opensearch" +make -C deployment -j1 certs-opensearch-nodes k3s-load-certs-opensearch NODES=opensearch-shared +make -C deployment helm-install-opensearch-stack ``` -For a packaged chart, set `chart=./opensearch` after extracting it and point -`certs` at your certificate directory. The archive contains the chart dependency, -the shared OpenSearch config, and the Security policy. - -```bash -kubectl create namespace search -kubectl -n search create secret generic opensearch-node-tls \ - --from-file=node.crt="$certs/opensearch-shared.crt" \ - --from-file=node.key="$certs/opensearch-shared.key" \ - --from-file=ca.crt="$certs/elastic-stack-ca.crt.pem" -helm upgrade --install opensearch "$chart" -n search \ - --set-file "opensearch.config.opensearch\.yml=$chart/config/opensearch.yml" -``` - -Helm loads the bundled [`opensearch.yml`](config/opensearch.yml) through `--set-file`. -`make -C deployment helm-install-opensearch` applies `OPENSEARCH_LOG_LEVEL` -from `deployment/env/opensearch.env` before invoking Helm. To apply all three -runtime ConfigMaps together, run `make -C deployment k3s-load-env-all`. - -Transport TLS checks the CA and shared node DN. Set `KUBE_NAMESPACE` or -`CLUSTER_DOMAIN` when issuing the certificate if either differs from `search` -or `cluster.local`. +The stack target prepares the authentication Secrets, then installs OpenSearch +and Dashboards. It uses `KUBE_NAMESPACE` from `deployment/env/general.env`. -### Authentication - -For K3s, initialize Security after OpenSearch starts. The Make target uses -`KUBE_NAMESPACE` from `deployment/env/general.env`. +To install OpenSearch on its own, prepare the bootstrap Secret before installing. ```bash make -C deployment k3s-load-auth-opensearch +make -C deployment helm-install-opensearch ``` -Set `OPENSEARCH_KIBANA_PASSWORD` in the environment or in `deployment/env/authentication.env`. -Use `OPENSEARCH_AUTH_FILE` to select a different file. If no password is supplied, -the target uses `dashboards-auth` if present or prompts in a terminal. The same -file or environment can supply the optional user passwords below. On an -initialized cluster the target reports that Security is already initialized. - -For direct Helm installs, run the bootstrap script with the following settings. -Export `OPENSEARCH_KIBANA_PASSWORD` for `kibanaserver`. Set +The loader requires `htpasswd`. Set `OPENSEARCH_KIBANA_PASSWORD` for +`kibanaserver` in the environment or `deployment/env/authentication.env`. It +also accepts the password from a preexisting `dashboards-auth` Secret. Set `OPENSEARCH_NIFI_PASSWORD`, `OPENSEARCH_PIPELINE_PASSWORD`, or -`OPENSEARCH_ANALYST_PASSWORD` to create `nifi`, -`cogstack_pipeline`, or `cogstack_user`, respectively. Export the absolute -`SECURITY_DIR` for a packaged chart or custom certificate location. After the -OpenSearch cluster forms, initialize Security once before starting Dashboards. +`OPENSEARCH_ANALYST_PASSWORD` to create `nifi`, `cogstack_pipeline`, or +`cogstack_user`. Set `OPENSEARCH_ADMIN_PASSWORD` to create a password-based +`admin` with the `all_access` role. Use `OPENSEARCH_AUTH_FILE` to select another +credentials file. -```bash -bash "$chart/security/bootstrap.sh" kubectl -n search exec -i opensearch-cluster-master-0 -- -``` +OpenSearch uses `opensearch-security-bootstrap` to initialize an empty Security +index. For an existing cluster that uses an admin certificate, create a +password-authenticated administrator in the existing Security index before +switching to HTTP. Use the current `kibanaserver` password when loading the +Dashboards Secret. -From inside the cluster, clients can use -`https://opensearch-cluster-master.search.svc:9200`. +Clients in the release namespace can use `http://opensearch-cluster-master:9200`. +External clients use the NGINX `/opensearch/` route over HTTPS. ## Replicas @@ -99,31 +71,31 @@ The StatefulSet creates one 8 GiB PVC per pod and mounts it at shows the claim template. The second lists claims after installation. ```bash -helm template opensearch deployment/charts/opensearch -n search \ +helm template opensearch deployment/charts/opensearch -n cogstack \ --show-only charts/opensearch/templates/statefulset.yaml -kubectl -n search get pvc +kubectl -n cogstack get pvc ``` -## Configuration and TLS +## Configuration -The chart links to the source at `apps/opensearch/config/opensearch.yml`. -In Docker, mount the source at `/usr/share/opensearch/config/opensearch.yml`. -Mount the shared certificate, key, and public CA as `node.crt`, `node.key`, -and `ca.crt` under `/usr/share/opensearch/config/tls`. +`helm-install-opensearch` loads the bundled configuration with `--set-file` and +applies `OPENSEARCH_LOG_LEVEL` from `deployment/env/opensearch.env`. The chart +sets `plugins.security.ssl.http.enabled=false` and enables Security bootstrap +from the mounted policy through the OpenSearch container's settings environment. ### Custom values -Pass a prepared file to Helm. The chart creates a ConfigMap and uses it to -populate the file mounted at `/usr/share/opensearch/config/opensearch.yml`. +For direct Helm installs, build the dependency and load a config file. The +release also requires the `opensearch-security-bootstrap` and +`opensearch-node-tls` Secrets in the same namespace. ```bash -helm upgrade --install opensearch deployment/charts/opensearch -n search \ - --set-file 'opensearch.config.opensearch\.yml=/path/to/kubernetes/opensearch.yml' +chart=deployment/charts/opensearch +helm repo add opensearch https://opensearch-project.github.io/helm-charts/ +helm dependency build "$chart" +helm upgrade --install opensearch "$chart" -n cogstack \ + --set-file "opensearch.config.opensearch\.yml=$chart/config/opensearch.yml" ``` -Put TLS keys and certificates in a Kubernetes Secret and mount it using -`opensearch.secretMounts`. Match the PEM paths in the config to the mount. -See the [upstream chart settings](https://github.com/opensearch-project/helm-charts/blob/main/charts/opensearch/README.md). - -Install Dashboards separately using the -[standalone Dashboards chart](../opensearch-dashboards/README.md). +For a packaged chart, set `chart=./opensearch` after extracting it. The archive +includes the chart dependency, OpenSearch configuration, and Security policy. diff --git a/deployment/charts/opensearch/ci/ci-values.yaml b/deployment/charts/opensearch/ci/ci-values.yaml index 7e9ad185..933112e8 100644 --- a/deployment/charts/opensearch/ci/ci-values.yaml +++ b/deployment/charts/opensearch/ci/ci-values.yaml @@ -1,6 +1,13 @@ opensearch: replicas: 1 secretMounts: [] + securityConfig: + internalUsersSecret: "" + rolesSecret: "" + rolesMappingSecret: "" + tenantsSecret: "" extraEnvs: - name: OPENSEARCH_INITIAL_ADMIN_PASSWORD value: "CogStack-Chart-Test9!" + - name: plugins.security.ssl.http.enabled + value: "false" diff --git a/deployment/charts/opensearch/values.env.yaml b/deployment/charts/opensearch/values.env.yaml index 5a67bade..8ee04943 100644 --- a/deployment/charts/opensearch/values.env.yaml +++ b/deployment/charts/opensearch/values.env.yaml @@ -1,5 +1,6 @@ opensearch: replicas: ${OPENSEARCH_K3S_REPLICA_COUNT} + protocol: http antiAffinity: hard nodeAffinity: ${OPENSEARCH_K3S_NODE_AFFINITY} # Each StatefulSet pod gets its own claim from the cluster's default StorageClass. @@ -10,6 +11,10 @@ opensearch: extraEnvs: - name: DISABLE_INSTALL_DEMO_CONFIG value: "true" + - name: plugins.security.ssl.http.enabled + value: "false" + - name: plugins.security.allow_default_init_securityindex + value: "true" envFrom: - configMapRef: name: opensearch-env @@ -19,6 +24,11 @@ opensearch: secretName: opensearch-node-tls path: /usr/share/opensearch/config/tls defaultMode: 0440 + securityConfig: + internalUsersSecret: opensearch-security-bootstrap + rolesSecret: opensearch-security-bootstrap + rolesMappingSecret: opensearch-security-bootstrap + tenantsSecret: opensearch-security-bootstrap resources: requests: cpu: "${OPENSEARCH_DOCKER_CPU_MIN}" diff --git a/deployment/charts/opensearch/values.yaml b/deployment/charts/opensearch/values.yaml index ea01e620..3f8e9a52 100644 --- a/deployment/charts/opensearch/values.yaml +++ b/deployment/charts/opensearch/values.yaml @@ -1,5 +1,6 @@ opensearch: replicas: 1 + protocol: http antiAffinity: hard nodeAffinity: {} # Each StatefulSet pod gets its own claim from the cluster's default StorageClass. @@ -10,6 +11,10 @@ opensearch: extraEnvs: - name: DISABLE_INSTALL_DEMO_CONFIG value: "true" + - name: plugins.security.ssl.http.enabled + value: "false" + - name: plugins.security.allow_default_init_securityindex + value: "true" envFrom: - configMapRef: name: opensearch-env @@ -19,6 +24,11 @@ opensearch: secretName: opensearch-node-tls path: /usr/share/opensearch/config/tls defaultMode: 0440 + securityConfig: + internalUsersSecret: opensearch-security-bootstrap + rolesSecret: opensearch-security-bootstrap + rolesMappingSecret: opensearch-security-bootstrap + tenantsSecret: opensearch-security-bootstrap resources: requests: cpu: "1" diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index a5817416..47f07085 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -34,8 +34,7 @@ The root CA generator uses `ROOT_CERTIFICATE_KEYSTORE_PASSWORD`. ### NiFi -The NiFi generator and the default `k3s-load-auth-nifi` workflow read -`NIFI_KEYSTORE_PASSWORD` and `NIFI_TRUSTSTORE_PASSWORD` from +The NiFi generator reads `NIFI_KEYSTORE_PASSWORD` and `NIFI_TRUSTSTORE_PASSWORD` from `deployment/env/certificates.env`. `KEYSTORE_PASSWORD` and `TRUSTSTORE_PASSWORD` take precedence when set. @@ -53,14 +52,6 @@ verify. `NIFI_HEALTHCHECK_HOST` also adds a name when supplied. 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.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/`. @@ -98,6 +89,9 @@ a Kubernetes Service FQDN. Outputs are under prefix. Use the issued node and admin subjects in the corresponding OpenSearch DN settings. +Kubernetes uses the NGINX certificate and the OpenSearch transport certificate. +Load them with `make -C deployment k3s-load-certs-all`. + ## Install, initialize and verify Install on every machine before creating or joining a cluster: diff --git a/deployment/scripts/security/load_nifi_auth.sh b/deployment/scripts/security/load_nifi_auth.sh index 2ae6dd3a..4cdaced6 100644 --- a/deployment/scripts/security/load_nifi_auth.sh +++ b/deployment/scripts/security/load_nifi_auth.sh @@ -15,42 +15,37 @@ if [[ -z ${NIFI_SINGLE_USER_CREDENTIALS_USERNAME:-} && -t 0 ]]; then IFS= read -r -p 'NiFi username: ' NIFI_SINGLE_USER_CREDENTIALS_USERNAME fi : "${NIFI_SINGLE_USER_CREDENTIALS_USERNAME:?Set NIFI_SINGLE_USER_CREDENTIALS_USERNAME or run in a terminal}" +# Reserve the checked-in password for Compose development. +if [[ ${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD:-} == cogstackNiFi ]]; then + unset NIFI_SINGLE_USER_CREDENTIALS_PASSWORD +fi require_password NIFI_SINGLE_USER_CREDENTIALS_PASSWORD if (( ${#NIFI_SINGLE_USER_CREDENTIALS_PASSWORD} < 12 )); then printf 'NiFi login password must be at least 12 characters.\n' >&2 exit 1 fi -if [[ -f "$script_dir/../../env/certificates.env" && - ( -z ${NIFI_AUTH_FILE:-} || "$auth_file" -ef "$script_dir/../../env/authentication.env" ) ]]; then - # shellcheck source=../../env/certificates.env - source "$script_dir/../../env/certificates.env" +if [[ "$NIFI_SINGLE_USER_CREDENTIALS_USERNAME" == *[[:cntrl:]:]* || "$NIFI_SINGLE_USER_CREDENTIALS_USERNAME" == \#* ]]; then + printf 'NiFi username cannot contain colons or control characters, or start with #.\n' >&2 + exit 1 fi -KEYSTORE_PASSWORD=${KEYSTORE_PASSWORD:-${NIFI_KEYSTORE_PASSWORD:-}} -TRUSTSTORE_PASSWORD=${TRUSTSTORE_PASSWORD:-${NIFI_TRUSTSTORE_PASSWORD:-}} -require_password KEYSTORE_PASSWORD -require_password TRUSTSTORE_PASSWORD +NIFI_HTPASSWD=$(bcrypt_entry "$NIFI_SINGLE_USER_CREDENTIALS_USERNAME" "$NIFI_SINGLE_USER_CREDENTIALS_PASSWORD") existing=$(kubectl -n "$namespace" get secret nifi-auth --ignore-not-found -o json) version=$(jq -r '.metadata.resourceVersion' <<< "$existing") key=$(jq -r '.data.NIFI_SENSITIVE_PROPS_KEY // "" | @base64d' <<< "$existing") NIFI_SENSITIVE_PROPS_KEY=${key:-${NIFI_SENSITIVE_PROPS_KEY:-$(openssl rand -hex 16)}} -NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CREDENTIALS_USERNAME} -export NIFI_SENSITIVE_PROPS_KEY NIFI_INITIAL_ADMIN_IDENTITY NIFI_SINGLE_USER_CREDENTIALS_USERNAME +export NIFI_SENSITIVE_PROPS_KEY NIFI_HTPASSWD manifest=$(jq -n --arg version "$version" '{ apiVersion: "v1", kind: "Secret", metadata: {name: "nifi-auth", resourceVersion: (if $version == "" then null else $version end)}, stringData: { - SINGLE_USER_CREDENTIALS_USERNAME: env.NIFI_SINGLE_USER_CREDENTIALS_USERNAME, - SINGLE_USER_CREDENTIALS_PASSWORD: env.NIFI_SINGLE_USER_CREDENTIALS_PASSWORD, - INITIAL_ADMIN_IDENTITY: env.NIFI_INITIAL_ADMIN_IDENTITY, - KEYSTORE_PASSWORD: env.KEYSTORE_PASSWORD, - TRUSTSTORE_PASSWORD: env.TRUSTSTORE_PASSWORD, + htpasswd: env.NIFI_HTPASSWD, NIFI_SENSITIVE_PROPS_KEY: env.NIFI_SENSITIVE_PROPS_KEY } }') if [[ -z "$version" ]]; then kubectl -n "$namespace" create -f - <<< "$manifest" else - kubectl -n "$namespace" patch secret nifi-auth --type=merge --patch-file=/dev/stdin <<< "$manifest" + kubectl -n "$namespace" replace -f - <<< "$manifest" fi diff --git a/deployment/scripts/security/load_opensearch_auth.sh b/deployment/scripts/security/load_opensearch_auth.sh index 21d9b6ff..6b272ead 100644 --- a/deployment/scripts/security/load_opensearch_auth.sh +++ b/deployment/scripts/security/load_opensearch_auth.sh @@ -11,18 +11,12 @@ script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) # shellcheck source=../../env/general.env source "$script_dir/../../env/general.env" namespace="${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" -pod=opensearch-cluster-master-0 - if [[ "$service" == opensearch ]]; then - status=$(kubectl -n "$namespace" exec "$pod" -- curl -sS --noproxy '*' \ - --retry 3 --retry-delay 2 --retry-connrefused --max-time 10 \ - --cacert /usr/share/opensearch/config/tls/ca.crt --output /dev/null \ - --write-out '%{http_code}' https://localhost:9200/_plugins/_security/health) - case "$status" in - 200) printf '%s\n' 'OpenSearch Security is already initialized.'; exit 0 ;; - 503) ;; - *) printf 'OpenSearch Security health check returned HTTP %s.\n' "$status" >&2; exit 1 ;; - esac + bootstrap=$(kubectl -n "$namespace" get secret opensearch-security-bootstrap --ignore-not-found -o name) + if [[ -n "$bootstrap" ]]; then + printf '%s\n' "$bootstrap already exists." + exit 0 + fi fi auth_file=${OPENSEARCH_AUTH_FILE:-$script_dir/../../env/authentication.env} @@ -44,9 +38,29 @@ fi require_password OPENSEARCH_KIBANA_PASSWORD if [[ "$service" == opensearch ]]; then - export OPENSEARCH_NIFI_PASSWORD OPENSEARCH_PIPELINE_PASSWORD OPENSEARCH_ANALYST_PASSWORD \ - OS_NIFI_PASSWORD OS_PIPELINE_PASSWORD OS_ANALYST_PASSWORD - exec bash "$script_dir/../../charts/opensearch/security/bootstrap.sh" kubectl -n "$namespace" exec -i "$pod" -- + policy="$script_dir/../../charts/opensearch/security" + internal_users=$( + printf '_meta:\n type: internalusers\n config_version: 2\n' + users=(kibanaserver nifi cogstack_pipeline cogstack_user admin) + passwords=("$OPENSEARCH_KIBANA_PASSWORD" "${OPENSEARCH_NIFI_PASSWORD:-${OS_NIFI_PASSWORD:-}}" + "${OPENSEARCH_PIPELINE_PASSWORD:-${OS_PIPELINE_PASSWORD:-}}" + "${OPENSEARCH_ANALYST_PASSWORD:-${OS_ANALYST_PASSWORD:-}}" "${OPENSEARCH_ADMIN_PASSWORD:-}") + for i in "${!users[@]}"; do + [[ -n "${passwords[i]}" ]] || continue + entry=$(bcrypt_entry "${users[i]}" "${passwords[i]}") || exit 1 + printf '%s:\n hash: "%s"\n' "${users[i]}" "${entry#*:}" + done + ) + roles_mapping=$(cat "$policy/roles_mapping.yml") + if [[ -n ${OPENSEARCH_ADMIN_PASSWORD:-} ]]; then + roles_mapping+=$'\n\nall_access:\n users: [admin]\n' + fi + kubectl -n "$namespace" create secret generic opensearch-security-bootstrap \ + --from-literal="internal_users.yml=$internal_users" \ + --from-file="roles.yml=$policy/roles.yml" \ + --from-literal="roles_mapping.yml=$roles_mapping" \ + --from-file="tenants.yml=$policy/tenants.yml" + exit fi DASHBOARDS_COOKIE_DATA=$(jq -r '.data.cookie // ""' <<< "$existing") diff --git a/deployment/scripts/security/password_prompt.sh b/deployment/scripts/security/password_prompt.sh index 5fe70e22..c18e0436 100644 --- a/deployment/scripts/security/password_prompt.sh +++ b/deployment/scripts/security/password_prompt.sh @@ -21,3 +21,12 @@ require_password() { printf '\n' >&2 export "$name=$password" } + +bcrypt_entry() { + local user=$1 password=$2 LC_ALL=C + if [[ "$password" == *[$'\r\n']* || ${#password} -gt 72 ]]; then + printf 'The password for %s must fit on one line and be at most 72 bytes.\n' "$user" >&2 + return 1 + fi + printf '%s\n' "$password" | htpasswd -nBi -C 10 -- "$user" +} From 9a95417ed33efa0c5b28b4ec96daf09b9b082ed2 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 16:01:59 +0000 Subject: [PATCH 51/63] Added easy command for setup-pre-reqs. --- deployment/Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/deployment/Makefile b/deployment/Makefile index 4b4a9387..5d2b62d8 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -1,7 +1,7 @@ SHELL := /usr/bin/env bash .SHELLFLAGS := -o pipefail -c -.PHONY: setup-install-pre-requisites setup-k3s-cluster-init setup-verify setup-k3s-cluster-remote setup-k3s-namespace help +.PHONY: setup-all setup-install-pre-requisites setup-k3s-cluster-init setup-verify setup-k3s-cluster-remote setup-k3s-namespace help setup-install-pre-requisites: ## Install host tools, Docker, K3s, and Helm locally by default bash scripts/installation_utils/install_os_tools_and_software.sh @@ -22,6 +22,12 @@ setup-verify: ## Check local Docker, Docker Compose, and K3s access without sudo bash scripts/installation_utils/verify_docker.sh bash scripts/installation_utils/verify_k3s.sh +setup-all: ## Install prerequisites, initialize K3s, create the namespace, and verify + $(MAKE) setup-install-pre-requisites + $(MAKE) setup-k3s-cluster-init + $(MAKE) setup-k3s-namespace + $(MAKE) setup-verify + # ====================================================================================================================================================== .PHONY: certs certs-all certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-nodes delete-certs-all From 9fc3f06783424df7327924043859dcabf3ea9557 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 16:17:17 +0000 Subject: [PATCH 52/63] fix(deployment): use OpenSSL for NiFi login hashes --- .github/workflows/helm_smoke_logins.yml | 2 +- deployment/charts/README.md | 6 +++--- deployment/charts/nifi/README.md | 4 ++-- deployment/scripts/security/load_nifi_auth.sh | 10 +++++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/helm_smoke_logins.yml b/.github/workflows/helm_smoke_logins.yml index 71f20bb1..127c4348 100644 --- a/.github/workflows/helm_smoke_logins.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -58,7 +58,6 @@ jobs: env: STACK: ${{ matrix.stack }} run: | - command -v htpasswd >/dev/null || sudo apt-get install -y apache2-utils source deployment/env/general.env SECURITY_DIR=$(mktemp -d "$RUNNER_TEMP/helm-smoke.XXXXXX") password=$(openssl rand -hex 16) @@ -83,6 +82,7 @@ jobs: - name: Install OpenSearch and Dashboards if: matrix.stack == 'opensearch' run: | + command -v htpasswd >/dev/null || sudo apt-get install -y apache2-utils sudo sysctl -w vm.max_map_count=262144 OPENSEARCH_KIBANA_PASSWORD="$SMOKE_PASSWORD" OPENSEARCH_ANALYST_PASSWORD="$SMOKE_PASSWORD" \ make -C deployment helm-install-opensearch-stack diff --git a/deployment/charts/README.md b/deployment/charts/README.md index f7d020dd..d2110c81 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -19,9 +19,9 @@ port 443. The cluster must enforce the NiFi NetworkPolicy. | [`opensearch-dashboards/`](opensearch-dashboards/README.md) | Dashboards UI. | For a new deployment, set `NGINX_TLS_NAMES` to the hostname or IP clients will -use. Supply your deployment credentials and install `htpasswd` on the machine -running the loaders (`apache2-utils` on Debian/Ubuntu or `httpd-tools` on RHEL). -Run these commands from the repository root. +use. Supply your deployment credentials. The OpenSearch loader uses `htpasswd` +(`apache2-utils` on Debian/Ubuntu or `httpd-tools` on RHEL). Run these commands +from the repository root. ```bash make -C deployment setup-k3s-namespace diff --git a/deployment/charts/nifi/README.md b/deployment/charts/nifi/README.md index 19c7f24b..52a35b4f 100644 --- a/deployment/charts/nifi/README.md +++ b/deployment/charts/nifi/README.md @@ -9,8 +9,8 @@ NGINX handles HTTPS and login for the UI and API. [NGINX chart](../nginx/README. Run `make -C deployment k3s-load-auth-nifi` to create or update `nifi-auth` with the NiFi flow encryption key and the NGINX `htpasswd` entry. Set `NIFI_SINGLE_USER_CREDENTIALS_USERNAME` and `NIFI_SINGLE_USER_CREDENTIALS_PASSWORD` -in the environment or `deployment/env/authentication.env`. The loader requires -`htpasswd` and prompts for a deployment password if needed. It preserves the +in the environment or `deployment/env/authentication.env`. The loader uses +OpenSSL and prompts for a deployment password if needed. It preserves the existing `NIFI_SENSITIVE_PROPS_KEY` when upgrading. The namespace needs a StorageClass or persistent volumes for the six claims per diff --git a/deployment/scripts/security/load_nifi_auth.sh b/deployment/scripts/security/load_nifi_auth.sh index 4cdaced6..4a0cc38f 100644 --- a/deployment/scripts/security/load_nifi_auth.sh +++ b/deployment/scripts/security/load_nifi_auth.sh @@ -20,15 +20,19 @@ if [[ ${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD:-} == cogstackNiFi ]]; then unset NIFI_SINGLE_USER_CREDENTIALS_PASSWORD fi require_password NIFI_SINGLE_USER_CREDENTIALS_PASSWORD -if (( ${#NIFI_SINGLE_USER_CREDENTIALS_PASSWORD} < 12 )); then - printf 'NiFi login password must be at least 12 characters.\n' >&2 +password=$NIFI_SINGLE_USER_CREDENTIALS_PASSWORD +if [[ "$password" == *[$'\r\n']* || ${#password} -lt 12 ]] || + (LC_ALL=C; (( ${#password} > 72 ))); then + printf 'NiFi login password must be one line, at least 12 characters and at most 72 bytes.\n' >&2 exit 1 fi if [[ "$NIFI_SINGLE_USER_CREDENTIALS_USERNAME" == *[[:cntrl:]:]* || "$NIFI_SINGLE_USER_CREDENTIALS_USERNAME" == \#* ]]; then printf 'NiFi username cannot contain colons or control characters, or start with #.\n' >&2 exit 1 fi -NIFI_HTPASSWD=$(bcrypt_entry "$NIFI_SINGLE_USER_CREDENTIALS_USERNAME" "$NIFI_SINGLE_USER_CREDENTIALS_PASSWORD") +salt=$(openssl rand -hex 8) +hash=$(openssl passwd -6 -salt "rounds=100000\$$salt" -stdin <<< "$password") +NIFI_HTPASSWD="$NIFI_SINGLE_USER_CREDENTIALS_USERNAME:$hash" existing=$(kubectl -n "$namespace" get secret nifi-auth --ignore-not-found -o json) version=$(jq -r '.metadata.resourceVersion' <<< "$existing") From 0fd9df447f79e6f232d6ea5b8369c68655751551 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 16:40:18 +0000 Subject: [PATCH 53/63] Makefile additions. --- deployment/Makefile | 15 ++++++++++++++- deployment/charts/README.md | 4 +--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/deployment/Makefile b/deployment/Makefile index 5d2b62d8..0ec37564 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -115,7 +115,12 @@ k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch: printf -- '---\n%s\n' "$${manifests[@]}" | \ kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-certificates -f - -.PHONY: k3s-load-auth-nifi k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards +.PHONY: k3s-load-auth-all k3s-load-auth-nifi k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards + +k3s-load-auth-all: ## Load the NiFi, Dashboards, and OpenSearch auth Secrets + $(MAKE) k3s-load-auth-nifi + $(MAKE) k3s-load-auth-opensearch-dashboards + $(MAKE) k3s-load-auth-opensearch # Uses env/authentication.env. Set NIFI_AUTH_FILE to choose another auth file. k3s-load-auth-nifi: ## Load the NiFi flow encryption key and NGINX login Secret @@ -213,6 +218,14 @@ helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch # ====================================================================================================================================================== +.PHONY: k3s-prepare-all + +k3s-prepare-all: ## Render Helm values and load TLS, runtime, and auth resources + $(MAKE) helm-values-all + $(MAKE) k3s-load-certs-all + $(MAKE) k3s-load-env-all + $(MAKE) k3s-load-auth-all + .PHONY: helm-install helm-install-nifi helm-install-nginx helm-install-nifi-stack .PHONY: helm-install-opensearch helm-install-opensearch-dashboards helm-install-opensearch-stack k3s-bootstrap-opensearch diff --git a/deployment/charts/README.md b/deployment/charts/README.md index d2110c81..105ad4c7 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -26,9 +26,7 @@ from the repository root. ```bash make -C deployment setup-k3s-namespace make -C deployment -j1 certs-root certs-nginx certs-opensearch-nodes NODES=opensearch-shared -make -C deployment k3s-load-certs-all k3s-load-auth-nifi -make -C deployment helm-install-nifi-stack -make -C deployment helm-install-opensearch-stack +make -C deployment -j1 k3s-prepare-all helm-install-nifi-stack helm-install-opensearch-stack BOOTSTRAP_OPENSEARCH_SECURITY=0 ``` Existing deployments must reload `nifi-auth` for NGINX before upgrading. From f2fe15295a28153f88b3bcf3e5c0290a714afdc3 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 17:14:17 +0000 Subject: [PATCH 54/63] Updated Makefile. --- .github/workflows/docker_smoke_nifi.yml | 2 +- deployment/Makefile | 53 ++++++++------- deployment/README.md | 86 +++++++++++++++++++++++++ deployment/charts/README.md | 4 +- deployment/scripts/README.md | 14 ++-- 5 files changed, 127 insertions(+), 32 deletions(-) create mode 100644 deployment/README.md diff --git a/.github/workflows/docker_smoke_nifi.yml b/.github/workflows/docker_smoke_nifi.yml index 89a37322..5399045e 100644 --- a/.github/workflows/docker_smoke_nifi.yml +++ b/.github/workflows/docker_smoke_nifi.yml @@ -60,7 +60,7 @@ jobs: NIFI_SENSITIVE_PROPS_KEY=$(openssl rand -hex 16) export SECURITY_DIR NIFI_SENSITIVE_PROPS_KEY export KEYSTORE_PASSWORD="$password" TRUSTSTORE_PASSWORD="$password" SINGLE_USER_CREDENTIALS_PASSWORD="$password" - ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" make -C ../../../deployment certs + ROOT_CERTIFICATE_KEYSTORE_PASSWORD="$password" make -C ../../../deployment -j1 certs-root certs-nifi certs-nginx # The published containers run as UID/GID 1000. sudo chown 1000:1000 "$SECURITY_DIR"/certificates/{nifi/nifi-keystore.jks,nginx/tls.key} diff --git a/deployment/Makefile b/deployment/Makefile index 0ec37564..cdc81892 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -30,23 +30,23 @@ setup-all: ## Install prerequisites, initialize K3s, create the namespace, and v # ====================================================================================================================================================== -.PHONY: certs certs-all certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-nodes delete-certs-all +.PHONY: certs-all certs-k3s certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-shared certs-opensearch-nodes delete-certs-all load_certificates_env = set -e; set -a; if [ -f ./env/certificates.env ]; then . ./env/certificates.env; fi; set +a +load_certificates_cluster_env = set -e; . ./env/general.env; export CLUSTER_DOMAIN; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" -certs: certs-root ## Generate the root CA and NiFi and NGINX certificates - $(MAKE) certs-nifi certs-nginx +certs-k3s: certs-root ## Generate the CA, NGINX HTTPS certificate, and OpenSearch transport certificate + $(MAKE) certs-nginx + @$(load_certificates_cluster_env); \ + $(MAKE) certs-opensearch-shared KUBE_NAMESPACE="$$namespace" -certs-all: ## Generate the root CA and NiFi, NGINX, OpenSearch, and Dashboards certificates - @set -e; \ - . ./env/general.env; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - export CLUSTER_DOMAIN; \ - $(MAKE) certs KUBE_NAMESPACE="$$namespace"; \ - $(MAKE) certs-opensearch KUBE_NAMESPACE="$$namespace" +certs-all: certs-k3s ## Generate the K3s and Docker certificate bundles + @$(load_certificates_cluster_env); \ + $(MAKE) certs-nifi KUBE_NAMESPACE="$$namespace" @$(load_certificates_env); \ OPENSEARCH_DASHBOARDS_DNS_NAMES="$${OPENSEARCH_DASHBOARDS_DNS_NAMES:-localhost}" \ - bash scripts/security/create_opensearch_client_admin_certs.sh --dashboards-only + bash scripts/security/create_opensearch_client_admin_certs.sh certs-root: ## Generate the root CA bundle @$(load_certificates_env); \ @@ -59,14 +59,16 @@ certs-nginx: ## Generate the NGINX certificate with the existing CA @$(load_certificates_env); \ bash scripts/security/create_nginx_certs.sh -certs-opensearch: ## Generate the shared OpenSearch node and admin client certificates +certs-opensearch: certs-opensearch-shared ## Generate the shared OpenSearch node and admin client certificates + @$(load_certificates_env); \ + bash scripts/security/create_opensearch_client_admin_certs.sh --admin-only + +certs-opensearch-shared: @$(load_certificates_env); \ service=opensearch-cluster-master; \ service_dns="$$service.$${KUBE_NAMESPACE:-search}.svc"; \ $(MAKE) certs-opensearch-nodes NODES=opensearch-shared \ OPENSEARCH_NODE_DNS_NAMES="$${OPENSEARCH_NODE_DNS_NAMES:-localhost,$$service,$$service_dns,$$service_dns.$${CLUSTER_DOMAIN:-cluster.local}}" - @$(load_certificates_env); \ - bash scripts/security/create_opensearch_client_admin_certs.sh --admin-only certs-opensearch-nodes: ## Generate OpenSearch node certificates for NODES="node1 node2 ..." @$(load_certificates_env); \ @@ -87,7 +89,7 @@ delete-certs-all: ## Delete generated local TLS certificates, keys, and stores .PHONY: k3s-load-certs k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch -k3s-load-certs: k3s-load-certs-all ## Alias for k3s-load-certs-all +k3s-load-certs: k3s-load-certs-all k3s-load-certs-all: ## Load the NGINX HTTPS and OpenSearch transport TLS Secrets k3s-load-certs-nginx: ## Load the NGINX certificate and key into nginx-tls k3s-load-certs-opensearch: ## Load the shared node certificate into opensearch-node-tls @@ -95,6 +97,7 @@ k3s-load-certs-opensearch: ## Load the shared node certificate into opensearch-n k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch: @set -eo pipefail; \ . ./env/general.env; \ + if [ -f ./env/certificates.env ]; then . ./env/certificates.env; fi; \ namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ certs="$${SECURITY_DIR:-security}/certificates"; \ services=$(@:k3s-load-certs-%=%); \ @@ -226,7 +229,7 @@ k3s-prepare-all: ## Render Helm values and load TLS, runtime, and auth resources $(MAKE) k3s-load-env-all $(MAKE) k3s-load-auth-all -.PHONY: helm-install helm-install-nifi helm-install-nginx helm-install-nifi-stack +.PHONY: helm-install helm-install-all helm-install-nifi helm-install-nginx helm-install-nifi-stack .PHONY: helm-install-opensearch helm-install-opensearch-dashboards helm-install-opensearch-stack k3s-bootstrap-opensearch # Set KUBE_NAMESPACE in deployment/env/general.env and create the namespace @@ -264,21 +267,21 @@ helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIM helm upgrade --install "$$release" "$$chart" -n "$$namespace" \ --wait --timeout "$${HELM_TIMEOUT:-10m}" "$${args[@]}" -helm-install-nifi: ## Install or upgrade NiFi - $(MAKE) helm-install CHART=nifi +helm-install-all: k3s-prepare-all ## Prepare and install or upgrade both application stacks + $(MAKE) helm-install-nifi-stack + $(MAKE) helm-install-opensearch-stack BOOTSTRAP_OPENSEARCH_SECURITY=0 +helm-install-nifi: ## Install or upgrade NiFi helm-install-nginx: k3s-load-env-nginx ## Load the NGINX environment, then install or upgrade NGINX - $(MAKE) helm-install CHART=nginx +helm-install-opensearch: k3s-load-env-opensearch ## Load the OpenSearch environment, then install or upgrade OpenSearch +helm-install-opensearch-dashboards: ## Install or upgrade OpenSearch Dashboards + +helm-install-nifi helm-install-nginx helm-install-opensearch helm-install-opensearch-dashboards: + $(MAKE) helm-install CHART=$(@:helm-install-%=%) helm-install-nifi-stack: helm-install-nifi ## Load the runtime environment and install or upgrade NiFi and NGINX $(MAKE) helm-install-nginx -helm-install-opensearch: k3s-load-env-opensearch ## Load the OpenSearch environment, then install or upgrade OpenSearch - $(MAKE) helm-install CHART=opensearch - -helm-install-opensearch-dashboards: ## Install or upgrade OpenSearch Dashboards - $(MAKE) helm-install CHART=opensearch-dashboards - k3s-bootstrap-opensearch: k3s-load-auth-opensearch ## Alias for k3s-load-auth-opensearch helm-install-opensearch-stack: ## Install OpenSearch and then Dashboards diff --git a/deployment/README.md b/deployment/README.md new file mode 100644 index 00000000..2f7b7382 --- /dev/null +++ b/deployment/README.md @@ -0,0 +1,86 @@ +# CogStack deployment + +## Prerequisites + +- A Debian, Ubuntu or Red Hat Enterprise Linux host running systemd, with + network access to package repositories, installer downloads and container + registries. [K3s host requirements](https://docs.k3s.io/installation/requirements) +- A full checkout of this repository, Bash, GNU Make and `sudo` access. Sign in + as the user who will manage the cluster. The setup scripts call `sudo` as + needed. +- Set `KUBE_NAMESPACE` in `env/general.env`. The default is `cogstack`. +- On a fresh host, run `export KUBECONFIG="$HOME/.kube/config"` in your setup + shell. Setup creates this file if it is absent. If you already have a + kubeconfig, point `KUBECONFIG` to a user-readable configuration for the local + K3s cluster. [Kubeconfig setup](scripts/README.md#kubectl-access) + +If you plan to use the NGINX chart with K3s ServiceLB, reserve TCP port `443` +for NGINX. Before starting K3s, add `traefik` to the `disable` list in +`/etc/rancher/k3s/config.yaml` on each server. [K3s configuration](https://docs.k3s.io/installation/configuration#configuration-file) + +```yaml +disable: + - traefik +``` + +## On-premises setup + +Run from the `deployment/` directory. + +```bash +make setup-all +``` + +This installs the host utilities, Docker with Compose, K3s and Helm. It starts +the first K3s server, creates the configured namespace and checks that Docker +and Kubernetes are accessible to your user. + +On a fresh Docker installation, your current shell may still lack the `docker` +group membership added during setup. If Docker verification fails with a +permissions error, sign out and back in, set `KUBECONFIG` again and run +`make setup-verify` from `deployment/`. + +For multi-node setup over SSH, follow the [cluster setup guide](scripts/README.md#set-up-a-cluster-over-ssh). + +## Install the applications + +The Helm targets deploy NiFi, NGINX, OpenSearch and OpenSearch Dashboards. +Before installing, make sure the cluster enforces NetworkPolicy and has a +StorageClass that can provision the NiFi and OpenSearch claims. Review the CPU, +memory and storage settings for your deployment. [Helm charts](charts/README.md) + +1. Install `htpasswd` for OpenSearch authentication. The package is + `apache2-utils` on Debian and Ubuntu or `httpd-tools` on RHEL. +2. Put your NiFi login and OpenSearch passwords in a private copy of + `env/authentication.env`. Export `NIFI_AUTH_FILE` and `OPENSEARCH_AUTH_FILE` + with the path to that file. Use a separate OpenSearch user, such as the + analyst configured by `OPENSEARCH_ANALYST_PASSWORD`, to sign in to Dashboards. +3. Set the certificate store passwords in `env/certificates.env`. For a new + deployment, generate the certificates using the hostname or IP address that + clients will use to reach NGINX. Then install the charts. + + ```bash + NGINX_TLS_NAMES=cogstack.example.org make certs-k3s + make helm-install-all + ``` + + If the required certificates are already in place, run `make helm-install-all` + to reuse them. This target renders the Helm values, loads the Kubernetes + Secrets and ConfigMaps and installs both application stacks. + +## Verify and access the applications + +Replace `cogstack` with your `KUBE_NAMESPACE` if you changed it. + +```bash +helm list -n cogstack +kubectl -n cogstack get pods,pvc,svc +``` + +Check that the four releases are deployed, the pods are ready and the PVCs are +bound. If using a hostname, point it to the external address of the +`cogstack-nginx` Service. Trust the generated CA on client machines. The default +CA path is `security/certificates/root/root-ca.pem`. Use the hostname or IP from +`NGINX_TLS_NAMES` over HTTPS with `/nifi/`, `/opensearch/` or `/dashboards/`. + +Run `make help` for the available deployment targets. diff --git a/deployment/charts/README.md b/deployment/charts/README.md index 105ad4c7..68483df9 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -25,8 +25,8 @@ from the repository root. ```bash make -C deployment setup-k3s-namespace -make -C deployment -j1 certs-root certs-nginx certs-opensearch-nodes NODES=opensearch-shared -make -C deployment -j1 k3s-prepare-all helm-install-nifi-stack helm-install-opensearch-stack BOOTSTRAP_OPENSEARCH_SECURITY=0 +make -C deployment certs-k3s +make -C deployment helm-install-all ``` Existing deployments must reload `nifi-auth` for NGINX before upgrading. diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index 47f07085..c848e9ec 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -15,10 +15,16 @@ The generators prompt for missing passwords with hidden input in a terminal. For non-interactive runs, provide the required passwords through the environment or the generator's configuration. -`make -C deployment certs`, `make -C deployment certs-all` and the individual -certificate targets load `deployment/env/certificates.env` automatically. For -a direct invocation of the root CA generator, load the file to use its sample -store password. +The Makefile loads `deployment/env/certificates.env` for certificate generation +and loading. Choose a bundle when generating fresh certificates. + +| Target | Certificates | +| --- | --- | +| `certs-k3s` | CA, NGINX HTTPS, and OpenSearch transport | +| `certs-all` | K3s bundle plus the NiFi, OpenSearch admin, and Dashboards certificates for Docker | + +For a direct invocation of the root CA generator, load the file to use its +sample store password. ```bash set -a From bf8d841f9895d7acd3090ed2042128f7e3e62d80 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 17:20:50 +0000 Subject: [PATCH 55/63] README updates. --- deployment/README.md | 102 +++++++++++++----------------------- deployment/charts/README.md | 55 +++++++++++++------ 2 files changed, 75 insertions(+), 82 deletions(-) diff --git a/deployment/README.md b/deployment/README.md index 2f7b7382..46adacd7 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -1,72 +1,45 @@ # CogStack deployment -## Prerequisites - -- A Debian, Ubuntu or Red Hat Enterprise Linux host running systemd, with - network access to package repositories, installer downloads and container - registries. [K3s host requirements](https://docs.k3s.io/installation/requirements) -- A full checkout of this repository, Bash, GNU Make and `sudo` access. Sign in - as the user who will manage the cluster. The setup scripts call `sudo` as - needed. -- Set `KUBE_NAMESPACE` in `env/general.env`. The default is `cogstack`. -- On a fresh host, run `export KUBECONFIG="$HOME/.kube/config"` in your setup - shell. Setup creates this file if it is absent. If you already have a - kubeconfig, point `KUBECONFIG` to a user-readable configuration for the local - K3s cluster. [Kubeconfig setup](scripts/README.md#kubectl-access) - -If you plan to use the NGINX chart with K3s ServiceLB, reserve TCP port `443` -for NGINX. Before starting K3s, add `traefik` to the `disable` list in -`/etc/rancher/k3s/config.yaml` on each server. [K3s configuration](https://docs.k3s.io/installation/configuration#configuration-file) - -```yaml -disable: - - traefik -``` - ## On-premises setup -Run from the `deployment/` directory. +Configure the host and credentials below, then run these commands from the +repository root on the first server. Replace `cogstack.example.org` with the +hostname or IP address clients use to reach NGINX. ```bash -make setup-all +make -C deployment setup-all +NGINX_TLS_NAMES=cogstack.example.org make -C deployment certs-k3s +make -C deployment helm-install-all ``` -This installs the host utilities, Docker with Compose, K3s and Helm. It starts -the first K3s server, creates the configured namespace and checks that Docker -and Kubernetes are accessible to your user. - -On a fresh Docker installation, your current shell may still lack the `docker` -group membership added during setup. If Docker verification fails with a -permissions error, sign out and back in, set `KUBECONFIG` again and run -`make setup-verify` from `deployment/`. +`setup-all` installs the host tools, starts K3s, creates the namespace, and +verifies access. `certs-k3s` creates a fresh CA, NGINX certificate, and +OpenSearch transport certificate. Once those files exist, use `helm-install-all` +to prepare and install or upgrade NiFi, NGINX, OpenSearch, and Dashboards. -For multi-node setup over SSH, follow the [cluster setup guide](scripts/README.md#set-up-a-cluster-over-ssh). - -## Install the applications - -The Helm targets deploy NiFi, NGINX, OpenSearch and OpenSearch Dashboards. -Before installing, make sure the cluster enforces NetworkPolicy and has a -StorageClass that can provision the NiFi and OpenSearch claims. Review the CPU, -memory and storage settings for your deployment. [Helm charts](charts/README.md) - -1. Install `htpasswd` for OpenSearch authentication. The package is - `apache2-utils` on Debian and Ubuntu or `httpd-tools` on RHEL. -2. Put your NiFi login and OpenSearch passwords in a private copy of - `env/authentication.env`. Export `NIFI_AUTH_FILE` and `OPENSEARCH_AUTH_FILE` - with the path to that file. Use a separate OpenSearch user, such as the - analyst configured by `OPENSEARCH_ANALYST_PASSWORD`, to sign in to Dashboards. -3. Set the certificate store passwords in `env/certificates.env`. For a new - deployment, generate the certificates using the hostname or IP address that - clients will use to reach NGINX. Then install the charts. - - ```bash - NGINX_TLS_NAMES=cogstack.example.org make certs-k3s - make helm-install-all - ``` +## Prerequisites - If the required certificates are already in place, run `make helm-install-all` - to reuse them. This target renders the Helm values, loads the Kubernetes - Secrets and ConfigMaps and installs both application stacks. +- Use Debian, Ubuntu, or RHEL with systemd, network access, Bash, GNU Make, + `sudo`, and a full repository checkout. For multiple servers, use the + [SSH cluster setup guide](scripts/README.md#set-up-a-cluster-over-ssh). +- Point `KUBECONFIG` at the intended K3s cluster. On a fresh host, run + `export KUBECONFIG="$HOME/.kube/config"` before `setup-all`. Set + `KUBE_NAMESPACE` in `deployment/env/general.env` if you want a namespace other + than `cogstack`. [Kubeconfig setup](scripts/README.md#kubectl-access) +- When using K3s ServiceLB, add `traefik` to the `disable` list in + `/etc/rancher/k3s/config.yaml` on each server before setup. This frees TCP port + `443` for NGINX. Use a cluster that enforces NetworkPolicy and can provision + the NiFi and OpenSearch persistent volumes. [Helm chart settings](charts/README.md) +- Install `htpasswd` for OpenSearch (`apache2-utils` on Debian or Ubuntu, + `httpd-tools` on RHEL). Put the NiFi and OpenSearch passwords in a private + copy of `deployment/env/authentication.env` and export its absolute path as + `NIFI_AUTH_FILE` and `OPENSEARCH_AUTH_FILE`. Set `OPENSEARCH_ANALYST_PASSWORD` + for the `cogstack_user` login in Dashboards. +- Set the store passwords in `deployment/env/certificates.env` and populate the + NiFi environment file used to render Helm values. [NiFi environment](charts/README.md#nifi-environment) + +If fresh Docker setup reports a permissions error, sign in again, set +`KUBECONFIG`, and run `make -C deployment setup-verify`. ## Verify and access the applications @@ -77,10 +50,7 @@ helm list -n cogstack kubectl -n cogstack get pods,pvc,svc ``` -Check that the four releases are deployed, the pods are ready and the PVCs are -bound. If using a hostname, point it to the external address of the -`cogstack-nginx` Service. Trust the generated CA on client machines. The default -CA path is `security/certificates/root/root-ca.pem`. Use the hostname or IP from -`NGINX_TLS_NAMES` over HTTPS with `/nifi/`, `/opensearch/` or `/dashboards/`. - -Run `make help` for the available deployment targets. +Check that the four releases are deployed, the pods are ready, and the PVCs +are bound. Point your DNS name at the external address of `cogstack-nginx` and +trust `deployment/security/certificates/root/root-ca.pem` on client machines. +Use HTTPS at `/nifi/`, `/opensearch/`, or `/dashboards/`. diff --git a/deployment/charts/README.md b/deployment/charts/README.md index 68483df9..c4a3febb 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -6,22 +6,32 @@ Folder names use component names, such as `medcat-service` and `jupyter-hub`. ## Kubernetes HTTPS entry point -Deploy the four standalone charts in the same namespace. NGINX exposes HTTPS -through a LoadBalancer Service on port 443 and forwards to HTTP Services in the -cluster. On K3s with ServiceLB, disable the bundled Traefik controller to free -port 443. The cluster must enforce the NiFi NetworkPolicy. - -| Chart | Purpose | -| --- | --- | -| [`nginx/`](nginx/README.md) | HTTPS reverse proxy and NiFi login. | -| [`nifi/`](nifi/README.md) | NiFi StatefulSet and persistent storage. | -| [`opensearch/`](opensearch/README.md) | OpenSearch Security and node transport TLS. | -| [`opensearch-dashboards/`](opensearch-dashboards/README.md) | Dashboards UI. | +Deploy the four standalone charts in the same namespace. NGINX serves HTTPS +for the stack and forwards requests to the application Services over HTTP. + +- **NiFi (`nifi/`)** runs Apache NiFi as a StatefulSet with persistent storage + for flow configuration and repositories. A NetworkPolicy restricts its + internal HTTP port `8080` to NGINX pods. Users reach the UI at `/nifi/` and the + API at `/nifi-api/`. [NiFi chart](nifi/README.md) +- **NGINX (`nginx/`)** exposes a `LoadBalancer` Service on port `443` and + terminates TLS with the `nginx-tls` Secret. It handles NiFi Basic Auth using + credentials from `nifi-auth`. [NGINX chart](nginx/README.md) +- **OpenSearch (`opensearch/`)** runs a StatefulSet with persistent storage. + OpenSearch Security controls access to the HTTP REST API on port `9200`, which + NGINX exposes at `/opensearch/`. The `opensearch-node-tls` Secret secures node + transport on port `9300`. [OpenSearch chart](opensearch/README.md) +- **OpenSearch Dashboards (`opensearch-dashboards/`)** serves the UI over HTTP + on port `5601` behind NGINX at `/dashboards/`. It connects to OpenSearch using + the `dashboards-auth` service account Secret. Users sign in with their + OpenSearch accounts. [OpenSearch Dashboards chart](opensearch-dashboards/README.md) + +### Install the standalone charts For a new deployment, set `NGINX_TLS_NAMES` to the hostname or IP clients will use. Supply your deployment credentials. The OpenSearch loader uses `htpasswd` -(`apache2-utils` on Debian/Ubuntu or `httpd-tools` on RHEL). Run these commands -from the repository root. +(`apache2-utils` on Debian/Ubuntu or `httpd-tools` on RHEL). Follow the host +prerequisites, then run these commands from the repository root. +[On-premises deployment guide](../README.md) ```bash make -C deployment setup-k3s-namespace @@ -45,9 +55,22 @@ See each chart's README for the ConfigMaps, Secrets and storage needed before installation. Run `make -C deployment helm-values-` for NiFi, NGINX, OpenSearch, or OpenSearch Dashboards to render `values.env.yaml` into `values.yaml` using `deployment/env/.env`. NGINX reads `nifi.env` for -its listener port and applies `nginx.env` when present. The local -`deployment/env/nifi.env` can link to `apps/nifi/env/nifi.env`. Docker memory -sizes such as `2g` render as `2Gi`. +its listener port and applies `nginx.env` when present. Docker memory sizes such +as `2g` render as `2Gi`. + +### NiFi environment + +`deployment/env/nifi.env` links to `apps/nifi/env/nifi.env`. If the file is +missing, create it with these defaults for Helm values rendering. + +```bash +NIFI_UID=1000 +NIFI_GID=1000 +NIFI_DOCKER_CPU_MIN=1 +NIFI_DOCKER_CPU_MAX=1 +NIFI_DOCKER_RAM=2G +NIFI_INTERNAL_PORT_NGINX=8443 +``` ## Validation and releases From a3f7ba2ad96a810c6725c0292ecbd53b2887cbef Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 17:29:46 +0000 Subject: [PATCH 56/63] updated readme. --- deployment/README.md | 126 +++++++++++++++++++++++++++++++------------ 1 file changed, 91 insertions(+), 35 deletions(-) diff --git a/deployment/README.md b/deployment/README.md index 46adacd7..98b8fe77 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -1,45 +1,101 @@ # CogStack deployment +Run the Makefile commands below from the `deployment/` directory. [Deployment Makefile](Makefile) + ## On-premises setup -Configure the host and credentials below, then run these commands from the -repository root on the first server. Replace `cogstack.example.org` with the -hostname or IP address clients use to reach NGINX. +> ⚠️ **Required for a fresh deployment.** Set up K3s and generate or provide the +> NGINX HTTPS and OpenSearch transport certificates before preparing the charts. + +Use a Debian, Ubuntu, or RHEL server with a full repository checkout, systemd, +network access, Bash, GNU Make, and `sudo`. With K3s ServiceLB, add `traefik` +to the `disable` list in `/etc/rancher/k3s/config.yaml` on each server before +setup to free TCP port `443` for NGINX. Run the following on the first server. ```bash -make -C deployment setup-all -NGINX_TLS_NAMES=cogstack.example.org make -C deployment certs-k3s -make -C deployment helm-install-all +export KUBECONFIG="$HOME/.kube/config" +make setup-all ``` -`setup-all` installs the host tools, starts K3s, creates the namespace, and -verifies access. `certs-k3s` creates a fresh CA, NGINX certificate, and -OpenSearch transport certificate. Once those files exist, use `helm-install-all` -to prepare and install or upgrade NiFi, NGINX, OpenSearch, and Dashboards. - -## Prerequisites +`setup-all` runs `setup-install-pre-requisites`, `setup-k3s-cluster-init`, +`setup-k3s-namespace`, and `setup-verify` in order. It installs the host tools, +Docker, K3s, and Helm, then creates the namespace from `env/general.env`. -- Use Debian, Ubuntu, or RHEL with systemd, network access, Bash, GNU Make, - `sudo`, and a full repository checkout. For multiple servers, use the +- For an existing cluster, point `KUBECONFIG` at it and run + `make setup-k3s-namespace`. The cluster needs NetworkPolicy enforcement and a + StorageClass for NiFi and OpenSearch. [Kubeconfig setup](scripts/README.md#kubectl-access) +- If Docker verification reports a group permission error, sign in again, set + `KUBECONFIG`, and run `make setup-verify`. For multiple servers, use the [SSH cluster setup guide](scripts/README.md#set-up-a-cluster-over-ssh). -- Point `KUBECONFIG` at the intended K3s cluster. On a fresh host, run - `export KUBECONFIG="$HOME/.kube/config"` before `setup-all`. Set - `KUBE_NAMESPACE` in `deployment/env/general.env` if you want a namespace other - than `cogstack`. [Kubeconfig setup](scripts/README.md#kubectl-access) -- When using K3s ServiceLB, add `traefik` to the `disable` list in - `/etc/rancher/k3s/config.yaml` on each server before setup. This frees TCP port - `443` for NGINX. Use a cluster that enforces NetworkPolicy and can provision - the NiFi and OpenSearch persistent volumes. [Helm chart settings](charts/README.md) -- Install `htpasswd` for OpenSearch (`apache2-utils` on Debian or Ubuntu, - `httpd-tools` on RHEL). Put the NiFi and OpenSearch passwords in a private - copy of `deployment/env/authentication.env` and export its absolute path as - `NIFI_AUTH_FILE` and `OPENSEARCH_AUTH_FILE`. Set `OPENSEARCH_ANALYST_PASSWORD` - for the `cogstack_user` login in Dashboards. -- Set the store passwords in `deployment/env/certificates.env` and populate the - NiFi environment file used to render Helm values. [NiFi environment](charts/README.md#nifi-environment) - -If fresh Docker setup reports a permissions error, sign in again, set -`KUBECONFIG`, and run `make -C deployment setup-verify`. + +### Generate certificates + +Set the store passwords in `env/certificates.env` and use the hostname or IP +clients will use for NGINX. + +```bash +NGINX_TLS_NAMES=cogstack.example.org make certs-k3s +``` + +This generates the CA, NGINX HTTPS certificate, and OpenSearch transport +certificate. Reuse an existing bundle from `SECURITY_DIR` when available. The +default directory is `deployment/security`. [Certificate targets](scripts/README.md#certificates) + +## Environment settings + +| File | Settings used by the deployment | +| --- | --- | +| `env/general.env` | `KUBE_NAMESPACE` (default `cogstack`) and `CLUSTER_DOMAIN`. | +| `env/certificates.env` | `SECURITY_DIR`, `NGINX_TLS_NAMES`, and certificate store passwords. | +| `env/authentication.env` | NiFi login and OpenSearch account passwords. | +| `env/nifi.env` | `NIFI_UID`, `NIFI_GID`, `NIFI_DOCKER_*` resources, `NIFI_K3S_WHITELIST`, and `NIFI_INTERNAL_PORT_NGINX`. | +| `env/nginx.env` (optional) | `NGINX_DOCKER_*` resource overrides and `NGINX_NIFI_SERVER_NAME`. | +| `env/opensearch.env` | `OPENSEARCH_K3S_REPLICA_COUNT`, `OPENSEARCH_K3S_BLACKLIST`, `OPENSEARCH_DOCKER_*` resources, and `OPENSEARCH_LOG_LEVEL`. | +| `env/opensearch-dashboards.env` | `OPENSEARCH_DASHBOARDS_DOCKER_*` resources. | + +Put your passwords in a private copy of `env/authentication.env` and export its +absolute path as `NIFI_AUTH_FILE` and `OPENSEARCH_AUTH_FILE`. Set +`NIFI_SINGLE_USER_CREDENTIALS_USERNAME` and `NIFI_SINGLE_USER_CREDENTIALS_PASSWORD` +for NiFi, `OPENSEARCH_KIBANA_PASSWORD` for the Dashboards service account, and +`OPENSEARCH_ANALYST_PASSWORD` to sign in to Dashboards as `cogstack_user`. +Install `htpasswd` for OpenSearch (`apache2-utils` on Debian or Ubuntu, +`httpd-tools` on RHEL). + +A fresh checkout needs an `apps/nifi/env/nifi.env` file for the `env/nifi.env` +symlink. [NiFi environment defaults](charts/README.md#nifi-environment) + +## Prepare Kubernetes resources + +After setting the environment and certificates, prepare the full stack before +running the install commands individually. + +```bash +make k3s-prepare-all +``` + +This renders Helm values (`helm-values-all`), loads TLS Secrets +(`k3s-load-certs-all`), loads runtime ConfigMaps (`k3s-load-env-all`), and loads +authentication Secrets (`k3s-load-auth-all`). `make helm-install-all` includes +this preparation and installs all four services. + +## Install the applications + +With the namespace prepared, choose a stack or install the charts individually. + +| Makefile command | What it installs or upgrades | +| --- | --- | +| `make helm-install-nifi-stack` | NiFi, then NGINX for the HTTPS UI and API. | +| `make helm-install-opensearch-stack BOOTSTRAP_OPENSEARCH_SECURITY=0` | OpenSearch, then Dashboards using the prepared authentication Secrets. | +| `make helm-install-nifi` | The NiFi StatefulSet. Use NGINX for HTTPS access. | +| `make helm-install-nginx` | The HTTPS gateway for the backends you deploy. | +| `make helm-install-opensearch` | The OpenSearch cluster and its REST API. | +| `make helm-install-opensearch-dashboards` | Dashboards. Install OpenSearch first. | + +`helm-install-opensearch-stack` defaults to `BOOTSTRAP_OPENSEARCH_SECURITY=1`, +which loads its authentication Secrets. Use `0` after `k3s-prepare-all` to reuse +those Secrets. Run `make help` for the individual preparation and install targets. +For single-chart overrides, pass `HELM_VALUES=/absolute/path.yaml` to its +install command. [Chart configuration and routes](charts/README.md#kubernetes-https-entry-point) ## Verify and access the applications @@ -50,7 +106,7 @@ helm list -n cogstack kubectl -n cogstack get pods,pvc,svc ``` -Check that the four releases are deployed, the pods are ready, and the PVCs -are bound. Point your DNS name at the external address of `cogstack-nginx` and -trust `deployment/security/certificates/root/root-ca.pem` on client machines. +Check that your selected releases are deployed, their pods are ready, and their +PVCs are bound. Point your DNS name at the external address of `cogstack-nginx` +and trust `deployment/security/certificates/root/root-ca.pem` on client machines. Use HTTPS at `/nifi/`, `/opensearch/`, or `/dashboards/`. From 58128fb3566d641868dabbd1cb756d44f584e3f7 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 17:40:18 +0000 Subject: [PATCH 57/63] More readme updates. --- deployment/README.md | 19 ++----------------- deployment/charts/README.md | 14 -------------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/deployment/README.md b/deployment/README.md index 98b8fe77..42086dcc 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -8,14 +8,7 @@ Run the Makefile commands below from the `deployment/` directory. [Deployment Ma > NGINX HTTPS and OpenSearch transport certificates before preparing the charts. Use a Debian, Ubuntu, or RHEL server with a full repository checkout, systemd, -network access, Bash, GNU Make, and `sudo`. With K3s ServiceLB, add `traefik` -to the `disable` list in `/etc/rancher/k3s/config.yaml` on each server before -setup to free TCP port `443` for NGINX. Run the following on the first server. - -```bash -export KUBECONFIG="$HOME/.kube/config" -make setup-all -``` +network access, Bash, GNU Make, and `sudo`. `setup-all` runs `setup-install-pre-requisites`, `setup-k3s-cluster-init`, `setup-k3s-namespace`, and `setup-verify` in order. It installs the host tools, @@ -58,8 +51,6 @@ absolute path as `NIFI_AUTH_FILE` and `OPENSEARCH_AUTH_FILE`. Set `NIFI_SINGLE_USER_CREDENTIALS_USERNAME` and `NIFI_SINGLE_USER_CREDENTIALS_PASSWORD` for NiFi, `OPENSEARCH_KIBANA_PASSWORD` for the Dashboards service account, and `OPENSEARCH_ANALYST_PASSWORD` to sign in to Dashboards as `cogstack_user`. -Install `htpasswd` for OpenSearch (`apache2-utils` on Debian or Ubuntu, -`httpd-tools` on RHEL). A fresh checkout needs an `apps/nifi/env/nifi.env` file for the `env/nifi.env` symlink. [NiFi environment defaults](charts/README.md#nifi-environment) @@ -85,18 +76,12 @@ With the namespace prepared, choose a stack or install the charts individually. | Makefile command | What it installs or upgrades | | --- | --- | | `make helm-install-nifi-stack` | NiFi, then NGINX for the HTTPS UI and API. | -| `make helm-install-opensearch-stack BOOTSTRAP_OPENSEARCH_SECURITY=0` | OpenSearch, then Dashboards using the prepared authentication Secrets. | +| `make helm-install-opensearch-stack` | OpenSearch, then Dashboards using the prepared authentication Secrets. | | `make helm-install-nifi` | The NiFi StatefulSet. Use NGINX for HTTPS access. | | `make helm-install-nginx` | The HTTPS gateway for the backends you deploy. | | `make helm-install-opensearch` | The OpenSearch cluster and its REST API. | | `make helm-install-opensearch-dashboards` | Dashboards. Install OpenSearch first. | -`helm-install-opensearch-stack` defaults to `BOOTSTRAP_OPENSEARCH_SECURITY=1`, -which loads its authentication Secrets. Use `0` after `k3s-prepare-all` to reuse -those Secrets. Run `make help` for the individual preparation and install targets. -For single-chart overrides, pass `HELM_VALUES=/absolute/path.yaml` to its -install command. [Chart configuration and routes](charts/README.md#kubernetes-https-entry-point) - ## Verify and access the applications Replace `cogstack` with your `KUBE_NAMESPACE` if you changed it. diff --git a/deployment/charts/README.md b/deployment/charts/README.md index c4a3febb..fe1bc74e 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -58,20 +58,6 @@ OpenSearch, or OpenSearch Dashboards to render `values.env.yaml` into its listener port and applies `nginx.env` when present. Docker memory sizes such as `2g` render as `2Gi`. -### NiFi environment - -`deployment/env/nifi.env` links to `apps/nifi/env/nifi.env`. If the file is -missing, create it with these defaults for Helm values rendering. - -```bash -NIFI_UID=1000 -NIFI_GID=1000 -NIFI_DOCKER_CPU_MIN=1 -NIFI_DOCKER_CPU_MAX=1 -NIFI_DOCKER_RAM=2G -NIFI_INTERNAL_PORT_NGINX=8443 -``` - ## Validation and releases The shared chart workflow discovers `deployment/charts/*/Chart.yaml` for From ad25b9769f87d999b335cc2701c8868a2bb8fe55 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 18:04:03 +0000 Subject: [PATCH 58/63] README update. --- deployment/README.md | 69 +++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/deployment/README.md b/deployment/README.md index 42086dcc..1cf2b072 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -2,10 +2,26 @@ Run the Makefile commands below from the `deployment/` directory. [Deployment Makefile](Makefile) -## On-premises setup +## Quickstart after setup + +After `make setup-all` succeeds, set `NGINX_TLS_NAMES` in `env/certificates.env` +to the hostname or IP clients will use for NGINX. Set the certificate store +passwords, provide deployment credentials, and create `../apps/nifi/env/nifi.env` +if it’s missing. [Environment settings](#environment-settings) -> ⚠️ **Required for a fresh deployment.** Set up K3s and generate or provide the -> NGINX HTTPS and OpenSearch transport certificates before preparing the charts. +```bash +make certs-all +make k3s-prepare-all +``` + +`certs-all` generates the certificate bundle. `k3s-prepare-all` renders Helm +values and loads the TLS Secrets, runtime ConfigMaps, and authentication Secrets. + +To deploy all four services, run `make certs-all` followed by +`make helm-install-all`, which runs preparation automatically. +[Install options](#install-the-applications) + +## On-premises setup Use a Debian, Ubuntu, or RHEL server with a full repository checkout, systemd, network access, Bash, GNU Make, and `sudo`. @@ -23,16 +39,11 @@ Docker, K3s, and Helm, then creates the namespace from `env/general.env`. ### Generate certificates -Set the store passwords in `env/certificates.env` and use the hostname or IP -clients will use for NGINX. - -```bash -NGINX_TLS_NAMES=cogstack.example.org make certs-k3s -``` - -This generates the CA, NGINX HTTPS certificate, and OpenSearch transport -certificate. Reuse an existing bundle from `SECURITY_DIR` when available. The -default directory is `deployment/security`. [Certificate targets](scripts/README.md#certificates) +Use `make certs-k3s` to generate the CA, NGINX HTTPS certificate, and OpenSearch +transport certificate for K3s. If you already have a bundle, set +`SECURITY_DIR` to the directory containing `certificates/` and start with +`make k3s-prepare-all`. The default directory is `deployment/security`. +[Certificate targets](scripts/README.md#certificates) ## Environment settings @@ -46,32 +57,32 @@ default directory is `deployment/security`. [Certificate targets](scripts/README | `env/opensearch.env` | `OPENSEARCH_K3S_REPLICA_COUNT`, `OPENSEARCH_K3S_BLACKLIST`, `OPENSEARCH_DOCKER_*` resources, and `OPENSEARCH_LOG_LEVEL`. | | `env/opensearch-dashboards.env` | `OPENSEARCH_DASHBOARDS_DOCKER_*` resources. | -Put your passwords in a private copy of `env/authentication.env` and export its -absolute path as `NIFI_AUTH_FILE` and `OPENSEARCH_AUTH_FILE`. Set +`k3s-prepare-all` reads login credentials from `env/authentication.env` by +default. To use a private copy, export its absolute path as `NIFI_AUTH_FILE` +and `OPENSEARCH_AUTH_FILE`. Set `NIFI_SINGLE_USER_CREDENTIALS_USERNAME` and `NIFI_SINGLE_USER_CREDENTIALS_PASSWORD` for NiFi, `OPENSEARCH_KIBANA_PASSWORD` for the Dashboards service account, and `OPENSEARCH_ANALYST_PASSWORD` to sign in to Dashboards as `cogstack_user`. +The NiFi loader prompts if its password is empty or still uses the checked-in +Compose sample. -A fresh checkout needs an `apps/nifi/env/nifi.env` file for the `env/nifi.env` -symlink. [NiFi environment defaults](charts/README.md#nifi-environment) +### NiFi environment -## Prepare Kubernetes resources +A fresh checkout needs `apps/nifi/env/nifi.env` for the `deployment/env/nifi.env` +symlink. Create the file with these starter values. -After setting the environment and certificates, prepare the full stack before -running the install commands individually. - -```bash -make k3s-prepare-all +```dotenv +NIFI_UID=1000 +NIFI_GID=1000 +NIFI_DOCKER_CPU_MIN=1 +NIFI_DOCKER_CPU_MAX=1 +NIFI_DOCKER_RAM=2g +NIFI_INTERNAL_PORT_NGINX=8443 ``` -This renders Helm values (`helm-values-all`), loads TLS Secrets -(`k3s-load-certs-all`), loads runtime ConfigMaps (`k3s-load-env-all`), and loads -authentication Secrets (`k3s-load-auth-all`). `make helm-install-all` includes -this preparation and installs all four services. - ## Install the applications -With the namespace prepared, choose a stack or install the charts individually. +After `make k3s-prepare-all`, choose a stack or install the charts individually. | Makefile command | What it installs or upgrades | | --- | --- | From ebd1f65be0acda2b86fbd41a1dda2aad8c06fdbb Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 18:06:21 +0000 Subject: [PATCH 59/63] Env update. --- deployment/env/authentication.env | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deployment/env/authentication.env b/deployment/env/authentication.env index aa871deb..d7a7356a 100644 --- a/deployment/env/authentication.env +++ b/deployment/env/authentication.env @@ -8,7 +8,7 @@ NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CRE NIFI_SENSITIVE_PROPS_KEY=${NIFI_SENSITIVE_PROPS_KEY:-c6063c770f5a281732877e7a9f7de2bc} # OpenSearch passwords for kibanaserver, nifi, cogstack_pipeline and cogstack_user. -OPENSEARCH_KIBANA_PASSWORD=${OPENSEARCH_KIBANA_PASSWORD:-} -OPENSEARCH_NIFI_PASSWORD=${OPENSEARCH_NIFI_PASSWORD:-} -OPENSEARCH_PIPELINE_PASSWORD=${OPENSEARCH_PIPELINE_PASSWORD:-} -OPENSEARCH_ANALYST_PASSWORD=${OPENSEARCH_ANALYST_PASSWORD:-} +OPENSEARCH_KIBANA_PASSWORD=${OPENSEARCH_KIBANA_PASSWORD:-demo} +OPENSEARCH_NIFI_PASSWORD=${OPENSEARCH_NIFI_PASSWORD:-demo} +OPENSEARCH_PIPELINE_PASSWORD=${OPENSEARCH_PIPELINE_PASSWORD:-demo} +OPENSEARCH_ANALYST_PASSWORD=${OPENSEARCH_ANALYST_PASSWORD:-demo} From 476f83938194f450ac20ed9314cad9348a5d9d02 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 19:58:51 +0000 Subject: [PATCH 60/63] Added extra auth. --- deployment/Makefile | 26 ++++++++++++++++++++++++++ deployment/README.md | 14 -------------- deployment/env/authentication.env | 3 +++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/deployment/Makefile b/deployment/Makefile index cdc81892..b7b83d35 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -136,6 +136,24 @@ k3s-load-auth-opensearch-dashboards: ## Load the OpenSearch Dashboards auth Secr k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards: @bash scripts/security/load_opensearch_auth.sh $(@:k3s-load-auth-%=%) +.PHONY: k3s-delete-auth-all k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards + +k3s-delete-auth-all: k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards ## Delete the NiFi, OpenSearch, and Dashboards auth Secrets +k3s-delete-auth-nifi: ## Delete the NiFi login and flow encryption key Secret +k3s-delete-auth-opensearch: ## Delete the OpenSearch security bootstrap Secret +k3s-delete-auth-opensearch-dashboards: ## Delete the OpenSearch Dashboards auth Secret + +k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards: + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + case "$(@:k3s-delete-auth-%=%)" in \ + nifi) secret=nifi-auth;; \ + opensearch) secret=opensearch-security-bootstrap;; \ + opensearch-dashboards) secret=dashboards-auth;; \ + esac; \ + kubectl -n "$$namespace" delete secret "$$secret" --ignore-not-found + .PHONY: k3s-load-env-all k3s-load-env-nginx k3s-load-env-opensearch k3s-load-env-all: k3s-load-env-nginx k3s-load-env-opensearch ## Load all runtime environment ConfigMaps @@ -295,6 +313,7 @@ helm-install-opensearch-stack: ## Install OpenSearch and then Dashboards .PHONY: helm-uninstall-nifi helm-uninstall-nginx helm-uninstall-nifi-stack .PHONY: helm-uninstall-opensearch helm-uninstall-opensearch-dashboards helm-uninstall-opensearch-stack +.PHONY: helm-delete-opensearch-volumes # Reinstall in the same namespace with the same StatefulSet names to reuse the retained PVCs. helm-uninstall-nifi: ## Uninstall NiFi and retain its PVCs @@ -317,6 +336,13 @@ helm-uninstall-nifi-stack: helm-uninstall-nginx ## Uninstall NGINX, then NiFi, a helm-uninstall-opensearch-stack: helm-uninstall-opensearch-dashboards ## Uninstall Dashboards, then OpenSearch, and retain PVCs $(MAKE) helm-uninstall-opensearch +helm-delete-opensearch-volumes: ## Delete OpenSearch data PVCs after uninstalling + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + kubectl -n "$$namespace" delete pvc --ignore-not-found \ + -l 'app.kubernetes.io/instance=opensearch,app.kubernetes.io/name=opensearch' + # ====================================================================================================================================================== help: ## Show deployment commands diff --git a/deployment/README.md b/deployment/README.md index 1cf2b072..dd6f0285 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -66,20 +66,6 @@ for NiFi, `OPENSEARCH_KIBANA_PASSWORD` for the Dashboards service account, and The NiFi loader prompts if its password is empty or still uses the checked-in Compose sample. -### NiFi environment - -A fresh checkout needs `apps/nifi/env/nifi.env` for the `deployment/env/nifi.env` -symlink. Create the file with these starter values. - -```dotenv -NIFI_UID=1000 -NIFI_GID=1000 -NIFI_DOCKER_CPU_MIN=1 -NIFI_DOCKER_CPU_MAX=1 -NIFI_DOCKER_RAM=2g -NIFI_INTERNAL_PORT_NGINX=8443 -``` - ## Install the applications After `make k3s-prepare-all`, choose a stack or install the charts individually. diff --git a/deployment/env/authentication.env b/deployment/env/authentication.env index d7a7356a..11bab001 100644 --- a/deployment/env/authentication.env +++ b/deployment/env/authentication.env @@ -7,6 +7,9 @@ NIFI_SINGLE_USER_CREDENTIALS_PASSWORD="${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD:- NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CREDENTIALS_USERNAME} NIFI_SENSITIVE_PROPS_KEY=${NIFI_SENSITIVE_PROPS_KEY:-c6063c770f5a281732877e7a9f7de2bc} +# Set the admin password to create an admin user with all_access during initial bootstrap. +OPENSEARCH_ADMIN_PASSWORD="${OPENSEARCH_ADMIN_PASSWORD:-demo}" + # OpenSearch passwords for kibanaserver, nifi, cogstack_pipeline and cogstack_user. OPENSEARCH_KIBANA_PASSWORD=${OPENSEARCH_KIBANA_PASSWORD:-demo} OPENSEARCH_NIFI_PASSWORD=${OPENSEARCH_NIFI_PASSWORD:-demo} From 351809ac91b2b5e27cd8ada43f270f76e4a66a34 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 19:59:48 +0000 Subject: [PATCH 61/63] Updated CE charts. --- deployment/charts/ce/values.yaml | 2 +- deployment/charts/ocr-service/Chart.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/charts/ce/values.yaml b/deployment/charts/ce/values.yaml index 785d77e4..c05c860b 100644 --- a/deployment/charts/ce/values.yaml +++ b/deployment/charts/ce/values.yaml @@ -47,7 +47,7 @@ ocr-service: # -- OCR service image repository. # repository: cogstacksystems/ocr-service # -- OCR service image tag. - # tag: "1.1.1" + # tag: "latest" medcat-trainer: # -- Enable MedCAT Trainer deployment. diff --git a/deployment/charts/ocr-service/Chart.yaml b/deployment/charts/ocr-service/Chart.yaml index fbcd1e41..58d1d315 100644 --- a/deployment/charts/ocr-service/Chart.yaml +++ b/deployment/charts/ocr-service/Chart.yaml @@ -21,7 +21,7 @@ version: 0.1.0 # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "1.1.1" +appVersion: "latest" keywords: - cogstack From 8b1ec6c9a3875e55eeb339ed8f4412138c682596 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 20:22:25 +0000 Subject: [PATCH 62/63] Auth env update. --- deployment/env/authentication.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/env/authentication.env b/deployment/env/authentication.env index 11bab001..e2732a06 100644 --- a/deployment/env/authentication.env +++ b/deployment/env/authentication.env @@ -8,7 +8,7 @@ NIFI_INITIAL_ADMIN_IDENTITY=${NIFI_INITIAL_ADMIN_IDENTITY:-$NIFI_SINGLE_USER_CRE NIFI_SENSITIVE_PROPS_KEY=${NIFI_SENSITIVE_PROPS_KEY:-c6063c770f5a281732877e7a9f7de2bc} # Set the admin password to create an admin user with all_access during initial bootstrap. -OPENSEARCH_ADMIN_PASSWORD="${OPENSEARCH_ADMIN_PASSWORD:-demo}" +OPENSEARCH_ADMIN_PASSWORD=${OPENSEARCH_ADMIN_PASSWORD:-demo} # OpenSearch passwords for kibanaserver, nifi, cogstack_pipeline and cogstack_user. OPENSEARCH_KIBANA_PASSWORD=${OPENSEARCH_KIBANA_PASSWORD:-demo} From 621a12871c935a80ee21daee060cb4472098ea23 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Thu, 26 Nov 2026 20:23:48 +0000 Subject: [PATCH 63/63] deployment makefile update (structure). --- .github/workflows/docker_smoke_nifi.yml | 1 + .github/workflows/docker_smoke_opensearch.yml | 1 + .github/workflows/helm_smoke_logins.yml | 1 + deployment/Makefile | 359 +----------------- deployment/make/certs.mk | 87 +++++ deployment/make/helm.mk | 153 ++++++++ deployment/make/k3s.mk | 68 ++++ deployment/make/setup.mk | 28 ++ 8 files changed, 355 insertions(+), 343 deletions(-) create mode 100644 deployment/make/certs.mk create mode 100644 deployment/make/helm.mk create mode 100644 deployment/make/k3s.mk create mode 100644 deployment/make/setup.mk diff --git a/.github/workflows/docker_smoke_nifi.yml b/.github/workflows/docker_smoke_nifi.yml index 5399045e..e4ec7f09 100644 --- a/.github/workflows/docker_smoke_nifi.yml +++ b/.github/workflows/docker_smoke_nifi.yml @@ -7,6 +7,7 @@ on: - 'apps/nifi/**' - 'apps/nginx/**' - 'deployment/Makefile' + - 'deployment/make/**' - 'deployment/scripts/security/**' - 'deployment/security/templates/**' - '.github/scripts/smoke_nifi_login.sh' diff --git a/.github/workflows/docker_smoke_opensearch.yml b/.github/workflows/docker_smoke_opensearch.yml index ac225062..63e03533 100644 --- a/.github/workflows/docker_smoke_opensearch.yml +++ b/.github/workflows/docker_smoke_opensearch.yml @@ -7,6 +7,7 @@ on: - 'apps/opensearch/**' - 'apps/opensearch-dashboards/**' - 'deployment/Makefile' + - 'deployment/make/**' - 'deployment/scripts/security/**' - 'deployment/security/templates/**' - '.github/workflows/docker_smoke_opensearch.yml' diff --git a/.github/workflows/helm_smoke_logins.yml b/.github/workflows/helm_smoke_logins.yml index 127c4348..f443cad4 100644 --- a/.github/workflows/helm_smoke_logins.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -9,6 +9,7 @@ on: - 'deployment/charts/opensearch/**' - 'deployment/charts/opensearch-dashboards/**' - 'deployment/Makefile' + - 'deployment/make/**' - 'deployment/env/authentication.env' - 'deployment/env/certificates.env' - 'deployment/env/general.env' diff --git a/deployment/Makefile b/deployment/Makefile index b7b83d35..2f0ca14d 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -1,352 +1,25 @@ SHELL := /usr/bin/env bash .SHELLFLAGS := -o pipefail -c +.DEFAULT_GOAL := setup-install-pre-requisites -.PHONY: setup-all setup-install-pre-requisites setup-k3s-cluster-init setup-verify setup-k3s-cluster-remote setup-k3s-namespace help +include $(addprefix $(dir $(lastword $(MAKEFILE_LIST)))make/,setup.mk certs.mk k3s.mk helm.mk) -setup-install-pre-requisites: ## Install host tools, Docker, K3s, and Helm locally by default - bash scripts/installation_utils/install_os_tools_and_software.sh - -setup-k3s-cluster-init: ## Initialize the first K3s server on this machine - bash scripts/installation_utils/setup_kubernetes_cluster.sh k3s server --cluster-init - -setup-k3s-cluster-remote: ## Install prerequisites, initialize the first server, and join the rest over SSH - bash scripts/installation_utils/setup_k3s_cluster.sh $(NODES) - -setup-k3s-namespace: ## Create the namespace configured in env/general.env - @set -eo pipefail; \ - . ./env/general.env; \ - kubectl create namespace "$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" --dry-run=client -o yaml | \ - kubectl apply --server-side --field-manager=cogstack-namespace -f - - -setup-verify: ## Check local Docker, Docker Compose, and K3s access without sudo - bash scripts/installation_utils/verify_docker.sh - bash scripts/installation_utils/verify_k3s.sh - -setup-all: ## Install prerequisites, initialize K3s, create the namespace, and verify - $(MAKE) setup-install-pre-requisites - $(MAKE) setup-k3s-cluster-init - $(MAKE) setup-k3s-namespace - $(MAKE) setup-verify - -# ====================================================================================================================================================== - -.PHONY: certs-all certs-k3s certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-shared certs-opensearch-nodes delete-certs-all - -load_certificates_env = set -e; set -a; if [ -f ./env/certificates.env ]; then . ./env/certificates.env; fi; set +a -load_certificates_cluster_env = set -e; . ./env/general.env; export CLUSTER_DOMAIN; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" - -certs-k3s: certs-root ## Generate the CA, NGINX HTTPS certificate, and OpenSearch transport certificate - $(MAKE) certs-nginx - @$(load_certificates_cluster_env); \ - $(MAKE) certs-opensearch-shared KUBE_NAMESPACE="$$namespace" - -certs-all: certs-k3s ## Generate the K3s and Docker certificate bundles - @$(load_certificates_cluster_env); \ - $(MAKE) certs-nifi KUBE_NAMESPACE="$$namespace" - @$(load_certificates_env); \ - OPENSEARCH_DASHBOARDS_DNS_NAMES="$${OPENSEARCH_DASHBOARDS_DNS_NAMES:-localhost}" \ - bash scripts/security/create_opensearch_client_admin_certs.sh - -certs-root: ## Generate the root CA bundle - @$(load_certificates_env); \ - bash scripts/security/create_root_ca_cert.sh - -certs-nifi: ## Generate the NiFi certificate and stores with the existing CA - bash scripts/security/create_nifi_certs.sh - -certs-nginx: ## Generate the NGINX certificate with the existing CA - @$(load_certificates_env); \ - bash scripts/security/create_nginx_certs.sh - -certs-opensearch: certs-opensearch-shared ## Generate the shared OpenSearch node and admin client certificates - @$(load_certificates_env); \ - bash scripts/security/create_opensearch_client_admin_certs.sh --admin-only - -certs-opensearch-shared: - @$(load_certificates_env); \ - service=opensearch-cluster-master; \ - service_dns="$$service.$${KUBE_NAMESPACE:-search}.svc"; \ - $(MAKE) certs-opensearch-nodes NODES=opensearch-shared \ - OPENSEARCH_NODE_DNS_NAMES="$${OPENSEARCH_NODE_DNS_NAMES:-localhost,$$service,$$service_dns,$$service_dns.$${CLUSTER_DOMAIN:-cluster.local}}" - -certs-opensearch-nodes: ## Generate OpenSearch node certificates for NODES="node1 node2 ..." - @$(load_certificates_env); \ - read -r -a nodes <<< "$$NODES"; \ - bash scripts/security/create_opensearch_node_cert.sh "$${nodes[@]}" - -delete-certs-all: ## Delete generated local TLS certificates, keys, and stores - @set -e; \ - certs="$${SECURITY_DIR:-security}/certificates"; \ - if [ -L "$$certs" ]; then printf 'Certificate directory is a symlink: %s\n' "$$certs" >&2; exit 1; fi; \ - [ -d "$$certs" ] || exit 0; \ - CDPATH= cd -- "$$certs"; \ - find -P . -maxdepth 2 \( -type f -o -type l \) \ - \( -path './root/*' -o -path './nifi/*' -o -path './nginx/*' -o -path './opensearch/*' \) \ - \( -name '*.crt' -o -name '*.pem' -o -name '*.key' -o -name '*.csr' -o -name '*.p12' -o -name '*.jks' \) -delete - -# ====================================================================================================================================================== - -.PHONY: k3s-load-certs k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch - -k3s-load-certs: k3s-load-certs-all -k3s-load-certs-all: ## Load the NGINX HTTPS and OpenSearch transport TLS Secrets -k3s-load-certs-nginx: ## Load the NGINX certificate and key into nginx-tls -k3s-load-certs-opensearch: ## Load the shared node certificate into opensearch-node-tls - -k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch: - @set -eo pipefail; \ - . ./env/general.env; \ - if [ -f ./env/certificates.env ]; then . ./env/certificates.env; fi; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - certs="$${SECURITY_DIR:-security}/certificates"; \ - services=$(@:k3s-load-certs-%=%); \ - if [ "$$services" = all ]; then services="nginx opensearch"; fi; \ - manifests=(); \ - for service in $$services; do \ - case "$$service" in \ - nginx) secret=(tls nginx-tls \ - --cert="$$certs/nginx/tls.crt" --key="$$certs/nginx/tls.key");; \ - opensearch) secret=(generic opensearch-node-tls \ - --from-file="node.crt=$$certs/opensearch/opensearch-shared.crt" \ - --from-file="node.key=$$certs/opensearch/opensearch-shared.key" \ - --from-file="ca.crt=$$certs/opensearch/elastic-stack-ca.crt.pem");; \ - esac; \ - manifest=$$(kubectl -n "$$namespace" create secret "$${secret[@]}" --dry-run=client -o yaml); \ - manifests+=("$$manifest"); \ - done; \ - printf -- '---\n%s\n' "$${manifests[@]}" | \ - kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-certificates -f - - -.PHONY: k3s-load-auth-all k3s-load-auth-nifi k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards - -k3s-load-auth-all: ## Load the NiFi, Dashboards, and OpenSearch auth Secrets - $(MAKE) k3s-load-auth-nifi - $(MAKE) k3s-load-auth-opensearch-dashboards - $(MAKE) k3s-load-auth-opensearch - -# Uses env/authentication.env. Set NIFI_AUTH_FILE to choose another auth file. -k3s-load-auth-nifi: ## Load the NiFi flow encryption key and NGINX login Secret - @bash scripts/security/load_nifi_auth.sh - -# Both targets use env/authentication.env unless OPENSEARCH_AUTH_FILE is set. -k3s-load-auth-opensearch: ## Load the bootstrap policy and users before installing OpenSearch -k3s-load-auth-opensearch-dashboards: ## Load the OpenSearch Dashboards auth Secret - -k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards: - @bash scripts/security/load_opensearch_auth.sh $(@:k3s-load-auth-%=%) - -.PHONY: k3s-delete-auth-all k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards - -k3s-delete-auth-all: k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards ## Delete the NiFi, OpenSearch, and Dashboards auth Secrets -k3s-delete-auth-nifi: ## Delete the NiFi login and flow encryption key Secret -k3s-delete-auth-opensearch: ## Delete the OpenSearch security bootstrap Secret -k3s-delete-auth-opensearch-dashboards: ## Delete the OpenSearch Dashboards auth Secret - -k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards: - @set -e; \ - . ./env/general.env; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - case "$(@:k3s-delete-auth-%=%)" in \ - nifi) secret=nifi-auth;; \ - opensearch) secret=opensearch-security-bootstrap;; \ - opensearch-dashboards) secret=dashboards-auth;; \ - esac; \ - kubectl -n "$$namespace" delete secret "$$secret" --ignore-not-found - -.PHONY: k3s-load-env-all k3s-load-env-nginx k3s-load-env-opensearch - -k3s-load-env-all: k3s-load-env-nginx k3s-load-env-opensearch ## Load all runtime environment ConfigMaps -k3s-load-env-nginx: ## Load the NGINX runtime settings into the nginx-env ConfigMap -k3s-load-env-opensearch: ## Load the OpenSearch log level into the opensearch-env ConfigMap - -k3s-load-env-nginx k3s-load-env-opensearch: - @set -eo pipefail; \ - . ./env/general.env; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - service=$(@:k3s-load-env-%=%); \ - env_file="./env/$$service.env"; \ - if [[ "$$service" == opensearch || -f "$$env_file" ]]; then . "$$env_file"; fi; \ - args=(); \ - case "$$service" in \ - nginx) args+=("--from-literal=NGINX_NIFI_SERVER_NAME=$${NGINX_NIFI_SERVER_NAME:-_}");; \ - opensearch) args+=("--from-literal=OPENSEARCH_LOG_LEVEL=$${OPENSEARCH_LOG_LEVEL:-INFO}");; \ - esac; \ - kubectl -n "$$namespace" create configmap "$$service-env" "$${args[@]}" --dry-run=client -o yaml | \ - kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-env -f - - -# ====================================================================================================================================================== - -.PHONY: helm-values-all helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards - -helm-values-all: helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards ## Render all four charts' environment-based values -helm-values-nifi: ## Render NiFi values.yaml from env/nifi.env -helm-values-nginx: ## Render NGINX values.yaml from env/nifi.env and optional env/nginx.env -helm-values-opensearch: ## Render OpenSearch values.yaml from env/opensearch.env -helm-values-opensearch-dashboards: ## Render OpenSearch Dashboards values.yaml from env/opensearch-dashboards.env - -helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards: - @set -e; \ - service=$(@:helm-values-%=%); \ - env_file="./env/$$service.env"; \ - set -a; \ - if [ "$$service" = nginx ]; then \ - : "$${NGINX_DOCKER_CPU_MIN:=1}" "$${NGINX_DOCKER_CPU_MAX:=1}" "$${NGINX_DOCKER_RAM:=512M}"; \ - if [ -f "$$env_file" ] && [ -f ./env/nifi.env ]; then . ./env/nifi.env; fi; \ - [ -f "$$env_file" ] || env_file=./env/nifi.env; \ - fi; \ - . "$$env_file"; \ - set +a; \ - case "$$service" in \ - nifi) node_setting=NIFI_K3S_WHITELIST; export NIFI_K3S_ALLOWED_NODES='[]';; \ - opensearch) node_setting=OPENSEARCH_K3S_BLACKLIST; export OPENSEARCH_K3S_NODE_AFFINITY='{}';; \ - *) node_setting=;; \ - esac; \ - if [ -n "$$node_setting" ]; then \ - node_list="$${!node_setting}"; \ - IFS=$$' ,\t' read -r -a nodes <<< "$${node_list//$$'\n'/ }"; \ - if (( $${#nodes[@]} )); then \ - node_label='[a-z0-9]([a-z0-9-]*[a-z0-9])?'; \ - for node in "$${nodes[@]}"; do \ - if [[ $${#node} -gt 253 || ! "$$node" =~ ^$$node_label([.]$$node_label)*$$ ]]; then \ - printf 'Invalid Kubernetes node name in %s: %s\n' "$$node_setting" "$$node" >&2; \ - exit 1; \ - fi; \ - done; \ - if [ "$$service" = nifi ]; then \ - printf -v names '"%s",' "$${nodes[@]}"; \ - NIFI_K3S_ALLOWED_NODES="[$${names%,}]"; \ - else \ - printf -v fields '{key: metadata.name, operator: NotIn, values: ["%s"]},' "$${nodes[@]}"; \ - OPENSEARCH_K3S_NODE_AFFINITY="{requiredDuringSchedulingIgnoredDuringExecution: {nodeSelectorTerms: [{matchFields: [$${fields%,}]}]}}"; \ - fi; \ - fi; \ - fi; \ - chart="charts/$$service"; \ - template="$$chart/values.env.yaml"; \ - variables=$$(envsubst --variables "$$(cat "$$template")"); \ - for name in $$variables; do \ - value="$${!name:?Set $$name in $$env_file before rendering}"; \ - if [[ "$$name" == *_DOCKER_RAM && "$$value" =~ ^([0-9]+([.][0-9]+)?)([kmgtp])[bB]?$$ ]]; then \ - unit=$$(printf '%s' "$${BASH_REMATCH[3]}" | tr kmgtp KMGTP); \ - export "$$name=$${BASH_REMATCH[1]}$${unit}i"; \ - fi; \ - done; \ - tmp=$$(mktemp -d "$$chart/.values.XXXXXX"); \ - trap 'rm -rf -- "$$tmp"' EXIT; \ - envsubst < "$$template" > "$$tmp/values.yaml"; \ - mv -- "$$tmp/values.yaml" "$$chart/values.yaml" - -# ====================================================================================================================================================== - -.PHONY: k3s-prepare-all - -k3s-prepare-all: ## Render Helm values and load TLS, runtime, and auth resources - $(MAKE) helm-values-all - $(MAKE) k3s-load-certs-all - $(MAKE) k3s-load-env-all - $(MAKE) k3s-load-auth-all - -.PHONY: helm-install helm-install-all helm-install-nifi helm-install-nginx helm-install-nifi-stack -.PHONY: helm-install-opensearch helm-install-opensearch-dashboards helm-install-opensearch-stack k3s-bootstrap-opensearch - -# Set KUBE_NAMESPACE in deployment/env/general.env and create the namespace -# and required Secrets and ConfigMaps. Run these from the repository root. -# make -C deployment helm-install-nifi HELM_TIMEOUT=15m -# make -C deployment helm-install-nginx -# make -C deployment helm-install-nifi-stack -# Load dashboards-auth first to share its service account password with bootstrap. -# make -C deployment k3s-load-auth-opensearch-dashboards -# make -C deployment k3s-load-auth-opensearch -# make -C deployment helm-install-opensearch -# make -C deployment helm-install-opensearch-dashboards HELM_VALUES=/path/to/dashboards-values.yaml -# Set BOOTSTRAP_OPENSEARCH_SECURITY=0 to use existing auth Secrets. -# make -C deployment helm-install-opensearch-stack HELM_VALUES=/path/to/dashboards-values.yaml -# The stack target uses HELM_VALUES for Dashboards. -# HELM_VALUES accepts an absolute path, a path relative to deployment/, or - for stdin. -# HELM_TIMEOUT defaults to 10m. -helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIMEOUT - @set -e; \ - . ./env/general.env; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - chart="charts/$${CHART:?Set CHART to a directory under deployment/charts}"; \ - release="$$CHART"; \ - args=(); \ - case "$$CHART" in \ - nifi|nginx) release="cogstack-$$CHART";; \ - opensearch|opensearch-dashboards) \ - helm repo add opensearch https://opensearch-project.github.io/helm-charts/; \ - helm dependency build "$$chart";; \ - esac; \ - if [ "$$CHART" = opensearch ]; then \ - args+=(--set-file "opensearch.config.opensearch\\.yml=$$chart/config/opensearch.yml"); \ - fi; \ - if [ -n "$${HELM_VALUES:-}" ]; then args+=(-f "$$HELM_VALUES"); fi; \ - helm upgrade --install "$$release" "$$chart" -n "$$namespace" \ - --wait --timeout "$${HELM_TIMEOUT:-10m}" "$${args[@]}" - -helm-install-all: k3s-prepare-all ## Prepare and install or upgrade both application stacks - $(MAKE) helm-install-nifi-stack - $(MAKE) helm-install-opensearch-stack BOOTSTRAP_OPENSEARCH_SECURITY=0 - -helm-install-nifi: ## Install or upgrade NiFi -helm-install-nginx: k3s-load-env-nginx ## Load the NGINX environment, then install or upgrade NGINX -helm-install-opensearch: k3s-load-env-opensearch ## Load the OpenSearch environment, then install or upgrade OpenSearch -helm-install-opensearch-dashboards: ## Install or upgrade OpenSearch Dashboards - -helm-install-nifi helm-install-nginx helm-install-opensearch helm-install-opensearch-dashboards: - $(MAKE) helm-install CHART=$(@:helm-install-%=%) - -helm-install-nifi-stack: helm-install-nifi ## Load the runtime environment and install or upgrade NiFi and NGINX - $(MAKE) helm-install-nginx - -k3s-bootstrap-opensearch: k3s-load-auth-opensearch ## Alias for k3s-load-auth-opensearch - -helm-install-opensearch-stack: ## Install OpenSearch and then Dashboards - @if [ "$${BOOTSTRAP_OPENSEARCH_SECURITY:-1}" = 1 ]; then \ - $(MAKE) k3s-load-auth-opensearch-dashboards && $(MAKE) k3s-bootstrap-opensearch; \ - fi - $(MAKE) helm-install-opensearch HELM_VALUES= - $(MAKE) helm-install-opensearch-dashboards - -# ====================================================================================================================================================== - -.PHONY: helm-uninstall-nifi helm-uninstall-nginx helm-uninstall-nifi-stack -.PHONY: helm-uninstall-opensearch helm-uninstall-opensearch-dashboards helm-uninstall-opensearch-stack -.PHONY: helm-delete-opensearch-volumes - -# Reinstall in the same namespace with the same StatefulSet names to reuse the retained PVCs. -helm-uninstall-nifi: ## Uninstall NiFi and retain its PVCs -helm-uninstall-nginx: ## Uninstall NGINX -helm-uninstall-opensearch: ## Uninstall OpenSearch and retain its PVCs -helm-uninstall-opensearch-dashboards: ## Uninstall OpenSearch Dashboards - -helm-uninstall-nifi helm-uninstall-nginx helm-uninstall-opensearch helm-uninstall-opensearch-dashboards: - @set -e; \ - . ./env/general.env; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - release=$(@:helm-uninstall-%=%); \ - case "$$release" in nifi|nginx) release="cogstack-$$release";; esac; \ - helm uninstall "$$release" -n "$$namespace" --ignore-not-found \ - --cascade foreground --wait --timeout "$${HELM_TIMEOUT:-10m}" - -helm-uninstall-nifi-stack: helm-uninstall-nginx ## Uninstall NGINX, then NiFi, and retain PVCs - $(MAKE) helm-uninstall-nifi - -helm-uninstall-opensearch-stack: helm-uninstall-opensearch-dashboards ## Uninstall Dashboards, then OpenSearch, and retain PVCs - $(MAKE) helm-uninstall-opensearch - -helm-delete-opensearch-volumes: ## Delete OpenSearch data PVCs after uninstalling - @set -e; \ - . ./env/general.env; \ - namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ - kubectl -n "$$namespace" delete pvc --ignore-not-found \ - -l 'app.kubernetes.io/instance=opensearch,app.kubernetes.io/name=opensearch' - -# ====================================================================================================================================================== +.PHONY: help +# Use the first comment in each included file as its help section heading. help: ## Show deployment commands @printf '%s\n' 'Deployment commands' - @awk -F ':.*## ' 'NF == 2 && $$1 ~ /^[[:alnum:]_-]+$$/ { printf " %-30s %s\n", $$1, $$2 }' "$(lastword $(MAKEFILE_LIST))" + @awk -F ':.*## ' ' \ + FNR == 1 && /^# / { labels[++count] = substr($$0, 3); next } \ + NF == 2 && $$1 ~ /^[[:alnum:]_-]+$$/ { \ + labels[++count] = $$1; descriptions[count] = $$2; \ + if (length($$1) > width) width = length($$1); \ + } \ + END { \ + for (i = 1; i <= count; i++) { \ + if (i in descriptions) printf " %-*s %s\n", width, labels[i], descriptions[i]; \ + else printf "\n%s\n", labels[i]; \ + } \ + }' $(MAKEFILE_LIST) @printf '\n%s\n %s\n' 'Remote setup example' \ 'make setup-k3s-cluster-remote NODES="admin@server1 admin@server2 admin@server3"' diff --git a/deployment/make/certs.mk b/deployment/make/certs.mk new file mode 100644 index 00000000..39c93c18 --- /dev/null +++ b/deployment/make/certs.mk @@ -0,0 +1,87 @@ +# Certificates + +.PHONY: certs-all certs-k3s certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-shared certs-opensearch-nodes delete-certs-all + +load_certificates_env = set -e; set -a; if [ -f ./env/certificates.env ]; then . ./env/certificates.env; fi; set +a +load_certificates_cluster_env = set -e; . ./env/general.env; export CLUSTER_DOMAIN; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" + +certs-k3s: certs-root ## Generate the CA, NGINX HTTPS certificate, and OpenSearch transport certificate + $(MAKE) certs-nginx + @$(load_certificates_cluster_env); \ + $(MAKE) certs-opensearch-shared KUBE_NAMESPACE="$$namespace" + +certs-all: certs-k3s ## Generate the K3s and Docker certificate bundles + @$(load_certificates_cluster_env); \ + $(MAKE) certs-nifi KUBE_NAMESPACE="$$namespace" + @$(load_certificates_env); \ + OPENSEARCH_DASHBOARDS_DNS_NAMES="$${OPENSEARCH_DASHBOARDS_DNS_NAMES:-localhost}" \ + bash scripts/security/create_opensearch_client_admin_certs.sh + +certs-root: ## Generate the root CA bundle + @$(load_certificates_env); \ + bash scripts/security/create_root_ca_cert.sh + +certs-nifi: ## Generate the NiFi certificate and stores with the existing CA + bash scripts/security/create_nifi_certs.sh + +certs-nginx: ## Generate the NGINX certificate with the existing CA + @$(load_certificates_env); \ + bash scripts/security/create_nginx_certs.sh + +certs-opensearch: certs-opensearch-shared ## Generate the shared OpenSearch node and admin client certificates + @$(load_certificates_env); \ + bash scripts/security/create_opensearch_client_admin_certs.sh --admin-only + +certs-opensearch-shared: + @$(load_certificates_env); \ + service=opensearch-cluster-master; \ + service_dns="$$service.$${KUBE_NAMESPACE:-search}.svc"; \ + $(MAKE) certs-opensearch-nodes NODES=opensearch-shared \ + OPENSEARCH_NODE_DNS_NAMES="$${OPENSEARCH_NODE_DNS_NAMES:-localhost,$$service,$$service_dns,$$service_dns.$${CLUSTER_DOMAIN:-cluster.local}}" + +certs-opensearch-nodes: ## Generate OpenSearch node certificates for NODES="node1 node2 ..." + @$(load_certificates_env); \ + read -r -a nodes <<< "$$NODES"; \ + bash scripts/security/create_opensearch_node_cert.sh "$${nodes[@]}" + +delete-certs-all: ## Delete generated local TLS certificates, keys, and stores + @set -e; \ + certs="$${SECURITY_DIR:-security}/certificates"; \ + if [ -L "$$certs" ]; then printf 'Certificate directory is a symlink: %s\n' "$$certs" >&2; exit 1; fi; \ + [ -d "$$certs" ] || exit 0; \ + CDPATH= cd -- "$$certs"; \ + find -P . -maxdepth 2 \( -type f -o -type l \) \ + \( -path './root/*' -o -path './nifi/*' -o -path './nginx/*' -o -path './opensearch/*' \) \ + \( -name '*.crt' -o -name '*.pem' -o -name '*.key' -o -name '*.csr' -o -name '*.p12' -o -name '*.jks' \) -delete + +.PHONY: k3s-load-certs k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch + +k3s-load-certs: k3s-load-certs-all +k3s-load-certs-all: ## Load the NGINX HTTPS and OpenSearch transport TLS Secrets +k3s-load-certs-nginx: ## Load the NGINX certificate and key into nginx-tls +k3s-load-certs-opensearch: ## Load the shared node certificate into opensearch-node-tls + +k3s-load-certs-all k3s-load-certs-nginx k3s-load-certs-opensearch: + @set -eo pipefail; \ + . ./env/general.env; \ + if [ -f ./env/certificates.env ]; then . ./env/certificates.env; fi; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + certs="$${SECURITY_DIR:-security}/certificates"; \ + services=$(@:k3s-load-certs-%=%); \ + if [ "$$services" = all ]; then services="nginx opensearch"; fi; \ + manifests=(); \ + for service in $$services; do \ + case "$$service" in \ + nginx) secret=(tls nginx-tls \ + --cert="$$certs/nginx/tls.crt" --key="$$certs/nginx/tls.key");; \ + opensearch) secret=(generic opensearch-node-tls \ + --from-file="node.crt=$$certs/opensearch/opensearch-shared.crt" \ + --from-file="node.key=$$certs/opensearch/opensearch-shared.key" \ + --from-file="ca.crt=$$certs/opensearch/elastic-stack-ca.crt.pem");; \ + esac; \ + manifest=$$(kubectl -n "$$namespace" create secret "$${secret[@]}" --dry-run=client -o yaml); \ + manifests+=("$$manifest"); \ + done; \ + printf -- '---\n%s\n' "$${manifests[@]}" | \ + kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-certificates -f - diff --git a/deployment/make/helm.mk b/deployment/make/helm.mk new file mode 100644 index 00000000..74dfdd96 --- /dev/null +++ b/deployment/make/helm.mk @@ -0,0 +1,153 @@ +# Helm values and releases + +.PHONY: helm-values-all helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards + +helm-values-all: helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards ## Render all four charts' environment-based values +helm-values-nifi: ## Render NiFi values.yaml from env/nifi.env +helm-values-nginx: ## Render NGINX values.yaml from env/nifi.env and optional env/nginx.env +helm-values-opensearch: ## Render OpenSearch values.yaml from env/opensearch.env +helm-values-opensearch-dashboards: ## Render OpenSearch Dashboards values.yaml from env/opensearch-dashboards.env + +helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards: + @set -e; \ + service=$(@:helm-values-%=%); \ + env_file="./env/$$service.env"; \ + set -a; \ + if [ "$$service" = nginx ]; then \ + : "$${NGINX_DOCKER_CPU_MIN:=1}" "$${NGINX_DOCKER_CPU_MAX:=1}" "$${NGINX_DOCKER_RAM:=512M}"; \ + if [ -f "$$env_file" ] && [ -f ./env/nifi.env ]; then . ./env/nifi.env; fi; \ + [ -f "$$env_file" ] || env_file=./env/nifi.env; \ + fi; \ + . "$$env_file"; \ + set +a; \ + case "$$service" in \ + nifi) node_setting=NIFI_K3S_WHITELIST; export NIFI_K3S_ALLOWED_NODES='[]';; \ + opensearch) node_setting=OPENSEARCH_K3S_BLACKLIST; export OPENSEARCH_K3S_NODE_AFFINITY='{}';; \ + *) node_setting=;; \ + esac; \ + if [ -n "$$node_setting" ]; then \ + node_list="$${!node_setting}"; \ + IFS=$$' ,\t' read -r -a nodes <<< "$${node_list//$$'\n'/ }"; \ + if (( $${#nodes[@]} )); then \ + node_label='[a-z0-9]([a-z0-9-]*[a-z0-9])?'; \ + for node in "$${nodes[@]}"; do \ + if [[ $${#node} -gt 253 || ! "$$node" =~ ^$$node_label([.]$$node_label)*$$ ]]; then \ + printf 'Invalid Kubernetes node name in %s: %s\n' "$$node_setting" "$$node" >&2; \ + exit 1; \ + fi; \ + done; \ + if [ "$$service" = nifi ]; then \ + printf -v names '"%s",' "$${nodes[@]}"; \ + NIFI_K3S_ALLOWED_NODES="[$${names%,}]"; \ + else \ + printf -v fields '{key: metadata.name, operator: NotIn, values: ["%s"]},' "$${nodes[@]}"; \ + OPENSEARCH_K3S_NODE_AFFINITY="{requiredDuringSchedulingIgnoredDuringExecution: {nodeSelectorTerms: [{matchFields: [$${fields%,}]}]}}"; \ + fi; \ + fi; \ + fi; \ + chart="charts/$$service"; \ + template="$$chart/values.env.yaml"; \ + variables=$$(envsubst --variables "$$(cat "$$template")"); \ + for name in $$variables; do \ + value="$${!name:?Set $$name in $$env_file before rendering}"; \ + if [[ "$$name" == *_DOCKER_RAM && "$$value" =~ ^([0-9]+([.][0-9]+)?)([kmgtp])[bB]?$$ ]]; then \ + unit=$$(printf '%s' "$${BASH_REMATCH[3]}" | tr kmgtp KMGTP); \ + export "$$name=$${BASH_REMATCH[1]}$${unit}i"; \ + fi; \ + done; \ + tmp=$$(mktemp -d "$$chart/.values.XXXXXX"); \ + trap 'rm -rf -- "$$tmp"' EXIT; \ + envsubst < "$$template" > "$$tmp/values.yaml"; \ + mv -- "$$tmp/values.yaml" "$$chart/values.yaml" + +.PHONY: helm-install helm-install-all helm-install-nifi helm-install-nginx helm-install-nifi-stack +.PHONY: helm-install-opensearch helm-install-opensearch-dashboards helm-install-opensearch-stack + +# Set KUBE_NAMESPACE in deployment/env/general.env and create the namespace +# and required Secrets and ConfigMaps. Run these from the repository root. +# make -C deployment helm-install-nifi HELM_TIMEOUT=15m +# make -C deployment helm-install-nginx +# make -C deployment helm-install-nifi-stack +# Load dashboards-auth first to share its service account password with bootstrap. +# make -C deployment k3s-load-auth-opensearch-dashboards +# make -C deployment k3s-load-auth-opensearch +# make -C deployment helm-install-opensearch +# make -C deployment helm-install-opensearch-dashboards HELM_VALUES=/path/to/dashboards-values.yaml +# Set BOOTSTRAP_OPENSEARCH_SECURITY=0 to use existing auth Secrets. +# make -C deployment helm-install-opensearch-stack HELM_VALUES=/path/to/dashboards-values.yaml +# The stack target uses HELM_VALUES for Dashboards. +# HELM_VALUES accepts an absolute path, a path relative to deployment/, or - for stdin. +# HELM_TIMEOUT defaults to 10m. +helm-install: ## Install or upgrade CHART with optional HELM_VALUES and HELM_TIMEOUT + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + chart="charts/$${CHART:?Set CHART to a directory under deployment/charts}"; \ + release="$$CHART"; \ + args=(); \ + case "$$CHART" in \ + nifi|nginx) release="cogstack-$$CHART";; \ + opensearch|opensearch-dashboards) \ + helm repo add opensearch https://opensearch-project.github.io/helm-charts/; \ + helm dependency build "$$chart";; \ + esac; \ + if [ "$$CHART" = opensearch ]; then \ + args+=(--set-file "opensearch.config.opensearch\\.yml=$$chart/config/opensearch.yml"); \ + fi; \ + if [ -n "$${HELM_VALUES:-}" ]; then args+=(-f "$$HELM_VALUES"); fi; \ + helm upgrade --install "$$release" "$$chart" -n "$$namespace" \ + --wait --timeout "$${HELM_TIMEOUT:-10m}" "$${args[@]}" + +helm-install-all: k3s-prepare-all ## Prepare and install or upgrade both application stacks + $(MAKE) helm-install-nifi-stack + $(MAKE) helm-install-opensearch-stack BOOTSTRAP_OPENSEARCH_SECURITY=0 + +helm-install-nifi: ## Install or upgrade NiFi +helm-install-nginx: k3s-load-env-nginx ## Load the NGINX environment, then install or upgrade NGINX +helm-install-opensearch: k3s-load-env-opensearch ## Load the OpenSearch environment, then install or upgrade OpenSearch +helm-install-opensearch-dashboards: ## Install or upgrade OpenSearch Dashboards + +helm-install-nifi helm-install-nginx helm-install-opensearch helm-install-opensearch-dashboards: + $(MAKE) helm-install CHART=$(@:helm-install-%=%) + +helm-install-nifi-stack: helm-install-nifi ## Load the runtime environment and install or upgrade NiFi and NGINX + $(MAKE) helm-install-nginx + +helm-install-opensearch-stack: ## Install OpenSearch and then Dashboards + @if [ "$${BOOTSTRAP_OPENSEARCH_SECURITY:-1}" = 1 ]; then \ + $(MAKE) k3s-load-auth-opensearch-dashboards && $(MAKE) k3s-bootstrap-opensearch; \ + fi + $(MAKE) helm-install-opensearch HELM_VALUES= + $(MAKE) helm-install-opensearch-dashboards + +.PHONY: helm-uninstall-nifi helm-uninstall-nginx helm-uninstall-nifi-stack +.PHONY: helm-uninstall-opensearch helm-uninstall-opensearch-dashboards helm-uninstall-opensearch-stack +.PHONY: helm-delete-opensearch-volumes + +# Reinstall in the same namespace with the same StatefulSet names to reuse the retained PVCs. +helm-uninstall-nifi: ## Uninstall NiFi and retain its PVCs +helm-uninstall-nginx: ## Uninstall NGINX +helm-uninstall-opensearch: ## Uninstall OpenSearch and retain its PVCs +helm-uninstall-opensearch-dashboards: ## Uninstall OpenSearch Dashboards + +helm-uninstall-nifi helm-uninstall-nginx helm-uninstall-opensearch helm-uninstall-opensearch-dashboards: + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + release=$(@:helm-uninstall-%=%); \ + case "$$release" in nifi|nginx) release="cogstack-$$release";; esac; \ + helm uninstall "$$release" -n "$$namespace" --ignore-not-found \ + --cascade foreground --wait --timeout "$${HELM_TIMEOUT:-10m}" + +helm-uninstall-nifi-stack: helm-uninstall-nginx ## Uninstall NGINX, then NiFi, and retain PVCs + $(MAKE) helm-uninstall-nifi + +helm-uninstall-opensearch-stack: helm-uninstall-opensearch-dashboards ## Uninstall Dashboards, then OpenSearch, and retain PVCs + $(MAKE) helm-uninstall-opensearch + +helm-delete-opensearch-volumes: ## Delete OpenSearch data PVCs after uninstalling + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + kubectl -n "$$namespace" delete pvc --ignore-not-found \ + -l 'app.kubernetes.io/instance=opensearch,app.kubernetes.io/name=opensearch' diff --git a/deployment/make/k3s.mk b/deployment/make/k3s.mk new file mode 100644 index 00000000..fa773e89 --- /dev/null +++ b/deployment/make/k3s.mk @@ -0,0 +1,68 @@ +# Kubernetes configuration + +.PHONY: k3s-load-auth-all k3s-load-auth-nifi k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards + +k3s-load-auth-all: ## Load the NiFi, Dashboards, and OpenSearch auth Secrets + $(MAKE) k3s-load-auth-nifi + $(MAKE) k3s-load-auth-opensearch-dashboards + $(MAKE) k3s-load-auth-opensearch + +# Uses env/authentication.env. Set NIFI_AUTH_FILE to choose another auth file. +k3s-load-auth-nifi: ## Load the NiFi flow encryption key and NGINX login Secret + @bash scripts/security/load_nifi_auth.sh + +# Both targets use env/authentication.env unless OPENSEARCH_AUTH_FILE is set. +k3s-load-auth-opensearch: ## Load the bootstrap policy and users before installing OpenSearch +k3s-load-auth-opensearch-dashboards: ## Load the OpenSearch Dashboards auth Secret + +k3s-load-auth-opensearch k3s-load-auth-opensearch-dashboards: + @bash scripts/security/load_opensearch_auth.sh $(@:k3s-load-auth-%=%) + +.PHONY: k3s-delete-auth-all k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards + +k3s-delete-auth-all: k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards ## Delete the NiFi, OpenSearch, and Dashboards auth Secrets +k3s-delete-auth-nifi: ## Delete the NiFi login and flow encryption key Secret +k3s-delete-auth-opensearch: ## Delete the OpenSearch security bootstrap Secret +k3s-delete-auth-opensearch-dashboards: ## Delete the OpenSearch Dashboards auth Secret + +k3s-delete-auth-nifi k3s-delete-auth-opensearch k3s-delete-auth-opensearch-dashboards: + @set -e; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + case "$(@:k3s-delete-auth-%=%)" in \ + nifi) secret=nifi-auth;; \ + opensearch) secret=opensearch-security-bootstrap;; \ + opensearch-dashboards) secret=dashboards-auth;; \ + esac; \ + kubectl -n "$$namespace" delete secret "$$secret" --ignore-not-found + +.PHONY: k3s-load-env-all k3s-load-env-nginx k3s-load-env-opensearch + +k3s-load-env-all: k3s-load-env-nginx k3s-load-env-opensearch ## Load all runtime environment ConfigMaps +k3s-load-env-nginx: ## Load the NGINX runtime settings into the nginx-env ConfigMap +k3s-load-env-opensearch: ## Load the OpenSearch log level into the opensearch-env ConfigMap + +k3s-load-env-nginx k3s-load-env-opensearch: + @set -eo pipefail; \ + . ./env/general.env; \ + namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}"; \ + service=$(@:k3s-load-env-%=%); \ + env_file="./env/$$service.env"; \ + if [[ "$$service" == opensearch || -f "$$env_file" ]]; then . "$$env_file"; fi; \ + args=(); \ + case "$$service" in \ + nginx) args+=("--from-literal=NGINX_NIFI_SERVER_NAME=$${NGINX_NIFI_SERVER_NAME:-_}");; \ + opensearch) args+=("--from-literal=OPENSEARCH_LOG_LEVEL=$${OPENSEARCH_LOG_LEVEL:-INFO}");; \ + esac; \ + kubectl -n "$$namespace" create configmap "$$service-env" "$${args[@]}" --dry-run=client -o yaml | \ + kubectl -n "$$namespace" apply --server-side --field-manager=cogstack-env -f - + +.PHONY: k3s-bootstrap-opensearch k3s-prepare-all + +k3s-bootstrap-opensearch: k3s-load-auth-opensearch ## Alias for k3s-load-auth-opensearch + +k3s-prepare-all: ## Render Helm values and load TLS, runtime, and auth resources + $(MAKE) helm-values-all + $(MAKE) k3s-load-certs-all + $(MAKE) k3s-load-env-all + $(MAKE) k3s-load-auth-all diff --git a/deployment/make/setup.mk b/deployment/make/setup.mk new file mode 100644 index 00000000..778deb87 --- /dev/null +++ b/deployment/make/setup.mk @@ -0,0 +1,28 @@ +# Cluster setup + +.PHONY: setup-all setup-install-pre-requisites setup-k3s-cluster-init setup-verify setup-k3s-cluster-remote setup-k3s-namespace + +setup-install-pre-requisites: ## Install host tools, Docker, K3s, and Helm locally by default + bash scripts/installation_utils/install_os_tools_and_software.sh + +setup-k3s-cluster-init: ## Initialize the first K3s server on this machine + bash scripts/installation_utils/setup_kubernetes_cluster.sh k3s server --cluster-init + +setup-k3s-cluster-remote: ## Install prerequisites, initialize the first server, and join the rest over SSH + bash scripts/installation_utils/setup_k3s_cluster.sh $(NODES) + +setup-k3s-namespace: ## Create the namespace configured in env/general.env + @set -eo pipefail; \ + . ./env/general.env; \ + kubectl create namespace "$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" --dry-run=client -o yaml | \ + kubectl apply --server-side --field-manager=cogstack-namespace -f - + +setup-verify: ## Check local Docker, Docker Compose, and K3s access without sudo + bash scripts/installation_utils/verify_docker.sh + bash scripts/installation_utils/verify_k3s.sh + +setup-all: ## Install prerequisites, initialize K3s, create the namespace, and verify + $(MAKE) setup-install-pre-requisites + $(MAKE) setup-k3s-cluster-init + $(MAKE) setup-k3s-namespace + $(MAKE) setup-verify