GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - openctemio/openctem-ansible: Self-host OpenCTEM on a hardened VM with Ansible: signed images, Cloudflare Tunnel, encrypted backups

BranchesTags
Open more actions menu

Latest commit

 

History

92 Commits
92 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
inventories/example
inventories/example
 
 
playbooks
playbooks
 
 
roles
roles
 
 
scripts
scripts
 
 
tests
tests
 
 
.ansible-lint
.ansible-lint
 
 
.betterleaks.toml
.betterleaks.toml
 
 
.gitignore
.gitignore
 
 
.gitleaksignore
.gitleaksignore
 
 
.yamllint
.yamllint
 
 
CLA-CORPORATE.md
CLA-CORPORATE.md
 
 
CLA.md
CLA.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
ansible.cfg
ansible.cfg
 
 
requirements.yml
requirements.yml
 
 
site.yml
site.yml
 
 
versions.yml
versions.yml
 
 

Repository files navigation

OpenCTEM self-hosting with Ansible

Install and operate a self-hosted OpenCTEM platform on one Ubuntu VM: a hardened host, OpenCTEM (web console, API, gateway, PostgreSQL, Redis) from signed release images pinned by digest, Cloudflare Tunnel and Access in front, and encrypted daily backups with a tested restore. Every stage is opt-in, rehearsable with --check --diff, and keeps your site data outside this repository.

  • Target: Ubuntu 26.04 LTS (24.04 works for every role except the pinned Docker packages) or Rocky / Alma / RHEL 9, on any hypervisor or cloud VM. Raise either floor with openctem_min_ubuntu or openctem_min_rhel.
  • Controller: Linux or macOS with Python 3.11–3.13 and ansible-core 2.18.
  • Sensors are not installed here: they run elsewhere and connect to the platform through the same public URL.
flowchart LR
  user(["People (browser)"]) -->|"HTTPS + Access login"| cf
  sensor(["Sensors"]) -->|"HTTPS, Access bypass: /api/v2/sensor/*"| cf
  ci(["CI pipelines"]) -->|"HTTPS, Access bypass: /api/v1/ci/..."| cf
  cf["Cloudflare edge: TLS, Access, WAF rate limit"]
  subgraph vm["Ubuntu VM: no inbound port except SSH from admin CIDRs"]
    cfd["cloudflared"] -->|"tunnel network: http://gateway:80"| gw["gateway (plane routing)"]
    gw -->|"origin network"| web["web console"]
    gw -->|"origin network"| api["API"]
    web --> api
    api -->|"data network, TLS"| pg[("PostgreSQL")]
    api -->|"data network, TLS"| rd[("Redis")]
  end
  cfd -.->|"outbound tunnel, port 7844"| cf
Loading

Contents

  1. Prerequisites
  2. Quickstart (15 minutes)
  3. Full runbook
  4. First administrator
  5. Backups and restore drill
  6. Upgrade and rollback
  7. Troubleshooting
  8. Security model and hardening checklist
  9. Repository layout and tests

No Ansible on the target? ansible-playbook scripts/render-standalone.yml renders a directory that server runs with docker compose alone, and writes a NEXT-STEPS.md into it saying what this kit does that the plain stack does not.

Detailed references: Installation scenarios · Private registry · Deploy without Ansible · Cloudflare Tunnel and Access · Firewall · Mail relay · docs site page.

Step-by-step guides on the documentation site (they cover the same ground with more context, for both ways of serving OpenCTEM):

  • Install with Ansible: VM, controller, inventory, stages, backups, upgrade and rollback.
  • Deploy with Cloudflare Tunnel and Access: no inbound port.
  • Deploy without Cloudflare: your own TLS proxy, public (Let's Encrypt) or private (internal CA).

1. Prerequisites

Minimum Notes
VM 4 vCPU, 8 GB RAM (7 GB usable), 80 GB disk The default limits fit this size with ~1.5 GB left to the OS (below).
OS Ubuntu 26.04 LTS or Rocky/Alma/RHEL 9, fresh install, SSH reachable A sudo user (ubuntu), your SSH public key in its authorized_keys.
Console hypervisor console access to the VM for recovery if SSH breaks; take snapshots
DNS a zone on Cloudflare (any plan) one host name, e.g. ctem.example.com
Cloudflare Zero Trust (free tier is enough) with your identity provider docs/CLOUDFLARE-ACCESS.md
Backups an age key pair, kept OFF the server recommended; without it backups stay local and unencrypted

Memory budget (4 vCPU / 7 GB): PostgreSQL 2 GB (shared_buffers 512 MB), API 1.5 GB, web 768 MB, Redis 512 MB, gateway 256 MB, cloudflared 256 MB (job signer 128 MB): about 5.4 GB for containers. Change the openctem_mem_* and openctem_pg_* values in your inventory for a bigger host.

Without Cloudflare (optional): set openctem_ingress: loopback. The gateway then listens on 127.0.0.1:8080 (plain HTTP) for a TLS reverse proxy you run on the host (Caddy, nginx). You own TLS, client-address forwarding (the proxy must set X-Forwarded-For) and access control. For a proxy on another host, publish the port where it can reach it with openctem_loopback_bind and name that proxy in openctem_trusted_proxies: the port is plain HTTP, so the network is then the only thing in front of the application, and without the second setting every client address the platform records becomes the proxy's. Opening 443 in the firewall is then your change. Also set monitoring_external_probes: false (those probes assume Cloudflare). The guide Deploy without Cloudflare has a Caddyfile for a public host (Let's Encrypt) and for a private network (internal CA), the firewall rules and the checks.

Controller, not server. Run every ansible and ansible-playbook command on a controller (your workstation or an admin box), never on the VM you install: Ansible connects to the VM over SSH, and a firewall or SSH stage would cut your own session. The controller needs Python 3.11 to 3.13 and git, and must be able to SSH to the VM with a key.

2. Quickstart (15 minutes)

On the controller:

git clone https://github.com/openctemio/openctem-ansible.git && cd openctem-ansible
python3 -m venv .venv && . .venv/bin/activate
pip install 'ansible-core>=2.18,<2.19'
ansible-galaxy collection install -r requirements.yml -p ./collections
# No python3-venv on the controller (minimal Ubuntu, no sudo)? Create the venv
# without pip and install into it from outside:
#   python3 -m venv --without-pip .venv
#   pip3 install --python .venv/bin/python 'ansible-core>=2.18,<2.19'
#   then call .venv/bin/ansible-playbook and .venv/bin/ansible-galaxy

# Your site data lives OUTSIDE the repository.
mkdir -p ~/.config/openctem-ansible && cp -r inventories/example ~/.config/openctem-ansible/inventory
mv ~/.config/openctem-ansible/inventory/group_vars/all.yml.example ~/.config/openctem-ansible/inventory/group_vars/all.yml
$EDITOR ~/.config/openctem-ansible/inventory/hosts.ini          # your VM address and user
$EDITOR ~/.config/openctem-ansible/inventory/group_vars/all.yml # host name, admin CIDRs, age public key
INV=~/.config/openctem-ansible/inventory/hosts.ini

