freman / caddy-reauth

Auth your Caddyserver requests against another server
MIT License
27 stars 15 forks source link

wrong number of arguments for ldap #34

Closed greenpau closed 4 years ago

greenpau commented 4 years ago

I am attempting LDAP configuration.

My config looks similar to this one.

reauth {
    path /
    ldap {"host":"ldap.jumpcloud.com","port":636,"ldaps":true,"tls":false,"timeout":"5s","bindUsername":"xxx","bindPassword":"xxx","base":"ou=Users,o=xxx,dc=jumpcloud,dc=com","filter":"(&(objectClass=inetOrgPerson)(uid=%s))"}
}

When validating the config, I get:

# caddy -validate -conf /etc/caddy/Caddyfile
2019/11/11 09:47:56 wrong number of arguments for ldap:   [{"host":"ldap.jumpcloud.com" ...
freman commented 4 years ago

Hi

Configuration doesn't support json, sorry.

Try

reauth {
    path /
    ldap url=ldaps:///ldap.jumpcloud.com:636,timeout=5s,username =xxx,password=xxx,base="ou=Users,o=xxx,dc=jumpcloud,dc=com",filter="(&(objectClass=inetOrgPerson)(uid=%s))"
}
greenpau commented 4 years ago

@freman , is the /// intentional or it is //? Any other way representing the config? it is a very long line :-)

greenpau commented 4 years ago

@freman , I have the following filter. The wrong number of arguments errors stems from that:

filter="(&(CN=My Web Managers,OU=Groups,DC=CONTOSO,DC=COM)(objectClass=user)(|(sAMAccountName=%s)(mail=%s)))"
swynter-ladbrokes commented 4 years ago

Nope, that extra slash was a side effect of phone editing.

Try using %[1]s instead of %s in both locations

greenpau commented 4 years ago

Try using %[1]s instead of %s in both locations

I did that.

This filter passed:

filter="(&(objectClass=user)(|(sAMAccountName=%[1]s)(mail=%[1]s)))"

This one too (3 conditions):

filter="(&(objectClass=person)(objectClass=user)(|(sAMAccountName=%[1]s)(mail=%[1]s)))"

However, this one did not:

filter="(&(CN=My Admins,OU=Groups,DC=CONTOSO,DC=COM)(objectClass=user)(|(sAMAccountName=%[1]s)(mail=%[1]s)))"

Then, I removed whitespaces from CN. It worked:

filter="(&(CN=MyAdmins,OU=Groups,DC=CONTOSO,DC=COM)(objectClass=user)(|(sAMAccountName=%[1]s)(mail=%[1]s)))"

It looks like there is an issue when passing CN and the CN has whitespaces.

greenpau commented 4 years ago

@freman , the test covers the use case without a whitespace.

Do you accept PRs for this?

greenpau commented 4 years ago

No need for PR. I guess I should try escaping \u0020.