Giter Site home page Giter Site logo

jpmens / mosquitto-auth-plug Goto Github PK

View Code? Open in Web Editor NEW
821.0 79.0 493.0 565 KB

Authentication plugin for Mosquitto with multiple back-ends (MySQL, Redis, CDB, SQLite3)

License: Other

Makefile 2.81% C 78.06% PHP 0.55% Java 1.67% JavaScript 2.77% Python 3.89% Shell 0.63% Ruby 0.10% Roff 7.74% C# 1.51% Go 0.28%

mosquitto-auth-plug's Introduction

mosquitto-auth-plug

As per 2019-03-11 I am archiving this repository and closing all currently open issues and pull requests without prejudice. The repository will continue to exist and you are welcome to work on your own fork of it, as long as you observe the LICENSEs.

I have not used the mosquitto-auth-plug myself for years now, but my users expect, nay, demand, that I support and help them with it. We've received over 580 stars (thank you for that!), and yet some people can't even be bothered to read the documentation and then send me private e-mails or DMs on Twitter, etc. to complain and/or ask for help. I'm tired of having to work on understanding and fixing issues users are experiencing with the software. I'm also a bit tired of the lack of help I've received for this project.

The original README begins below this line.

mosquitto-auth-plug

This is a plugin to authenticate and authorize Mosquitto users from one or more of a variety of back-ends:

Introduction