-i must name the file hosts.ini (as INV does), not the inventory directory: a directory gives No inventory was parsed. group_vars/ beside the file is still read. -K below (--ask-become-pass) asks once for the sudo password of the SSH user on the VM (BECOME password:); it stays in Ansible's memory and is never written anywhere. Leave -K out when that user has passwordless sudo. Check the connection first: ansible -i $INV openctem -m ping.

In Cloudflare: create the tunnel and copy its token (§1). On the VM (console or SSH), store the token:

sudo install -d -m 0700 -o root -g root /opt/openctem/secrets
sudo sh -c 'umask 077; cat > /opt/openctem/secrets/cloudflared_tunnel_token'   # paste, Enter, Ctrl-D
sudo chown 65532:65532 /opt/openctem/secrets/cloudflared_tunnel_token && sudo chmod 0400 /opt/openctem/secrets/cloudflared_tunnel_token

Then, from the controller (-K asks for the sudo password):

ansible-playbook -i $INV playbooks/00-preflight.yml -K               # read-only
ansible-playbook -i $INV site.yml -K --check --diff \
  -e apply_os=true -e apply_ssh=true -e apply_docker=true -e apply_firewall=true
ansible-playbook -i $INV site.yml -K \
  -e apply_os=true -e apply_ssh=true -e apply_docker=true -e docker_daemon_restart=true \
  -e apply_firewall=true -e apply_openctem=true -e apply_backup=true -e apply_monitoring=true

Finish the Cloudflare side (§2–§5), create the first administrator (§4), and run the acceptance tests (§3.10). For a production host, follow the full runbook instead: it applies one stage at a time with a snapshot and a dry run in between.

3. Full runbook

Every command below runs from the repository root on the controller with INV=~/.config/openctem-ansible/inventory/hosts.ini. Each stage changes the host only when its apply_* flag is true. Without it, the play prints that it was skipped.

3.1 Preflight (read-only)

ansible -i $INV openctem -m ping
ansible-playbook -i $INV playbooks/00-preflight.yml -K

Checks the OS, sudo, CPU/RAM/disk, the tunnel token's owner and mode (metadata only: the token is never read), Docker, listeners, ufw, time sync (fails when the clock is unsynchronised or more than 5 s off, because sensor signatures allow only about 2 minutes of skew; fix with sudo chronyc makestep, see "Time synchronisation" in docs/self-hosting-with-ansible.md) and the effective sshd settings. Fix anything unexpected before going on.

3.2 Snapshot

Take a hypervisor snapshot of the VM, and keep its console open for the SSH and firewall stages. A snapshot is a change checkpoint, not a backup: delete it after the change is accepted.

3.3 Rehearse

ansible-playbook -i $INV site.yml -K --check --diff -e apply_os=true -e apply_ssh=true \
  -e apply_docker=true -e apply_firewall=true

--check cannot predict everything: package installs, the DevSec roles' internal checks and Docker-dependent tasks are skipped or approximate on a host without Docker yet. Read the diff; then apply stage by stage.

3.4 OS baseline

ansible-playbook -i $INV playbooks/10-os.yml -K -e apply_os=true

DevSec OS hardening (kernel/sysctl, file permissions, login defaults; IPv4 forwarding kept on for Docker), unattended security upgrades (no automatic reboot unless os_baseline_unattended_reboot: true), chrony (steps the clock whenever it is more than 1 s off), auditd with rules for identities, sudoers, SSH, Docker and /opt/openctem/secrets (reads included), and a persistent journal capped at 1 GB / 1 month. Each part can be turned off (roles/os_baseline/defaults/main.yml); tags os_devsec, os_updates, os_time, os_audit, os_journal.

3.5 SSH

ansible-playbook -i $INV playbooks/20-ssh.yml -K -e apply_ssh=true                 # stage 1
ansible-playbook -i $INV playbooks/20-ssh.yml -K -e apply_ssh=true -e ssh_stage=2  # stage 2

Stage 1 applies DevSec SSH hardening (no root login, no forwarding, strong algorithms) and keeps password login as a fallback. It also installs fail2ban for sshd (admin CIDRs never banned). Open a new SSH session with your key before stage 2. Stage 2 first proves a key-only login from this controller, refuses otherwise, then turns passwords off and proves the key login again.

3.6 Docker

ansible-playbook -i $INV playbooks/30-docker.yml -K -e apply_docker=true -e docker_daemon_restart=true

Docker Engine and the compose plugin from Docker's apt repository. The key is checked by hash and fingerprint, versions are pinned in versions.yml and held (apt-mark hold). The role stops with a clear message if Docker publishes no repository for the host's release. daemon.json: log rotation, live-restore, userland-proxy: false, no-new-privileges. Nobody is added to the docker group (it is root-equivalent); use sudo docker ....

3.7 Firewall

ansible-playbook -i $INV playbooks/35-firewall.yml -K -e apply_firewall=true

ufw: deny inbound except SSH from admin_cidrs. Refuses to run if this controller is outside them. Read docs/FIREWALL.md for why Docker-published ports bypass ufw and how this deployment avoids publishing any.

The same stage can also close the stack's outbound side: with openctem_egress_policy: restricted (the default for a hosted service, openctem_signup_mode: open) the API and the tunnel connector cannot reach private, link-local/metadata, CGNAT, loopback or host-local addresses, only the internet. Operator-approved internal destinations (an internal SMTP relay, an on-premises Jira) go in openctem_egress_allow. Inside a corporate network whose only way out is an HTTPS proxy, openctem_feed_proxy sends the platform's own feeds through it (nothing an organization configures). See docs/FIREWALL.md.

3.8 OpenCTEM

Place the tunnel token first (see the quickstart), then:

ansible-playbook -i $INV playbooks/50-openctem.yml -K -e apply_openctem=true

What it does, in order:

  1. checks that the tunnel token is present, owned by uid 65532 and mode 0400 (metadata only), and that the release is pinned by digest;
  2. copies the release's gateway configuration and database-roles SQL (vendored here, verified against SHA256SUMS on the controller);
  3. generates every secret on the host (/usr/local/sbin/openctem-secrets, openssl rand): database superuser, migrator and app passwords, Redis password, APP_ENCRYPTION_KEY, FINGERPRINT_KEY, metrics token. Files are 0400 in /opt/openctem/secrets (0700, root). Values never leave the host or reach Ansible output; a second run changes nothing;
  4. verifies every OpenCTEM image digest with cosign against the release workflow's keyless identity (https://github.com/openctemio/openctem/.github/workflows/docker-publish.yml@refs/tags/<version>), before pulling;
  5. renders /opt/openctem/compose.yml (+ compose.cloudflared.yml), pulls, starts with --wait: database roles and migrations run as one-shot jobs before the API starts;
  6. runs /usr/local/sbin/openctem-verify: every service healthy, no port published, the gateway routes the console, the API, the sensor and CI planes correctly, internal endpoints closed, other host names refused.

