web-app-xwiki: admin bootstrap & REST/extension install fixes

• Guard admin tasks via XWIKI_SSO_ENABLED
• Create admin using XWikiUsers object API
• Wait for REST without DW redirect
• Install OIDC/LDAP via /rest/jobs (+verify)
• Mount xwiki.cfg/properties under Tomcat WEB-INF
• Build REST URLs with url_join; enable DW auto bootstrap + repos

https://chatgpt.com/share/68c42502-a5cc-800f-b05a-a1dbe48f014d
This commit is contained in:
2025-09-12 15:50:30 +02:00
parent 53b3a3a7b1
commit f106d5ec36
7 changed files with 108 additions and 42 deletions

View File

@@ -16,6 +16,7 @@
- name: Load setup procedures for admin - name: Load setup procedures for admin
include_tasks: 03_administrator.yml include_tasks: 03_administrator.yml
when: not (XWIKI_SSO_ENABLED | bool)
- name: Load setup procedures for extensions - name: Load setup procedures for extensions
include_tasks: 04_extensions.yml include_tasks: 04_extensions.yml

View File

@@ -1,43 +1,73 @@
--- # 1) Create page XWiki.<userid> (PUT is idempotent)
# Wait until REST endpoint is available (01_core usually ensures this, but add safety) - name: "XWIKI | Ensure user page exists: XWiki.{{ XWIKI_ADMIN_USER }}"
- name: "XWIKI | Wait until REST answers"
uri: uri:
url: "{{ XWIKI_REST_BASE }}" url: "{{ XWIKI_REST_BASE }}wikis/xwiki/spaces/XWiki/pages/{{ XWIKI_ADMIN_USER | urlencode }}"
status_code: [200, 401] method: PUT
register: _rest_ping user: "{{ XWIKI_SUPERADMIN_USERNAME }}"
retries: 60 password: "{{ XWIKI_SUPERADMIN_PASSWORD }}"
delay: 5 force_basic_auth: true
until: _rest_ping is succeeded status_code: [201, 202, 204, 200]
headers:
Content-Type: "application/xml"
Accept: "application/xml"
body: |
<page xmlns="http://www.xwiki.org">
<title>{{ XWIKI_ADMIN_USER }}</title>
</page>
register: _user_page
# Check if the target admin already exists # 2) Add XWiki.XWikiUsers object (only if it does not already exist)
# 404 => missing, 302 => DW redirect (treat as missing for bootstrap) - name: "XWIKI | Check if XWikiUsers object exists"
- name: "XWIKI | Check if target admin user exists"
uri: uri:
url: "{{ XWIKI_REST_XWIKI }}/users/{{ XWIKI_ADMIN_USER | urlencode }}" url: "{{ XWIKI_REST_BASE }}wikis/xwiki/spaces/XWiki/pages/{{ XWIKI_ADMIN_USER | urlencode }}/objects?classname=XWiki.XWikiUsers"
method: GET method: GET
user: "{{ XWIKI_SUPERADMIN_USERNAME }}" user: "{{ XWIKI_SUPERADMIN_USERNAME }}"
password: "{{ XWIKI_SUPERADMIN_PASSWORD }}" password: "{{ XWIKI_SUPERADMIN_PASSWORD }}"
force_basic_auth: true force_basic_auth: true
status_code: [200, 404, 302] status_code: [200, 404]
register: _admin_exists register: _users_obj_list
# Create admin user if not existing (or DW still redirecting) - name: "XWIKI | Add XWiki.XWikiUsers object"
- name: "XWIKI | Create admin user via REST"
uri: uri:
url: "{{ XWIKI_REST_XWIKI }}/users" url: "{{ XWIKI_REST_BASE }}wikis/xwiki/spaces/XWiki/pages/{{ XWIKI_ADMIN_USER | urlencode }}/objects"
method: POST method: POST
user: "{{ XWIKI_SUPERADMIN_USERNAME }}" user: "{{ XWIKI_SUPERADMIN_USERNAME }}"
password: "{{ XWIKI_SUPERADMIN_PASSWORD }}" password: "{{ XWIKI_SUPERADMIN_PASSWORD }}"
force_basic_auth: true force_basic_auth: true
status_code: 201 status_code: [201, 200]
headers: headers:
Content-Type: "application/xml" Content-Type: "application/xml"
Accept: "application/xml"
body: | body: |
<user> <object xmlns="http://www.xwiki.org">
<firstName>{{ users.administrator.firstname | default('Admin') }}</firstName> <className>XWiki.XWikiUsers</className>
<lastName>{{ users.administrator.lastname | default('User') }}</lastName> <properties>
<email>{{ users.administrator.email }}</email> <property name="first_name">{{ users.administrator.firstname | default('Admin') }}</property>
<username>{{ XWIKI_ADMIN_USER }}</username> <property name="last_name">{{ users.administrator.lastname | default('User') }}</property>
<password>{{ XWIKI_ADMIN_PASS }}</password> <property name="email">{{ users.administrator.email }}</property>
</user> <property name="active">1</property>
when: _admin_exists.status in [404, 302] </properties>
</object>
when: _users_obj_list.status == 404 or ('<object' not in (_users_obj_list.content | default('')))
register: _user_obj_created
# 3) (Optional) Assign admin rights by adding the user to XWikiAdminGroup
- name: "XWIKI | Ensure user is in XWikiAdminGroup"
uri:
url: "{{ XWIKI_REST_BASE }}wikis/xwiki/spaces/XWiki/pages/XWikiAdminGroup/objects"
method: POST
user: "{{ XWIKI_SUPERADMIN_USERNAME }}"
password: "{{ XWIKI_SUPERADMIN_PASSWORD }}"
force_basic_auth: true
status_code: [201, 200]
headers:
Content-Type: "application/xml"
Accept: "application/xml"
body: |
<object xmlns="http://www.xwiki.org">
<className>XWiki.XWikiGroups</className>
<properties>
<property name="member">XWiki.{{ XWIKI_ADMIN_USER }}</property>
</properties>
</object>
when: XWIKI_LDAP_ENABLED | bool == false and XWIKI_OIDC_ENABLED | bool == false