This plugin can perform authentication (check username / password) and authorization (grant permission to subscribe and/or publish to specific topics via ACL). Currently, not all back-ends have the same capabilities (see the section on the back-end you're interested in).

Capability cdb files http jwt ldap mongo mysql postgres psk redis sqlite
authentication Y Y Y Y Y Y Y Y Y Y Y
superusers Y Y Y Y Y 3
acl checking 2 Y Y Y Y Y Y 3 1 2
static superusers Y Y Y Y Y Y Y 3 Y Y
  1. Topic wildcards (+/#) are not supported
  2. Currently not implemented; back-end returns TRUE
  3. Dependent on the database used by PSK

Multiple back-ends can be configured simultaneously for authentication, and they're attempted in the order you specify. Once a user has been authenticated, the same back-end is used to check authorization (ACLs). Superusers are checked for in all back-ends. The configuration option is called auth_opt_backends and it takes a comma-separated list of back-end names which are checked in exactly that order.

auth_opt_backends cdb,sqlite,mysql,redis,postgres,http,jwt,mongo

Note: anonymous MQTT connections are assigned a username configured in the plugin as auth_opt_anonusername and they are handled by a so-called fallback back-end which is the first configured back-end.

Passwords are obtained from the back-end as PBKDF2 strings (see Passwords below). If you store a clear-text password or any hash not generated the same way, the comparison and the authentication will fail.

The mysql and mongo back-ends support expansion of %c and %u as clientid and username respectively. This allows ACLs in the database to look like this:

+-----------+---------------------------------+----+
| username  | topic                           | rw |
+-----------+---------------------------------+----+
| bridge-01 | $SYS/broker/connection/%c/state |  2 |
+-----------+---------------------------------+----+

The plugin supports so-called superusers. These are usernames exempt from ACL checking. In other words, if a user is a superuser, that user can access any topic without needing ACLs.

A static superuser is one configured with the fnmatch(3) auth_opt_superusers option. Regular superusers are configured (i.e., enabled) from within the particular database back-end. Effectively, both are identical in that ACL checking is disabled if a user is a superuser.

Note that not all back-ends currently have 'superuser' queries implemented. This is a todo and the auth_opt_superusers option will probably disappear when it is finished.

Building the plugin

In order to compile the plugin you'll require:

  • a copy of the Mosquitto source code together with the libraries required for the back-end you want to use in the plugin, and
  • a recent version of OpenSSL (if the version with your OS, e.g., OS X, is too old, you may need to use one supplied by home brew or build your own).

Copy config.mk.in to config.mk and modify config.mk to suit your building environment. In particular, you have to configure which back-ends you want to provide as well as the path to the Mosquitto source and its library, and possibly the path to OpenSSL (OPENSSLDIR).

After a make you should have a shared object called auth-plug.so which you will reference in your mosquitto.conf.

Configuration

The plugin is configured in Mosquitto's configuration file (typically mosquitto.conf), and it is loaded into Mosquitto auth with the auth_plugin option.

auth_plugin /path/to/auth-plug.so

Options therein with a leading auth_opt_ are handed to the plugin. The following "global" auth_opt_* plugin options exist:

Option default Mandatory Meaning
backends Y comma-separated list of back-ends to load
superusers fnmatch(3) case-sensitive string
log_quiet false don't log DEBUG messages
cacheseconds Deprecated. Alias for acl_cacheseconds
acl_cacheseconds 300 number of seconds to cache ACL lookups. 0 disables
auth_cacheseconds 0 number of seconds to cache AUTH lookups. 0 disables
acl_cachejitter 0 maximum number of seconds to add/remove to ACL lookups cache TTL. 0 disables
auth_cachejitter 0 maximum number of seconds to add/remove to AUTH lookups cache TTL. 0 disables

Individual back-ends each have various additional options described in the sections below.

There are two caches, one for ACL and another for authentication. By default only the ACL cache is enabled.

After a backend responds (postitively or negatively) to an ACL or AUTH lookup, the result will be kept in cache for the configured TTL. The same ACL lookup will be served from the cache as long as the TTL is valid. The configured TTL is the auth_cacheseconds/acl_cacheseconds combined with a random value between -auth_/acl_cachejitter and +auth_/acl_cachejitter. For example, with an acl_cacheseconds of 300 and acl_cachejitter of 10, ACL lookup TTLs are distributed between 290 and 310 seconds.

Set auth/acl_cachejitter to 0 disable any randomization of cache TTL. Setting auth/acl_cacheseconds to 0 disables caching entirely. Caching is useful when your backend lookup is expensive. Remember that ACL lookup will be performed for each message which is sent/received on a topic. Jitter is useful to reduce lookup storms that could occur every auth/acl_cacheseconds if lots of clients connect at the same time (for example, after a server restart, all your clients may reconnect immediately and each cause ACL lookups every acl_cacheseconds).

MySQL auth

The mysql back-end is currently the most feature-complete: it supports obtaining passwords, checking for superusers, and verifying ACLs by configuring up to three distinct SQL queries used to obtain those results.

You configure the SQL queries in order to adapt to whichever schema you currently have.

The following auth_opt_ options are supported by the mysql back-end:

Option default Mandatory Meaning
host localhost hostname/address
port 3306 TCP port
user username
pass password
dbname Y database name
userquery Y SQL for users
superquery SQL for superusers
aclquery SQL for ACLs
mysql_opt_reconnect true enable MYSQL_OPT_RECONNECT option
mysql_auto_connect true enable auto_connect function
anonusername anonymous username to use for anonymous connections
ssl_enabled false enable SSL
ssl_key path name of client private key file
ssl_cert path name of client public key certificate file
ssl_ca path name of Certificate Authority(CA) certificate file
ssl_capath path name of directory that contains trusted CA certifcate files
ssl_cipher permitted ciphers for SSL encryption

The SQL query for looking up a user's password hash is mandatory. The query MUST return a single row only (any other number of rows is considered to be "user not found"), and it MUST return a single column with only the PBKDF2 password hash. Two '%s' in the auth_opt_userquery string are replaced by the username attempting to access the broker and the clientid, in that order. If the clientid is not to be used in the SQL, insert just a single '%s':

SELECT pw FROM users WHERE username = '%s' LIMIT 1

The SQL query for checking whether a user is a superuser - and thus circumventing ACL checks - is optional. If it is specified, the query MUST return a single row with a single value: 0 is false and 1 is true. We recommend using a SELECT IFNULL(COUNT(*),0) FROM ... for this query as it satisfies both conditions. A single '%s' in the auth_opt_superquery string is replaced by the username attempting to access the broker. The following example uses the same users table, but it could just as well reference a distinct table or view.

SELECT IFNULL(COUNT(*), 0) FROM users WHERE username = '%s' AND super = 1

The SQL query for checking ACLs is optional, but if it is specified, the mysql back-end can try to limit access to particular topics or topic branches depending on the value of a database table. The query MAY return zero or more rows for a particular user, each containing EXACTLY one column containing a topic (wildcards are supported). A single '%s' in the query string is replaced by the username attempting to access the broker, and a single '%d' is replaced with an integer, 1 signifying a read-only access attempt (SUB) or 2 signifying a read-write access attempt (PUB).

In the following example, the table has an INT(1) column rw containing 1 for readonly topics, and 2 for read-write topics:

SELECT topic FROM acls WHERE (username = '%s') AND (rw >= %d)

Sample Mosquitto configuration (e.g., mosquitto.conf) for the mysql back-end:

auth_plugin /home/jpm/mosquitto-auth-plug/auth-plug.so
auth_opt_host localhost
auth_opt_port 3306
auth_opt_dbname test
auth_opt_user jjj
auth_opt_pass supersecret
auth_opt_userquery SELECT pw FROM users WHERE username = '%s'
# auth_opt_userquery SELECT pwhash FROM user WHERE username = '%s' AND clientid = '%s'
auth_opt_superquery SELECT COUNT(*) FROM users WHERE username = '%s' AND super = 1
auth_opt_aclquery SELECT topic FROM acls WHERE (username = '%s') AND (rw >= %d)
auth_opt_anonusername AnonymouS

Assuming the following database tables:

mysql> SELECT * FROM users;
+----+----------+---------------------------------------------------------------------+-------+
| id | username | pw                                                                  | super |
+----+----------+---------------------------------------------------------------------+-------+
|  1 | jjolie   | PBKDF2$sha256$901$x8mf3JIFTUFU9C23$Mid2xcgTrKBfBdye6W/4hE3GKeksu00+ |     0 |
|  2 | a        | PBKDF2$sha256$901$XPkOwNbd05p5XsUn$1uPtR6hMKBedWE44nqdVg+2NPKvyGst8 |     0 |
|  3 | su1      | PBKDF2$sha256$901$chEZ4HcSmKtlV0kf$yRh2N62uq6cHoAB6FIrxIN2iihYqNIJp |     1 |
+----+----------+---------------------------------------------------------------------+-------+

mysql> SELECT * FROM acls;
+----+----------+-------------------+----+
| id | username | topic             | rw |
+----+----------+-------------------+----+
|  1 | jjolie   | loc/jjolie        |  1 |
|  2 | jjolie   | $SYS/something    |  1 |
|  3 | a        | loc/test/#        |  1 |
|  4 | a        | $SYS/broker/log/+ |  1 |
|  5 | su1      | mega/secret       |  1 |
|  6 | nop      | mega/secret       |  1 |
+----+----------+-------------------+----+

the above SQL queries would enable the following combinations (the * at the beginning of the line indicates a superuser)

  jjolie     PBKDF2$sha256$901$x8mf3JIFTUFU9C23$Mid2xcgTrKBfBdye6W/4hE3GKeksu00+
	loc/a                                    DENY
	loc/jjolie                               PERMIT
	mega/secret                              DENY
	loc/test                                 DENY
	$SYS/broker/log/N                        DENY
  nop        <nil>
	loc/a                                    DENY
	loc/jjolie                               DENY
	mega/secret                              PERMIT
	loc/test                                 DENY
	$SYS/broker/log/N                        DENY
  a          PBKDF2$sha256$901$XPkOwNbd05p5XsUn$1uPtR6hMKBedWE44nqdVg+2NPKvyGst8
	loc/a                                    DENY
	loc/jjolie                               DENY
	mega/secret                              DENY
	loc/test                                 PERMIT
	$SYS/broker/log/N                        PERMIT
* su1        PBKDF2$sha256$901$chEZ4HcSmKtlV0kf$yRh2N62uq6cHoAB6FIrxIN2iihYqNIJp
	loc/a                                    PERMIT
	loc/jjolie                               PERMIT
	mega/secret                              PERMIT
	loc/test                                 PERMIT
	$SYS/broker/log/N                        PERMIT

The mysql back-end will re-connect to the MySQL server when the connection has been lost. If you wish, you can disable this by configuring:

auth_opt_mysql_opt_reconnect false
auth_opt_mysql_auto_connect false

LDAP auth

The LDAP plugin currently does authentication only; authenticated users are allowed to publish/subscribe at will.

The user that connects to the broker is searched for in the LDAP directory indicated via the ldap_uri configuration parameter. This LDAP search MUST return exactly one entry. The user's password is then used with the DN of the that entry to bind to the directory. If that LDAP bind succeeds, the user is authenticated. In all other cases, authentication fails.

Option default Mandatory Meaning
binddn Y the DN of an object which may search users
bindpw Y its password
ldap_uri Y an LDAP uri with filter
ldap_acl_deny false return DENY instead of ALLOW to ACL checks

Example configuration:

auth_plugin /path/to/auth-plug.so
auth_opt_backends ldap
auth_opt_binddn cn=manager,dc=mens,dc=de
auth_opt_bindpw s3crit
auth_opt_ldap_uri ldap://127.0.0.1/ou=Users,dc=mens,dc=de?cn?sub?(&(objectclass=inetOrgPerson)(uid=@))
auth_opt_ldap_acl_deny false

With the ldap_acl_deny we return DENY instead of ALLOW for every ACL check. This makes it possible to chain other backends with ldap backend, and use LDAP for authentification and, e.g., MySQL for ACL checking.

CDB auth

Option default Mandatory Meaning
cdbname Y path to .cdb

SQLITE auth

Option default Mandatory Meaning
dbpath Y path to database
sqliteuserquery Y SQL for users

Example:

auth_opt_sqliteuserquery SELECT pw FROM users WHERE username = ?

Redis auth

auth_opt_redis_userquery GET %s
auth_opt_redis_aclquery GET %s-%s

In auth_opt_redis_userquery the %s parameter is the username, whereas in auth_opt_redis_aclquery, the first %s is the username and the second is the topic. When using ACLs, topic must be an exact match - wildcards are not supported.

If no options are provided, then the plugin will default to not using an ACL and using the above userquery.

Option default Mandatory Meaning
redis_host localhost hostname / IP address
redis_port 6379 TCP port number

HTTP auth

The http back-end is for auth by custom HTTP API.

The following auth_opt_ options are supported by the http back-end:

Option default Mandatory Meaning
http_ip Y IP address, will skip DNS lookup
http_port 80 TCP port number
http_hostname hostname for HTTP header
http_getuser_uri Y URI for checking username/password
http_superuser_uri Y URI for checking superuser
http_aclcheck_uri Y URI for checking acl
http_with_tls false Use TLS on connect
http_basic_auth_key Basic Authentication Key
http_retry_count 3 Number of retries done if backend is unavailable

If the configured URLs return an HTTP status code == 2xx, the authentication / authorization succeeds. If the status code == 4xx, authentication / authorization fails. For a status code == 5xx or server Unreachable, the HTTP request will be retried up to http_retry_count. If all tries fail and if no other backend succeeded, then an error is returned and the client is disconnected.

URI-Param username password clientid topic acc
http_getuser_uri Y Y N N N
http_superuser_uri Y N N N N
http_aclcheck_uri Y N Y Y Y

Mosquitto configuration for the http back-end:

auth_opt_backends http
auth_opt_http_ip 127.0.0.1
auth_opt_http_port 8089
#auth_opt_http_hostname example.org
auth_opt_http_getuser_uri /auth
auth_opt_http_superuser_uri /superuser
auth_opt_http_aclcheck_uri /acl

A very simple example service using Python and bottle can be found in examples/http-auth-be.py.

The http plugin can utilize environment variables which are exported before it (i.e., Mosquitto) is started by adding configuration settings like

auth_opt_<interface>_<method>_params <key>=<evn_name>[,<key>=<evn_name>]*

For example, set the following:

export DOMAIN=example.com
export PORT=8080

and add the following settings to mosquitto.conf:

auth_opt_http_getuser_params domain=DOMAIN,port=PORT
auth_opt_http_superuser_params domain=DOMAIN,port=PORT
auth_opt_http_aclcheck_params domain=DOMAIN,port=PORT

JWT auth

The jwt back-end is for auth by JWT-webtokens. The JWT and HTTP configurations are identical, so please read the http-section above.

The username field is interpreted as the token-field and passed to the http-server in an Authorization-header.

Authorization: Bearer %token

Note: Some clients require the password field to be populated. This field is ignored by the JWT-backend, so feel free to input some gibberish.

PostgreSQL auth

The postgres back-end, like mysql, is currently the most feature-complete: it supports distinct SQL queries for obtaining passwords, checking for superusers, and verifying ACLs, each configurable to suit your schema.

The following auth_opt_ options are supported by the postgres back-end:

Option default Mandatory Meaning
host localhost hostname/address
port 5432 TCP port
user username
pass password
dbname Y database name
userquery Y SQL for users
superquery SQL for superusers
aclquery SQL for ACLs
sslcert SSL/TLS Client Cert.
sslkey SSL/TLS Client Cert. Key

The SQL query for looking up a user's password hash is mandatory. The query must return a single row only (any other number of rows is considered to be "user not found"), and it must return a single column only with the PBKDF2 password hash. A single $1 in the query string is replaced by the username attempting to access the broker.

SELECT pass FROM account WHERE username = $1 limit 1

The SQL query for checking whether a user is a superuser - and thus circumventing ACL checks - is optional. If it is specified, the query must return a single row with a single value: 0 is false and 1 is true. We recommend using a SELECT COALESCE(COUNT(*),0) FROM ... for this query as it satisfies both conditions. A single $1 in the auth_opt_superquery string is replaced by the username attempting to access the broker. The following example uses the same account table, but it could just as well reference a distinct table or view.

SELECT COALESCE(COUNT(*),0) FROM account WHERE username = $1 AND super = 1

The SQL query for checking ACLs is optional, but if it is specified, the postgres back-end can try to limit access to particular topics or topic branches depending on the value of a database table. The query MAY return zero or more rows for a particular user, each containing EXACTLY one column containing a topic (wildcards are supported). A single $1 in the query string is replaced by the username attempting to access the broker, and a single $2 is replaced with an integer, 1 signifying a read-only access attempt (SUB) or 2 signifying a read-write access attempt (PUB).

In the following example, the table has a column rw containing 1 for readonly topics, 2 for writeonly topics and 3 for readwrite topics:

SELECT topic FROM acl WHERE (username = $1) AND rw >= $2

Sample Mosquitto configuration for the postgres back-end:

auth_plugin /home/jpm/mosquitto-auth-plug/auth-plug.so
auth_opt_host localhost
auth_opt_port 5432
auth_opt_dbname test
auth_opt_user jjj
auth_opt_pass supersecret
auth_opt_userquery SELECT pw FROM account WHERE username = $1 limit 1
auth_opt_superquery SELECT COALESCE(COUNT(*),0) FROM account WHERE username = $1 AND mosquitto_super = 1
auth_opt_aclquery SELECT topic FROM acls WHERE (username = $1) AND (rw & $2) > 0
auth_opt_sslcert /etc/postgresql/ssl/client.crt
auth_opt_sslkey /etc/postgresql/ssl/client.key

Assuming the following database tables:

=> SELECT * FROM account;
+----+----------+---------------------------------------------------------------------+-------+
| id | username | pw                                                                  | super |
+----+----------+---------------------------------------------------------------------+-------+
|  1 | jjolie   | PBKDF2$sha256$901$x8mf3JIFTUFU9C23$Mid2xcgTrKBfBdye6W/4hE3GKeksu00+ |     0 |
|  2 | a        | PBKDF2$sha256$901$XPkOwNbd05p5XsUn$1uPtR6hMKBedWE44nqdVg+2NPKvyGst8 |     0 |
|  3 | su1      | PBKDF2$sha256$901$chEZ4HcSmKtlV0kf$yRh2N62uq6cHoAB6FIrxIN2iihYqNIJp |     1 |
+----+----------+---------------------------------------------------------------------+-------+

=> SELECT * FROM acls;
+----+----------+-------------------+----+
| id | username | topic             | rw |
+----+----------+-------------------+----+
|  1 | jjolie   | loc/jjolie        |  1 |
|  2 | jjolie   | $SYS/something    |  1 |
|  3 | a        | loc/test/#        |  1 |
|  4 | a        | $SYS/broker/log/+ |  1 |
|  5 | su1      | mega/secret       |  1 |
|  6 | nop      | mega/secret       |  1 |
+----+----------+-------------------+----+

the above SQL queries would enable the following combinations (the * at the beginning of the line indicates a superuser)

  jjolie     PBKDF2$sha256$901$x8mf3JIFTUFU9C23$Mid2xcgTrKBfBdye6W/4hE3GKeksu00+
  loc/a                                    DENY
  loc/jjolie                               PERMIT
  mega/secret                              DENY
  loc/test                                 DENY
  $SYS/broker/log/N                        DENY
  nop        <nil>
  loc/a                                    DENY
  loc/jjolie                               DENY
  mega/secret                              PERMIT
  loc/test                                 DENY
  $SYS/broker/log/N                        DENY
  a          PBKDF2$sha256$901$XPkOwNbd05p5XsUn$1uPtR6hMKBedWE44nqdVg+2NPKvyGst8
  loc/a                                    DENY
  loc/jjolie                               DENY
  mega/secret                              DENY
  loc/test                                 PERMIT
  $SYS/broker/log/N                        PERMIT
* su1        PBKDF2$sha256$901$chEZ4HcSmKtlV0kf$yRh2N62uq6cHoAB6FIrxIN2iihYqNIJp
  loc/a                                    PERMIT
  loc/jjolie                               PERMIT
  mega/secret                              PERMIT
  loc/test                                 PERMIT
  $SYS/broker/log/N                        PERMIT

Note that the above sample auth_opt_aclquery is sensitive to new permission values used in Mosquitto 1.5.

You can either adapt to the updated binary-style permissions (2 for write, 5 for read+subscribe, 7 for read/write), modify your query to work around them, or modify the constants in the Mosquitto source.

MongoDB auth

The mongo back-end works with superuser and ACL checks. Additional build dependencies are https://github.com/mongodb/mongo-c-driver >=1.4.0 and https://github.com/mongodb/libbson >=1.4.0.

You should set up a users collection (required) and a topic lists collection (optional) with the following format:

Users collection

Each user document must have a username, a hashed password, and at least one of:

  • A superuser prop, allowing full access to all topics
  • An embedded array or sub-document to use as an ACL (see 'ACL format')
  • A foreign key pointing to another document containing an ACL (see 'ACL format')

You may use any combination of these options; authorisation will be granted if any check passes.

The user document has the following format (note that the property names are configurable variables, see 'Configuration').

{
    [user_username_prop]: string, // Username as given in the MQTT connect request
    [user_password_prop]: string, // A PBKDF2 hash, see 'Passwords' section
    [user_topiclist_fk_prop]: int | oid | string, // reference to a document in collection_topics)
    [user_topics_prop]: string[] | { [topic: string]: "r"|"w"|"rw" }, // see 'ACL format'
    [user_superuser_prop]: int | boolean // optional, superuser if truthy
}

As an example using default options, a user document with an embedded ACL might look like:

{
    "username": "user1",
    "password": "PBKDF2$sha256$901$8ebTR72Pcmjl3cYq$SCVHHfqn9t6Ev9sE6RMTeF3pawvtGqTu",
    "superuser": false,
    "topics": {
        "public/#": "r",
	"client/user1/#": "rw"
    }
}

Topic lists collection (optional)

If the user document references a separate topics document, that document should exist and must have the format:

{
    [topiclist_key_prop]: int | oid | string, // unique id, as referenced by users[user_topiclist_fk_prop],
    [topiclist_topics_prop]: string[] | { [topic: string]: "r"|"w"|"rw" } // see 'ACL format'
}

This strategy will be especially suitable if you have a complex ACL shared between many users.

ACL format

Topics may be given as either an array of topic strings, eg ["topic1/#", "topic2/+"], in which case all topics will be read-write, or as a sub-document mapping topic names to the strings "r", "w", "rw", eg { "article/#":"r", "article/+/comments":"rw", "ballotbox":"w" }.

Configuration

The following auth_opt_mongo_ options are supported by the mongo back-end:

Option default Meaning
uri mongodb://localhost:27107 MongoDB connection string (database part is ignored)
database mqGate Name of the database containing users (and topiclists)
user_coll users Collection for user documents
topiclist_coll topics Collection for topiclist documents (optional if embedded topics are used)
user_username_prop username Username property name in the user document
user_password_prop password Password property name in the user document
user_superuser_prop superuser Superuser property name in the user document
user_topics_prop topics Name of a property on the user document containing an embedded topic list
user_topiclist_fk_prop topics Property used as a foreign key to reference a topiclist document
topiclist_key_prop _id Unique key in the topiclist document pointed to by user_topiclist_fk_prop
topiclist_topics_prop topics Property containing topics within the topiclist document

Mosquitto configuration for the mongo back-end:

auth_plugin /home/jpm/mosquitto-auth-plug/auth-plug.so
auth_opt_mongo_uri mongodb://localhost:27017

Files auth

The files backend attempts to re-implement the files behavior in vanilla Mosquitto, however the user's password file contains PBKDF2 passwords instead of passwords hashed with the mosquitto-passwd program; you would use our np utility or similar to create the PBKDF2 hashes.

The configuration directives for the Files backend are as follows:

auth_opt_backends files
auth_opt_password_file file.pw
auth_opt_acl_file file.acl

with examples of these files being:

password_file

# comment
jpm:PBKDF2$sha256$901$UGfDz79cAaydRsEF$XvYwauPeviFd1NfbGL+dxcn1K7BVfMeW
jane:PBKDF2$sha256$901$wvvH0fe7Ftszt8nR$NZV6XWWg01dCRiPOheVNsgMJDX1mzd2v

acl_file

user jane
topic read #

user jpm
topic dd

The syntax for the ACL file is that as described in mosquitto.conf(5).

PSK auth

If Mosquitto has been built with PSK support, and auth-plug has been built with BE_PSK defined, it supports authenticating PSK connections over TLS, as long as Mosquitto is appropriately configured.

The way this works is that the psk back-end actually uses one of auth-plug's other databases (mysql, sqlite, cdb, etc.) to obtain the pre-shared key from the "users" query, and it uses the same database's back-end for performing authorization (aka ACL checks).

Consider the following mosquitto.conf snippet:

...
auth_opt_psk_database mysql
...
listener 8885
psk_hint hint1
tls_version tlsv1
use_identity_as_username true

TLS PSK is available on port 8885 and is activated with, say,

mosquitto_pub -h localhost -p 8885 -t x -m hi --psk-identity ps2 --psk 020202

The use_identity_as_username option has auth-plug see the name ps2 as the username, and this is given to the database back-end (here: mysql) to look up the password as defined for the mysql back-end. auth-plug uses its getuser() query to read the clear-text (not PKBDF2) hex key string which it returns to Mosquitto for authentication. If authentication passes, the connection is established.

For authorization, auth_plug uses the identity as the username and the topic to perform ACL-checking as described earlier.

The following log-snippet serves as an illustration:

New connection from ::1 on port 8885.
|-- psk_key_get(hint1, ps1) from [mysql] finds PSK: 1
New client connected from ::1 as mosqpub/90759-tiggr.ww. (c1, k60).
Sending CONNACK to mosqpub/90759-tiggr.ww. (0)
|-- user ps1 was authenticated in back-end 0 (psk)
|--   mysql: topic_matches(x, x) == 1
|-- aclcheck(ps1, x, 2) AUTHORIZED=1 by psk
Received PUBLISH from mosqpub/90759-tiggr.ww. (d0, q0, r0, m0, 'x', ... (2 bytes))
Received DISCONNECT from mosqpub/90759-tiggr.ww.

In the case of this MySQL example, we added the clear text of the PSK key to the database:

mysql> INSERT INTO user (username, pwhash, superuser) VALUES ('mylistener', 'F0BEEF', 0);

Passwords

A user's password is stored as a PBKDF2 hash in the back-end. An example "password" is a string with five pieces in it, delimited by $, inspired by this.

PBKDF2$sha256$901$8ebTR72Pcmjl3cYq$SCVHHfqn9t6Ev9sE6RMTeF3pawvtGqTu
--^--- --^--- -^- ------^--------- -------------^------------------
  |      |     |        |                       |
  |      |     |        |                       +-- : hashed password
  |      |     |        +-------------------------- : salt
  |      |     +----------------------------------- : iterations
  |      +----------------------------------------- : hash function
  +------------------------------------------------ : marker

Note that the salt by default will be taken as-is (thus it will not be base64 decoded before the validation). In case your own implementation uses the raw bytes when hashing the password and base64 is only used for display purpose, compile this project with the -DRAW_SALT flag (you could add this in the config.mk file to CFG_CFLAGS).

Creating a user

A trivial utility to generate hashes is included as np. Copy and paste the whole string generated into the respective back-end.

$ np
Enter password:
Re-enter same password:
PBKDF2$sha256$901$Qh18ysY4wstXoHhk$g8d2aDzbz3rYztvJiO3dsV698jzECxSg

For example, in Redis:

$ redis-cli
> SET n2 PBKDF2$sha256$901$Qh18ysY4wstXoHhk$g8d2aDzbz3rYztvJiO3dsV698jzECxSg
> QUIT

Configuring Mosquitto

listener 1883

auth_plugin /path/to/auth-plug.so
auth_opt_redis_host 127.0.0.1
auth_opt_redis_port 6379

# Usernames with this fnmatch(3) (a.k.a glob(3))  pattern are exempt from the
# module's ACL checking
auth_opt_superusers S*

ACL

In addition to the ACL checking which might be performed by a back-end, there's a more "static" checking which can be configured in mosquitto.conf.

Note that if ACLs are being verified by the plugin, this also applies to Will topics (last will and testament). Failing to correctly set up an ACL for these, will cause a broker to silently fail with a 'not authorized' message.

Users can be given "superuser" status (i.e. they may access any topic) if their username matches the glob specified in auth_opt_superusers.

In our example above, any user with a username beginning with a capital "S" is exempt from ACL-checking.

PUB/SUB

At this point you ought to be able to connect to Mosquitto using, e.g., the Mosquitto client:

mosquitto_pub  -t '/location/n2' -m hello -u n2 -P secret

Requirements

  • A Mosquitto broker
  • OpenSSL (tested with 1.0.0c, but should work with earlier versions)

Some of the back-ends require a server instance or client libraries. For example:

  • for redis: a Redis server and hiredis, the Minimalistic C client for Redis
  • for cdb: TinyCDB by Michael Tokarev (included in contrib/)
  • for postgres: the latest dev version of postgresql-server

Credits

  • Uses base64.[ch] (and yes, I know OpenSSL has base64 routines, but no thanks). These files are

Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Hgskolan (Royal Institute of Technology, Stockholm, Sweden).

  • Uses uthash by Troy D. Hanson.

Possibly related

Press

mosquitto-auth-plug's People

Contributors

auselen avatar bartbes avatar brocaar avatar felipejfc avatar flightonary avatar gjongenelen avatar hinzundcode avatar jasiek avatar johanstokking avatar jpmens avatar krishnapg avatar kuroei avatar mberka avatar myagley avatar osterlad avatar petervanpansen avatar pierref avatar premsangeeth avatar rh389 avatar rlamp avatar robhogan avatar samsk avatar sfowlr avatar sjorsdewit avatar sreeisalso avatar stefanoterna avatar tpb-dev avatar vinnyt avatar webworxshop avatar wendal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mosquitto-auth-plug's Issues

Compilation error

I've got some troubles compiling the mosquitto-auth-plugin on a raspberyy pi running RASPBIAN, Version:June 2014, Release date:2014-06-20.

I want to run the backend mysql and I've installed the prerequisites:

mosquitto (1.3.2) mosquitto-clients python-mosquitto (from http://repo.mosquitto.org/debian/mosquitto-repo)
mysql-server-5.5
libmysqlclient-dev
libssl-dev

I've only enabled the mysql backend:

BACKENDS=-DBE_MYSQL

But the compiler complaints:

openhab@openhab ~/checkout/mosquitto-auth-plug $ make clean && make
rm -f _.o *.so
(cd contrib/tinycdb-0.78; make realclean )
make[1]: Entering directory /home/openhab/checkout/mosquitto-auth-plug/contrib/tinycdb-0.78' rm -f *.o *.lo core *~ libcdb[._][aps]_ libnss_cdb.so.2\* cdb cdb-shared make[1]: Leaving directory /home/openhab/checkout/mosquitto-auth-plug/contrib/tinycdb-0.78'
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o auth-plug.o auth-plug.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o base64.o base64.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o pbkdf2-check.o pbkdf2-check.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o log.o log.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o hash.o hash.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o be-psk.o be-psk.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o be-cdb.o be-cdb.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o be-mysql.o be-mysql.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o be-sqlite.o be-sqlite.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o be-redis.o be-redis.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o be-postgres.o be-postgres.c
cc -I/home/openhab/checkout/mosquitto-1.3.2/src/ -I/home/openhab/checkout/mosquitto-1.3.2/lib/ -fPIC -Wall -Werror -DBE_MYSQLmysql_config --cflags-Icontrib/tinycdb-0.78// -I/usr/local/include/hiredis -I/usr/include -I/src -DDEBUG=1 -I/usr/include/openssl/include -c -o be-ldap.o be-ldap.c
(cd contrib/tinycdb-0.78; make libcdb.a cdb )
make[1]: Entering directory/home/openhab/checkout/mosquitto-auth-plug/contrib/tinycdb-0.78' cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_init.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_find.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_findnext.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_seq.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_seek.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_unpack.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_make_add.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_make_put.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_make.c cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb_hash.c rm -f libcdb.a ar rv libcdb.a cdb_init.o cdb_find.o cdb_findnext.o cdb_seq.o cdb_seek.o cdb_unpack.o cdb_make_add.o cdb_make_put.o cdb_make.o cdb_hash.o ar: creating libcdb.a a - cdb_init.o a - cdb_find.o a - cdb_findnext.o a - cdb_seq.o a - cdb_seek.o a - cdb_unpack.o a - cdb_make_add.o a - cdb_make_put.o a - cdb_make.o a - cdb_hash.o ranlib libcdb.a cc -fPIC -O -D_FILE_OFFSET_BITS=64 -c cdb.c cc -fPIC -o cdb cdb.o libcdb.a make[1]: Leaving directory /home/openhab/checkout/mosquitto-auth-plug/contrib/tinycdb-0.78'
cc -fPIC -shared auth-plug.o base64.o pbkdf2-check.o log.o hash.o be-psk.o be-cdb.o be-mysql.o be-sqlite.o be-redis.o be-postgres.o be-ldap.o -o auth-plug.so -L/usr/include/openssl/lib -lcrypto contrib/tinycdb-0.78/libcdb.amysql_config --libs -lpq -Lcontrib/tinycdb-0.78 -lcdb -lsqlite3 -L/usr/local/lib -lhiredis -L/usr/lib -lldap -llber -L/usr/include/openssl/lib -lcrypto -L/home/openhab/checkout/mosquitto-1.3.2/lib/ -lmosquitto
/usr/bin/ld: cannot find -lpq
/usr/bin/ld: cannot find -lsqlite3
/usr/bin/ld: cannot find -lhiredis
/usr/bin/ld: cannot find -lldap
/usr/bin/ld: cannot find -llber
/usr/bin/ld: cannot find -lmosquitto
collect2: ld returned 1 exit status
make: *** [auth-plug.so] Error 1

What do I need to do to have the compiler find these libraries?

Thanks in advance!

nord is -1: unpossible!

Hi,
I'm running your auth plugin since november with mysql based autentication.
These days I'm starting to get "nord is -1: unpossible!" error, then all other autentication fail.

Here is the log:
1426542924: New connection from 188.216.166.aaa on port 1884.
1426542924: |-- mosquitto_auth_unpwd_check(USER_NOT_IN_DB)
1426542924: |-- ** checking backend mysql
1426542924: |-- getuser(USER_NOT_IN_DB) AUTHENTICATED=0 by none
1426542928: New connection from 188.216.166.aaa on port 1884.
1426542928: |-- mosquitto_auth_unpwd_check(USER_NOT_IN_DB)
1426542928: |-- ** checking backend mysql
1426542928: |-- getuser(USER_NOT_IN_DB) AUTHENTICATED=0 by none
1426542937: New connection from 188.216.166.aaa on port 1884.
1426542937: |-- mosquitto_auth_unpwd_check(USER_NOT_IN_DB)
1426542937: |-- ** checking backend mysql
1426542937: |-- getuser(USER_NOT_IN_DB) AUTHENTICATED=0 by none
1426542938: |-- mosquitto_auth_acl_check(..., CLIENT_XX, USER_OK_1, TOPIC_1_1_OK, 2)
1426542938: |-- nord is -1: unpossible!
1426542968: New connection from 188.216.166.aaa on port 1884.
1426542968: |-- mosquitto_auth_unpwd_check(USER_NOT_IN_DB)
1426542968: |-- ** checking backend mysql
1426542968: |-- getuser(USER_NOT_IN_DB) AUTHENTICATED=0 by none
1426542976: |-- mosquitto_auth_acl_check(..., CLIENT_YY, USER_OK_2, TOPIC_2_1_OK, 2)
1426542976: |-- nord is -1: unpossible!
1426542976: |-- mosquitto_auth_acl_check(..., CLIENT_YY, USER_OK_2, TOPIC_2_2_OK, 2)
1426542976: |-- nord is -1: unpossible!
1426542976: |-- mosquitto_auth_acl_check(..., CLIENT_YY, USER_OK_2, TOPIC_2_3_OK, 2)
1426542976: |-- nord is -1: unpossible!
1426542976: |-- mosquitto_auth_acl_check(..., CLIENT_YY, USER_OK_2, TOPIC_2_4_OK, 2)
1426542976: |-- nord is -1: unpossible!
1426542976: |-- mosquitto_auth_acl_check(..., CLIENT_YY, USER_OK_2, TOPIC_2_5_OK, 2)
1426542976: |-- nord is -1: unpossible!
1426542976: |-- mosquitto_auth_acl_check(..., CLIENT_YY, USER_OK_2, TOPIC_2_6_OK, 2)
1426542976: |-- nord is -1: unpossible!
1426542976: |-- mosquitto_auth_acl_check(..., CLIENT_YY, USER_OK_2, TOPIC_2_7_OK, 2)

I think the problem starts when USER_NOT_IN_DB try to connect.
Here is configuration quey:
auth_opt_userquery SELECT passwordpbkdf2 FROM User WHERE username = '%s';
auth_opt_superquery SELECT IFNULL(COUNT(*), 0) FROM User WHERE username = '%s' AND superuser = 1

DENY Sub

Hi,
I have done some tests. It's working excellent. But i've found something, I don't know if it is a bug or is just not implemented.
If a user has no ACL permission he may subscribe as read on any existent or inexistent topic.
When the user subscribes I get

1418921109: New connection from 192.168.1.1 on port 1883.
1418921109: |-- mosquitto_auth_unpwd_check(mihai)
1418921109: |-- ** checking backend mysql
1418921109: |-- getuser(mihai) AUTHENTICATED=1 by mysql
1418921109: New client connected from 192.168.1.1 as mosqsub/42087-mihais-ma (c1, k60, umihai).
1418921109: Sending CONNACK to mosqsub/42087-mihais-ma (0)
1418921109: Received SUBSCRIBE from mosqsub/42087-mihais-ma
1418921109: test/test (QoS 0)
1418921109: mosqsub/42087-mihais-ma 0 test/test
1418921109: Sending SUBACK to mosqsub/42087-mihais-ma

and the aclcheck step is not there.
Thank you

Can't authenticate on mysql

I have created a user : 123456789 and a hash for password "testpassword" : PBKDF2$sha256$901$SALT$dc59c53d92f078d49b34

When i try to connect using : mosquitto_pub -h myIP -t '/base' -m 'test_topic' -u 123456789 -P testpassword I get an error :

Connection Refused: bad user name or password.
Error: The connection was refused.

The log of mosquitto daemon says :

1416769178: |-- mosquitto_auth_unpwd_check(123456789)
1416769178: |-- ** checking backend mysql
1416769178: |-- getuser(123456789) AUTHENTICATED=0 by none

Do you have any idea about my issue ?

Superuser wildcard subscription to /location/# not working

If I subscribe a superuser to /location/# the subscriber will not receive messages publishes to /location/foo or /location/bar. Subscribing directly to /location/bar and /location/foo works however.

Is this an intended behaviour?

ACL check only on publish

Using the configuration from examples/mosquitto-mysql.conf when I publish to the topic I got denied but I still can subscribe without any problem.

libmosquitto not required

mosquitto_topic_matches_sub() is available in the mosquitto exe, so you shouldn't need to link against libmosquitto.

REST

Inspired by this we could add a libcurl-based REST API of some sort.

mqttwarn compatibility

Hi JP,

I would like to know if this plugin is compatible with mqttwarn module. I need to use mqttwarn on the same server and save into mysql every dispatched message. Now after I have installed the auth-plug module mosquitto daemon keep crashing, I believe because mqttwarn is trying to connect without user and password .

thank you

%u and %c in field 'topic' of table acls

Good night,

after setting up correctly my bridged mosquitto architecture and the mosquitto-auth-plug, I've tried to set topics in 'acls' table that include %d and %u, thinking that maybe it would work fine, the same way that # and + do. But it does not seems to work.

Are you thinking on implementing this feature in a near future. It whould be very useful!!

Best regards and... thank you for this really good job!!

PS: os maybe it works and I'm doing it the wrong way.

Error on loading in mosquitto 1.4

hi,
I've a problem with auth-plugin when i try to start mosquitto.
I recieve this error: auth-plugin.so undefinied sum ol ares_library_init.
I work on centos 6.5 with c-ares19 library and devel installed.
Someone could help me please?
Luca

segfault with http when client publish without user

mosquitto_pub -t /test -m ciao
produce segfault:

Using host libthread_db library "/lib64/libthread_db.so.1".
1416706120: mosquitto version 1.3.5 (build date 2014-10-08 22:06:55+0000) starting
1416706120: Config loaded from /etc/mosquitto/mosquitto.conf.
1416706120: |-- *** auth-plug: startup
1416706120: |-- ** Configured order: http

1416706120: |-- getuser_uri=/auth
1416706120: |-- superuser_uri=/superuser
1416706120: |-- aclcheck_uri=/acl
1416706120: Opening ipv4 listen socket on port 1883.
1416706120: Opening ipv6 listen socket on port 1883.
1416706127: New connection from 192.168.1.172 on port 1883.
1416706127: New client connected from 192.168.1.172 as mosqpub/3837-asus-pat1 (c1, k60).
1416706127: Sending CONNACK to mosqpub/3837-asus-pat1 (0)
1416706127: |-- mosquitto_auth_acl_check(..., mosqpub/3837-asus-pat1, NULL, /test, MOSQ_ACL_WRITE)

Program received signal SIGSEGV, Segmentation fault.
0x00000036157398cf in __strlen_sse42 () from /lib64/libc.so.6
(gdb) where
#0 0x00000036157398cf in __strlen_sse42 () from /lib64/libc.so.6
#1 0x00007ffff7baa780 in hexify (clientid=0x652460 "mosqpub/3837-asus-pat1", username=0x0, topic=0x650b60 "/test", access=2,

hex=0x7fffffffd2c0 "`\ve") at cache.c:64

#2 0x00007ffff7babfd8 in cache_q (clientid=0x652460 "mosqpub/3837-asus-pat1", username=0x0, topic=0x650b60 "/test", access=2,

userdata=0x64dd20) at cache.c:144

#3 0x00007ffff7ba84df in mosquitto_auth_acl_check (userdata=0x64dd20, clientid=0x652460 "mosqpub/3837-asus-pat1",

username=0x0, topic=0x650b60 "/test", access=2) at auth-plug.c:440

