Quickstart
The quickstart is one file, compose.yaml, which runs the FerroSMART image
beside PostgreSQL. It needs Docker with Compose and no checkout of the
repository. It pulls ghcr.io/ferrohealth/ferrosmart at the release the
file shipped with, v0.3.0 (the image).
Run it
Download compose.yaml from the repository or from a release, and create
the three secret files beside it. FerroSMART runs as uid 65532, so the two
files it reads must be readable by that user:
mkdir -p secrets
openssl rand -hex 24 > secrets/postgres_password
printf 'postgresql://ferrosmart:%s@postgres:5432/ferrosmart?sslmode=disable' \
"$(cat secrets/postgres_password)" > secrets/database_url
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out secrets/signing_key.pem
chmod 0644 secrets/database_url secrets/signing_key.pem
docker compose up
FerroSMART migrates its database at start. Read its SMART configuration:
curl http://localhost:8080/.well-known/smart-configuration
With no identity provider configured, this is the Backend Services document: FerroSMART issues tokens to registered systems and nobody logs in.
What the file sets
The environment of the ferrosmart service sets the issuer, the signing
key, the database URL and one FHIR server. Two variables change the
defaults, in your shell or a .env file beside compose.yaml:
| Variable | Default | What it is |
|---|---|---|
FERROSMART_ISSUER | http://localhost:8080 | The URL clients and resource servers reach FerroSMART by: https, or http on a loopback host |
FERROSMART_RESOURCE | http://localhost:8090/fhir | The base URL of the FHIR server the tokens are for, their aud |
Everything else goes in a configuration file in the config directory,
which FERROSMART_CONFIG names. A Backend Services client with its JWK Set
URL:
mkdir -p config
cat > config/ferrosmart.toml <<'TOML'
[[ferrosmart.client]]
client_id = "bulk-export"
name = "Bulk export"
kind = "confidential_asymmetric"
resources = ["http://localhost:8090/fhir"]
jwks_uri = "https://export.example.org/jwks.json"
scopes = ["system/Patient.rs", "system/Observation.rs"]
grant_types = ["client_credentials"]
TOML
FERROSMART_CONFIG=/etc/ferrosmart/ferrosmart.toml docker compose up
The environment wins over the file. docker compose run --rm ferrosmart config check prints the configuration as FerroSMART reads it, every secret
masked. Configuration lists every key.
Add a login
To have people log in, run an identity provider upstream. The repository carries two overlays of this file that do it on your machine:
docker compose -f compose.yaml -f compose.keycloak.yaml up
docker compose -f compose.yaml -f compose.zitadel.yaml up
Each needs a few more secret files, listed at the top of the overlay, and a checkout of the repository for its realm file or bootstrap script. Identity providers describes both, and Entra ID and Okta.
The hardening the file applies
- The port binds loopback. A published port on
0.0.0.0is reachable from the network even when the host firewall says otherwise, so the file binds127.0.0.1. To serve other machines, put a reverse proxy that terminates TLS in front and setFERROSMART_ISSUERto itshttpsURL. - A read-only root. Every piece of state is in PostgreSQL and every secret is read once at start, so the container’s filesystem is read-only.
- No capabilities. FerroSMART drops every Linux capability and cannot
gain new privileges. PostgreSQL keeps the five its entrypoint needs to
hand its data directory to the
postgresuser, and publishes no port. - Secrets as files. The database password, the database URL and the signing key are Compose secrets, never environment values.
The whole file
# SPDX-FileCopyrightText: Cadasto B.V.
# SPDX-License-Identifier: BUSL-1.1
#
# The FerroSMART quickstart, a standalone file: download it, create the
# secret files beside it, and run
#
# docker compose up
# curl http://localhost:8080/.well-known/smart-configuration
#
# It pulls the published image (ghcr.io/ferrohealth/ferrosmart, pinned to the
# release this file shipped with) beside PostgreSQL, and needs no repository
# checkout. The release plan refuses a tag whose version differs from the
# default below (scripts/release/plan.sh, check_compose_pin).
#
# SECRETS. Three files under ./secrets are yours to create before the first
# `docker compose up`; compose refuses to start a service whose secret is
# missing. Compose mounts each file as it is on the host, and FerroSMART runs
# as uid 65532, so make the two it reads readable to that user. Never commit
# them.
#
# mkdir -p secrets
# openssl rand -hex 24 > secrets/postgres_password
# printf 'postgresql://ferrosmart:%s@postgres:5432/ferrosmart?sslmode=disable' \
# "$(cat secrets/postgres_password)" > secrets/database_url
# openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:3072 -out secrets/signing_key.pem
# chmod 0644 secrets/database_url secrets/signing_key.pem
#
# The signing key signs every access token under RS256 and is published,
# public half only, at the `jwks_uri` of the SMART configuration. Rotation
# adds a next and a previous key ([ferrosmart.keys], in the configuration
# file below).
#
# CONFIGURATION. The environment below sets what the quickstart needs, and
# every key of the configuration tree is reachable the same way, as
# FERROSMART__<SECTION>__<KEY>, with an index naming an element of an array
# of tables. Set these in your shell or in a .env file beside this one:
#
# FERROSMART_ISSUER the URL clients and resource servers reach
# FerroSMART by: https, or http on localhost
# (default http://localhost:8080)
# FERROSMART_RESOURCE the base URL of the FHIR server the tokens are for,
# their `aud` (default http://localhost:8090/fhir)
#
# Clients, more resource servers and the rest of the policy go in a
# configuration file in the ./config directory beside this one, which
# FERROSMART_CONFIG names. A Backend Services client with its JWK Set URL:
#
# mkdir -p config
# cat > config/ferrosmart.toml <<'TOML'
# [[ferrosmart.client]]
# client_id = "bulk-export"
# name = "Bulk export"
# kind = "confidential_asymmetric"
# jwks_uri = "https://export.example.org/jwks.json"
# resources = ["http://localhost:8090/fhir"]
# scopes = ["system/Patient.rs", "system/Observation.rs"]
# grant_types = ["client_credentials"]
# TOML
# FERROSMART_CONFIG=/etc/ferrosmart/ferrosmart.toml
#
# The environment wins over the file. `docker compose run --rm ferrosmart
# config check` prints the resolved configuration with every secret masked.
#
# PORTS. The published port binds the loopback interface by default. A
# published port is DNAT'd ahead of the host firewall's own chains, so a port
# on 0.0.0.0 is reachable from the network even when the firewall says
# otherwise (https://docs.docker.com/engine/network/packet-filtering-firewalls/).
# To serve another machine, put a reverse proxy that terminates TLS in front
# and set FERROSMART_ISSUER to its https URL.
#
# HEALTH. The image's HEALTHCHECK runs `ferrosmart healthcheck`, which asks the
# server for GET /health/readiness on loopback and exits 0 only on 200, so
# `docker compose ps` shows FerroSMART healthy once it serves and its database
# answers.
# Without this the project is named after the directory the file sits in.
name: ferrosmart
services:
ferrosmart:
image: ghcr.io/ferrohealth/ferrosmart:${FERROSMART_VERSION:-0.3.0}
container_name: ferrosmart
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
ports:
- "${FERROSMART_BIND_HOST:-127.0.0.1}:${FERROSMART_PORT:-8080}:8080"
environment:
# A key with no value passes the variable through only when your shell
# or .env sets it, so no file is read until you write one.
FERROSMART_CONFIG:
FERROSMART__FERROSMART__ISSUER: ${FERROSMART_ISSUER:-http://localhost:8080}
FERROSMART__FERROSMART__KEYS__PRIVATE_KEY_FILE: /run/secrets/signing_key
FERROSMART__FERROSMART__DATABASE__URL_FILE: /run/secrets/database_url
FERROSMART__FERROSMART__RESOURCE__0__BASE: ${FERROSMART_RESOURCE:-http://localhost:8090/fhir}
FERROSMART__FERROSMART__RESOURCE__0__KIND: fhir
# `auto` renders pretty output on a terminal and JSON otherwise.
FERROSMART__TELEMETRY__FORMAT: ${FERROSMART_LOG_FORMAT:-auto}
FERROSMART__TELEMETRY__FILTER: ${FERROSMART_LOG_FILTER:-info}
secrets:
- database_url
- signing_key
# Every piece of state lives in PostgreSQL and every secret is read once
# at boot, so the root filesystem is read-only and nothing is mounted
# writable.
read_only: true
volumes:
- type: bind
source: ${FERROSMART_CONFIG_DIR:-./config}
target: /etc/ferrosmart
read_only: true
bind:
create_host_path: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
# The store of every client, token record and assertion id. FerroSMART
# migrates it at start. The password never reaches the environment: the
# official image reads POSTGRES_PASSWORD_FILE.
postgres:
image: postgres:19.0@sha256:bb6e70add742cd868fb62cb3b2f67d1dd2bdd2b65a521e778420748753687c60
container_name: ferrosmart-postgres
restart: unless-stopped
environment:
POSTGRES_DB: ferrosmart
POSTGRES_USER: ferrosmart
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
secrets:
- postgres_password
volumes:
- postgres-data:/var/lib/postgresql
healthcheck:
test: ["CMD", "pg_isready", "-U", "ferrosmart", "-d", "ferrosmart"]
interval: 5s
timeout: 5s
retries: 12
# The entrypoint starts as root to own the data directory, then drops to
# the postgres user, so it keeps the capabilities that hand-over needs.
cap_drop:
- ALL
cap_add:
- CHOWN
- DAC_OVERRIDE
- FOWNER
- SETGID
- SETUID
security_opt:
- no-new-privileges:true
# No published port: only FerroSMART reaches the database.
secrets:
postgres_password:
file: ./secrets/postgres_password
database_url:
file: ./secrets/database_url
signing_key:
file: ./secrets/signing_key.pem
volumes:
postgres-data: