From af6ad223fab38a7700aeafc198691dea0f9f072e Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Mon, 18 Nov 2024 17:22:31 +0100 Subject: [PATCH 1/7] feat: Add LDAP setup step to Nextcloud service initialization --- imageroot/systemd/user/nextcloud-app.service | 1 + 1 file changed, 1 insertion(+) diff --git a/imageroot/systemd/user/nextcloud-app.service b/imageroot/systemd/user/nextcloud-app.service index 114a820..d0e3252 100644 --- a/imageroot/systemd/user/nextcloud-app.service +++ b/imageroot/systemd/user/nextcloud-app.service @@ -13,6 +13,7 @@ ExecStartPre=/bin/rm -f %t/nextcloud-app.pid %t/nextcloud-app.ctr-id ExecStartPre=-runagent discover-smarthost ExecStartPost=runagent wait-startup ExecStartPost=runagent setup-smtp +ExecStartPost=runagent setup-ldap ExecStart=/usr/bin/podman run --conmon-pidfile %t/nextcloud-app.pid --cidfile %t/nextcloud-app.ctr-id --cgroups=no-conmon --pod-id-file %t/nextcloud.pod-id --replace -d --name nextcloud-app --env-file=%S/state/config.env --env-file=%S/state/smarthost.env -v nextcloud-app-data:/var/www/html -v %S/state/zzz_nethserver.conf:/usr/local/etc/php-fpm.d/zzz_nethserver.conf:z ${NEXTCLOUD_APP_IMAGE} ExecStop=/usr/bin/podman stop --ignore --cidfile %t/nextcloud-app.ctr-id -t 10 ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/nextcloud-app.ctr-id From b340340a13c193e9e7e872d016d34a6f62694e60 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Mon, 18 Nov 2024 17:22:25 +0100 Subject: [PATCH 2/7] feat: Remove deprecated LDAP configuration script --- imageroot/actions/configure-module/70ldap | 27 ----------------------- 1 file changed, 27 deletions(-) delete mode 100755 imageroot/actions/configure-module/70ldap diff --git a/imageroot/actions/configure-module/70ldap b/imageroot/actions/configure-module/70ldap deleted file mode 100755 index ac9ddaf..0000000 --- a/imageroot/actions/configure-module/70ldap +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash - -# -# Copyright (C) 2021 Nethesis S.r.l. -# http://www.nethesis.it - nethserver@nethesis.it -# -# This script is part of NethServer. -# -# NethServer is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, -# or any later version. -# -# NethServer is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with NethServer. If not, see COPYING. -# - -domain=$(cat config.json | jq -r '.domain // empty') - -if [ "x$domain" != "x" ]; then - setup-ldap "$domain" -fi From 26df31e624a01b88e2bc0f5d8ca9121d85affa75 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Mon, 18 Nov 2024 17:22:20 +0100 Subject: [PATCH 3/7] feat: Add user-domain-changed event handler for Nextcloud service management --- .../user-domain-changed /20configure_ldap | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 imageroot/events/user-domain-changed /20configure_ldap diff --git a/imageroot/events/user-domain-changed /20configure_ldap b/imageroot/events/user-domain-changed /20configure_ldap new file mode 100755 index 0000000..c6fc5e4 --- /dev/null +++ b/imageroot/events/user-domain-changed /20configure_ldap @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +# +# Copyright (C) 2024 Nethesis S.r.l. +# SPDX-License-Identifier: GPL-3.0-or-later +# + +import json +import sys +import agent +import os + +event = json.load(sys.stdin) + +if event.get('domain') != os.getenv('NEXTCLOUD_DOMAIN'): + exit(0) + +if 'node' in event and str(event['node']) != os.getenv('NODE_ID'): + exit(0) # ignore event if the source is not in our node + +agent.run_helper('systemctl', '--user', '-T', 'try-reload-or-restart', 'nextcloud.service').check_returncode() From 6b8a20c945a437091409c64131f3b1ea00353cdb Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Mon, 18 Nov 2024 17:22:00 +0100 Subject: [PATCH 4/7] feat: Load LDAP domain from config.json instead of command line argument --- imageroot/bin/setup-ldap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imageroot/bin/setup-ldap b/imageroot/bin/setup-ldap index 7b3a1b3..9d6722a 100755 --- a/imageroot/bin/setup-ldap +++ b/imageroot/bin/setup-ldap @@ -30,6 +30,7 @@ import sys import agent import subprocess from agent.ldapproxy import Ldapproxy +import json # Execute occ command # It returns the process exit code and output @@ -41,11 +42,10 @@ def occ(args): def set_ldap(k, v): return occ(["ldap:set-config", "s01", k, v]) -if len(sys.argv) < 2: - print("setup-ldap: no argument given", file=sys.stderr) - sys.exit(1) +with open('config.json', 'r') as cf: + config = json.loads(cf.read()) +cdomain = config.get("domain") -cdomain = sys.argv[1] commands = [] if not cdomain: From 09e2600bb9ae86630fa15480b73f1e3e72e53c11 Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Tue, 19 Nov 2024 12:52:00 +0100 Subject: [PATCH 5/7] fix: Correct key name in user-domain-changed event handler for node validation --- imageroot/events/user-domain-changed /20configure_ldap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imageroot/events/user-domain-changed /20configure_ldap b/imageroot/events/user-domain-changed /20configure_ldap index c6fc5e4..3391eda 100755 --- a/imageroot/events/user-domain-changed /20configure_ldap +++ b/imageroot/events/user-domain-changed /20configure_ldap @@ -15,7 +15,7 @@ event = json.load(sys.stdin) if event.get('domain') != os.getenv('NEXTCLOUD_DOMAIN'): exit(0) -if 'node' in event and str(event['node']) != os.getenv('NODE_ID'): +if 'node_id' in event and str(event['node_id']) != os.getenv('NODE_ID'): exit(0) # ignore event if the source is not in our node agent.run_helper('systemctl', '--user', '-T', 'try-reload-or-restart', 'nextcloud.service').check_returncode() From 6a29247cec5744c4b72231f053d4a1fea332b42a Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Thu, 21 Nov 2024 17:42:48 +0100 Subject: [PATCH 6/7] feat(event): Read NEXTCLOUD_DOMAIN from config.env in user-domain-changed event handler --- .../20configure_ldap | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) rename imageroot/events/{user-domain-changed => user-domain-changed}/20configure_ldap (75%) diff --git a/imageroot/events/user-domain-changed /20configure_ldap b/imageroot/events/user-domain-changed/20configure_ldap similarity index 75% rename from imageroot/events/user-domain-changed /20configure_ldap rename to imageroot/events/user-domain-changed/20configure_ldap index 3391eda..d12d73d 100755 --- a/imageroot/events/user-domain-changed /20configure_ldap +++ b/imageroot/events/user-domain-changed/20configure_ldap @@ -12,7 +12,10 @@ import os event = json.load(sys.stdin) -if event.get('domain') != os.getenv('NEXTCLOUD_DOMAIN'): +config = agent.read_envfile("config.env") +nextcloud_domain = config.get('NEXTCLOUD_DOMAIN', '') + +if event.get('domain') != nextcloud_domain: exit(0) if 'node_id' in event and str(event['node_id']) != os.getenv('NODE_ID'): From 1d222e23a2078232b3116b8ef392cff7f674ec4f Mon Sep 17 00:00:00 2001 From: Stephane de Labrusse Date: Fri, 22 Nov 2024 12:05:13 +0100 Subject: [PATCH 7/7] fix(event): Remove node ID validation from user-domain-changed event handler --- imageroot/events/user-domain-changed/20configure_ldap | 3 --- 1 file changed, 3 deletions(-) diff --git a/imageroot/events/user-domain-changed/20configure_ldap b/imageroot/events/user-domain-changed/20configure_ldap index d12d73d..3320f3d 100755 --- a/imageroot/events/user-domain-changed/20configure_ldap +++ b/imageroot/events/user-domain-changed/20configure_ldap @@ -18,7 +18,4 @@ nextcloud_domain = config.get('NEXTCLOUD_DOMAIN', '') if event.get('domain') != nextcloud_domain: exit(0) -if 'node_id' in event and str(event['node_id']) != os.getenv('NODE_ID'): - exit(0) # ignore event if the source is not in our node - agent.run_helper('systemctl', '--user', '-T', 'try-reload-or-restart', 'nextcloud.service').check_returncode()