#4 0x000000000040fbcb in ?? ()
#5 0x000000000040f255 in ?? ()
#6 0x000000000040b212 in ?? ()
#7 0x000000000040401b in ?? ()
#8 0x0000003615621b45 in __libc_start_main () from /lib64/libc.so.6
#9 0x0000000000404139 in ?? ()

Mosquitto dies on wrong password.

When usin the MySQL backend, on wrong password - mosquitto dies

Mosquitto version 1.2.2

It sigfaults.

mosquitto[4984]: segfault at 7ff8705257d8 ip 00007ff8705257d8 sp 00007fff90610d48 error 15 in libc-2.17.so[7ff870525000+2000

installation issue

undefined symbol: ares_library_init (./auth-plug.so)
undefined symbol: ares_library_cleanup (./auth-plug.so)

ACL check issue?

HI JPMens,

I'm having some problems with acl checking. Could you help me?

I've two users manolodd and backenduser.

manolodd has read acces (1) to: mobile/1/0/auth/api/responses/users/%u/#
backend user has rw acces (2) to: mobile/1/0/auth/api/responses/users/#

manolo subscribes to mobile/1/0/auth/api/responses/users/manolodd/#
backenduser publishes to: mobile/1/0/auth/api/reponses/users/manolodd/login

But backenduser is not authorized to publish, although it has rw=2 for mobile/1/0/auth/api/responses/users/# which includes mobile/1/0/auth/api/reponses/users/manolodd/login

This is the log:

1426446906: |-- mosquitto_auth_unpwd_check(backenduser)
1426446906: |-- ** checking backend mysql
1426446906: |-- getuser(backenduser) AUTHENTICATED=1 by mysql
1426446906: |-- mosquitto_auth_acl_check(..., mosqpub/16279-manolodd-, backenduser, mobile/1/0/auth/api/reponses/users/manolodd/login, MOSQ_ACL_WRITE)
1426446906: |-- user backenduser was authenticated in back-end 0 (mysql)
1426446906: |-- mysql: topic_matches(mobile/1/0/auth/api/responses/users/#, mobile/1/0/auth/api/responses/users/#) == 0
1426446906: |-- mysql: topic_matches(mobile/1/0/auth/platform/broadcast/#, mobile/1/0/auth/platform/broadcast/#) == 0
1426446906: |-- mysql: topic_matches(mobile/1/0/anon/api/responses/clients/#, mobile/1/0/anon/api/responses/clients/#) == 0
1426446906: |-- mysql: topic_matches(mobile/1/0/anon/platform/status/#, mobile/1/0/anon/platform/status/#) == 0
1426446906: |-- aclcheck(backenduser, mobile/1/0/auth/api/reponses/users/manolodd/login, 2) AUTHORIZED=0 by mysql

And mosquitto logs:

Mar 15 20:27:19 mosquitto-big mosquitto[5557]: New connection from 192.168.1.100 on port 8883.
Mar 15 20:27:19 mosquitto-big mosquitto[5557]: New client connected from 192.168.1.100 as mosqpub/16362-manolodd- (c1, k60, u'backenduser').
Mar 15 20:27:19 mosquitto-big mosquitto[5557]: Sending CONNACK to mosqpub/16362-manolodd- (0, 0)
Mar 15 20:27:19 mosquitto-big mosquitto[5557]: Denied PUBLISH from mosqpub/16362-manolodd- (d0, q2, r0, m1, 'mobile/1/0/auth/api/reponses/users/manolodd/login', ... (4 bytes))
Mar 15 20:27:19 mosquitto-big mosquitto[5557]: Sending PUBREC to mosqpub/16362-manolodd- (Mid: 1)
Mar 15 20:27:19 mosquitto-big mosquitto[5557]: Received PUBREL from mosqpub/16362-manolodd- (Mid: 1)
Mar 15 20:27:19 mosquitto-big mosquitto[5557]: Sending PUBCOMP to mosqpub/16362-manolodd- (Mid: 1)
Mar 15 20:27:19 mosquitto-big mosquitto[5557]: Received DISCONNECT from mosqpub/16362-manolodd-
Mar 15 20:27:19 mosquitto-big mosquitto[5557]: Client mosqpub/16362-manolodd- disconnected.

It is a bug?

Thanks

CDB support for people who don't want Redis

Redis adds moving parts to the infrastructure. Maybe add CDB support as a lightweight constant db.

In which case, I'd rename the plugin to something more generic.

Another option, particularly for huge environments: LMDB

Mandatory parameter `redis_userquery' missing

Hi,
I think both redis_userquery and redis_aclquery are mandatory. yet I could not find any mention of these in the README or repo. Could you please give me a mosquitto.conf example for Redis..?

I get the following error.
|-- *** auth-plug: startup
1426207703: |-- ** Configured order: redis

1426207703: |-- }}}} Redis
|-- Mandatory parameter `redis_userquery' missing
|-- *** ABORT.

Segmentation fault using bridging

Summary

Setup client(a) <----> mosq(a) <----> mosq(b) <----> client(b)

Bridging in one direction seems to work fine. The issue seems to come about when publishing to a server that is bridged and hasn't published anything yet. If you bring up mosquitto on mosq(a) and mosq(b) where mosq(a) has two connections defined (an in and an out) if it receives on the in before the out the process Seg Faults.

It looks, based on the memory address, that the pointer is in protected memory space. I am really not a C++ guy so I am sorry I am not much help here. Mosq(a) is an embedded debian host running on an arm platform and mosq(b) is on an intel platform.

The versions on both servers are the same auth-plug from master yesterday.

mosquitto version 1.3 (build date 2014-03-25 02:40:13+0000)
mosquitto is an MQTT v3.1 broker.

mosq(a) configuration

# Global options
retry_interval 5
sys_interval 10
persistence true 
autosave_interval 1800
persistent_client_expiration 1m
persistence_location /var/lib/mosquitto/
queue_qos0_messages true


# Multiple log_dest supported

log_dest syslog
log_dest stdout

listener 1883
listener 1884

# topic logs to the broker topic '$SYS/broker/log/<severity>',
# where severity is one of D, E, W, N, I, M which are debug, error,

log_dest topic

# Possible types are: debug, error, warning, notice, information,
# none, subscribe, unsubscribe, all.

log_type all

# Authentication config
auth_plugin /var/lib/mosquitto/auth-plug.so
auth_opt_backends redis
auth_opt_host localhost
auth_opt_port 6379

connection toCloud
address 10.0.0.7
username ***
password ***
restart_timeout 5
topic /remote/# out "" ""

connection fromCloud
address 10.0.0.7
username ***
password ***
restart_timeout 5
topic /remote/test/control in "" ""

mosq(b) config

# Global options
retry_interval 5
sys_interval 10
persistence true # for whatever reason this breaks shit
autosave_interval 1800
persistent_client_expiration 1m
persistence_location /var/lib/mosquitto/
upgrade_outgoing_qos true
queue_qos0_messages true

# Multiple log_dest supported

log_dest syslog
log_dest stdout

listener 1883
listener 1884

# topic logs to the broker topic '$SYS/broker/log/<severity>',
# where severity is one of D, E, W, N, I, M which are debug, error,

log_dest topic

# Possible types are: debug, error, warning, notice, information,
# none, subscribe, unsubscribe, all.

log_type all

# Authentication config
auth_plugin /var/lib/mosquitto/auth-plug.so
auth_opt_backends mysql
auth_opt_host localhost
auth_opt_port 3306
auth_opt_dbname mqtt_auth
auth_opt_user ***
auth_opt_pass ***
auth_opt_userquery SELECT password FROM users WHERE username = '%s'
auth_opt_superquery SELECT COUNT(*) FROM users WHERE username = '%s' AND super = 1
auth_opt_aclquery SELECT topic FROM acls WHERE (username = '%s') AND (rw & 1)

connection bridge
clientid bridge
address localhost:1884
topic #  in "" /bridge
username ***
password ***
#restart_timeout 5
#start_type automatic
#try_private false
cleansession true
#connection_messages true
max_connections -1

gdb output

root@monolith:/usr/local# gdb
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) exec-file /usr/local/sbin/mosquitto 
(gdb) handle SIGILL nostop noprint
Signal        Stop  Print   Pass to program Description
SIGILL        No    No  Yes     Illegal instruction
(gdb) run -c /etc/mosquitto/mosquitto.conf
Starting program: /usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
1395917698: mosquitto version 1.3 (build date 2014-03-27 00:13:27+0000) starting
1395917698: Config loaded from /etc/mosquitto/mosquitto.conf.
*** auth-plug: backend=BACKEND
1395917698: |-- AuthOptions: key=backends, val=redis
1395917698: |-- AuthOptions: key=host, val=localhost
1395917698: |-- AuthOptions: key=port, val=6379
** Configured order: redis
1395917698: |-- }}}} Redis
1395917698: Opening ipv4 listen socket on port 1883.
1395917698: Opening ipv6 listen socket on port 1883.
1395917698: Opening ipv4 listen socket on port 1884.
1395917698: Opening ipv6 listen socket on port 1884.
1395917698: Bridge monolith.toCloud doing local SUBSCRIBE on topic /remote/#
1395917698: Connecting bridge toCloud (10.0.0.7:1883)
1395917698: Error creating bridge: Connection refused.
1395917698: Warning: Unable to connect to bridge toCloud.
1395917698: Connecting bridge fromCloud (10.0.0.7:1883)
1395917698: Error creating bridge: Connection refused.
1395917698: Warning: Unable to connect to bridge fromCloud.
1395917703: Bridge monolith.toCloud doing local SUBSCRIBE on topic /remote/#
1395917703: Connecting bridge toCloud (10.0.0.7:1883)
1395917703: Error creating bridge: Connection refused.
1395917703: Connecting bridge fromCloud (10.0.0.7:1883)
1395917703: Error creating bridge: Connection refused.
1395917709: Bridge monolith.toCloud doing local SUBSCRIBE on topic /remote/#
1395917709: Connecting bridge toCloud (10.0.0.7:1883)
1395917709: Bridge monolith.toCloud sending CONNECT
1395917709: Connecting bridge fromCloud (10.0.0.7:1883)
1395917709: Bridge monolith.fromCloud sending CONNECT
1395917709: Received CONNACK on connection monolith.toCloud.
1395917709: Bridge monolith.toCloud sending UNSUBSCRIBE (Mid: 32, Topic: /remote/#)
1395917709: Received PUBACK from monolith.toCloud (Mid: 31)
1395917709: Received CONNACK on connection monolith.fromCloud.
1395917709: Bridge monolith.fromCloud sending SUBSCRIBE (Mid: 2, Topic: /remote/test/control, QoS: 0)
1395917709: Received UNSUBACK from monolith.toCloud
1395917709: Received PUBACK from monolith.fromCloud (Mid: 1)
1395917709: Received SUBACK from monolith.fromCloud
1395917713: |-- user bridge was authenticated in back-end 16 (<nil>)

Program received signal SIGSEGV, Segmentation fault.
0xb6fd65bc in mosquitto_auth_acl_check (userdata=0x38560, clientid=0x38ff8 "monolith.toCloud", username=0x351f0 "bridge", topic=0x36ed8 "/remote/test/control", access=2) at auth-plug.c:369
369     match = (*bep)->aclcheck((*bep)->conf, username, topic, access);
(gdb) 

Redirect log with log_dest file

Hi,
enabling mosquitto file log with "log_dest file " in mosqsuitto.conf the auth messages are not stored.

I've tried changing in plugin sources:
_log(LOG_NOTICE,
to
_mosquitto_log_printf(NULL, MOSQ_LOG_INFO,
like mosquitto source but the plugin doesn't compile.

Can you help me?

64bit Ubuntu 13.10 loading issues

Hi,

I'm having problems getting auth-plug to work on my new 13.10 x64 machine. I have tried loading from /usr/lib and /usr/lib/x86_64-linux-gnu

ldd from the lib is:

linux-vdso.so.1 => (0x00007fffc5ede000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f108bf31000)
libmysqlclient.so.18 => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 (0x00007f108b9f9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f108b630000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f108b42c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f108b213000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f108aff5000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f108acf1000)
/lib64/ld-linux-x86-64.so.2 (0x00007f108c533000)

and from mosquitto:

linux-vdso.so.1 => (0x00007fff495fe000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0626cf0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f06269ec000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f06267e3000)
libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0 (0x00007f06265d9000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f062637b000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f0625f9e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0625bd6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0626f0b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f06259b9000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007f062579e000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f0625585000)

I'm now using Mosquitto 1.3.1

Any ideas?

Thanks,

Ian

Really big logs

Hi JPMens,

I've discovered the mosquitto.log file under /var/log/upstart that, due to its content, I suppose that belongs to mosquitto-auth-plug. It has caused some failures because of my disk is full (it is a virtualized machine). There is not problem as I have already trunked it to 0 bytes, but... ¿Is there any possibility of deactivate logging option for mosquitto-auth-plug? Or at least It could be useful to be able to specify the desired location for it (on another /dev or partition, on /dev/null, on a secondary storage...)

Thanks so much.

mosquitto-auth-plug extended ACL support

Hello,

Is it possible extend the mosquitto-auth-plugin to support read only access to topics?

As at this moment there is only RW ... or I didn't understand the workings of the plugin. I need users to be able to see topic but to be unable to write to it as it is in the mosquitto basic auth - write and read ACLs are separated.

Access denied for user 'root'@'localhost' (using password: NO)

This is what i got on my log when I try to start mosquitto .
In my /etc/mosquitto/mosquitto.conf I don't have root user but mqtt user and it's password.

1416657377: mosquitto version 1.3.4 (build date 2014-08-08 09:26:34+0000) starting
1416657377: Config loaded from /etc/mosquitto/mosquitto.conf.
1416657377: |-- *** auth-plug: startup
1416657377: |-- ** Configured order: mysql

1416657377: |-- }}}} MYSQL
Access denied for user 'root'@'localhost' (using password: NO)
1416657377: Opening ipv4 listen socket on port 1883.
1416657377: Opening ipv6 listen socket on port 1883.
1416657378: New connection from xx.xx.xx.xxx on port 1883.

