Skip to content

Commit 8db87c2

Browse files
Feature/m8 f 159 cleanup ticket (#88)
* M8F-89: [Feature] Update docker files to setup and run the application correctly * M8F-89: [Feature] Removed unnecessary migrate script * Docker setup completed * Dockeker working * Create a service that initializes the keycloak realms * Removed unnecessary logic from backend * M8F-89: [Feature] Updated docker compose to run keycloak realm setup on start * User non root user in docker * M8F-89: [Feature] Updated document and removed unnecessary script * M8F-89: [Feature] fix: Keycloak theme CLI opts; add healthcheck and backend depends_on keycloak healthy * M8F-89: [Feature] Run images with non-root default user * Docker Deployed * Deployment workking * Cleanup logs and minor optimization * M8F-89: [Feature] Updated tenant creation to use domain from env * Updated Sample env * Fixed issues with minio deployment * Opened messages and health_check APIs * M8F-89: [Feature] Fixed PR comments * M8F-89: [Feature] Fixed the docker compose builds * Conflicts resolved * AWS Deployment fixed * Added Guards to keycloak_service.py and cookie_path_patch.py * Moved out changes in spiffworkflow-frontend/bin/boot_server_in_docker * Commented realm import * Fixed Issues with Roles, Nats container * keycloak-entrypoint.sh Updated defaults for SUPERADMIN_USER and SUPERADMIN_PASS * Fix line endings in entrypoint script for compatibility.Updated backend configuration in sample.env to change ports and URLs for local development. * PR comments * Fixed Routing issues for keycloak * M8F-159: [Feature] Uncommented necessary lines from sample.env * M8F-159: [Feature] Updated sample.env to use localhost instead of LOCAL_IP * M8F-159: [Feature] Made changes According to PR comments -Changed /health to /ping -Updated documentation and comments * M8F-159: [Feature] Moved comments form sample.env to relevant docs * M8F-159: [Feature] Removed unused line of code --------- Co-authored-by: auslin-aot <99173163+auslin-aot@users.noreply.github.com>
1 parent edce0e5 commit 8db87c2

File tree

10 files changed

+65
-33
lines changed

10 files changed

+65
-33
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ A sample environment file is provided at the repository root. Create a working e
7777
cp sample.env .env
7878
```
7979

80-
Edit the `.env` file if adjustments are required for the local setup. Key tenancy options (`M8FLOW_DEFAULT_TENANT_ID`, `M8FLOW_ALLOW_MISSING_TENANT_CONTEXT`, `M8FLOW_TENANT_CLAIM`) are described in `sample.env`.
80+
Edit the `.env` file if adjustments are required for the local setup. **Environment variable meanings and examples** are documented in [docs/env-reference.md](docs/env-reference.md) (canonical reference; avoid duplicating long env explanations in this README). Variable names for tenancy and other areas also appear in `sample.env`.
8181

8282
---
8383

@@ -217,7 +217,7 @@ After the containers start, continue below to the Keycloak Setup to import the r
217217

218218
### Import Realm
219219

220-
You can import realms manually as below, or run `./extensions/m8flow-backend/keycloak/start_keycloak.sh` after starting Docker to import the identity realm and tenant-a.
220+
You can import realms by running `./extensions/m8flow-backend/keycloak/start_keycloak.sh` after starting Docker to import the identity realm.
221221

222222
In the Keycloak Admin Console http://localhost:7002/ log in using the configured administrator credentials.
223223

@@ -232,6 +232,8 @@ Browse or copy the content of `extensions/m8flow-backend/keycloak/realm_exports/
232232
<img src="./docs/images/keycloak-realm-settings-2.png" />
233233
</div>
234234

235+
For Keycloak-related URL and issuer settings in `.env`, see [docs/env-reference.md](docs/env-reference.md) (Keycloak URLs).
236+
235237
### Configure Client
236238

237239
With the realm "spiffworkflow" selected, click on "Clients" and then on the client ID **spiffworkflow-backend**.

docker/DEPLOYMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export TAG="latest"
3737

3838
Ensure the image is built from the repo that includes the m8flow-backend extension (tenancy, Keycloak realm APIs, and support for `SPIFFWORKFLOW_BACKEND_WSGI_PATH_PREFIX` and `M8FLOW_KEYCLOAK_ADMIN_PASSWORD`). ECS expects the API under `/api/v1.0/*`.
3939

40-
The backend uses the Keycloak **superadmin** user by default (username `superadmin`, created by the Keycloak image entrypoint). Set `KEYCLOAK_ADMIN_PASSWORD` or `M8FLOW_KEYCLOAK_ADMIN_PASSWORD` to the superadmin password (same as `KEYCLOAK_SUPERADMIN_PASSWORD` when using the Keycloak image entrypoint) so the backend can create realms and run partial import.
40+
The backend uses the Keycloak **super-admin** user by default (username `super-admin`, created by the Keycloak image entrypoint). Set `KEYCLOAK_ADMIN_PASSWORD` or `M8FLOW_KEYCLOAK_ADMIN_PASSWORD` to the super-admin password (same as `KEYCLOAK_SUPERADMIN_PASSWORD` when using the Keycloak image entrypoint) so the backend can create realms and run partial import.
4141

4242
Build the production backend image (target `prod`, `linux/amd64` for ECS):
4343

docker/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This directory contains the Docker setup for running M8Flow: Compose files, Dockerfiles for app services, and the Keycloak reverse-proxy config.
44

5+
**Environment variables:** Full meanings and examples live in [docs/env-reference.md](../docs/env-reference.md). This README only adds Docker Compose–specific behavior; do not duplicate the env reference here.
6+
57
---
68

79
## File reference
@@ -100,6 +102,8 @@ Use with: `docker compose -f docker/m8flow-docker-compose.yml -f docker/m8flow-d
100102

101103
Set production values in `.env` (e.g. `KEYCLOAK_HOSTNAME`, `M8FLOW_BACKEND_DATABASE_URI`, secrets) before running.
102104

105+
**Docker Compose caveat:** The `m8flow-backend` service sets `KEYCLOAK_URL` and `M8FLOW_KEYCLOAK_URL` to `http://keycloak-proxy:7002` so server-side calls use the proxy, while browsers use the public URL (often `http://localhost:7002` or `http://<host>:7002`). For all other env semantics, see [docs/env-reference.md](../docs/env-reference.md).
106+
103107
---
104108

105109
## Non-root and ports

docs/env-reference.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Environment variable reference
2+
3+
This file is the **canonical** place for environment variable meanings and examples. The root [README.md](../README.md) and [docker/README.md](../docker/README.md) link here instead of repeating full definitions, to reduce drift.
4+
5+
## Keycloak URLs
6+
7+
- `KEYCLOAK_HOSTNAME`: Browser/public base URL used to reach Keycloak (for example `http://localhost:7002`). If clients access from another machine, use `http://<host>:7002` (or your real hostname and port).
8+
- `KEYCLOAK_HOSTNAME_URL`: Public Keycloak base URL Keycloak uses for token issuer (`iss`). In this repo’s Docker Compose, `KC_HOSTNAME_URL` is wired from `KEYCLOAK_HOSTNAME`; set `KEYCLOAK_HOSTNAME` consistently with how users reach Keycloak.
9+
- `KEYCLOAK_HOSTNAME_HOST` (optional): Hostname segment passed to Keycloak as `KC_HOSTNAME` in [docker/m8flow-docker-compose.yml](../docker/m8flow-docker-compose.yml) (default `localhost`). Adjust if your deployment needs a different hostname for Keycloak’s own hostname configuration.
10+
- `KEYCLOAK_URL` / `M8FLOW_KEYCLOAK_URL`: Backend URL for Keycloak Admin/API calls. **Docker Compose:** set by compose to `http://keycloak-proxy:7002` for `m8flow-backend` (internal network). **Local dev:** often `http://localhost:7002` to match the proxy port on the host.
11+
- `M8FLOW_APP_PUBLIC_BASE_URL` (optional): Set when the app and Keycloak are exposed on different public hosts. If unset, `KEYCLOAK_HOSTNAME` is used for generated app-facing URLs where applicable.
12+
13+
## Connector attachment paths
14+
15+
For SMTP and Slack connectors:
16+
17+
- `*_ATTACHMENTS_DIR`: Host/source path where files are read from.
18+
- `*_ATTACHMENTS_USER_ACCESS_DIR`: User-visible mounted path used in service-task file selection.
19+
20+
Examples:
21+
22+
- `M8FLOW_CONNECTOR_SMTP_ATTACHMENTS_DIR=../email_attachments`
23+
- `M8FLOW_CONNECTOR_SMTP_ATTACHMENTS_USER_ACCESS_DIR=/email_attachments`
24+
- `M8FLOW_CONNECTOR_SLACK_ATTACHMENTS_DIR=../slack_attachments`
25+
- `M8FLOW_CONNECTOR_SLACK_ATTACHMENTS_USER_ACCESS_DIR=/slack_attachments`
26+
27+
## Advanced Keycloak auth configs
28+
29+
For `SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS` patterns (master realm, `admin-cli`, role mapping), see [extensions/m8flow-backend/keycloak/KEYCLOAK_SETUP.md](../extensions/m8flow-backend/keycloak/KEYCLOAK_SETUP.md).

extensions/m8flow-backend/bin/run_m8flow_backend.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ fi
3838

3939
export SPIFFWORKFLOW_BACKEND_DATABASE_URI="${M8FLOW_BACKEND_DATABASE_URI}"
4040
export SPIFFWORKFLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR="${M8FLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR}"
41-
export SPIFFWORKFLOW_BACKEND_RUN_DATA_SETUP="${SPIFFWORKFLOW_BACKEND_RUN_DATA_SETUP:-false}"
4241

4342
if [[ "${M8FLOW_BACKEND_UPGRADE_DB:-true}" != "false" ]]; then
4443
cd "$repo_root/spiffworkflow-backend"

extensions/m8flow-backend/src/m8flow_backend/api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ info:
33
version: 1.0.0
44
title: m8flow-backend-extension
55
paths:
6-
/health:
6+
/ping:
77
get:
88
summary: Health check for load balancers and monitoring
99
description: Returns 200 when the process is up. Public, no authentication required.

extensions/m8flow-backend/src/m8flow_backend/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def keycloak_public_issuer_base() -> str:
3030

3131

3232
def keycloak_admin_user() -> str:
33-
"""Master realm admin username (default: super-admin, created by Keycloak entrypoint)."""
34-
return _get("KEYCLOAK_ADMIN_USER") or _get("M8FLOW_KEYCLOAK_ADMIN_USER") or "super-admin"
33+
"""Master realm admin username (default is created by Keycloak entrypoint)."""
34+
return _get("KEYCLOAK_ADMIN_USER") or _get("M8FLOW_KEYCLOAK_ADMIN_USER")
3535

3636

3737
def keycloak_admin_password() -> str:

extensions/m8flow-backend/src/m8flow_backend/tenancy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
TENANT_CONTEXT_EXEMPT_PATH_PREFIXES: tuple[str, ...] = (
2929
"/.well-known",
3030
"/favicon.ico",
31-
"/v1.0/health",
31+
"/v1.0/ping",
3232
"/v1.0/healthy",
3333
"/v1.0/status",
3434
"/v1.0/openapi.json",

extensions/m8flow-backend/src/m8flow_backend/utils/openapi_merge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def unified_add_api(self, specification, **kwargs):
3535

3636
# 3. Define extension path prefix and root-level paths (no prefix)
3737
ext_prefix = "/m8flow"
38-
ROOT_LEVEL_EXTENSION_PATHS = ("/health",)
38+
ROOT_LEVEL_EXTENSION_PATHS = ("/ping",)
3939

4040
# 4. Merge Paths - keep core paths unchanged, add extension paths with prefix
4141
# Core paths remain as-is; root-level extension paths stay as-is, others get /m8flow prefix

sample.env

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ M8FLOW_BACKEND_BPMN_SPEC_ABSOLUTE_DIR=./process_models
3939
M8FLOW_TEMPLATES_STORAGE_DIR=./templates
4040

4141
# --- Auth (OIDC / Keycloak) ---
42-
# KEYCLOAK_HOSTNAME=http://localhost:7002 # URL used to reach Keycloak; set to http://<host>:7002 when accessing from another machine
43-
# KEYCLOAK_HOSTNAME_URL=http://localhost:7002 # Public Keycloak base URL; tokens use this as issuer (iss)
44-
# With Docker Compose, KEYCLOAK_URL is set to http://keycloak-proxy:7002 so the backend uses the proxy.
42+
# KEYCLOAK_HOSTNAME=http://localhost:7002
43+
# KEYCLOAK_HOSTNAME_URL=http://localhost:7002
44+
# See docs: README Keycloak Setup (hostname/issuer notes).
4545
M8FLOW_KEYCLOAK_URL=http://localhost:7002
4646
M8FLOW_BACKEND_OPEN_ID_SERVER_URL=http://localhost:7002/realms/spiffworkflow
4747
M8FLOW_BACKEND_OPEN_ID_CLIENT_ID=spiffworkflow-backend
@@ -54,10 +54,8 @@ M8FLOW_KEYCLOAK_SPOKE_KEYSTORE_P12=extensions/m8flow-backend/keystore.p12
5454
# Keystore password; required for tenant login flow when using spoke keystore.
5555
M8FLOW_KEYCLOAK_SPOKE_KEYSTORE_PASSWORD=
5656

57-
# Optional: SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS for Keycloak (identifier should match frontend cookie).
58-
# For master-realm super-admin browser access, add a second config: identifier=master, uri=.../realms/master.
59-
# If you also use API-style admin-cli tokens, add additional_valid_client_ids=admin-cli; the backend can map
60-
# matching M8Flow realm roles from realm_access.roles when no groups claim is present.
57+
# Optional Keycloak auth configs (identifier should match frontend cookie).
58+
# Advanced master/admin-cli config notes: extensions/m8flow-backend/keycloak/KEYCLOAK_SETUP.md
6159
SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__identifier=spiffworkflow-local
6260
SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__label=Keycloak
6361
SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__0__uri=http://localhost:7002/realms/spiffworkflow-local
@@ -69,7 +67,7 @@ SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__client_id=spiffworkflow-backend
6967
SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__client_secret=JXeQExm0JhQPLumgHtIIqf52bDalHz0q
7068
SPIFFWORKFLOW_BACKEND_AUTH_CONFIGS__1__additional_valid_client_ids=admin-cli
7169
SPIFFWORKFLOW_BACKEND_OPEN_ID_ADDITIONAL_VALID_ISSUERS=http://localhost:7002/realms/master,http://localhost:7002/realms/m8flow
72-
# Optional local-development bootstrap for the master realm browser client and global admin user.
70+
# Optional local bootstrap for master realm browser client and global admin user.
7371
# M8FLOW_KEYCLOAK_MASTER_CLIENT_SECRET=JXeQExm0JhQPLumgHtIIqf52bDalHz0q
7472
# KEYCLOAK_SUPER_ADMIN_USER=super-admin
7573
# KEYCLOAK_SUPER_ADMIN_PASSWORD=super-admin
@@ -78,7 +76,7 @@ SPIFFWORKFLOW_BACKEND_OPEN_ID_ADDITIONAL_VALID_ISSUERS=http://localhost:7002/rea
7876
M8FLOW_BACKEND_CELERY_ENABLED=true
7977
M8FLOW_BACKEND_CELERY_BROKER_URL=redis://localhost:6379/0
8078
M8FLOW_BACKEND_CELERY_RESULT_BACKEND=redis://localhost:6379/0
81-
# Backend/API should be false; the worker/flower launchers override this inside their own containers.
79+
# Keep false for backend/API; worker and flower launchers override.
8280
# M8FLOW_BACKEND_RUNNING_IN_CELERY_WORKER=false
8381
M8FLOW_BACKEND_RUN_BACKGROUND_SCHEDULER_IN_CREATE_APP=true
8482
M8FLOW_BACKEND_CELERY_ENABLE_EVENTS=true
@@ -90,34 +88,34 @@ M8FLOW_BACKEND_CELERY_AUTOSCALE_MAX=4
9088
# M8FLOW_BACKEND_CELERY_CONCURRENCY=2
9189

9290
# ---Flower ---
93-
# Optional basic auth for Flower, format user:password (empty disables auth).
91+
# Optional Flower basic auth: user:password (empty disables).
9492
M8FLOW_BACKEND_CELERY_FLOWER_BASIC_AUTH=admin:admin
9593
# Optional worker/flower mount overrides.
9694
# M8FLOW_BACKEND_CELERY_PROCESS_MODELS_MOUNT_SOURCE=process_models_cache
9795

9896

9997
# --- Connector proxy ---
100-
# CONNECTOR_PROXY_PORT=8004
101-
# M8FLOW_BACKEND_CONNECTOR_PROXY_URL=http://localhost:8004
98+
CONNECTOR_PROXY_PORT=8004
99+
M8FLOW_BACKEND_CONNECTOR_PROXY_URL=http://localhost:8004
102100
# --- M8Flow Connector: SMTP ---
103-
# Local directory for connector to map attachments to.
101+
# SMTP attachment source dir (host path).
104102
M8FLOW_CONNECTOR_SMTP_ATTACHMENTS_DIR=../email_attachments
105-
# Mapped volume name for attachments directory. Users will select files from this directory when attaching files in the service task. E.g.: "/email_attachments/file.pdf".
103+
# SMTP attachment user-visible mount path in service tasks.
106104
M8FLOW_CONNECTOR_SMTP_ATTACHMENTS_USER_ACCESS_DIR=/email_attachments
107105
M8FLOW_CONNECTOR_SMTP_ATTACHMENTS_LIMIT_IN_MB=10
108106
M8FLOW_CONNECTOR_SMTP_TIMEOUT_SECONDS=300
109107

110108
# --- M8Flow Connector: Slack ---
111-
# Local directory for connector to map Slack attachments from (host path for sync).
109+
# Slack attachment source dir (host path).
112110
M8FLOW_CONNECTOR_SLACK_ATTACHMENTS_DIR=../slack_attachments
113-
# Mapped volume path for attachments directory. Users select files from this path when attaching in the service task. E.g.: "/slack_attachments/sample.txt".
111+
# Slack attachment user-visible mount path in service tasks.
114112
M8FLOW_CONNECTOR_SLACK_ATTACHMENTS_USER_ACCESS_DIR=/slack_attachments
115113
M8FLOW_CONNECTOR_SLACK_UPLOAD_FILE_LIMIT_MB=50
116114
# --- Permissions ---
117115
M8FLOW_BACKEND_PERMISSIONS_FILE_ABSOLUTE_PATH=./extensions/m8flow-backend/src/m8flow_backend/config/permissions/m8flow.yml
118116
#M8FLOW_BACKEND_PERMISSIONS_FILE_NAME=m8flow.yml
119117

120-
# Multitenant: true = tenant selection at / and /tenants/check; false = single-tenant.
118+
# Multitenant mode: true enables tenant selection routes.
121119
MULTI_TENANT_ON=false
122120

123121
# --- SQLAlchemy Logs ---
@@ -128,27 +126,27 @@ M8FLOW_BACKEND_ENCRYPTION_LIB=cryptography
128126
M8FLOW_BACKEND_ENCRYPTION_KEY=0123456789abcdef0123456789abcdef
129127

130128
# --- Tenancy ---
131-
# Default tenant id; one Keycloak realm per tenant.
129+
# Default tenant id.
132130
M8FLOW_DEFAULT_TENANT_ID=default
133131
M8FLOW_ALLOW_MISSING_TENANT_CONTEXT=true
134-
# JWT claim name for tenant id. Default: m8flow_tenant_id
132+
# JWT claim name for tenant id.
135133
# M8FLOW_TENANT_CLAIM=m8flow_tenant_id
136134

137135
# --- Keycloak ---
138136
KEYCLOAK_ADMIN=admin
139-
# Keycloak admin app: URL, realm, admin user. Backend accepts KEYCLOAK_URL (or M8FLOW_KEYCLOAK_URL).
140-
# Set KEYCLOAK_HOSTNAME to the URL users/browser use to reach Keycloak so the backend accepts the token iss claim (e.g. http://localhost:7002 or http://localhost:7002). Required when using Docker or a proxy.
137+
# Keycloak admin app settings.
138+
# See docs: README Keycloak Setup and docs/env-reference.md.
141139
KEYCLOAK_HOSTNAME=http://localhost:7002
142-
# When Keycloak and the app are on different hosts, set M8FLOW_APP_PUBLIC_BASE_URL (e.g. https://app.example.com or http://localhost:7001). When not set, KEYCLOAK_HOSTNAME is used.
140+
# Optional public app URL when app and Keycloak are on different hosts.
143141
# M8FLOW_APP_PUBLIC_BASE_URL=
144142
KEYCLOAK_URL=http://localhost:7002
145143
KEYCLOAK_REALM=tenant-a
146144
KEYCLOAK_ADMIN_USER=admin
147-
# Admin password for create-realm API (KEYCLOAK_ADMIN_PASSWORD or M8FLOW_KEYCLOAK_ADMIN_PASSWORD).
145+
# Admin password for create-realm API.
148146
KEYCLOAK_ADMIN_PASSWORD=admin
149147
KEYCLOAK_CLIENT_ID=my-backend-app
150148
KEYCLOAK_CLIENT_SECRET=
151-
# Optional mTLS: KEYCLOAK_CERT_FILE, KEYCLOAK_KEY_FILE.
149+
# Optional mTLS cert/key paths.
152150
# KEYCLOAK_CERT_FILE=
153151
# KEYCLOAK_KEY_FILE=
154152
# Keycloak DB (used by docker/m8flow-docker-compose.yml for keycloak-db and keycloak service)

0 commit comments

Comments
 (0)