diff --git a/.github/workflows/helm_smoke_logins.yml b/.github/workflows/helm_smoke_logins.yml index f443cad4..8d3c7e02 100644 --- a/.github/workflows/helm_smoke_logins.yml +++ b/.github/workflows/helm_smoke_logins.yml @@ -16,6 +16,7 @@ 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 @@ -95,7 +96,7 @@ jobs: type: ClusterIP YAML - - name: NGINX Helm proxy login + - name: NiFi login through NGINX if: matrix.stack == 'nifi' || matrix.stack == 'nginx' run: | kubectl port-forward svc/cogstack-nginx 8443:443 & @@ -104,8 +105,8 @@ jobs: --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' + SINGLE_USER_CREDENTIALS_PASSWORD="$SMOKE_PASSWORD" \ + bash .github/scripts/smoke_nifi_login.sh https://127.0.0.1:8443 - name: OpenSearch and Dashboards through NGINX if: matrix.stack == 'opensearch' diff --git a/apps/nifi/Dockerfile b/apps/nifi/Dockerfile index aa70e156..80749f56 100644 --- a/apps/nifi/Dockerfile +++ b/apps/nifi/Dockerfile @@ -1,11 +1,12 @@ # syntax=docker/dockerfile:1 -ARG NIFI_BASE_IMAGE=apache/nifi:2.12.0@sha256:6f7f2840dbf178c6dd3fa13435b9b358f3be3c6fb7417de467a35a267f4d28ad +ARG NIFI_BASE_IMAGE=apache/nifi:2.13.0@sha256:bc4f695c6ae29c51b68062a16463fb4f6c93ccac8609e774d5097af0be034672 FROM ${NIFI_BASE_IMAGE} SHELL ["/bin/bash", "-o", "pipefail", "-c"] -ARG NIFI_VERSION=2.12.0 +# Match the downloaded NARs to the Apache NiFi version in NIFI_BASE_IMAGE. +ARG NIFI_VERSION=2.13.0 ARG GROOVY_VERSION=5.1.0 ARG HTTP_PROXY="" @@ -16,6 +17,7 @@ ARG DEBIAN_FRONTEND=noninteractive ARG TZ="Europe/London" ENV TZ=${TZ} +# Make the bundled Python dependencies and CogStack modules available to processors. ENV PYTHONPATH=${NIFI_HOME}/python/framework # python stuff @@ -25,6 +27,7 @@ ENV PIP_NO_CACHE_DIR=1 # Turns off buffering for easier container logging ENV PYTHONUNBUFFERED=1 + USER root # Install system dependencies using the repositories provided by the base image. @@ -39,11 +42,11 @@ RUN set -eux; \ git \ iputils-ping \ jq \ + libpq-dev \ libsqlite3-dev \ libssl-dev \ make \ openssl \ - postgresql-server-dev-all \ python3.11 \ python3.11-dev \ python3-dev \ @@ -58,17 +61,10 @@ RUN set -eux; \ apt-get clean; \ rm -rf /var/lib/apt/lists/* -# install rust, medcat requirement, install UV +# Install uv as root. ENV HOME=/root -ENV PATH="/root/.cargo/bin:${PATH}" ENV UV_INSTALL_DIR=/usr/local/bin -RUN set -eux; \ - curl -sSf https://sh.rustup.rs -o /tmp/rustup-init.sh; \ - chmod +x /tmp/rustup-init.sh; \ - /tmp/rustup-init.sh -y; \ - rm /tmp/rustup-init.sh - # Install the exact or minimum uv version required by the repository. COPY pyproject.toml /tmp/cogstack_nifi/pyproject.toml RUN set -eux; \ @@ -82,9 +78,17 @@ RUN set -eux; \ RUN uv pip install --no-cache-dir --break-system-packages --system --upgrade pip setuptools wheel -# Install the locked runtime dependencies used by NiFi scripts and extensions. +# Install locked runtime dependencies before copying CogStack sources so code +# changes can reuse the dependency layer. +# Keep Rust available for source builds and remove it in the same layer. COPY uv.lock /tmp/cogstack_nifi/uv.lock -RUN uv export \ +RUN set -eux; \ + rust_toolchain="$(mktemp -d)"; \ + export CARGO_HOME="$rust_toolchain/cargo" RUSTUP_HOME="$rust_toolchain/rustup"; \ + export PATH="$CARGO_HOME/bin:$PATH"; \ + curl -fsSL https://sh.rustup.rs -o "$rust_toolchain/install.sh"; \ + sh "$rust_toolchain/install.sh" -y --profile minimal --no-modify-path; \ + uv export \ --project /tmp/cogstack_nifi \ --frozen \ --no-dev \ @@ -96,7 +100,8 @@ RUN uv export \ --break-system-packages \ --target=${NIFI_HOME}/python/framework \ -r /tmp/cogstack_nifi/requirements.txt \ - --index-url https://pypi.org/simple + --index-url https://pypi.org/simple \ + && rm -rf "$rust_toolchain" ####################################################################################################### @@ -108,8 +113,8 @@ ENV JAVA_OPTS="-Dhttp.proxyHost=${HTTP_PROXY} -Dhttps.proxyHost=${HTTPS_PROXY} - WORKDIR /opt/nifi/groovy RUN set -eux; \ - url1="https://archive.apache.org/dist/groovy/${GROOVY_VERSION}/distribution/apache-groovy-binary-${GROOVY_VERSION}.zip"; \ - url2="https://repo.maven.apache.org/maven2/org/apache/groovy/apache-groovy-binary/${GROOVY_VERSION}/apache-groovy-binary-${GROOVY_VERSION}.zip"; \ + url1="https://repo.maven.apache.org/maven2/org/apache/groovy/groovy-binary/${GROOVY_VERSION}/groovy-binary-${GROOVY_VERSION}.zip"; \ + url2="https://archive.apache.org/dist/groovy/${GROOVY_VERSION}/distribution/apache-groovy-binary-${GROOVY_VERSION}.zip"; \ curl -fsSL --retry 8 --retry-delay 3 --connect-timeout 20 -o groovy.zip "$url1" \ || curl -fsSL --retry 8 --retry-delay 3 --connect-timeout 20 -o groovy.zip "$url2"; \ unzip groovy.zip; rm groovy.zip @@ -159,17 +164,14 @@ RUN set -eu; \ ######################################################################################################## -# Baseline resources work without a repository checkout. Processor directories -# can still be overridden by writable, deployment-owned volumes. -COPY __init__.py /tmp/cogstack_nifi/__init__.py -COPY user_scripts /tmp/cogstack_nifi/user_scripts -COPY user_python_extensions /tmp/cogstack_nifi/user_python_extensions -RUN uv pip install --no-cache-dir --break-system-packages --no-deps \ - --target=${NIFI_HOME}/python/framework /tmp/cogstack_nifi - ARG NIFI_UID=1000 ARG NIFI_GID=1000 +# Establish the nifi Python package on the framework's import path. +COPY --chown=${NIFI_UID}:${NIFI_GID} __init__.py ${NIFI_HOME}/python/framework/nifi/__init__.py + +# Use the resource paths referenced by flows. NiFi discovers native Python +# processors in its python_extensions directory. COPY --chown=${NIFI_UID}:${NIFI_GID} drivers /opt/nifi/drivers COPY --chown=${NIFI_UID}:${NIFI_GID} user_schemas /opt/nifi/user_schemas COPY --chown=${NIFI_UID}:${NIFI_GID} user_templates /opt/nifi/user_templates @@ -177,16 +179,23 @@ COPY --chown=${NIFI_UID}:${NIFI_GID} user_scripts /opt/nifi/user_scripts COPY --chown=${NIFI_UID}:${NIFI_GID} user_python_extensions /opt/nifi/nifi-current/python_extensions COPY --chmod=755 docker/healthcheck.sh /opt/nifi/scripts/cogstack-healthcheck.sh -# Keep Apache's configuration defaults and startup script. Deployment credentials -# and mutable configuration from the checkout never enter the image. +# Tune Apache's default configuration to reload TLS stores and give active +# processors time to stop. Supply deployment credentials and configuration at runtime. RUN sed -i \ -e 's|^nifi.security.autoreload.enabled=.*|nifi.security.autoreload.enabled=true|' \ -e 's|^nifi.flowcontroller.graceful.shutdown.period=.*|nifi.flowcontroller.graceful.shutdown.period=30 sec|' \ "${NIFI_HOME}/conf/nifi.properties" \ - && sed -i 's|^graceful.shutdown.seconds=.*|graceful.shutdown.seconds=60|' "${NIFI_HOME}/conf/bootstrap.conf" \ - && cp -a "${NIFI_HOME}/conf" /tmp/cogstack_nifi/conf + && sed -i 's|^graceful.shutdown.seconds=.*|graceful.shutdown.seconds=60|' "${NIFI_HOME}/conf/bootstrap.conf" + -# Apache ships owner-only executables; remap them only for custom UID builds. +# We keep a copy of the image conf folder because we use it later in Helm to copy contents directly to the PVC +# rather than doing the weird trick where we create a init container to copy contents, no more initContainer needed :) +RUN cp -a "${NIFI_HOME}/conf" /tmp/cogstack_nifi/conf && chown -R "${NIFI_UID}:${NIFI_GID}" /tmp/cogstack_nifi/conf + +# Remap Apache's NiFi account for custom UID/GID builds. The owner-only +# executables must follow the account when its UID changes. +# Point nifi.user_scripts at /opt/nifi/user_scripts so imports use the same +# files as the Compose development bind mount. RUN set -eux; \ if [ "$(id -g nifi)" != "${NIFI_GID}" ]; then groupmod -o -g "${NIFI_GID}" nifi; fi; \ if [ "$(id -u nifi)" != "${NIFI_UID}" ]; then \ @@ -196,15 +205,15 @@ RUN set -eux; \ mkdir -p "${NIFI_HOME}/run" "${NIFI_HOME}/work/python" \ "${NIFI_HOME}/logs/user_scripts" "${NIFI_HOME}/state/user_scripts/db" \ /opt/nifi/pipeline/flowfile-errors /data /opt/models; \ - rm -rf "${NIFI_HOME}/python/framework/nifi/user_scripts"; \ - ln -s /opt/nifi/user_scripts "${NIFI_HOME}/python/framework/nifi/user_scripts"; \ - ln -s /opt/nifi/drivers /tmp/cogstack_nifi/drivers; \ - ln -s /opt/nifi/user_schemas /tmp/cogstack_nifi/user_schemas; \ - ln -s /opt/nifi/user_templates /tmp/cogstack_nifi/user_templates; \ + ln -sT /opt/nifi/user_scripts "${NIFI_HOME}/python/framework/nifi/user_scripts"; \ chown -R "${NIFI_UID}:${NIFI_GID}" \ "${NIFI_HOME}"/{conf,logs,run,work,database_repository,flowfile_repository,content_repository,provenance_repository,state,nar_extensions,python_extensions} \ /home/nifi /opt/nifi/pipeline/flowfile-errors /data /opt/models +COPY --chmod=755 docker/entrypoint.sh /opt/nifi/scripts/cogstack-entrypoint.sh + + +ENV COGSTACK_NIFI_MODE=docker ENV HOME=/home/nifi ENV NIFI_WEB_HTTPS_HOST="0.0.0.0" ENV PATH=/usr/local/bin:${JAVA_HOME}/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin @@ -212,7 +221,11 @@ ENV UV_CACHE_DIR=/opt/nifi/nifi-current/work/python/uv-cache ENV PYTHONPYCACHEPREFIX=/opt/nifi/nifi-current/work/python/pycache ENV NIFI_USER_SCRIPT_LOGS_DIR=/opt/nifi/nifi-current/logs/user_scripts ENV NIFI_USER_SCRIPT_DB_DIR=/opt/nifi/nifi-current/state/user_scripts/db + WORKDIR /opt/nifi/nifi-current USER ${NIFI_UID}:${NIFI_GID} + HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=3 \ CMD ["/opt/nifi/scripts/cogstack-healthcheck.sh", "ready"] + +ENTRYPOINT ["/opt/nifi/scripts/cogstack-entrypoint.sh"] diff --git a/apps/nifi/README.md b/apps/nifi/README.md index 89d33caa..fb7fb251 100644 --- a/apps/nifi/README.md +++ b/apps/nifi/README.md @@ -42,8 +42,8 @@ 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) +[Apache's startup script](https://github.com/apache/nifi/blob/rel/nifi-2.13.0/nifi-docker/dockerhub/sh/start.sh) +and [Docker setup guide](https://github.com/apache/nifi/blob/rel/nifi-2.13.0/nifi-docker/dockerhub/README.md) for additional settings. ### TLS certificates @@ -88,10 +88,10 @@ 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` | 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`. | +| `make start` | Use `docker-compose.yml` to start published images with a Compose-managed `cogstack-net`. | +| `make start-dev` | Start NiFi and NGINX with the dev settings. | +| `make start-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-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 @@ -122,11 +122,13 @@ host data. 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. +`make stop-dev`, `make stop-prod`, or `docker compose stop` for the +default stack after sourcing the env files. `make delete-dev` removes the +**dev** containers and preserves their volumes. `make delete-all` stops and +removes the NiFi and NGINX containers across the default, dev, and prod stacks. +`make delete-dev-volumes` also deletes the dev volumes, including saved flows +and queued data. Back up FlowFile and content repositories together when +preserving queues. ## Build the image diff --git a/apps/nifi/docker/Makefile b/apps/nifi/docker/Makefile index b347f961..ed566842 100644 --- a/apps/nifi/docker/Makefile +++ b/apps/nifi/docker/Makefile @@ -1,13 +1,16 @@ SHELL := /usr/bin/env bash .SHELLFLAGS := -o pipefail -c +.DEFAULT_GOAL := help DC_START_CMD := up -d DC_STOP_CMD := stop +DC_DELETE_CMD := rm --force --stop +COMPOSE_BASE := docker-compose.base.yml 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 + -f $(COMPOSE_BASE) -f docker-compose.dev.yml +COMPOSE_PROD := docker compose -f $(COMPOSE_BASE) -f docker-compose.prod.yml define WITH_ENV source ./export_env_vars.sh || exit $$?; @@ -24,38 +27,26 @@ endef WITH_START = $(WITH_ENV) $(CHECK_TLS_FILES) -help: ## List available targets with descriptions - @echo "Available targets:" - @awk '\ - function default_desc(target) { \ - 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 == "load-env") return "Load variables from export_env_vars.sh"; \ - if (target == "show-env") return "Print current environment variables"; \ - return "(no description)"; \ - } \ - /^[a-zA-Z0-9][a-zA-Z0-9_-]*:/ { \ - raw=$$0; \ - target=raw; \ - sub(/:.*/, "", target); \ - if (!(target in seen)) { \ - seen[target]=1; \ - } \ - if (index(raw, "##") > 0) { \ - description=raw; \ - sub(/^.*##[[:space:]]*/, "", description); \ - desc[target]=description; \ - } \ - } \ - END { \ - for (target in seen) { \ - description=desc[target]; \ - if (description == "") description=default_desc(target); \ - print target "\t" description; \ +.PHONY: help load-env show-env check-config check-tls build-image \ + start start-dev start-dev-build start-prod stop-dev stop-prod \ + delete-dev delete-all delete-dev-volumes delete-dev-images + +# Utilities + +help: ## List available targets and their descriptions + @printf '%s\n' 'NiFi Docker commands' + @awk -F ':.*## ' ' \ + /^# / { labels[++count] = substr($$0, 3); next } \ + NF == 2 && $$1 ~ /^[[:alnum:]_-]+$$/ { \ + labels[++count] = $$1; descriptions[count] = $$2; \ + if (length($$1) > width) width = length($$1); \ } \ - } \ - ' $(MAKEFILE_LIST) | sort | awk -F '\t' '{printf " %-28s %s\n", $$1, $$2}' + 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) load-env: ## Load variables from export_env_vars.sh in a subshell $(WITH_ENV) echo "Environment variables loaded." @@ -69,21 +60,9 @@ check-config: ## Validate the default, dev and prod Compose configurations check-tls: ## Check the TLS files required by NiFi and NGINX @$(WITH_ENV) $(CHECK_TLS_FILES) -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_START) $(COMPOSE_DEV) $(DC_START_CMD) nifi nifi-nginx - -start-nifi-dev-build: ## Build and start NiFi dev services - $(WITH_START) $(COMPOSE_DEV) up -d --build nifi nifi-nginx - -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 +build-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_VERSION="$${NIFI_VERSION:-2.13.0}" \ --build-arg NIFI_BASE_IMAGE \ --build-arg NIFI_UID="$${COGSTACK_LOCAL_UID:-1000}" \ --build-arg NIFI_GID="$${COGSTACK_LOCAL_GID:-1000}" \ @@ -91,28 +70,46 @@ build-nifi-image: ## Build the local NiFi image without starting services --file ../Dockerfile \ .. -stop-nifi-dev: ## Stop the NiFi dev services +# Start services + +start: ## Start the default NiFi and NGINX stack + $(WITH_START) docker compose $(DC_START_CMD) + +start-dev: ## Start NiFi and NGINX with local builds + $(WITH_START) $(COMPOSE_DEV) $(DC_START_CMD) nifi nifi-nginx + +start-dev-build: ## Build and start the development stack + $(WITH_START) $(COMPOSE_DEV) $(DC_START_CMD) --build nifi nifi-nginx + +start-prod: ## Start the published NiFi and NGINX images on cogstack-net + $(WITH_START) $(COMPOSE_PROD) $(DC_START_CMD) + +# Stop services + +stop-dev: ## Stop the NiFi dev services $(WITH_ENV) $(COMPOSE_DEV) $(DC_STOP_CMD) nifi nifi-nginx -stop-nifi-prod: ## Stop the NiFi prod services +stop-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 local resources -delete-nifi-dev-containers: ## Remove the NiFi dev containers - $(WITH_ENV) $(COMPOSE_DEV) rm -f -s nifi nifi-nginx +delete-dev: ## Stop and remove the development containers + $(WITH_ENV) $(COMPOSE_DEV) $(DC_DELETE_CMD) nifi nifi-nginx -delete-nifi-dev-volumes: delete-nifi-dev-containers ## Remove the NiFi and NGINX containers and delete NiFi dev volume data +delete-all: delete-dev ## Stop and remove all local NiFi and NGINX containers + $(WITH_ENV) docker compose $(DC_DELETE_CMD) nifi nifi-nginx + $(WITH_ENV) $(COMPOSE_PROD) $(DC_DELETE_CMD) nifi nifi-nginx + +delete-dev-volumes: delete-dev ## Remove development containers and delete their volume data @$(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 the NiFi dev images +delete-dev-images: ## Delete the development 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 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 diff --git a/apps/nifi/docker/docker-compose.base.yml b/apps/nifi/docker/docker-compose.base.yml index f1f1890c..3af2e2e1 100644 --- a/apps/nifi/docker/docker-compose.base.yml +++ b/apps/nifi/docker/docker-compose.base.yml @@ -1,113 +1,43 @@ -#---------------------------------------------------------------------------# -# 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:-/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} - 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:-${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_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 - -x-mounts: - nifi: &nifi-volumes - # Security certificates - - ${SECURITY_DIR:-../../../deployment/security}/certificates/nifi:/security/certificates/nifi:ro - - type: bind - source: ${SECURITY_DIR:-../../../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 - - # 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 - - nifi-nginx-tmpfs: &nifi-nginx-tmpfs - - /tmp:mode=1777 - - nifi-nginx: &nifi-nginx-volumes - - ${SECURITY_DIR:-../../../deployment/security}/certificates/nginx:/certificates/nginx:ro - - type: bind - source: ${SECURITY_DIR:-../../../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 - - 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 + restart: unless-stopped shm_size: ${NIFI_DOCKER_SHM_SIZE:-1g} - environment: *nifi-env + env_file: + - "${COGSTACK_GENERAL_ENV_FILE:-../env/general.env}" + - "${COGSTACK_NIFI_ENV_FILE:-../env/nifi.env}" + environment: + # 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:-/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} + JVM_OPTS: ${NIFI_JVM_OPTS:--XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+ParallelRefProcEnabled -Djava.security.egd=file:/dev/./urandom} + ulimits: + nofile: + soft: 65535 + hard: 65535 + nproc: 65535 + memlock: + soft: -1 + hard: -1 deploy: resources: limits: @@ -116,8 +46,26 @@ services: reservations: cpus: "${NIFI_DOCKER_CPU_MIN}" memory: "${NIFI_DOCKER_RAM}" - volumes: *nifi-volumes - + volumes: + - ${SECURITY_DIR:-../../../deployment/security}/certificates/nifi:/security/certificates/nifi:ro + - &root-ca + type: bind + source: ${SECURITY_DIR:-../../../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 + + # 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 + networks: [cognet] stop_grace_period: 120s logging: *nifi-logging-common @@ -125,10 +73,19 @@ services: image: ${NIFI_NGINX_IMAGE:-cogstacksystems/nginx:latest} restart: always shm_size: ${NGINX_SHM_SIZE:-512mb} - environment: *nifi-nginx-env + environment: + NIFI_INTERNAL_PORT_NGINX: ${NIFI_INTERNAL_PORT_NGINX:-8443} + NIFI_WEB_PROXY_PORT: ${NIFI_WEB_PROXY_PORT:-${NIFI_INTERNAL_PORT_NGINX:-8443}} + NIFI_INTERNAL_PORT: ${NIFI_INTERNAL_PORT:-8443} + NIFI_UPSTREAM_HOST: ${NIFI_UPSTREAM_HOST:-nifi} + 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 stop_grace_period: 90s read_only: true - tmpfs: *nifi-nginx-tmpfs + tmpfs: + - /tmp:mode=1777 deploy: resources: limits: @@ -137,18 +94,17 @@ services: reservations: cpus: "${NGINX_DOCKER_CPU_MIN:-1}" memory: "${NGINX_DOCKER_RAM:-1g}" - volumes: *nifi-nginx-volumes + volumes: + - ${SECURITY_DIR:-../../../deployment/security}/certificates/nginx:/certificates/nginx:ro + - <<: *root-ca + target: /certificates/root/root-ca.pem ports: - - "${NIFI_EXTERNAL_PORT_NGINX:-8443}:${NIFI_INTERNAL_PORT_NGINX:-8443}" - networks: *cognet + - "${NIFI_INTERNAL_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-conf: {} nifi-vol-logs: driver: local @@ -167,9 +123,6 @@ volumes: nifi-vol-state: 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 23159786..47b8b777 100644 --- a/apps/nifi/docker/docker-compose.dev.yml +++ b/apps/nifi/docker/docker-compose.dev.yml @@ -7,7 +7,7 @@ services: context: .. dockerfile: Dockerfile args: - NIFI_VERSION: ${NIFI_VERSION:-2.12.0} + NIFI_VERSION: ${NIFI_VERSION:-2.13.0} NIFI_BASE_IMAGE: # Use the Dockerfile default when unset. NIFI_UID: ${COGSTACK_LOCAL_UID:-1000} NIFI_GID: ${COGSTACK_LOCAL_GID:-1000} diff --git a/apps/nifi/docker/entrypoint.sh b/apps/nifi/docker/entrypoint.sh new file mode 100644 index 00000000..142a333d --- /dev/null +++ b/apps/nifi/docker/entrypoint.sh @@ -0,0 +1,66 @@ +#!/bin/sh +set -eu + +fail() { + printf 'NiFi startup: %s\n' "$*" >&2 + exit 1 +} + +validate_configuration() { + for name in nifi.properties bootstrap.conf state-management.xml authorizers.xml login-identity-providers.xml logback.xml; do + file=$1/$name + if [ ! -f "$file" ] || [ ! -s "$file" ] || [ ! -r "$file" ]; then + fail "Missing, empty or unreadable configuration file $file." + fi + if [ "$2" = writable ] && [ ! -w "$file" ]; then + fail "Configuration file $file must be writable by the NiFi user." + fi + done +} + +initialize_configuration() { + conf="${NIFI_HOME:?NIFI_HOME must be set}/conf" + defaults=/tmp/cogstack_nifi/conf + incomplete="$conf/.nifi-bootstrap-incomplete" + complete="$conf/.nifi-bootstrap-complete" + + mountpoint -q -- "$conf" || fail "Kubernetes mode requires a configuration PVC mounted at $conf." + if [ ! -r "$conf" ] || [ ! -w "$conf" ] || [ ! -x "$conf" ]; then + fail "Configuration PVC $conf must be accessible and writable by the NiFi user." + fi + if [ -e "$incomplete" ] || [ -L "$incomplete" ]; then + fail "Interrupted configuration initialization. Restore or verify the PVC before starting NiFi." + fi + if [ -f "$complete" ] && [ ! -L "$complete" ]; then + validate_configuration "$conf" writable + return + fi + + contents=$(find "$conf" -mindepth 1 -maxdepth 1 ! \( -type d -name lost+found \) -print -quit) + if [ -n "$contents" ]; then + fail "Unverified nonempty configuration PVC. Verify or restore it before creating .nifi-bootstrap-complete." + fi + validate_configuration "$defaults" readable + + # Reserve initialization and leave the marker in place if copying fails. + (set -C; : > "$incomplete") || fail "Could not mark configuration initialization at $conf." + if [ -e "$complete" ] || [ -L "$complete" ]; then + rm -- "$incomplete" + fail "Another process initialized the configuration PVC. Retry startup." + fi + sync -f "$conf" + find "$defaults" -mindepth 1 -maxdepth 1 \ + -exec cp -R --preserve=mode,timestamps -t "$conf" -- {} + + validate_configuration "$conf" writable + sync -f "$conf" + mv -- "$incomplete" "$complete" + sync -f "$conf" +} + +case "${COGSTACK_NIFI_MODE:-docker}" in + docker) ;; + kubernetes) initialize_configuration ;; + *) fail "Unsupported COGSTACK_NIFI_MODE '$COGSTACK_NIFI_MODE'." ;; +esac + +exec /opt/nifi/scripts/start.sh "$@" diff --git a/apps/nifi/env/nifi.env b/apps/nifi/env/nifi.env new file mode 100644 index 00000000..aaeaf5d9 --- /dev/null +++ b/apps/nifi/env/nifi.env @@ -0,0 +1,147 @@ + + +############################################################################################################################## +# IMPORTANT SETTINGS FOR DEPLOYMENTS RESOURCE SCOPED +############################################################################################################################## +NIFI_JVM_OPTS="-XX:+UseG1GC -XX:MaxGCPauseMillis=250 -XX:+ParallelRefProcEnabled -Xlog:gc*:file=/opt/nifi/nifi-current/logs/gc.log:time,uptime,level,tags:filecount=5,filesize=50m -Djava.security.egd=file:/dev/./urandom" +NIFI_JVM_HEAP_INIT=768M +NIFI_JVM_HEAP_MAX=1G + + +NIFI_DOCKER_SHM_SIZE=512M + +NIFI_DOCKER_CPU_MIN=1 +NIFI_DOCKER_CPU_MAX=1 +# Allow memory beyond the Java heap for native allocations and Python processors. +NIFI_DOCKER_RAM=2G + +NIFI_DOCKER_LOG_SIZE_PER_FILE="250M" +NIFI_DOCKER_LOG_NUM_FILES=10 + +############################################################################################################################## + +# NiFi base image and extension version used by local image builds. +NIFI_VERSION="2.13.0" + +# Published NiFi 2.12.0 image, pinned to its multi-platform registry manifest. +NIFI_DOCKER_IMAGE="cogstacksystems/cogstack-nifi@sha256:f3f0ce9c23f9e503042f646675ddef372acda5cffc2491f07a38996a95a948dd" + +# Published nginx proxy image, pinned to its multi-platform registry manifest. +NIFI_NGINX_DOCKER_IMAGE=cogstacksystems/nifi-nginx@sha256:486c933b05e14b4a3a1e4f966d832b27b2097f6789d8c9fbeb0c129d97a7136f + +# Local builds use a separate tag; never tag a build with the published digest. +NIFI_LOCAL_DOCKER_IMAGE="cogstacksystems/nifi:local" +NIFI_BASE_IMAGE=apache/nifi:2.13.0@sha256:bc4f695c6ae29c51b68062a16463fb4f6c93ccac8609e774d5097af0be034672 + + + +############################################################################################################################## +# NIFI SECTION +############################################################################################################################## +NIFI_ENV_FILE="./nifi.env" +NIFI_SECURITY_DIR="../../../deployment/security/certificates/nifi/" +NIFI_DATA_PATH="../data/" + +NIFI_TOOLKIT_VERSION=$NIFI_VERSION + +# this is to mount medcat models (optional) +NIFI_MEDCAT_SERVICE_MODEL_PRODUCTION_PATH="../services/cogstack-nlp/medcat-service/models/" + +#### Port and network settings +NIFI_WEB_PROXY_CONTEXT_PATH=/nifi + +# Update NIFI_WEB_PROXY_HOST when changing the published NGINX port. + +# If browsers have trouble with localhost-scoped auth cookies, using 127.0.0.1 +# avoids the special-case cookie handling around localhost. +NIFI_WEB_HTTPS_HOST=0.0.0.0 + +# NiFi validates reverse proxy headers against this public host:port list. +# For remote deployments, include the exact hostname or IP users open in a browser, +# for example: "localhost:8443,nifi.example.org:8443". +NIFI_WEB_PROXY_HOST=localhost:8443,127.0.0.1:8443,nifi.cogstack:8443 + +# NiFi HTTPS listener inside the NiFi container. NGINX connects to this port. +NIFI_INTERNAL_PORT=8443 + +# NGINX HTTPS listener. Docker Compose publishes the same port on the host. +# The Helm Service forwards to this listener. +NIFI_INTERNAL_PORT_NGINX=8443 + +# NiFi endpoint used by nginx; the TLS name must match the NiFi certificate. +NIFI_UPSTREAM_HOST=nifi +NIFI_UPSTREAM_TLS_NAME=nifi + +NIFI_OUTPUT_PORT=8082 +NIFI_INPUT_SOCKET_PORT=10000 + +NIFI_UID=1000 +NIFI_GID=1000 + +# Comma-separated Kubernetes node names allowed to run NiFi. +NIFI_K3S_WHITELIST= + +# Kubernetes PVC sizes per replica. Use quantities such as 100Gi. +NIFI_K3S_FLOWFILE_VOLUME_SIZE="${NIFI_K3S_FLOWFILE_VOLUME_SIZE:-50Gi}" +NIFI_K3S_CONTENT_VOLUME_SIZE="${NIFI_K3S_CONTENT_VOLUME_SIZE:-100Gi}" +NIFI_K3S_PROVENANCE_VOLUME_SIZE="${NIFI_K3S_PROVENANCE_VOLUME_SIZE:-100Gi}" +NIFI_K3S_DATABASE_VOLUME_SIZE="${NIFI_K3S_DATABASE_VOLUME_SIZE:-10Gi}" +NIFI_K3S_STATE_VOLUME_SIZE="${NIFI_K3S_STATE_VOLUME_SIZE:-20Gi}" +NIFI_K3S_CONF_VOLUME_SIZE="${NIFI_K3S_CONF_VOLUME_SIZE:-5Gi}" +# Leave empty to use the cluster's default StorageClass for the claims. +NIFI_K3S_STORAGE_CLASS="${NIFI_K3S_STORAGE_CLASS:-}" + +# env vars defining locations of proposed output logs for scripts +NIFI_USER_SCRIPT_LOGS_DIR="/opt/nifi/nifi-current/logs/user_scripts/" + +# env vars for defining SQLITE DB locations +NIFI_USER_SCRIPT_DB_DIR="/opt/nifi/nifi-current/state/user_scripts/db/" + +# nifi.python.framework.source.directory=/opt/nifi/nifi-current/python/framework + +NIFI_PYTHON_FRAMEWORK_SOURCE_DIRECTORY="/opt/nifi/nifi-current/python/framework" + +# nifi.python.extensions.source.directory.default=/opt/nifi/nifi-current/python_extensions +NIFI_PYTHON_EXTENSIONS_SOURCE_DIRECTORY_DEFAULT="/opt/nifi/nifi-current/python_extensions" + +# Generated Python environments/caches are separate from editable processor source. +NIFI_PYTHON_WORKING_DIRECTORY="/opt/nifi/nifi-current/work/python" +NIFI_PYTHONPATH=$NIFI_PYTHON_FRAMEWORK_SOURCE_DIRECTORY + +NIFI_LOG_LEVEL="ERROR" + +# Apache startup's AUTH and provider settings are passed explicitly in Compose. +# Certificate reload and shutdown periods are configured in nifi.properties/bootstrap.conf. +NIFI_HEALTHCHECK_HOST=nifi +NIFI_HEALTHCHECK_CA_FILE="/security/certificates/root/root-ca.pem" + +NIFI_KEYSTORE_PATH="/security/certificates/nifi/nifi-keystore.jks" +NIFI_TRUSTSTORE_PATH="/security/certificates/nifi/nifi-truststore.jks" + +NIFI_KEYSTORE_TYPE=JKS +NIFI_TRUSTSTORE_TYPE=JKS + +# this is from ./security/certificates_nifi.env, NIFI_SUBJ_LINE_CERTIFICATE_CN +NIFI_INITIAL_ADMIN_IDENTITY="cogstack" + + + +# OIDC settings +# taken from: https://raw.githubusercontent.com/apache/nifi/refs/heads/main/nifi-docker/dockerhub/sh/update_oidc_properties.sh + +NIFI_SECURITY_USER_OIDC_DISCOVERY_URL="" +NIFI_SECURITY_USER_OIDC_CONNECT_TIMEOUT="" +NIFI_SECURITY_USER_OIDC_READ_TIMEOUT="" +NIFI_SECURITY_USER_OIDC_CLIENT_ID="" +NIFI_SECURITY_USER_OIDC_CLIENT_SECRET="" +NIFI_SECURITY_USER_OIDC_PREFERRED_JWSALGORITHM="" +NIFI_SECURITY_USER_OIDC_ADDITIONAL_SCOPES="" +NIFI_SECURITY_USER_OIDC_CLAIM_IDENTIFYING_USER="" +NIFI_SECURITY_USER_OIDC_CLAIM_GROUPS="" +NIFI_SECURITY_USER_OIDC_FALLBACK_CLAIMS_IDENTIFYING_USER="" +NIFI_SECURITY_USER_OIDC_TRUSTSTORE_STRATEGY="" +NIFI_SECURITY_USER_OIDC_TOKEN_REFRESH_WINDOW="" +KEYSTORE_PATH=/security/certificates/nifi/nifi-keystore.jks +KEYSTORE_TYPE=JKS +TRUSTSTORE_PATH=/security/certificates/nifi/nifi-truststore.jks +TRUSTSTORE_TYPE=JKS diff --git a/deployment/Makefile b/deployment/Makefile index 2f011ff9..7f791543 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -1,25 +1,20 @@ SHELL := /usr/bin/env bash .SHELLFLAGS := -o pipefail -c -.DEFAULT_GOAL := setup-install-pre-requisites +.DEFAULT_GOAL := help -include $(addprefix $(dir $(lastword $(MAKEFILE_LIST)))make/,setup.mk certs.mk k3s.mk charts.mk) +load_kube_namespace = . ./env/general.env; namespace="$${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" + +recipe_files := make/setup.mk make/certs.mk make/k3s-config.mk make/charts.mk +include make/arguments.mk $(recipe_files) .PHONY: help -# Use the first comment in each included file as its help section heading. +# Use the first comment in each recipe file as its help section heading. help: ## Show deployment commands @printf '%s\n' 'Deployment commands' @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) + FNR == 1 && /^# / { printf "\n%s\n", substr($$0, 3); next } \ + NF == 2 && $$1 ~ /^[[:alnum:]_-]+$$/ { printf " %-30s %s\n", $$1, $$2 }' \ + Makefile $(recipe_files) @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/README.md b/deployment/README.md index ec74faee..9106eb45 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -1,25 +1,21 @@ # CogStack deployment -Run the Makefile commands below from the `deployment/` directory. [Deployment Makefile](Makefile) +Run these commands from `deployment/`. Run `make` to see the available commands. -## Quickstart after setup +## Deploy both stacks 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 copy `../apps/nifi/env/nifi.env.example` -to `../apps/nifi/env/nifi.env` if it’s missing. [Environment settings](#environment-settings) +passwords and provide deployment credentials. [Environment settings](#environment-settings) ```bash -make certs-all -make k3s-prepare-all +make cert +make install ``` -`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) +`make cert` generates the Kubernetes certificate bundle. `make install` +renders Helm values, applies the TLS Secrets, runtime ConfigMaps, and +authentication Secrets, then installs or upgrades both stacks. ## On-premises setup @@ -39,10 +35,10 @@ Docker, K3s, and Helm, then creates the namespace from `env/general.env`. ### Generate 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`. +Set `SECURITY_DIR` to use an existing bundle or write certificates to a different +directory. It defaults to `deployment/security`, with the bundle under +`certificates/`. Use `make cert nginx` to issue an NGINX certificate from +the existing CA, then `make k3s-load-certs nginx` to apply it. [Certificate targets](scripts/README.md#certificates) ## Environment settings @@ -57,9 +53,9 @@ transport certificate for K3s. If you already have a bundle, set | `env/opensearch.env` | `OPENSEARCH_K3S_REPLICA_COUNT`, `OPENSEARCH_K3S_BLACKLIST`, `OPENSEARCH_K3S_VOLUME_SIZE`, `OPENSEARCH_K3S_STORAGE_CLASS`, `OPENSEARCH_DOCKER_*` resources, and `OPENSEARCH_LOG_LEVEL`. | | `env/opensearch-dashboards.env` | `OPENSEARCH_DASHBOARDS_DOCKER_*` resources. | -`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 +`make prepare` and the full install read 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`. @@ -68,25 +64,56 @@ Compose sample. ## Install the applications -After `make k3s-prepare-all`, choose a stack or install the charts individually. +Run `make prepare` to render values and apply Kubernetes configuration for both +stacks in a separate step. For chart-specific prerequisites, see the +[chart guides](charts/README.md#kubernetes-https-entry-point). | 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` | 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. | +| `make install nifi-stack` | NiFi, then NGINX for the HTTPS UI and API. | +| `make install opensearch-stack` | OpenSearch, then Dashboards. | +| `make install nifi` | The NiFi StatefulSet. Use NGINX for HTTPS access. | +| `make install nginx` | The HTTPS gateway for the backends you deploy. | +| `make install opensearch` | The OpenSearch cluster and its REST API. | +| `make install opensearch-dashboards` | Dashboards. Install OpenSearch first. | + +`HELM_TIMEOUT` defaults to `10m`. Set `HELM_VALUES` to a path or `-` for +standard input. For `make install opensearch-stack`, the override applies to Dashboards. +Set `BOOTSTRAP_OPENSEARCH_SECURITY=0` on that stack to reuse existing auth Secrets. +For other local charts, pass the directory name under `charts/` to `make install`. ### Standalone JupyterHub -Run `make helm-install-jupyter-hub` with the namespace from `env/general.env` +Run `make install jupyter-hub` with the namespace from `env/general.env` in place. Use `make setup-k3s-namespace` to create the namespace if needed. The target stages the chart in a writable temporary directory, so it works from a read-only checkout. [JupyterHub chart values](charts/jupyter-hub/values.yaml) +### Update configuration + +| Makefile command | Values for the selector | +| --- | --- | +| `make helm-values nginx` | `all` (default), `nifi`, `nginx`, `opensearch`, `opensearch-dashboards` | +| `make k3s-load-certs nginx` | `all` (default), `nginx`, `opensearch` | +| `make k3s-load-env nginx` | `all` (default), `nginx`, `opensearch` | +| `make k3s-load-auth nifi` | `all` (default), `nifi`, `opensearch`, `opensearch-dashboards` | + +### Uninstall and clean up + +Use `make uninstall ` with one of the names in the install table +or `jupyter-hub`. NiFi and OpenSearch PVCs are retained for +reinstallation. To delete the OpenSearch data PVCs after uninstalling, run +`make helm-delete-opensearch-volumes`. + +Use `make k3s-delete-auth ` to remove the selected authentication +Secrets. It accepts the same service names as `k3s-load-auth`. Pass `all` to +delete all authentication Secrets. + +Use `make delete-cert nginx` to remove an entire local certificate bundle +after confirming the prompt. Choose `nifi`, `opensearch`, `nginx`, or `all`. +`make delete-cert all` also removes the root CA. + ## 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 3d13185d..49fd4760 100644 --- a/deployment/charts/README.md +++ b/deployment/charts/README.md @@ -7,14 +7,15 @@ 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 serves HTTPS -for the stack and forwards requests to the application Services over HTTP. +for the stack. It connects to NiFi over HTTPS and to OpenSearch and Dashboards +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 + internal HTTPS port `8443` 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 + terminates TLS with the `nginx-tls` Secret. NiFi handles its own login 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 @@ -35,11 +36,12 @@ prerequisites, then run these commands from the repository root. ```bash make -C deployment setup-k3s-namespace -make -C deployment certs-k3s -make -C deployment helm-install-all +make -C deployment cert +make -C deployment install ``` -Existing deployments must reload `nifi-auth` for NGINX before upgrading. +Run `make -C deployment k3s-load-auth nifi` before upgrading NiFi and NGINX +together to populate the native login credentials in `nifi-auth`. OpenSearch upgrades also require the bootstrap Secret and preparation of administrative access when using an admin certificate. [OpenSearch upgrade details](opensearch/README.md#install) @@ -59,7 +61,7 @@ helm template cogstack-nginx deployment/charts/nginx --namespace cogstack ``` See each chart's README for the ConfigMaps, Secrets and storage needed before -installation. Run `make -C deployment helm-values-` for NiFi, NGINX, +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. Docker memory sizes such diff --git a/deployment/charts/jupyter-hub/Chart.yaml b/deployment/charts/jupyter-hub/Chart.yaml index f5805cc3..53ecb738 100644 --- a/deployment/charts/jupyter-hub/Chart.yaml +++ b/deployment/charts/jupyter-hub/Chart.yaml @@ -6,6 +6,7 @@ version: 0.6.0 maintainers: - name: cogstack + url: https://github.com/CogStack icon: "https://avatars.githubusercontent.com/u/28688163" diff --git a/deployment/charts/nginx/Chart.yaml b/deployment/charts/nginx/Chart.yaml index 02dd4e50..fe6a51cf 100644 --- a/deployment/charts/nginx/Chart.yaml +++ b/deployment/charts/nginx/Chart.yaml @@ -27,6 +27,6 @@ home: https://docs.cogstack.org/ sources: - https://github.com/CogStack/cogstack-platform maintainers: - - name: vladd-bit - email: 62345326+vladd-bit@users.noreply.github.com + - name: cogstack + url: https://github.com/CogStack icon: "https://avatars.githubusercontent.com/u/28688163" diff --git a/deployment/charts/nginx/README.md b/deployment/charts/nginx/README.md index 9d9472d6..61a86ab7 100644 --- a/deployment/charts/nginx/README.md +++ b/deployment/charts/nginx/README.md @@ -1,29 +1,29 @@ # CogStack NGINX Helm chart 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. +Service. It proxies to NiFi over HTTPS and to OpenSearch and Dashboards over +HTTP within the release namespace. | HTTPS path | Backend | Client authentication | | --- | --- | --- | -| `/nifi/`, `/nifi-api/` | NiFi on `8080` | NGINX Basic Auth | +| `/nifi/`, `/nifi-api/` | NiFi on `8443` | NiFi login and API bearer tokens | | `/opensearch/` | OpenSearch on `9200` | OpenSearch Security | | `/dashboards/` | OpenSearch Dashboards on `5601` | Dashboards login | -Load `nginx-tls` with `make -C deployment k3s-load-certs-nginx`, or provide a +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`. +certificate with `make -C deployment cert nginx`. -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. +Run `make -C deployment k3s-load-auth nifi` to supply NiFi's login credentials. +NiFi reads the `nifi-auth` Secret at startup. NGINX forwards API bearer tokens +to NiFi. [NiFi credentials](../nifi/README.md#prerequisites) On K3s using ServiceLB, disable the bundled Traefik controller on all servers with `--disable=traefik` to free port `443` for NGINX. ```bash -make -C deployment helm-install-nginx +make -C deployment install nginx ``` For local access, set `service.type: ClusterIP` and forward the NGINX Service. diff --git a/deployment/charts/nginx/nginx.conf.template b/deployment/charts/nginx/nginx.conf.template index 6f345f42..a6e9ccb0 100644 --- a/deployment/charts/nginx/nginx.conf.template +++ b/deployment/charts/nginx/nginx.conf.template @@ -45,10 +45,7 @@ server { } 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 Host "{{ .Values.nifi.tlsName | default "localhost" }}:{{ .Values.nifi.port }}"; proxy_set_header X-ProxyHost $host; proxy_set_header X-ProxyPort $nifi_public_port; proxy_set_header X-ProxyScheme $scheme; @@ -57,6 +54,8 @@ server { proxy_set_header X-Forwarded-Prefix ""; proxy_set_header X-Forwarded-For $remote_addr; proxy_redirect http://$http_host/ /; - proxy_pass http://nifi; + proxy_ssl_server_name on; + proxy_ssl_name "{{ .Values.nifi.tlsName | default "localhost" }}"; + proxy_pass https://nifi; } } diff --git a/deployment/charts/nginx/render.yaml b/deployment/charts/nginx/render.yaml deleted file mode 100644 index 291ff1a3..00000000 --- a/deployment/charts/nginx/render.yaml +++ /dev/null @@ -1,159 +0,0 @@ ---- -# Source: nginx/templates/configmap.yaml -apiVersion: v1 -kind: ConfigMap -metadata: - name: cogstack-nginx-config -data: - nginx.conf.template: | - resolver ${NGINX_LOCAL_RESOLVERS} valid=10s; - resolver_timeout 3s; - - upstream nifi { - zone nifi 64k; - server cogstack-nifi.default.svc.cluster.local:8080 resolve; - } - upstream opensearch { - zone opensearch 64k; - server opensearch-cluster-master.default.svc.cluster.local:9200 resolve; - } - upstream dashboards { - zone dashboards 64k; - server opensearch-dashboards.default.svc.cluster.local:5601 resolve; - } - - map $request_port $nifi_public_port { - "" 443; - default $request_port; - } - - server { - listen 8443 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; - } - } - - ---- -# Source: nginx/templates/service.yaml -apiVersion: v1 -kind: Service -metadata: - name: cogstack-nginx -spec: - type: LoadBalancer - selector: - app: cogstack-nginx - ports: - - name: https - port: 443 - targetPort: https - protocol: TCP - ---- -# Source: nginx/templates/deployment.yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name: cogstack-nginx - -spec: - replicas: 1 - selector: - matchLabels: - app: cogstack-nginx - - template: - metadata: - labels: - app: cogstack-nginx - annotations: - checksum/config: 31b6ee535d8b5fbef67ff3a68ebfb63239bed379853c1bb666f6aaf0089c7caf - - spec: - containers: - - name: nginx - image: "cogstacksystems/nginx:latest" - imagePullPolicy: Always - - ports: - - name: https - containerPort: 8443 - - envFrom: - - configMapRef: - name: 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: - tcpSocket: - port: https - - resources: - limits: - cpu: 1 - memory: 512M - requests: - cpu: 1 - memory: 128M - - volumes: - - name: config - configMap: - name: cogstack-nginx-config - - name: tls - secret: - secretName: nginx-tls - - name: nifi-auth - secret: - secretName: nifi-auth - optional: true - items: - - key: htpasswd - path: htpasswd diff --git a/deployment/charts/nginx/templates/deployment.yaml b/deployment/charts/nginx/templates/deployment.yaml index 26961b2f..e783dbd9 100644 --- a/deployment/charts/nginx/templates/deployment.yaml +++ b/deployment/charts/nginx/templates/deployment.yaml @@ -38,9 +38,6 @@ spec: - name: tls mountPath: /certificates readOnly: true - - name: nifi-auth - mountPath: /etc/nginx/nifi-auth - readOnly: true readinessProbe: tcpSocket: @@ -56,10 +53,3 @@ spec: - name: tls 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/values.env.yaml b/deployment/charts/nginx/values.env.yaml index efcb1dbb..c4cee0db 100644 --- a/deployment/charts/nginx/values.env.yaml +++ b/deployment/charts/nginx/values.env.yaml @@ -12,13 +12,13 @@ clusterDomain: cluster.local nifi: host: "" - port: 8080 + port: ${NIFI_INTERNAL_PORT} opensearch: host: "" - port: 9200 + port: ${OPENSEARCH_HTTP_PORT} dashboards: host: "" - port: 5601 + port: ${OPENSEARCH_DASHBOARDS_SERVER_OUTPUT_PORT} tls: existingSecret: nginx-tls diff --git a/deployment/charts/nginx/values.yaml b/deployment/charts/nginx/values.yaml index 3fd8f548..48412890 100644 --- a/deployment/charts/nginx/values.yaml +++ b/deployment/charts/nginx/values.yaml @@ -12,7 +12,7 @@ clusterDomain: cluster.local nifi: host: "" - port: 8080 + port: 8443 opensearch: host: "" port: 9200 diff --git a/deployment/charts/nifi/Chart.yaml b/deployment/charts/nifi/Chart.yaml index 6eff45a0..eec5cdac 100644 --- a/deployment/charts/nifi/Chart.yaml +++ b/deployment/charts/nifi/Chart.yaml @@ -8,7 +8,9 @@ appVersion: "latest" home: https://docs.cogstack.org/ sources: - https://github.com/CogStack/cogstack-platform + maintainers: - - name: vladd-bit - email: 62345326+vladd-bit@users.noreply.github.com + - name: cogstack + url: https://github.com/CogStack + icon: "https://avatars.githubusercontent.com/u/28688163" diff --git a/deployment/charts/nifi/README.md b/deployment/charts/nifi/README.md index 019e218d..36354603 100644 --- a/deployment/charts/nifi/README.md +++ b/deployment/charts/nifi/README.md @@ -1,22 +1,21 @@ # CogStack NiFi Helm chart -Deploys the CogStack Apache NiFi image with a StatefulSet, cluster-internal HTTP +Deploys the CogStack Apache NiFi image with a StatefulSet, cluster-internal HTTPS Services, and persistent storage for configuration and NiFi repositories. -NGINX handles HTTPS and login for the UI and API. [NGINX chart](../nginx/README.md) +NGINX proxies the UI and API to NiFi, which handles login. [NGINX chart](../nginx/README.md) ## Prerequisites -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 +Run `make -C deployment k3s-load-auth nifi` to create or update `nifi-auth` with +the NiFi flow encryption key and single-user login credentials. Set `NIFI_SINGLE_USER_CREDENTIALS_USERNAME` and `NIFI_SINGLE_USER_CREDENTIALS_PASSWORD` -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. +in the environment or `deployment/env/authentication.env`. The loader prompts +for a deployment password if needed and preserves the existing +`NIFI_SENSITIVE_PROPS_KEY`. Restart NiFi to pick up a credential change. -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. +The namespace needs a StorageClass or persistent volumes for the chart's claims. +Use a cluster that enforces NetworkPolicy so the chart can restrict access to +NGINX pods in the same namespace. ## Render and install @@ -33,11 +32,12 @@ 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. -Use the NGINX `/nifi/` and `/nifi-api/` routes with HTTP Basic authentication. +Sign in at `/nifi/` through NGINX. API clients can obtain a bearer token at +`/nifi-api/access/token`. ## Persistent configuration and data -The chart creates six PVCs per replica. Set their sizes in +The chart creates six PVCs per replica by default. Set their sizes in `apps/nifi/env/nifi.env` using Kubernetes quantities such as `200Gi`. [NiFi environment settings](../../../apps/nifi/README.md#environment-files) @@ -63,15 +63,39 @@ Claims are retained when the StatefulSet is deleted or scaled down. Configure storage with `persistence.storageClassName`, `persistence.accessModes` and `persistence.volumes.`. A `null` StorageClass uses the cluster default; an empty string selects no StorageClass. Each claim can override the global -StorageClass and access modes. Existing StatefulSet claim templates have -Kubernetes immutability constraints; plan storage changes and backups separately. +StorageClass and access modes. Kubernetes treats existing StatefulSet claim +templates as immutable. Drivers, schemas and Python processors are bundled by the NiFi image. Startup -and readiness probes use NiFi's loopback HTTP endpoint. +and readiness probes use NiFi's loopback HTTPS endpoint. + +### Three-claim layout + +For a new installation, pass a Helm values file with the shared claim size. + +```yaml +persistence: + volumes: + shared: + size: 65Gi +``` + +The FlowFile and content repositories keep dedicated claims. The shared claim +holds the provenance repository, database repository, local state and `conf`. +Each directory mounts at its usual NiFi path using `subPath`. The example +requests the same total capacity as the four individual claims at their default +sizes. Size it for their combined usage and use split claims if provenance +needs independent capacity or I/O. +[NiFi repository storage guidance](https://nifi.apache.org/nifi-docs/administration-guide.html#content-repository) + +Use the same storage values on subsequent upgrades. Changing layouts for an +existing release requires stopping NiFi, backing up the claims, and recreating +the StatefulSet. Restore each affected directory into its target claim before +starting NiFi, including the bootstrap marker in `conf`. ## Environment-based values -Run `make -C deployment helm-values-nifi` to render `values.env.yaml` using +Run `make -C deployment helm-values nifi` to render `values.env.yaml` using `deployment/env/nifi.env`, which links to `apps/nifi/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. @@ -79,8 +103,9 @@ populate `allowedNodes`. An empty list allows any otherwise eligible node. ## Resource names 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. +connects to the `cogstack-nifi` ClusterIP Service on its fixed port `8080`. The +Service forwards to the pod's named `http` port, set by `nifi.internalPort`. +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/rendered.yaml b/deployment/charts/nifi/rendered.yaml deleted file mode 100644 index da666466..00000000 --- a/deployment/charts/nifi/rendered.yaml +++ /dev/null @@ -1,244 +0,0 @@ ---- -# Source: nifi/templates/networkpolicy.yaml -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: 8080 - ---- -# Source: nifi/templates/service.yaml -apiVersion: v1 -kind: Service -metadata: - name: cogstack-nifi-headless -spec: - type: ClusterIP - clusterIP: None - selector: - app: cogstack-nifi - ports: - - name: http - port: 8080 - ---- -# Source: nifi/templates/service.yaml -apiVersion: v1 -kind: Service -metadata: - name: cogstack-nifi -spec: - type: ClusterIP - selector: - app: cogstack-nifi - ports: - - name: http - port: 8080 - targetPort: http - ---- -# Source: nifi/templates/statefulset.yaml -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: cogstack-nifi - -spec: - serviceName: cogstack-nifi-headless - replicas: 1 - persistentVolumeClaimRetentionPolicy: - whenDeleted: Retain - whenScaled: Retain - selector: - matchLabels: - app: cogstack-nifi - template: - metadata: - labels: - app: cogstack-nifi - spec: - securityContext: - fsGroup: 1000 - fsGroupChangePolicy: OnRootMismatch - runAsGroup: 1000 - runAsNonRoot: true - runAsUser: 1000 - terminationGracePeriodSeconds: 120 - initContainers: - - name: initialize-conf - image: "cogstacksystems/nifi:latest" - imagePullPolicy: Always - securityContext: - allowPrivilegeEscalation: false - resources: - limits: - cpu: "1" - memory: 2G - requests: - cpu: "1" - memory: 2G - command: ["/bin/sh", "-ec"] - args: - - | - marker=/mnt/conf/.nifi-bootstrap-incomplete - complete=/mnt/conf/.nifi-bootstrap-complete - if [ -e "$marker" ]; then - echo "Interrupted conf initialization; restore the conf PVC before starting NiFi." >&2 - exit 1 - fi - test -w /mnt/conf || { echo "The conf PVC is not writable by the configured NiFi UID/GID." >&2; exit 1; } - if [ ! -f "$complete" ]; then - if [ -n "$(find /mnt/conf -mindepth 1 -maxdepth 1 ! -name lost+found -print -quit)" ]; then - echo "Unverified non-empty conf PVC; verify or restore its configuration before creating .nifi-bootstrap-complete." >&2 - exit 1 - fi - touch "$marker" - sync -f /mnt/conf - find "$NIFI_HOME/conf" -mindepth 1 -maxdepth 1 \ - -exec cp -R --preserve=mode,timestamps -t /mnt/conf -- {} + - fi - for file in nifi.properties bootstrap.conf state-management.xml authorizers.xml login-identity-providers.xml logback.xml; do - if [ ! -s "/mnt/conf/$file" ] || [ ! -r "/mnt/conf/$file" ] || [ ! -w "/mnt/conf/$file" ]; then - echo "Missing, empty or inaccessible NiFi configuration file: $file" >&2 - exit 1 - fi - done - if [ -e "$marker" ]; then - sync -f /mnt/conf - mv "$marker" "$complete" - sync -f /mnt/conf - fi - volumeMounts: - - name: conf - mountPath: /mnt/conf - containers: - - name: nifi - securityContext: - allowPrivilegeEscalation: false - 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' '8080' - 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: flowfile-repository - mountPath: /opt/nifi/nifi-current/flowfile_repository - - name: content-repository - mountPath: /opt/nifi/nifi-current/content_repository - - name: provenance-repository - mountPath: /opt/nifi/nifi-current/provenance_repository - - name: database-repository - mountPath: /opt/nifi/nifi-current/database_repository - - name: state - mountPath: /opt/nifi/nifi-current/state - - name: conf - mountPath: /opt/nifi/nifi-current/conf - - image: "cogstacksystems/nifi:latest" - imagePullPolicy: Always - ports: - - name: http - containerPort: 8080 - startupProbe: - exec: &healthcheck - command: ["curl", "-fsS", "--noproxy", "*", "-o", "/dev/null", "http://127.0.0.1:8080/nifi-api/authentication/configuration"] - timeoutSeconds: 10 - failureThreshold: 30 - readinessProbe: - exec: *healthcheck - timeoutSeconds: 10 - resources: - limits: - cpu: "1" - memory: 2G - requests: - cpu: "1" - memory: 2G - - volumeClaimTemplates: - - metadata: - name: flowfile-repository - spec: - accessModes: - - ReadWriteOnce - volumeMode: Filesystem - resources: - requests: - storage: "20Gi" - - metadata: - name: content-repository - spec: - accessModes: - - ReadWriteOnce - volumeMode: Filesystem - resources: - requests: - storage: "100Gi" - - metadata: - name: provenance-repository - spec: - accessModes: - - ReadWriteOnce - volumeMode: Filesystem - resources: - requests: - storage: "50Gi" - - metadata: - name: database-repository - spec: - accessModes: - - ReadWriteOnce - volumeMode: Filesystem - resources: - requests: - storage: "5Gi" - - metadata: - name: state - spec: - accessModes: - - ReadWriteOnce - volumeMode: Filesystem - resources: - requests: - storage: "5Gi" - - metadata: - name: conf - spec: - accessModes: - - ReadWriteOnce - volumeMode: Filesystem - resources: - requests: - storage: "5Gi" diff --git a/deployment/charts/nifi/templates/statefulset.yaml b/deployment/charts/nifi/templates/statefulset.yaml index 4cbb1a48..1924c5fc 100644 --- a/deployment/charts/nifi/templates/statefulset.yaml +++ b/deployment/charts/nifi/templates/statefulset.yaml @@ -1,4 +1,15 @@ -{{- $directories := list "flowfile_repository" "content_repository" "provenance_repository" "database_repository" "state" "conf" -}} +{{- if not (has (toString .Values.replicaCount) (list "0" "1")) -}} + {{- fail "NiFi supports replicaCount 1, or 0 for maintenance and CI." -}} +{{- end -}} +{{- $dedicatedDirectories := list "flowfile_repository" "content_repository" -}} +{{- $sharedDirectories := list "provenance_repository" "database_repository" "state" "conf" -}} +{{- $directories := concat $dedicatedDirectories $sharedDirectories -}} +{{- $volumes := .Values.persistence.volumes | default dict -}} +{{- $useSharedClaim := ne $volumes.shared nil -}} +{{- $claimKeys := $directories -}} +{{- if $useSharedClaim -}} + {{- $claimKeys = append $dedicatedDirectories "shared" -}} +{{- end -}} apiVersion: apps/v1 kind: StatefulSet metadata: @@ -33,50 +44,9 @@ spec: securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} - initContainers: - - name: initialize-conf - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - resources: - {{- toYaml .Values.resources | nindent 12 }} - command: ["/bin/sh", "-ec"] - args: - - | - marker=/mnt/conf/.nifi-bootstrap-incomplete - complete=/mnt/conf/.nifi-bootstrap-complete - if [ -e "$marker" ]; then - echo "Interrupted conf initialization; restore the conf PVC before starting NiFi." >&2 - exit 1 - fi - test -w /mnt/conf || { echo "The conf PVC is not writable by the configured NiFi UID/GID." >&2; exit 1; } - if [ ! -f "$complete" ]; then - if [ -n "$(find /mnt/conf -mindepth 1 -maxdepth 1 ! -name lost+found -print -quit)" ]; then - echo "Unverified non-empty conf PVC; verify or restore its configuration before creating .nifi-bootstrap-complete." >&2 - exit 1 - fi - touch "$marker" - sync -f /mnt/conf - find "$NIFI_HOME/conf" -mindepth 1 -maxdepth 1 \ - -exec cp -R --preserve=mode,timestamps -t /mnt/conf -- {} + - fi - for file in nifi.properties bootstrap.conf state-management.xml authorizers.xml login-identity-providers.xml logback.xml; do - if [ ! -s "/mnt/conf/$file" ] || [ ! -r "/mnt/conf/$file" ] || [ ! -w "/mnt/conf/$file" ]; then - echo "Missing, empty or inaccessible NiFi configuration file: $file" >&2 - exit 1 - fi - done - if [ -e "$marker" ]; then - sync -f /mnt/conf - mv "$marker" "$complete" - sync -f /mnt/conf - fi - volumeMounts: - - name: conf - mountPath: /mnt/conf + containers: - - name: nifi + - name: nifi-container securityContext: {{- toYaml .Values.securityContext | nindent 12 }} env: @@ -85,29 +55,29 @@ spec: 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 + {{- range list "SINGLE_USER_CREDENTIALS_USERNAME" "SINGLE_USER_CREDENTIALS_PASSWORD" }} + - name: {{ . }} + valueFrom: + secretKeyRef: + name: nifi-auth + key: {{ . }} + optional: true + {{- end }} + - name: COGSTACK_NIFI_MODE + value: "kubernetes" + - name: NIFI_WEB_HTTPS_PORT + value: {{ .Values.nifi.internalPort | int | quote }} + - name: NIFI_WEB_PROXY_HOST + value: {{ .Values.nifi.web_proxy_host | toString | quote }} volumeMounts: {{- range $directory := $directories }} - - name: {{ $directory | replace "_" "-" }} + {{- $sharedMount := and $useSharedClaim (has $directory $sharedDirectories) }} + - name: {{ ternary "shared" ($directory | replace "_" "-") $sharedMount }} mountPath: /opt/nifi/nifi-current/{{ $directory }} + {{- if $sharedMount }} + subPath: {{ $directory }} + {{- end }} {{- end }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" @@ -117,7 +87,7 @@ spec: containerPort: {{ .Values.nifi.internalPort | int }} startupProbe: exec: &healthcheck - command: ["curl", "-fsS", "--noproxy", "*", "-o", "/dev/null", "http://127.0.0.1:{{ .Values.nifi.internalPort }}/nifi-api/authentication/configuration"] + command: ["curl", "-4kfsS", "--noproxy", "*", "-o", "/dev/null", "https://localhost:{{ .Values.nifi.internalPort }}/nifi-api/authentication/configuration"] timeoutSeconds: 10 failureThreshold: 30 readinessProbe: @@ -127,14 +97,14 @@ spec: {{- toYaml .Values.resources | nindent 12 }} volumeClaimTemplates: - {{- range $directory := $directories }} - {{- $claim := required (printf "persistence.volumes.%s is required" $directory) (index $.Values.persistence.volumes $directory) }} + {{- range $claimKey := $claimKeys }} + {{- $claim := required (printf "persistence.volumes.%s is required" $claimKey) (index $volumes $claimKey) }} {{- $storageClass := $.Values.persistence.storageClassName }} {{- if hasKey $claim "storageClassName" }} {{- $storageClass = $claim.storageClassName }} {{- end }} - metadata: - name: {{ $directory | replace "_" "-" }} + name: {{ $claimKey | replace "_" "-" }} spec: accessModes: {{- toYaml (default $.Values.persistence.accessModes $claim.accessModes) | nindent 10 }} @@ -144,5 +114,5 @@ spec: volumeMode: Filesystem resources: requests: - storage: {{ required (printf "persistence.volumes.%s.size is required" $directory) $claim.size | quote }} + storage: {{ required (printf "persistence.volumes.%s.size is required" $claimKey) $claim.size | quote }} {{- end }} diff --git a/deployment/charts/nifi/values.env.yaml b/deployment/charts/nifi/values.env.yaml index b5d41728..238cf92b 100644 --- a/deployment/charts/nifi/values.env.yaml +++ b/deployment/charts/nifi/values.env.yaml @@ -6,7 +6,7 @@ allowedNodes: ${NIFI_K3S_ALLOWED_NODES} image: repository: cogstacksystems/nifi - tag: "latest" + tag: "nifi_chart_updates" pullPolicy: Always @@ -24,14 +24,15 @@ podSecurityContext: fsGroupChangePolicy: OnRootMismatch nifi: - internalPort: 8080 + internalPort: ${NIFI_INTERNAL_PORT} + web_proxy_host: ${NIFI_WEB_PROXY_HOST} persistence: # null uses the cluster default; "" selects no StorageClass (pre-provisioned PVs). # Select a durable production backend; Retain does not replace backups. storageClassName: ${NIFI_K3S_STORAGE_CLASS_YAML} accessModes: [ReadWriteOnce] - # Every volume is a separate PVC per replica. Each can override storageClassName/accessModes. + # Each claim can override storageClassName and accessModes. # Existing data must be restored while NiFi is stopped; no automatic migration or resizing. # Claim templates are immutable on existing StatefulSets; plan replacement/expansion explicitly. volumes: @@ -49,6 +50,9 @@ persistence: # Seeded only when empty; image upgrades never overwrite persisted configuration. # Existing PVCs without .nifi-bootstrap-complete require verification and explicit marking. size: "${NIFI_K3S_CONF_VOLUME_SIZE}" + # Set to {size: 65Gi} in a Helm values override to share one PVC per replica + # across provenance, database, state and conf. + shared: null resources: requests: diff --git a/deployment/charts/nifi/values.yaml b/deployment/charts/nifi/values.yaml index 63ebf65e..b25fb863 100644 --- a/deployment/charts/nifi/values.yaml +++ b/deployment/charts/nifi/values.yaml @@ -6,7 +6,7 @@ allowedNodes: [] image: repository: cogstacksystems/nifi - tag: "latest" + tag: "nifi_chart_updates" pullPolicy: Always @@ -24,31 +24,35 @@ podSecurityContext: fsGroupChangePolicy: OnRootMismatch nifi: - internalPort: 8080 + internalPort: 8443 + web_proxy_host: localhost:8443,127.0.0.1:8443,nifi.cogstack:8443 persistence: # null uses the cluster default; "" selects no StorageClass (pre-provisioned PVs). # Select a durable production backend; Retain does not replace backups. storageClassName: null accessModes: [ReadWriteOnce] - # Every volume is a separate PVC per replica. Each can override storageClassName/accessModes. + # Each claim can override storageClassName and accessModes. # Existing data must be restored while NiFi is stopped; no automatic migration or resizing. # Claim templates are immutable on existing StatefulSets; plan replacement/expansion explicitly. volumes: flowfile_repository: - size: 20Gi + size: "50Gi" content_repository: - size: 100Gi + size: "100Gi" provenance_repository: - size: 50Gi + size: "100Gi" database_repository: - size: 5Gi + size: "10Gi" state: - size: 5Gi + size: "20Gi" conf: # Seeded only when empty; image upgrades never overwrite persisted configuration. # Existing PVCs without .nifi-bootstrap-complete require verification and explicit marking. - size: 5Gi + size: "5Gi" + # Set to {size: 65Gi} in a Helm values override to share one PVC per replica + # across provenance, database, state and conf. + shared: null resources: requests: diff --git a/deployment/charts/ocr-service/Chart.yaml b/deployment/charts/ocr-service/Chart.yaml index 58d1d315..d48b1754 100644 --- a/deployment/charts/ocr-service/Chart.yaml +++ b/deployment/charts/ocr-service/Chart.yaml @@ -34,8 +34,7 @@ sources: - https://github.com/CogStack/cogstack-ocr-service maintainers: - - name: vladd-bit - email: 62345326+vladd-bit@users.noreply.github.com + - name: cogstack url: https://github.com/CogStack icon: "https://avatars.githubusercontent.com/u/28688163" diff --git a/deployment/charts/opensearch-dashboards/README.md b/deployment/charts/opensearch-dashboards/README.md index 6e96fb3b..2d9abde1 100644 --- a/deployment/charts/opensearch-dashboards/README.md +++ b/deployment/charts/opensearch-dashboards/README.md @@ -13,8 +13,8 @@ to share the `kibanaserver` password. If OpenSearch is already initialized, use its current `kibanaserver` password. ```bash -make -C deployment k3s-load-auth-opensearch-dashboards -make -C deployment helm-install-opensearch-dashboards +make -C deployment k3s-load-auth opensearch-dashboards +make -C deployment install opensearch-dashboards ``` The default values use `dashboards-auth` and `.kibana`, which matches the diff --git a/deployment/charts/opensearch-dashboards/values.env.yaml b/deployment/charts/opensearch-dashboards/values.env.yaml index d26c6d81..e66e6a13 100644 --- a/deployment/charts/opensearch-dashboards/values.env.yaml +++ b/deployment/charts/opensearch-dashboards/values.env.yaml @@ -1,9 +1,12 @@ opensearch-dashboards: - opensearchHosts: http://opensearch-cluster-master:9200 + opensearchHosts: http://opensearch-cluster-master:${OPENSEARCH_HTTP_PORT} + service: + port: ${OPENSEARCH_DASHBOARDS_SERVER_OUTPUT_PORT} opensearchAccount: secret: dashboards-auth config: opensearch_dashboards.yml: + server.port: ${OPENSEARCH_DASHBOARDS_SERVER_OUTPUT_PORT} server.ssl.enabled: false server.basePath: /dashboards server.rewriteBasePath: true diff --git a/deployment/charts/opensearch-dashboards/values.yaml b/deployment/charts/opensearch-dashboards/values.yaml index 84c17a08..6a97d0ae 100644 --- a/deployment/charts/opensearch-dashboards/values.yaml +++ b/deployment/charts/opensearch-dashboards/values.yaml @@ -1,9 +1,12 @@ opensearch-dashboards: opensearchHosts: http://opensearch-cluster-master:9200 + service: + port: 5601 opensearchAccount: secret: dashboards-auth config: opensearch_dashboards.yml: + server.port: 5601 server.ssl.enabled: false server.basePath: /dashboards server.rewriteBasePath: true diff --git a/deployment/charts/opensearch/README.md b/deployment/charts/opensearch/README.md index 5c3b00cf..1bd4bdf5 100644 --- a/deployment/charts/opensearch/README.md +++ b/deployment/charts/opensearch/README.md @@ -13,8 +13,9 @@ Use an absolute `SECURITY_DIR` for a custom certificate directory. [Cluster prerequisites](https://docs.opensearch.org/latest/opensearch/install/helm/#prerequisites) ```bash -make -C deployment -j1 certs-opensearch-nodes k3s-load-certs-opensearch NODES=opensearch-shared -make -C deployment helm-install-opensearch-stack +make -C deployment cert opensearch-nodes NODES=opensearch-shared +make -C deployment k3s-load-certs opensearch +make -C deployment install opensearch-stack ``` The stack target prepares the authentication Secrets, then installs OpenSearch @@ -23,8 +24,8 @@ and Dashboards. It 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 +make -C deployment k3s-load-auth opensearch +make -C deployment install opensearch ``` The loader requires `htpasswd`. Set `OPENSEARCH_KIBANA_PASSWORD` for @@ -48,7 +49,7 @@ External clients use the NGINX `/opensearch/` route over HTTPS. ## Replicas Set `OPENSEARCH_K3S_REPLICA_COUNT` in `deployment/env/opensearch.env` -and run `make -C deployment helm-values-opensearch` before installing or +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. @@ -74,7 +75,7 @@ or leave it empty to use the cluster default. Render the values and inspect the claim template before installing. ```bash -make -C deployment helm-values-opensearch +make -C deployment helm-values opensearch helm template opensearch deployment/charts/opensearch -n cogstack \ --show-only charts/opensearch/templates/statefulset.yaml ``` diff --git a/deployment/charts/opensearch/values.env.yaml b/deployment/charts/opensearch/values.env.yaml index c0a09cb9..ed9c5a5d 100644 --- a/deployment/charts/opensearch/values.env.yaml +++ b/deployment/charts/opensearch/values.env.yaml @@ -3,6 +3,7 @@ opensearch: # The upstream 3.10.0 chart defaults to the 3.10.0 image. tag: "3.10.1" replicas: ${OPENSEARCH_K3S_REPLICA_COUNT} + httpPort: ${OPENSEARCH_HTTP_PORT} protocol: http antiAffinity: hard nodeAffinity: ${OPENSEARCH_K3S_NODE_AFFINITY} @@ -13,6 +14,8 @@ opensearch: storageClass: "${OPENSEARCH_K3S_STORAGE_CLASS}" # Supply opensearch.yml with --set-file as shown in the README. extraEnvs: + - name: http.port + value: "${OPENSEARCH_HTTP_PORT}" - name: DISABLE_INSTALL_DEMO_CONFIG value: "true" - name: plugins.security.ssl.http.enabled diff --git a/deployment/charts/opensearch/values.yaml b/deployment/charts/opensearch/values.yaml index 48d7a96f..a9fc9345 100644 --- a/deployment/charts/opensearch/values.yaml +++ b/deployment/charts/opensearch/values.yaml @@ -3,6 +3,7 @@ opensearch: # The upstream 3.10.0 chart defaults to the 3.10.0 image. tag: "3.10.1" replicas: 1 + httpPort: 9200 protocol: http antiAffinity: hard nodeAffinity: {} @@ -13,6 +14,8 @@ opensearch: storageClass: "" # Supply opensearch.yml with --set-file as shown in the README. extraEnvs: + - name: http.port + value: "9200" - name: DISABLE_INSTALL_DEMO_CONFIG value: "true" - name: plugins.security.ssl.http.enabled diff --git a/deployment/make/arguments.mk b/deployment/make/arguments.mk new file mode 100644 index 00000000..c2fc2036 --- /dev/null +++ b/deployment/make/arguments.mk @@ -0,0 +1,61 @@ +# Allowed positional names and defaults. +cert_commands := cert delete-cert +cert_choices := k3s all root nifi nginx opensearch opensearch-nodes +cert_default := k3s +delete-cert_choices := all nifi opensearch nginx + +k3s_commands := k3s-load-auth k3s-delete-auth k3s-load-env k3s-load-certs +k3s_auth_services := nifi opensearch-dashboards opensearch +k3s_runtime_services := nginx opensearch +k3s-load-auth_choices := all $(k3s_auth_services) +k3s-delete-auth_choices := $(k3s-load-auth_choices) +k3s-load-env_choices := all $(k3s_runtime_services) +k3s-load-certs_choices := $(k3s-load-env_choices) +k3s-load-auth_default := all +k3s-load-env_default := all +k3s-load-certs_default := all + +chart_commands := install uninstall helm-values +helm_values_charts := nifi nginx opensearch opensearch-dashboards +helm_install_charts := $(patsubst charts/%/Chart.yaml,%,$(wildcard charts/*/Chart.yaml)) +helm_stacks := nifi-stack opensearch-stack +install_choices := all $(helm_stacks) $(helm_install_charts) +uninstall_choices := $(helm_stacks) $(helm_values_charts) jupyter-hub +helm-values_choices := all $(helm_values_charts) +install_default := all +helm-values_default := all + +# Make treats a positional name as a second goal. +argument_command := $(firstword $(filter $(cert_commands) $(k3s_commands) $(chart_commands),$(MAKECMDGOALS))) +ifneq ($(argument_command),) +argument_word := $(word 2,$(MAKECMDGOALS)) +argument_choices := $($(argument_command)_choices) +argument_value := $(or $(argument_word),$($(argument_command)_default)) +argument_usage := Use make $(argument_command) with one name from $(argument_choices) + +# Reject old selectors before a command can use its default. +ifneq ($(filter $(cert_commands),$(argument_command)),) +legacy_selector := CERT +else ifneq ($(filter $(k3s_commands),$(argument_command)),) +legacy_selector := SERVICE +else +legacy_selector := CHART +endif +ifneq ($(origin $(legacy_selector)),undefined) +$(error Pass the name after $(argument_command)) +endif + +ifneq ($(MAKECMDGOALS),$(strip $(argument_command) $(argument_word))) +$(error $(argument_usage)) +endif +ifeq ($(filter $(argument_choices),$(argument_value)),) +$(error $(argument_usage)) +endif + +override $(argument_command)_argument := $(argument_value) +ifneq ($(argument_word),) +.PHONY: $(argument_word) +$(argument_word): $(argument_command) + @: +endif +endif diff --git a/deployment/make/certs.mk b/deployment/make/certs.mk index 39c93c18..83b411c2 100644 --- a/deployment/make/certs.mk +++ b/deployment/make/certs.mk @@ -1,87 +1,18 @@ # Certificates -.PHONY: certs-all certs-k3s certs-root certs-nifi certs-nginx certs-opensearch certs-opensearch-shared certs-opensearch-nodes delete-certs-all +cert_targets := $(addprefix certs-,$(cert_choices)) certs-opensearch-shared +cert_script := bash scripts/security/certificates.sh -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}" +.PHONY: cert $(cert_targets) delete-cert -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" +cert: $(addprefix certs-,$(cert_argument)) ## Generate certificates (make cert nginx, defaults to k3s) -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-k3s: certs-root +certs-all: certs-k3s +certs-opensearch: certs-opensearch-shared -certs-root: ## Generate the root CA bundle - @$(load_certificates_env); \ - bash scripts/security/create_root_ca_cert.sh +$(cert_targets): + @$(cert_script) $(@:certs-%=%) -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 - +delete-cert: ## Confirm deletion of a local certificate bundle (make delete-cert nginx) + @$(cert_script) delete "$(delete-cert_argument)" diff --git a/deployment/make/charts.mk b/deployment/make/charts.mk index 75528105..371e2b3f 100644 --- a/deployment/make/charts.mk +++ b/deployment/make/charts.mk @@ -1,183 +1,65 @@ # Helm values and releases -.PHONY: helm-values-all helm-values-nifi helm-values-nginx helm-values-opensearch helm-values-opensearch-dashboards +helm_values_targets := $(addprefix helm-values-,$(helm_values_charts)) +helm_install_targets := $(addprefix helm-install-,$(helm_install_charts)) -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 +.PHONY: helm-values helm-values-all $(helm_values_targets) -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='[]'; \ - export NIFI_K3S_FLOWFILE_VOLUME_SIZE="$${NIFI_K3S_FLOWFILE_VOLUME_SIZE:-20Gi}"; \ - export NIFI_K3S_CONTENT_VOLUME_SIZE="$${NIFI_K3S_CONTENT_VOLUME_SIZE:-100Gi}"; \ - export NIFI_K3S_PROVENANCE_VOLUME_SIZE="$${NIFI_K3S_PROVENANCE_VOLUME_SIZE:-50Gi}"; \ - export NIFI_K3S_DATABASE_VOLUME_SIZE="$${NIFI_K3S_DATABASE_VOLUME_SIZE:-5Gi}"; \ - export NIFI_K3S_STATE_VOLUME_SIZE="$${NIFI_K3S_STATE_VOLUME_SIZE:-5Gi}"; \ - export NIFI_K3S_CONF_VOLUME_SIZE="$${NIFI_K3S_CONF_VOLUME_SIZE:-5Gi}"; \ - export NIFI_K3S_STORAGE_CLASS_YAML=null; \ - if [ -n "$${NIFI_K3S_STORAGE_CLASS:-}" ]; then \ - printf -v NIFI_K3S_STORAGE_CLASS_YAML '"%s"' "$$NIFI_K3S_STORAGE_CLASS"; \ - fi;; \ - opensearch) \ - node_setting=OPENSEARCH_K3S_BLACKLIST; \ - export OPENSEARCH_K3S_NODE_AFFINITY='{}'; \ - export OPENSEARCH_K3S_VOLUME_SIZE="$${OPENSEARCH_K3S_VOLUME_SIZE:-8Gi}";; \ - *) 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 \ - if [ "$$name" = OPENSEARCH_K3S_STORAGE_CLASS ]; then continue; fi; \ - 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 -.PHONY: helm-install-jupyter-hub - -# 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";; \ - jupyter-hub) \ - build_dir=$$(mktemp -d "$${TMPDIR:-/tmp}/cogstack-jupyter-hub.XXXXXX"); \ - trap 'rm -rf -- "$$build_dir"' EXIT; \ - cp -R "$$chart" "$$build_dir/"; \ - chart="$$build_dir/$$CHART"; \ - chmod -R u+w "$$chart"; \ - helm repo add jupyterhub https://hub.jupyter.org/helm-chart/; \ - 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-jupyter-hub: ## Install or upgrade standalone JupyterHub - -helm-install-nifi helm-install-nginx helm-install-opensearch \ -helm-install-opensearch-dashboards helm-install-jupyter-hub: - $(MAKE) helm-install CHART=$(@:helm-install-%=%) - -helm-install-nifi-stack: helm-install-nifi ## Load the runtime environment and install or upgrade NiFi and NGINX +helm-values: $(addprefix helm-values-,$(helm-values_argument)) ## Render values (make helm-values nginx, defaults to all) + +helm-values-all: $(helm_values_targets) + +$(helm_values_targets): + @bash scripts/utils/render_helm_values.sh "$(@:helm-values-%=%)" + +.PHONY: install helm-install-all $(helm_install_targets) $(addprefix helm-install-,$(helm_stacks)) + +install: $(addprefix helm-install-,$(install_argument)) ## Install or upgrade (make install nifi-stack, defaults to all) + +# Full installs apply both runtime ConfigMaps during preparation. +helm_install_prepared := 0 + +helm-install-all: prepare + $(MAKE) helm-install-nifi-stack helm_install_prepared=1 + $(MAKE) helm-install-opensearch-stack helm_install_prepared=1 BOOTSTRAP_OPENSEARCH_SECURITY=0 + +ifneq ($(helm_install_prepared),1) +helm-install-nginx: k3s-load-env-nginx +helm-install-opensearch: k3s-load-env-opensearch +endif + +$(helm_install_targets): + @bash scripts/utils/helm_install.sh "$(@:helm-install-%=%)" + +helm-install-nifi-stack: helm-install-nifi $(MAKE) helm-install-nginx -helm-install-opensearch-stack: ## Install OpenSearch and then Dashboards +helm-install-opensearch-stack: @if [ "$${BOOTSTRAP_OPENSEARCH_SECURITY:-1}" = 1 ]; then \ - $(MAKE) k3s-load-auth-opensearch-dashboards && $(MAKE) k3s-bootstrap-opensearch; \ + $(MAKE) k3s-load-auth-opensearch-dashboards && $(MAKE) k3s-load-auth-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-uninstall-jupyter-hub -.PHONY: helm-delete-opensearch-volumes +.PHONY: uninstall 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-jupyter-hub: ## Uninstall standalone JupyterHub - -helm-uninstall-nifi helm-uninstall-nginx helm-uninstall-opensearch \ -helm-uninstall-opensearch-dashboards helm-uninstall-jupyter-hub: +uninstall: ## Uninstall a chart or stack (make uninstall nifi-stack) and retain PVCs @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 + chart="$(uninstall_argument)"; \ + case "$$chart" in \ + nifi-stack) releases=(cogstack-nginx cogstack-nifi);; \ + opensearch-stack) releases=(opensearch-dashboards opensearch);; \ + nifi|nginx) releases=("cogstack-$$chart");; \ + *) releases=("$$chart");; \ + esac; \ + $(load_kube_namespace); \ + for release in "$${releases[@]}"; do \ + helm uninstall "$$release" -n "$$namespace" --ignore-not-found \ + --cascade foreground --wait --timeout "$${HELM_TIMEOUT:-10m}"; \ + done 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}"; \ + $(load_kube_namespace); \ 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-config.mk b/deployment/make/k3s-config.mk new file mode 100644 index 00000000..2c549635 --- /dev/null +++ b/deployment/make/k3s-config.mk @@ -0,0 +1,68 @@ +# Kubernetes configuration + +.PHONY: prepare + +prepare: ## Render values and apply TLS, runtime, and auth resources for both stacks + $(MAKE) helm-values-all + $(MAKE) k3s-load-certs-all + $(MAKE) k3s-load-env-all + $(MAKE) k3s-load-auth-all + +tls_targets := $(addprefix k3s-load-certs-,all $(k3s_runtime_services)) +.PHONY: k3s-load-certs $(tls_targets) + +k3s-load-certs: $(addprefix k3s-load-certs-,$(k3s-load-certs_argument)) ## Apply TLS Secrets (make k3s-load-certs nginx, defaults to all) + +$(tls_targets): + @$(cert_script) load $(@:k3s-load-certs-%=%) + +auth_targets := $(addprefix k3s-load-auth-,all $(k3s_auth_services)) +.PHONY: k3s-load-auth $(auth_targets) + +k3s-load-auth: $(addprefix k3s-load-auth-,$(k3s-load-auth_argument)) ## Apply authentication Secrets (make k3s-load-auth nifi, defaults to all) + +# Load Dashboards before OpenSearch so they share the service account password. +$(auth_targets): + @set -e; \ + services=$(@:k3s-load-auth-%=%); \ + if [ "$$services" = all ]; then services="$(k3s_auth_services)"; fi; \ + for service in $$services; do \ + case "$$service" in \ + nifi) bash scripts/security/load_nifi_auth.sh;; \ + *) bash scripts/security/load_opensearch_auth.sh "$$service";; \ + esac; \ + done + +.PHONY: k3s-delete-auth + +k3s-delete-auth: ## Delete authentication Secrets for a service (make k3s-delete-auth nifi) + @set -e; \ + $(load_kube_namespace); \ + case "$(k3s-delete-auth_argument)" in \ + nifi) secrets=(nifi-auth);; \ + opensearch) secrets=(opensearch-security-bootstrap);; \ + opensearch-dashboards) secrets=(dashboards-auth);; \ + all) secrets=(nifi-auth opensearch-security-bootstrap dashboards-auth);; \ + esac; \ + kubectl -n "$$namespace" delete secret "$${secrets[@]}" --ignore-not-found + +env_targets := $(addprefix k3s-load-env-,$(k3s_runtime_services)) +.PHONY: k3s-load-env k3s-load-env-all $(env_targets) + +k3s-load-env: $(addprefix k3s-load-env-,$(k3s-load-env_argument)) ## Apply runtime ConfigMaps (make k3s-load-env nginx, defaults to all) + +k3s-load-env-all: $(env_targets) + +$(env_targets): + @set -eo pipefail; \ + $(load_kube_namespace); \ + 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 - diff --git a/deployment/make/k3s.mk b/deployment/make/k3s.mk deleted file mode 100644 index fa773e89..00000000 --- a/deployment/make/k3s.mk +++ /dev/null @@ -1,68 +0,0 @@ -# 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 index 778deb87..efab2a9a 100644 --- a/deployment/make/setup.mk +++ b/deployment/make/setup.mk @@ -2,10 +2,10 @@ .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 +setup-install-pre-requisites: bash scripts/installation_utils/install_os_tools_and_software.sh -setup-k3s-cluster-init: ## Initialize the first K3s server on this machine +setup-k3s-cluster-init: 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 @@ -13,8 +13,8 @@ setup-k3s-cluster-remote: ## Install prerequisites, initialize the first server, 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 | \ + $(load_kube_namespace); \ + kubectl create namespace "$$namespace" --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 diff --git a/deployment/scripts/README.md b/deployment/scripts/README.md index c848e9ec..5c1ea3ac 100644 --- a/deployment/scripts/README.md +++ b/deployment/scripts/README.md @@ -18,10 +18,15 @@ or the generator's configuration. The Makefile loads `deployment/env/certificates.env` for certificate generation and loading. Choose a bundle when generating fresh certificates. -| Target | Certificates | +| Command | Certificates | | --- | --- | -| `certs-k3s` | CA, NGINX HTTPS, and OpenSearch transport | -| `certs-all` | K3s bundle plus the NiFi, OpenSearch admin, and Dashboards certificates for Docker | +| `make -C deployment cert` | CA, NGINX HTTPS, and OpenSearch transport | +| `make -C deployment cert all` | K3s bundle plus the NiFi, OpenSearch admin, and Dashboards certificates for Docker | +| `make -C deployment cert root` | Root CA | +| `make -C deployment cert nifi` | NiFi certificate and stores using the existing CA | +| `make -C deployment cert nginx` | NGINX HTTPS certificate using the existing CA | +| `make -C deployment cert opensearch` | Shared OpenSearch transport and admin client certificates | +| `make -C deployment cert opensearch-nodes NODES="node1 node2"` | OpenSearch node certificates using the existing CA | For a direct invocation of the root CA generator, load the file to use its sample store password. @@ -96,7 +101,7 @@ 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`. +Load them with `make -C deployment k3s-load-certs`. ## Install, initialize and verify diff --git a/deployment/scripts/security/certificates.sh b/deployment/scripts/security/certificates.sh new file mode 100644 index 00000000..e3365b87 --- /dev/null +++ b/deployment/scripts/security/certificates.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +set -eo pipefail + +# Make orders the certificate prerequisites in make/certs.mk. +CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." + +action=${1:?Set a certificate action} +case "$action" in + k3s|all|load) + # shellcheck source=../../env/general.env + source env/general.env + export CLUSTER_DOMAIN KUBE_NAMESPACE="${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" + ;; +esac +if [[ "$action" != nifi && -f env/certificates.env ]]; then + set -a + # shellcheck source=../../env/certificates.env + source env/certificates.env + set +a +fi +certs_dir="${SECURITY_DIR:-security}/certificates" + +create_shared_opensearch() { + local service=opensearch-cluster-master + local service_dns="$service.${KUBE_NAMESPACE:-search}.svc" + + OPENSEARCH_NODE_DNS_NAMES="${OPENSEARCH_NODE_DNS_NAMES:-localhost,$service,$service_dns,$service_dns.${CLUSTER_DOMAIN:-cluster.local}}" \ + bash scripts/security/create_opensearch_node_cert.sh opensearch-shared +} + +case "$action" in + root) bash scripts/security/create_root_ca_cert.sh ;; + nifi) bash scripts/security/create_nifi_certs.sh ;; + nginx) bash scripts/security/create_nginx_certs.sh ;; + opensearch) bash scripts/security/create_opensearch_client_admin_certs.sh --admin-only ;; + opensearch-shared) create_shared_opensearch ;; + opensearch-nodes) + read -r -a nodes <<< "${NODES:-}" + bash scripts/security/create_opensearch_node_cert.sh "${nodes[@]}" + ;; + k3s) + bash scripts/security/create_nginx_certs.sh + create_shared_opensearch + ;; + all) + bash scripts/security/create_nifi_certs.sh + OPENSEARCH_DASHBOARDS_DNS_NAMES="${OPENSEARCH_DASHBOARDS_DNS_NAMES:-localhost}" \ + bash scripts/security/create_opensearch_client_admin_certs.sh + ;; + load) + service=${2:-} + case "$service" in + all) services=(nginx opensearch) ;; + nginx|opensearch) services=("$service") ;; + *) printf 'Usage: make k3s-load-certs \n' >&2; exit 2 ;; + esac + manifests=() + for service in "${services[@]}"; do + case "$service" in + nginx) secret=(tls nginx-tls --cert="$certs_dir/nginx/tls.crt" --key="$certs_dir/nginx/tls.key") ;; + opensearch) secret=(generic opensearch-node-tls + --from-file="node.crt=$certs_dir/opensearch/opensearch-shared.crt" + --from-file="node.key=$certs_dir/opensearch/opensearch-shared.key" + --from-file="ca.crt=$certs_dir/opensearch/elastic-stack-ca.crt.pem") ;; + esac + manifest=$(kubectl -n "$KUBE_NAMESPACE" create secret "${secret[@]}" --dry-run=client -o yaml) + manifests+=("$manifest") + done + printf -- '---\n%s\n' "${manifests[@]}" | + kubectl -n "$KUBE_NAMESPACE" apply --server-side --field-manager=cogstack-certificates -f - + ;; + delete) + selection=${2:-} + case "$selection" in + all) targets=("$certs_dir"/{root,nifi,opensearch,nginx}) ;; + nifi|opensearch|nginx) targets=("$certs_dir/$selection") ;; + *) printf 'Usage: make delete-cert \n' >&2; exit 2 ;; + esac + if [[ -L "$certs_dir" ]]; then + printf 'Certificate directory is a symlink: %s\n' "$certs_dir" >&2 + exit 1 + fi + if [[ ! -t 0 ]]; then + printf 'Certificate deletion requires an interactive terminal.\n' >&2 + exit 1 + fi + read -r -p "Delete $selection certificate bundles in $certs_dir? [y/N] " answer + if [[ "$answer" == [yY] || "$answer" == [yY][eE][sS] ]]; then + rm -rf -- "${targets[@]}" + fi + ;; + *) printf 'Unknown certificate action %s.\n' "$action" >&2; exit 2 ;; +esac diff --git a/deployment/scripts/security/load_nifi_auth.sh b/deployment/scripts/security/load_nifi_auth.sh index 4a0cc38f..89ccdef2 100644 --- a/deployment/scripts/security/load_nifi_auth.sh +++ b/deployment/scripts/security/load_nifi_auth.sh @@ -1,55 +1,18 @@ #!/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" +CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." +source ./env/general.env +source ./env/authentication.env -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 -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 -salt=$(openssl rand -hex 8) -hash=$(openssl passwd -6 -salt "rounds=100000\$$salt" -stdin <<< "$password") -NIFI_HTPASSWD="$NIFI_SINGLE_USER_CREDENTIALS_USERNAME:$hash" +: "${KUBE_NAMESPACE:?Set KUBE_NAMESPACE}" \ + "${NIFI_SINGLE_USER_CREDENTIALS_USERNAME:?Set NIFI_SINGLE_USER_CREDENTIALS_USERNAME}" \ + "${NIFI_SINGLE_USER_CREDENTIALS_PASSWORD:?Set NIFI_SINGLE_USER_CREDENTIALS_PASSWORD}" \ + "${NIFI_SENSITIVE_PROPS_KEY:?Set NIFI_SENSITIVE_PROPS_KEY}" -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)}} -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: { - 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" replace -f - <<< "$manifest" -fi +kubectl -n "$KUBE_NAMESPACE" create secret generic nifi-auth \ + --from-literal="SINGLE_USER_CREDENTIALS_USERNAME=$NIFI_SINGLE_USER_CREDENTIALS_USERNAME" \ + --from-literal="SINGLE_USER_CREDENTIALS_PASSWORD=$NIFI_SINGLE_USER_CREDENTIALS_PASSWORD" \ + --from-literal="NIFI_SENSITIVE_PROPS_KEY=$NIFI_SENSITIVE_PROPS_KEY" \ + --dry-run=client -o yaml | + kubectl -n "$KUBE_NAMESPACE" apply -f - diff --git a/deployment/scripts/security/load_opensearch_auth.sh b/deployment/scripts/security/load_opensearch_auth.sh index 6b272ead..3ce78143 100644 --- a/deployment/scripts/security/load_opensearch_auth.sh +++ b/deployment/scripts/security/load_opensearch_auth.sh @@ -7,9 +7,9 @@ case "$service" in *) 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" +CDPATH='' cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." +source ./env/general.env +source ./env/authentication.env namespace="${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" if [[ "$service" == opensearch ]]; then bootstrap=$(kubectl -n "$namespace" get secret opensearch-security-bootstrap --ignore-not-found -o name) @@ -19,35 +19,18 @@ if [[ "$service" == opensearch ]]; then fi 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" - -OPENSEARCH_KIBANA_PASSWORD=${OPENSEARCH_KIBANA_PASSWORD:-${KIBANA_PASSWORD:-}} -existing= -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 "$OPENSEARCH_KIBANA_PASSWORD" && -n "$existing" ]]; then - # Append a character so command substitution preserves trailing newlines. - stored_password=$(jq -j '(.data.password // "" | @base64d) + "."' <<< "$existing") - OPENSEARCH_KIBANA_PASSWORD=${stored_password%.} -fi -require_password OPENSEARCH_KIBANA_PASSWORD +: "${OPENSEARCH_KIBANA_PASSWORD:?Set OPENSEARCH_KIBANA_PASSWORD in env/authentication.env}" if [[ "$service" == opensearch ]]; then - policy="$script_dir/../../charts/opensearch/security" + policy=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:-}") + passwords=("$OPENSEARCH_KIBANA_PASSWORD" "${OPENSEARCH_NIFI_PASSWORD:-}" + "${OPENSEARCH_PIPELINE_PASSWORD:-}" "${OPENSEARCH_ANALYST_PASSWORD:-}" "${OPENSEARCH_ADMIN_PASSWORD:-}") for i in "${!users[@]}"; do [[ -n "${passwords[i]}" ]] || continue - entry=$(bcrypt_entry "${users[i]}" "${passwords[i]}") || exit 1 + entry=$(printf '%s\n' "${passwords[i]}" | htpasswd -nBi -C 10 -- "${users[i]}") || exit 1 printf '%s:\n hash: "%s"\n' "${users[i]}" "${entry#*:}" done ) @@ -63,12 +46,13 @@ if [[ "$service" == opensearch ]]; then exit fi +existing=$(kubectl -n "$namespace" get secret dashboards-auth --ignore-not-found -o json) 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 +export OPENSEARCH_KIBANA_PASSWORD DASHBOARDS_COOKIE_DATA manifest=$(jq -s '.[0] | { apiVersion: "v1", kind: "Secret", type: "Opaque", diff --git a/deployment/scripts/utils/helm_install.sh b/deployment/scripts/utils/helm_install.sh new file mode 100644 index 00000000..2263beca --- /dev/null +++ b/deployment/scripts/utils/helm_install.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -eo pipefail + +. ./env/general.env +namespace="${KUBE_NAMESPACE:?Set KUBE_NAMESPACE in env/general.env}" +chart_name=${1:?Set a chart name} +chart="charts/$chart_name" +release="$chart_name" +args=() + +case "$chart_name" in + nifi|nginx) + release="cogstack-$chart_name" + ;; + opensearch|opensearch-dashboards) + helm repo add opensearch https://opensearch-project.github.io/helm-charts/ + helm dependency build "$chart" + ;; + jupyter-hub) + build_dir=$(mktemp -d "${TMPDIR:-/tmp}/cogstack-jupyter-hub.XXXXXX") + trap 'rm -rf -- "$build_dir"' EXIT + cp -R "$chart" "$build_dir/" + chart="$build_dir/$chart_name" + chmod -R u+w "$chart" + helm repo add jupyterhub https://hub.jupyter.org/helm-chart/ + helm dependency build "$chart" + ;; +esac + +if [ "$chart_name" = 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[@]}" diff --git a/deployment/scripts/utils/render_helm_values.sh b/deployment/scripts/utils/render_helm_values.sh new file mode 100644 index 00000000..68bf4ce7 --- /dev/null +++ b/deployment/scripts/utils/render_helm_values.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash +set -eo pipefail + +service=${1:?Set a chart name} +env_file="./env/$service.env" +set -a +if [[ "$service" == nginx || "$service" == opensearch-dashboards ]]; then + . ./env/opensearch.env +fi +if [ "$service" = nginx ]; then + . ./env/opensearch-dashboards.env + : "${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='[]' + export NIFI_K3S_FLOWFILE_VOLUME_SIZE="${NIFI_K3S_FLOWFILE_VOLUME_SIZE:-20Gi}" + export NIFI_K3S_CONTENT_VOLUME_SIZE="${NIFI_K3S_CONTENT_VOLUME_SIZE:-100Gi}" + export NIFI_K3S_PROVENANCE_VOLUME_SIZE="${NIFI_K3S_PROVENANCE_VOLUME_SIZE:-50Gi}" + export NIFI_K3S_DATABASE_VOLUME_SIZE="${NIFI_K3S_DATABASE_VOLUME_SIZE:-5Gi}" + export NIFI_K3S_STATE_VOLUME_SIZE="${NIFI_K3S_STATE_VOLUME_SIZE:-5Gi}" + export NIFI_K3S_CONF_VOLUME_SIZE="${NIFI_K3S_CONF_VOLUME_SIZE:-5Gi}" + export NIFI_K3S_STORAGE_CLASS_YAML=null + if [ -n "${NIFI_K3S_STORAGE_CLASS:-}" ]; then + printf -v NIFI_K3S_STORAGE_CLASS_YAML '"%s"' "$NIFI_K3S_STORAGE_CLASS" + fi + ;; + opensearch) + node_setting=OPENSEARCH_K3S_BLACKLIST + export OPENSEARCH_K3S_NODE_AFFINITY='{}' + export OPENSEARCH_K3S_VOLUME_SIZE="${OPENSEARCH_K3S_VOLUME_SIZE:-8Gi}" + ;; + *) 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 + if [ "$name" = OPENSEARCH_K3S_STORAGE_CLASS ]; then continue; fi + 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"