Issue Loading Libray

I'm having problems loading the library... I get

sudo mosquitto -d -c /etc/mosquitto/mosquitto.conf
1389563557: mosquitto version 1.2.3 (build date 2013-12-04 21:22:55+0000) starting
1389563557: Config loaded from /etc/mosquitto/mosquitto.conf.
iandl@Beaker:~$ 1389563557: Error: Unable to load auth plugin "/usr/lib/auth-plug.so".

It's compiled ok and I'm using Mosquitto 1.2.3 and OpenSSL 1.0.1c and MySQL. I've attached the (top part of) Makefile:

BACKENDS=-DBE_MYSQL

BE_CFLAGS=mysql_config --cflags
BE_LDFLAGS=mysql_config --libs
BE_DEPS=

CDBDIR=contrib/tinycdb-0.78
CDB=$(CDBDIR)/cdb
CDBINC=$(CDBDIR)/
CDBLIB=$(CDBDIR)/libcdb.a
BE_CFLAGS += -I$(CDBINC)/
BE_LDFLAGS += -L$(CDBDIR) -lcdb
BE_DEPS += $(CDBLIB)

BE_LDFLAGS += -lsqlite3

BE_CFLAGS += -I/usr/local/include/hiredis

BE_LDFLAGS += -L/usr/local/lib -lhiredis

