Self Host Wizard Documentación

CRM (espocrm)

CRM en una caja Self Host Wizard: la pieza espocrm, en crm.<dominio de apps>, ingreso oidc, límite de memoria 357 MB.

De un vistazo

DatoValor
Direcciónhttps://crm.<dominio de apps>
Ingresooidc: OpenID Connect con Authelia: el ingreso de la oficina sirve también acá
Límite de memoria357 MB (ram_mb: pico medido × 1,3)
Base de datosmariadb
Necesitalldap, authelia, mariadb
La necesitannada
Contenedoresespocrm, espocrm-daemon
Imagen: espocrmespocrm/espocrm:10.1.4@sha256:5f8fa9a708893b9fbfe55a778f24c952a6a73b94c97fb126eccd21aa936c878c
Imagen: espocrm-daemonespocrm/espocrm:10.1.4@sha256:5f8fa9a708893b9fbfe55a778f24c952a6a73b94c97fb126eccd21aa936c878c
Script de configuración al arrancarscripts/post-up.py, diario
Licencia (según el README)AGPL-3.0
Proyecto original (según el README)https://www.espocrm.com

Cómo activarla

thx enable agrega espocrm y todo lo que necesita al estado de la caja; después thx apply la instala. Las apps se aplican recién cuando site_domain está definido.

sudo thx enable espocrm
sudo thx apply

Notas técnicas (pieces/espocrm/README.md)

Las notas técnicas de cada pieza están en inglés, tal como están en el repositorio.

EspoCRM 10.1.4, AGPL-3.0: accounts, contacts, leads, opportunities, cases, calendar, email. PHP 8.4 on Apache. Image espocrm/espocrm:10.1.4 (the official Docker Library image), pinned by index digest sha256:5f8fa9a7…878c; the index has linux/arm64 (docker buildx imagetools inspect, 2026-11-24). We ship only compose + config + post_up and pull the upstream image unmodified.

How it is wired

  • Two containers from one image: espocrm (Apache + PHP, the web UI and API) and espocrm-daemon (docker-daemon.sh: EspoCRM's scheduler; starts cron.php every 10 s). daemonMaxProcessNumber=1 (upstream default 5) so at most one cron worker runs; jobs run serially (upstream default). Apache prefork is cut to 1–6 workers (files/mpm_prefork.conf; the image's default allows 150, each 30–60 MiB).
  • Database: MariaDB from the box (THX_DB_*, db = "mariadb" in piece.toml). Files, custom metadata and client customisations in THX_DATA/{data,custom,client-custom}. The first start installs the schema and creates the built-in admin with THX_SECRET_ADMIN_PASSWORD.
  • Config by environment: the image's entrypoint writes every ESPOCRM_CONFIG_<NAME> into EspoCRM's config on every start (bin/command config:set --type=auto), so a changed value takes effect on restart. It handles scalars only; the list/object settings go through post_up.
  • Login: OIDC through Authelia. OpenID Connect is in the free core since 7.x (verified in 10.1.4 application/Espo/Core/Authentication/Oidc). Redirect URI https://crm.<apps_domain>/oauth-callback.php. EspoCRM sends the client secret in the token request body, so the Authelia client needs token_endpoint_auth_method: client_secret_post ([oidc] in piece.toml). PKCE on. Users are created on first login (username = preferred_username) and their name, email and teams are synced at every login. Authelia 4.39 puts groups in userinfo only; EspoCRM reads userinfo. The authorization prompt is select_account: EspoCRM's default consent makes Authelia show a consent page at every login regardless of the client's consent_mode, and login would ask for the password every time.
  • Login is automatic, in the same tab. EspoCRM's own OIDC login opens a popup on a click. The files in scripts/espo/ (copied by post_up into the container's custom/ and client/custom/, i.e. THX_DATA, owned by www-data; caches rebuilt when they changed) replace that:

    • client/custom/src/handlers/login/thx-oidc.js, made the OIDC login handler by custom/…/metadata/authenticationMethods/Oidc.json, extends upstream's handler: the login page starts the sign-in by itself and the tab goes to Authelia (PKCE verifier in the PHP session, as upstream). It does not start by itself when the page was reached from the CRM's own pages (after signing out the login page stays), for "log in as another user", or twice within a minute.
    • custom/Espo/Custom/EntryPoints/OauthCallback.php, made the oauthCallback entry point by custom/…/metadata/app/entryPoints.json (upstream pins its own class there): /oauth-callback.php hands the code back to the login page through sessionStorage and returns there. With a popup (other OAuth connections) it behaves as upstream, whose page only prints a line for the popup. With an Authelia session, opening https://crm.<apps_domain>/ lands inside with no click; without one, Authelia's form once and straight back. A refused code shows EspoCRM's error on the login page and stays there (tested; upstream answers Authelia's HTTP 400 for a bad code with "Internal server error"). Signing out also signs out of Authelia (oidcLogoutUrl, upstream behaviour; not tested here), so the next visit asks for the password at Authelia.
  • Password login is kept for administrators only (oidcFallback with oidcAllowRegularUserFallback=false): the box's own admin, used by post_up. People sign in with SSO; a regular user's password login gets 401 (tested). OIDC users are never made admins (oidcAllowAdminUser=false).
  • Mail: THX_SMTP_HOST:THX_SMTP_PORT, no auth, no TLS on the internal hop (smtpSecurity is set to empty; upstream default is TLS), from THX_MAIL_FROM. EspoCRM's guard against internal mail hosts would refuse the admin's "send test email" to that relay; post_up adds THX_SMTP_HOST:THX_SMTP_PORT to emailServerAllowedAddressList (via bin/command, as the Settings API does not expose it).