Containers run with cap_drop: ALL (Postgres and Redis keep only what their entrypoints need to drop to their own users), no-new-privileges, read-only root filesystems where the image allows, memory/CPU/PID limits, health checks, restart: unless-stopped and rotated logs.

From the release that ships openctem-console (console_service in versions.yml), the platform console runs as its own service on its own site (recommended in production: its own host name, openctem_admin_site: host, behind its own Cloudflare Access application; the default is a second port, 8443, on the loopback ingress). It is never published through the tunnel without that zero-trust layer; see docs/self-hosting-with-ansible.md.

3.8.1 Mail without an online provider (optional)

The platform e-mail needs one SMTP server. If you run none and want no online provider, the kit can install a send-only Postfix relay beside OpenCTEM. Off by default; see docs/MAIL-RELAY.md (security properties, the settings, the DNS records, troubleshooting).

# inventory: openctem_mail_relay: true, openctem_mail_relay_from, mail_relay_hostname, mail_relay_sender_domains
ansible-playbook -i $INV playbooks/52-mail-relay.yml -K -e apply_mail_relay=true   # before the OpenCTEM stage

3.9 Cloudflare

Follow docs/CLOUDFLARE-ACCESS.md: the public hostname route to http://gateway:80 (in the dashboard, or with cloudflared_management: local for a locally managed tunnel); one Access application for people (IdP + MFA); Bypass applications on exactly /api/v2/sensor/*, /api/v3/sensor/*, /api/v1/ci/oidc/exchange and /api/v1/ci/runs/*; a WAF rate limit on them; WebSockets on.

Sensors and CI use the same URL as people: https://<openctem_app_host>.

3.10 Acceptance tests

On the host: sudo openctem-verify. From outside: the commands and the expected results in docs/CLOUDFLARE-ACCESS.md §6 and the matrix in docs/FIREWALL.md. Then the exposure audit and the general audit:

ansible-playbook -i $INV playbooks/85-exposure-audit.yml -K
ansible-playbook -i $INV playbooks/80-audit.yml -K

3.11 Backups and monitoring

ansible-playbook -i $INV playbooks/55-backup.yml -K -e apply_backup=true -e backup_run_now=true
ansible-playbook -i $INV playbooks/60-monitoring.yml -K -e apply_monitoring=true

Then run a restore drill (§5).

4. First administrator

OpenCTEM has no default account. Create the first platform administrator and its break-glass backup on the server's console or an interactive SSH session. The one-time credentials are printed once, to that terminal only. The wrapper refuses to run without a terminal, so it can never print into Ansible output or a log file.

sudo openctem-bootstrap-admin [email protected] [email protected]
# optionally the first organization and its owner:
sudo openctem-bootstrap-admin [email protected] [email protected] \
  -org-name="Example Security" [email protected]

Sign in at https://<app host>/login with the printed temporary password, change it, and enroll an authenticator (TOTP), which the admin console requires. Store the break-glass credentials offline. Organizations are created by the platform administrator: public sign-up is off (openctem_signup_mode: disabled, the API's SIGNUP_MODE), and no console change can open it. Configure e-mail in the admin console (System → E-mail) so invitations can be sent.

Sign-up modes

openctem_signup_mode sets the API's sign-up ceiling (SIGNUP_MODE):

Value Who can create an account Who creates organizations
disabled (default) the platform administrator, an invitation, or an organization's SSO the platform administrator
domain also anyone whose address is on an organization's verified domain; they join that organization the platform administrator
open anyone (hosted service) anyone, within the console policy and the limits

The admin console (System → Sign-up) can keep sign-up closed or pause it below the ceiling, never above it. domain and open verify every self-registered address, so the API refuses to start until the platform e-mail is set: run openctem-bootstrap-admin with BOOTSTRAP_SMTP_* first, or deploy once with disabled, set System → E-mail, then change the mode and deploy again.

Hosted-service sign-up (open on the internet) also needs Cloudflare Turnstile, or the API refuses to start in production:

openctem_signup_mode: open
openctem_captcha_turnstile_site_key: "0x4AAAA..."   # public site key

and the secret on the server (never in the inventory), which the secrets script adds to api.env:

printf '%s' '0x4AAAA...secret' | sudo install -m 0400 /dev/stdin /opt/openctem/secrets/captcha_turnstile_secret

Upgrading from a kit that set openctem_tenant_creation_mode: remove it. admin_only is openctem_signup_mode: disabled (the default); self_service is open. The play stops while the old variable is set.

Social login (Google, GitHub, Microsoft)