View File

@@ -24,15 +24,32 @@
- name: "Install LDAP and/or OIDC extensions" - name: "Install LDAP and/or OIDC extensions"
uri: uri:
url: "{{ XWIKI_REST_EXTENSION_INSTALL }}" url: "{{ XWIKI_REST_EXTENSION_INSTALL }}?jobType=install&async=false"
method: PUT method: PUT
user: "{{ XWIKI_SUPERADMIN_USERNAME }}" user: "{{ XWIKI_SUPERADMIN_USERNAME }}"
password: "{{ XWIKI_SUPERADMIN_PASSWORD }}" password: "{{ XWIKI_SUPERADMIN_PASSWORD }}"
force_basic_auth: yes force_basic_auth: yes
headers: { Content-Type: "text/xml" } headers:
Content-Type: "text/xml"
Accept: "application/xml"
X-Requested-With: "XMLHttpRequest"
body: "{{ lookup('template', 'installjobrequest.xml.j2') }}" body: "{{ lookup('template', 'installjobrequest.xml.j2') }}"
status_code: 200 status_code: [200, 202]
when: when:
- (XWIKI_OIDC_ENABLED | bool and xwiki_oidc_ext.status == 404) or - (XWIKI_OIDC_ENABLED | bool and xwiki_oidc_ext.status == 404) or
(XWIKI_LDAP_ENABLED | bool and (xwiki_ldap_ext is not skipped) and xwiki_ldap_ext.status == 404) (XWIKI_LDAP_ENABLED | bool and (xwiki_ldap_ext is not skipped) and xwiki_ldap_ext.status == 404)
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}" no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
- name: "Verify OIDC extension is installed"
when: XWIKI_OIDC_ENABLED | bool
uri:
url: "{{ XWIKI_REST_XWIKI }}/extensions/{{ XWIKI_EXT_OIDC_ID | urlencode }}"
method: GET
user: "{{ XWIKI_SUPERADMIN_USERNAME }}"
password: "{{ XWIKI_SUPERADMIN_PASSWORD }}"
force_basic_auth: yes
status_code: 200
register: _oidc_ok
retries: 12
delay: 5
until: _oidc_ok is succeeded

View File

@@ -13,13 +13,16 @@
- name: "flush docker compose for '{{ application_id }}'" - name: "flush docker compose for '{{ application_id }}'"
meta: flush_handlers meta: flush_handlers
- name: "Wait until XWiki REST is ready" - name: "Wait until XWiki REST is ready (no DW redirect)"
uri: uri:
url: "{{ XWIKI_REST_BASE }}" url: "{{ XWIKI_REST_BASE }}"
status_code: [200, 401, 302] status_code: [200, 401]
return_content: no return_content: no
changed_when: false follow_redirects: none
register: xwiki_rest_up register: xwiki_rest_up
changed_when: false
retries: 60 retries: 60
delay: 5 delay: 5
until: xwiki_rest_up is succeeded until:
- xwiki_rest_up is succeeded
- (xwiki_rest_up.redirected is not defined) or (not xwiki_rest_up.redirected)

View File

