From 279a449566abef819d69ff6a89d71cbeadbbd8db Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 3 Nov 2026 20:42:17 +0100 Subject: [PATCH] fix(web-app-moodle): sync the auth_oidc plugin from the image into the code volume The entrypoint refills the shared code volume only when the release changes, so a volume bootstrapped at 5.3.0 by an image without auth_oidc never received the plugin from a later same-release image; galaxyserver's production deploy failed at the presence check although the image ships it (probe: /opt/moodle-source/public/auth/oidc exists). 04_oidc.yml now asserts the image ships the plugin, naming the image when it does not, and syncs it into the volume as the runtime user through a staging directory, only when diff -rq finds a difference, before the existing presence check. The OIDC upgrade.php run no longer hides a failed plugin install behind failed_when: false, matching the MCP and objectfs plugin tasks. Co-Authored-By: Claude Opus 5.5 --- roles/web-app-moodle/tasks/04_oidc.yml | 30 ++++- roles/web-app-moodle/vars/main.yml | 2 + .../roles/web-app-moodle/tasks/__init__.py | 0 .../web-app-moodle/tasks/test_04_oidc.py | 117 ++++++++++++++++++ 4 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 tests/unit/python/roles/web-app-moodle/tasks/__init__.py create mode 100644 tests/unit/python/roles/web-app-moodle/tasks/test_04_oidc.py diff --git a/roles/web-app-moodle/tasks/04_oidc.yml b/roles/web-app-moodle/tasks/04_oidc.yml index 78c613db4b..41d41d5bfe 100644 --- a/roles/web-app-moodle/tasks/04_oidc.yml +++ b/roles/web-app-moodle/tasks/04_oidc.yml @@ -2,6 +2,33 @@ # Configure Moodle's auth_oidc plugin (variant 0 only). Variant 1 # disables the OIDC shared service so this file is not included. +- name: "🔎 Check the auth_oidc plugin is baked into the image" + shell: > + container exec --user root {{ MOODLE_CONTAINER_ADDRESS }} test -d {{ MOODLE_OIDC_PLUGIN_SOURCE_DIR }} + register: moodle_oidc_plugin_source + changed_when: false + failed_when: moodle_oidc_plugin_source.rc not in [0, 1] + +- name: "🛑 Refuse a Moodle image built without the auth_oidc plugin" + ansible.builtin.assert: + that: + - moodle_oidc_plugin_source.rc == 0 + fail_msg: >- + {{ MOODLE_OIDC_PLUGIN_SOURCE_DIR }} is missing, so the Moodle image was built + without the auth_oidc plugin and the code volume cannot receive it. + +- name: "📋 Sync the auth_oidc plugin from the image into the code volume" + shell: > + container exec --user {{ MOODLE_RUNTIME_USER }} {{ MOODLE_CONTAINER_ADDRESS }} + sh -c 'diff -rq {{ MOODLE_OIDC_PLUGIN_SOURCE_DIR }} {{ MOODLE_OIDC_PLUGIN_DIR }} >/dev/null 2>&1 && exit 0; + rm -rf {{ MOODLE_OIDC_PLUGIN_SYNC_DIR }} + && cp -aT {{ MOODLE_OIDC_PLUGIN_SOURCE_DIR }} {{ MOODLE_OIDC_PLUGIN_SYNC_DIR }} + && rm -rf {{ MOODLE_OIDC_PLUGIN_DIR }} + && mv {{ MOODLE_OIDC_PLUGIN_SYNC_DIR }} {{ MOODLE_OIDC_PLUGIN_DIR }} + && echo synced' + register: moodle_oidc_plugin_sync + changed_when: "'synced' in moodle_oidc_plugin_sync.stdout" + - name: "🔎 Check OIDC plugin presence" shell: > container exec --user root {{ MOODLE_CONTAINER_ADDRESS }} test -d {{ MOODLE_OIDC_PLUGIN_DIR }} @@ -11,7 +38,7 @@ - name: "🛑 Fail if OIDC plugin is missing" fail: - msg: "auth_oidc plugin not found at {{ MOODLE_OIDC_PLUGIN_DIR }} — image build is incomplete" + msg: "auth_oidc plugin not found at {{ MOODLE_OIDC_PLUGIN_DIR }} after the sync from {{ MOODLE_OIDC_PLUGIN_SOURCE_DIR }}" when: oidc_plugin_check.rc != 0 - name: "▶️ Run Moodle DB upgrade for OIDC plugin" @@ -19,7 +46,6 @@ container exec --user {{ MOODLE_RUNTIME_USER }} {{ MOODLE_CONTAINER_ADDRESS }} php {{ MOODLE_CLI_DIR }}/upgrade.php --non-interactive changed_when: false - failed_when: false - name: "🔧 Set Moodle OIDC configuration via CLI" include_tasks: utils/plugin_config.yml diff --git a/roles/web-app-moodle/vars/main.yml b/roles/web-app-moodle/vars/main.yml index 8be83dab15..24b7209d6b 100644 --- a/roles/web-app-moodle/vars/main.yml +++ b/roles/web-app-moodle/vars/main.yml @@ -41,7 +41,9 @@ MOODLE_OIDC_PLUGIN_UPSTREAM: "{{ lookup('config', application_id, 'addons.auth_o MOODLE_OIDC_PLUGIN_ARCHIVE_URL: "https://github.com/{{ MOODLE_OIDC_PLUGIN_UPSTREAM }}/archive/refs/tags/{{ MOODLE_OIDC_PLUGIN_VERSION }}.zip" MOODLE_OIDC_PLUGIN_URL_PATH: "auth/oidc" MOODLE_OIDC_PLUGIN_RELPATH: "{{ [MOODLE_WEBROOT_SUBDIR, MOODLE_OIDC_PLUGIN_URL_PATH] | path_join }}" +MOODLE_OIDC_PLUGIN_SOURCE_DIR: "{{ [MOODLE_SOURCE_DIR, MOODLE_OIDC_PLUGIN_RELPATH] | path_join }}" MOODLE_OIDC_PLUGIN_DIR: "{{ [MOODLE_CODE_DIR, MOODLE_OIDC_PLUGIN_RELPATH] | path_join }}" +MOODLE_OIDC_PLUGIN_SYNC_DIR: "{{ [MOODLE_CODE_DIR, '.auth_oidc.sync'] | path_join }}" MOODLE_CLI_DIR: "{{ [MOODLE_CODE_DIR, MOODLE_CLI_RELPATH] | path_join }}" MOODLE_CONFIG: "{{ [MOODLE_CODE_DIR, 'config.php'] | path_join }}" MOODLE_PLUGIN_CONFIG_SCRIPT: "/tmp/infinito-plugin-config.php" diff --git a/tests/unit/python/roles/web-app-moodle/tasks/__init__.py b/tests/unit/python/roles/web-app-moodle/tasks/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/python/roles/web-app-moodle/tasks/test_04_oidc.py b/tests/unit/python/roles/web-app-moodle/tasks/test_04_oidc.py new file mode 100644 index 0000000000..76fdf5b224 --- /dev/null +++ b/tests/unit/python/roles/web-app-moodle/tasks/test_04_oidc.py @@ -0,0 +1,117 @@ +import filecmp +import re +import subprocess +import tempfile +import unittest +from pathlib import Path + +from jinja2 import Environment, StrictUndefined + +from utils import PROJECT_ROOT +from utils.cache.yaml import load_yaml_any + +TASKS = PROJECT_ROOT / "roles/web-app-moodle/tasks/04_oidc.yml" +SYNC_TASK = "📋 Sync the auth_oidc plugin from the image into the code volume" +PLUGIN_V2 = { + "version.php": "version = 2;\n", + "classes/oidcclient.php": "version = 1;\n", + "classes/oidcclient.php": "