The client ID and the switches are ordinary settings in openctem_api_env; the client secret stays on the server (never in the inventory) and the secrets script adds it to api.env. Example for Google (callback URL to register with Google: https://<your host>/auth/callback/google):

openctem_api_env:
  OAUTH_ENABLED: "true"
  OAUTH_GOOGLE_ENABLED: "true"
  OAUTH_GOOGLE_CLIENT_ID: "1234-abc.apps.googleusercontent.com"
printf '%s' 'GOCSPX-...' | sudo install -m 0400 /dev/stdin /opt/openctem/secrets/oauth_google_client_secret

GitHub and Microsoft use OAUTH_GITHUB_* / OAUTH_MICROSOFT_* and the files oauth_github_client_secret / oauth_microsoft_client_secret. Then run playbooks/50-openctem.yml -e apply_openctem=true (the API restarts with the new api.env). A provider appears on the sign-in page only when it is enabled and both its client ID and secret are set. Removing the file and the settings turns it off at the next run.

Administrators' audit sink

The platform console keeps a hash-chained audit log of the platform administrators' actions in the database. The sink writes a copy outside the database, so a database-level rewrite is detectable.

Which releases have it:

  • Releases from v0.22.0 on (admin_audit_sink_removed in versions.yml): the audit stream is not included in the release's own images. Leave openctem_admin_audit_sink unset; MANAGED_SERVICE needs no sink. A server refuses to start while an ADMIN_AUDIT_SINK* setting is present, and the kit's checks stop the run earlier, before changing anything (see the upgrade note below). The variables below then apply only with a custom server image that includes the stream.
  • Earlier releases that require it (admin_audit_sink_required): a managed service (MANAGED_SERVICE: "true" in openctem_api_env) must have a sink; the server refuses to start without, and playbooks/50-openctem.yml fails in its checks, before changing anything.
Variable Default Meaning
openctem_admin_audit_sink '' (off) file, or an https:// URL
openctem_admin_audit_sink_head_interval '' (API default, 15m) interval of the signed chain-head records, e.g. 5m
openctem_admin_audit_sink_dir /opt/openctem/admin-audit file mode: host directory
openctem_admin_audit_sink_provided false true only with a custom server image that includes the audit stream (see the upgrade note below)
  • file: the kit creates openctem_admin_audit_sink_dir (owner uid 1000, the API's user, mode 0750), mounts it into the API at /var/lib/openctem-admin-audit and sets ADMIN_AUDIT_SINK=file:///var/lib/openctem-admin-audit/admin-audit.jsonl. openctem-backup archives the directory as admin-audit.tar.gz, so the copy leaves the host with the (age-encrypted, off-host) backups. Restore it with tar -xzf into the directory.

  • https://host/path: the API posts each record, signed with an HMAC key, to a receiver you run. Create the key on the server first (the kit never puts it in the inventory; the API has no _FILE variant, so the generated api.env carries it like the other secrets):

    sudo sh -c 'umask 077; openssl rand -hex 32 > /opt/openctem/secrets/admin_audit_sink_secret'

    The file must be at least 32 bytes and mode 0600 or 0400; give the same key to the receiver, which verifies the signature with it. The backup includes the key in secrets.tar.gz.

  • syslog+tls:// is not supported by this kit yet (the API needs CA and client certificate files mounted into the container); the checks refuse it.

Upgrade note, releases flagged admin_audit_sink_removed. The images of such a release do not include the audit stream (it is provided by an optional module) and refuse to start while ADMIN_AUDIT_SINK (or any ADMIN_AUDIT_SINK_*) is set; MANAGED_SERVICE=true no longer needs a sink. For such a release the checks refuse a non-empty openctem_admin_audit_sink (failing before the host is touched, not at container start) unless openctem_admin_audit_sink_provided: true, which you set only when openctem_custom_api_image is an API image that includes the stream (the checks refuse the flag without one; see Custom server image: that keeps the sink, its mount and its position across the upgrade). To upgrade a server that uses a sink with the release's own images, unset openctem_admin_audit_sink; the kit then renders no ADMIN_AUDIT_SINK* variable and no mount. The existing file copy under openctem_admin_audit_sink_dir and the backup of it stay on disk; nothing is deleted. scripts/vendor-release.sh prints the flag from the release's own source; every release from v0.22.0 on carries it, and the checks refuse such a versions.yml entry without it (or with admin_audit_sink_required as well). Before such a release the checks also read the server: a compose override file (compose.override.yml, docker-compose.override.yml, .yaml too) in openctem_root, or an env file in openctem_root or openctem_secrets_dir other than the generated api.env, that still sets an ADMIN_AUDIT_SINK* variable fails the run with the file names (never their content), before anything changes. Remove those lines first.

Threat model. The file sink is on the same host as the database: it protects against rewrites inside the database and leaves the host with the backups, but anyone with root on the host can still edit both. An https receiver run by a different party (or at least on a different host and account) is the real off-box copy: use it for a hosted service. Neither mode stores a secret in the inventory, the compose file or git.

Custom server image

An installation can run a custom build of the platform API: an image that is this release's core with extensions compiled in (for example one that provides a feature not included in the release's own image, such as the administrators' audit stream from a release flagged admin_audit_sink_removed). It replaces the image of the api service only; web, console, gateway, migrations, the job signer and the first-admin tool keep the release's signed images.

openctem_custom_api_image: registry.example.com/org/server:v0.22.0@sha256:<64 hex>
openctem_custom_api_cosign_identity: https://github.com/<org>/<repo>/.github/workflows/<workflow>.yml@refs/tags/v0.22.0
# openctem_custom_api_cosign_issuer: https://token.actions.githubusercontent.com   # the default
# Its own migrations, if it has any (an argv list; never a password in it):
# openctem_custom_api_migrate_command: ["/app/<tool>", ..., "-database",
#   "postgres://openctem_migrator@postgres:5432/openctem?sslmode=require", "up"]
# openctem_admin_audit_sink_provided: true   # only if this image includes the audit stream
# openctem_registry_docker_config_dir: /root/.docker   # a private registry (below)
Variable Default Meaning
openctem_custom_api_image '' (the release's image) image reference pinned by digest; used as given (openctem_registry_mirror does not rewrite it)
openctem_custom_api_cosign_identity '' exact keyless certificate identity of the workflow that signs it; required with the image
openctem_custom_api_cosign_issuer GitHub Actions OIDC certificate issuer of that identity
openctem_custom_api_migrate_command [] the image's own migrations, run once per deploy as the one-shot migrate-extension

What the kit enforces:

  • Pinned and verified. The reference must end in @sha256:<64 hex>. Before anything is pulled (also in --check), cosign verifies its keyless signature against openctem_custom_api_cosign_identity and the issuer, and the release's own images against the release identity as always. A custom image cannot run unverified: openctem_verify_signatures: false is refused with it.
  • Built on this release. The signature must carry the annotation io.openctem.core.version=<openctem_version> (cosign sign -a io.openctem.core.version=vX.Y.Z). An image built on another release fails the check, so upgrading openctem_version without a new custom image stops before the host changes.
  • Migrations. With openctem_custom_api_migrate_command, the one-shot service migrate-extension runs the custom image with that argv (first element as the entrypoint) after migrate and before the grants and the API, with the migrator's role and migrate.env (PGPASSWORD), on the data network, read-only. In releases that rerun the least-privilege SQL after the migrations (db-grants, every release flagged console_db_role), that rerun waits for it too and covers any schema its migrations created. A password in the arguments is refused.
  • The check prints which API image this deploy uses and with which identity.
  • Rollback (playbooks/71-rollback.yml, and the automatic rollback of a failed deploy) restores the previous compose file, which holds the previous API image by digest, and starts it without one-shot jobs (migrate-extension included). A schema the custom image's migrations created stays, unused, in the database.

Private registry. docker compose pull uses root's Docker login on the host, and the cosign check runs in a container that needs the same login:

# on the host, as root, with a read-only (pull) token of that registry
sudo docker login <registry host> -u <user> --password-stdin < token-file

then set openctem_registry_docker_config_dir: /root/.docker (mounted read-only into the cosign container). The cosign check runs as the owner of that config.json (root's is readable by root only), still with a read-only file system and no capabilities; a directory without config.json stops the run before anything changes. Use a token that can only read packages, and rotate it like the other host secrets.

tests/custom-image.sh covers the refusals, the rendered compose file (api image, migrate-extension, the sink and its mount kept) and the cosign commands, including an image built on another release.

Private registry / air-gapped

By default the images come from ghcr.io/openctemio and the role pulls from the public registries. To run from your own registry (Harbor, Nexus, a GitLab registry), mirror the images with scripts/mirror-to-registry.sh — the walkthrough is docs/CORPORATE-REGISTRY.md — and set, in group_vars:

openctem_registry_mirror: registry.example.com/openctem          # replaces ghcr.io/openctemio
openctem_third_party_registry_mirror: registry.example.com/mirror # replaces the host of the others
# openctem_registry_docker_config_dir: /root/.docker   # the host's `docker login` for the cosign check
# openctem_registry_ca_file: /etc/ssl/certs/registry-ca.pem
  • OpenCTEM images (openctem-server, published as openctem-api up to v0.22.x, openctem-web, openctem-gateway, migrations, openctem-console): the prefix is swapped, the repository name and the digest stay, so ghcr.io/openctemio/openctem-server@sha256:... becomes registry.example.com/openctem/openctem-server@sha256:.... The digest is the integrity anchor: a mirror that serves other bytes fails the pull.
  • Signatures. The cosign check runs against the mirror reference with the same certificate identity and issuer as before, so the mirror must hold our signatures. They are OCI referrers of the digest: copy them with the image (cosign copy <src>@sha256:... <mirror>/<name> or oras cp -r). If the signature is not on the mirror the run stops before anything is pulled; there is no way to skip it except openctem_verify_signatures: false, which you should not use.
  • Third-party images (PostgreSQL, Redis, rclone, cloudflared, cosign): the registry host is replaced and the path kept, so docker.io/library/postgres is read from registry.example.com/mirror/library/postgres, docker.io/rclone/rclone from .../rclone/rclone, docker.io/cloudflare/cloudflared from .../cloudflare/cloudflared and ghcr.io/sigstore/cosign/cosign from .../sigstore/cosign/cosign. Digests are unchanged. These variables cannot be overridden one by one in group_vars (versions.yml is loaded with higher precedence); use the mirror variable.
  • Registry access. The host runs docker login <registry> once (root's Docker config); for the cosign check, which runs in a container, set openctem_registry_docker_config_dir to the directory holding that config.json (mounted read-only). A private CA is trusted by the Docker daemon through /etc/docker/certs.d/<host>/ca.crt, and by the cosign check through openctem_registry_ca_file (mounted read-only). Plain-HTTP registries are not supported.
  • Nothing changes while both mirror variables are empty (the rendered files are identical). Both are validated by the preflight (a host and optional path: no scheme, no digest). tests/registry-mirror.sh renders both ways and checks the cosign command that would run.

Automatic coverage

OpenCTEM (v0.9.6 and later, with fixes in v0.9.7) keeps each organization's assets covered on its own: a background loop takes the assets that are due for a capability (subdomain discovery, DNS, ports, HTTP probe, templates; never an intrusive one), passes them through the scope gate and runs them on the organization's "Continuous coverage" scans. That needs a sensor able to run those tools.

  • On by default for every organization. It stays off for an organization whose scan approval mode is Strict, until that organization turns it on.

  • Per organization: console → Scoping → Settings → Automatic coverage. Changing it needs the scope-approver permission and a recent re-authentication; it is audited and every administrator is notified.

  • Platform-wide (operator): ASSET_COVERAGE_ENABLED: "false" turns the loop off, and ASSET_COVERAGE_DAILY_BUDGET caps attempts per organization per 24 hours (default 5000). Set them in your inventory:

    openctem_api_env:
      ASSET_COVERAGE_DAILY_BUDGET: "2000"

    then rerun playbooks/50-openctem.yml. openctem_api_env accepts non-secret settings only; the role refuses the ones it manages itself.

Review each organization's scope (Scoping) before onboarding its assets: with automatic coverage on, in-scope assets are scanned without a manual trigger.

5. Backups and restore drill

openctem-backup runs daily (systemd timer, 03:15 UTC) and on demand (sudo systemctl start openctem-backup). One backup is a directory under /var/backups/openctem/<UTC time>/ (0700, root) with:

  • openctem.dump: pg_dump -Fc, checked with pg_restore --list;
  • api-data.tar.gz: uploaded attachments and evidence;
  • signer-*.tar.gz: the job signer's key and state, when the signer is on;
  • secrets.tar.gz: the generated secrets. APP_ENCRYPTION_KEY decrypts the stored integration credentials, so a dump without it is unusable. The tunnel token is not included: re-issue it in Cloudflare;
  • deployment.tar.gz, VERSION, SHA256SUMS.

Retention: backup_keep_days (14).

Two modes:

backup_age_recipient Mode
empty local: plaintext files, root-only, on this host only. An off-host copy is refused, and every run logs that the backups are not off-host.
age1... (public key) age: every file is encrypted on the host to your public key (*.age + MANIFEST.sha256); the plaintext staging copy is deleted. Off-host copy allowed.

Create the key on your workstation, never on the server:

age-keygen -o ~/openctem-backup-identity.txt     # keep it offline (password manager, hardware token)
age-keygen -y ~/openctem-backup-identity.txt     # prints age1...: put it in backup_age_recipient

Off-host copy: set backup_offsite_command to a command that receives the new backup directory as $1, e.g. rclone copy --config /root/.config/rclone/rclone.conf "$1" offsite:openctem/$(basename "$1"). Keep the remote's credentials in a root-only file on the host. Only encrypted backups are copied.

Off-host backups are encrypted, signed and cannot be deleted from the host. The role refuses an off-host copy without backup_age_recipient. Every backup manifest (MANIFEST.sha256), WAL segment and base-backup meta.json is signed with an ed25519 key generated once on the host (/etc/openctem/backup-signing, root 0400); age alone proves nothing about the author, because the recipient key is public. The backup play prints the public key as an allowed_signers line: store it off the host and pass it to restores, --allowed-signers=FILE (or set backup_signing_allowed_signers, which also puts a copy on the host for the drill). Restore, drill and point-in-time recovery refuse an unsigned or badly signed backup unless you pass --allow-unsigned (logged to the journal). Backups made before this change are unsigned: restore them with --allow-unsigned once. The bucket credential on the host should be write-only, with versioning and object lock on the bucket and pruning by a lifecycle rule: see docs/BACKUP-PITR.md; the host deletes from the bucket only with backup_wal_prune: true.

Restore drill (monthly at least): restores into a throwaway PostgreSQL with no network and compares row counts with the running database, without touching the stack.

# local mode
sudo openctem-restore-drill
# age mode: copy the identity to the host for the drill only, then delete it
scp ~/openctem-backup-identity.txt vm:/tmp/id.txt
ssh -t vm 'sudo install -m 0600 /tmp/id.txt /root/drill.key && rm /tmp/id.txt && \
  sudo openctem-restore-drill /var/backups/openctem/<UTC time> /root/drill.key; sudo rm -f /root/drill.key'

Full restore over the running stack (stops cloudflared, gateway, web and API while it runs, replaces the database and the uploaded files, re-applies the database roles, starts what was running, verifies):

sudo openctem-restore /var/backups/openctem/<UTC time> [/root/drill.key] --yes --allowed-signers=/path/to/allowed_signers

It refuses a backup of another release than the one running (--allow-version-mismatch), saves the current database to /var/backups/openctem/pre-restore-<time>.dump[.age] before dropping it (--skip-pre-restore-dump only if it cannot be dumped; delete the file once you are satisfied, it is never pruned), and logs who ran it (journalctl -t openctem-restore).

Continuous archiving and point-in-time recovery (off by default; needs an S3-compatible bucket and its access key, which only you can provide): the database ships every WAL segment, encrypted, to the bucket, and openctem-restore --pitr "<UTC time>" recovers to a time. RPO about 6 minutes. See docs/BACKUP-PITR.md.

On a new host, deploy the backup's release first (VERSION), then add --with-secrets: it restores the generated secrets (so APP_ENCRYPTION_KEY matches the data) except the new host's own Postgres superuser password. Rerun playbooks/50-openctem.yml afterwards to reset file owners.

Job signer key

The job signer (openctem_job_signer: true, the default) signs every job the API hands a sensor. It runs as its own container (user 1001, no network), with its key and state in their own volumes (signer-keys, signer-state); the key volume is never mounted into the API, which reaches the signer only through a Unix socket on a shared volume. The first deploy creates the key and prints its id and public key; record them. The API refuses to start without the signer (APP_ENV=production); the preflight stops an inventory with openctem_job_signer: false unless openctem_api_env sets SIGNER_DANGEROUS_ALLOW_UNSIGNED_JOBS: "true" (not recommended).

openctem_signer_ledger (default audit) is the signer's scope-ledger mode: audit records what enforce would refuse and still signs, which is the safe mode when upgrading an installation that already signed jobs. Bootstrap the ledger (docs/architecture/job-signing.md, "Scope ledger" in the OpenCTEM repository), then set openctem_signer_ledger: enforce.

Feed relay. With feed relay the OpenCTEM API makes no outbound feed requests: a platform-owned shared sensor downloads the signed feed files from allowlisted https origins (GET only) and uploads them. This kit installs no sensor (see "Sensors are not installed here"), so it has no sensor variables and no -feed-relay step: the sensor runs elsewhere and relays by default when it is a shared sensor with a pinned job-signing key (SENSOR_FEED_RELAY=0 turns it off there; that is host policy and only narrows). The kit's only part is the signer's allowlist: openctem_sensor_feed_relay_origins (default [], full https download prefixes, matched exactly by the signer, such as https://mirror.example.com/vulnfeed-bundles/releases/latest/download for a mirror whose VULNFEED_BASE_URL is https://mirror.example.com/vulnfeed-bundles/releases). When set, the kit renders SIGNER_FEED_ORIGINS on the signer container as the official origins (openctem_feed_relay_official_origins) followed by these: a set SIGNER_FEED_ORIGINS replaces the signer's built-in official list. Add a mirror there and in that sensor's SENSOR_FEED_RELAY_ORIGINS; an origin missing on either side is refused. A new database created by this kit does not store relay mode (that needs bootstrap-admin sensor-token ... -feed-relay with a bundled sensor), and an existing installation stays direct because its feed delivery setting already exists. Choose the delivery mode in the console.

Key backup. Losing the key makes every paired sensor refuse new jobs; a leaked key lets its holder sign any job. So the key is backed up only encrypted:

  1. Create an age key pair on your own workstation (age-keygen -o ctem.age); keep the identity file offline (password manager or hardware token), never on this host.
  2. Put the public key (age1...) in backup_age_recipient, run playbooks/55-backup.yml. openctem-backup then writes signer-keys.tar.gz.age and signer-state.tar.gz.age with the other files; copy them off the host together with the database backup (see the off-host backup section). The plain signer-keys.tar.gz of an unencrypted backup stays on this host and must not be copied anywhere.
  3. Test the restore on a scratch host at least once: age -d -i ctem.age signer-keys.tar.gz.age | tar -tz.

6. Upgrade and rollback

Releases this kit can run are listed in versions.yml (openctem_releases, digests per image). To upgrade:

git pull                                            # a kit version that lists the release
ansible-playbook -i $INV playbooks/50-openctem.yml -K -e apply_openctem=true -e openctem_version=vX.Y.Z

Then set openctem_version in your inventory. The play:

  1. verifies the new images' signatures;
  2. runs a backup first and stops if it fails (the backup role must be installed; -e openctem_backup_before_upgrade=false only after a backup you took yourself);
  3. keeps the running compose file as compose.prev.yml and the previous release's gateway files under /opt/openctem/releases/<version>;
  4. pulls and starts the new release; migrations run before the API starts;
  5. verifies. On any failure it restores compose.prev.yml, starts the previous release and verifies again.

Manual rollback, for example a problem found after the upgrade:

ansible-playbook -i $INV playbooks/71-rollback.yml -K -e apply_rollback=true

Going back starts the previous release without its migration job: an older migration job refuses a database a newer release already migrated, and an older API runs on the newer schema (tested: v0.9.6 on the v0.9.7 schema). Migrations are not reversed. If the previous release misbehaves on the migrated database, restore the pre-upgrade backup with openctem-restore while the previous release runs.

6.1 Upgrading to v0.10.1 (v0.10.0)

Read before the first apply of the kit version that lists v0.10.1. v0.10.0 was tagged but its images were never published, so the kit does not list it: go from v0.9.x straight to v0.10.1. Everything below that says v0.10.0 holds for v0.10.1 too.

  1. FINGERPRINT_KEY is required (at least 32 characters). It keys the fingerprint of every stored secret finding. The kit manages it on the host like the encryption key (/opt/openctem/secrets/fingerprint_key, 0400, root, never printed, never in Ansible output):
    • on an existing install the first apply copies the stored app_encryption_key into fingerprint_key, because that is the key the existing fingerprints were made with. It never generates a new random one for an install that already has an encryption key: a different value gives every known secret a new identity and reopens each as a new finding;
    • a new install gets its own random key, independent of the encryption key;
    • the play refuses to deploy while the file is missing, shorter than 32 characters or not 0400. Never set FINGERPRINT_KEY through openctem_api_env (refused);
    • back it up with the database: openctem-backup includes it, and openctem-restore --with-secrets restores it (a backup taken before this kit version has none: this server's stays).
    • Verify after the apply: sudo stat -c '%a %U %s' /opt/openctem/secrets/fingerprint_key prints 400 root 65 (or more), and sudo cmp /opt/openctem/secrets/fingerprint_key /opt/openctem/secrets/app_encryption_key is silent on an upgraded install (identical). Do not print either file.
  2. TENANT_CREATION_MODE is gone (the API refuses to start while it is set). The kit never renders it; openctem_signup_mode (default disabled) becomes SIGNUP_MODE. openctem_api_env refuses TENANT_CREATION_MODE and the other names v0.10.0 removed (openctem_api_env_removed). If your inventory still sets openctem_tenant_creation_mode, remove it (the play already stops on it).
  3. Other v0.10.0 settings, checked against the release's environment registry (api/internal/config/env_registry.yaml):
    • the other variables required in production (DB_PASSWORD, REDIS_PASSWORD, REDIS_TLS_ENABLED, APP_ENCRYPTION_KEY, DB_SSLMODE, AUTH_COOKIE_SECURE) are already set by the kit;
    • the administrators' audit sink (ADMIN_AUDIT_SINK) is configured by the kit through openctem_admin_audit_sink (section "Administrators' audit sink" below). A release that requires it (admin_audit_sink_required in versions.yml) refuses to start with MANAGED_SERVICE=true and no sink, and the preflight stops before the host is touched. Do not set ADMIN_AUDIT_SINK* through openctem_api_env (refused);
    • v0.10.1 ships the platform console as its own service (image openctem-console, cosign-verified with the other images) and the gateway's console site, so versions.yml flags it admin_plane, console_db_role and console_service. The kit renders the console service, ADMIN_LISTEN_ADDR and ADMIN_ALLOWED_CIDRS for it. Leave openctem_admin_host empty unless you set up the console host (behind Cloudflare Access, docs/CLOUDFLARE-ACCESS.md; see docs/self-hosting-with-ansible.md);
    • sensors over mTLS (api:9443, passed through by the gateway at layer 4) are off in the kit's gateway (sensors/off.wrappers); enrolling sensors needs a kit change of its own;
    • the kit sets OPENCTEM_CLIENT_IP_HEADERS=Cf-Connecting-Ip on the gateway (visitor address behind the tunnel, docs/CLOUDFLARE-ACCESS.md); only v0.10.1's gateway reads it (v0.9.7's ignores it, so the API sees the tunnel's address there);
    • there is no INTERNAL_API_* variable in v0.10.0;
    • the SMTP variables are removed (platform e-mail is set in the console, System > E-mail); the kit never rendered them.
  4. Database role for the console. The v0.10.1 least-privilege SQL has the console identity role (admin_user; v0.9.7's has none), so scripts/vendor-release.sh flags the release console_db_role: true and the kit renders DB_ADMIN_USER/DB_ADMIN_PASSWORD for it. The password (db_console_password) is already generated on every install. This path has not run on a live release before: check that openctem-verify passes and the API starts after the upgrade.
  5. Take the usual pre-upgrade backup (the play does), then:
git pull
ansible-playbook -i $INV playbooks/50-openctem.yml -K -e apply_openctem=true -e openctem_version=v0.10.1

Rollback to v0.9.7 keeps working (an older API ignores FINGERPRINT_KEY); see the rollback notes below.

6.2 Upgrading to v0.23.0

Read before applying the kit version that lists v0.23.0. The kit's release entry needs no inventory change.

  1. The server image is renamed. From v0.23.0 the API image is ghcr.io/openctemio/openctem-server (openctem-api keeps its tags up to v0.22.x and gets no new ones). The entry in versions.yml pins the new name by digest under the same key api, so the older entries (and a rollback to v0.22.x) keep their openctem-api digests. The signature identity is unchanged (docker-publish.yml@refs/tags/<version>). Nothing to change in the inventory, with one exception: a private registry (openctem_registry_mirror) must hold openctem-server (mirror the release with its own mirror-images.sh) and allow-lists naming openctem-api need the new name too.
  2. Database migrations (applied by the release's migration job before the API starts): nine, listed in the pull request of the release entry. One backfills data (asset_ip_addresses, batches of 2000 assets, minutes on a large inventory; a range filter can miss an older asset until it ends); the rest are schema only.
  3. The least-privilege SQL changes: the app role loses write access to the migration tracking tables in every application schema. The kit re-runs the script on apply; it needs no setting.
  4. PostgreSQL 17.12 (a security release) is a separate kit setting already in the kit; apply it before or with this release.

6.3 v0.21.1 (hotfix of the v0.21 line)

v0.21.1 fixes sign-in for people who use a Google, GitHub or Microsoft account in an organization that requires two-factor authentication. It is for installs that stay on v0.21.x; v0.23.0 remains the newest release. Images only: no database migration, and the gateway files and least-privilege SQL are the same as v0.21.0. No inventory change besides openctem_version; rollback to v0.21.0 with playbooks/71-rollback.yml.

7. Troubleshooting

Symptom Cause and fix
install: invalid user '65532' (Ubuntu 26.04) Ubuntu 26.04 ships the Rust uutils coreutils, whose install -o needs a passwd entry. Use chown 65532:65532 (numeric ids work) or Ansible's file/copy with numeric owners, as this kit does.
A GNU flag of stat/date/sed -i behaves differently uutils replaces coreutils (not sed, grep, find or tar, which stay GNU). This kit's scripts use only flags tested on 26.04 (tests/smoke.sh runs them there).
sudo behaves differently / Ansible become fails 26.04 defaults to sudo-rs. Classic sudo is /usr/bin/sudo.ws: set ansible_become_exe=/usr/bin/sudo.ws in the inventory.
Python warnings about the interpreter set ansible_python_interpreter=/usr/bin/python3.14 (26.04) in the inventory.
A port is reachable although ufw denies it a container publishes it: Docker bypasses ufw (docs/FIREWALL.md). playbooks/85-exposure-audit.yml lists them.
Containers have no internet after hardening net.ipv4.ip_forward was turned off, or iptables: false was set in daemon.json. The OS role pins forwarding on; remove iptables: false.
A new host name (for example the console's openctem_admin_host) still answers 404 after Access although /opt/openctem/cloudflared.yml has it The connector read the route file when it started. A locally managed tunnel's file is bind-mounted as a single file that the play replaces, so the connector must be recreated. Kit versions with the Recreate cloudflared handler do it in the same run; with an older kit run sudo docker compose -p openctem -f /opt/openctem/compose.yml -f /opt/openctem/compose.cloudflared.yml up -d --no-deps --force-recreate cloudflared (the tunnel drops for a few seconds). A remotely managed tunnel keeps its routes in Cloudflare and is not affected.
No inventory was parsed -i names a directory. Name the file: -i ~/.config/openctem-ansible/inventory/hosts.ini.
python3 -m venv fails with ensurepip is not available python3-venv is missing: python3 -m venv --without-pip .venv, then pip3 install --python .venv/bin/python 'ansible-core>=2.18,<2.19'.
Tunnel "Down" / cloudflared unhealthy outbound 7844/udp and 7844/tcp blocked upstream, or a wrong token: sudo docker logs openctem-cloudflared-1 (tokens are not printed), re-place the token, sudo docker compose -p openctem -f /opt/openctem/compose.yml -f /opt/openctem/compose.cloudflared.yml up -d cloudflared.
503 for every path through the tunnel, connector logs No ingress rules were defined the tunnel has no route. Remotely managed tunnel: add the public hostname in the dashboard. Locally managed tunnel (the dashboard says routes come from the local configuration file): set cloudflared_management: local and re-run playbooks/50-openctem.yml (docs/CLOUDFLARE-ACCESS.md §1).
--check stops at a read-only check every read-only command task runs under --check (check_mode: false); tasks that depend on packages a previous stage installs (auditd, fail2ban) report "not found" in check mode before that stage ran. Run the stages in order.
Firewall stage refuses: "Controller address … is not inside admin_cidrs" the lockout guard: the address you connect from is not in admin_cidrs. Add your network (several CIDRs are fine) before enforcing.
404 for every page through the tunnel the route sends another host name, or an HTTP Host Header override: the gateway serves only openctem_app_host.
Sensors or CI get an HTML login page the Access Bypass application for that path is missing or its path is wrong (docs/CLOUDFLARE-ACCESS.md §3).
Sensors get 429 the WAF rate limit is too low for the number of sensors behind one address.
Audit log shows 172.30.81.10 (or another internal address) for every request; one client's sign-in or CI throttling hits everyone the API sees the tunnel connector instead of the visitor: the gateway image predates the client-address fix. Deploy a release that has it and re-run playbooks/50-openctem.yml; the gateway must have OPENCTEM_CLIENT_IP_HEADERS=Cf-Connecting-Ip (sudo docker inspect openctem-gateway-1 --format '{{.Config.Env}}'). Check: docs/CLOUDFLARE-ACCESS.md, Client address.
CI jobs get 429 from Cloudflare on /api/v1/ci/oidc/exchange a per-IP edge limit sized for one machine: hosted runners share egress addresses across customers. Use 600 per minute per IP (docs/CLOUDFLARE-ACCESS.md §4).
Uploads over 100 MB fail Cloudflare's request body limit (Free/Pro).
docker compose "no configuration file" always name the project and files: sudo docker compose -p openctem -f /opt/openctem/compose.yml -f /opt/openctem/compose.cloudflared.yml ps (or cd /opt/openctem first, where .env sets them).
Deploy stops at "Verify the release signatures" the image digest is not signed by the release workflow at that tag, or sigstore is unreachable. Do not disable openctem_verify_signatures to get past it; investigate.
Backup "off-host copy refused" backups are in local (unencrypted) mode: set backup_age_recipient.
API log shows GET /api/v2/sensor/hello 401, POST /api/v1/ci/oidc/exchange 400 and GET /api/v1/me every 5 minutes with no sensor installed expected: the monitor (openctem-monitor, through the tunnel) and openctem-verify (inside the gateway) probe that sensors and CI reach the API and that people are challenged by Access. Their user agents are openctem-monitor and openctem-verify. A 404 on /api/v1/me with an alert "without a Cloudflare Access challenge" means the Access application is not enforcing yet.
journalctl -t openctem-monitor shows alerts each line names the failing check: health, routing, disk, backup age, tunnel path, certificate, Access, client address.

Logs: sudo docker compose -p openctem -f ... logs <service>, journalctl -u openctem-backup, journalctl -t openctem-monitor, sudo ausearch -k openctem_secrets (who read the secrets).

8. Security model and hardening checklist

Trust boundaries. The internet reaches the VM only through Cloudflare: TLS, Access (people) or a Bypass on the exact machine paths, then the WAF rate limit. Inside, cloudflared reaches only the gateway. The gateway routes by API plane and refuses other host names and the internal endpoints (/metrics, /ready, /debug). Only the API reaches PostgreSQL and Redis, over TLS, with least-privilege database roles (the API's role has DML only; migrations run as a separate schema owner). Machine paths are authenticated by OpenCTEM itself: sensor keys and optionally signed jobs, and CI OIDC exchanged for a short-lived run token.

Secrets. Generated on the host; files 0400 in a 0700 root directory, passed to containers as environment files or mounted files, never as command arguments. The tunnel token is placed by you and only its metadata is checked. Ansible tasks that touch secrets use no_log. auditd records every read of the secrets directory. Backups contain the secrets: encrypt them (age).

Supply chain. OpenCTEM images by digest with keyless cosign verification against the release workflow and tag; third-party images (PostgreSQL, Redis, cloudflared, cosign) by digest; Docker packages by version with a fingerprint-checked key; collections by exact version; vendored release files by SHA-256.

Checklist (after deployment):

  • Snapshot taken before each stage and deleted after acceptance
  • 00-preflight clean; OS is Ubuntu 26.04 with security updates
  • SSH stage 2 applied: sshd -T shows passwordauthentication no, permitrootlogin no
  • ufw active: only 22/tcp from admin CIDRs; 85-exposure-audit passes
  • Nobody in the docker group
  • sudo openctem-verify passes; no published port
  • Cloudflare: Access app with IdP + MFA; Bypass apps only on the four machine paths; WAF rate limit; WebSockets on; no origin JWT check on the route
  • Outside acceptance tests pass (console and /api/v1/me challenged; sensor 401; CI exchange 400)
  • First administrator created on the console, TOTP enrolled, break-glass stored offline
  • E-mail configured; sign-up policy disabled (the default openctem_signup_mode)
  • Automatic coverage reviewed per organization (Scoping → Settings) and the daily budget set
  • Backups in age mode, off-host copy configured, restore drill passed
  • Monitoring timer active, webhook tested (sudo systemctl start openctem-monitor)
  • Hypervisor-level backups or snapshots of the VM per your policy
  • Calendar: monthly restore drill, OpenCTEM upgrades, rotation of the tunnel token and the age key yearly

Not covered here: OS-level CIS certification (DevSec hardening is not CIS compliance), host intrusion detection, central log shipping, and a compromised hypervisor or root on the host. A Docker internal network is no boundary against root on the host.

9. Repository layout and tests

site.yml                 every stage in runbook order (each gated by apply_*)
playbooks/               00-preflight 10-os 20-ssh 30-docker 35-firewall 50-openctem 52-mail-relay
                         55-backup 60-monitoring 71-rollback 80-audit 85-exposure-audit
roles/                   os_baseline ssh docker firewall openctem cloudflared mail_relay backup monitoring
                         (+ openctem_common: shared defaults, loads versions.yml)
versions.yml             every pinned version and digest
requirements.yml         exact collection versions
inventories/example/     example inventory; copy it outside the repository
docs/                    Cloudflare, firewall, docs-site page
scripts/vendor-release.sh   add an OpenCTEM release (reads server/deploy, or api/deploy in releases from before the backend directory rename; the server image is openctem-server from v0.23.0, openctem-api before, both under the key api)
tests/                   render.yml, vendor-release-layout.sh, console.sh, mail-relay.sh, audit-sink.sh, custom-image.sh, signer.sh, registry-mirror.sh, cloudflared-restart.sh, smoke.sh (stack in Docker-in-Docker), role-e2e.sh (roles in DinD)

Tests never touch your workstation's containers: tests/smoke.sh and tests/role-e2e.sh create one uniquely named Docker-in-Docker container and run everything inside it. CI (.github/workflows/ci.yml) runs yamllint, ansible-lint (production profile), syntax checks, shellcheck, template render with docker compose config, a gitleaks scan, the smoke test and the roles end to end on Ubuntu 26.04.

License: Apache-2.0. Security reports: SECURITY.md. Contributions: CONTRIBUTING.md.

About

Self-host OpenCTEM on a hardened VM with Ansible: signed images, Cloudflare Tunnel, encrypted backups

docs.openctem.io

Topics

ansiblectemdevsecopssecurityself-hosted

Resources

Readme
Apache-2.0 license

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.