diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..62382bf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +node_modules +test +.github +.vscode +nextcloud +production +config +certs +config.* +docker* +Docker* +.git* \ No newline at end of file diff --git a/.gitignore b/.gitignore index ef7f1e2..4ca36bb 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ config.yml production nextcloud certs +config diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c40ae75 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM node:18 +LABEL authors="Alex Roehm" +# update dependencies and install curl +RUN apt-get update && apt-get install -y \ + curl dumb-init\ + && rm -rf /var/lib/apt/lists/* + +# Create app directory +WORKDIR /ldap +RUN chown 1000:1000 . + +COPY --chown=node:node . . + +USER 1000:1000 + +# update each dependency in package.json to the latest version +ENV NODE_ENV=production +RUN yarn install --production + +EXPOSE 1389 +ENTRYPOINT [ "dumb-init", "node", "." ] diff --git a/config.example.yml b/config.example.yml index ca4bd35..54253b6 100644 --- a/config.example.yml +++ b/config.example.yml @@ -1,3 +1,9 @@ +server: + port: 1389 + ip: 0.0.0.0 + updateinterval: 600 // intervall in seconds + cert: certs/ldap.crt + key: certs/ldap.key sites: ccf: site: @@ -8,19 +14,20 @@ sites: ldap: o: Organisation Name dc: dc=myorg,dc=tld // domain components - admin: admin + admincn: admin password: secret2 - port: 1389 - cert: certs/ldap.crt - key: certs/ldap.key attributes: // fields to add to user - name: key1 default: defaultvalue1 replacements: // add value to user with id - - id: 156 + - id: id value: extra - name: key2 default: defaultvalue2 + adminGroup: + cn: "admin" // + members: // personid s of users to put in admin group + - id selectionGroupIds: // ChurchTools Group Ids - only members of these groups will be served by ldap - gid - gid diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ff77dd5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.1' + +services: + ccf-ctldap: + image: ccf-ctldap + ports: + - 1389:1389 + volumes: + - ./config:/ldap/config + - ./certs:/ldap/certs diff --git a/index.js b/index.js index 852aedc..8418d4e 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,8 @@ const log = require('./src/logging'); const nc = require('./src/nextcloud'); const fs = require('fs'); const { argv } = require('process'); +const pino = require('pino') +const pretty = require('pino-pretty') function write(name, data) { try { @@ -71,7 +73,7 @@ run = async () => { } else if (process.argv.includes('--testsnapshot')) { sanpshot(); } else { - log.logger.level = 'info' + log.logger = pino({ level: 'info', transport: { target: 'pino-pretty' } }) const config = main.getConfig(c.CONFIG_FILE) start = await main.start( config, diff --git a/package.json b/package.json index 04c63e7..bc247fa 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,8 @@ "ldapjs": "^2.3.1", "path": "^0.12.7", "pino": "^8.6.0", - "yamljs": "^0.3.0" + "yamljs": "^0.3.0", + "pino-pretty": "^9.1.0" + } } diff --git a/src/constants.js b/src/constants.js index 33ce203..de47920 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,4 +1,4 @@ -exports.CONFIG_FILE = "./production/config.yml" +exports.CONFIG_FILE = "/ldap/config/config.yml" exports.API_SLUG = "api" exports.WHOAMI_AP = "/whoami?only_allow_authenticated=true" exports.CSRF_AP = "/csrftoken" diff --git a/src/ldapcache.js b/src/ldapcache.js index 3668157..debd452 100644 --- a/src/ldapcache.js +++ b/src/ldapcache.js @@ -1,7 +1,6 @@ const c = require('./constants') const log = require('./logging') var ldapEsc = require('ldap-escape'); -const { use } = require('chai'); ldapcache = []