go-ldap / ldap

Basic LDAP v3 functionality for the GO programming language.
Other
2.19k stars 352 forks source link

Not possible to connect ldap #512

Closed raizdev closed 2 months ago

raizdev commented 2 months ago

I am trying to migrate my nodejs application to go lang.

I am able to connect in nodejs with the ldap-authentication library to the ldap server. But in go im getting the error: LDAP Result Code 200 "Network Error": dial tcp 10.8.24.10:636: connectex: An attempt was made to access a socket in a way forbidden by its access permissions.

I tried serveral things but couldnt figure out why this error occurs

any suggestions?

cpuschma commented 2 months ago

Can you show us the relevant code if possible? Thank you.

raizdev commented 2 months ago

Ofcourse!

This is the code in ldap where I am able to log into ldap

    const { authenticate } = require('ldap-authentication');

    let options = {
        ldapOpts: {
            url: 'ldaps://ldaps.wnl.local:636,
            tlsOptions: { rejectUnauthorized: false },
        },
        userDn: req.body.username + '@wnl.local',
        username: req.body.username,
        userPassword: req.body.password,
        userSearchBase: 'OU=Managed Users,OU=KK,DC=wnl,DC=local',
        usernameAttribute: 'name',
        attributes: ['thumbnailPhoto;binary', 'givenName', 'sn', 'cn', 'dn', 'title', 'mail', 'memberOf', 'msExchExtensionAttribute34' , 'msExchExtensionAttribute16']
    };

In golang im trying to authenticate with

    ldapURL := "ldaps://ldaps.wnl.local:636"
    l, err := ldap.DialURL(ldapURL, ldap.DialWithTLSConfig(&tls.Config{InsecureSkipVerify: true}))
    if err != nil {
            log.Fatal(err)
    }
    defer l.Close()
cpuschma commented 2 months ago

The code looks OK to me. Looking at your error, the error looks to be coming from the Go net Dialer. The error message "connectex: An attempt was made to access a socket in a way forbidden by its access permissions" typically indicates a problem with the network access permissions or configuration on the system where your Go application is running. Do you have a XDR solution, an antivirus or some sort of firewall enforcement running that could block your application from accessing the destination server? It's not unusual for example for Windows Defender to block Go's temporary compiled binaries when running go run, as they're unknown and constantly change signature and path.

raizdev commented 2 months ago

You're right! Windows is blocking my ass off at the moment. Even when I compile the program it gives the same error. Now I have it working via WSL. thanks for your thoughts!

t2y commented 2 months ago

@raizdev Use GitHub Discussions next time you have a question like this.

raizdev commented 2 months ago

@raizdev Use GitHub Discussions next time you have a question like this.

Im sorry, thanks for the headsup