Commit graph

90 commits

Author SHA1 Message Date
Kim Alvefur
9db7569abc luacheck: Declare new config globals 2025-01-18 12:33:18 +01:00
Kim Alvefur
dc80c46504 luacheckrc: Add module.ready() 2025-01-10 12:34:29 +01:00
Kim Alvefur
dadd754f74 luacheckrc: Reorder module API methods for consistency with prosody-modules
Makes it easier to keep them in sync when the diff is smaller
2025-01-10 12:32:29 +01:00
Kim Alvefur
ddd479afe2 util.rfc6724: Remove, unused since introduction of Happy Eyeballs
It was mainly used to determine whether to try IPv6 or IPv4 first,
following the rules for this in the RFC.

Now we always try IPv6 and IPv4 at roughly the same time, thus there no
need to carry these rules.
2024-02-22 19:46:52 +01:00
Matthew Wild
4263537301 luacheckrc, mod_http_file_share: Update for module API change (once->on_ready) 2023-11-30 10:14:17 +00:00
Matthew Wild
b3e293118d .luacheckrc: Add module:could() 2023-11-07 11:56:15 +00:00
Kim Alvefur
33657b4001 lint: Teach luacheck about module:once
Silence warning for using this introduced in 9c62ffbdf2ae
2023-10-15 16:43:14 +02:00
Kim Alvefur
210f608086 moduleapi: Add :get_option_integer()
Many options in Prosody that are treated as numbers don't make sense as
floats, e.g. sizes and limits measured in bytes.

Simplified implementation based on an earlier attempt dating back to 2020
2023-07-17 00:09:41 +02:00
Kim Alvefur
3c4dc9a754 core.moduleapi: Add :get_option_period for parsing time intervals
E.g. for use in mod_mam and others that take an amount of time before
some (usually cleanup) action is taken.
2023-07-16 19:49:12 +02:00
Kim Alvefur
c4abd68e92 moduleapi: Add enum config option method
For when a setting has a few fixed values it can take
2021-01-16 20:40:14 +01:00
Kim Alvefur
66d38cb199 luacheck: Remove long gone mod_storage_sql1 from excludes
No point not checking a file that doesn't exist
2023-01-19 17:29:40 +01:00
Matthew Wild
02352c6dcf .luacheckrc: Add test_mutants.sh.lua to the ignore list 2022-10-11 13:12:26 +01:00
Matthew Wild
d73714b4f4 Switch to a new role-based authorization framework, removing is_admin()
We began moving away from simple "is this user an admin?" permission checks
before 0.12, with the introduction of mod_authz_internal and the ability to
dynamically change the roles of individual users.

The approach in 0.12 still had various limitations however, and apart from
the introduction of roles other than "admin" and the ability to pull that info
from storage, not much actually changed.

This new framework shakes things up a lot, though aims to maintain the same
functionality and behaviour on the surface for a default Prosody
configuration. That is, if you don't take advantage of any of the new
features, you shouldn't notice any change.

The biggest change visible to developers is that usermanager.is_admin() (and
the auth provider is_admin() method) have been removed. Gone. Completely.

Permission checks should now be performed using a new module API method:

  module:may(action_name, context)

This method accepts an action name, followed by either a JID (string) or
(preferably) a table containing 'origin'/'session' and 'stanza' fields (e.g.
the standard object passed to most events). It will return true if the action
should be permitted, or false/nil otherwise.

Modules should no longer perform permission checks based on the role name.
E.g. a lot of code previously checked if the user's role was prosody:admin
before permitting some action. Since many roles might now exist with similar
permissions, and the permissions of prosody:admin may be redefined
dynamically, it is no longer suitable to use this method for permission
checks. Use module:may().

If you start an action name with ':' (recommended) then the current module's
name will automatically be used as a prefix.

To define a new permission, use the new module API:

  module:default_permission(role_name, action_name)
  module:default_permissions(role_name, { action_name[, action_name...] })

This grants the specified role permission to execute the named action(s) by
default. This may be overridden via other mechanisms external to your module.

The built-in roles that developers should use are:

 - prosody:user (normal user)
 - prosody:admin (host admin)
 - prosody:operator (global admin)

The new prosody:operator role is intended for server-wide actions (such as
shutting down Prosody).

Finally, all usage of is_admin() in modules has been fixed by this commit.
Some of these changes were trickier than others, but no change is expected to
break existing deployments.