OPENSSLDIR=/usr/local/stow/openssl-1.0.0c/

OPENSSLDIR=/home/iandl/mosquitto-auth/openssl-1.0.1c/
OSSLINC=-I$(OPENSSLDIR)/include
OSSLIBS=-L$(OPENSSLDIR)/lib -lcrypto

CFLAGS = -I/home/iandl/mosquitto-auth/mosquitto-1.2.3/src/

CFLAGS = -I~/mosquitto-auth/mosquitto-1.2.3/src/

CFLAGS += -I/home/iandl/mosquitto-auth/mosquitto-1.2.3/lib/

CFLAGS = -I../../../../pubgit/MQTT/mosquitto/src/

CFLAGS += -I../../../../pubgit/MQTT/mosquitto/lib/

CFLAGS += -fPIC -Wall -Werror $(BACKENDS) $(BE_CFLAGS) -I$(MOSQ)/src -DDEBUG=1 $(OSSLINC)
LDFLAGS=$(BE_LDFLAGS) -lmosquitto $(OSSLIBS)

LDFLAGS += -L../../../../pubgit/MQTT/mosquitto/lib

LDFLAGS += -L/home/iandl/mosquitto-auth/mosquitto-1.2.3/lib/

LDFLAGS += -Wl,-rpath,$(../../../../pubgit/MQTT/mosquitto/lib) -lc

