From 3d307b8121d4ab52750aa37092348ab4e4b027eb Mon Sep 17 00:00:00 2001 From: fpotier Date: Wed, 29 May 2024 15:13:47 +0200 Subject: [PATCH] BE v3 LDAP config --- .../backend/services/v3/compose.base.yaml | 8 ++++- .../backend/services/v3/compose.ldap.yaml | 12 ++++++++ services/backend/services/v3/compose.yaml | 1 + services/backend/services/v3/config/init.sh | 7 +++++ .../backend/services/v3/config/mergeJson.js | 30 +++++++++++++++++++ .../services/v3/config/providers.ldap.json | 24 +++++++++++++++ 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 services/backend/services/v3/compose.ldap.yaml create mode 100755 services/backend/services/v3/config/init.sh create mode 100644 services/backend/services/v3/config/mergeJson.js create mode 100644 services/backend/services/v3/config/providers.ldap.json diff --git a/services/backend/services/v3/compose.base.yaml b/services/backend/services/v3/compose.base.yaml index e0bfb1ca..70074656 100644 --- a/services/backend/services/v3/compose.base.yaml +++ b/services/backend/services/v3/compose.base.yaml @@ -8,7 +8,13 @@ services: volumes: - ./config/config.local.js:/home/node/app/server/config.local.js - ./config/datasources.json:/home/node/app/server/datasources.json - - ./config/providers.json:/home/node/app/server/providers.json + - ./config/providers.json:/config/providers.base.json + - ./config/init.sh:/init.sh + - ./config/mergeJson.js:/config/mergeJson.js + command: + - sh + - -c + - /init.sh && node . healthcheck: test: wget --spider 'http://127.0.0.1:3000/' start_period: 5s diff --git a/services/backend/services/v3/compose.ldap.yaml b/services/backend/services/v3/compose.ldap.yaml new file mode 100644 index 00000000..284f448c --- /dev/null +++ b/services/backend/services/v3/compose.ldap.yaml @@ -0,0 +1,12 @@ +include: + - ../ldap/compose.yaml + +services: + backend: + depends_on: + ldap: + condition: service_healthy + volumes: + - ./config/providers.ldap.json:/config/providers.ldap.json + environment: + LDAP_ENABLED: true diff --git a/services/backend/services/v3/compose.yaml b/services/backend/services/v3/compose.yaml index 29bd32ce..28186ec5 100644 --- a/services/backend/services/v3/compose.yaml +++ b/services/backend/services/v3/compose.yaml @@ -2,3 +2,4 @@ include: - path: - ./compose.base.yaml - ./services/rabbitmq/.${JOBS_ENABLED:+./../}compose${JOBS_ENABLED:+.jobs}.yaml + - ../ldap/.${LDAP_ENABLED:+./v3/}compose${LDAP_ENABLED:+.ldap}.yaml diff --git a/services/backend/services/v3/config/init.sh b/services/backend/services/v3/config/init.sh new file mode 100755 index 00000000..18ed4b07 --- /dev/null +++ b/services/backend/services/v3/config/init.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +INCLUDE="base" +[ -n "$LDAP_ENABLED" ] && INCLUDE="${INCLUDE} ldap" + +# shellcheck disable=SC2046 +node /config/mergeJson.js $(for c in $INCLUDE; do echo "/config/providers.${c}.json"; done) /home/node/app/server/providers.json diff --git a/services/backend/services/v3/config/mergeJson.js b/services/backend/services/v3/config/mergeJson.js new file mode 100644 index 00000000..023a60df --- /dev/null +++ b/services/backend/services/v3/config/mergeJson.js @@ -0,0 +1,30 @@ +const fs = require("fs"); + +const readJsonFile = (filePath) => { + return JSON.parse(fs.readFileSync(filePath, "utf8")); +}; + +const writeJsonFile = (filePath, data) => { + fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf8"); +}; + +const mergeJsonFiles = (inputPaths, outputPath) => { + let mergedJson = {}; + + inputPaths.forEach(filePath => { + const jsonData = readJsonFile(filePath); + mergedJson = { ...mergedJson, ...jsonData }; + }); + + writeJsonFile(outputPath, mergedJson); + console.log(`Merged JSON has been written to ${outputPath}`); +}; + +const args = process.argv.slice(2); +if (args.length < 2) { + console.error("Please provide at least one input file and one output file."); + process.exit(1); +} +const outputPath = args.pop(); + +mergeJsonFiles(args, outputPath); diff --git a/services/backend/services/v3/config/providers.ldap.json b/services/backend/services/v3/config/providers.ldap.json new file mode 100644 index 00000000..a0a1a4c6 --- /dev/null +++ b/services/backend/services/v3/config/providers.ldap.json @@ -0,0 +1,24 @@ +{ + "ldap": { + "provider": "ldap", + "authScheme": "ldap", + "module": "passport-ldapauth", + "authPath": "/auth/msad", + "successRedirect": "/auth/account", + "failureRedirect": "/msad", + "session": true, + "json": true, + "failureFlash": true, + "profileAttributesFromLDAP": { + "displayName": "displayName", + "email": "mail" + }, + "server": { + "url": "ldap://ldap:389", + "bindDn": "cn=admin,dc=facility", + "bindCredentials": "admin", + "searchBase": "ou=users,dc=facility", + "searchFilter": "(uid={{username}})" + } + } +}