Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better design of emqx-auth-ldap #46

Merged
merged 17 commits into from Dec 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -17,3 +17,6 @@ eunit.coverdata
logs/
test/ct.cover.spec
.DS_Store
_build/
rebar.lock
erlang.mk
69 changes: 54 additions & 15 deletions Makefile
Expand Up @@ -2,18 +2,16 @@ PROJECT = emqx_auth_ldap
PROJECT_DESCRIPTION = EMQ X Authentication/ACL with LDAP
PROJECT_VERSION = 3.0

LOCAL_DEPS = eldap

DEPS = ecpool clique emqx_passwd
dep_ecpool = git-emqx https://github.com/emqx/ecpool master
dep_clique = git-emqx https://github.com/emqx/clique develop
DEPS = ecpool emqx_passwd eldap2
dep_eldap2 = git-emqx https://github.com/emqx/eldap2 eldap2
dep_ecpool = git-emqx https://github.com/emqx/ecpool master
dep_emqx_passwd = git-emqx https://github.com/emqx/emqx-passwd emqx30

BUILD_DEPS = emqx cuttlefish
dep_emqx = git-emqx https://github.com/emqx/emqx emqx30
dep_cuttlefish = git-emqx https://github.com/emqx/cuttlefish
dep_emqx = git-emqx https://github.com/emqx/emqx emqx30
dep_cuttlefish = git-emqx https://github.com/emqx/cuttlefish v2.1.1

NO_AUTOPATCH = cuttlefish
NO_AUTOPATCH = cuttlefish eldap2

ERLC_OPTS += +debug_info

Expand All @@ -24,14 +22,55 @@ TEST_ERLC_OPTS += +debug_info

COVER = true

define dep_fetch_git-emqx
git clone -q --depth 1 -b $(call dep_commit,$(1)) -- $(call dep_repo,$(1)) $(DEPS_DIR)/$(call dep_name,$(1)) > /dev/null 2>&1; \
cd $(DEPS_DIR)/$(call dep_name,$(1));
endef
$(shell [ -f erlang.mk ] || curl -s -o erlang.mk https://raw.githubusercontent.com/emqx/erlmk/master/erlang.mk)

include erlang.mk

app:: rebar.config
CUTTLEFISH_SCRIPT = _build/default/lib/cuttlefish/cuttlefish

app.config: $(CUTTLEFISH_SCRIPT) etc/emqx_auth_ldap.conf
$(verbose) $(CUTTLEFISH_SCRIPT) -l info -e etc/ -c etc/emqx_auth_ldap.conf -i priv/emqx_auth_ldap.schema -d data

$(CUTTLEFISH_SCRIPT): rebar-deps
@if [ ! -f cuttlefish ]; then make -C _build/default/lib/cuttlefish; fi

distclean::
@rm -rf _build cover deps logs log data
@rm -f rebar.lock compile_commands.json cuttlefish

rebar-deps:
rebar3 get-deps

rebar-clean:
@rebar3 clean

rebar-compile: rebar-deps
rebar3 compile

rebar-ct: app.config
rebar3 ct

rebar-xref:
@rebar3 xref

## Below are for version consistency check during erlang.mk and rebar3 dual mode support
none=
space = $(none) $(none)
comma = ,
quote = \"
curly_l = "{"
curly_r = "}"
dep-versions = [$(foreach dep,$(DEPS) $(BUILD_DEPS) $(TEST_DEPS),$(curly_l)$(dep),$(quote)$(word 3,$(dep_$(dep)))$(quote)$(curly_r)$(comma))[]]

app.config::
./deps/cuttlefish/cuttlefish -l info -e etc/ -c etc/emqx_auth_ldap.conf -i priv/emqx_auth_ldap.schema -d data
.PHONY: dep-vsn-check
dep-vsn-check:
spring2maz marked this conversation as resolved.
Show resolved Hide resolved
$(verbose) erl -noshell -eval \
"MkVsns = lists:sort(lists:flatten($(dep-versions))), \
{ok, Conf} = file:consult('rebar.config'), \
{_, Deps} = lists:keyfind(deps, 1, Conf), \
F = fun({N, V}) when is_list(V) -> {N, V}; ({N, {git, _, {branch, V}}}) -> {N, V} end, \
RebarVsns = lists:sort(lists:map(F, Deps)), \
case {RebarVsns -- MkVsns, MkVsns -- RebarVsns} of \
{[], []} -> halt(0); \
{Rebar, Mk} -> erlang:error({deps_version_discrepancy, [{rebar, Rebar}, {mk, Mk}]}) \
end."
88 changes: 34 additions & 54 deletions README.md
Expand Up @@ -7,89 +7,69 @@ Build
-----

```
make && make tests
make
```

Configuration
-------------

File: etc/emqx_auth_ldap.conf
Load the Plugin
---------------

```
auth.ldap.servers = 127.0.0.1

auth.ldap.port = 389

auth.ldap.timeout = 30

auth.ldap.bind_dn = cn=root,dc=emqtt,dc=com

auth.ldap.bind_password = public

auth.ldap.ssl = false

## TODO: SSL Support

#auth.ldap.ssl.certfile = etc/certs/cert.pem

#auth.ldap.ssl.keyfile = etc/certs/key.pem

#auth.ldap.ssl.cacertfile = etc/certs/cacert.pem

#auth.ldap.ssl.verify = verify_peer

#auth.ldap.ssl.fail_if_no_peer_cert = true

## Variables: %u = username, %c = clientid
auth.ldap.auth_dn = cn=%u,ou=auth,dc=emqtt,dc=com

## Password hash: plain, md5, sha, sha256
auth.ldap.password_hash = sha256

## Temporarily unavailable
## auth.ldap.acl_dn = cn=%u,ou=acl,dc=emqtt,dc=com

# ./bin/emqx_ctl plugins load emqx_auth_ldap
```

Load the Plugin
Generate Password
---------------

```
./bin/emqx_ctl plugins load emqx_auth_ldap
slappasswd -h '{ssha}' -s public
```

Configuration Open LDAP
-----------------------

vim /etc/openldap/slapd.conf

```
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/ppolicy.schema
include /etc/openldap/schema/emqx.schema

database bdb
suffix "dc=emqtt,dc=com"
rootdn "cn=root,dc=emqtt,dc=com"
rootpw {SSHA}xvvgeQvLGZzHrCzFTfAOkL1gkHQrJX59
suffix "dc=emqx,dc=io"
rootdn "cn=root,dc=emqx,dc=io"
rootpw {SSHA}eoF7NhNrejVYYyGHqnt+MdKNBh4r1w3W

directory /etc/openldap/data
```

Import EMQX User Data
----------------------

Include Emqtt Schema
--------------------

vim /etc/openldap/slapd.conf
Use ldapadd
```
include emqtt.schema
# ldapadd -x -D "cn=root,dc=emqx,dc=io" -w public -f emqx.com.ldif
```

Create Emqtt User Data
----------------------
Use slapadd
```
# sudo slapadd -l schema/emqx.io.ldif -f slapd.conf
```

Launch slapd
```
# ldapadd -x -D "cn=root,dc=emqtt,dc=com" -w public -f emqtt.com.ldif
# sudo slapd -d 3
```

TODO
----
Test
-------
After configure slapd correctly and launch slapd successfully.
You could execute

Support SSL Options
``` bash
# make tests
```

License
-------
Expand Down
33 changes: 0 additions & 33 deletions emqtt.com.ldif

This file was deleted.

45 changes: 0 additions & 45 deletions emqtt.schema

This file was deleted.