LDFLAGS += -export-dynamic

CFLAGS += -DDEBUG=1

And the Mosquitto Conf part is:

auth_plugin /usr/lib/auth-plug.so
auth_opt_backends mysql
auth_opt_host localhost
auth_opt_port 3306
auth_opt_dbname mosquitto
auth_opt_user myuser
auth_opt_pass mypwd
auth_opt_userquery SELECT pw FROM users WHERE username = '%s'
auth_opt_superquery SELECT COUNT(*) FROM users WHERE username = '%s' AND super = 1

auth_opt_aclquery SELECT topic FROM acls WHERE username = '%s'

auth_opt_aclquery SELECT topic FROM acls WHERE (username = '%s') AND (rw & %d)

auth_opt_superusers S*

Any ideas what I'm missing?

Yet another unable to load auth-plugin.

Hi, i followed #33 but no luck. Any help appreciated.

1422608200: mosquitto version 1.3.5 (build date 2015-01-29 19:51:52+0200) starting
1422608200: Config loaded from mosquitto.conf.
LOADERROR /usr/lib/x86_64-linux-gnu/auth-plug.so: undefined symbol: deflate
1422608200: Error: Unable to load auth plugin "/usr/lib/x86_64-linux-gnu/auth-plug.so".


System Info:

  • OS: Ubuntu 14.04.1 LTS
  • Linux 3.13.0-44-generic x86_64 GNU/Linux
  • package: zlib1g-dev / Status: install ok installed