@@ -9,6 +9,8 @@
ports: ports:
- "127.0.0.1:{{ XWIKI_HOST_PORT }}:{{ container_port }}" - "127.0.0.1:{{ XWIKI_HOST_PORT }}:{{ container_port }}"
volumes: volumes:
- "{{ XWIKI_HOST_CONF_PATH }}:/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.cfg"
- "{{ XWIKI_HOST_PROPERTIES_PATH }}:/usr/local/tomcat/webapps/ROOT/WEB-INF/xwiki.properties"
- "{{ XWIKI_HOST_CONF_PATH }}:/usr/local/xwiki/xwiki.cfg" - "{{ XWIKI_HOST_CONF_PATH }}:/usr/local/xwiki/xwiki.cfg"
- "{{ XWIKI_HOST_PROPERTIES_PATH }}:/usr/local/xwiki/xwiki.properties" - "{{ XWIKI_HOST_PROPERTIES_PATH }}:/usr/local/xwiki/xwiki.properties"
- 'data:/usr/local/xwiki' - 'data:/usr/local/xwiki'

View File

@@ -16,7 +16,19 @@ oidc.groups.mapping=XWiki.XWikiAdminGroup={{ XWIKI_OIDC_ADMIN_PROVIDER_GROUP }}
{% endif %} {% endif %}
############################################ ############################################
# Distribution Wizard # Distribution Wizard (bootstrap)
# Disable automatic start so REST is reachable during automation {% if xwiki_superadmin_enabled_switch | bool %}
distribution.automaticStartOnMainWiki=false # Start DW automatisch und ohne Interaktion
distribution.automaticStartOnWiki=false distribution.automaticStartOnMainWiki=true
distribution.automaticStartOnWiki=true
distribution.job.interactive=false
# Standard-Flavor für Main Wiki (XWiki Standard)
distribution.defaultUI=org.xwiki.platform:xwiki-platform-distribution-flavor-mainwiki
{% endif %}
# Keep data in the Docker volume
environment.permanentDirectory=/usr/local/xwiki/data
# Make sure Extension Manager can fetch artifacts
extension.repositories=maven:xwiki-public https://nexus.xwiki.org/nexus/content/groups/public/,\
maven:central https://repo1.maven.org/maven2/

View File

@@ -26,6 +26,7 @@ XWIKI_DATA_VOLUME: "{{ applications | get_app_conf(applicatio
# Feature toggles (must be set in config/main.yml -> features) # Feature toggles (must be set in config/main.yml -> features)
XWIKI_LDAP_ENABLED: "{{ applications | get_app_conf(application_id, 'features.ldap') }}" XWIKI_LDAP_ENABLED: "{{ applications | get_app_conf(application_id, 'features.ldap') }}"
XWIKI_OIDC_ENABLED: "{{ applications | get_app_conf(application_id, 'features.oidc') }}" XWIKI_OIDC_ENABLED: "{{ applications | get_app_conf(application_id, 'features.oidc') }}"
XWIKI_SSO_ENABLED: "{{ (XWIKI_OIDC_ENABLED | bool) or (XWIKI_LDAP_ENABLED | bool) }}"
# Admin credentials (must be provided via inventory/vault) # Admin credentials (must be provided via inventory/vault)
XWIKI_ADMIN_USER: "{{ users.administrator.username }}" XWIKI_ADMIN_USER: "{{ users.administrator.username }}"
@@ -37,9 +38,9 @@ XWIKI_SUPERADMIN_PASSWORD: "{{ applications | get_app_conf(applicatio
XWIKI_SUPERADMIN_USERNAME: "superadmin" XWIKI_SUPERADMIN_USERNAME: "superadmin"
# REST endpoint (local inside container) # REST endpoint (local inside container)
XWIKI_REST_BASE: "http://127.0.0.1:{{ XWIKI_HOST_PORT }}/xwiki/rest/" XWIKI_REST_BASE: "{{ ['http://127.0.0.1:'~ XWIKI_HOST_PORT, '/rest/'] | url_join }}"
XWIKI_REST_EXTENSION_INSTALL: "{{ XWIKI_REST_BASE }}jobs?jobType=install&async=false" XWIKI_REST_EXTENSION_INSTALL: "{{ [XWIKI_REST_BASE, 'jobs'] | url_join }}"
XWIKI_REST_XWIKI: "{{ XWIKI_REST_BASE }}wikis/xwiki" XWIKI_REST_XWIKI: "{{ [XWIKI_REST_BASE, 'wikis/xwiki'] | url_join }}"
# Extension IDs + Versions (pin versions explicitly) # Extension IDs + Versions (pin versions explicitly)
XWIKI_EXT_LDAP_ID: "org.xwiki.contrib.ldap:ldap-authenticator" XWIKI_EXT_LDAP_ID: "org.xwiki.contrib.ldap:ldap-authenticator"