0

I am running four docker container on my local machine:

ldap:
   container_name: openldap
   image: osixia/openldap:latest
  app:
    build:
    image: digitalocean.com/php
    container_name: app
  webserver:
    image: nginx:alpine
    container_name: webserver
  db:
    image: mysql:5.7.22
    container_name: db
  phpmyadmin:
    image: phpmyadmin/phpmyadmin

What I am now trying to do is to do a ldap request from my laravel controller to the openLdap. The program LDAPAdmin allows me to connect to the openLdap container with following settings:

    Host: localhost:389
    Base: dc=myworld,dc=com
    Username: cn=admin,dc=myworld,dc=com
    Password: PassWord
    Version: 3
    Simple Authentication

My Controller looks like this:

use Adldap\Adldap;

        $LDAPconfig = [
            'default' => [
                'hosts'            => ['openldap', 'localhost'],
                'base_dn'          => env('ADLDAP_BASEDN', "dc=myworld,dc=com"),
                'username'         => env('ADLDAP_ADMIN_USERNAME', "admin"),
                'password'         => env('ADLDAP_ADMIN_PASSWORD', "PassWord"),

                // Optional Configuration Options
                'schema' => \Adldap\Schemas\OpenLDAP::class,
                'account_prefix' => '',
                'account_suffix' => '',
                'port'             => 389,
                'follow_referrals' => false,
                'use_ssl'          => false,
                'use_tls'          => false,
                'version'          => 3,
                'timeout'          => 5,
            ]
        ];

        $ad = new Adldap();

        $config = new \Adldap\Configuration\DomainConfiguration($LDAPconfig['default']);

        $provider = new Adldap();
        $provider->addProvider($config);

        try {
            $provider->connect();
        } catch (\Exception $e) {
            dd($e);
        }

If I return just the $provider, it looks promising:

Adldap {#268 ▼
  #default: "default"
  #providers: array:1 [▼
    "default" => Provider {#276 ▼
      #connection: Ldap {#277 ▼
        #name: "default"
        #host: "ldap://openldap:389 ldap://localhost:389"
        #connection: ldap link resource @338
        #bound: false
        #useSSL: false
        #useTLS: false
      }
      #configuration: DomainConfiguration {#267 ▼
        #options: array:14 [▼
          "hosts" => array:2 [▶]
          "timeout" => 5
          "version" => 3
          "port" => 389
          "schema" => "Adldap\Schemas\OpenLDAP"
          "base_dn" => "dc=myworld,dc=com"
          "username" => "admin"
          "password" => "PassWord"
          "account_prefix" => ""
          "account_suffix" => ""
          "use_ssl" => false
          "use_tls" => false
          "follow_referrals" => false
          "custom_options" => []
        ]
      }
      #schema: OpenLDAP {#278}
      #guard: null
    }
  ]
  #listen: array:3 [▼
    0 => "Adldap\Auth\Events\*"
    1 => "Adldap\Query\Events\*"
    2 => "Adldap\Models\Events\*"
  ]
}

But when I try to access my web site I get the exception "Can't contact LDAP server" and I am not sure if it is even trying to connect to the container, or why the request is rejected.

BindException {#281 ▼
  #detailedError: DetailedError {#282 ▶}
  #message: "Can't contact LDAP server"
  #code: -1
  #file: "/var/www/vendor/adldap2/adldap2/src/Auth/Guard.php"
  #line: 109
  -previous: Exception {#280 ▶}
  trace: {▶}

Has someone maybe a hint?

Thanks

Stephan


Update

The line 109 return from the function bind in the Guard.php

public function bind($username = null, $password = null){
    $this->fireBindingEvent($username, $password);

    try {
        if (@$this->connection->bind($username, $password) === true) {
            $this->fireBoundEvent($username, $password);
        } else {
            throw new Exception($this->connection->getLastError(), $this->connection->errNo());
        }
    } catch (Throwable $e) {
        $this->fireFailedEvent($username, $password);

        throw (new BindException($e->getMessage(), $e->getCode(), $e))
            ->setDetailedError($this->connection->getDetailedError());
    }
}
Stephan
  • 335
  • 3
  • 12

1 Answers1

0

Ok, I solved the error after hours.

The problem is that I am doing two things at the same time I have no idea about. The first thing is laravel, the second one is docker. It turns out that my laravel code was working fine. The issue was related to my container’s network infrastructure. Because I was using two different docker-compose.yml files, the container couldn’t talk to each other, even if I said this as the network interface in both files:

networks:
  app-network:
    driver: bridge

However, for the moment I merged everything in one docker-compose.yml file until I figure out how to keep them in the same network running.

Thanks

Stephan


Update

My compose files, version 3.5:

Main file:

#Docker Networks
networks:
    app-network:
        driver: bridge
        name: app-network

Second file:

#Docker Networks
networks:
  app-networkk:
    external:
        name: app-network
Stephan
  • 335
  • 3
  • 12