ldd /usr/local/sbin/mosquitto
linux-vdso.so.1 => (0x00007fff840ef000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f6a3c388000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6a3c082000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f6a3be79000)
libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f6a3bc1b000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f6a3b841000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6a3b47a000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6a3c5a8000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f6a3b25c000)

ldd auth-plug.so
linux-vdso.so.1 => (0x00007fff83fba000)
libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f526b99c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f526b5d6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f526b3d1000)
/lib64/ld-linux-x86-64.so.2 (0x00007f526c29c000)


cat config.mk
BACKEND_CDB ?= no
BACKEND_MYSQL ?= yes
BACKEND_SQLITE ?= no
BACKEND_REDIS ?= no
BACKEND_POSTGRES ?= no
BACKEND_LDAP ?= no
BACKEND_HTTP ?= no

MOSQUITTO_SRC = /home/gkraggel/Downloads/mosquitto/mosquitto-1.3.5

OPENSSLDIR = /usr/include/openssl


locate zlib.h
/usr/include/zlib.h
/usr/src/linux-headers-3.13.0-32/include/linux/zlib.h
/usr/src/linux-headers-3.13.0-32-generic/include/config/crypto/zlib.h
/usr/src/linux-headers-3.13.0-32-generic/include/config/jffs2/zlib.h
/usr/src/linux-headers-3.13.0-32-generic/include/config/squashfs/zlib.h
/usr/src/linux-headers-3.13.0-32-generic/include/config/ubifs/fs/zlib.h
/usr/src/linux-headers-3.13.0-32-generic/include/linux/zlib.h
/usr/src/linux-headers-3.13.0-40/include/linux/zlib.h
/usr/src/linux-headers-3.13.0-40-generic/include/config/crypto/zlib.h
/usr/src/linux-headers-3.13.0-40-generic/include/config/jffs2/zlib.h
/usr/src/linux-headers-3.13.0-40-generic/include/config/squashfs/zlib.h
/usr/src/linux-headers-3.13.0-40-generic/include/config/ubifs/fs/zlib.h
/usr/src/linux-headers-3.13.0-40-generic/include/linux/zlib.h
/usr/src/linux-headers-3.13.0-43/include/linux/zlib.h
/usr/src/linux-headers-3.13.0-43-generic/include/config/crypto/zlib.h
/usr/src/linux-headers-3.13.0-43-generic/include/config/jffs2/zlib.h
/usr/src/linux-headers-3.13.0-43-generic/include/config/squashfs/zlib.h
/usr/src/linux-headers-3.13.0-43-generic/include/config/ubifs/fs/zlib.h
/usr/src/linux-headers-3.13.0-43-generic/include/linux/zlib.h
/usr/src/linux-headers-3.13.0-44/include/linux/zlib.h
/usr/src/linux-headers-3.13.0-44-generic/include/config/crypto/zlib.h
/usr/src/linux-headers-3.13.0-44-generic/include/config/jffs2/zlib.h
/usr/src/linux-headers-3.13.0-44-generic/include/config/squashfs/zlib.h
/usr/src/linux-headers-3.13.0-44-generic/include/config/ubifs/fs/zlib.h
/usr/src/linux-headers-3.13.0-44-generic/include/linux/zlib.h