Companies → teams: how far it got

Done and tested, as far as EspoCRM's own access model goes:

  • post_up creates one team org-<org> per company in THX_ORGS, each carrying the role Company member: create = yes; read, edit, stream = team; delete = own; for Account, Contact, Lead, Opportunity, Case, Meeting, Call, Task, Document, Campaign, Target List. Assignment and user permission are team-level, so people can only assign records to colleagues and see colleagues only.
  • It maps LLDAP group org-<org> to team org-<org> (oidcTeamsIds + oidcTeamsColumns) with oidcSyncTeams, so each login sets the person's teams from the groups claim (and removes a team when they leave the group).
  • New records get the creator's teams: post_up puts one line at the top of each entity's before-save formula (marked // thx:, kept on re-runs, the admin's own formula lines stay below): ifThen(entity\isNew() && array\length(teamsIds) == 0, teamsIds = env\userAttribute('teamsIds')). OIDC sync does not set a user's default team, which is what the UI would otherwise put on new records, so without this line records would be team-less and invisible to colleagues.
  • Proven: alice (org-acme) creates an account and a contact; both land on org-acme; bob (org-acme) reads them; carol (org-globex) gets 403 and the account is absent from her list.

Limits:

  • A person in two companies sees both companies' records and their new records go to both teams.
  • Admins (the built-in admin) see everything; that is EspoCRM's admin model.
  • Orgs removed from THX_ORGS keep their team and records; the login mapping drops them.
  • Only the entities listed above are covered; a custom entity an admin adds later needs the role and formula line added (rerun post_up after adding it to SCOPES).

Test (./test.sh)

Throwaway LLDAP (alice + bob in org-acme, carol in org-globex), Authelia with the client the core lane is asked to generate from piece.toml, Caddy with its local CA (EspoCRM trusts it through a mounted CA bundle, test-only), Mailpit as the relay, MariaDB 11.8 (pinned, tmpfs). It checks: the first start installs; post_up prints changed, a second run prints nothing; in headless Chrome (test/sso.py) alice (Authelia session, no CRM account yet) opens the CRM and is inside as herself with no click, her account made with team org-acme; carol (no session) signs in at Authelia once and lands inside with team org-globex; a refused code leaves the login page showing EspoCRM's error, with no new trip to Authelia; alice, bob and carol log in through the same calls the login page makes (Oidc/authorizationData → Authelia → oauth-callback code → App/user with **oidc: auth) and their stored teams match their LLDAP groups; alice creates an account and a contact (sending the assigned user the edit form fills in) and both get team org-acme; bob reads the account, carol gets 403 and does not see it listed nor read the contact; password login for a regular user gets 401; the admin's test email reaches Mailpit from THX_MAIL_FROM; the daemon's scheduler has run (cronLastRunTime written).

RAM

Measured 2026-11-25 on the amd64 dev PC (the box is arm64; same PHP image, expect similar). Each container's cgroup is sampled every 0.25 s (memory.current minus inactive_file, as docker stats reports), through install, post_up, three logins and the checks. Peaks vary run to run with the scheduled jobs the daemon happens to run, so the limit uses the highest of the runs:

containerpeaks (MiB) over runslimit (max × 1.3)
espocrm120, 97, 108, 131mem_limit: 171m
espocrm-daemon51, 78, 132, 143mem_limit: 186m

ram_mb = 357 (both; the fourth run, 2026-11-25 by the conform lane, raised both). The test fails on any OOM kill under these limits (cgroup oom_kill and Docker oom events). The confirming run at the earlier 156m/172m limits passed with no OOM kill, but the daemon's figure reached its then 172 MiB limit (web 93 MiB): the figure counts active page cache, which the kernel reclaims under the limit, so it fills what it is given. Its true floor is unknown; watch it on the box (memory.events oom_kill) before lowering or trusting it. An earlier run with the daemon at 107 MiB, set from a 2 s docker stats sample of 82 MiB, OOM-killed two cron.php workers: the daemon idles at a few MiB and each cron.php spikes briefly, which coarse sampling misses. MariaDB is the box's shared one and not counted. The test makes few concurrent requests; Apache may run up to 6 PHP workers, so re-measure on the box with several people working.

Needs from other lanes

  • Authelia client (core): generated from piece.toml with token_endpoint_auth_method: client_secret_post — a new [oidc] key (default client_secret_basic).
  • MariaDB (core): database + user from THX_DB_*, utf8mb4.
  • post_up runner (core): runs scripts/post-up.py (python3 stdlib only) after compose up, with the piece's THX_* environment; it talks to 127.0.0.1:THX_PORT.

Known gaps

  • Company separation limits (above).
  • Mailboxes: personal/group mail accounts (IMAP from Stalwart) are refused for internal hosts unless host:port is in emailServerAllowedAddressList; post_up allows only the SMTP relay. The IMAP host:port needs a contract variable (THX_IMAP_HOST/PORT) before it can be added.
  • EspoCRM upgrades: the login handler extends upstream's handlers/login/oidc (10.1.4) and the callback replaces upstream's oauthCallback; re-run test.sh on every image bump.
  • Company admins (org-<org>-admins) get the same role as their colleagues: EspoCRM's admin flag is box-wide (every company's records), and OIDC users are never made admins (oidcAllowAdminUser=false). Owner decision (recommendation: keep it; a per-company admin role can be added when someone asks for it).
  • People removed from LLDAP keep their EspoCRM user (inactive login, since SSO refuses them); an admin deactivates the user to free the seat in lists.
  • No WebSocket (useWebSocket off, upstream default): lists refresh on navigation, not live.

Los datos de esta página salen de estos archivos del repositorio selfhostwizard:

  • pieces/espocrm/piece.toml
  • pieces/espocrm/compose.yaml
  • pieces/espocrm/README.md
  • internal/piece/piece.go

Esta página se genera desde el código al compilar el sitio, así que cambia cuando cambia el código.