EXCEPT: mod_auth_ldap no longer supports the ldap_admin_filter option. It's
very possible nobody is using this, but if someone is then we can later update
it to pull roles from LDAP somehow.
2022-06-15 12:15:01 +01:00
Kim Alvefur
561c588fd5 luacheck: Set expected globals to Lua 5.4 + compat
Requires luacheck 0.25.0
2022-07-10 16:10:29 +02:00
Kim Alvefur
afe8199ba9 luacheck: Ignore new warning about uses of not (x == y) and similar
Added in luacheck 0.26.
2022-05-30 17:12:58 +02:00
Kim Alvefur
3721a65c80 luacheck: Ignore new warning about using variables prefixed with '_'
luacheck 0.26 considers the _ prefix as a hint that the variable or
argument is unused, then warns if they are used despite this.

We have several places where this prefix is used to avoid shadowing
another similarly named variable, resulting in many instances of this
warning.
2022-05-30 16:49:52 +02:00
Kim Alvefur
f56aaf1ba1 mod_c2s,mod_s2s: Disable and close port listeners before closing sessions
This ensures no new clients can start connecting during shutdown
2022-02-11 21:36:53 +01:00
Kim Alvefur
aa20355fa2 prosody: Expose main thread on the 'prosody' global
To allow running things in it.
2021-10-06 14:49:26 +02:00
Kim Alvefur
8aa16eaec0 mod_cron: Add a 'weekly' job frequency 2021-12-03 09:05:41 +01:00
Kim Alvefur
7f2412db5c core.moduleapi: Add API for adding daily or hourly tasks via mod_cron 2021-11-21 18:13:21 +01:00
Jonas Schäfer
5d597837f5 Statistics: Rewrite statistics backends to use OpenMetrics
The metric subsystem of Prosody has had some shortcomings from
the perspective of the current state-of-the-art in metric
observability.

The OpenMetrics standard [0] is a formalization of the data
model (and serialization format) of the well-known and
widely-used Prometheus [1] software stack.

The previous stats subsystem of Prosody did not map well to that
format (see e.g. [2] and [3]); the key reason is that it was
trying to do too much math on its own ([2]) while lacking
first-class support for "families" of metrics ([3]) and
structured metric metadata (despite the `extra` argument to
metrics, there was no standard way of representing common things
like "tags" or "labels").

Even though OpenMetrics has grown from the Prometheus world of
monitoring, it maps well to other popular monitoring stacks
such as:

- InfluxDB (labels can be mapped to tags and fields as necessary)
- Carbon/Graphite (labels can be attached to the metric name with
  dot-separation)
- StatsD (see graphite when assuming that graphite is used as
  backend, which is the default)

The util.statsd module has been ported to use the OpenMetrics
model as a proof of concept. An implementation which exposes
the util.statistics backend data as Prometheus metrics is
ready for publishing in prosody-modules (most likely as
mod_openmetrics_prometheus to avoid breaking existing 0.11
deployments).

At the same time, the previous measure()-based API had one major
advantage: It is really simple and easy to use without requiring
lots of knowledge about OpenMetrics or similar concepts. For that
reason as well as compatibility with existing code, it is preserved
and may even be extended in the future.

However, code relying on the `stats-updated` event as well as
`get_stats` from `statsmanager` will break because the data
model has changed completely; in case of `stats-updated`, the
code will simply not run (as the event was renamed in order
to avoid conflicts); the `get_stats` function has been removed
completely (so it will cause a traceback when it is attempted
to be used).

Note that the measure_*_event methods have been removed from
the module API. I was unable to find any uses or documentation
and thus deemed they should not be ported. Re-implementation is
possible when necessary.

   [0]: https://openmetrics.io/
   [1]: https://prometheus.io/
   [2]: #959
   [3]: #960
