From 226d5b5366c0680da4bf5cdec830f6c2f7b87518 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 17 Jun 2026 11:21:38 +0200 Subject: [PATCH] feat(wordpress): migrate plugins to meta/addons (req 026) plugin/mu_plugin addons declared; daggerhart OIDC + rbac-mapper bridge sso, wp-discourse bridges discourse. Settings absorbed from vars/oidc.yml + vars/discourse.yml (deleted); wp-discourse task uses include_vars for the runtime vault key. Co-Authored-By: Claude Opus 4.8 (1M context) --- roles/web-app-wordpress/README.md | 16 ++ .../meta/addons/activitypub.yml | 9 + .../daggerhart-openid-connect-generic.yml | 37 +++ .../meta/addons/infinito-oidc-rbac-mapper.yml | 6 + .../meta/addons/wp-discourse.yml | 25 ++ roles/web-app-wordpress/meta/services.yml | 13 +- .../daggerhart-openid-connect-generic.yml | 8 +- .../tasks/plugins/wp-discourse.yml | 12 +- roles/web-app-wordpress/vars/discourse.yml | 255 ------------------ roles/web-app-wordpress/vars/main.yml | 3 +- roles/web-app-wordpress/vars/oidc.yml | 30 --- 11 files changed, 108 insertions(+), 306 deletions(-) create mode 100644 roles/web-app-wordpress/meta/addons/activitypub.yml create mode 100644 roles/web-app-wordpress/meta/addons/daggerhart-openid-connect-generic.yml create mode 100644 roles/web-app-wordpress/meta/addons/infinito-oidc-rbac-mapper.yml create mode 100644 roles/web-app-wordpress/meta/addons/wp-discourse.yml delete mode 100644 roles/web-app-wordpress/vars/discourse.yml delete mode 100644 roles/web-app-wordpress/vars/oidc.yml diff --git a/roles/web-app-wordpress/README.md b/roles/web-app-wordpress/README.md index 3811b7297e..385c7b6932 100644 --- a/roles/web-app-wordpress/README.md +++ b/roles/web-app-wordpress/README.md @@ -50,6 +50,22 @@ RBAC under Multisite uses the hierarchical Keycloak group path: Operator-facing instructions for assigning these groups live in [Administration RBAC](../../docs/administration/configuration/rbac.md). The design contract is in [RBAC design](../../docs/contributing/design/iam/rbac.md). +## Addons + +Plugins and the OIDC→RBAC mu-plugin are declared in +[`meta/addons/`](./meta/addons/) under the unified addon contract +(requirement 026). The OIDC and WP-Discourse runtime config lives in each addon's `config:` block. + +| Addon | Mechanism | Default state | Bridges | +|-------|-----------|---------------|---------| +| `daggerhart-openid-connect-generic` | `plugin` | enabled with the `sso` service | `sso` → `web-app-keycloak` | +| `wp-discourse` | `plugin` | enabled with the `discourse` service | `discourse` → `web-app-discourse` | +| `activitypub` | `plugin` | always enabled (Fediverse federation) | none | +| `infinito-oidc-rbac-mapper` | `mu_plugin` | `required` (always installed, vendored) | `sso` → `web-app-keycloak` | + +The OIDC login + RBAC paths are covered by `test-admin-oidc-login.js` / +`test-rbac-roles.js`, the Discourse round-trip by `test-discourse-roundtrip.js`. + ## Playwright service dependencies The Playwright suite in [files/playwright/playwright.spec.js](files/playwright/playwright.spec.js) gates its scenarios on the following shared services (requirement 006). Scenarios that depend on a service report as `skipped` when the corresponding `_SERVICE_ENABLED=false` in the staged `.env`: diff --git a/roles/web-app-wordpress/meta/addons/activitypub.yml b/roles/web-app-wordpress/meta/addons/activitypub.yml new file mode 100644 index 0000000000..07cb903022 --- /dev/null +++ b/roles/web-app-wordpress/meta/addons/activitypub.yml @@ -0,0 +1,9 @@ +--- +enabled: true +required: false +mechanism: plugin +source: upstream +update: + monitored: true + catalog: wordpress-org + upstream_id: activitypub diff --git a/roles/web-app-wordpress/meta/addons/daggerhart-openid-connect-generic.yml b/roles/web-app-wordpress/meta/addons/daggerhart-openid-connect-generic.yml new file mode 100644 index 0000000000..474cb447b6 --- /dev/null +++ b/roles/web-app-wordpress/meta/addons/daggerhart-openid-connect-generic.yml @@ -0,0 +1,37 @@ +--- +enabled: "{{ lookup('config', 'web-app-wordpress', 'services.sso.enabled') | bool }}" +required: false +mechanism: plugin +source: upstream +bridges: + - sso +update: + monitored: true + catalog: wordpress-org + upstream_id: daggerhart-openid-connect-generic +config: + oidc_settings: + client_id: "{{ OIDC.CLIENT.ID }}" + client_secret: "{{ OIDC.CLIENT.SECRET }}" + issuer: "{{ OIDC.CLIENT.ISSUER_URL }}" + endpoint_login: "{{ OIDC.CLIENT.AUTHORIZE_URL }}" + endpoint_token: "{{ OIDC.CLIENT.TOKEN_URL }}" + endpoint_userinfo: "{{ OIDC.CLIENT.USER_INFO_URL }}" + endpoint_jwks: "{{ OIDC.CLIENT.CERTS }}" + endpoint_end_session: "{{ OIDC.CLIENT.LOGOUT_URL }}" + login_type: "auto" + scope: "openid profile email {{ RBAC.GROUP.CLAIM }}" + create_if_does_not_exist: true + enforce_privacy: false + link_existing_users: true + redirect_on_logout: true + redirect_user_back: true + enable_logging: "{{ MODE_DEBUG }}" + no_sslverify: false + http_request_timeout: 5 + identity_key: "{{ OIDC.ATTRIBUTES.USERNAME }}" + nickname_key: "{{ OIDC.ATTRIBUTES.USERNAME }}" + email_format: "{{ OIDC.ATTRIBUTES.EMAIL }}" + displayname_format: "{{ OIDC.ATTRIBUTES.GIVEN_NAME }} {{ OIDC.ATTRIBUTES.FAMILY_NAME }}" + identify_with_username: true + state_time_limit: 180 diff --git a/roles/web-app-wordpress/meta/addons/infinito-oidc-rbac-mapper.yml b/roles/web-app-wordpress/meta/addons/infinito-oidc-rbac-mapper.yml new file mode 100644 index 0000000000..6ec62d8281 --- /dev/null +++ b/roles/web-app-wordpress/meta/addons/infinito-oidc-rbac-mapper.yml @@ -0,0 +1,6 @@ +--- +required: true +mechanism: mu_plugin +source: vendored +bridges: + - sso diff --git a/roles/web-app-wordpress/meta/addons/wp-discourse.yml b/roles/web-app-wordpress/meta/addons/wp-discourse.yml new file mode 100644 index 0000000000..6871364e86 --- /dev/null +++ b/roles/web-app-wordpress/meta/addons/wp-discourse.yml @@ -0,0 +1,25 @@ +--- +enabled: "{{ lookup('config', 'web-app-wordpress', 'services.discourse.enabled') | bool }}" +required: false +mechanism: plugin +source: upstream +bridges: + - discourse +update: + monitored: true + catalog: wordpress-org + upstream_id: wp-discourse +config: + discourse_settings: + - name: discourse_connect + key: url + value: "{{ lookup('tls', 'web-app-discourse', 'url.base') }}" + - name: discourse_connect + key: api-key + value: "{{ vault_discourse_api_key }}" + - name: discourse_connect + key: publish-username + value: "system" + - name: discourse_logs + key: logs-enabled + value: "{{ MODE_DEBUG }}" diff --git a/roles/web-app-wordpress/meta/services.yml b/roles/web-app-wordpress/meta/services.yml index 73c6cdc0a8..61c4544088 100644 --- a/roles/web-app-wordpress/meta/services.yml +++ b/roles/web-app-wordpress/meta/services.yml @@ -1,5 +1,5 @@ --- -# nocheck: seaweedfs-required — object storage not implemented for this role +# nocheck: seaweedfs-required, object storage not implemented for this role sso: enabled: "{{ 'web-app-keycloak' in group_names }}" shared: "{{ 'web-app-keycloak' in group_names }}" @@ -13,7 +13,7 @@ dashboard: matomo: enabled: "{{ 'web-app-matomo' in group_names }}" shared: "{{ 'web-app-matomo' in group_names }}" -# nocheck: playwright-service-flag — DB engine, covered by role-local integration tests +# nocheck: playwright-service-flag, DB engine, covered by role-local integration tests mariadb: enabled: true # nocheck: dynamic-flag shared: "{{ 'svc-db-mariadb' in group_names }}" @@ -35,20 +35,13 @@ wordpress: max_upload_size: 256M multisite: enabled: false - plugins: - wp-discourse: - enabled: "{{ lookup('config', 'web-app-wordpress', 'services.discourse.enabled') | bool }}" - daggerhart-openid-connect-generic: - enabled: "{{ lookup('config', 'web-app-wordpress', 'services.sso.enabled') | bool }}" - activitypub: - enabled: true ports: local: http: 8003 run_after: - web-app-keycloak lifecycle: beta -# nocheck: playwright-service-flag — verified by web-svc-css provider spec +# nocheck: playwright-service-flag, verified by web-svc-css provider spec css: enabled: "{{ 'web-svc-css' in group_names }}" shared: "{{ 'web-svc-css' in group_names }}" diff --git a/roles/web-app-wordpress/tasks/plugins/daggerhart-openid-connect-generic.yml b/roles/web-app-wordpress/tasks/plugins/daggerhart-openid-connect-generic.yml index 59e81f949f..48311b125b 100644 --- a/roles/web-app-wordpress/tasks/plugins/daggerhart-openid-connect-generic.yml +++ b/roles/web-app-wordpress/tasks/plugins/daggerhart-openid-connect-generic.yml @@ -1,11 +1,5 @@ --- -- name: "Load OIDC settings variables" - include_vars: - file: "{{ role_path }}/vars/oidc.yml" - name: oidc_vars - - name: "Ensure the OIDC settings option exists as a PHP-serialized empty array" - # Generate an empty serialized array in the container, then add or update the option command: > {{ BIN_COMPOSE }} exec -u www-data -T application bash -lc "serialized_empty_array=$(wp eval 'echo serialize(array());' --path={{ WORDPRESS_DOCKER_HTML_PATH }}); \ @@ -18,7 +12,7 @@ - name: "Apply all OIDC settings via WP-CLI eval (safe via base64)" # Convert the settings map to base64-encoded JSON to avoid shell escaping issues vars: - oidc_settings_json_b64: "{{ oidc_vars.oidc_settings | to_json | b64encode }}" + oidc_settings_json_b64: "{{ lookup('config', application_id, 'addons.daggerhart-openid-connect-generic.config.oidc_settings') | to_json | b64encode }}" command: > {{ BIN_COMPOSE }} exec -u www-data -T application bash -lc "wp eval \"update_option('openid_connect_generic_settings', json_decode(base64_decode('{{ oidc_settings_json_b64 }}'), true));\" --path={{ WORDPRESS_DOCKER_HTML_PATH diff --git a/roles/web-app-wordpress/tasks/plugins/wp-discourse.yml b/roles/web-app-wordpress/tasks/plugins/wp-discourse.yml index c9039410c7..1c14bf4076 100644 --- a/roles/web-app-wordpress/tasks/plugins/wp-discourse.yml +++ b/roles/web-app-wordpress/tasks/plugins/wp-discourse.yml @@ -43,9 +43,15 @@ set_fact: vault_discourse_api_key: "{{ discourse_generated_api_key.stdout | trim }}" -- name: "Load WP Discourse settings" - include_vars: - file: "{{ role_path }}/vars/discourse.yml" +# Use include_vars (not lookup('file')|from_yaml) so values lazy-render and the deploy-time vault_discourse_api_key resolves in this scope. +- name: "Load WP Discourse addon spec from meta/addons/wp-discourse.yml" + ansible.builtin.include_vars: + file: "{{ [role_path, 'meta/addons', 'wp-discourse.yml'] | path_join }}" + name: wp_discourse_addon +- name: "Resolve WP Discourse settings" + set_fact: + discourse_settings: "{{ wp_discourse_addon.config.discourse_settings | default([]) }}" + changed_when: false - name: "Install WP Discourse plugin" command: > diff --git a/roles/web-app-wordpress/vars/discourse.yml b/roles/web-app-wordpress/vars/discourse.yml deleted file mode 100644 index d2144d2590..0000000000 --- a/roles/web-app-wordpress/vars/discourse.yml +++ /dev/null @@ -1,255 +0,0 @@ ---- -# Defines WP Discourse plugin settings -# @see https://github.com/discourse/wp-discourse - -# Defines WP Discourse plugin settings (exported from your current wp_options dump) -# -# wp-discourse `auto-publish` stays DISABLED by default. The per-post -# "Publish to Discourse" sidebar toggle MUST remain the default -# authoring path, because it matches the real editor workflow and is -# therefore what the Playwright round-trip scenario drives. -# Setting `discourse_publish.auto-publish: true` globally would bypass -# exactly the plugin code path the test is meant to exercise. -# If an operator wants network-wide auto-publish for a deployment they -# MUST override this setting in inventory rather than flipping the -# commented-out default below. - -discourse_settings: - # - name: wpdc_discourse_domain - # key: wpdc_discourse_domain - # value: "" - - - name: discourse_connect - key: url - value: "{{ lookup('tls', 'web-app-discourse', 'url.base') }}" - - name: discourse_connect - key: api-key - value: "{{ vault_discourse_api_key }}" - - name: discourse_connect - key: publish-username - value: "system" - - #- name: discourse_publish - # key: display-subcategories - # value: false - #- name: discourse_publish - # key: publish-category - # value: false - #- name: discourse_publish - # key: publish-category-update - # value: false - #- name: discourse_publish - # key: full-post-content - # value: false - #- name: discourse_publish - # key: allow-tags - # value: false - #- name: discourse_publish - # key: max-tags - # value: 5 - #- name: discourse_publish - # key: publish-as-unlisted - # value: false - #- name: discourse_publish - # key: custom-excerpt-length - # value: 55 - #- name: discourse_publish - # key: add-featured-link - # value: false - #- name: discourse_publish - # key: auto-publish - # value: false - #- name: discourse_publish - # key: force-publish - # value: false - #- name: discourse_publish - # key: force-publish-max-age - # value: 0 - #- name: discourse_publish - # key: publish-failure-notice - # value: true - #- name: discourse_publish - # key: publish-failure-email - # value: "{{ lookup('users', 'administrator').email }}" - #- name: discourse_publish - # key: auto-track - # value: true - #- name: discourse_publish - # key: allowed_post_types - # value: - # - post - #- name: discourse_publish - # key: hide-discourse-name-field - # value: false - #- name: discourse_publish - # key: discourse-username-editable - # value: false - # - #- name: discourse_comment - # key: enable-discourse-comments - # value: false - #- name: discourse_comment - # key: comment-type - # value: "display-comments" - #- name: discourse_comment - # key: ajax-load - # value: false - #- name: discourse_comment - # key: cache-html - # value: false - #- name: discourse_comment - # key: clear-cached-comment-html - # value: false - #- name: discourse_comment - # key: discourse-new-tab - # value: false - #- name: discourse_comment - # key: comment-sync-period - # value: 10 - #- name: discourse_comment - # key: hide-wordpress-comments - # value: false - #- name: discourse_comment - # key: show-existing-comments - # value: false - #- name: discourse_comment - # key: existing-comments-heading - # value: "" - #- name: discourse_comment - # key: max-comments - # value: 5 - #- name: discourse_comment - # key: min-replies - # value: 1 - #- name: discourse_comment - # key: min-score - # value: 0 - #- name: discourse_comment - # key: min-trust-level - # value: 1 - #- name: discourse_comment - # key: bypass-trust-level-score - # value: 50 - #- name: discourse_comment - # key: custom-datetime-format - # value: "" - #- name: discourse_comment - # key: only-show-moderator-liked - # value: false - #- name: discourse_comment - # key: load-comment-css - # value: false - # - #- name: discourse_configurable_text - # key: discourse-link-text - # value: "" - #- name: discourse_configurable_text - # key: start-discussion-text - # value: "Start the discussion at" - #- name: discourse_configurable_text - # key: continue-discussion-text - # value: "Continue the discussion at" - #- name: discourse_configurable_text - # key: join-discussion-text - # value: "Join the discussion at" - #- name: discourse_configurable_text - # key: comments-singular-text - # value: "Comment" - #- name: discourse_configurable_text - # key: comments-plural-text - # value: "Comments" - #- name: discourse_configurable_text - # key: no-comments-text - # value: "Join the Discussion" - #- name: discourse_configurable_text - # key: notable-replies-text - # value: "Notable Replies" - #- name: discourse_configurable_text - # key: comments-not-available-text - # value: "Comments are not currently available for this post." - #- name: discourse_configurable_text - # key: participants-text - # value: "Participants" - #- name: discourse_configurable_text - # key: published-at-text - # value: "Originally published at:" - #- name: discourse_configurable_text - # key: single-reply-text - # value: "Reply" - #- name: discourse_configurable_text - # key: many-replies-text - # value: "Replies" - #- name: discourse_configurable_text - # key: more-replies-more-text - # value: "more" - #- name: discourse_configurable_text - # key: external-login-text - # value: "Log in with Discourse" - #- name: discourse_configurable_text - # key: link-to-discourse-text - # value: "Link your account to Discourse" - #- name: discourse_configurable_text - # key: linked-to-discourse-text - # value: "Your account is linked with Discourse!" - # - #- name: discourse_webhook - # key: use-discourse-webhook - # value: false - #- name: discourse_webhook - # key: webhook-secret - # value: "" - #- name: discourse_webhook - # key: webhook-match-old-topics - # value: false - #- name: discourse_webhook - # key: use-discourse-user-webhook - # value: false - #- name: discourse_webhook - # key: webhook-match-user-email - # value: false - # - #- name: discourse_sso_common - # key: sso-secret - # value: "" - # - #- name: discourse_sso_provider - # key: enable-sso - # value: false - #- name: discourse_sso_provider - # key: auto-create-sso-user - # value: false - #- name: discourse_sso_provider - # key: login-path - # value: "" - #- name: discourse_sso_provider - # key: real-name-as-discourse-name - # value: false - #- name: discourse_sso_provider - # key: force-avatar-update - # value: false - #- name: discourse_sso_provider - # key: redirect-without-login - # value: false - # - #- name: discourse_sso_client - # key: sso-desktop-enabled - # value: false - #- name: discourse_sso_client - # key: sso-desktop-login-form-change - # value: false - #- name: discourse_sso_client - # key: sso-desktop-login-form-redirect - # value: "" - #- name: discourse_sso_client - # key: sso-desktop-sync-by-email - # value: false - #- name: discourse_sso_client - # key: sso-desktop-disable-create-user - # value: false - #- name: discourse_sso_client - # key: sso-desktop-sync-logout - # value: false - # - - name: discourse_logs - key: logs-enabled - value: "{{ MODE_DEBUG }}" diff --git a/roles/web-app-wordpress/vars/main.yml b/roles/web-app-wordpress/vars/main.yml index 1950078921..940c8577b1 100644 --- a/roles/web-app-wordpress/vars/main.yml +++ b/roles/web-app-wordpress/vars/main.yml @@ -15,7 +15,8 @@ WORDPRESS_IMAGE: "{{ lookup('config', application_id, 'services.' ~ entity_name WORDPRESS_CONTAINER: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.name') }}" WORDPRESS_VOLUME: "{{ lookup('config', application_id, 'volumes.data') }}" WORDPRESS_DOMAINS: "{{ lookup('config', application_id, 'server.domains.canonical') }}" -WORDPRESS_PLUGINS: "{{ lookup('config', application_id, 'services.' ~ entity_name ~ '.plugins') | dict2items }}" +# Excludes the mu_plugin, which 05_mu_plugins.yml installs separately. +WORDPRESS_PLUGINS: "{{ lookup('config', application_id, 'addons') | dict2items | selectattr('value.mechanism', 'equalto', 'plugin') | list }}" WORDPRESS_USER: "www-data" # Email diff --git a/roles/web-app-wordpress/vars/oidc.yml b/roles/web-app-wordpress/vars/oidc.yml deleted file mode 100644 index 7ab48180fb..0000000000 --- a/roles/web-app-wordpress/vars/oidc.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -# Defines OIDC settings for the OpenID Connect Generic plugin, with explanatory comments. - -oidc_settings: - client_id: "{{ OIDC.CLIENT.ID }}" # The client ID that identifies WordPress as the OIDC client. - client_secret: "{{ OIDC.CLIENT.SECRET }}" # The secret key used by WordPress to authenticate to the OIDC provider. - issuer: "{{ OIDC.CLIENT.ISSUER_URL }}" # Expected issuer (`iss`) used for strict JWT issuer validation. - endpoint_login: "{{ OIDC.CLIENT.AUTHORIZE_URL }}" # URL of the authorization endpoint to initiate the login flow. - endpoint_token: "{{ OIDC.CLIENT.TOKEN_URL }}" # URL of the token endpoint for exchanging authorization codes for tokens. - endpoint_userinfo: "{{ OIDC.CLIENT.USER_INFO_URL }}" # URL of the userinfo endpoint to retrieve user profile data. - endpoint_jwks: "{{ OIDC.CLIENT.CERTS }}" # URL of the JWKS endpoint used to verify ID token signatures. - endpoint_end_session: "{{ OIDC.CLIENT.LOGOUT_URL }}" # URL of the end-session endpoint to log users out of the IDP. - login_type: "auto" # Determines how the login interface is rendered (e.g., button or form). - scope: "openid profile email {{ RBAC.GROUP.CLAIM }}" # Scopes requested from the OIDC provider during authentication. Includes the RBAC group-membership scope so Keycloak emits the `groups` claim consumed by the mu-plugin infinito-oidc-rbac-mapper.php for role mapping. - create_if_does_not_exist: true # Auto-create a new WP user if one doesn’t exist. - enforce_privacy: false # Require authentication for all site pages if set to true. - link_existing_users: true # Link OIDC login to existing WP users by matching email. - redirect_on_logout: true # Redirect users after logout to the login screen or homepage. - redirect_user_back: true # Return users to their original URL after successful login. - #acr_values: "{{ OIDC.CLIENT.acr_values | default('') }}" # ACR values defining required authentication context (e.g., MFA level). - enable_logging: "{{ MODE_DEBUG }}" # Enable detailed plugin logging for debugging and auditing. - # log_limit: "{{ OIDC.CLIENT.log_limit | default('') }}" # Maximum number of log entries to retain before pruning. - no_sslverify: false # The flag to enable/disable SSL verification during authorization. - http_request_timeout: 5 # The timeout for requests made to the IDP. Default value is 5. - identity_key: "{{ OIDC.ATTRIBUTES.USERNAME }}" # The key in the user claim array to find the user's identification data. - nickname_key: "{{ OIDC.ATTRIBUTES.USERNAME }}" # The key in the user claim array to find the user's nickname. - email_format: "{{ OIDC.ATTRIBUTES.EMAIL }}" # The key(s) in the user claim array to formulate the user's email address. - displayname_format: "{{ OIDC.ATTRIBUTES.GIVEN_NAME }} {{ OIDC.ATTRIBUTES.FAMILY_NAME }}" # The key(s) in the user claim array to formulate the user's display name. - identify_with_username: true # The flag which indicates how the user's identity will be determined. - state_time_limit: 180 # The valid time limit of the state, in seconds. Defaults to 180 seconds.