small issue in the example config

In the first part you say "users:" then you say "u:" - is that a mistake?

# Optional: prefix users with the following string
auth_opt_redis_username_prefix users:
auth_opt_redis_host 127.0.0.1
auth_opt_redis_port 6379

# Clients may PUB/SUB to the following prefix. '%' is replaced
# with an authorized user's username (sans username_prefix). So,
# user 'jjolie' may PUB/SUB to "/location/jjolie" and her password
# is at Redis key "u:jjolie"

plug in won't work well after verify a wrong user, use mysql

Step to reproduce:

use mysql db, have table user and acls

  1. create 2 users, for example: sub, pub
  2. create a topic in acls, for example: test, sub can subscribe and pub can publish
  3. connect with user "sub"
  4. publish a message with user "pub", then user "sub" can receive the topic message
  5. connect with user "xx" which the wrong user
  6. publish a message with user "pub", then user "sub" can't receive the topic message

due to userdata-> authentication_be is equal -1, the plugin call mosquitto_auth_unpwd_check to check user "xx" will set that variable to -1

Error: Unable to load auth plugin "/usr/lib/auth-plug.so"

Hi,
I've a problem running your library on a x86 machine:

./mosquitto -c mosquitto.conf1412605004: mosquitto version 1.3.4 (build date 2014-10-06 16:14:36+0200) starting
1412605004: Config loaded from mosquitto.conf.
1412605004: Error: Unable to load auth plugin "/usr/lib/auth-plug.so".

I've succesfully compiled the library without modify your makefile (I've only changed the MOSQUITTO_SRC) and moved to /usr/lib/auth.plugin.so.

I'm using mosquitto 1.3.4 compiled by myself and here is my mosquitto.conf:

autosave_interval 1800
connection_messages true
log_timestamp true
listener 1883
auth_plugin /usr/lib/auth-plug.so
auth_opt_backends mysql
auth_opt_host 127.0.0.1
auth_opt_port 3306
auth_opt_dbname mqtt
auth_opt_user mqttauth
auth_opt_pass mqttauthpassword
auth_opt_userquery SELECT password FROM USERS WHERE id_user = %s
auth_opt_superquery SELECT IFNULL(COUNT(), 0) FROM USERS WHERE id_user = %s AND superuser = 1
auth_opt_superusers S

Support for hash based data-scheme instead of prefix:username=>password

The section "data layout" of http://redis.io/topics/twitter-clone states "... what should identify a user inside our system? The username can be a good idea since it is unique, but it is also too big, and we want to stay low on memory"

As such a simple user-prefix to support scenarios of "prefix:username"=>"password-hash" is a good start but not very likely to be used.

I like an approach* of prefix:userid" => hash, where the password is stored together with every other attribute inside the hash. To get the hash for a username, I usually use a single larger hash as an index called User:uniques:name that maps a username to the id. This is a similar approach to the one recommended in the above mentioned section on the Redis site. While the principle is the same, it doesn't create at least 2*n new keys (assuming a single password attribute) for n users, but merely n+1 which don't change for more than one user attributes. I'm by no means a Redis export, but imho this feels cleaner.

Assuming, the user hash was defined HMSET User:1000 username foo password bar, and an username->id hash entry was defined with hset User:uniques:name foo 1000 the user password can be queried easily with

$uniqueid = HGET User:uniques:name testuser
HGET user:$uniqueid password

*Note: I'm a little biased, as this is the format that https://github.com/soveran/ohm is using

Change in NP or creating of API to support Web based requests

As I said in twitter - I'm working on project based on MQTTitude using mosquitto + mosquitto-auth-plug.

I want to have single point of authnetication for easy web based interface. I'm using the MQTTitude contrib form m2s.

Is it possible to calculate user password HASH in PHP or exec external program with parameter to check password validity to hash? And can it be creted API for new users/change of password?

Regards.

Will ACL

This one took me several hours to debug. Even though the ACLs were set up correctly and the debug output returned a ACL permit, Mosquitto kept sending "Sending CONNACK to ec6d3c6a4a0f342f (5)" / "Connection Refused: not authorized".

The reason for this was, that I specified a will topic that was not covered by the ACL rules. Maybe it should be documented, that when specifying a will message it should be covered by the ACL or else Mosquitto will fail silently. When thinking about it, it's quite obvious but it's easy to miss.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.