2026-01-05 16:40:37 +01:00
|
|
|
---
|
2026-01-06 09:49:16 +01:00
|
|
|
# OIDC Application creation tasks via Zitadel API
|
|
|
|
|
# Fully automated OIDC app provisioning for Nextcloud and other services
|
2026-01-05 16:40:37 +01:00
|
|
|
|
2026-01-06 16:43:57 +01:00
|
|
|
- name: Create Zitadel scripts directory
|
|
|
|
|
file:
|
|
|
|
|
path: /opt/zitadel
|
|
|
|
|
state: directory
|
|
|
|
|
mode: '0755'
|
|
|
|
|
|
2026-01-06 09:49:16 +01:00
|
|
|
- name: Copy OIDC automation scripts to server
|
|
|
|
|
copy:
|
|
|
|
|
src: "{{ item }}"
|
|
|
|
|
dest: "/opt/zitadel/{{ item }}"
|
|
|
|
|
mode: '0755'
|
|
|
|
|
loop:
|
2026-01-06 16:43:57 +01:00
|
|
|
- zitadel_api.py
|
2026-01-06 09:49:16 +01:00
|
|
|
|
2026-01-06 16:43:57 +01:00
|
|
|
- name: Install Python libraries for OIDC automation
|
2026-01-06 09:49:16 +01:00
|
|
|
package:
|
2026-01-06 16:43:57 +01:00
|
|
|
name:
|
|
|
|
|
- python3-requests
|
|
|
|
|
- python3-jwt
|
2026-01-06 09:49:16 +01:00
|
|
|
state: present
|
|
|
|
|
become: yes
|
|
|
|
|
|
2026-01-06 16:43:57 +01:00
|
|
|
- name: Check if JWT key file exists
|
|
|
|
|
shell: docker exec zitadel ls /machinekey/api-automation.json
|
|
|
|
|
register: jwt_key_check
|
|
|
|
|
failed_when: false
|
2026-01-06 09:49:16 +01:00
|
|
|
changed_when: false
|
|
|
|
|
|
2026-01-06 16:43:57 +01:00
|
|
|
- name: Set JWT authentication available
|
2026-01-06 09:49:16 +01:00
|
|
|
set_fact:
|
2026-01-06 16:43:57 +01:00
|
|
|
jwt_auth_available: "{{ jwt_key_check.rc == 0 }}"
|
2026-01-06 09:49:16 +01:00
|
|
|
|
2026-01-06 16:43:57 +01:00
|
|
|
- name: Copy JWT key from container to host
|
|
|
|
|
shell: docker cp zitadel:/machinekey/api-automation.json /tmp/api-automation.json
|
|
|
|
|
when: jwt_auth_available
|
|
|
|
|
changed_when: false
|
|
|
|
|
|
|
|
|
|
- name: Create OIDC application for Nextcloud using JWT auth
|
2026-01-06 09:49:16 +01:00
|
|
|
shell: |
|
2026-01-06 16:43:57 +01:00
|
|
|
python3 /opt/zitadel/zitadel_api.py \
|
2026-01-06 09:49:16 +01:00
|
|
|
"{{ zitadel_domain }}" \
|
2026-01-06 16:43:57 +01:00
|
|
|
"/tmp/api-automation.json" \
|
2026-01-06 09:49:16 +01:00
|
|
|
"Nextcloud" \
|
|
|
|
|
"https://nextcloud.{{ client_domain }}/apps/user_oidc/code"
|
|
|
|
|
register: oidc_app_result
|
2026-01-06 16:43:57 +01:00
|
|
|
when: jwt_auth_available
|
2026-01-06 09:49:16 +01:00
|
|
|
changed_when: "'created' in oidc_app_result.stdout"
|
|
|
|
|
failed_when: oidc_app_result.rc != 0
|
|
|
|
|
|
2026-01-06 16:43:57 +01:00
|
|
|
- name: Clean up temporary JWT key file
|
|
|
|
|
file:
|
|
|
|
|
path: /tmp/api-automation.json
|
|
|
|
|
state: absent
|
|
|
|
|
when: jwt_auth_available
|
|
|
|
|
|
2026-01-06 09:49:16 +01:00
|
|
|
- name: Parse OIDC app creation result
|
|
|
|
|
set_fact:
|
|
|
|
|
oidc_app_data: "{{ oidc_app_result.stdout | from_json }}"
|
2026-01-06 16:43:57 +01:00
|
|
|
when: jwt_auth_available and oidc_app_result is defined
|
2026-01-06 09:49:16 +01:00
|
|
|
|
|
|
|
|
- name: Display OIDC app status
|
2026-01-05 16:40:37 +01:00
|
|
|
debug:
|
2026-01-06 09:49:16 +01:00
|
|
|
msg: |
|
2026-01-06 16:43:57 +01:00
|
|
|
✅ Nextcloud OIDC Application: {{ oidc_app_data.status }}
|
2026-01-06 09:49:16 +01:00
|
|
|
Client ID: {{ oidc_app_data.client_id | default('N/A') }}
|
|
|
|
|
Redirect URI: {{ oidc_app_data.redirect_uri | default('N/A') }}
|
2026-01-06 16:43:57 +01:00
|
|
|
when: jwt_auth_available and oidc_app_data is defined
|
2026-01-06 09:49:16 +01:00
|
|
|
|
|
|
|
|
- name: Save OIDC credentials for Nextcloud configuration
|
|
|
|
|
set_fact:
|
|
|
|
|
nextcloud_oidc_client_id: "{{ oidc_app_data.client_id }}"
|
|
|
|
|
nextcloud_oidc_client_secret: "{{ oidc_app_data.client_secret }}"
|
2026-01-06 16:43:57 +01:00
|
|
|
when: jwt_auth_available and oidc_app_data is defined and oidc_app_data.status == 'created'
|
2026-01-06 09:49:16 +01:00
|
|
|
no_log: true
|
|
|
|
|
|
|
|
|
|
- name: Configure OIDC provider in Nextcloud
|
|
|
|
|
shell: |
|
|
|
|
|
docker exec -u www-data nextcloud php occ user_oidc:provider:add \
|
|
|
|
|
--clientid="{{ nextcloud_oidc_client_id }}" \
|
|
|
|
|
--clientsecret="{{ nextcloud_oidc_client_secret }}" \
|
|
|
|
|
--discoveryuri="https://{{ zitadel_domain }}/.well-known/openid-configuration" \
|
|
|
|
|
"Zitadel" || true
|
2026-01-06 16:43:57 +01:00
|
|
|
when: jwt_auth_available and nextcloud_oidc_client_id is defined and nextcloud_oidc_client_secret is defined
|
2026-01-06 09:49:16 +01:00
|
|
|
register: oidc_config_result
|
|
|
|
|
changed_when: "'Provider Zitadel has been created' in oidc_config_result.stdout"
|
|
|
|
|
|
|
|
|
|
- name: Display OIDC configuration result
|
|
|
|
|
debug:
|
|
|
|
|
msg: |
|
2026-01-06 16:43:57 +01:00
|
|
|
✅ Nextcloud OIDC Provider Configuration: {{ 'Success' if oidc_config_result.changed else 'Already configured' }}
|
2026-01-06 09:49:16 +01:00
|
|
|
|
|
|
|
|
Users can now login to Nextcloud using Zitadel SSO!
|
|
|
|
|
Visit: https://nextcloud.{{ client_domain }}
|
2026-01-06 16:43:57 +01:00
|
|
|
when: jwt_auth_available and oidc_config_result is defined
|
|
|
|
|
|
|
|
|
|
- name: OIDC automation not available
|
|
|
|
|
debug:
|
|
|
|
|
msg: |
|
|
|
|
|
⚠️ OIDC automation not available - JWT key not found.
|
|
|
|
|
|
|
|
|
|
This should not happen if FirstInstance completed successfully.
|
|
|
|
|
Check Zitadel logs: docker logs zitadel
|
|
|
|
|
when: not jwt_auth_available
|