Repository navigation
04. Users
To use objects on Nexus an user is needed. When sys.login is called successfully a session is created.
Users can be created (user.create), deleted (user.delete) and listed (user.list); their password can be changed (user.setPass).
Each user has a set of tags that serves to store its Nexus permissions and custom application data. Tags are key-value data pairs related to a prefix.
Tags are returned when an user logs in and with calls to user.list, user.getTags and user.getEffectiveTags. Tags can be set on a prefix to a user with user.setTags and deleted with user.delTags.
The tags for a Nexus user could look like this:
{
"some.prefix": {
"@task.push": true,
},
"services.mail": {
"role": "admin",
"allow": ["send", "attach", "receive"]
}
}
Those tags can be interpreted as:
- On prefix
some.prefixthe user has a tag@task.pushwith valuetrue. As we will see later, tags starting with@have a special meaning for Nexus as they are interpreted as permissions. So this tag means the user has permission to call task.push tosome.prefixand all its children. - On prefix
services.mailthe user has a tagrolewith valueadminand a tagallowwith value["send", "attach", "receive"]. Those are application data tags and have no special meaning for Nexus.
The effective tags for a prefix represent the tags that will be used by Nexus when performing certain actions on that prefix. To calculate the effective tags, the tags on higher nodes on the prefix take precedence over the lower ones.
For example, given the following user tags:
{
"myprefix": { "mytag": "hello" },
"myprefix.sub": { "mytag": "bye" }
}
The effective tag mytag value for the prefix myprefix.sub will be "hello" instead of "bye" because myprefix is higher in the hierachy.
Some special tags on nexus (those starting with @) grant permissions to call certain methods on some prefixes. For example, given the following user tags:
{
"services": { "@task.push": true },
"services.mine": { "@admin": true },
".": { "@user.list": true }
}
- The user has permission to call task.push on
servicesprefix and all its children (services.mine,services.some.other.prefix, ...). - The user has permission to call any method on
services.mineprefix and all its children. The special permission tag@admingives permission to call all the methods on a prefix. - The user has permission to call user.list on any Nexus prefix. The
.prefix is the root of all prefixes.
When an user calls a Nexus method, a tag @ or @admin is searched on a prefix (and all its ancestors), if its value is true or 1 then the user is authorized to execute the method. Depending on the method, the prefixes that are checked are:
-
All methods that are called with a prefix (all user.* methods, all topic.* methods, all sync.* methods, task.push, task.pull, task.list and sys.session.list) check that prefix for the permission tag.
-
sys.session.kick and sys.session.reload are called with a connid, the user prefix which owns that connid is checked for the permission tag.
-
As an exception sys.node.list is checked on prefix
sys.node.
The permissions needed for each method are documented on the Nexus API Document.
When checking a permission tag on a prefix, effective tags are used, so the higher prefix has precedence. For example, if a user wants to execute a topic.pub method on prefix weather.spain.castellon and it has a @topic.pub tag with value true on prefix weather.spain and a @topic.pub tag with value false on prefix weather, the tag of weather has precedence and the user won't be able to call the method.
Some methods don't need any permission to be executed (sys.ping, sys.version, sys.watchdog, sys.login, sys.info, pipe.create, pipe.open, pipe.write, pipe.read).
Methods user.addTemplate and user.delTemplate check an additional permission. The user must have the permission tag
@user.useTemplateor@adminon the prefix of the template user.
To allow multiple users to share the same tags without having to modify them individually Nexus allows to define a set of templates for a user. A template is a reference to another Nexus user from which to import tags. Modifying the tags of the template user, all the users that have this user as a template will have their tags modified too.
Usually you don't want users used as templates to be allowed to login, this can be accomplished by creating the user with an empty password.
Templates can be added to a user with user.addTemplate and deleted with user.delTemplate.
To compute the resulting tags for a user, defined templates are applied sequentially (in the order they were added) on top of the user tags. If some template has templates, the sub-templates are applied right after its parent template has been applied.
When applying tags, if some tag doesn't already exist, it is added; if it already exists it is ignored (user tags have priority over templates and first added templates have priority over the ones added later).
For example given the following user and its templates:
user
{
"templates": ["template1", "template2"],
"tags": {
"prefix1": { "tagA": "userVal" }
}
}
The templates of user will be applied on top of its tags. The template1 will be applied first.
template1
{
"templates": ["subtemplate"],
"tags": {
"prefix1": { "tagA": "template1Val", "tagB": "template1Val" }
}
}
As tagA is already defined on user, it won't be added. As tagB is not defined, it's added.
The template1 templates will be applied before applying template2.
subtemplate
{
"templates": [],
"tags": {
"prefix1": { "tagA": "subtemplateVal", "tagB": "subtemplateVal", "tagC": "subtemplateVal" }
}
}
As tagA and tagB are already defined, they are not added. Only tagC will be added.
The template1 has no more templates, so template2 is applied.
template2
{
"templates": [],
"tags": {
"prefix1": { "tagA": "template2Val", "tagB": "template2Val", "tagC": "template2Val", "tagD": "template2Val" }
}
}
The only tag that has not already been defined is tagD, so it will be added.
The resulting tags for the user will be:
{
"prefix1": { "tagA": "userVal", "tagB": "template1Val", "tagC": "subtemplateVal", "tagD": "template2Val" }
}
One user can have many sessions opened with Nexus at the same time, but it's limited by max-sessions (50 by default). This number can be set calling user.setMaxSessions.
By default users can connect from any IP, but you can restrict the allowed IPs using its whitelist and blacklist. When a user attempts to connect to Nexus they are checked as follows:
- If the IP from where the user is connecting matches some of its whitelist patterns it's allowed to connect.
- If no whitelist matched, the blacklist patterns are checked; if some matches the user is not allowed to connect.
- If no whitelist or blacklist matched, it's allowed to connect.
This can be configured with calls to user.addWhitelist, user.delWhitelist, user.addBlacklist and user.delBlacklist.