docker icon indicating copy to clipboard operation
docker copied to clipboard

Automatic LDAP setup using env variables

Open PorgJuice opened this issue 6 years ago • 4 comments

It would be great if we could point Nextcloud to an LDAP database using an environment variable and use that for our logins without having to go into the instance and configure it.

PorgJuice avatar Apr 04 '20 18:04 PorgJuice

It looks doable long as you add the variables in your compose file/secrets for all of the LDAP configuration variables but there are quite a few: ./occ ldap:show-config

Set the vars in your docker-compose:

environment:
  - NEXTCLOUD_LDAP_HOST=172.16.2.2
  - NEXTCLOUD_LDAP_AGENT_NAME="CN=Nextcloud.System,CN=SystemUsers,DC=yourdomain,DC=local"
- etc etc etc for all the different variables

Under docker-entrypoint.sh line 146 it would be smart to build some error checking but something like:

                if [ -n "${NEXTCLOUD_LDAP_HOST}" ]; then
                    echo "enabling ldap…"
                    run_as "php /var/www/html/occ app:enable user_ldap"

                    echo "setting up ldap…"
                    run_as "php /var/www/html/occ ldap:create-empty-config"
                    run_as "php /var/www/html/occ ldap:set-config ldapHost \"${NEXTCLOUD_LDAP_HOST}\""
                    run_as "php /var/www/html/occ ldap:set-config ldapAttributesForUserSearch \"${NEXTCLOUD_LDAP_AGENT_NAME}\""
                    #etc etc etc for all the different variables
                fi

would probably work.

occ ldap command reference

ohkeenan avatar Apr 05 '20 06:04 ohkeenan

Great news, thanks so much for that! I'm getting this when I try to run ./occ ldap:show-config. Am I doing something wrong?

Screen Shot 2020-04-05 at 4 30 58 PM

PorgJuice avatar Apr 05 '20 20:04 PorgJuice

ldap:show-config may need a named ldap config according to the documentation:

Try ./occ config:list to get the name of the config. (s01, s02, etc)

Then occ ldap:show-config s01 if it's s01 (probably is? depends on what you've done to the instance.

The only working LDAP config I have is on NC 17.0.5 and it's been upgraded from 15. I found LDAP doesn't work correctly in recent versions for whatever reason (which is actually why I was here searching open issues of LDAP and found you)

ohkeenan avatar Apr 05 '20 22:04 ohkeenan

As this is a fairly old issue and seems to have been addressed (and has been dormant for >3 years), I'm going to close this out. Feel free to follow-up at the Nextcloud Help Forum with questions or troubleshooting assistance. Or open a new Issue here if you have an actionable enhancement idea to discuss or bug to report related to the Nextcloud community Docker image itself.

joshtrichards avatar Oct 20 '23 21:10 joshtrichards