2021-04-18 11:47:41 +02:00
Kim Alvefur
081eb23c54 util.datamapper: Library for extracting data from stanzas
Based on the XML support in the OpenAPI specification.
2021-03-07 00:57:36 +01:00
Kim Alvefur
02da1378f8 util.jsonschema: Library for JSON Schema validation 2021-03-06 21:07:53 +01:00
Kim Alvefur
6a30c93ed3 luacheck: Remove exception for net.cqueues since it is now clean 2020-07-08 20:22:48 +02:00
Kim Alvefur
44ed7a0e21 util.sasl.digest-md5: Remove, obsolete since 2011
RFC 6331 lists several problems with this outdated authentication
mechanism. The code here was also completely ignored by lint checks and
has probably not been used for a long time, as it is incompatible with
SCRAM-hashed password storage.
2020-04-14 16:51:24 +02:00
Kim Alvefur
b3259cf52e luacheck: Don't not warn about not using secondary return values
Brace for ONE BILLION WARNINGS!!!
2019-12-20 22:23:22 +01:00
Matthew Wild
fbb0bbe1b4 .luacheckrc: Remove passing spec/ files from ignore list 2019-12-09 12:44:43 +00:00
Matthew Wild
6866201d71 .luacheckrc: Remove passing file from ignore list 2019-12-09 12:42:22 +00:00
Kim Alvefur
ce1056dc43 .luacheckrc: Correct indentation of 'exclude_files' list 2019-04-01 21:15:47 +02:00
Matthew Wild
d89b760be1 .luacheckrc: Update to reflect new module API methods 2019-03-19 09:07:36 +00:00
Kim Alvefur
92445d93df luacheckrc: Teach luacheck about the new module:send_iq() API 2018-12-30 03:20:37 +01:00
Kim Alvefur
4da406588e net.adns: Silence individual luacheck warnings instead of ignoring entire file 2018-12-24 03:00:27 +01:00
Kim Alvefur
5e2c950296 luacheckrc: No longer ignore access to undefined fields on table lib 2018-12-08 17:13:39 +01:00
Kim Alvefur
2d56ac0394 lint: No longer ignore access to the deprecated global 'unpack'
_G.unpack is deprecated in Lua 5.2
2018-12-08 17:07:28 +01:00
Kim Alvefur
fa9d2ec963 luacheckrc: Set Lua standard to 5.3 with 5.2 compat enabled 2018-12-08 17:00:30 +01:00
Kim Alvefur
9c1bbd8313 mod_net_multiplex: Remove exception from luacheck 2018-10-10 21:55:58 +02:00
Kim Alvefur
681bf74342 mod_http_files: Remove exception from luacheck 2018-10-10 21:53:15 +02:00
Kim Alvefur
19f86b5428 mod_privacy: Remove exception from luacheck
Plugin has been removed and replaced by a tombstone, no point in
excluding it from linting
2018-10-10 21:48:38 +02:00
Kim Alvefur
a19ac39844 mod_storage_sql: Remove exception from luacheck 2018-10-10 21:22:43 +02:00
Kim Alvefur
18f98f7017 .luacheckrc: Ignore unused secondaries in non-strict mode
Previous commit was backwards
2018-10-06 18:56:22 +02:00
Kim Alvefur
e33c9e7a43 .luacheckrc: Do not ignore unused secondaries in strict mode 2018-10-06 18:52:52 +02:00
Kim Alvefur
0ddec30924 mod_websocket: Silence the one warning instead of ignoring the entire file 2018-09-30 17:55:13 +02:00
Kim Alvefur
4f7af62406 mod_s2s: Silence all warnings instead of ignoring the entire module 2018-09-30 17:49:56 +02:00
Kim Alvefur
ca83f517b7 mod_admin_telnet: Remove from luacheck ignore list 2018-09-30 14:38:32 +02:00
Kim Alvefur
a5765839cd mod_admin_adhoc: Remove from global luacheck ignore list 2018-09-30 13:37:13 +02:00
Matthew Wild
db08521d47 .luacheckrc: Allow randomize() global in spec/
This is a busted function that is not currently recognized by luacheck.

See https://github.com/mpeterv/luacheck/pull/183
2018-09-29 12:20:51 +01:00
Matthew Wild
0207b2d785 util.json tests: Add [luacheck] annotation to mark intentionally-empty if branch 2018-09-17 15:28:53 +01:00
Matthew Wild
5c12f56a9e .luacheckrc: Remove util_cache_spec.lua from the ignore list 2018-09-17 15:27:01 +01:00
Matthew Wild
5bf9e2cd57 .luacheckrc: Remove aspirational goals from strict check, keep it simple for now 2018-09-13 16:17:46 +01:00
Kim Alvefur
02b86f45f9 luacheckrc: Remove mod_groups from ignored files 2018-07-07 21:00:14 +02:00