From 9456bdbdd7fa496ec74840b32737258f3ef166ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 25 Nov 2026 14:49:44 +0100 Subject: [PATCH] run the thumbnails service in its own container (#435) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * run the thumbnails service in its own container Since 9.0.0 the thumbnails service is a stateless resizer: webdav posts the source image to WEBDAV_THUMBNAILS_GENERATOR_URL and keeps the cache. We now start it as `opencloud thumbnails server` in a dedicated container from the same image and exclude it from the main container. Decoding untrusted images is a classic attack surface. The new container has no access to the config, the secrets or the data, runs read-only without capabilities and is only reachable on the internal thumbnails-net. The service has no authentication, so it must not be exposed. It costs about 50MB of RAM for the extra process. The exclude list becomes static, so the idm files simply add thumbnails to it. This avoids the order dependent EXCLUDE_ADDITIONAL_SERVICES workaround of https://github.com/opencloud-eu/opencloud-compose/pull/422, the imagor module only has to point the generator URL at imagor. The container registers with an in memory registry, there is no nats to talk to and webdav uses the URL anyway. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Jörn Friedrich Dreyer * let imagor replace the thumbnails container thumbnails/imagor.yml now scales the built-in thumbnails container to 0 instead of leaving it idle next to imagor. opencloud only waits for imagor, the depends_on of the base file is replaced with !override, which needs docker compose 2.24.4 or newer. Scaling to 0 instead of a profile also stops a running thumbnails container when imagor is added to an existing deployment. Removing imagor.yml again brings it back, --remove-orphans cleans up imagor. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Jörn Friedrich Dreyer --------- Signed-off-by: Jörn Friedrich Dreyer --- README.md | 10 ++++++++-- docker-compose.yml | 45 +++++++++++++++++++++++++++++++++++++++++++ idm/external-idp.yml | 3 ++- idm/ldap-keycloak.yml | 3 ++- thumbnails/imagor.yml | 9 ++++++++- 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8062cf8..d2e78e8 100644 --- a/README.md +++ b/README.md @@ -196,11 +196,17 @@ By default, OpenCloud Compose uses the base variant of `apache/tika` which provi The base variant is recommended for most use cases. If you need advanced features like specialized OCR processing or specific image format support, you can switch to the full variant by setting `TIKA_DOCKER_VARIANT=full` in your `.env` file. +### Thumbnails + +The thumbnails service of OpenCloud runs in its own `thumbnails` container, started from the same image as `opencloud`. Decoding untrusted images is a classic attack surface, so it happens in a container without access to the config, the secrets or the data of OpenCloud: a read-only filesystem, no capabilities and only the internal `thumbnails-net` network, which has no route to the outside. The service has no authentication, so never publish its port or route to it through the reverse proxy. + +The webdav service posts the source images to `http://thumbnails:9186`. The additional container needs about 50 MB of RAM. + ### With imagor Previews The OpenCloud image ships no libheif on purpose, so a heic, heif or avif is refused with `406 unreadable image`. imagor reads those formats. Enable it using either method: -> **Version Requirement**: This setup needs OpenCloud 9.0.0 or newer. +> **Version Requirement**: This setup needs OpenCloud 9.0.0 or newer and Docker Compose 2.24.4 or newer, which understands the `!override` tag. Using `-f` flags: ```bash @@ -213,7 +219,7 @@ COMPOSE_FILE=docker-compose.yml:thumbnails/imagor.yml:traefik/opencloud.yml ``` This setup includes: -- imagor as the preview generator OpenCloud posts source images to +- imagor as the preview generator OpenCloud posts source images to, replacing the `thumbnails` container, which is scaled to 0 - Previews for heic, heif and avif files, including image sequences, in the file list and the preview app - imagor on an internal network without a route to the outside, with a read-only filesystem and no capabilities diff --git a/docker-compose.yml b/docker-compose.yml index 08faee8..b635288 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,7 @@ services: user: ${OC_CONTAINER_UID_GID:-1000:1000} networks: opencloud-net: + thumbnails-net: entrypoint: - /bin/sh # run opencloud init to initialize a configuration file with random secrets @@ -65,6 +66,9 @@ services: # with X being a number larger than 10240000. You can set a custom limit, for example 20480000. # Keep in mind that doubling the GRPC_MAX_RECEIVED_MESSAGE_SIZE limit may also double your peak RAM usage. OC_GRPC_MAX_RECEIVED_MESSAGE_SIZE: + # thumbnails are made by the thumbnails container below, webdav posts the images there + OC_EXCLUDE_RUN_SERVICES: thumbnails + WEBDAV_THUMBNAILS_GENERATOR_URL: http://thumbnails:9186 volumes: - ./config/opencloud/csp.yaml:/etc/opencloud/csp.yaml - ./config/opencloud/apps.yaml:/etc/opencloud/apps.yaml @@ -73,6 +77,45 @@ services: - ${OC_CONFIG_DIR:-opencloud-config}:/etc/opencloud - ${OC_DATA_DIR:-opencloud-data}:/var/lib/opencloud - ${OC_APPS_DIR:-./config/opencloud/apps}:/var/lib/opencloud/web/assets/apps + depends_on: + thumbnails: + condition: service_healthy + logging: + driver: ${LOG_DRIVER:-local} + restart: always + + # The built-in thumbnails service runs in its own container, so decoding untrusted + # images happens without access to the config, the secrets or the data of OpenCloud. + # It has no authentication, so it is only reachable on the internal thumbnails-net. + # Do NOT publish a port or expose it via the reverse proxy. + thumbnails: + # same image as opencloud, keep both tags in sync + # renovate: depName=opencloudeu/opencloud-rolling + image: ${OC_DOCKER_IMAGE:-opencloudeu/opencloud-rolling}:${OC_DOCKER_TAG:-9.1.0} + user: ${OC_CONTAINER_UID_GID:-1000:1000} + command: ["thumbnails", "server"] + environment: + THUMBNAILS_HTTP_ADDR: 0.0.0.0:9186 + # webdav finds the service by WEBDAV_THUMBNAILS_GENERATOR_URL, there is no nats to register with + MICRO_REGISTRY: memory + OC_LOG_LEVEL: ${LOG_LEVEL:-info} + OC_LOG_COLOR: "${LOG_PRETTY:-false}" + OC_LOG_PRETTY: "${LOG_PRETTY:-false}" + networks: + thumbnails-net: + read_only: true + tmpfs: + - /tmp:size=256m + cap_drop: + - ALL + security_opt: + - no-new-privileges:true + healthcheck: + test: ["CMD", "opencloud", "thumbnails", "health"] + interval: 5s + timeout: 5s + retries: 10 + start_period: 5s logging: driver: ${LOG_DRIVER:-local} restart: always @@ -83,3 +126,5 @@ volumes: networks: opencloud-net: + thumbnails-net: + internal: true diff --git a/idm/external-idp.yml b/idm/external-idp.yml index 38e4601..e256700 100644 --- a/idm/external-idp.yml +++ b/idm/external-idp.yml @@ -28,7 +28,8 @@ services: PROXY_ROLE_ASSIGNMENT_DRIVER: ${PROXY_ROLE_ASSIGNMENT_DRIVER:-oidc} OC_OIDC_ISSUER: ${IDP_ISSUER_URL:-https://keycloak.opencloud.test/realms/openCloud} # This specifies to start all services except idm and idp. These are replaced by external services. - OC_EXCLUDE_RUN_SERVICES: idm,idp + # thumbnails runs in its own container, see docker-compose.yml + OC_EXCLUDE_RUN_SERVICES: idm,idp,thumbnails # IdP specific configuration for auto-provisioning OC_LDAP_SERVER_WRITE_ENABLED: "true" PROXY_AUTOPROVISION_ACCOUNTS: "true" diff --git a/idm/ldap-keycloak.yml b/idm/ldap-keycloak.yml index 272cd54..7d39958 100644 --- a/idm/ldap-keycloak.yml +++ b/idm/ldap-keycloak.yml @@ -19,7 +19,8 @@ services: FRONTEND_READONLY_USER_ATTRIBUTES: "user.onPremisesSamAccountName,user.displayName,user.mail,user.passwordProfile,user.accountEnabled,user.appRoleAssignments" OC_LDAP_SERVER_WRITE_ENABLED: "false" # the ldap is managed by Keycloak, so it is not writable by OpenCloud # This specifies to start all services except idm and idp. These are replaced by external services. - OC_EXCLUDE_RUN_SERVICES: idm,idp + # thumbnails runs in its own container, see docker-compose.yml + OC_EXCLUDE_RUN_SERVICES: idm,idp,thumbnails # Keycloak IDP specific configuration PROXY_AUTOPROVISION_ACCOUNTS: "false" PROXY_ROLE_ASSIGNMENT_DRIVER: "oidc" diff --git a/thumbnails/imagor.yml b/thumbnails/imagor.yml index 5283b0f..0f43d17 100644 --- a/thumbnails/imagor.yml +++ b/thumbnails/imagor.yml @@ -35,10 +35,17 @@ services: OC_THUMBNAILS_ADDITIONAL_SOURCE_TYPES: ${THUMBNAILS_ADDITIONAL_SOURCE_TYPES:-image/heic,image/heif,image/avif,image/heic-sequence,image/heif-sequence} networks: imagor-net: - depends_on: + # replaces the thumbnails container, so opencloud must not wait for it + depends_on: !override imagor: condition: service_healthy + # imagor replaces the built-in thumbnails container. Scaling it to 0 also stops + # it when imagor is added to an existing deployment. + thumbnails: + deploy: + replicas: 0 + networks: imagor-net: internal: true